Skip to content

Commit b8f01e3

Browse files
committed
updated README.md, small fixes
1 parent 366cae5 commit b8f01e3

File tree

11 files changed

+187
-33
lines changed

11 files changed

+187
-33
lines changed

README.md

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,126 @@
11
# FileContextCore
2-
FileContextCore is a "Database"-Provider for Entity Framework Core and adds the ability to store information in files instead of being limited to databases.
2+
3+
FileContextCore is a "Database"-Provider for Entity Framework Core and adds the ability to store information in files instead of being limited to databases. It enables fast developments because of the advantage of just copy, edit and delete files.
4+
5+
This framework bases on the idea of FileContext by DevMentor ([https://github.com/pmizel/DevMentor.Context.FileContext](https://github.com/pmizel/DevMentor.Context.FileContext))
6+
7+
## Advantages
8+
9+
- No database needed
10+
- easy configuration
11+
- rapid data-modelling, -modification
12+
- share data through version-control
13+
- supports all serializable .NET types
14+
- integrated seamlessly into EF Core
15+
- diferrent serializer supported (XML, JSON, CSV, Excel)
16+
- supports encryption
17+
- supports relations
18+
19+
!This extension is not intended to be used in production systems!
20+
21+
## Install
22+
23+
```
24+
PM > Install-Package FileContextCore
25+
```
26+
27+
Configure EF Core
28+
29+
```cs
30+
optionsBuilder.UseFileContext();
31+
```
32+
33+
or
34+
35+
```cs
36+
services.AddEntityFramework().AddDbContext<Context>(options => options.UseFileContext());
37+
```
38+
39+
## Example
40+
41+
For an Example check out: [Example](https://github.com/morrisjdev/FileContextCore/tree/master/src/Example)
42+
43+
## Configuration
44+
45+
By default the extension uses `JSON`-serialization and the `DefaultFileManager`
46+
47+
## Available Serializer
48+
49+
### XMLSerializer
50+
51+
Serializes data using System.XML
52+
53+
```cs
54+
optionsBuilder.UseFileContext(new FileContextCore.Serializer.XMLSerializer());
55+
56+
//disable indent
57+
optionsBuilder.UseFileContext(new FileContextCore.Serializer.XMLSerializer(false));
58+
```
59+
60+
### CSVSerializer
61+
62+
Serializes data using CsvHelper ([https://joshclose.github.io/CsvHelper/](https://joshclose.github.io/CsvHelper/))
63+
64+
```cs
65+
optionsBuilder.UseFileContext(new FileContextCore.Serializer.CSVSerializer());
66+
67+
//change default delimiter (,)
68+
optionsBuilder.UseFileContext(new FileContextCore.Serializer.CSVSerializer(";"));
69+
```
70+
71+
### JSONSerializer
72+
73+
Serializes data using Newtonsoft Json.NET ([http://www.newtonsoft.com/json](http://www.newtonsoft.com/json))
74+
75+
```cs
76+
optionsBuilder.UseFileContext(new FileContextCore.Serializer.JSONSerializer());
77+
78+
//change formatting
79+
optionsBuilder.UseFileContext(
80+
new FileContextCore.Serializer.JSONSerializer(Newtonsoft.Json.Formatting.None)
81+
);
82+
```
83+
84+
## File Manager
85+
86+
### DefaultFileManager
87+
88+
Saves the data into files
89+
90+
```cs
91+
optionsBuilder.UseFileContext(fileManager: new FileContextCore.FileManager.DefaultFileManager());
92+
```
93+
94+
### EncryptedFileManager
95+
96+
Encrypts the data and saves them into files
97+
98+
```cs
99+
optionsBuilder.UseFileContext(fileManager: new FileContextCore.FileManager.EncryptedFileManager());
100+
101+
//change key
102+
optionsBuilder.UseFileContext(fileManager: new FileContextCore.FileManager.EncryptedFileManager("key"));
103+
```
104+
105+
## Combined Manager
106+
107+
### Excel Manager
108+
109+
Saves files into an .xlsx-file and enables the quick editing of the data using Excel
110+
111+
Uses [EEPlus](http://epplus.codeplex.com/documentation) implementation for .Net Core ([https://github.com/VahidN/EPPlus.Core](https://github.com/VahidN/EPPlus.Core))
112+
113+
```cs
114+
optionsBuilder.UseFileContext(new FileContextCore.CombinedManager.ExcelManager());
115+
116+
//use password
117+
optionsBuilder.UseFileContext(new FileContextCore.CombinedManager.ExcelManager("password"));
118+
```
119+
120+
## Custom implementation
121+
122+
For customization you can implement the Interfaces `ISerializer`, `IFileManager` and `ICombinedManager`
123+
124+
## Author
125+
126+
[Morris Janatzek](http://morrisj.net) ([morrisjdev](https://github.com/morrisjdev))

src/Example/Data/Context.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class Context : DbContext
1616

1717
public DbSet<Setting> Settings { get; set; }
1818

19+
public DbSet<Messurement> Messurements { get; set; }
20+
1921
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
2022
{
2123
//Default: JSON-Serialize
@@ -30,7 +32,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
3032
//CSV
3133
//optionsBuilder.UseFileContext(new FileContextCore.Serializer.CSVSerializer());
3234

33-
//Excel with password
35+
//Excel
3436
optionsBuilder.UseFileContext(new FileContextCore.CombinedManager.ExcelManager());
3537
}
3638

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Example.Data.Entities
6+
{
7+
public class Messurement : Base
8+
{
9+
public TimeSpan TimeRead { get; set; }
10+
11+
public TimeSpan TimeWrite { get; set; }
12+
13+
public int EntryCount { get; set; }
14+
}
15+
}

src/Example/Program.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using Example.Data;
22
using Example.Data.Entities;
33
using Microsoft.EntityFrameworkCore;
4+
using Microsoft.EntityFrameworkCore.Storage;
45
using System;
56
using System.Collections.Generic;
7+
using System.Diagnostics;
68
using System.Linq;
79
using System.Threading.Tasks;
810

@@ -14,15 +16,22 @@ public static void Main(string[] args)
1416
{
1517
Context db = new Context();
1618

17-
//db.Database.EnsureCreated();
19+
Messurement current = new Messurement();
1820

19-
//db.Database.EnsureDeleted();
21+
Stopwatch watch = new Stopwatch();
22+
23+
watch.Start();
2024

2125
List<User> users = db.Users.Include(x => x.Contents).Include(x => x.Settings).ToList();
2226

2327
List<Content> contents = db.Contents.Include(x => x.User).ToList();
2428

25-
IEnumerable<User> test = db.Users;
29+
watch.Stop();
30+
current.TimeRead = watch.Elapsed;
31+
current.EntryCount = users.Count + contents.Count;
32+
Console.WriteLine((users.Count + contents.Count) + " Werte in " + watch.ElapsedMilliseconds + " ms gelesen");
33+
34+
watch.Restart();
2635

2736
User us = new User()
2837
{
@@ -38,15 +47,6 @@ public static void Main(string[] args)
3847
UserId = us.Id
3948
});
4049

41-
db.SaveChanges();
42-
43-
Console.WriteLine(db.Contents.Count());
44-
Console.WriteLine(db.Users.Count());
45-
46-
Context db2 = new Context();
47-
Console.WriteLine(db2.Contents.Count());
48-
Console.WriteLine(db2.Users.Count());
49-
5050
db.Users.Add(new User()
5151
{
5252
Username = "test123",
@@ -67,10 +67,12 @@ public static void Main(string[] args)
6767

6868
db.SaveChanges();
6969

70-
Console.WriteLine(db.Users.Count());
71-
Console.WriteLine(db2.Users.Count());
70+
watch.Stop();
71+
current.TimeWrite = watch.Elapsed;
72+
Console.WriteLine("Werte in " + watch.ElapsedMilliseconds + " ms geschrieben");
7273

73-
Console.ReadKey();
74+
db.Messurements.Add(current);
75+
db.SaveChanges();
7476
}
7577
}
7678
}

src/FileContextCore/CombinedManager/ExcelManager.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using OfficeOpenXml;
1+
using FileContextCore.Helper;
2+
using OfficeOpenXml;
23
using System;
34
using System.Collections;
45
using System.Collections.Generic;
@@ -55,7 +56,14 @@ public IList GetItems(Type t)
5556

5657
foreach(KeyValuePair<int, PropertyInfo> prop in properties)
5758
{
58-
prop.Value.SetValue(item, Convert.ChangeType(ws.Cells[i + 1, prop.Key].Value, prop.Value.PropertyType));
59+
if(prop.Value.PropertyType == typeof(TimeSpan))
60+
{
61+
prop.Value.SetValue(item, TimeSpan.Parse((string)ws.Cells[i + 1, prop.Key].Value));
62+
}
63+
else
64+
{
65+
prop.Value.SetValue(item, Convert.ChangeType(ws.Cells[i + 1, prop.Key].Value, prop.Value.PropertyType));
66+
}
5967
}
6068

6169
result.Add(item);

src/FileContextCore/Extensions/FileContextDbContextOptionsExtensions.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ namespace FileContextCore.Extensions
1414
{
1515
public static class FileContextDbContextOptionsExtensions
1616
{
17-
public static DbContextOptionsBuilder UseFileContext(this DbContextOptionsBuilder optionsBuilder)
18-
{
19-
((IDbContextOptionsBuilderInfrastructure)optionsBuilder).AddOrUpdateExtension(
20-
new FileContextOptionsExtension());
21-
22-
return optionsBuilder;
23-
}
24-
2517
public static DbContextOptionsBuilder UseFileContext(this DbContextOptionsBuilder optionsBuilder, ISerializer serializer = null, IFileManager fileManager = null)
2618
{
2719
((IDbContextOptionsBuilderInfrastructure)optionsBuilder).AddOrUpdateExtension(

src/FileContextCore/FileContextCore.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
<RepositoryUrl>https://github.com/morrisjdev/FileContextCore</RepositoryUrl>
2020
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
2121
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
22-
<Version>1.0.1</Version>
22+
<Version>1.0.2</Version>
2323
<PackageTags>ef, database, file, db, filedb, json, xml, csv, xlsx, excel, dbcontext, entity framework</PackageTags>
24+
<PackageIconUrl>https://morrisj.net/img/morrisjdev_logo.png</PackageIconUrl>
2425
</PropertyGroup>
2526

2627
<ItemGroup>

src/FileContextCore/FileManager/DefaultFileManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using FileContextCore.Helper;
2+
using System;
23
using System.Collections.Generic;
34
using System.IO;
45
using System.Text;

src/FileContextCore/FileManager/EncryptedFileManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using FileContextCore.Helper;
2+
using System;
23
using System.Collections.Generic;
34
using System.IO;
45
using System.Security.Cryptography;

src/FileContextCore/Storage/FileContextCreator.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public FileContextCreator(FileContextCache _cache)
2424

2525
public bool EnsureCreated()
2626
{
27-
return !fileManager.DatabaseExists();
27+
return false;
28+
//return !fileManager.DatabaseExists();
2829
}
2930

3031
public Task<bool> EnsureCreatedAsync(CancellationToken cancellationToken = default(CancellationToken))
@@ -35,7 +36,8 @@ public bool EnsureCreated()
3536
public bool EnsureDeleted()
3637
{
3738
cache.Clear();
38-
return fileManager.Clear();
39+
return true;
40+
//return fileManager.Clear();
3941
}
4042

4143
public Task<bool> EnsureDeletedAsync(CancellationToken cancellationToken = default(CancellationToken))

0 commit comments

Comments
 (0)