Skip to content

Commit 827e52b

Browse files
committed
changed to netstandard
fixed naming of key fixed EXCELSerializer
1 parent 431554c commit 827e52b

File tree

12 files changed

+57
-41
lines changed

12 files changed

+57
-41
lines changed

AspNetOAuth/AspNetOAuth.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<ItemGroup>
99
<PackageReference Include="Microsoft.AspNetCore.All" />
10-
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.0" PrivateAssets="All" />
10+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" PrivateAssets="All" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

Example/Data/Context.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ public class Context : DbContext
2020

2121
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
2222
{
23-
//Default: JSON-Serialize
24-
//optionsBuilder.UseFileContext();
23+
//Default: JSON-Serialize
24+
optionsBuilder.UseFileContext();
2525

26-
//JSON-Serialize + simple Encryption
27-
//optionsBuilder.UseFileContext("json", "encrypted");
26+
//JSON-Serialize + simple Encryption
27+
//optionsBuilder.UseFileContext("json", "encrypted");
2828

29-
//XML
30-
optionsBuilder.UseFileContext("xml");
31-
//optionsBuilder.UseFileContext("xml", "private");
29+
//XML
30+
//optionsBuilder.UseFileContext("xml");
31+
//optionsBuilder.UseFileContext("xml", "private");
3232

33-
//CSV
34-
//optionsBuilder.UseFileContext("csv");
33+
//CSV
34+
//optionsBuilder.UseFileContext("csv");
3535

36-
//Excel
37-
//optionsBuilder.UseFileContext("excel");
38-
}
36+
//Excel
37+
//optionsBuilder.UseFileContext("excel");
38+
}
3939

