From 55e0010fa94aa480ad2fbb1b5252f2d823fd5b1a Mon Sep 17 00:00:00 2001 From: Simon Gockner Date: Wed, 12 Feb 2020 16:02:33 +0100 Subject: [PATCH] - add gBase base class --- GBase/GBase.cs | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 GBase/GBase.cs diff --git a/GBase/GBase.cs b/GBase/GBase.cs new file mode 100644 index 0000000..10b6879 --- /dev/null +++ b/GBase/GBase.cs @@ -0,0 +1,96 @@ +// Author: Gockner, Simon +// Created: 2020-02-12 +// Copyright(c) 2020 SimonG. All Rights Reserved. + +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using GBase.Interfaces; +using GBase.Interfaces.Settings; + +namespace GBase +{ + /// + /// The base class of the GBase database + /// + public class GBase : IGBase + { + /// + /// The base class of the GBase database + /// + /// The for this + public GBase(IGBaseSettings settings) + { + Settings = settings; + Tables = new List(); + } + + /// + /// The name of this + /// + public string Name { get; private set; } + + /// + /// The settings of this + /// + public IGBaseSettings Settings { get; } + + /// + /// The s of this + /// + public List Tables { get; } + + + /// + /// Initialize this + /// + /// The name of this + /// A to cancel the asynchronous operation + /// True if successful, false if not + public async Task Init(string name, CancellationToken cancellationToken) + { + Name = name; + return true; + } + + /// + /// Add a given to this + /// + /// The given + /// True if successful, false if not + public bool AddTable(IGBaseTable table) + { + if (Tables.Contains(table)) + return false; + + if (Tables.Any(t => t.Name.Equals(table.Name))) + return false; + + Tables.Add(table); + return true; + } + + /// + /// Removes a given from this + /// + /// The given + /// True if successful, false if not + public bool RemoveTable(IGBaseTable table) + { + if (!Tables.Contains(table)) + return false; + + return Tables.Remove(table); + } + + /// + /// Dispose used resources asynchronously + /// + /// A to await + public async ValueTask DisposeAsync() + { + Tables.Clear(); + } + } +} \ No newline at end of file