- add gBase base class

pull/26/head
Simon Gockner 6 years ago
parent c6376e9d23
commit 55e0010fa9
  1. 96
      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
{
/// <summary>
/// The base class of the GBase database
/// </summary>
public class GBase : IGBase
{
/// <summary>
/// The base class of the GBase database
/// </summary>
/// <param name="settings">The <see cref="IGBaseSettings"/> for this <see cref="GBase"/></param>
public GBase(IGBaseSettings settings)
{
Settings = settings;
Tables = new List<IGBaseTable>();
}
/// <summary>
/// The name of this <see cref="GBase"/>
/// </summary>
public string Name { get; private set; }
/// <summary>
/// The settings of this <see cref="GBase"/>
/// </summary>
public IGBaseSettings Settings { get; }
/// <summary>
/// The <see cref="IGBaseTable"/>s of this <see cref="GBase"/>
/// </summary>
public List<IGBaseTable> Tables { get; }
/// <summary>
/// Initialize this <see cref="GBase"/>
/// </summary>
/// <param name="name">The name of this <see cref="GBase"/></param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to cancel the asynchronous operation</param>
/// <returns>True if successful, false if not</returns>
public async Task<bool> Init(string name, CancellationToken cancellationToken)
{
Name = name;
return true;
}
/// <summary>
/// Add a given <see cref="IGBaseTable"/> to this <see cref="GBase"/>
/// </summary>
/// <param name="table">The given <see cref="IGBaseTable"/></param>
/// <returns>True if successful, false if not</returns>
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;
}
/// <summary>
/// Removes a given <see cref="IGBaseTable"/> from this <see cref="GBase"/>
/// </summary>
/// <param name="table">The given <see cref="IGBaseTable"/></param>
/// <returns>True if successful, false if not</returns>
public bool RemoveTable(IGBaseTable table)
{
if (!Tables.Contains(table))
return false;
return Tables.Remove(table);
}
/// <summary>
/// Dispose used resources asynchronously
/// </summary>
/// <returns>A <see cref="ValueTask"/> to await</returns>
public async ValueTask DisposeAsync()
{
Tables.Clear();
}
}
}
Loading…
Cancel
Save