diff --git a/GBase.Api/IGBaseObject.cs b/GBase.Api/IGBaseObject.cs
index 67d6483..7319dd8 100644
--- a/GBase.Api/IGBaseObject.cs
+++ b/GBase.Api/IGBaseObject.cs
@@ -11,11 +11,16 @@ namespace GBase.Api
///
public interface IGBaseObject
{
+ ///
+ /// The FileName of the GBase file for an entry of this object
+ ///
+ string FileName { get; }
+
///
/// Initialize this from a given
///
/// The given
- void InitializeFromString(string @string);
+ void InitializeFromString(string @string); //TODO: Try to remove this method, work with keys
void Initialize(List parameters);
}
diff --git a/GBase/FileHandling/FileHandler.cs b/GBase/FileHandling/FileHandler.cs
index 58162dc..17cba08 100644
--- a/GBase/FileHandling/FileHandler.cs
+++ b/GBase/FileHandling/FileHandler.cs
@@ -7,6 +7,7 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+using GBase.Api;
using GBase.FileHandling.Exceptions;
using GBase.Interfaces;
using GBase.Interfaces.FileHandling;
@@ -60,7 +61,7 @@ namespace GBase.FileHandling
return _files;
}
- public IGBaseFile CreateEntryFile(T entry, IGBaseTable table)
+ public IGBaseFile CreateEntryFile(T entry, IGBaseTable table) where T : IGBaseObject //TODO: Use IGBaseObject as T, add method like GetFilename()
{
string directoryPath = Path.Combine(_path, table.FolderName);
@@ -68,7 +69,7 @@ namespace GBase.FileHandling
Directory.CreateDirectory(directoryPath);
//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
IGBaseFile file = _files.FirstOrDefault(f => f.FilePath.Equals(filePath));
diff --git a/GBase/GBaseObject.cs b/GBase/GBaseObject.cs
index 24a355d..57c5401 100644
--- a/GBase/GBaseObject.cs
+++ b/GBase/GBaseObject.cs
@@ -29,6 +29,8 @@ namespace GBase
throw new MissingTableException();
}
+ public abstract string FileName { get; }
+
protected async Task SetValue(T @this, string propertyName, TProperty value, CancellationToken cancellationToken) =>
await _gBaseTable.SetValue(@this, propertyName, value, cancellationToken);
@@ -37,7 +39,7 @@ namespace GBase
protected async Task> GetValues(T @this, string propertyName, CancellationToken cancellationToken) =>
await _gBaseTable.GetValues(@this, propertyName, cancellationToken);
-
+
///
/// Initialize this from a given
///
diff --git a/GBase/Interfaces/FileHandling/IFileHandler.cs b/GBase/Interfaces/FileHandling/IFileHandler.cs
index e0f9497..1c8fb4e 100644
--- a/GBase/Interfaces/FileHandling/IFileHandler.cs
+++ b/GBase/Interfaces/FileHandling/IFileHandler.cs
@@ -6,6 +6,7 @@ using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
+using GBase.Api;
namespace GBase.Interfaces.FileHandling
{
@@ -23,7 +24,7 @@ namespace GBase.Interfaces.FileHandling
/// True if successful, false if not
List Init(string path, string folderName, CancellationToken cancellationToken);
- IGBaseFile CreateEntryFile(T entry, IGBaseTable table);
+ IGBaseFile CreateEntryFile(T entry, IGBaseTable table) where T : IGBaseObject;
Task DeleteEntryFile(T entry);
diff --git a/Test.GBase/GBaseIntegrationTest/Group.cs b/Test.GBase/GBaseIntegrationTest/Group.cs
index 0976ea5..97c7908 100644
--- a/Test.GBase/GBaseIntegrationTest/Group.cs
+++ b/Test.GBase/GBaseIntegrationTest/Group.cs
@@ -24,6 +24,7 @@ namespace Test.GBase.GBaseIntegrationTest
[GBaseColumn]
public int Key { get; private set; }
public List Items { get; }
+ public string FileName => $"Group{Key}";
public override string ToString() => $"{Key}";
public void InitializeFromString(string @string) => Key = int.Parse(@string);
diff --git a/Test.GBase/GBaseIntegrationTest/Item.cs b/Test.GBase/GBaseIntegrationTest/Item.cs
index 44e38f5..19ccdf3 100644
--- a/Test.GBase/GBaseIntegrationTest/Item.cs
+++ b/Test.GBase/GBaseIntegrationTest/Item.cs
@@ -26,8 +26,9 @@ namespace Test.GBase.GBaseIntegrationTest
[GBaseColumn]
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)
{
diff --git a/Test.GBase/TestClasses/Foo.cs b/Test.GBase/TestClasses/Foo.cs
index 9213c15..1ebc020 100644
--- a/Test.GBase/TestClasses/Foo.cs
+++ b/Test.GBase/TestClasses/Foo.cs
@@ -35,6 +35,8 @@ namespace Test.GBase.TestClasses
}
}
+ public string FileName => Name;
+
public void InitializeFromString(string @string)
{
throw new NotImplementedException();
diff --git a/Test.GBase/TestClasses/UserType.cs b/Test.GBase/TestClasses/UserType.cs
index 53cf071..f5173c2 100644
--- a/Test.GBase/TestClasses/UserType.cs
+++ b/Test.GBase/TestClasses/UserType.cs
@@ -22,6 +22,8 @@ namespace Test.GBase.TestClasses
private int Number { get; set; }
+ public string FileName { get; }
+
public void InitializeFromString(string @string)
{
string numberString = @string.Split('_').Last();