From 2bad02b45b85922f737c0617d8fd88418ced2947 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Tue, 12 Nov 2019 19:21:18 -0500 Subject: [PATCH] Import DatabaseObjectModel from old Universal Data Storage codebase --- .../ObjectModels/Database/DatabaseField.cs | 53 +++++++++++++++++++ .../Database/DatabaseObjectModel.cs | 44 +++++++++++++++ .../ObjectModels/Database/DatabaseRecord.cs | 38 +++++++++++++ .../ObjectModels/Database/DatabaseTable.cs | 41 ++++++++++++++ .../UniversalEditor.Essential.csproj | 5 ++ 5 files changed, 181 insertions(+) create mode 100755 CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Database/DatabaseField.cs create mode 100644 CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Database/DatabaseObjectModel.cs create mode 100755 CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Database/DatabaseRecord.cs create mode 100755 CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Database/DatabaseTable.cs diff --git a/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Database/DatabaseField.cs b/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Database/DatabaseField.cs new file mode 100755 index 00000000..3cf13b24 --- /dev/null +++ b/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Database/DatabaseField.cs @@ -0,0 +1,53 @@ +using System; +namespace UniversalEditor.ObjectModels.Database +{ + public class DatabaseField : ICloneable + { + + public class DatabaseFieldCollection + : System.Collections.ObjectModel.Collection + { + private System.Collections.Generic.Dictionary fieldsByName = new System.Collections.Generic.Dictionary(); + public DatabaseField Add(string Name) + { + return Add(Name, String.Empty); + } + public DatabaseField Add(string Name, object Value) + { + DatabaseField df = new DatabaseField(); + df.Name = Name; + df.Value = Value; + + base.Add(df); + return df; + } + + public DatabaseField this[string Name] + { + get + { + return fieldsByName[Name]; + } + } + } + + public string Name { get; set; } = String.Empty; + public object Value { get; set; } = null; + + public object Clone() + { + DatabaseField clone = new DatabaseField(); + clone.Name = (Name.Clone() as string); + if (Value is ICloneable) + { + clone.Value = (Value as ICloneable).Clone(); + } + else + { + clone.Value = Value; + } + return clone; + } + } +} + diff --git a/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Database/DatabaseObjectModel.cs b/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Database/DatabaseObjectModel.cs new file mode 100644 index 00000000..1af45d8b --- /dev/null +++ b/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Database/DatabaseObjectModel.cs @@ -0,0 +1,44 @@ +// +// DatabaseObjectModel.cs +// +// Author: +// Mike Becker +// +// Copyright (c) 2019 Mike Becker +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +namespace UniversalEditor.ObjectModels.Database +{ + public class DatabaseObjectModel : ObjectModel + { + public DatabaseTable.DatabaseTableCollection Tables { get; } = new DatabaseTable.DatabaseTableCollection(); + + public override void Clear() + { + Tables.Clear(); + } + public override void CopyTo(ObjectModel where) + { + DatabaseObjectModel clone = (where as DatabaseObjectModel); + if (clone == null) + throw new ObjectModelNotSupportedException(); + + for (int i = 0; i < Tables.Count; i++) + { + clone.Tables.Add(Tables[i].Clone() as DatabaseTable); + } + } + } +} diff --git a/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Database/DatabaseRecord.cs b/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Database/DatabaseRecord.cs new file mode 100755 index 00000000..49da3d75 --- /dev/null +++ b/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Database/DatabaseRecord.cs @@ -0,0 +1,38 @@ +using System; + +namespace UniversalEditor.ObjectModels.Database +{ + public class DatabaseRecord : ICloneable + { + + public class DatabaseRecordCollection + : System.Collections.ObjectModel.Collection + { + public DatabaseRecord Add(params DatabaseField[] parameters) + { + DatabaseRecord dr = new DatabaseRecord(); + foreach (DatabaseField df in parameters) + { + dr.Fields.Add(df.Name, df.Value); + } + return dr; + } + } + + private DatabaseField.DatabaseFieldCollection mvarFields = new DatabaseField.DatabaseFieldCollection (); + public DatabaseField.DatabaseFieldCollection Fields + { + get { return mvarFields; } + } + + public object Clone() + { + DatabaseRecord clone = new DatabaseRecord(); + for (int i = 0; i < Fields.Count; i++) + { + clone.Fields.Add(Fields[i].Clone() as DatabaseField); + } + return clone; + } + } +} \ No newline at end of file diff --git a/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Database/DatabaseTable.cs b/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Database/DatabaseTable.cs new file mode 100755 index 00000000..767686a4 --- /dev/null +++ b/CSharp/Libraries/UniversalEditor.Essential/ObjectModels/Database/DatabaseTable.cs @@ -0,0 +1,41 @@ +using System; + +namespace UniversalEditor.ObjectModels.Database +{ + public class DatabaseTable : ICloneable + { + public class DatabaseTableCollection + : System.Collections.ObjectModel.Collection + { + } + + public string Name { get; set; } = String.Empty; + + private DatabaseField.DatabaseFieldCollection mvarFields = new DatabaseField.DatabaseFieldCollection(); + public DatabaseField.DatabaseFieldCollection Fields + { + get { return mvarFields; } + } + + private DatabaseRecord.DatabaseRecordCollection mvarRecords = new DatabaseRecord.DatabaseRecordCollection(); + public DatabaseRecord.DatabaseRecordCollection Records + { + get { return mvarRecords; } + } + + public object Clone() + { + DatabaseTable clone = new DatabaseTable(); + clone.Name = (Name.Clone() as string); + for (int i = 0; i < Fields.Count; i++) + { + clone.Fields.Add(Fields[i].Clone() as DatabaseField); + } + for (int i = 0; i < Records.Count; i++) + { + clone.Records.Add(Records[i].Clone() as DatabaseRecord); + } + return clone; + } + } +} \ No newline at end of file diff --git a/CSharp/Libraries/UniversalEditor.Essential/UniversalEditor.Essential.csproj b/CSharp/Libraries/UniversalEditor.Essential/UniversalEditor.Essential.csproj index 3b34843e..9df6d71e 100644 --- a/CSharp/Libraries/UniversalEditor.Essential/UniversalEditor.Essential.csproj +++ b/CSharp/Libraries/UniversalEditor.Essential/UniversalEditor.Essential.csproj @@ -189,6 +189,10 @@ + + + + @@ -212,6 +216,7 @@ +