From 614ad24b5c359870716ff1cdafec7d8220b5f454 Mon Sep 17 00:00:00 2001 From: Simon G Date: Fri, 13 Nov 2020 13:17:34 +0100 Subject: [PATCH 01/12] - add GenericMethodCaller and matching exception --- .../GenericMethodNotFoundException.cs | 24 ++++ GBase/Helpers/GenericMethodCaller.cs | 108 ++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 GBase/Exceptions/GenericMethodNotFoundException.cs create mode 100644 GBase/Helpers/GenericMethodCaller.cs diff --git a/GBase/Exceptions/GenericMethodNotFoundException.cs b/GBase/Exceptions/GenericMethodNotFoundException.cs new file mode 100644 index 0000000..45f6658 --- /dev/null +++ b/GBase/Exceptions/GenericMethodNotFoundException.cs @@ -0,0 +1,24 @@ +// Author: Gockner, Simon +// Created: 2020-11-13 +// Copyright(c) 2020 SimonG. All Rights Reserved. + +using System; + +namespace GBase.Exceptions +{ + /// + /// Could not find generic method + /// + internal class GenericMethodNotFoundException : Exception + { + /// + /// Could not find generic method + /// + /// The name of the generic method + public GenericMethodNotFoundException(string functionName) + : base($"Could not find function {functionName}") + { + + } + } +} \ No newline at end of file diff --git a/GBase/Helpers/GenericMethodCaller.cs b/GBase/Helpers/GenericMethodCaller.cs new file mode 100644 index 0000000..9ac3ed5 --- /dev/null +++ b/GBase/Helpers/GenericMethodCaller.cs @@ -0,0 +1,108 @@ +// Author: Gockner, Simon +// Created: 2020-11-13 +// Copyright(c) 2020 SimonG. All Rights Reserved. + +using System; +using System.Reflection; +using System.Threading.Tasks; +using GBase.Exceptions; + +namespace GBase.Helpers +{ + internal static class GenericMethodCaller + { + /// + /// Call a generic method without generic type parameters + /// + /// The caller of the method + /// The name of the method to call + /// The to find the method + /// The generic parameter as parameter + /// The parameters of the method + /// The result of invoking the method + /// Could not find the generic method + /// Any thrown after invoking the generic method + public static object Call(object caller, string functionName, BindingFlags bindingFlags, Type genericParameter, params object[] parameters) => + GetGenericMethod(caller, functionName, bindingFlags, genericParameter).InvokeGenericMethod(caller, parameters); + + /// + /// Call a generic method without generic type parameters + /// + /// The caller of the method + /// The name of the method to call + /// The to find the method + /// The generic parameter as parameter + /// + /// The parameters of the method + /// The result of invoking the method + /// Could not find the generic method + /// Any thrown after invoking the generic method + public static object Call(object caller, string functionName, BindingFlags bindingFlags, Type genericParameter, Type secondGenericParameter,params object[] parameters) => + GetGenericMethod(caller, functionName, bindingFlags, genericParameter, secondGenericParameter).InvokeGenericMethod(caller, parameters); + + /// + /// Call a generic method asynchronously without generic type parameters + /// + /// The caller of the method + /// The name of the method to call + /// The to find the method + /// The generic parameter as parameter + /// The parameters of the method + /// The result of invoking the method + /// Could not find the generic method + /// Any thrown after invoking the generic method + public static async Task CallAsync(object caller, string functionName, BindingFlags bindingFlags, Type genericParameter, params object[] parameters) => + await GetGenericMethod(caller, functionName, bindingFlags, genericParameter).InvokeGenericMethodAsync(caller, parameters); + + /// + /// Call a generic method asynchronously without generic type parameters + /// + /// The caller of the method + /// The name of the method to call + /// The to find the method + /// The generic parameter as parameter + /// + /// The parameters of the method + /// The result of invoking the method + /// Could not find the generic method + /// Any thrown after invoking the generic method + public static async Task CallAsync(object caller, string functionName, BindingFlags bindingFlags, Type genericParameter, Type secondGenericParameter, params object[] parameters) => + await GetGenericMethod(caller, functionName, bindingFlags, genericParameter, secondGenericParameter).InvokeGenericMethodAsync(caller, parameters); + + private static MethodInfo GetGenericMethod(object caller, string functionName, BindingFlags bindingFlags, params Type[] genericParameters) + { + MethodInfo genericMethod = caller.GetType().GetMethod(functionName, bindingFlags)?.MakeGenericMethod(genericParameters); + + if (genericMethod == null) + throw new GenericMethodNotFoundException(functionName); + + return genericMethod; + } + + private static object InvokeGenericMethod(this MethodInfo genericMethod, object caller, params object[] parameters) + { + try //exceptions thrown by methods called with invoke are wrapped into another exception, the exception thrown by the invoked method can be returned by `Exception.GetBaseException()` + { + return genericMethod.Invoke(caller, parameters); + } + catch (Exception ex) + { + throw ex.GetBaseException(); + } + } + + private static async Task InvokeGenericMethodAsync(this MethodInfo genericMethod, object caller, params object[] parameters) + { + try //exceptions thrown by methods called with invoke are wrapped into another exception, the exception thrown by the invoked method can be returned by `Exception.GetBaseException()` + { + dynamic awaitable = genericMethod.Invoke(caller, parameters); + await awaitable; + return awaitable.GetAwaiter().GetResult(); + } + catch (Exception ex) + { + throw ex.GetBaseException(); + } + } + } +} \ No newline at end of file -- 2.36.2 From 4ce5e0914e7041689f40ee21cf49368365a87e33 Mon Sep 17 00:00:00 2001 From: Simon G Date: Fri, 13 Nov 2020 13:17:53 +0100 Subject: [PATCH 02/12] - add setter for entry --- GBase/FileHandling/GBaseFile.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GBase/FileHandling/GBaseFile.cs b/GBase/FileHandling/GBaseFile.cs index aaf0f56..c29b582 100644 --- a/GBase/FileHandling/GBaseFile.cs +++ b/GBase/FileHandling/GBaseFile.cs @@ -16,7 +16,7 @@ namespace GBase.FileHandling FilePath = filePath; } - public object Entry { get; } + public object Entry { get; set; } public FileStream File { get; } public string FilePath { get; } public bool InUse { get; private set; } -- 2.36.2 From b693b100e890d00a2fd06c04d5fd8d9a0fa0706b Mon Sep 17 00:00:00 2001 From: Simon G Date: Fri, 13 Nov 2020 13:18:08 +0100 Subject: [PATCH 03/12] - add type of property --- GBase/GBaseColumn.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/GBase/GBaseColumn.cs b/GBase/GBaseColumn.cs index 25d2da2..fd8587e 100644 --- a/GBase/GBaseColumn.cs +++ b/GBase/GBaseColumn.cs @@ -16,12 +16,14 @@ namespace GBase /// /// A column of a /// - public GBaseColumn(string name) + public GBaseColumn(string name, Type type) { Name = name; + Type = type; } public string Name { get; } + public Type Type { get; } /// /// The method -- 2.36.2 From 8ac13bf6ec58b70b1bd6fefae1e72af46095a2c8 Mon Sep 17 00:00:00 2001 From: Simon G Date: Fri, 13 Nov 2020 13:18:23 +0100 Subject: [PATCH 04/12] - add microsoft.csharp package --- GBase/GBase.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/GBase/GBase.csproj b/GBase/GBase.csproj index 917f8f6..cd8bbf9 100644 --- a/GBase/GBase.csproj +++ b/GBase/GBase.csproj @@ -24,6 +24,7 @@ + -- 2.36.2 From baa8acae603eec5271a8014545b9620d57cc36d2 Mon Sep 17 00:00:00 2001 From: Simon G Date: Fri, 13 Nov 2020 13:18:55 +0100 Subject: [PATCH 05/12] - add type to factory as well --- GBase/Factories/IGBaseColumnFactory.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GBase/Factories/IGBaseColumnFactory.cs b/GBase/Factories/IGBaseColumnFactory.cs index 7bd39ed..9d133e6 100644 --- a/GBase/Factories/IGBaseColumnFactory.cs +++ b/GBase/Factories/IGBaseColumnFactory.cs @@ -3,6 +3,7 @@ // Copyright(c) 2020 SimonG. All Rights Reserved. +using System; using GBase.Interfaces; namespace GBase.Factories @@ -16,6 +17,6 @@ namespace GBase.Factories /// Creates an /// /// A newly created instance of the implementation for - IGBaseColumn Create(string name); + IGBaseColumn Create(string name, Type type); } } \ No newline at end of file -- 2.36.2 From fababa96d796621a91f75e24754cbf0881ae9aca Mon Sep 17 00:00:00 2001 From: Simon G Date: Fri, 13 Nov 2020 13:19:03 +0100 Subject: [PATCH 06/12] - add type to interface as well --- GBase/Interfaces/IGBaseColumn.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/GBase/Interfaces/IGBaseColumn.cs b/GBase/Interfaces/IGBaseColumn.cs index 59cd728..0292153 100644 --- a/GBase/Interfaces/IGBaseColumn.cs +++ b/GBase/Interfaces/IGBaseColumn.cs @@ -12,5 +12,6 @@ namespace GBase.Interfaces public interface IGBaseColumn : IAsyncDisposable //TODO: Make column generic (generic type is type of the value of the column?)? { string Name { get; } + Type Type { get; } } } \ No newline at end of file -- 2.36.2 From f52ab833c11252b3deb88660646d8937412a57db Mon Sep 17 00:00:00 2001 From: Simon G Date: Fri, 13 Nov 2020 13:19:23 +0100 Subject: [PATCH 07/12] - add setter of entry to interface --- GBase/Interfaces/FileHandling/IGBaseFile.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GBase/Interfaces/FileHandling/IGBaseFile.cs b/GBase/Interfaces/FileHandling/IGBaseFile.cs index 9904130..fd0d0bd 100644 --- a/GBase/Interfaces/FileHandling/IGBaseFile.cs +++ b/GBase/Interfaces/FileHandling/IGBaseFile.cs @@ -9,7 +9,7 @@ namespace GBase.Interfaces.FileHandling { public interface IGBaseFile : IDisposable { - object Entry { get; } + object Entry { get; set; } FileStream File { get; } string FilePath { get; } bool InUse { get; } -- 2.36.2 From a949f786f885f2270cb138859348a1e48c71d556 Mon Sep 17 00:00:00 2001 From: Simon G Date: Fri, 13 Nov 2020 13:19:56 +0100 Subject: [PATCH 08/12] - add initialize() method to IGBaseObject --- GBase.Api/IGBaseObject.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/GBase.Api/IGBaseObject.cs b/GBase.Api/IGBaseObject.cs index 01c6e28..67d6483 100644 --- a/GBase.Api/IGBaseObject.cs +++ b/GBase.Api/IGBaseObject.cs @@ -2,6 +2,8 @@ // Created: 2020-02-14 // Copyright(c) 2020 SimonG. All Rights Reserved. +using System.Collections.Generic; + namespace GBase.Api { /// @@ -14,5 +16,7 @@ namespace GBase.Api /// /// The given void InitializeFromString(string @string); + + void Initialize(List parameters); } } \ No newline at end of file -- 2.36.2 From d4ab37de84238cb7a92382cbdf91d34be78f72e8 Mon Sep 17 00:00:00 2001 From: Simon G Date: Fri, 13 Nov 2020 13:20:29 +0100 Subject: [PATCH 09/12] - initialize existing files --- GBase/FileHandling/FileHandler.cs | 27 ++++++++++++++++--- GBase/Interfaces/FileHandling/IFileHandler.cs | 4 ++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/GBase/FileHandling/FileHandler.cs b/GBase/FileHandling/FileHandler.cs index 4e1d396..58162dc 100644 --- a/GBase/FileHandling/FileHandler.cs +++ b/GBase/FileHandling/FileHandler.cs @@ -38,12 +38,26 @@ namespace GBase.FileHandling /// Initialize this /// /// The path of the database + /// /// A to cancel the asynchronous operation /// True if successful, false if not - public async Task Init(string path, CancellationToken cancellationToken) + public List Init(string path, string folderName, CancellationToken cancellationToken) { _path = path; - return true; //TODO: initialize existing files + + string directoryPath = Path.Combine(_path, folderName); + if (!Directory.Exists(directoryPath)) + return null; + + string[] files = Directory.GetFiles(directoryPath, $"*.{GBASE_TABLE_FILE_EXTENSION}"); + + foreach (var file in files) + { + FileStream entryFile = File.Open(file, FileMode.OpenOrCreate, FileAccess.ReadWrite); + _files.Add(new GBaseFile(null, entryFile, file)); + } + + return _files; } public IGBaseFile CreateEntryFile(T entry, IGBaseTable table) @@ -55,9 +69,14 @@ namespace GBase.FileHandling //create new entry file string filePath = $"{Path.Combine(directoryPath, entry.ToString())}.{GBASE_TABLE_FILE_EXTENSION}"; - FileStream entryFile = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite); //TODO: Stream has to be disposed + + //check if file is already opened + IGBaseFile file = _files.FirstOrDefault(f => f.FilePath.Equals(filePath)); + if (file != null) + return file.UseFile(); - IGBaseFile file = new GBaseFile(entry, entryFile, filePath); + FileStream entryFile = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite); + file = new GBaseFile(entry, entryFile, filePath); _files.Add(file); return file.UseFile(); diff --git a/GBase/Interfaces/FileHandling/IFileHandler.cs b/GBase/Interfaces/FileHandling/IFileHandler.cs index 0e9ca47..e0f9497 100644 --- a/GBase/Interfaces/FileHandling/IFileHandler.cs +++ b/GBase/Interfaces/FileHandling/IFileHandler.cs @@ -3,6 +3,7 @@ // Copyright(c) 2020 SimonG. All Rights Reserved. using System; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -17,9 +18,10 @@ namespace GBase.Interfaces.FileHandling /// Initialize this /// /// The path of the database + /// /// A to cancel the asynchronous operation /// True if successful, false if not - Task Init(string path, CancellationToken cancellationToken); + List Init(string path, string folderName, CancellationToken cancellationToken); IGBaseFile CreateEntryFile(T entry, IGBaseTable table); -- 2.36.2 From be4ccf97e55c7db0410c7a75714881964f6a0ced Mon Sep 17 00:00:00 2001 From: Simon G Date: Fri, 13 Nov 2020 13:22:47 +0100 Subject: [PATCH 10/12] - initialize entries from existing files - T has to be creatable - T has to be of type IGBaseObject --- GBase/GBase.cs | 11 +++++---- GBase/GBaseObject.cs | 4 ++- GBase/GBaseTable.cs | 43 +++++++++++++++++++++++++++------ GBase/Interfaces/IGBase.cs | 11 +++++---- GBase/Interfaces/IGBaseTable.cs | 2 +- 5 files changed, 52 insertions(+), 19 deletions(-) diff --git a/GBase/GBase.cs b/GBase/GBase.cs index eba244f..7c0b03f 100644 --- a/GBase/GBase.cs +++ b/GBase/GBase.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Reflection; using System.Threading; using System.Threading.Tasks; +using GBase.Api; using GBase.Attributes; using GBase.Exceptions; using GBase.Factories; @@ -96,7 +97,7 @@ namespace GBase return true; } - public IGBaseTable GetTable() + public IGBaseTable GetTable() where T : IGBaseObject, new() { if (Tables.OfType>().Any()) return Tables.OfType>().First(); @@ -119,7 +120,7 @@ namespace GBase return Tables.Remove(table); } - public async Task AddEntry(T entry, CancellationToken cancellationToken) + public async Task AddEntry(T entry, CancellationToken cancellationToken) where T : IGBaseObject, new() { IGBaseTable table = GetTable(); if (table == null) @@ -128,7 +129,7 @@ namespace GBase return await table.AddEntry(entry, cancellationToken); } - public async Task SetValue(T entry, string propertyName, TProperty value, CancellationToken cancellationToken) + public async Task SetValue(T entry, string propertyName, TProperty value, CancellationToken cancellationToken) where T : IGBaseObject, new() { IGBaseTable table = GetTable(); if (table == null) @@ -137,7 +138,7 @@ namespace GBase await table.SetValue(entry, propertyName, value, cancellationToken); } - public async Task GetValue(T entry, string propertyName, CancellationToken cancellationToken) + public async Task GetValue(T entry, string propertyName, CancellationToken cancellationToken) where T : IGBaseObject, new() { IGBaseTable table = GetTable(); if (table == null) @@ -146,7 +147,7 @@ namespace GBase return await table.GetValue(entry, propertyName, cancellationToken); } - public async Task> GetValues(T entry, string propertyName, CancellationToken cancellationToken) + public async Task> GetValues(T entry, string propertyName, CancellationToken cancellationToken) where T : IGBaseObject, new() { IGBaseTable table = GetTable(); if (table == null) diff --git a/GBase/GBaseObject.cs b/GBase/GBaseObject.cs index 2711bed..24a355d 100644 --- a/GBase/GBaseObject.cs +++ b/GBase/GBaseObject.cs @@ -14,7 +14,7 @@ namespace GBase /// /// GBase object that supplies inheriting classes with methods to get data from a /// - public abstract class GBaseObject : IGBaseObject + public abstract class GBaseObject : IGBaseObject where T : IGBaseObject, new() { private readonly IGBaseTable _gBaseTable; @@ -43,5 +43,7 @@ namespace GBase /// /// The given public abstract void InitializeFromString(string @string); + + public abstract void Initialize(List parameters); } } \ No newline at end of file diff --git a/GBase/GBaseTable.cs b/GBase/GBaseTable.cs index 644e0fe..23912cc 100644 --- a/GBase/GBaseTable.cs +++ b/GBase/GBaseTable.cs @@ -12,6 +12,7 @@ using GBase.Api; using GBase.Attributes; using GBase.Factories; using GBase.FileHandling.Factories; +using GBase.Helpers; using GBase.Interfaces; using GBase.Interfaces.DataHandling; using GBase.Interfaces.DataHandling.Pool; @@ -22,7 +23,7 @@ namespace GBase /// /// A table /// - public class GBaseTable : IGBaseTable + public class GBaseTable : IGBaseTable where T : IGBaseObject, new() { private readonly IFileHandler _fileHandler; private readonly IDataHandlerPool _dataHandlerPool; @@ -74,11 +75,10 @@ namespace GBase /// /// A to cancel the asynchronous operation /// True if successful, false if not - public async Task Init(Type type, string databasePath, string folderName, CancellationToken cancellationToken) + public async Task Init(Type type, string databasePath, string folderName, CancellationToken cancellationToken) //TODO: Remove bool return value? { Type = type; FolderName = folderName; - await _fileHandler.Init(databasePath, cancellationToken); //TODO: Init columns list depending on GBaseColumnAttributes set for this GBaseTable foreach (var property in type.GetProperties()) @@ -87,9 +87,38 @@ namespace GBase if (gBaseColumnAttribute == null) continue; - IGBaseColumn gBaseColumn = _gBaseColumnFactory.Create(property.Name); + IGBaseColumn gBaseColumn = _gBaseColumnFactory.Create(property.Name, property.PropertyType); AddColumn(gBaseColumn); } + + List files = _fileHandler.Init(databasePath, FolderName, cancellationToken); + if (files == null) + return true; + + foreach (var file in files) //create entries for existing files + { + using (file.UseFile()) + { + T entry = new T(); + + List parameters = new List(); + foreach (var column in Columns) + { + IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken); + + parameters.Add(await GenericMethodCaller.CallAsync(dataHandler, + nameof(IDataHandler.GetValue), + BindingFlags.Public | BindingFlags.Instance, + typeof(T), column.Type, + file.File, column.Name, cancellationToken)); + } + + entry.Initialize(parameters); + + file.Entry = entry; + Entries.Add(entry); + } + } return true; } @@ -156,21 +185,21 @@ namespace GBase public async Task SetValue(T entry, string propertyName, TProperty value, CancellationToken cancellationToken) { using IGBaseFile file = await _fileHandler.RequestEntryFile(entry); - IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, CancellationToken.None); + IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken); await dataHandler.SetValue(file.File, propertyName, value, cancellationToken); } public async Task GetValue(T entry, string propertyName, CancellationToken cancellationToken) { using IGBaseFile file = await _fileHandler.RequestEntryFile(entry); - IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, CancellationToken.None); + IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken); return await dataHandler.GetValue(file.File, propertyName, cancellationToken); } public async Task> GetValues(T entry, string propertyName, CancellationToken cancellationToken) { using IGBaseFile file = await _fileHandler.RequestEntryFile(entry); - IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, CancellationToken.None); + IDataHandler dataHandler = await _dataHandlerPool.RequestDataHandler(this, false, cancellationToken); return await dataHandler.GetValues(file.File, propertyName, cancellationToken); } diff --git a/GBase/Interfaces/IGBase.cs b/GBase/Interfaces/IGBase.cs index 74b571c..b33b335 100644 --- a/GBase/Interfaces/IGBase.cs +++ b/GBase/Interfaces/IGBase.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Reflection; using System.Threading; using System.Threading.Tasks; +using GBase.Api; using GBase.Interfaces.Settings; namespace GBase.Interfaces @@ -48,7 +49,7 @@ namespace GBase.Interfaces /// True if successful, false if not bool AddTable(IGBaseTable table); - IGBaseTable GetTable(); + IGBaseTable GetTable() where T : IGBaseObject, new(); /// /// Removes a given from this @@ -57,10 +58,10 @@ namespace GBase.Interfaces /// True if successful, false if not bool RemoveTable(IGBaseTable table); - Task AddEntry(T entry, CancellationToken cancellationToken); + Task AddEntry(T entry, CancellationToken cancellationToken) where T : IGBaseObject, new(); - Task SetValue(T entry, string propertyName, TProperty value, CancellationToken cancellationToken); - Task GetValue(T entry, string propertyName, CancellationToken cancellationToken); - Task> GetValues(T entry, string propertyName, CancellationToken cancellationToken); + Task SetValue(T entry, string propertyName, TProperty value, CancellationToken cancellationToken) where T : IGBaseObject, new(); + Task GetValue(T entry, string propertyName, CancellationToken cancellationToken) where T : IGBaseObject, new(); + Task> GetValues(T entry, string propertyName, CancellationToken cancellationToken) where T : IGBaseObject, new(); } } \ No newline at end of file diff --git a/GBase/Interfaces/IGBaseTable.cs b/GBase/Interfaces/IGBaseTable.cs index 277c1c5..a43a036 100644 --- a/GBase/Interfaces/IGBaseTable.cs +++ b/GBase/Interfaces/IGBaseTable.cs @@ -10,7 +10,7 @@ using GBase.Api; namespace GBase.Interfaces { - public interface IGBaseTable : IGBaseTable + public interface IGBaseTable : IGBaseTable where T : IGBaseObject, new() { /// /// The entries of this -- 2.36.2 From 6b9c8277176e92b75fbfc3de9a1befdb2100b183 Mon Sep 17 00:00:00 2001 From: Simon G Date: Fri, 13 Nov 2020 13:23:09 +0100 Subject: [PATCH 11/12] - update xml --- GBase/GBase.xml | 75 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/GBase/GBase.xml b/GBase/GBase.xml index d9641b4..2344c22 100644 --- a/GBase/GBase.xml +++ b/GBase/GBase.xml @@ -334,6 +334,17 @@ No root element is set + + + Could not find generic method + + + + + Could not find generic method + + The name of the generic method + that an interface was passed as the generic type of an @@ -395,7 +406,7 @@ Factory for the - + Creates an @@ -450,11 +461,12 @@ Internal file handler - + Initialize this The path of the database + A to cancel the asynchronous operation True if successful, false if not @@ -525,7 +537,7 @@ A column of a - + A column of a @@ -647,6 +659,60 @@ An of Interface was passed to an + + + Call a generic method without generic type parameters + + The caller of the method + The name of the method to call + The to find the method + The generic parameter as parameter + The parameters of the method + The result of invoking the method + Could not find the generic method + Any thrown after invoking the generic method + + + + Call a generic method without generic type parameters + + The caller of the method + The name of the method to call + The to find the method + The generic parameter as parameter + + The parameters of the method + The result of invoking the method + Could not find the generic method + Any thrown after invoking the generic method + + + + Call a generic method asynchronously without generic type parameters + + The caller of the method + The name of the method to call + The to find the method + The generic parameter as parameter + The parameters of the method + The result of invoking the method + Could not find the generic method + Any thrown after invoking the generic method + + + + Call a generic method asynchronously without generic type parameters + + The caller of the method + The name of the method to call + The to find the method + The generic parameter as parameter + + The parameters of the method + The result of invoking the method + Could not find the generic method + Any thrown after invoking the generic method + for the data handling @@ -904,11 +970,12 @@ Internal file handler - + Initialize this The path of the database + A to cancel the asynchronous operation True if successful, false if not -- 2.36.2 From e7bd2206b4ea1370ffc57d74f7ca64375bbae25d Mon Sep 17 00:00:00 2001 From: Simon G Date: Fri, 13 Nov 2020 13:23:18 +0100 Subject: [PATCH 12/12] - adapt test classes --- Test.GBase/GBaseIntegrationTest/Group.cs | 9 +++++++++ Test.GBase/GBaseIntegrationTest/Item.cs | 12 ++++++++++++ Test.GBase/GBaseIntegrationTest/Model.cs | 12 ++++++------ Test.GBase/GBaseTableIntegrationTest.cs | 5 +++-- Test.GBase/TestClasses/Foo.cs | 19 ++++++++++++++++++- Test.GBase/TestClasses/UserType.cs | 6 ++++++ 6 files changed, 54 insertions(+), 9 deletions(-) diff --git a/Test.GBase/GBaseIntegrationTest/Group.cs b/Test.GBase/GBaseIntegrationTest/Group.cs index b9587af..0976ea5 100644 --- a/Test.GBase/GBaseIntegrationTest/Group.cs +++ b/Test.GBase/GBaseIntegrationTest/Group.cs @@ -10,6 +10,11 @@ namespace Test.GBase.GBaseIntegrationTest [GBaseTable("Groups")] public class Group : IGroup { + public Group() + { + Items = new List(); + } + public Group(int key) { Key = key; @@ -22,5 +27,9 @@ namespace Test.GBase.GBaseIntegrationTest public override string ToString() => $"{Key}"; public void InitializeFromString(string @string) => Key = int.Parse(@string); + public void Initialize(List parameters) + { + Key = (int) parameters[0]; + } } } \ No newline at end of file diff --git a/Test.GBase/GBaseIntegrationTest/Item.cs b/Test.GBase/GBaseIntegrationTest/Item.cs index e49acd8..44e38f5 100644 --- a/Test.GBase/GBaseIntegrationTest/Item.cs +++ b/Test.GBase/GBaseIntegrationTest/Item.cs @@ -2,6 +2,7 @@ // Created: 2020-09-18 // Copyright(c) 2020 SimonG. All Rights Reserved. +using System.Collections.Generic; using GBase.Attributes; namespace Test.GBase.GBaseIntegrationTest @@ -9,6 +10,11 @@ namespace Test.GBase.GBaseIntegrationTest [GBaseTable("Items")] public class Item : IItem { + public Item() + { + + } + public Item(string name, int key) { Name = name; @@ -30,5 +36,11 @@ namespace Test.GBase.GBaseIntegrationTest Key = int.Parse(properties[0]); Name = properties[1]; } + + public void Initialize(List parameters) + { + Name = (string) parameters[0]; + Key = (int) parameters[1]; + } } } \ No newline at end of file diff --git a/Test.GBase/GBaseIntegrationTest/Model.cs b/Test.GBase/GBaseIntegrationTest/Model.cs index 0b608a7..a446b8f 100644 --- a/Test.GBase/GBaseIntegrationTest/Model.cs +++ b/Test.GBase/GBaseIntegrationTest/Model.cs @@ -30,13 +30,13 @@ namespace Test.GBase.GBaseIntegrationTest { await _gBase.Init("DB", Assembly.GetExecutingAssembly(), cancellationToken); - // IGBaseTable itemsTable = _gBase.GetTable(); - // Items = itemsTable.Entries.Cast().ToList(); - Items = (await _gBase.GetValues(this, nameof(Items), cancellationToken)).Cast().ToList(); + IGBaseTable itemsTable = _gBase.GetTable(); + Items = itemsTable.Entries.Cast().ToList(); + //Items = (await _gBase.GetValues(this, nameof(Items), cancellationToken)).Cast().ToList(); - // IGBaseTable groupsTable = _gBase.GetTable(); - // Groups = groupsTable.Entries.Cast().ToList(); - Groups = (await _gBase.GetValues(this, nameof(Groups), cancellationToken)).Cast().ToList(); + IGBaseTable groupsTable = _gBase.GetTable(); + Groups = groupsTable.Entries.Cast().ToList(); + //Groups = (await _gBase.GetValues(this, nameof(Groups), cancellationToken)).Cast().ToList(); } public async Task AddItem(Item item, CancellationToken cancellationToken) diff --git a/Test.GBase/GBaseTableIntegrationTest.cs b/Test.GBase/GBaseTableIntegrationTest.cs index cf69136..8d2269f 100644 --- a/Test.GBase/GBaseTableIntegrationTest.cs +++ b/Test.GBase/GBaseTableIntegrationTest.cs @@ -2,6 +2,7 @@ // Created: 2020-03-09 // Copyright(c) 2020 SimonG. All Rights Reserved. +using System; using System.Threading; using GBase; using GBase.Factories; @@ -26,8 +27,8 @@ namespace Test.GBase IGBaseColumn gBaseColumn = null; Mock gBaseColumnFactoryMock = new Mock(); - gBaseColumnFactoryMock.Setup(c => c.Create(It.IsAny())) - .Callback(name => { gBaseColumn = new GBaseColumn(name); }) + gBaseColumnFactoryMock.Setup(c => c.Create(It.IsAny(), It.IsAny())) + .Callback((name, type) => { gBaseColumn = new GBaseColumn(name, type); }) .Returns(gBaseColumn); Mock dataHandlerPoolMock = new Mock(); diff --git a/Test.GBase/TestClasses/Foo.cs b/Test.GBase/TestClasses/Foo.cs index 2cfbb7c..9213c15 100644 --- a/Test.GBase/TestClasses/Foo.cs +++ b/Test.GBase/TestClasses/Foo.cs @@ -2,16 +2,23 @@ // Created: 2020-01-27 // Copyright(c) 2020 SimonG. All Rights Reserved. +using System; +using System.Collections.Generic; using GBase.Api; using GBase.Attributes; namespace Test.GBase.TestClasses { [GBaseTable("Foo")] - public class Foo : NotifyGBaseEntryChanged + public class Foo : NotifyGBaseEntryChanged, IGBaseObject { private string _name; + public Foo() + { + + } + public Foo(string name) { Name = name; @@ -27,5 +34,15 @@ namespace Test.GBase.TestClasses RaiseGBaseEntryChanged(this, nameof(Name), _name); } } + + public void InitializeFromString(string @string) + { + throw new NotImplementedException(); + } + + public void Initialize(List parameters) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/Test.GBase/TestClasses/UserType.cs b/Test.GBase/TestClasses/UserType.cs index 6b81c1f..53cf071 100644 --- a/Test.GBase/TestClasses/UserType.cs +++ b/Test.GBase/TestClasses/UserType.cs @@ -3,6 +3,7 @@ // Copyright(c) 2020 SimonG. All Rights Reserved. using System; +using System.Collections.Generic; using System.Linq; namespace Test.GBase.TestClasses @@ -27,6 +28,11 @@ namespace Test.GBase.TestClasses Number = Convert.ToInt32(numberString); } + public void Initialize(List parameters) + { + throw new NotImplementedException(); + } + public override string ToString() => $"{nameof(UserType)}_{nameof(Number)}_{Number}"; public override bool Equals(object obj) -- 2.36.2