|
|
|
|
@ -6,10 +6,9 @@ using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Threading; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
using GBase.DataHandling.Factories; |
|
|
|
|
using GBase.Interfaces; |
|
|
|
|
using GBase.Interfaces.DataHandling; |
|
|
|
|
using GBase.Interfaces.DataHandling.Xml; |
|
|
|
|
using GBase.Interfaces.DataHandling.Pool; |
|
|
|
|
using GBase.Interfaces.FileHandling; |
|
|
|
|
|
|
|
|
|
namespace GBase.FileHandling |
|
|
|
|
@ -19,22 +18,17 @@ namespace GBase.FileHandling |
|
|
|
|
/// </summary> |
|
|
|
|
public class FileHandler : IFileHandler |
|
|
|
|
{ |
|
|
|
|
private readonly IXmlDataHandlerFactory _dataHandlerFactory; |
|
|
|
|
private readonly IDataHandlerPool _dataHandlerPool; |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Internal file handler |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="xmlDataHandlerFactory">Factory for the <see cref="IXmlDataHandler"/></param> |
|
|
|
|
public FileHandler(IXmlDataHandlerFactory xmlDataHandlerFactory) |
|
|
|
|
/// <param name="dataHandlerPool">The <see cref="IDataHandlerPool"/></param> |
|
|
|
|
public FileHandler(IDataHandlerPool dataHandlerPool) |
|
|
|
|
{ |
|
|
|
|
_dataHandlerFactory = xmlDataHandlerFactory; |
|
|
|
|
_dataHandlerPool = dataHandlerPool; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// The <see cref="IDataHandler"/> of this <see cref="IFileHandler"/> |
|
|
|
|
/// </summary> |
|
|
|
|
private IDataHandler DataHandler { get; set; } |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Initialize this <see cref="IFileHandler"/> |
|
|
|
|
/// </summary> |
|
|
|
|
@ -43,10 +37,7 @@ namespace GBase.FileHandling |
|
|
|
|
/// <returns>True if successful, false if not</returns> |
|
|
|
|
public async Task<bool> Init(string path, CancellationToken cancellationToken) |
|
|
|
|
{ |
|
|
|
|
DataHandler = _dataHandlerFactory.Create(); //FixMe: Factory is missing parameters |
|
|
|
|
|
|
|
|
|
bool success = await DataHandler.Init(false, cancellationToken); |
|
|
|
|
return success; |
|
|
|
|
return true; //TODO: is there anything that needs to be initialized here? |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Task AddEntry<T>(T entry, IGBaseTable table) |
|
|
|
|
@ -68,10 +59,12 @@ namespace GBase.FileHandling |
|
|
|
|
/// <typeparam name="TProperty">The <see cref="Type"/> of the property</typeparam> |
|
|
|
|
/// <param name="propertyName">The name of the property</param> |
|
|
|
|
/// <param name="value">The value to set</param> |
|
|
|
|
/// <param name="cancellationToken"></param> |
|
|
|
|
/// <returns>A <see cref="Task"/> to await</returns> |
|
|
|
|
public async Task SetValue<T, TProperty>(string propertyName, TProperty value) |
|
|
|
|
public async Task SetValue<T, TProperty>(string propertyName, TProperty value, CancellationToken cancellationToken) |
|
|
|
|
{ |
|
|
|
|
await DataHandler.SetValue<T, TProperty>(propertyName, value); |
|
|
|
|
IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken); |
|
|
|
|
await dataHandler.SetValue<T, TProperty>(propertyName, value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
@ -81,10 +74,12 @@ namespace GBase.FileHandling |
|
|
|
|
/// <typeparam name="TProperty">The <see cref="Type"/> of the property</typeparam> |
|
|
|
|
/// <param name="propertyName">The name of the property</param> |
|
|
|
|
/// <param name="value">The value to set</param> |
|
|
|
|
/// <param name="cancellationToken"></param> |
|
|
|
|
/// <returns>A <see cref="Task"/> to await</returns> |
|
|
|
|
public async Task RemoveValue<T, TProperty>(string propertyName, TProperty value) |
|
|
|
|
public async Task RemoveValue<T, TProperty>(string propertyName, TProperty value, CancellationToken cancellationToken) |
|
|
|
|
{ |
|
|
|
|
await DataHandler.RemoveValue<T, TProperty>(propertyName, value); |
|
|
|
|
IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken); |
|
|
|
|
await dataHandler.RemoveValue<T, TProperty>(propertyName, value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
@ -93,10 +88,12 @@ namespace GBase.FileHandling |
|
|
|
|
/// <typeparam name="T">The <see cref="Type"/> of the property</typeparam> |
|
|
|
|
/// <typeparam name="TProperty">The <see cref="Type"/> of the property</typeparam> |
|
|
|
|
/// <param name="propertyName">The name of the property</param> |
|
|
|
|
/// <param name="cancellationToken"></param> |
|
|
|
|
/// <returns>The value for the given property</returns> |
|
|
|
|
public async Task<TProperty> GetValue<T, TProperty>(string propertyName) |
|
|
|
|
public async Task<TProperty> GetValue<T, TProperty>(string propertyName, CancellationToken cancellationToken) |
|
|
|
|
{ |
|
|
|
|
return await DataHandler.GetValue<T, TProperty>(propertyName); |
|
|
|
|
IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken); |
|
|
|
|
return await dataHandler.GetValue<T, TProperty>(propertyName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
@ -105,19 +102,18 @@ namespace GBase.FileHandling |
|
|
|
|
/// <typeparam name="T">The <see cref="Type"/> of the property</typeparam> |
|
|
|
|
/// <typeparam name="TProperty">The <see cref="Type"/> of the property</typeparam> |
|
|
|
|
/// <param name="propertyName">The name of the property</param> |
|
|
|
|
/// <param name="cancellationToken"></param> |
|
|
|
|
/// <returns>An <see cref="IEnumerable{T}"/> with all the values for the property</returns> |
|
|
|
|
public async Task<IEnumerable<TProperty>> GetValues<T, TProperty>(string propertyName) |
|
|
|
|
public async Task<IEnumerable<TProperty>> GetValues<T, TProperty>(string propertyName, CancellationToken cancellationToken) |
|
|
|
|
{ |
|
|
|
|
return await DataHandler.GetValues<T, TProperty>(propertyName); |
|
|
|
|
IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken); |
|
|
|
|
return await dataHandler.GetValues<T, TProperty>(propertyName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Dispose used resources asynchronously |
|
|
|
|
/// </summary> |
|
|
|
|
/// <returns>A <see cref="ValueTask"/> to await</returns> |
|
|
|
|
public async ValueTask DisposeAsync() |
|
|
|
|
{ |
|
|
|
|
await DataHandler.DisposeAsync(); |
|
|
|
|
} |
|
|
|
|
public async ValueTask DisposeAsync() => await _dataHandlerPool.DisposeAsync(); |
|
|
|
|
} |
|
|
|
|
} |