jkpete
2 months ago
8 changed files with 128 additions and 43 deletions
@ -1,15 +0,0 @@
@@ -1,15 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace EGFramework |
||||
{ |
||||
public class EGCsv : EGModule |
||||
{ |
||||
public override void Init() |
||||
{ |
||||
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Linq.Expressions; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace EGFramework |
||||
{ |
||||
public class EGCsvSave : IEGSaveData, IEGSave |
||||
{ |
||||
public void InitSaveFile(string path) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void SetData<TData>(string dataKey, TData data, object id) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
public TData GetData<TData>(string dataKey, object id) where TData : new() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
public IEnumerable<TData> QueryData<TData>(string dataKey, string sql) where TData : new() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public IEnumerable<TData> GetAll<TData>(string dataKey) where TData : new() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public IEnumerable<TData> FindData<TData>(string dataKey, Expression<Func<TData, bool>> expression) where TData : new() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -1,16 +0,0 @@
@@ -1,16 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
using LiteDB; |
||||
|
||||
namespace EGFramework |
||||
{ |
||||
public class EGLiteDB : EGModule |
||||
{ |
||||
public override void Init() |
||||
{ |
||||
// throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using System.Linq.Expressions; |
||||
using System.Threading.Tasks; |
||||
using LiteDB; |
||||
|
||||
namespace EGFramework |
||||
{ |
||||
public class EGLiteDBSave : IEGSave,IEGSaveData |
||||
{ |
||||
private string DefaultPath { set; get; } |
||||
private LiteDatabase _Database { set; get; } |
||||
private LiteDatabase Database{ |
||||
get { |
||||
if(_Database == null){ |
||||
InitSaveFile(DefaultPath); |
||||
} |
||||
return _Database; |
||||
} |
||||
} |
||||
|
||||
public void InitSaveFile(string path) |
||||
{ |
||||
DefaultPath = path; |
||||
if (!Directory.Exists(Path.GetDirectoryName(DefaultPath))) |
||||
{ |
||||
Directory.CreateDirectory(Path.GetDirectoryName(DefaultPath)); |
||||
} |
||||
// Default is "SaveData/DefaultLiteDBData.db" |
||||
_Database = new LiteDatabase(path); |
||||
} |
||||
|
||||
public TData GetData<TData>(string dataKey, object id) where TData : new() |
||||
{ |
||||
LiteCollection<TData> collection = (LiteCollection<TData>)Database.GetCollection<TData>(dataKey); |
||||
TData result = collection.FindById((BsonValue)id); |
||||
return result; |
||||
} |
||||
|
||||
public void SetData<TData>(string dataKey, TData data, object id) |
||||
{ |
||||
LiteCollection<TData> collection = (LiteCollection<TData>)Database.GetCollection<TData>(dataKey); |
||||
if(collection.FindById((BsonValue)id)==null){ |
||||
collection.Insert((BsonValue)id, data); |
||||
} |
||||
collection.Update(data); |
||||
} |
||||
|
||||
public IEnumerable<TData> GetAll<TData>(string dataKey) where TData : new() |
||||
{ |
||||
LiteCollection<TData> collection = (LiteCollection<TData>)Database.GetCollection<TData>(dataKey); |
||||
return collection.FindAll(); |
||||
} |
||||
|
||||
public IEnumerable<TData> FindData<TData>(string dataKey, Expression<Func<TData, bool>> expression) where TData : new() |
||||
{ |
||||
LiteCollection<TData> collection = (LiteCollection<TData>)Database.GetCollection<TData>(dataKey); |
||||
return collection.Find(expression); |
||||
} |
||||
|
||||
public IEnumerable<TData> QueryData<TData>(string dataKey, string sql="") where TData : new() |
||||
{ |
||||
LiteCollection<TData> collection = (LiteCollection<TData>)Database.GetCollection<TData>(dataKey); |
||||
return collection.FindAll(); |
||||
} |
||||
|
||||
|
||||
} |
||||
} |
Loading…
Reference in new issue