Import DatabaseObjectModel from old Universal Data Storage codebase

This commit is contained in:
Michael Becker 2019-11-12 19:21:18 -05:00
parent f7fdb51610
commit 2bad02b45b
No known key found for this signature in database
GPG Key ID: 389DFF5D73781A12
5 changed files with 181 additions and 0 deletions

View File

@ -0,0 +1,53 @@
using System;
namespace UniversalEditor.ObjectModels.Database
{
public class DatabaseField : ICloneable
{
public class DatabaseFieldCollection
: System.Collections.ObjectModel.Collection<DatabaseField>
{
private System.Collections.Generic.Dictionary<string, DatabaseField> fieldsByName = new System.Collections.Generic.Dictionary<string, DatabaseField>();
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;
}
}
}

View File

@ -0,0 +1,44 @@
//
// DatabaseObjectModel.cs
//
// Author:
// Mike Becker <alcexhim@gmail.com>
//
// 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 <http://www.gnu.org/licenses/>.
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);
}
}
}
}

View File

@ -0,0 +1,38 @@
using System;
namespace UniversalEditor.ObjectModels.Database
{
public class DatabaseRecord : ICloneable
{
public class DatabaseRecordCollection
: System.Collections.ObjectModel.Collection<DatabaseRecord>
{
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;
}
}
}

View File

@ -0,0 +1,41 @@
using System;
namespace UniversalEditor.ObjectModels.Database
{
public class DatabaseTable : ICloneable
{
public class DatabaseTableCollection
: System.Collections.ObjectModel.Collection<DatabaseTable>
{
}
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;
}
}
}

View File

@ -189,6 +189,10 @@
<Compile Include="ObjectModels\BinaryGrammar\GrammarItems\GrammarItemString.cs" />
<Compile Include="ObjectModels\BinaryGrammar\FixedValue.cs" />
<Compile Include="DataFormats\Text\Plain\ByteOrderMark.cs" />
<Compile Include="ObjectModels\Database\DatabaseField.cs" />
<Compile Include="ObjectModels\Database\DatabaseRecord.cs" />
<Compile Include="ObjectModels\Database\DatabaseTable.cs" />
<Compile Include="ObjectModels\Database\DatabaseObjectModel.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\UniversalEditor.Core\UniversalEditor.Core.csproj">
@ -212,6 +216,7 @@
<Folder Include="DataFormats\Shortcut\Linux\" />
<Folder Include="ObjectModels\BinaryGrammar\" />
<Folder Include="ObjectModels\BinaryGrammar\GrammarItems\" />
<Folder Include="ObjectModels\Database\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.