Skip to content

Commit 44cfba6

Browse files
author
n.bitounis
committed
Revert "* Turned the primes document into an embedded resource to avoid having it as a separate file having to be carried around in the nuget."
This reverts commit 100563f.
1 parent 4baacc0 commit 44cfba6

File tree

2 files changed

+15
-28
lines changed

2 files changed

+15
-28
lines changed

DataStructures/Common/PrimesList.cs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Collections.Generic;
44
using System.IO;
55
using System.Reflection;
6-
using System.Text;
76

87
namespace DataStructures.Common
98
{
@@ -65,7 +64,8 @@ public static PrimesList Instance
6564
/// </summary>
6665
private static void _initializeData()
6766
{
68-
string[] lines = _readResource("DataStructures.Data.PrimesDocument_10K.csv");
67+
_primesDocPath = Path.Combine(Path.GetDirectoryName(typeof(PrimesList).GetTypeInfo().Assembly.Location), @"Data/PrimesDocument_10K.csv");
68+
string[] lines = File.ReadAllLines(_primesDocPath);
6969

7070
foreach (var line in lines)
7171
{
@@ -84,28 +84,10 @@ private static void _initializeData()
8484
}
8585
}
8686

87-
/// <summary>
88-
/// Reads an embedded resource as a text file.
89-
/// </summary>
90-
/// <returns></returns>
91-
public static string[] _readResource(string resourceName)
92-
{
93-
try
94-
{
95-
using (var stream = typeof(PrimesList).GetTypeInfo().Assembly.GetManifestResourceStream(resourceName))
96-
using (var reader = new StreamReader(stream ?? throw new InvalidOperationException("Failed to read resource"), Encoding.UTF8))
97-
return reader.ReadToEnd().Split("\r\n");
98-
}
99-
catch (Exception ex)
100-
{
101-
throw new Exception($"Failed to read resource {resourceName}", ex);
102-
}
103-
}
104-
105-
/// <summary>
106-
/// Return count of primes.
107-
/// </summary>
108-
public int Count
87+
/// <summary>
88+
/// Return count of primes.
89+
/// </summary>
90+
public int Count
10991
{
11092
get { return _primes.Count; }
11193
}
@@ -228,4 +210,5 @@ public void CopyTo(int[] array, int index = 0)
228210
}
229211

230212
}
213+
231214
}

DataStructures/DataStructures.csproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
<PropertyGroup>
33
<TargetFramework>netcoreapp2.0</TargetFramework>
44
</PropertyGroup>
5+
56
<ItemGroup>
6-
<None Remove="Data\PrimesDocument_10K.csv" />
7+
<Content Include="Data\PrimesDocument_10K.csv">
8+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
9+
</Content>
710
</ItemGroup>
11+
812
<ItemGroup>
9-
<EmbeddedResource Include="Data\PrimesDocument_10K.csv">
10-
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
11-
</EmbeddedResource>
13+
<None Update="Data\PrimesDocument_10K.csv">
14+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
15+
</None>
1216
</ItemGroup>
1317
</Project>

0 commit comments

Comments
 (0)