#25: start adapting FileHandler, add todo for possibly a better usage

pull/27/head
Simon G 5 years ago
parent 1cfa80c199
commit c446babb05
  1. 22
      GBase/FileHandling/FileHandler.cs
  2. 3
      GBase/Interfaces/FileHandling/IFileHandler.cs

@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using GBase.Interfaces;
@ -17,7 +18,7 @@ namespace GBase.FileHandling
/// <summary>
/// Internal file handler
/// </summary>
public class FileHandler : IFileHandler
public class FileHandler : IFileHandler //TODO: Don't let file handler call data handler, have them parallel and have file handler only handle the files. this also makes more sense with the dataHandlerPool
{
/// <summary>
/// The file extension for all GBase tables
@ -27,6 +28,8 @@ namespace GBase.FileHandling
private readonly IDataHandlerPool _dataHandlerPool;
private string _path;
private readonly List<(object entry, FileStream file, string filePath, bool inUse)> _files;
/// <summary>
/// Internal file handler
/// </summary>
@ -34,6 +37,7 @@ namespace GBase.FileHandling
public FileHandler(IDataHandlerPool dataHandlerPool)
{
_dataHandlerPool = dataHandlerPool;
_files = new List<(object entry, FileStream file, string filePath, bool inUse)>();
}
/// <summary>
@ -61,12 +65,19 @@ namespace GBase.FileHandling
IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken);
await dataHandler.AddEntry(entry, table, entryFile, cancellationToken);
_files.Add((entry, entryFile, filePath, false));
}
public Task<bool> RemoveEntry<T>(T entry)
public async Task<bool> RemoveEntry<T>(T entry)
{
//remove entry file
throw new NotImplementedException();
var file = _files.FirstOrDefault(f => f.entry.Equals(entry));
if (file == default)
return false;
await file.file.DisposeAsync();
File.Delete(file.filePath);
return true;
}
/// <summary>
@ -74,11 +85,12 @@ namespace GBase.FileHandling
/// </summary>
/// <typeparam name="T">The <see cref="Type"/> of the property</typeparam>
/// <typeparam name="TProperty">The <see cref="Type"/> of the property</typeparam>
/// <param name="entry"></param>
/// <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, CancellationToken cancellationToken)
public async Task SetValue<T, TProperty>(T entry, string propertyName, TProperty value, CancellationToken cancellationToken)
{
IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken);
await dataHandler.SetValue<T, TProperty>(TODO, propertyName, value, cancellationToken);

@ -31,11 +31,12 @@ namespace GBase.Interfaces.FileHandling
/// </summary>
/// <typeparam name="T">The <see cref="Type"/> of the property</typeparam>
/// <typeparam name="TProperty">The <see cref="Type"/> of the property</typeparam>
/// <param name="entry"></param>
/// <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>
Task SetValue<T, TProperty>(string propertyName, TProperty value, CancellationToken cancellationToken);
Task SetValue<T, TProperty>(T entry, string propertyName, TProperty value, CancellationToken cancellationToken);
/// <summary>
/// Remove the value for the given property

Loading…
Cancel
Save