|
|
|
@ -12,6 +12,7 @@ using GBase.Api; |
|
|
|
using GBase.Attributes; |
|
|
|
using GBase.Attributes; |
|
|
|
using GBase.Factories; |
|
|
|
using GBase.Factories; |
|
|
|
using GBase.FileHandling.Factories; |
|
|
|
using GBase.FileHandling.Factories; |
|
|
|
|
|
|
|
using GBase.Helpers; |
|
|
|
using GBase.Interfaces; |
|
|
|
using GBase.Interfaces; |
|
|
|
using GBase.Interfaces.DataHandling; |
|
|
|
using GBase.Interfaces.DataHandling; |
|
|
|
using GBase.Interfaces.DataHandling.Pool; |
|
|
|
using GBase.Interfaces.DataHandling.Pool; |
|
|
|
@ -22,7 +23,7 @@ namespace GBase |
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// A <see cref="IGBase"/> table |
|
|
|
/// A <see cref="IGBase"/> table |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
public class GBaseTable<T> : IGBaseTable<T> |
|
|
|
public class GBaseTable<T> : IGBaseTable<T> where T : IGBaseObject, new() |
|
|
|
{ |
|
|
|
{ |
|
|
|
private readonly IFileHandler _fileHandler; |
|
|
|
private readonly IFileHandler _fileHandler; |
|
|
|
private readonly IDataHandlerPool _dataHandlerPool; |
|
|
|
private readonly IDataHandlerPool _dataHandlerPool; |
|
|
|
@ -74,11 +75,10 @@ namespace GBase |
|
|
|
/// <param name="folderName"></param> |
|
|
|
/// <param name="folderName"></param> |
|
|
|
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to cancel the asynchronous operation</param> |
|
|
|
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to cancel the asynchronous operation</param> |
|
|
|
/// <returns>True if successful, false if not</returns> |
|
|
|
/// <returns>True if successful, false if not</returns> |
|
|
|
public async Task<bool> Init(Type type, string databasePath, string folderName, CancellationToken cancellationToken) |
|
|
|
public async Task<bool> Init(Type type, string databasePath, string folderName, CancellationToken cancellationToken) //TODO: Remove bool return value? |
|
|
|
{ |
|
|
|
{ |
|
|
|
Type = type; |
|
|
|
Type = type; |
|
|
|
FolderName = folderName; |
|
|
|
FolderName = folderName; |
|
|
|
await _fileHandler.Init(databasePath, cancellationToken); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: Init columns list depending on GBaseColumnAttributes set for this GBaseTable |
|
|
|
//TODO: Init columns list depending on GBaseColumnAttributes set for this GBaseTable |
|
|
|
foreach (var property in type.GetProperties()) |
|
|
|
foreach (var property in type.GetProperties()) |
|
|
|
@ -87,10 +87,39 @@ namespace GBase |
|
|
|
if (gBaseColumnAttribute == null) |
|
|
|
if (gBaseColumnAttribute == null) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
IGBaseColumn gBaseColumn = _gBaseColumnFactory.Create(property.Name); |
|
|
|
IGBaseColumn gBaseColumn = _gBaseColumnFactory.Create(property.Name, property.PropertyType); |
|
|
|
AddColumn(gBaseColumn); |
|
|
|
AddColumn(gBaseColumn); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<IGBaseFile> files = _fileHandler.Init(databasePath, FolderName, cancellationToken); |
|
|
|
|
|
|
|
if (files == null) |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var file in files) //create entries for existing files |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
using (file.UseFile()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
T entry = new T(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<object> parameters = new List<object>(); |
|
|
|
|
|
|
|
foreach (var column in Columns) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parameters.Add(await GenericMethodCaller.CallAsync(dataHandler, |
|
|
|
|
|
|
|
nameof(IDataHandler.GetValue), |
|
|
|
|
|
|
|
BindingFlags.Public | BindingFlags.Instance, |
|
|
|
|
|
|
|
typeof(T), column.Type, |
|
|
|
|
|
|
|
file.File, column.Name, cancellationToken)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
entry.Initialize(parameters); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file.Entry = entry; |
|
|
|
|
|
|
|
Entries.Add(entry); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -156,21 +185,21 @@ namespace GBase |
|
|
|
public async Task SetValue<TProperty>(T entry, string propertyName, TProperty value, CancellationToken cancellationToken) |
|
|
|
public async Task SetValue<TProperty>(T entry, string propertyName, TProperty value, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
{ |
|
|
|
using IGBaseFile file = await _fileHandler.RequestEntryFile(entry); |
|
|
|
using IGBaseFile file = await _fileHandler.RequestEntryFile(entry); |
|
|
|
IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, CancellationToken.None); |
|
|
|
IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken); |
|
|
|
await dataHandler.SetValue<T, TProperty>(file.File, propertyName, value, cancellationToken); |
|
|
|
await dataHandler.SetValue<T, TProperty>(file.File, propertyName, value, cancellationToken); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task<TProperty> GetValue<TProperty>(T entry, string propertyName, CancellationToken cancellationToken) |
|
|
|
public async Task<TProperty> GetValue<TProperty>(T entry, string propertyName, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
{ |
|
|
|
using IGBaseFile file = await _fileHandler.RequestEntryFile(entry); |
|
|
|
using IGBaseFile file = await _fileHandler.RequestEntryFile(entry); |
|
|
|
IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, CancellationToken.None); |
|
|
|
IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken); |
|
|
|
return await dataHandler.GetValue<T, TProperty>(file.File, propertyName, cancellationToken); |
|
|
|
return await dataHandler.GetValue<T, TProperty>(file.File, propertyName, cancellationToken); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<TProperty>> GetValues<TProperty>(T entry, string propertyName, CancellationToken cancellationToken) |
|
|
|
public async Task<IEnumerable<TProperty>> GetValues<TProperty>(T entry, string propertyName, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
{ |
|
|
|
using IGBaseFile file = await _fileHandler.RequestEntryFile(entry); |
|
|
|
using IGBaseFile file = await _fileHandler.RequestEntryFile(entry); |
|
|
|
IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, CancellationToken.None); |
|
|
|
IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken); |
|
|
|
return await dataHandler.GetValues<T, TProperty>(file.File, propertyName, cancellationToken); |
|
|
|
return await dataHandler.GetValues<T, TProperty>(file.File, propertyName, cancellationToken); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|