#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;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using GBase.Interfaces; using GBase.Interfaces;
@ -17,7 +18,7 @@ namespace GBase.FileHandling
/// <summary> /// <summary>
/// Internal file handler /// Internal file handler
/// </summary> /// </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> /// <summary>
/// The file extension for all GBase tables /// The file extension for all GBase tables
@ -27,6 +28,8 @@ namespace GBase.FileHandling
private readonly IDataHandlerPool _dataHandlerPool; private readonly IDataHandlerPool _dataHandlerPool;
private string _path; private string _path;
private readonly List<(object entry, FileStream file, string filePath, bool inUse)> _files;
/// <summary> /// <summary>
/// Internal file handler /// Internal file handler
/// </summary> /// </summary>
@ -34,6 +37,7 @@ namespace GBase.FileHandling
public FileHandler(IDataHandlerPool dataHandlerPool) public FileHandler(IDataHandlerPool dataHandlerPool)
{ {
_dataHandlerPool = dataHandlerPool; _dataHandlerPool = dataHandlerPool;
_files = new List<(object entry, FileStream file, string filePath, bool inUse)>();
} }
/// <summary> /// <summary>
@ -61,12 +65,19 @@ namespace GBase.FileHandling
IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken); IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken);
await dataHandler.AddEntry(entry, table, entryFile, 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 var file = _files.FirstOrDefault(f => f.entry.Equals(entry));
throw new NotImplementedException(); if (file == default)
return false;
await file.file.DisposeAsync();
File.Delete(file.filePath);
return true;
} }
/// <summary> /// <summary>
@ -74,11 +85,12 @@ namespace GBase.FileHandling
/// </summary> /// </summary>
/// <typeparam name="T">The <see cref="Type"/> of the property</typeparam> /// <typeparam name="T">The <see cref="Type"/> of the property</typeparam>
/// <typeparam name="TProperty">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="propertyName">The name of the property</param>
/// <param name="value">The value to set</param> /// <param name="value">The value to set</param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns>A <see cref="Task"/> to await</returns> /// <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); IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken);
await dataHandler.SetValue<T, TProperty>(TODO, propertyName, value, cancellationToken); await dataHandler.SetValue<T, TProperty>(TODO, propertyName, value, cancellationToken);

@ -31,11 +31,12 @@ namespace GBase.Interfaces.FileHandling
/// </summary> /// </summary>
/// <typeparam name="T">The <see cref="Type"/> of the property</typeparam> /// <typeparam name="T">The <see cref="Type"/> of the property</typeparam>
/// <typeparam name="TProperty">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="propertyName">The name of the property</param>
/// <param name="value">The value to set</param> /// <param name="value">The value to set</param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns>A <see cref="Task"/> to await</returns> /// <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> /// <summary>
/// Remove the value for the given property /// Remove the value for the given property

Loading…
Cancel
Save