ln.types/odb/ODB.cs

83 lines
2.1 KiB
C#
Raw Normal View History

2019-03-13 08:22:08 +01:00
// /**
// * File: ODB.cs
// * Author: haraldwolff
// *
// * This file and it's content is copyrighted by the Author and / or copyright holder.
// * Any use wihtout proper permission is illegal and may lead to legal actions.
// *
// *
// **/
using System;
using System.IO;
using System.Collections.Generic;
2019-03-20 14:28:56 +01:00
using Castle.DynamicProxy;
using ln.types.serialize;
using Castle.Components.DictionaryAdapter;
using System.Linq;
2019-03-26 12:54:02 +01:00
using ln.logging;
using ln.types.odb.values;
2019-03-13 08:22:08 +01:00
namespace ln.types.odb
{
2019-03-20 14:28:56 +01:00
2019-03-26 12:54:02 +01:00
public class ODB : IDisposable
2019-03-13 08:22:08 +01:00
{
2019-03-20 14:28:56 +01:00
public String BasePath { get; set; }
2019-03-13 08:22:08 +01:00
2019-03-26 12:54:02 +01:00
Dictionary<string, ODBCollection> collections = new Dictionary<string, ODBCollection>();
2019-03-13 08:22:08 +01:00
2019-03-20 14:28:56 +01:00
public ODB(string basePath)
2019-03-13 08:22:08 +01:00
{
2019-03-20 14:28:56 +01:00
BasePath = Path.GetFullPath(basePath);
2019-03-26 12:54:02 +01:00
if (!Directory.Exists(BasePath))
Directory.CreateDirectory(BasePath);
2019-03-13 08:22:08 +01:00
}
2019-03-26 12:54:02 +01:00
public ODBCollection GetCollection(string colName)
2019-03-20 14:28:56 +01:00
{
2019-03-26 12:54:02 +01:00
if (!collections.ContainsKey(colName))
collections[colName] = new ODBCollection(this, colName);
2019-03-20 14:28:56 +01:00
2019-03-26 12:54:02 +01:00
return collections[colName];
2019-03-20 14:28:56 +01:00
}
2019-03-26 12:54:02 +01:00
public ODBCollection<T> GetCollection<T>() where T:class
2019-03-21 07:43:39 +01:00
{
2019-03-26 12:54:02 +01:00
return new ODBCollection<T>(this);
2019-03-20 14:28:56 +01:00
}
2019-03-21 07:43:39 +01:00
2019-03-26 12:54:02 +01:00
internal void DisposeCollection(ODBCollection collection)
{
ODBCollection check = collections[collection.CollectionName];
if (check == collection)
collections.Remove(collection.CollectionName);
2019-03-21 07:43:39 +01:00
}
2019-03-26 12:54:02 +01:00
private void Initialize()
2019-03-20 14:28:56 +01:00
{
}
2019-03-26 12:54:02 +01:00
public void Dispose()
2019-03-20 14:28:56 +01:00
{
2019-03-26 12:54:02 +01:00
foreach (ODBCollection col in collections.Values.ToArray())
2019-03-20 14:28:56 +01:00
{
2019-03-26 12:54:02 +01:00
col.Dispose();
2019-03-20 14:28:56 +01:00
}
}
2019-03-26 12:54:02 +01:00
static ODB()
2019-03-20 14:28:56 +01:00
{
2019-03-26 12:54:02 +01:00
new ODBDocument();
new ODBNull();
new ODBStringValue();
new ODBList();
new ODBInteger();
new ODBUInteger();
new ODBLong();
new ODBULong();
new ODBDouble();
new ODBGuid();
2019-03-20 14:28:56 +01:00
}
2019-03-26 12:54:02 +01:00
2019-03-13 08:22:08 +01:00
}
2019-03-26 12:54:02 +01:00
}