- introduce FileName property to IGBaseObject that returns the file name of an entry

master
Simon G 5 years ago
parent 1b0610c514
commit af2a5768e7
  1. 7
      GBase.Api/IGBaseObject.cs
  2. 5
      GBase/FileHandling/FileHandler.cs
  3. 4
      GBase/GBaseObject.cs
  4. 3
      GBase/Interfaces/FileHandling/IFileHandler.cs
  5. 1
      Test.GBase/GBaseIntegrationTest/Group.cs
  6. 3
      Test.GBase/GBaseIntegrationTest/Item.cs
  7. 2
      Test.GBase/TestClasses/Foo.cs
  8. 2
      Test.GBase/TestClasses/UserType.cs

@ -11,11 +11,16 @@ namespace GBase.Api
/// </summary> /// </summary>
public interface IGBaseObject public interface IGBaseObject
{ {
/// <summary>
/// The FileName of the GBase file for an entry of this object
/// </summary>
string FileName { get; }
/// <summary> /// <summary>
/// Initialize this <see cref="IGBaseObject"/> from a given <see cref="string"/> /// Initialize this <see cref="IGBaseObject"/> from a given <see cref="string"/>
/// </summary> /// </summary>
/// <param name="string">The given <see cref="string"/></param> /// <param name="string">The given <see cref="string"/></param>
void InitializeFromString(string @string); void InitializeFromString(string @string); //TODO: Try to remove this method, work with keys
void Initialize(List<object> parameters); void Initialize(List<object> parameters);
} }

@ -7,6 +7,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using GBase.Api;
using GBase.FileHandling.Exceptions; using GBase.FileHandling.Exceptions;
using GBase.Interfaces; using GBase.Interfaces;
using GBase.Interfaces.FileHandling; using GBase.Interfaces.FileHandling;
@ -60,7 +61,7 @@ namespace GBase.FileHandling
return _files; return _files;
} }
public IGBaseFile CreateEntryFile<T>(T entry, IGBaseTable table) public IGBaseFile CreateEntryFile<T>(T entry, IGBaseTable table) where T : IGBaseObject //TODO: Use IGBaseObject as T, add method like GetFilename()
{ {
string directoryPath = Path.Combine(_path, table.FolderName); string directoryPath = Path.Combine(_path, table.FolderName);
@ -68,7 +69,7 @@ namespace GBase.FileHandling
Directory.CreateDirectory(directoryPath); Directory.CreateDirectory(directoryPath);
//create new entry file //create new entry file
string filePath = $"{Path.Combine(directoryPath, entry.ToString())}.{GBASE_TABLE_FILE_EXTENSION}"; string filePath = $"{Path.Combine(directoryPath, entry.FileName)}.{GBASE_TABLE_FILE_EXTENSION}";
//check if file is already opened //check if file is already opened
IGBaseFile file = _files.FirstOrDefault(f => f.FilePath.Equals(filePath)); IGBaseFile file = _files.FirstOrDefault(f => f.FilePath.Equals(filePath));

@ -29,6 +29,8 @@ namespace GBase
throw new MissingTableException<T>(); throw new MissingTableException<T>();
} }
public abstract string FileName { get; }
protected async Task SetValue<TProperty>(T @this, string propertyName, TProperty value, CancellationToken cancellationToken) => protected async Task SetValue<TProperty>(T @this, string propertyName, TProperty value, CancellationToken cancellationToken) =>
await _gBaseTable.SetValue(@this, propertyName, value, cancellationToken); await _gBaseTable.SetValue(@this, propertyName, value, cancellationToken);
@ -37,7 +39,7 @@ namespace GBase
protected async Task<IEnumerable<TProperty>> GetValues<TProperty>(T @this, string propertyName, CancellationToken cancellationToken) => protected async Task<IEnumerable<TProperty>> GetValues<TProperty>(T @this, string propertyName, CancellationToken cancellationToken) =>
await _gBaseTable.GetValues<TProperty>(@this, propertyName, cancellationToken); await _gBaseTable.GetValues<TProperty>(@this, propertyName, cancellationToken);
/// <summary> /// <summary>
/// Initialize this <see cref="GBaseObject{T}"/> from a given <see cref="string"/> /// Initialize this <see cref="GBaseObject{T}"/> from a given <see cref="string"/>
/// </summary> /// </summary>

@ -6,6 +6,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using GBase.Api;
namespace GBase.Interfaces.FileHandling namespace GBase.Interfaces.FileHandling
{ {
@ -23,7 +24,7 @@ namespace GBase.Interfaces.FileHandling
/// <returns>True if successful, false if not</returns> /// <returns>True if successful, false if not</returns>
List<IGBaseFile> Init(string path, string folderName, CancellationToken cancellationToken); List<IGBaseFile> Init(string path, string folderName, CancellationToken cancellationToken);
IGBaseFile CreateEntryFile<T>(T entry, IGBaseTable table); IGBaseFile CreateEntryFile<T>(T entry, IGBaseTable table) where T : IGBaseObject;
Task<bool> DeleteEntryFile<T>(T entry); Task<bool> DeleteEntryFile<T>(T entry);

@ -24,6 +24,7 @@ namespace Test.GBase.GBaseIntegrationTest
[GBaseColumn] [GBaseColumn]
public int Key { get; private set; } public int Key { get; private set; }
public List<IItem> Items { get; } public List<IItem> Items { get; }
public string FileName => $"Group{Key}";
public override string ToString() => $"{Key}"; public override string ToString() => $"{Key}";
public void InitializeFromString(string @string) => Key = int.Parse(@string); public void InitializeFromString(string @string) => Key = int.Parse(@string);

@ -26,8 +26,9 @@ namespace Test.GBase.GBaseIntegrationTest
[GBaseColumn] [GBaseColumn]
public int Key { get; private set; } public int Key { get; private set; }
public string FileName => Name;
public override string ToString() => $"{Name}"; public override string ToString() => $"{Key}/{Name}";
public void InitializeFromString(string @string) public void InitializeFromString(string @string)
{ {

@ -35,6 +35,8 @@ namespace Test.GBase.TestClasses
} }
} }
public string FileName => Name;
public void InitializeFromString(string @string) public void InitializeFromString(string @string)
{ {
throw new NotImplementedException(); throw new NotImplementedException();

@ -22,6 +22,8 @@ namespace Test.GBase.TestClasses
private int Number { get; set; } private int Number { get; set; }
public string FileName { get; }
public void InitializeFromString(string @string) public void InitializeFromString(string @string)
{ {
string numberString = @string.Split('_').Last(); string numberString = @string.Split('_').Last();

Loading…
Cancel
Save