diff --git a/GBase/FileHandling/FileHandler.cs b/GBase/FileHandling/FileHandler.cs index cbc1952..dcc9103 100644 --- a/GBase/FileHandling/FileHandler.cs +++ b/GBase/FileHandling/FileHandler.cs @@ -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 /// public class FileHandler : IFileHandler { - private readonly IXmlDataHandlerFactory _dataHandlerFactory; + private readonly IDataHandlerPool _dataHandlerPool; /// /// Internal file handler /// - /// Factory for the - public FileHandler(IXmlDataHandlerFactory xmlDataHandlerFactory) + /// The + public FileHandler(IDataHandlerPool dataHandlerPool) { - _dataHandlerFactory = xmlDataHandlerFactory; + _dataHandlerPool = dataHandlerPool; } - /// - /// The of this - /// - private IDataHandler DataHandler { get; set; } - /// /// Initialize this /// @@ -43,10 +37,7 @@ namespace GBase.FileHandling /// True if successful, false if not public async Task 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 entry, IGBaseTable table) @@ -68,10 +59,12 @@ namespace GBase.FileHandling /// The of the property /// The name of the property /// The value to set + /// /// A to await - public async Task SetValue(string propertyName, TProperty value) + public async Task SetValue(string propertyName, TProperty value, CancellationToken cancellationToken) { - await DataHandler.SetValue(propertyName, value); + IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken); + await dataHandler.SetValue(propertyName, value); } /// @@ -81,10 +74,12 @@ namespace GBase.FileHandling /// The of the property /// The name of the property /// The value to set + /// /// A to await - public async Task RemoveValue(string propertyName, TProperty value) + public async Task RemoveValue(string propertyName, TProperty value, CancellationToken cancellationToken) { - await DataHandler.RemoveValue(propertyName, value); + IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken); + await dataHandler.RemoveValue(propertyName, value); } /// @@ -93,10 +88,12 @@ namespace GBase.FileHandling /// The of the property /// The of the property /// The name of the property + /// /// The value for the given property - public async Task GetValue(string propertyName) + public async Task GetValue(string propertyName, CancellationToken cancellationToken) { - return await DataHandler.GetValue(propertyName); + IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken); + return await dataHandler.GetValue(propertyName); } /// @@ -105,19 +102,18 @@ namespace GBase.FileHandling /// The of the property /// The of the property /// The name of the property + /// /// An with all the values for the property - public async Task> GetValues(string propertyName) + public async Task> GetValues(string propertyName, CancellationToken cancellationToken) { - return await DataHandler.GetValues(propertyName); + IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken); + return await dataHandler.GetValues(propertyName); } /// /// Dispose used resources asynchronously /// /// A to await - public async ValueTask DisposeAsync() - { - await DataHandler.DisposeAsync(); - } + public async ValueTask DisposeAsync() => await _dataHandlerPool.DisposeAsync(); } } \ No newline at end of file diff --git a/GBase/Interfaces/FileHandling/IFileHandler.cs b/GBase/Interfaces/FileHandling/IFileHandler.cs index ae3eb99..31a8b86 100644 --- a/GBase/Interfaces/FileHandling/IFileHandler.cs +++ b/GBase/Interfaces/FileHandling/IFileHandler.cs @@ -33,8 +33,9 @@ namespace GBase.Interfaces.FileHandling /// The of the property /// The name of the property /// The value to set + /// /// A to await - Task SetValue(string propertyName, TProperty value); + Task SetValue(string propertyName, TProperty value, CancellationToken cancellationToken); /// /// Remove the value for the given property @@ -43,8 +44,9 @@ namespace GBase.Interfaces.FileHandling /// The of the property /// The name of the property /// The value to set + /// /// A to await - Task RemoveValue(string propertyName, TProperty value); + Task RemoveValue(string propertyName, TProperty value, CancellationToken cancellationToken); /// /// Get the value for the given property, if multiple values are set the first is returned @@ -52,8 +54,9 @@ namespace GBase.Interfaces.FileHandling /// The of the property /// The of the property /// The name of the property + /// /// The value for the given property - Task GetValue(string propertyName); + Task GetValue(string propertyName, CancellationToken cancellationToken); /// /// Get all the values that are set for the given property @@ -61,7 +64,8 @@ namespace GBase.Interfaces.FileHandling /// The of the property /// The of the property /// The name of the property + /// /// An with all the values for the property - Task> GetValues(string propertyName); + Task> GetValues(string propertyName, CancellationToken cancellationToken); } } \ No newline at end of file