4040
protected override void OnModelCreating(ModelBuilder modelBuilder)
4141
{

Example/Example.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.4" />
10-
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.1.4" />
9+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" />
10+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.2.0" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

FileContextCore.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example", "Example\Example.
99
EndProject
1010
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetOAuth", "AspNetOAuth\AspNetOAuth.csproj", "{A78088E6-B64B-4D98-96CE-2C30D82E3187}"
1111
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileContextCore-Tests", "FileContextCore-Tests\FileContextCore-Tests.csproj", "{E1FA3EA9-0142-4F64-88DB-32DF20000BD0}"
13+
EndProject
1214
Global
1315
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1416
Debug|Any CPU = Debug|Any CPU
@@ -27,6 +29,10 @@ Global
2729
{A78088E6-B64B-4D98-96CE-2C30D82E3187}.Debug|Any CPU.Build.0 = Debug|Any CPU
2830
{A78088E6-B64B-4D98-96CE-2C30D82E3187}.Release|Any CPU.ActiveCfg = Release|Any CPU
2931
{A78088E6-B64B-4D98-96CE-2C30D82E3187}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{E1FA3EA9-0142-4F64-88DB-32DF20000BD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{E1FA3EA9-0142-4F64-88DB-32DF20000BD0}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{E1FA3EA9-0142-4F64-88DB-32DF20000BD0}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{E1FA3EA9-0142-4F64-88DB-32DF20000BD0}.Release|Any CPU.Build.0 = Release|Any CPU
3036
EndGlobalSection
3137
GlobalSection(SolutionProperties) = preSolution
3238
HideSolutionNode = FALSE

FileContextCore/Check.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal static class Check
1717
[ContractAnnotation("value:null => halt")]
1818
public static T NotNull<T>([NoEnumeration] T value, [InvokerParameterName] [NotNull] string parameterName)
1919
{
20-
if (ReferenceEquals(value, null))
20+
if (value == null)
2121
{
2222
NotEmpty(parameterName, nameof(parameterName));
2323

@@ -33,7 +33,7 @@ public static T NotNull<T>(
3333
[InvokerParameterName] [NotNull] string parameterName,
3434
[NotNull] string propertyName)
3535
{
36-
if (ReferenceEquals(value, null))
36+
if (value == null)
3737
{
3838
NotEmpty(parameterName, nameof(parameterName));
3939
NotEmpty(propertyName, nameof(propertyName));
@@ -63,7 +63,7 @@ public static IReadOnlyList<T> NotEmpty<T>(IReadOnlyList<T> value, [InvokerParam
6363
public static string NotEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
6464
{
6565
Exception e = null;
66-
if (ReferenceEquals(value, null))
66+
if (value == null)
6767
{
6868
e = new ArgumentNullException(parameterName);
6969
}
@@ -84,8 +84,7 @@ public static string NotEmpty(string value, [InvokerParameterName] [NotNull] str
8484

8585
public static string NullButNotEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
8686
{
87-
if (!ReferenceEquals(value, null)
88-
&& value.Length == 0)
87+
if (value != null && value.Length == 0)
8988
{
9089
NotEmpty(parameterName, nameof(parameterName));
9190

@@ -116,7 +115,7 @@ public static Type ValidEntityType(Type value, [InvokerParameterName] [NotNull]
116115
{
117116
NotEmpty(parameterName, nameof(parameterName));
118117

119-
throw new ArgumentException(CoreStrings.InvalidEntityType(value, parameterName));
118+
throw new ArgumentException(CoreStrings.InvalidEntityType(value));
120119
}
121120

122121
return value;

FileContextCore/FileContextCore.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFramework>netstandard2.0</TargetFramework>
55
<SignAssembly>true</SignAssembly>
66
<AssemblyOriginatorKeyFile>FileContextCoreCert.pfx</AssemblyOriginatorKeyFile>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
@@ -22,11 +22,11 @@
2222
</PropertyGroup>
2323

2424
<ItemGroup>
25-
<PackageReference Include="CsvHelper" Version="7.1.1" />
25+
<PackageReference Include="CsvHelper" Version="12.1.0" />
2626
<PackageReference Include="EPPlus.Core" Version="1.5.4" />
27-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.4" />
28-
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
29-
<PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.1" />
27+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" />
28+
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
29+
<PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.2" />
3030
<PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0" />
3131
</ItemGroup>
3232

FileContextCore/Query/Internal/FileContextQueryModelVisitor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ private static IEnumerable<TEntity> EntityQuery<TEntity>(
7171
.QueryBuffer
7272
.GetEntity(
7373
key,
74+
#pragma warning disable CS0618 // Typ oder Element ist veraltet
7475
new EntityLoadInfo(
7576
valueBuffer,
7677
vr => materializer(t.EntityType, vr)),
78+
#pragma warning restore CS0618 // Typ oder Element ist veraltet
7779
queryStateManager,
7880
throwOnNullKey: false);
7981
}));

FileContextCore/Serializer/BSONSerializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public Dictionary<TKey, object[]> Deserialize<TKey>(string list, Dictionary<TKey
4141
{
4242
JObject json = (JObject)current.Value;
4343

44-
TKey key = (TKey)json.Value<string>("Key").Deserialize(typeof(TKey));
44+
TKey key = (TKey)json.Value<string>("__Key__").Deserialize(typeof(TKey));
4545
List<object> value = new List<object>();
4646

4747
for (int i = 0; i < propertyKeys.Length; i++)
@@ -72,7 +72,7 @@ public string Serialize<TKey>(Dictionary<TKey, object[]> list)
7272
{
7373
writer.WriteStartObject();
7474

75-
writer.WritePropertyName("Key");
75+
writer.WritePropertyName("__Key__");
7676
writer.WriteValue(val.Key.Serialize());
7777

7878
for (int i = 0; i < propertyKeys.Length; i++)

FileContextCore/Serializer/EXCELSerializer.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ class EXCELSerializer
1414
private string[] propertyKeys;
1515
private readonly Type[] typeList;
1616
private readonly string password;
17+
private readonly string databaseName;
1718

19+
private static Dictionary<string, ExcelPackage> packages = new Dictionary<string, ExcelPackage>();
1820
private ExcelPackage package;
1921
private ExcelWorksheet worksheet;
2022

2123

2224
FileInfo GetFilePath()
2325
{
24-
string folder = Path.Combine(AppContext.BaseDirectory, "appdata");
26+
string folder = Path.Combine(AppContext.BaseDirectory, "appdata", databaseName);
2527

2628
if (!Directory.Exists(folder))
2729
{
@@ -31,24 +33,31 @@ FileInfo GetFilePath()
3133
return new FileInfo(Path.Combine(folder, "data.xlsx"));
3234
}
3335

34-
public EXCELSerializer(IEntityType _entityType, string _password)
36+
public EXCELSerializer(IEntityType _entityType, string _password, string databaseName)
3537
{
3638
entityType = _entityType;
3739
propertyKeys = entityType.GetProperties().Select(p => p.Name).ToArray();
3840
typeList = entityType.GetProperties().Select(p => p.ClrType).ToArray();
3941
password = _password;
42+
this.databaseName = databaseName;
4043

41-
if (package == null)
44+
if (!packages.ContainsKey(databaseName))
4245
{
4346
if (!String.IsNullOrEmpty(password))
4447
{
4548
package = new ExcelPackage(GetFilePath(), password);
49+
packages.Add(databaseName, package);
4650
}
4751
else
4852
{
4953
package = new ExcelPackage(GetFilePath());
54+
packages.Add(databaseName, package);
5055
}
5156
}
57+
else
58+
{
59+
package = packages[databaseName];
60+
}
5261

5362
string[] nameParts = entityType.Name.Split('.');
5463
string name = nameParts[nameParts.Length - 1];

FileContextCore/Serializer/JSONSerializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public Dictionary<TKey, object[]> Deserialize<TKey>(string list, Dictionary<TKey
2727

2828
foreach (JObject json in array)
2929
{
30-
TKey key = (TKey)json.Value<string>("Key").Deserialize(typeof(TKey));
30+
TKey key = (TKey)json.Value<string>("__Key__").Deserialize(typeof(TKey));
3131
List<object> value = new List<object>();
3232

3333
for (int i = 0; i < propertyKeys.Length; i++)
@@ -51,7 +51,7 @@ public string Serialize<TKey>(Dictionary<TKey, object[]> list)
5151
{
5252
JObject json = new JObject
5353
{
54-
new JProperty("Key", val.Key.Serialize())
54+
new JProperty("__Key__", val.Key.Serialize())
5555
};
5656

5757
for (int i = 0; i < propertyKeys.Length; i++)

0 commit comments

Comments
 (0)