@ -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 _d ataHandlerPool ;
private readonly IDataHandlerPool _d ataHandlerPool ;
private string _ path ;
private string _ path ;
private readonly List < ( object entry , FileStream file , string filePath , bool inUse ) > _f iles ;
/// <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 )
{
{
_d ataHandlerPool = dataHandlerPool ;
_d ataHandlerPool = dataHandlerPool ;
_f iles = new List < ( object entry , FileStream file , string filePath , bool inUse ) > ( ) ;
}
}
/// <summary>
/// <summary>
@ -61,12 +65,19 @@ namespace GBase.FileHandling
IDataHandler dataHandler = await _d ataHandlerPool . RequestDataHandler ( this , false , cancellationToken ) ;
IDataHandler dataHandler = await _d ataHandlerPool . RequestDataHandler ( this , false , cancellationToken ) ;
await dataHandler . AddEntry ( entry , table , entryFile , cancellationToken ) ;
await dataHandler . AddEntry ( entry , table , entryFile , cancellationToken ) ;
_f iles . 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 = _f iles . 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 _d ataHandlerPool . RequestDataHandler ( this , false , cancellationToken ) ;
IDataHandler dataHandler = await _d ataHandlerPool . RequestDataHandler ( this , false , cancellationToken ) ;
await dataHandler . SetValue < T , TProperty > ( TODO , propertyName , value , cancellationToken ) ;
await dataHandler . SetValue < T , TProperty > ( TODO , propertyName , value , cancellationToken ) ;