aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-11-14 22:02:45 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-11-14 22:02:45 +0200
commit76b22e4d05cbd8d771f678e4b5adc2dc5159afa8 (patch)
tree815892d26cbf716d9fae9e01d46109299875d94d /Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB
parentf838a715af54ef7fc35bf9d99fee95dd8ac6533f (diff)
downloadTango-76b22e4d05cbd8d771f678e4b5adc2dc5159afa8.tar.gz
Tango-76b22e4d05cbd8d771f678e4b5adc2dc5159afa8.zip
Moved data store projects to DataStore folder.
Diffstat (limited to 'Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB')
-rw-r--r--Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/LiteDBDataStoreCollection.cs113
-rw-r--r--Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/LiteDBDataStoreItem.cs30
-rw-r--r--Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/LiteDBDataStoreManager.cs47
-rw-r--r--Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/Properties/AssemblyInfo.cs7
-rw-r--r--Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/Tango.DataStore.Lite.csproj66
-rw-r--r--Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/packages.config4
6 files changed, 267 insertions, 0 deletions
diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/LiteDBDataStoreCollection.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/LiteDBDataStoreCollection.cs
new file mode 100644
index 000000000..c76a3b6d9
--- /dev/null
+++ b/Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/LiteDBDataStoreCollection.cs
@@ -0,0 +1,113 @@
+using LiteDB;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.DataStore.Lite
+{
+ public class LiteDBDataStoreCollection : IDataStoreCollection
+ {
+ private ILiteCollection<IDataStoreItem> _collection;
+
+ public string Name { get; private set; }
+
+ public LiteDBDataStoreCollection(ILiteCollection<IDataStoreItem> collection)
+ {
+ _collection = collection;
+ }
+
+ public void Put<T>(string key, T value)
+ {
+ Put(key, (object)value);
+ }
+
+ public void Put(string key, object value)
+ {
+ Put(key, DataStoreHelper.GetDataType(value), value);
+ }
+
+ public void Put(string key, DataType type, object value)
+ {
+ _collection.Upsert(new LiteDBDataStoreItem()
+ {
+ Key = key,
+ Date = DateTime.UtcNow,
+ Type = type,
+ Value = value,
+ IsSynchronized = false,
+ });
+ }
+
+ public T Get<T>(string key)
+ {
+ return (T)Convert.ChangeType(Get(key), typeof(T));
+ }
+
+ public T Get<T>(string key, T defaultValue)
+ {
+ return (T)Convert.ChangeType(Get(key, defaultValue), typeof(T));
+ }
+
+ public object Get(string key)
+ {
+ return Get(key, null);
+ }
+
+ public object Get(string key, object defaultValue)
+ {
+ return GetItem(key, defaultValue).Value;
+ }
+
+ public IDataStoreItem GetItem(string key)
+ {
+ return GetItem(key, null);
+ }
+
+ public IDataStoreItem GetItem(string key, object defaultValue)
+ {
+ var item = _collection.FindById(key);
+
+ if (item == null)
+ {
+ if (defaultValue == null)
+ {
+ throw new KeyNotFoundException("The specified key was not found on the data store.");
+ }
+ else
+ {
+ Put(key, defaultValue);
+ return GetItem(key);
+ }
+ }
+
+ return item;
+ }
+
+ public List<IDataStoreItem> GetAll()
+ {
+ return _collection.FindAll().ToList();
+ }
+
+ public void Delete(string key)
+ {
+ _collection.Delete(key);
+ }
+
+ public void DeleteAll()
+ {
+ _collection.DeleteMany(x => true);
+ }
+
+ public int Count()
+ {
+ return _collection.Count();
+ }
+
+ public List<IDataStoreItem> GetUnsynchronized()
+ {
+ return _collection.Find(x => !x.IsSynchronized).ToList();
+ }
+ }
+}
diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/LiteDBDataStoreItem.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/LiteDBDataStoreItem.cs
new file mode 100644
index 000000000..ba2e5748e
--- /dev/null
+++ b/Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/LiteDBDataStoreItem.cs
@@ -0,0 +1,30 @@
+using LiteDB;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.DataStore.Lite
+{
+ public class LiteDBDataStoreItem : IDataStoreItem
+ {
+ public String Guid { get; set; }
+ [BsonId]
+ public string Key { get; set; }
+ public DataType Type { get; set; }
+ public object Value { get; set; }
+ public DateTime Date { get; set; }
+ public bool IsSynchronized { get; set; }
+
+ public LiteDBDataStoreItem()
+ {
+ Guid = System.Guid.NewGuid().ToString();
+ }
+
+ public override string ToString()
+ {
+ return DataStoreHelper.FormatDataStoreItem(this);
+ }
+ }
+}
diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/LiteDBDataStoreManager.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/LiteDBDataStoreManager.cs
new file mode 100644
index 000000000..25abd91ab
--- /dev/null
+++ b/Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/LiteDBDataStoreManager.cs
@@ -0,0 +1,47 @@
+using LiteDB;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.DataStore.Lite
+{
+ public class LiteDBDataStoreManager : IDataStoreManager
+ {
+ private bool _disposed;
+ private LiteDatabase _database;
+
+ public String DatabasePath { get; private set; }
+
+ public LiteDBDataStoreManager(String databasePath)
+ {
+ DatabasePath = databasePath;
+ Directory.CreateDirectory(Path.GetDirectoryName(DatabasePath));
+ _database = new LiteDatabase($"Filename={DatabasePath}");
+ _database.Pragma("TIMEOUT", 10); //Read Timeout
+ _database.Pragma("UTC_DATE", true); //Keep time as UTC when getting data
+ _database.Commit();
+ }
+
+ public IDataStoreCollection GetCollection(string name)
+ {
+ return new LiteDBDataStoreCollection(_database.GetCollection<IDataStoreItem>(name));
+ }
+
+ public List<String> GetCollectionNames()
+ {
+ return _database.GetCollectionNames().ToList();
+ }
+
+ public void Dispose()
+ {
+ if (!_disposed)
+ {
+ _disposed = true;
+ _database.Dispose();
+ }
+ }
+ }
+}
diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/Properties/AssemblyInfo.cs b/Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/Properties/AssemblyInfo.cs
new file mode 100644
index 000000000..f1b35f107
--- /dev/null
+++ b/Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/Properties/AssemblyInfo.cs
@@ -0,0 +1,7 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+[assembly: AssemblyTitle("Tango - Data Store LiteDB Implementation")]
+[assembly: AssemblyVersion("2.0.4.1608")]
+[assembly: ComVisible(false)] \ No newline at end of file
diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/Tango.DataStore.Lite.csproj b/Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/Tango.DataStore.Lite.csproj
new file mode 100644
index 000000000..65ba97520
--- /dev/null
+++ b/Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/Tango.DataStore.Lite.csproj
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{FA96BC0C-4055-475C-9DCC-70A5A9436B10}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Tango.DataStore.Lite</RootNamespace>
+ <AssemblyName>Tango.DataStore.Lite</AssemblyName>
+ <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <Deterministic>true</Deterministic>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="LiteDB, Version=5.0.4.0, Culture=neutral, PublicKeyToken=4ee40123013c9f27, processorArchitecture=MSIL">
+ <HintPath>..\packages\LiteDB.5.0.4\lib\net45\LiteDB.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Runtime" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Net.Http" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\..\Versioning\GlobalVersionInfo.cs">
+ <Link>GlobalVersionInfo.cs</Link>
+ </Compile>
+ <Compile Include="LiteDBDataStoreCollection.cs" />
+ <Compile Include="LiteDBDataStoreItem.cs" />
+ <Compile Include="LiteDBDataStoreManager.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Tango.DataStore\Tango.DataStore.csproj">
+ <Project>{e0364dfa-0721-4637-9d32-9d22aac109d6}</Project>
+ <Name>Tango.DataStore</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project> \ No newline at end of file
diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/packages.config b/Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/packages.config
new file mode 100644
index 000000000..9dcac7837
--- /dev/null
+++ b/Software/Visual_Studio/DataStore/Tango.DataStore.LiteDB/packages.config
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="LiteDB" version="5.0.4" targetFramework="net461" />
+</packages> \ No newline at end of file