|
|
|
@ -2,10 +2,14 @@ |
|
|
|
// Created: 2020-02-12 |
|
|
|
// Created: 2020-02-12 |
|
|
|
// Copyright(c) 2020 SimonG. All Rights Reserved. |
|
|
|
// Copyright(c) 2020 SimonG. All Rights Reserved. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Linq; |
|
|
|
|
|
|
|
using System.Reflection; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
using GBase.Attributes; |
|
|
|
|
|
|
|
using GBase.Factories; |
|
|
|
using GBase.Interfaces; |
|
|
|
using GBase.Interfaces; |
|
|
|
using GBase.Interfaces.Settings; |
|
|
|
using GBase.Interfaces.Settings; |
|
|
|
|
|
|
|
|
|
|
|
@ -21,12 +25,17 @@ namespace GBase |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
public const string GBASE_TABLE_FILE_EXTENSION = "gb"; //TODO: Find correct place for this const |
|
|
|
public const string GBASE_TABLE_FILE_EXTENSION = "gb"; //TODO: Find correct place for this const |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private readonly IGBaseTableFactory _gBaseTableFactory; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// The base class of the GBase database |
|
|
|
/// The base class of the GBase database |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <param name="settings">The <see cref="IGBaseSettings"/> for this <see cref="GBase"/></param> |
|
|
|
/// <param name="settings">The <see cref="IGBaseSettings"/> for this <see cref="GBase"/></param> |
|
|
|
public GBase(IGBaseSettings settings) |
|
|
|
/// <param name="gBaseTableFactory">Factory for the <see cref="IGBaseTable"/></param> |
|
|
|
|
|
|
|
public GBase(IGBaseSettings settings, IGBaseTableFactory gBaseTableFactory) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
_gBaseTableFactory = gBaseTableFactory; |
|
|
|
|
|
|
|
|
|
|
|
Settings = settings; |
|
|
|
Settings = settings; |
|
|
|
Tables = new List<IGBaseTable>(); |
|
|
|
Tables = new List<IGBaseTable>(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -51,11 +60,26 @@ namespace GBase |
|
|
|
/// Initialize this <see cref="GBase"/> |
|
|
|
/// Initialize this <see cref="GBase"/> |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <param name="name">The name of this <see cref="GBase"/></param> |
|
|
|
/// <param name="name">The name of this <see cref="GBase"/></param> |
|
|
|
|
|
|
|
/// <param name="databaseAssembly">The <see cref="Assembly"/> of the database</param> |
|
|
|
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to cancel the asynchronous operation</param> |
|
|
|
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to cancel the asynchronous operation</param> |
|
|
|
/// <returns>True if successful, false if not</returns> |
|
|
|
/// <returns>True if successful, false if not</returns> |
|
|
|
public async Task<bool> Init(string name, CancellationToken cancellationToken) |
|
|
|
public async Task<bool> Init(string name, Assembly databaseAssembly, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Name = name; |
|
|
|
Name = name; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Type[] types = databaseAssembly.GetTypes(); |
|
|
|
|
|
|
|
foreach (var type in types) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
GBaseTableAttribute gBaseTableAttribute = type.GetCustomAttribute<GBaseTableAttribute>(); |
|
|
|
|
|
|
|
if (gBaseTableAttribute == null) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IGBaseTable gBaseTable = _gBaseTableFactory.Create(); |
|
|
|
|
|
|
|
await gBaseTable.Init(type, type.Name, Settings.DatabasePath, cancellationToken); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AddTable(gBaseTable); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|