diff --git a/Libraries/Siaqodb/siaqodb.XML b/Libraries/Siaqodb/siaqodb.XML new file mode 100644 index 000000000..32203e305 --- /dev/null +++ b/Libraries/Siaqodb/siaqodb.XML @@ -0,0 +1,636 @@ + + + + siaqodb + + + + + Attribute to be used for a member of a storable class and that object will be ignored by siaqodb engine + + + + + Attribute to be used for a member of type String of a storable class to limit Length of a string object to be stored in database + + + + + Create an attribute instance of Type MaxLength + + number of characters from string to be stored in database + + + + Use this attribute if you use a Property and inside that + property use some complex code and when Siaqodb engine is not able + to get what is backing field of that Property, variableName is used for Siaqodb engine when that property is used + + + + + + Do NOT use it!, it is used only internally + + + + + Do NOT use it!, it is used only internally + + + + + + + + + Do NOT use it!, it is used only internally + + + + + + + + + Do NOT use it!, it is used only internally + + + + + Do NOT use it!, it is used only internally + + + + + Do NOT use it!, it is used only internally + + + + + Do NOT use it!, it is used only internally + + + + + Do NOT use it!, it is used only internally + + + + + Do NOT use it!, it is used only internally + + + + + Do NOT use it!, it is used only internally + + + + + Main interface to be used by implementers to retrieve objects from database + + + + + + + + + + Class that describe a field of an object stored in database + + + + + Name of field stored in database + + + + + Type of field stored in database + + + + + Class that describe Type of objects stored in database + + + + + Name of Type stored in database + + + + + List of fields + + + + + List used to retrieve objects from database + + Type of objects from list + + + + Add obeject of Type T in the list + + object to be added + + + + Remove all elements from list + + + + + Determines if an element is in list + + The object to locate in list + bool value if object was found or not + + + + Remove object from list + + The object to remove + bool value if object was removed or not + + + + Main class of siaqodb database engine responsible for storing, retrieving ,deleting objects on database files + + + + + Create a new instance of Siaqodb, database is not opened yet + + + + + Create a new instance of Siaqodb and open the database + + Physical folder name where objects are stored + + + + Open database folder + + path where objects are stored + + + + Insert or update object; if object is loaded from database and this method is called then update will occur, if object is new created then insert will occur + + Object to be stored + + + + Insert or update object partially, only provided properties are saved + + object of which properties will be stored + properties to be stored + + + + Insert or update object partially, only provided properties are saved + + object of which properties will be stored + properties to be stored + if true,it will store only references to complex objects + + + + Insert or update object by a Transaction; if object is loaded from database and this method is called then update will occur, if object is new created then insert will occur + + Object to be stored + Transaction object + + + + Load all objects of Type provided + + Type of objects to be loaded from database + List of objects retrieved from database + + + + Load object from database by OID provided + + The Type of object to be loaded + oid of object + the object stored in database with oid provided + + + + Close database + + + + + Cast method to be used in LINQ queries + + Type over which LINQ will take action + + + + + + Query method to be used in LINQ queries + + Type over which LINQ will take action + + + + + + Load OIDs by expression + + Type for which OIDs will be loaded + filter expression + List of OIDs + + + + Load all object OIDs of MetaType provided + + meta type Load by method GetAllTypes() + + + + + + Load value of a field of an object identified by OID provided + + OID of object + fieldName + MetaType + + + + + + Delete an object from database + + Object to be deleted + + + + Delete an object from database using a Transaction + + Object to be deleted + Transaction + + + + Delete an object from database by a certain field(ex:ID that come from server) + + Object to be deleted + Names of field that this method will lookup for object to delete it + + + + Delete an object from database by a certain field(ex:ID that come from server) + + Object to be deleted + Names of fields that this method will lookup for object to delete it + + + + Delete an object from database by a certain field(ex:ID that come from server) + + Object to be deleted + Names of fields that this method will lookup for object to delete it + Transaction object + + + + Delete an object from database by a criteria + + Pairs of fields-values to lookup for object to delete it + Number of objects deleted + + + + Delete all objects of Type provided + + Type of objects to be deleted + + + + Delete all objects of Type provided + + Type of objects to be deleted> + + + + Delete all objects of Type provided + + Type of objects to be deleted + If this is TRUE all dynamic length data associated with objects will be marked as free and Shrink method is able to free the space + + + + Return all Types from database folder + + List of MetaType objects + + + + Return number of objects of Type provided + + Type of objects + + + + + + Export to XML all objects of Type provided from database + + Type of objects to be exported + XmlWriter + + + + Export to XML list of objects provided + + Type of objects + XmlWriter + list of objects to be exported + + + + Import from XML objects and return a list of them + + Type of objects to be imported + XmlReader + List of objects imported + + + + Import from XML objects and return a list and save into database + + Type of objects to be imported + XmlReader + if TRUE objects are saved also in database + List of objects imported + + + + this method is obsolete Use SiaqodbConfigurator.SetDatabaseFileName() method + + type + fielName + + + + Update an object in database by a certain Field(eq: ID that come from a server) + + FieldName by which update is made(eq an ID) + object that has all values but not OID to update it in database + true if object was updated and false if object was not found in database + + + + Update an object in database by certain Fields(eq: ID that come from a server) + + name of fields by which update is made(eq an ID) + object that has all values but not OID to update it in database + true if object was updated and false if object was not found in database + + + + Update an object in database by certain Fields(eq: ID that come from a server) + + name of fields by which update is made(eq an ID) + object that has all values but not OID to update it in database + Transaction object + true if object was updated and false if object was not found in database + + + + return current database path + + The database folder path + + + + Start a database Transaction to be used on insert/update/delete objects + + Transaction object + + + + Get a list of unique values for a field index + + Type where index is defined + Type of field indexed + Name of field or automatic property which is indexed + + + + + + Load all objects in Lazy mode, objects are activated/read from db when it is accessed + by index or by enumerator + + Type of objects to be loaded from database + LazyObjectList of objects + + + + Get OID of object, if the Type of object has not defined OID property then object and OID are weak cached during object load from database and this value is returned, + otherwise it is returned value of the OID property + + The object for which OID is returned + The OID associated with object that is stored in database + + + + Raised before an object is saved in database + + + + + Raised after an object is saved in database + + + + + Raised before an object is deleted from database + + + + + Raised after an object is deleted from database + + + + + Raised before an object is loaded from database + + + + + Raised after object is loaded from database + + + + + Class responsible for configurations of Siaqodb database engine + + + + + Add an index for a field or automatic property of a certain Type,an Index can be added also by using Attribute: Sqo.Attributes.Index; + both ways of adding index are similar + + Field name or automatic property name + Type that declare the field + + + + Add an UniqueConstraint for a field of a certain Type,an UniqueConstraint can be added also by using Attribute: Sqo.Attributes.UniqueConstraint; + both ways of adding UniqueConstraint are similar + + Field name or automatic property name + Type that declare the field + + + + Put MaxLength for a string field or automatic property of a Type, MaxLength can be set also by using Attribute: Sqo.Attributes.MaxLength + + Field name or automatic property name + max length for a string + Type that declare the field + + + + Ignore a field or automatic property to be stored + + Name of field or automatic property + Type that declare the field + + + + Set the name of backing field for a property in case engine cannto discover it, this also can be set by attribute: Sqo.Attributes.UseVariable + + Name of property + Name of backing field of property + + + + + + Set the password for encryption algorithm used to encrypt database data + + The password + + + + Set your custom encryption algorithm that implemets IEncryptor interface + + The instance of custom encryption algorithm + + + + Set build-in encryption algorithm + + Encryption algorithm + + + + Set custom fileName on disk of database file for Type T + + Type of objects + Name of database file on disk + + + + By default this is true for all types. Set this to false to not load childs entities of objects of Type provided + + Type for objects + true if related object need to be loaded, false if you want to load by Include(...) method + + + + Set true to raise Loading/Loaded events + + + + + + + Set if database will be encrypted or not + + + + + Database utilities + + + + + Rebuild and defragment indexes + + + + + + + Shrink database files including rawdata.sqr and indexes + + + + + Repair database files by fixing corrupted objects bytes + + + + + + + Repair database file of Type provided, the corrupted objects will be recuperated or deleted + + + + + + + Normal shrink, all blocks marked as free will be supressed + + + + + All database files will be parsed and check if a block can be marked as free then supress free blocks; + This operation can be slow if your database is big. + + + + + This includes Normal + ForceClaimSpace but also shrink of every db file; after this operation OID values of the stored objects may change. + + + + + Basic class that any siaqodb storable class may inherits from + + + + + Object Identifier(unique per Type) + + + + + Commit transaction to database + + + + + Rollback changes + + + + \ No newline at end of file diff --git a/Libraries/Siaqodb/siaqodb.dll b/Libraries/Siaqodb/siaqodb.dll new file mode 100644 index 000000000..06a93d402 Binary files /dev/null and b/Libraries/Siaqodb/siaqodb.dll differ diff --git a/NzbDrone.Core.Test/Datastore/IndexProviderFixture.cs b/NzbDrone.Core.Test/Datastore/IndexProviderFixture.cs deleted file mode 100644 index d6891ed35..000000000 --- a/NzbDrone.Core.Test/Datastore/IndexProviderFixture.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using FluentAssertions; -using NUnit.Framework; -using NzbDrone.Core.Datastore; -using NzbDrone.Core.Repository; -using NzbDrone.Core.Test.Framework; - -namespace NzbDrone.Core.Test.Datastore -{ - [TestFixture] - public class IndexProviderFixture : ObjectDbTest - { - [SetUp] - public void Setup() - { - WithObjectDb(); - } - - [Test] - public void should_be_able_to_get_sequential_numbers() - { - var indexs = new List(); - - - for (var i = 0; i < 1000; i++) - { - indexs.Add(Subject.Next(GetType())); - } - - indexs.Should().OnlyHaveUniqueItems(); - } - - - - [Test] - public void diffrentTypes_should_get_their_own_counter() - { - var seriesIndex = new List(); - var episodeIndex = new List(); - - - for (var i = 0; i < 200; i++) - { - seriesIndex.Add(Subject.Next(typeof(Series))); - } - - for (var i = 0; i < 100; i++) - { - episodeIndex.Add(Subject.Next(typeof(Episode))); - } - - seriesIndex.Should().OnlyHaveUniqueItems(); - episodeIndex.Should().OnlyHaveUniqueItems(); - - seriesIndex.Min(c => c).Should().Be(1); - seriesIndex.Max(c => c).Should().Be(200); - - episodeIndex.Min(c => c).Should().Be(1); - episodeIndex.Max(c => c).Should().Be(100); - } - - } -} - - - diff --git a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs index 898a7e9bc..06f7e7427 100644 --- a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs +++ b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Eloquera.Client; using FizzWare.NBuilder; using FluentAssertions; using NUnit.Framework; @@ -20,16 +19,16 @@ namespace NzbDrone.Core.Test.Datastore [SetUp] public void SetUp() { - WithObjectDb(false); + WithObjectDb(memory:false); testSeries = Builder .CreateNew() - .With(s => s.Id = 0) + .With(s => s.OID = 0) .Build(); testEpisode = Builder .CreateNew() - .With(e => e.Id = 0) + .With(e => e.OID = 0) .Build(); @@ -52,7 +51,7 @@ namespace NzbDrone.Core.Test.Datastore [Test] public void update_item_with_root_index_0_should_faile() { - testSeries.Id = 0; + testSeries.OID = 0; Assert.Throws(() => Db.Update(testSeries)); } @@ -93,7 +92,7 @@ namespace NzbDrone.Core.Test.Datastore { testEpisode.Series = Builder .CreateNew() - .With(s => s.Id = 0) + .With(s => s.OID = 0) .Build(); Db.Insert(testEpisode); @@ -110,19 +109,19 @@ namespace NzbDrone.Core.Test.Datastore [Test] public void new_objects_should_get_id() { - testSeries.Id = 0; + testSeries.OID = 0; Db.Insert(testSeries); - testSeries.Id.Should().NotBe(0); + testSeries.OID.Should().NotBe(0); } [Test] public void new_object_should_get_new_id() { - testSeries.Id = 0; + testSeries.OID = 0; Db.Insert(testSeries); Db.AsQueryable().Should().HaveCount(1); - testSeries.Id.Should().Be(1); + testSeries.OID.Should().Be(1); } @@ -135,31 +134,31 @@ namespace NzbDrone.Core.Test.Datastore Db.Insert(nested); - nested.Id.Should().Be(1); - nested.List.Should().OnlyContain(c => c.Id > 0); + nested.OID.Should().Be(1); + nested.List.Should().OnlyContain(c => c.OID > 0); } [Test] public void should_have_id_when_returned_from_database() { - testSeries.Id = 0; + testSeries.OID = 0; Db.Insert(testSeries); var item = Db.AsQueryable(); item.Should().HaveCount(1); - item.First().Id.Should().NotBe(0); - item.First().Id.Should().BeLessThan(100); - item.First().Id.Should().Be(testSeries.Id); + item.First().OID.Should().NotBe(0); + item.First().OID.Should().BeLessThan(100); + item.First().OID.Should().Be(testSeries.OID); } [Test] public void should_be_able_to_find_object_by_id() { Db.Insert(testSeries); - var item = Db.AsQueryable().Single(c => c.Id == testSeries.Id); + var item = Db.AsQueryable().Single(c => c.OID == testSeries.OID); - item.Id.Should().NotBe(0); - item.Id.Should().Be(testSeries.Id); + item.OID.Should().NotBe(0); + item.OID.Should().Be(testSeries.OID); } [Test] @@ -181,7 +180,7 @@ namespace NzbDrone.Core.Test.Datastore List = new List { this }; } - public IList List { get; set; } + public List List { get; set; } } } diff --git a/NzbDrone.Core.Test/Eloquera.config b/NzbDrone.Core.Test/Eloquera.config deleted file mode 100644 index 5ae536d21..000000000 --- a/NzbDrone.Core.Test/Eloquera.config +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - diff --git a/NzbDrone.Core.Test/Framework/ObjectDbTest.cs b/NzbDrone.Core.Test/Framework/ObjectDbTest.cs index f859f635f..1d6df4375 100644 --- a/NzbDrone.Core.Test/Framework/ObjectDbTest.cs +++ b/NzbDrone.Core.Test/Framework/ObjectDbTest.cs @@ -36,8 +36,8 @@ namespace NzbDrone.Core.Test.Framework public abstract class ObjectDbTest : CoreTest { - private EloqueraDb _db; - protected EloqueraDb Db + private IObjectDatabase _db; + protected IObjectDatabase Db { get { @@ -52,15 +52,14 @@ namespace NzbDrone.Core.Test.Framework { if (memory) { - _db = new EloqueraDbFactory(new EnvironmentProvider()).CreateMemoryDb(); + _db = new SiaqoDbFactory(new DiskProvider()).CreateMemoryDb(); } else { - _db = new EloqueraDbFactory(new EnvironmentProvider()).Create(Path.Combine(Environment.CurrentDirectory,Guid.NewGuid().ToString()+ ".elq")); + _db = new SiaqoDbFactory(new DiskProvider()).Create(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Guid.NewGuid().ToString())); } Mocker.SetConstant(Db); - Mocker.SetConstant(Db.Db); } [TearDown] diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 2a4408ee0..3a78efc33 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -90,18 +90,6 @@ False ..\Libraries\DeskMetrics\DeskMetrics.NET.dll - - ..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Client.dll - True - - - ..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Common.dll - True - - - ..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Server.exe - True - ..\packages\NBuilder.3.0.1.1\lib\FizzWare.NBuilder.dll @@ -163,7 +151,6 @@ - @@ -336,7 +323,6 @@ Always - Always diff --git a/NzbDrone.Core.Test/ProviderTests/RootFolderServiceTests/FreeSpaceOnDrivesFixture.cs b/NzbDrone.Core.Test/ProviderTests/RootFolderServiceTests/FreeSpaceOnDrivesFixture.cs index 1c6d60edf..ca53b1ea1 100644 --- a/NzbDrone.Core.Test/ProviderTests/RootFolderServiceTests/FreeSpaceOnDrivesFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/RootFolderServiceTests/FreeSpaceOnDrivesFixture.cs @@ -29,7 +29,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RootDirProviderTests { Mocker.GetMock() .Setup(s => s.All()) - .Returns(new List { new RootFolder { Id = 1, Path = @"C:\Test\TV" } }); + .Returns(new List { new RootFolder { OID = 1, Path = @"C:\Test\TV" } }); Mocker.GetMock() .Setup(s => s.GetPathRoot(@"C:\Test\TV")) @@ -49,8 +49,8 @@ namespace NzbDrone.Core.Test.ProviderTests.RootDirProviderTests { Mocker.GetMock() .Setup(s => s.All()) - .Returns(new List { new RootFolder { Id = 1, Path = @"C:\Test\TV" }, - new RootFolder { Id = 2, Path = @"C:\Test\TV2" }}); + .Returns(new List { new RootFolder { OID = 1, Path = @"C:\Test\TV" }, + new RootFolder { OID = 2, Path = @"C:\Test\TV2" }}); Mocker.GetMock() .Setup(s => s.GetPathRoot(It.IsAny())) @@ -70,8 +70,8 @@ namespace NzbDrone.Core.Test.ProviderTests.RootDirProviderTests { Mocker.GetMock() .Setup(s => s.All()) - .Returns(new List { new RootFolder { Id = 1, Path = @"C:\Test\TV" }, - new RootFolder { Id = 2, Path = @"D:\Test\TV" }}); + .Returns(new List { new RootFolder { OID = 1, Path = @"C:\Test\TV" }, + new RootFolder { OID = 2, Path = @"D:\Test\TV" }}); Mocker.GetMock() .Setup(s => s.GetPathRoot(@"C:\Test\TV")) @@ -95,7 +95,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RootDirProviderTests { Mocker.GetMock() .Setup(s => s.All()) - .Returns(new List { new RootFolder { Id = 1, Path = @"C:\Test\TV" } }); + .Returns(new List { new RootFolder { OID = 1, Path = @"C:\Test\TV" } }); Mocker.GetMock() .Setup(s => s.GetPathRoot(@"C:\Test\TV")) diff --git a/NzbDrone.Core.Test/ProviderTests/RootFolderServiceTests/RootFolderServiceFixture.cs b/NzbDrone.Core.Test/ProviderTests/RootFolderServiceTests/RootFolderServiceFixture.cs index ab231306c..13bc0463c 100644 --- a/NzbDrone.Core.Test/ProviderTests/RootFolderServiceTests/RootFolderServiceFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/RootFolderServiceTests/RootFolderServiceFixture.cs @@ -93,7 +93,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RootFolderServiceTests public void invalid_folder_path_throws_on_add(string path) { Assert.Throws(() => - Mocker.Resolve().Add(new RootFolder { Id = 0, Path = path }) + Mocker.Resolve().Add(new RootFolder { OID = 0, Path = path }) ); } diff --git a/NzbDrone.Core.Test/packages.config b/NzbDrone.Core.Test/packages.config index ee8569b1f..c5b39c855 100644 --- a/NzbDrone.Core.Test/packages.config +++ b/NzbDrone.Core.Test/packages.config @@ -3,7 +3,6 @@ - diff --git a/NzbDrone.Core/ContainerExtentions.cs b/NzbDrone.Core/ContainerExtentions.cs index 2f0c452cd..3602c37aa 100644 --- a/NzbDrone.Core/ContainerExtentions.cs +++ b/NzbDrone.Core/ContainerExtentions.cs @@ -82,8 +82,8 @@ namespace NzbDrone.Core container.Register(c => { - return c.Resolve().Create(); - }).As().SingleInstance(); + return c.Resolve().Create(""); + }).As().SingleInstance(); container.RegisterType().WithParameter(ResolvedParameter.ForNamed("DatabaseTarget")); container.RegisterType().WithParameter(ResolvedParameter.ForNamed("LogProvider")); diff --git a/NzbDrone.Core/Datastore/BaseRepositoryModel.cs b/NzbDrone.Core/Datastore/BaseRepositoryModel.cs index 01d8d4928..d85f6aae2 100644 --- a/NzbDrone.Core/Datastore/BaseRepositoryModel.cs +++ b/NzbDrone.Core/Datastore/BaseRepositoryModel.cs @@ -1,14 +1,10 @@ using System.Linq; -using Eloquera.Client; namespace NzbDrone.Core.Datastore { public abstract class BaseRepositoryModel { - [ID] - private long _eqId; - [PetaPoco.Ignore] - public int Id { get; set; } + public int OID { get; set; } } } diff --git a/NzbDrone.Core/Datastore/BasicRepository.cs b/NzbDrone.Core/Datastore/BasicRepository.cs index ed018fb92..9648514a7 100644 --- a/NzbDrone.Core/Datastore/BasicRepository.cs +++ b/NzbDrone.Core/Datastore/BasicRepository.cs @@ -13,32 +13,32 @@ namespace NzbDrone.Core.Datastore public class BasicRepository : IBasicRepository where TModel : BaseRepositoryModel, new() { - public BasicRepository(EloqueraDb eloqueraDb) + public BasicRepository(IObjectDatabase objectDatabase) { - EloqueraDb = eloqueraDb; + ObjectDatabase = objectDatabase; } - protected EloqueraDb EloqueraDb { get; private set; } + protected IObjectDatabase ObjectDatabase { get; private set; } public List All() { - return EloqueraDb.AsQueryable().ToList(); + return ObjectDatabase.AsQueryable().ToList(); } public TModel Get(int id) { - return EloqueraDb.AsQueryable().Single(c => c.Id == id); + return ObjectDatabase.AsQueryable().Single(c => c.OID == id); } public TModel Add(TModel model) { - return EloqueraDb.Insert(model); + return ObjectDatabase.Insert(model); } public void Delete(int id) { var itemToDelete = Get(id); - EloqueraDb.Delete(itemToDelete); + ObjectDatabase.Delete(itemToDelete); } } } diff --git a/NzbDrone.Core/Datastore/EloqueraDbFactory.cs b/NzbDrone.Core/Datastore/EloqueraDbFactory.cs deleted file mode 100644 index 83ac51ac0..000000000 --- a/NzbDrone.Core/Datastore/EloqueraDbFactory.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using Eloquera.Client; -using NzbDrone.Common; -using NzbDrone.Core.Repository; -using NzbDrone.Core.RootFolders; - -namespace NzbDrone.Core.Datastore -{ - public class EloqueraDbFactory - { - private readonly EnvironmentProvider _environmentProvider; - - private readonly string dllPath; - - public EloqueraDbFactory(EnvironmentProvider environmentProvider) - { - _environmentProvider = environmentProvider; - dllPath = _environmentProvider.GetWebBinPath();// this is the path where Eloquera dlls live. - } - - public EloqueraDb CreateMemoryDb() - { - return InternalCreate("server=(local);password=;options=inmemory;uselocalpath=" + dllPath, Guid.NewGuid().ToString()); - } - - public EloqueraDb Create(string dbPath = null) - { - if (dbPath == null) - { - dbPath = _environmentProvider.GetElqMainDbPath(); - } - - var file = new FileInfo(dbPath); - - return InternalCreate(string.Format("server=(local);password=;usedatapath={0};uselocalpath={1}", file.Directory.FullName, dllPath), file.Name); - } - - private EloqueraDb InternalCreate(string connectionString, string databaseName) - { - var db = new DB(connectionString); - - try - { - db.OpenDatabase(databaseName); - } - catch (FileNotFoundException) - { - db.CreateDatabase(databaseName); - db.OpenDatabase(databaseName); - } - - //This seemse to cause Invalid Cast Exceptions... WTF - //db.RefreshMode = ObjectRefreshMode.AlwaysReturnUpdatedValues; - - RegisterTypeRules(); - RegisterTypes(db); - - return new EloqueraDb(db, new IdService(new IndexProvider(db))); - } - - private void RegisterTypeRules() - { - RootFolder rootFolder = null; - DB.TypeRules - //.SetIDField(() => rootFolder.Id) - .IgnoreProperty(() => rootFolder.FreeSpace) - .IgnoreProperty(() => rootFolder.UnmappedFolders); - - //Series series = null; - //DB.TypeRules - // .SetIDField(() => series.Id); - } - - private void RegisterTypes(DB db) - { - db.RegisterType(typeof(RootFolder)); - db.RegisterType(typeof(Series)); - db.RegisterType(typeof(Episode)); - } - } -} diff --git a/NzbDrone.Core/Datastore/IdService.cs b/NzbDrone.Core/Datastore/IdService.cs deleted file mode 100644 index 1a8887736..000000000 --- a/NzbDrone.Core/Datastore/IdService.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -namespace NzbDrone.Core.Datastore -{ - public class IdService - { - private readonly IndexProvider _indexProvider; - - private static readonly ConcurrentDictionary> propertyCache = new ConcurrentDictionary>(); - - public IdService(IndexProvider indexProvider) - { - _indexProvider = indexProvider; - } - - public void EnsureIds(T obj, HashSet context) - { - //context is use to prevent infinite loop if objects are recursively looped. - if (obj == null || context.Contains(obj)) - { - return; - } - - context.Add(obj); - - var modelBase = obj as BaseRepositoryModel; - - if (modelBase != null && modelBase.Id == 0) - { - modelBase.Id = _indexProvider.Next(obj.GetType()); - } - - var list = obj as IEnumerable; - if (list != null) - { - foreach (var item in list) - { - EnsureIds(item, context); - } - return; - } - - foreach (var propertyInfo in GetPotentialProperties(obj.GetType())) - { - var propValue = propertyInfo.GetValue(obj, null); - EnsureIds(propValue, context); - } - } - - private IList GetPotentialProperties(Type type) - { - IList result; - if (!propertyCache.TryGetValue(type.FullName, out result)) - { - result = type.GetProperties().Where(ShouldCrawl).ToList(); - propertyCache.TryAdd(type.FullName, result); - } - - return result; - } - - private bool ShouldCrawl(PropertyInfo propertyInfo) - { - return propertyInfo.CanRead && ShouldCrawl(propertyInfo.PropertyType); - } - - private bool ShouldCrawl(Type type) - { - if (type.IsGenericType) - { - var genericArg = type.GetGenericArguments()[0]; - - //skip if generic argument type isn't interesting - if (!ShouldCrawl(genericArg)) - { - return false; - } - - var listType = typeof(IList<>).MakeGenericType(genericArg); - return listType.IsAssignableFrom(type); - } - - return type.IsClass && type.FullName.StartsWith("NzbDrone"); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Datastore/IndexProvider.cs b/NzbDrone.Core/Datastore/IndexProvider.cs deleted file mode 100644 index 9854da8be..000000000 --- a/NzbDrone.Core/Datastore/IndexProvider.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Eloquera.Client; - -namespace NzbDrone.Core.Datastore -{ - public interface IProvideIndex - { - int Next(Type type); - } - - public class IndexProvider : IProvideIndex - { - private readonly DB _db; - - private static object _lock = new object(); - - public IndexProvider(DB db) - { - _db = db; - - if (db.IsTypeRegistered(typeof(IndexList))) - { - db.RegisterType(typeof(IndexList)); - } - - lock (_lock) - { - try - { - _db.Query().Count(); - - } - catch (EloqueraException ex) - { - _db.Store(new IndexList()); - } - } - - } - - public int Next(Type type) - { - if (type == null) - { - throw new ArgumentException(); - } - - var key = type.Name; - - lock (_lock) - { - var indexList = _db.Query().Single(); - - var indexInfo = indexList.SingleOrDefault(c => c.Type == key); - - if (indexInfo == null) - { - indexInfo = new IndexInfo { Type = key }; - indexList.Add(indexInfo); - } - - indexInfo.Index++; - - _db.Store(indexList); - - return indexInfo.Index; - } - } - - public class IndexList : List { } - - public class IndexInfo - { - public string Type { get; set; } - public int Index { get; set; } - } - - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Datastore/Migrations/NzbDroneMigration.cs b/NzbDrone.Core/Datastore/Migrations/NzbDroneMigration.cs index d846b4ea0..055f46e9e 100644 --- a/NzbDrone.Core/Datastore/Migrations/NzbDroneMigration.cs +++ b/NzbDrone.Core/Datastore/Migrations/NzbDroneMigration.cs @@ -35,12 +35,12 @@ namespace NzbDrone.Core.Datastore.Migrations } } - protected EloqueraDb GetObjectDb() + protected IObjectDatabase GetObjectDb() { var sqlCeConnection = SqlCeProxy.EnsureDatabase(Database.ConnectionString); var eqPath = sqlCeConnection.Database.Replace(".sdf", ".eq"); - return new EloqueraDbFactory(new EnvironmentProvider()).Create(eqPath); + return new SiaqoDbFactory(new DiskProvider()).Create(eqPath); } public override void Down() diff --git a/NzbDrone.Core/Datastore/ObjectDbFactory.cs b/NzbDrone.Core/Datastore/ObjectDbFactory.cs new file mode 100644 index 000000000..10a45053d --- /dev/null +++ b/NzbDrone.Core/Datastore/ObjectDbFactory.cs @@ -0,0 +1,42 @@ +using System; +using System.Linq; +using NzbDrone.Common; +using Sqo; + +namespace NzbDrone.Core.Datastore +{ + public interface IObjectDbFactory + { + IObjectDatabase CreateMemoryDb(); + IObjectDatabase Create(string dbPath); + } + + public class SiaqoDbFactory : IObjectDbFactory + { + private readonly DiskProvider _diskProvider; + + public SiaqoDbFactory(DiskProvider diskProvider) + { + _diskProvider = diskProvider; + } + + public IObjectDatabase CreateMemoryDb() + { + throw new NotImplementedException(); + } + + public IObjectDatabase Create(string dbPath) + { + if(!_diskProvider.FolderExists(dbPath)) + { + _diskProvider.CreateDirectory(dbPath); + } + + SiaqodbConfigurator.SetTrialLicense("uvhpW4hT5Rtq+Uoyq8MOm1Smon15foxV5iS5bAegIXU="); + + var db = new Siaqodb(dbPath); + + return new SiaqodbProxy(db); + } + } +} diff --git a/NzbDrone.Core/Datastore/EloqueraDb.cs b/NzbDrone.Core/Datastore/SiaqodbProxy.cs similarity index 55% rename from NzbDrone.Core/Datastore/EloqueraDb.cs rename to NzbDrone.Core/Datastore/SiaqodbProxy.cs index ca9909d93..e60680bce 100644 --- a/NzbDrone.Core/Datastore/EloqueraDb.cs +++ b/NzbDrone.Core/Datastore/SiaqodbProxy.cs @@ -1,80 +1,81 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Reflection; -using Eloquera.Client; +using Sqo; namespace NzbDrone.Core.Datastore { - public class EloqueraDb : IDisposable + public interface IObjectDatabase : IDisposable { - private readonly IdService _idService; - public DB Db { get; private set; } + IEnumerable AsQueryable(); + T Insert(T obj) where T : BaseRepositoryModel; + T Update(T obj) where T : BaseRepositoryModel; + IList InsertMany(IList objects) where T : BaseRepositoryModel; + IList UpdateMany(IList objects) where T : BaseRepositoryModel; + void Delete(T obj) where T : BaseRepositoryModel; + void DeleteMany(IEnumerable objects) where T : BaseRepositoryModel; + } - public EloqueraDb(DB db, IdService idService) + public class SiaqodbProxy : IObjectDatabase + { + private readonly Siaqodb _db; + + public SiaqodbProxy(Siaqodb db) { - _idService = idService; - Db = db; + _db = db; + } + + public void Dispose() + { + } public IEnumerable AsQueryable() { - return Db.Query(); + return _db.Cast(); } public T Insert(T obj) where T : BaseRepositoryModel { - if (obj.Id != 0) + if (obj.OID != 0) { throw new InvalidOperationException("Attempted to insert object with existing ID as new object"); } - _idService.EnsureIds(obj, new HashSet()); - Db.Store(obj); + _db.StoreObject(obj); return obj; } public T Update(T obj) where T : BaseRepositoryModel { - if (obj.Id == 0) + if (obj.OID == 0) { - throw new InvalidOperationException("Attempted to update object without ID"); + throw new InvalidOperationException("Attempted to update object without an ID"); } - _idService.EnsureIds(obj, new HashSet()); - Db.Store(obj); + _db.StoreObject(obj); return obj; } public IList InsertMany(IList objects) where T : BaseRepositoryModel { - _idService.EnsureIds(objects, new HashSet()); - return DoMany(objects, Insert); + return DoMany(objects,Insert); } - + public IList UpdateMany(IList objects) where T : BaseRepositoryModel { - _idService.EnsureIds(objects, new HashSet()); return DoMany(objects, Update); + } public void Delete(T obj) where T : BaseRepositoryModel { - if (obj.Id == 0) - { - throw new InvalidOperationException("Attempted to delete an object without an ID"); - } - - Db.Delete(obj); + throw new NotImplementedException(); } public void DeleteMany(IEnumerable objects) where T : BaseRepositoryModel { - foreach (var o in objects) - { - Delete(o); - } + throw new NotImplementedException(); } private IList DoMany(IEnumerable objects, Func function) where T : BaseRepositoryModel @@ -82,10 +83,5 @@ namespace NzbDrone.Core.Datastore return objects.Select(function).ToList(); } - - public void Dispose() - { - Db.Dispose(); - } } } diff --git a/NzbDrone.Core/Eloquera.config b/NzbDrone.Core/Eloquera.config deleted file mode 100644 index 5ae536d21..000000000 --- a/NzbDrone.Core/Eloquera.config +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 43a517c9b..533784647 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -167,15 +167,6 @@ ..\Libraries\DeskMetrics\DeskMetrics.NET.dll - - ..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Client.dll - - - ..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Common.dll - - - ..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Server.exe - ..\packages\Growl.0.6\lib\Growl.Connector.dll @@ -219,6 +210,9 @@ ..\packages\RestSharp.104.1\lib\net4\RestSharp.dll + + ..\Libraries\Siaqodb\siaqodb.dll + ..\packages\SignalR.Server.0.5.3\lib\net40\SignalR.dll @@ -258,10 +252,8 @@ - - - - + + @@ -670,7 +662,6 @@ - diff --git a/NzbDrone.Core/Repository/Episode.cs b/NzbDrone.Core/Repository/Episode.cs index 7425c8494..091a8f89a 100644 --- a/NzbDrone.Core/Repository/Episode.cs +++ b/NzbDrone.Core/Repository/Episode.cs @@ -1,5 +1,4 @@ using System; -using Eloquera.Client; using NzbDrone.Core.Datastore; using NzbDrone.Core.Model; using PetaPoco; diff --git a/NzbDrone.Core/Repository/Series.cs b/NzbDrone.Core/Repository/Series.cs index 157bf8acf..ddfd335f6 100644 --- a/NzbDrone.Core/Repository/Series.cs +++ b/NzbDrone.Core/Repository/Series.cs @@ -1,6 +1,5 @@ using System; using System.ComponentModel; -using Eloquera.Client; using NzbDrone.Core.Datastore; using NzbDrone.Core.Model; using NzbDrone.Core.Repository.Quality; diff --git a/NzbDrone.Core/RootFolders/RootFolderRepository.cs b/NzbDrone.Core/RootFolders/RootFolderRepository.cs index c5929edbe..c71ee7a3b 100644 --- a/NzbDrone.Core/RootFolders/RootFolderRepository.cs +++ b/NzbDrone.Core/RootFolders/RootFolderRepository.cs @@ -1,7 +1,4 @@ -using System.Collections.Generic; -using Eloquera.Client; -using NzbDrone.Core.Datastore; -using NzbDrone.Core.Repository; +using NzbDrone.Core.Datastore; using System.Linq; namespace NzbDrone.Core.RootFolders @@ -14,15 +11,15 @@ namespace NzbDrone.Core.RootFolders //This way we only need to implement none_custom methods for repos, like custom queries etc... rest is done automagically. public class RootFolderRepository : BasicRepository, IRootFolderRepository { - public RootFolderRepository(EloqueraDb eloqueraDb) - : base(eloqueraDb) + public RootFolderRepository(IObjectDatabase objectDatabase) + : base(objectDatabase) { } public RootFolder Add(RootFolder rootFolder) { - return EloqueraDb.Insert(rootFolder); + return ObjectDatabase.Insert(rootFolder); } } } diff --git a/NzbDrone.Core/packages.config b/NzbDrone.Core/packages.config index d39efd159..5a6f46417 100644 --- a/NzbDrone.Core/packages.config +++ b/NzbDrone.Core/packages.config @@ -3,7 +3,6 @@ - diff --git a/NzbDrone.Web/Eloquera.config b/NzbDrone.Web/Eloquera.config deleted file mode 100644 index 5ae536d21..000000000 --- a/NzbDrone.Web/Eloquera.config +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index deb611854..062a5bbb4 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -92,17 +92,6 @@ ..\packages\DynamicQuery.1.0\lib\35\Dynamic.dll - - False - ..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Client.dll - - - False - ..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Common.dll - - - ..\packages\EloqueraDB.5.0.0\lib\net40\Eloquera.Server.exe - ..\packages\LowercaseRoutesMVC.1.0.3\lib\LowercaseRoutesMVC.dll @@ -435,7 +424,6 @@ - diff --git a/NzbDrone.Web/packages.config b/NzbDrone.Web/packages.config index 3184e9642..3a9452572 100644 --- a/NzbDrone.Web/packages.config +++ b/NzbDrone.Web/packages.config @@ -12,7 +12,6 @@ - diff --git a/SqlCe/NzbDrone.SqlCe.dll b/SqlCe/NzbDrone.SqlCe.dll index 9cde16324..87aa47a56 100644 Binary files a/SqlCe/NzbDrone.SqlCe.dll and b/SqlCe/NzbDrone.SqlCe.dll differ