diff --git a/Libraries/Sqlite/Mono.Data.Sqlite.dll b/Libraries/Sqlite/Mono.Data.Sqlite.dll new file mode 100644 index 000000000..dad79f065 Binary files /dev/null and b/Libraries/Sqlite/Mono.Data.Sqlite.dll differ diff --git a/NzbDrone.Core.Test/Datastore/BasicRepositoryFixture.cs b/NzbDrone.Core.Test/Datastore/BasicRepositoryFixture.cs index a4e89b8fa..a15c00c6b 100644 --- a/NzbDrone.Core.Test/Datastore/BasicRepositoryFixture.cs +++ b/NzbDrone.Core.Test/Datastore/BasicRepositoryFixture.cs @@ -3,14 +3,14 @@ using System.Data; using System.Linq; using FizzWare.NBuilder; using FluentAssertions; +using Marr.Data.Mapping; using NUnit.Framework; using NzbDrone.Core.Datastore; using NzbDrone.Core.Test.Framework; -using ServiceStack.OrmLite; namespace NzbDrone.Core.Test.Datastore { - public class BaiscType : ModelBase + public class BasicType : ModelBase { public string Name { get; set; } public string Tilte { get; set; } @@ -18,26 +18,33 @@ namespace NzbDrone.Core.Test.Datastore } [TestFixture] - public class BasicRepositoryFixture : DbTest,BaiscType> + public class + BasicRepositoryFixture : DbTest, BasicType> { - private BaiscType _baiscType; + private BasicType _basicType; [SetUp] public void Setup() { - _baiscType = Builder + _basicType = Builder .CreateNew() .With(c => c.Id = 0) .Build(); - Mocker.Resolve().CreateTable(); + var mapping = new FluentMappings(true); + + mapping.Entity() + .Columns.AutoMapSimpleTypeProperties() + .For(c => c.Id).SetAutoIncrement() + .SetPrimaryKey(); + } [Test] public void should_be_able_to_add() { - Subject.Insert(_baiscType); + Subject.Insert(_basicType); Subject.All().Should().HaveCount(1); } @@ -46,21 +53,21 @@ namespace NzbDrone.Core.Test.Datastore [Test] public void should_be_able_to_delete_model() { - Subject.Insert(_baiscType); + Subject.Insert(_basicType); Subject.All().Should().HaveCount(1); - Subject.Delete(_baiscType.Id); + Subject.Delete(_basicType.Id); Subject.All().Should().BeEmpty(); } [Test] public void should_be_able_to_find_by_id() { - Subject.Insert(_baiscType); - Subject.Get(_baiscType.Id) + Subject.Insert(_basicType); + Subject.Get(_basicType.Id) .ShouldHave() .AllProperties() - .EqualTo(_baiscType); + .EqualTo(_basicType); } [Test] diff --git a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs index 42ca25dac..a42a03470 100644 --- a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs +++ b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs @@ -7,32 +7,29 @@ using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.Datastore; using NzbDrone.Core.Test.Framework; -using ServiceStack.OrmLite; namespace NzbDrone.Core.Test.Datastore { [TestFixture] - public class ObjectDatabaseFixture : DbTest, BaiscType> + public class ObjectDatabaseFixture : DbTest, BasicType> { - private BaiscType _sampleType; + private BasicType _sampleType; [SetUp] public void SetUp() { - _sampleType = Builder + _sampleType = Builder .CreateNew() .With(s => s.Id = 0) .Build(); - Mocker.Resolve().CreateTable(); - } [Test] public void should_be_able_to_write_to_database() { Subject.Insert(_sampleType); - Db.All().Should().HaveCount(1); + Db.All().Should().HaveCount(1); } [Test] @@ -52,7 +49,7 @@ namespace NzbDrone.Core.Test.Datastore [Test] public void should_be_able_to_store_empty_list() { - var series = new List(); + var series = new List(); Subject.InsertMany(series); } @@ -71,7 +68,7 @@ namespace NzbDrone.Core.Test.Datastore _sampleType.Id = 0; Subject.Insert(_sampleType); - Db.All().Should().HaveCount(1); + Db.All().Should().HaveCount(1); _sampleType.Id.Should().Be(1); } @@ -83,7 +80,7 @@ namespace NzbDrone.Core.Test.Datastore { _sampleType.Id = 0; Subject.Insert(_sampleType); - var item = Db.All(); + var item = Db.All(); item.Should().HaveCount(1); item.First().Id.Should().NotBe(0); @@ -95,7 +92,7 @@ namespace NzbDrone.Core.Test.Datastore public void should_be_able_to_find_object_by_id() { Subject.Insert(_sampleType); - var item = Db.All().Single(c => c.Id == _sampleType.Id); + var item = Db.All().Single(c => c.Id == _sampleType.Id); item.Id.Should().NotBe(0); item.Id.Should().Be(_sampleType.Id); @@ -105,7 +102,7 @@ namespace NzbDrone.Core.Test.Datastore [Test] public void update_field_should_only_update_that_filed() { - var childModel = new BaiscType + var childModel = new BasicType { Address = "Address", Name = "Name", @@ -121,9 +118,9 @@ namespace NzbDrone.Core.Test.Datastore Subject.UpdateFields(childModel, t => t.Name); - Db.All().Single().Address.Should().Be("Address"); - Db.All().Single().Name.Should().Be("B"); - Db.All().Single().Tilte.Should().Be("Title"); + Db.All().Single().Address.Should().Be("Address"); + Db.All().Single().Name.Should().Be("B"); + Db.All().Single().Tilte.Should().Be("Title"); } diff --git a/NzbDrone.Core.Test/Framework/DbTest.cs b/NzbDrone.Core.Test/Framework/DbTest.cs index 8dad18197..0bc4e78c9 100644 --- a/NzbDrone.Core.Test/Framework/DbTest.cs +++ b/NzbDrone.Core.Test/Framework/DbTest.cs @@ -1,11 +1,12 @@ using System; using System.Collections.Generic; using System.Data; +using System.IO; using System.Linq; +using Marr.Data; using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Core.Datastore; -using ServiceStack.OrmLite; namespace NzbDrone.Core.Test.Framework { @@ -61,8 +62,12 @@ namespace NzbDrone.Core.Test.Framework public abstract class DbTest : CoreTest { - private IDatabase _db; - protected IDatabase Db + private string _dbName; + + private ITestDatabase _db; + private IDatabase _database; + + protected ITestDatabase Db { get { @@ -75,10 +80,15 @@ namespace NzbDrone.Core.Test.Framework private void WithObjectDb(bool memory = true) { + + _dbName = DateTime.Now.Ticks.ToString() + ".db"; + + MapRepository.Instance.EnableTraceLogging = true; + var factory = new DbFactory(); - var dbConnection = factory.Create(); - _db = new TestDatabase(dbConnection); - Mocker.SetConstant(dbConnection); + _database = factory.Create(_dbName); + _db = new TestTestDatabase(_database); + Mocker.SetConstant(_database); } [SetUp] @@ -87,51 +97,68 @@ namespace NzbDrone.Core.Test.Framework WithObjectDb(); } + [TearDown] + public void TearDown() + { + var files = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.db"); + + foreach (var file in files) + { + try + { + File.Delete(file); + } + catch (Exception) + { + + } + } + } } - public interface IDatabase + public interface ITestDatabase { - void InsertMany(IEnumerable items) where T : new(); - void Insert(T item) where T : new(); - IEnumerable All() where T : new(); - void Update(T childModel) where T : new(); - void Delete(T childModel) where T : new(); + void InsertMany(IEnumerable items) where T : ModelBase, new(); + void Insert(T item) where T : ModelBase, new(); + IEnumerable All() where T : ModelBase, new(); + void Update(T childModel) where T : ModelBase, new(); + void Delete(T childModel) where T : ModelBase, new(); } - public class TestDatabase : IDatabase + public class TestTestDatabase : ITestDatabase { - private readonly IDbConnection _dbConnection; + private readonly IDatabase _dbConnection; - public TestDatabase(IDbConnection dbConnection) + public TestTestDatabase(IDatabase dbConnection) { _dbConnection = dbConnection; } - public void InsertMany(IEnumerable items) where T : new() + public void InsertMany(IEnumerable items) where T : ModelBase, new() { - _dbConnection.InsertAll(items); + new BasicRepository(_dbConnection).InsertMany(items.ToList()); } - public void Insert(T item) where T : new() + public void Insert(T item) where T : ModelBase, new() { - _dbConnection.Insert(item); + new BasicRepository(_dbConnection).Insert(item); } - public IEnumerable All() where T : new() + public IEnumerable All() where T : ModelBase, new() { - return _dbConnection.Select(); + return new BasicRepository(_dbConnection).All(); } - public void Update(T childModel) where T : new() + public void Update(T childModel) where T : ModelBase, new() { - _dbConnection.Update(childModel); + new BasicRepository(_dbConnection).Update(childModel); } - public void Delete(T childModel) where T : new() + public void Delete(T childModel) where T : ModelBase, new() { - _dbConnection.Delete(childModel); + new BasicRepository(_dbConnection).Delete(childModel); } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index b63cca0d2..ace617aae 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -77,6 +77,9 @@ False ..\packages\FluentAssertions.2.0.0.1\lib\net40\FluentAssertions.dll + + ..\packages\MarrDataMapper.3.17.4747.34302\lib\Marr.Data.dll + False @@ -89,9 +92,6 @@ ..\packages\Unity.2.1.505.2\lib\NET35\Microsoft.Practices.Unity.Configuration.dll - - ..\packages\ServiceStack.OrmLite.Sqlite.Mono.3.9.42\lib\net35\Mono.Data.Sqlite.dll - ..\packages\Moq.4.0.10827\lib\NET40\Moq.dll @@ -114,26 +114,6 @@ False ..\packages\Prowlin.0.9.4456.26422\lib\net40\Prowlin.dll - - False - ..\packages\ServiceStack.Common.3.9.42\lib\net35\ServiceStack.Common.dll - - - ..\packages\ServiceStack.Common.3.9.42\lib\net35\ServiceStack.Interfaces.dll - True - - - ..\packages\ServiceStack.OrmLite.Sqlite.Mono.3.9.42\lib\net35\ServiceStack.OrmLite.dll - True - - - ..\packages\ServiceStack.OrmLite.Sqlite.Mono.3.9.42\lib\net35\ServiceStack.OrmLite.Sqlite.dll - True - - - False - ..\packages\ServiceStack.Text.3.9.42\lib\net35\ServiceStack.Text.dll - False ..\packages\SignalR.Server.0.5.3\lib\net40\SignalR.dll diff --git a/NzbDrone.Core.Test/packages.config b/NzbDrone.Core.Test/packages.config index 75d53ccde..03b747121 100644 --- a/NzbDrone.Core.Test/packages.config +++ b/NzbDrone.Core.Test/packages.config @@ -11,9 +11,6 @@ - - - \ No newline at end of file diff --git a/NzbDrone.Core/Configuration/Config.cs b/NzbDrone.Core/Configuration/Config.cs index 211d5055d..53ff3f921 100644 --- a/NzbDrone.Core/Configuration/Config.cs +++ b/NzbDrone.Core/Configuration/Config.cs @@ -1,11 +1,9 @@ using NzbDrone.Core.Datastore; -using ServiceStack.DataAnnotations; namespace NzbDrone.Core.Configuration { public class Config : ModelBase { - [Index(Unique = true)] public string Key { get; set; } public string Value { get; set; } } diff --git a/NzbDrone.Core/Configuration/ConfigRepository.cs b/NzbDrone.Core/Configuration/ConfigRepository.cs index 3c282dee6..c3acb5785 100644 --- a/NzbDrone.Core/Configuration/ConfigRepository.cs +++ b/NzbDrone.Core/Configuration/ConfigRepository.cs @@ -12,7 +12,7 @@ namespace NzbDrone.Core.Configuration public class ConfigRepository : BasicRepository, IConfigRepository { - public ConfigRepository(IDbConnection database) + public ConfigRepository(IDatabase database) : base(database) { } @@ -20,7 +20,7 @@ namespace NzbDrone.Core.Configuration public Config Get(string key) { - return SingleOrDefault(c => c.Key == key); + return Queryable().SingleOrDefault(c => c.Key == key); } diff --git a/NzbDrone.Core/Datastore/BasicRepository.cs b/NzbDrone.Core/Datastore/BasicRepository.cs index 5b175978f..a6112c81c 100644 --- a/NzbDrone.Core/Datastore/BasicRepository.cs +++ b/NzbDrone.Core/Datastore/BasicRepository.cs @@ -3,7 +3,9 @@ using System.Collections.Generic; using System.Data; using System.Linq; using System.Linq.Expressions; -using ServiceStack.OrmLite; +using Marr.Data; +using Marr.Data.QGen; + namespace NzbDrone.Core.Datastore { @@ -11,12 +13,8 @@ namespace NzbDrone.Core.Datastore { IEnumerable All(); int Count(); - bool Any(Expression> predicate); TModel Get(int id); - TModel Single(Expression> predicate); TModel SingleOrDefault(); - TModel SingleOrDefault(Expression> predicate); - List Where(Expression> predicate); TModel Insert(TModel model); TModel Update(TModel model); TModel Upsert(TModel model); @@ -29,38 +27,39 @@ namespace NzbDrone.Core.Datastore bool HasItems(); void DeleteMany(IEnumerable ids); void UpdateFields(TModel model, Expression> onlyFields); - List Where(SqlExpressionVisitor expression); } public class BasicRepository : IBasicRepository where TModel : ModelBase, new() { - private readonly IDbConnection _database; + private readonly IDataMapper _dataMapper; - public BasicRepository(IDbConnection database) + public BasicRepository(IDatabase database) { - _database = database; + _dataMapper = database.DataMapper; } - public IEnumerable All() + protected QueryBuilder Queryable() { - return _database.Select(); + return _dataMapper.Query(); } - public int Count() + public IEnumerable All() { - return (int)_database.Count(); + return _dataMapper.Query().ToList(); } - public bool Any(Expression> predicate) + public int Count() { - return _database.Exists(predicate); + return _dataMapper.Query().Count(); } public TModel Get(int id) { try { - return _database.GetById(id); + var c = _dataMapper.Query().FromTable(typeof(TModel).Name); + + return null; } catch (ArgumentNullException e) { @@ -69,36 +68,12 @@ namespace NzbDrone.Core.Datastore } - public TModel Single(Expression> predicate) - { - return _database.Select(predicate).Single(); - } public TModel SingleOrDefault() { return All().Single(); } - public TModel Single() - { - throw new System.NotImplementedException(); - } - - public TModel SingleOrDefault(Expression> predicate) - { - return _database.Select(predicate).SingleOrDefault(); - } - - public List Where(Expression> predicate) - { - return _database.Select(predicate); - } - - public List Where(SqlExpressionVisitor expression) - { - return _database.Select(expression); - } - public TModel Insert(TModel model) { if (model.Id != 0) @@ -106,8 +81,7 @@ namespace NzbDrone.Core.Datastore throw new InvalidOperationException("Can't insert model with existing ID"); } - _database.Insert(model); - model.Id = (int)_database.GetLastInsertId(); + var id = _dataMapper.Insert(model); return model; } @@ -118,56 +92,61 @@ namespace NzbDrone.Core.Datastore throw new InvalidOperationException("Can't update model with ID 0"); } - _database.Update(model); + _dataMapper.Update(model, c => c.Id == model.Id); return model; } public void Delete(TModel model) { - _database.Delete(model); + _dataMapper.Delete(c => c.Id == model.Id); } public void InsertMany(IList models) { - _database.InsertAll(models); + foreach (var model in models) + { + Insert(model); + } } public void UpdateMany(IList models) { - _database.UpdateAll(models); + foreach (var model in models) + { + Update(model); + } } public void DeleteMany(List models) { - _database.DeleteAll(models); + models.ForEach(Delete); } public TModel Upsert(TModel model) { if (model.Id == 0) { - _database.Insert(model); - model.Id = (int)_database.GetLastInsertId(); + Insert(model); return model; } - _database.Update(model); + Update(model); return model; } public void Delete(int id) { - _database.DeleteById(id); + _dataMapper.Delete(c => c.Id == id); } public void DeleteMany(IEnumerable ids) { - _database.DeleteByIds(ids); + ids.ToList().ForEach(Delete); } public void Purge() { - _database.DeleteAll(); + _dataMapper.Delete(c => c.Id > -1); } public bool HasItems() @@ -182,7 +161,7 @@ namespace NzbDrone.Core.Datastore throw new InvalidOperationException("Attempted to updated model without ID"); } - _database.UpdateOnly(model, onlyFields, m => m.Id == model.Id); + // _database.UpdateOnly(model, onlyFields, m => m.Id == model.Id); } } } diff --git a/NzbDrone.Core/Datastore/Database.cs b/NzbDrone.Core/Datastore/Database.cs new file mode 100644 index 000000000..2786600f1 --- /dev/null +++ b/NzbDrone.Core/Datastore/Database.cs @@ -0,0 +1,21 @@ +using System; +using Marr.Data; + +namespace NzbDrone.Core.Datastore +{ + public interface IDatabase + { + IDataMapper DataMapper { get; } + } + + public class Database : IDatabase + { + + public Database(IDataMapper dataMapper) + { + DataMapper = dataMapper; + } + + public IDataMapper DataMapper { get; private set; } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Datastore/DbFactory.cs b/NzbDrone.Core/Datastore/DbFactory.cs index 171aec337..357f3f2f1 100644 --- a/NzbDrone.Core/Datastore/DbFactory.cs +++ b/NzbDrone.Core/Datastore/DbFactory.cs @@ -1,25 +1,21 @@ using System; using System.Data; -using ServiceStack.OrmLite; -using ServiceStack.OrmLite.Sqlite; +using Marr.Data; +using Mono.Data.Sqlite; + namespace NzbDrone.Core.Datastore { public interface IDbFactory { - IDbConnection Create(string dbPath = null); + IDatabase Create(string dbPath = null); } public class DbFactory : IDbFactory { private const string MemoryConnectionString = "Data Source=:memory:;Version=3;New=True;"; - static DbFactory() - { - OrmLiteConfig.DialectProvider = new SqliteOrmLiteDialectProvider(); - } - - public IDbConnection Create(string dbPath = null) + public IDatabase Create(string dbPath = null) { var connectionString = MemoryConnectionString; @@ -29,15 +25,11 @@ namespace NzbDrone.Core.Datastore } MigrationHelper.MigrateToLatest(connectionString, MigrationType.Main); + var dataMapper = new DataMapper(SqliteFactory.Instance, connectionString); + return new Database(dataMapper); + } - OrmLiteConfig.DialectProvider = new SqliteOrmLiteDialectProvider(); - var dbFactory = new OrmLiteConnectionFactory(connectionString); - var connection = dbFactory.Open(); - - Migration.CreateTables(connection); - return connection; - } private string GetConnectionString(string dbPath) { diff --git a/NzbDrone.Core/Datastore/Migration.cs b/NzbDrone.Core/Datastore/Migration.cs index a43391811..8e381389f 100644 --- a/NzbDrone.Core/Datastore/Migration.cs +++ b/NzbDrone.Core/Datastore/Migration.cs @@ -1,22 +1,10 @@ using System.Data; using System.Linq; -using ServiceStack.OrmLite; + namespace NzbDrone.Core.Datastore { public static class Migration { - public static void CreateTables(IDbConnection dbConnection) - { - var types = typeof(ModelBase).Assembly.GetTypes(); - - var models = types.Where(c => c.BaseType == typeof(ModelBase)); - - foreach (var model in models) - { - dbConnection.CreateTable(true, model); - } - } - } } diff --git a/NzbDrone.Core/Datastore/ModelBase.cs b/NzbDrone.Core/Datastore/ModelBase.cs index 264fff0b8..5176ab4ad 100644 --- a/NzbDrone.Core/Datastore/ModelBase.cs +++ b/NzbDrone.Core/Datastore/ModelBase.cs @@ -1,12 +1,12 @@ -using System.Diagnostics; -using ServiceStack.DataAnnotations; +using System.Data; +using System.Diagnostics; +using Marr.Data; namespace NzbDrone.Core.Datastore { [DebuggerDisplay("{GetType()} ID = {Id}")] public abstract class ModelBase { - [AutoIncrement] public int Id { get; set; } } } diff --git a/NzbDrone.Core/ExternalNotification/ExternalNotificationRepository.cs b/NzbDrone.Core/ExternalNotification/ExternalNotificationRepository.cs index 667f28af9..6fe3326be 100644 --- a/NzbDrone.Core/ExternalNotification/ExternalNotificationRepository.cs +++ b/NzbDrone.Core/ExternalNotification/ExternalNotificationRepository.cs @@ -1,4 +1,5 @@ using System.Data; +using System.Linq; using NzbDrone.Core.Datastore; namespace NzbDrone.Core.ExternalNotification @@ -10,14 +11,14 @@ namespace NzbDrone.Core.ExternalNotification public class ExternalNotificationRepository : BasicRepository, IExternalNotificationRepository { - public ExternalNotificationRepository(IDbConnection database) + public ExternalNotificationRepository(IDatabase database) : base(database) { } public ExternalNotificationDefinition Get(string name) { - return SingleOrDefault(c => c.Name.ToLower() == name.ToLower()); + return Queryable().SingleOrDefault(c => c.Name.ToLower() == name.ToLower()); } } } \ No newline at end of file diff --git a/NzbDrone.Core/History/HistoryRepository.cs b/NzbDrone.Core/History/HistoryRepository.cs index 6774d0bd4..fecde87dd 100644 --- a/NzbDrone.Core/History/HistoryRepository.cs +++ b/NzbDrone.Core/History/HistoryRepository.cs @@ -14,21 +14,21 @@ namespace NzbDrone.Core.History public class HistoryRepository : BasicRepository, IHistoryRepository { - public HistoryRepository(IDbConnection database) + public HistoryRepository(IDatabase database) : base(database) { } public void Trim() { - var oldIds = Where(c => c.Date < DateTime.Now.AddDays(-30).Date).Select(c => c.Id); + var oldIds = Queryable().Where(c => c.Date < DateTime.Now.AddDays(-30).Date).Select(c => c.Id); DeleteMany(oldIds); } public QualityModel GetBestQualityInHistory(int episodeId) { - var history = Where(c => c.EpisodeId == episodeId) + var history = Queryable().Where(c => c.EpisodeId == episodeId) .OrderByDescending(c => c.Quality).FirstOrDefault(); if (history != null) diff --git a/NzbDrone.Core/Indexers/IndexerRepository.cs b/NzbDrone.Core/Indexers/IndexerRepository.cs index f06af337f..7d7c9be33 100644 --- a/NzbDrone.Core/Indexers/IndexerRepository.cs +++ b/NzbDrone.Core/Indexers/IndexerRepository.cs @@ -1,5 +1,6 @@ using System; using System.Data; +using System.Linq; using NzbDrone.Core.Datastore; namespace NzbDrone.Core.Indexers @@ -11,14 +12,14 @@ namespace NzbDrone.Core.Indexers public class IndexerRepository : BasicRepository, IIndexerRepository { - public IndexerRepository(IDbConnection database) + public IndexerRepository(IDatabase database) : base(database) { } public Indexer Find(Type type) { - return Single(i => i.Type == type.ToString()); + return Queryable().Single(i => i.Type == type.ToString()); } } } diff --git a/NzbDrone.Core/Indexers/NewznabRepository.cs b/NzbDrone.Core/Indexers/NewznabRepository.cs index 4f20cfc01..e591af314 100644 --- a/NzbDrone.Core/Indexers/NewznabRepository.cs +++ b/NzbDrone.Core/Indexers/NewznabRepository.cs @@ -14,13 +14,13 @@ namespace NzbDrone.Core.Indexers public class NewznabRepository : BasicRepository, INewznabRepository { - public NewznabRepository(IDbConnection database) : base(database) + public NewznabRepository(IDatabase database) : base(database) { } public IEnumerable Enabled() { - return Where(n => n.Enable); + return Queryable().Where(n => n.Enabled); } } } diff --git a/NzbDrone.Core/Instrumentation/LogRepository.cs b/NzbDrone.Core/Instrumentation/LogRepository.cs index 1d4d152c5..134531c84 100644 --- a/NzbDrone.Core/Instrumentation/LogRepository.cs +++ b/NzbDrone.Core/Instrumentation/LogRepository.cs @@ -12,14 +12,14 @@ namespace NzbDrone.Core.Instrumentation public class LogRepository : BasicRepository, ILogRepository { - public LogRepository(IDbConnection database) + public LogRepository(IDatabase database) : base(database) { } public void Trim() { - var oldIds = Where(c => c.Time < DateTime.Now.AddDays(-30).Date).Select(c => c.Id); + var oldIds = Queryable().Where(c => c.Time < DateTime.Now.AddDays(-30).Date).Select(c => c.Id); DeleteMany(oldIds); } } diff --git a/NzbDrone.Core/Jobs/JobRepository.cs b/NzbDrone.Core/Jobs/JobRepository.cs index 3094d74df..70185839f 100644 --- a/NzbDrone.Core/Jobs/JobRepository.cs +++ b/NzbDrone.Core/Jobs/JobRepository.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Data; using System.Linq; using NLog; using NzbDrone.Core.Datastore; @@ -19,7 +18,7 @@ namespace NzbDrone.Core.Jobs private readonly IEnumerable _jobs; private readonly Logger _logger; - public JobRepository(IDbConnection database, IEnumerable jobs, Logger logger) + public JobRepository(IDatabase database, IEnumerable jobs, Logger logger) : base(database) { _jobs = jobs; @@ -28,13 +27,13 @@ namespace NzbDrone.Core.Jobs public JobDefinition GetDefinition(Type type) { - return Single(c => c.Type == type.FullName); + return Queryable().Single(c => c.TypeName == type.FullName); } public IList GetPendingJobs() { - return Where(c => c.Enable && c.LastExecution < DateTime.Now.AddMinutes(-c.Interval)).ToList(); + return Queryable().Where(c => c.Enable && c.LastExecution < DateTime.Now.AddMinutes(-c.Interval)).ToList(); } public void Init() @@ -73,4 +72,4 @@ namespace NzbDrone.Core.Jobs } } } -} \ No newline at end of file +} diff --git a/NzbDrone.Core/MediaFiles/MediaFileRepository.cs b/NzbDrone.Core/MediaFiles/MediaFileRepository.cs index 8c15e243a..2493ea591 100644 --- a/NzbDrone.Core/MediaFiles/MediaFileRepository.cs +++ b/NzbDrone.Core/MediaFiles/MediaFileRepository.cs @@ -15,7 +15,7 @@ namespace NzbDrone.Core.MediaFiles public class MediaFileRepository : BasicRepository, IMediaFileRepository { - public MediaFileRepository(IDbConnection database) + public MediaFileRepository(IDatabase database) : base(database) { } @@ -23,17 +23,17 @@ namespace NzbDrone.Core.MediaFiles public EpisodeFile GetFileByPath(string path) { - return SingleOrDefault(c => c.Path == path); + return Queryable().SingleOrDefault(c => c.Path == path); } public List GetFilesBySeries(int seriesId) { - return Where(c => c.SeriesId == seriesId).ToList(); + return Queryable().Where(c => c.SeriesId == seriesId).ToList(); } public List GetFilesBySeason(int seriesId, int seasonNumber) { - return Where(c => c.SeriesId == seriesId && c.SeasonNumber == seasonNumber).ToList(); + return Queryable().Where(c => c.SeriesId == seriesId && c.SeasonNumber == seasonNumber).ToList(); } } diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index fce2e8096..98c40be8a 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -132,6 +132,8 @@ ..\packages\FluentMigrator.1.0.6.0\tools\FluentMigrator.Runner.dll + + ..\packages\MarrDataMapper.3.17.4747.34302\lib\FastReflection.dll ..\packages\Growl.0.6\lib\Growl.Connector.dll @@ -142,12 +144,16 @@ ..\packages\DotNetZip.1.9.1.8\lib\net20\Ionic.Zip.dll + + ..\packages\MarrDataMapper.3.17.4747.34302\lib\Marr.Data.dll + ..\packages\MediaInfoNet.0.3\lib\MediaInfoDotNet.dll - - ..\packages\ServiceStack.OrmLite.Sqlite.Mono.3.9.42\lib\net35\Mono.Data.Sqlite.dll + + False + ..\Libraries\Sqlite\Mono.Data.Sqlite.dll False @@ -163,21 +169,6 @@ ..\packages\RestSharp.104.1\lib\net4\RestSharp.dll - - ..\packages\ServiceStack.Common.3.9.42\lib\net35\ServiceStack.Common.dll - - - ..\packages\ServiceStack.Common.3.9.42\lib\net35\ServiceStack.Interfaces.dll - - - ..\packages\ServiceStack.OrmLite.Sqlite.Mono.3.9.42\lib\net35\ServiceStack.OrmLite.dll - - - ..\packages\ServiceStack.OrmLite.Sqlite.Mono.3.9.42\lib\net35\ServiceStack.OrmLite.Sqlite.dll - - - ..\packages\ServiceStack.Text.3.9.42\lib\net35\ServiceStack.Text.dll - ..\packages\SignalR.Server.0.5.3\lib\net40\SignalR.dll @@ -214,6 +205,7 @@ + @@ -610,4 +602,4 @@ --> - \ No newline at end of file + diff --git a/NzbDrone.Core/Qualities/QualityProfileRepository.cs b/NzbDrone.Core/Qualities/QualityProfileRepository.cs index c57e2188a..c36b8f6c4 100644 --- a/NzbDrone.Core/Qualities/QualityProfileRepository.cs +++ b/NzbDrone.Core/Qualities/QualityProfileRepository.cs @@ -14,7 +14,7 @@ namespace NzbDrone.Core.Qualities public class QualityProfileRepository : BasicRepository, IQualityProfileRepository { - public QualityProfileRepository(IDbConnection database) + public QualityProfileRepository(IDatabase database) : base(database) { } diff --git a/NzbDrone.Core/Qualities/QualitySizeRepository.cs b/NzbDrone.Core/Qualities/QualitySizeRepository.cs index fe6f4bcb5..141247692 100644 --- a/NzbDrone.Core/Qualities/QualitySizeRepository.cs +++ b/NzbDrone.Core/Qualities/QualitySizeRepository.cs @@ -11,14 +11,14 @@ namespace NzbDrone.Core.Qualities public class QualitySizeRepository : BasicRepository, IQualitySizeRepository { - public QualitySizeRepository(IDbConnection database) + public QualitySizeRepository(IDatabase database) : base(database) { } public QualitySize GetByQualityId(int qualityId) { - return Single(q => q.QualityId == qualityId); + return Queryable().Single(q => q.QualityId == qualityId); } } } diff --git a/NzbDrone.Core/ReferenceData/SceneMappingRepository.cs b/NzbDrone.Core/ReferenceData/SceneMappingRepository.cs index b05b12741..db27c38a3 100644 --- a/NzbDrone.Core/ReferenceData/SceneMappingRepository.cs +++ b/NzbDrone.Core/ReferenceData/SceneMappingRepository.cs @@ -13,19 +13,19 @@ namespace NzbDrone.Core.ReferenceData public class SceneMappingRepository : BasicRepository, ISceneMappingRepository { - public SceneMappingRepository(IDbConnection database) + public SceneMappingRepository(IDatabase database) : base(database) { } public SceneMapping FindByTvdbId(int tvdbId) { - return SingleOrDefault(c => c.TvdbId == tvdbId); + return Queryable().SingleOrDefault(c => c.TvdbId == tvdbId); } public SceneMapping FindByCleanTitle(string cleanTitle) { - return SingleOrDefault(c => c.CleanTitle == cleanTitle); + return Queryable().SingleOrDefault(c => c.CleanTitle == cleanTitle); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Tv/EpisodeRepository.cs b/NzbDrone.Core/Tv/EpisodeRepository.cs index c8eb94002..51beb68d5 100644 Binary files a/NzbDrone.Core/Tv/EpisodeRepository.cs and b/NzbDrone.Core/Tv/EpisodeRepository.cs differ diff --git a/NzbDrone.Core/Tv/SeasonRepository.cs b/NzbDrone.Core/Tv/SeasonRepository.cs index 43d183194..890d71e21 100644 --- a/NzbDrone.Core/Tv/SeasonRepository.cs +++ b/NzbDrone.Core/Tv/SeasonRepository.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; using NzbDrone.Core.Datastore; -using ServiceStack.OrmLite; + namespace NzbDrone.Core.Tv { @@ -18,33 +18,33 @@ namespace NzbDrone.Core.Tv { private readonly IDbConnection _database; - public SeasonRepository(IDbConnection database) + public SeasonRepository(IDatabase database) : base(database) { } public IList GetSeasonNumbers(int seriesId) { - return _database.List("SELECT SeasonNumber WHERE SeriesId = {0}", seriesId); + return Queryable().Where(c => c.SeriesId == seriesId).Select(c => c.SeriesId).ToList(); } public Season Get(int seriesId, int seasonNumber) { - return _database.Select(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber).Single(); + return Queryable().Single(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber); } public bool IsIgnored(int seriesId, int seasonNumber) { - var season = _database.Select(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber).SingleOrDefault(); + var season = Queryable().SingleOrDefault(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber); - if(season == null) return false; + if (season == null) return false; return season.Ignored; } public List GetSeasonBySeries(int seriesId) { - return _database.Select(s => s.SeriesId == seriesId); + return Queryable().Where(s => s.SeriesId == seriesId); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Tv/SeriesRepository.cs b/NzbDrone.Core/Tv/SeriesRepository.cs index a6386fbde..8f1297a49 100644 --- a/NzbDrone.Core/Tv/SeriesRepository.cs +++ b/NzbDrone.Core/Tv/SeriesRepository.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Data; +using System.Linq; using NzbDrone.Core.Datastore; namespace NzbDrone.Core.Tv @@ -15,29 +16,29 @@ namespace NzbDrone.Core.Tv public class SeriesRepository : BasicRepository, ISeriesRepository { - public SeriesRepository(IDbConnection database) + public SeriesRepository(IDatabase database) : base(database) { } public bool SeriesPathExists(string path) { - return Any(c => c.Path == path); + return Queryable().Any(c => c.Path == path); } public List Search(string title) { - return Where(s => s.Title.Contains(title)); + return Queryable().Where(s => s.Title.Contains(title)); } public Series GetByTitle(string cleanTitle) { - return SingleOrDefault(s => s.CleanTitle.Equals(cleanTitle)); + return Queryable().SingleOrDefault(s => s.CleanTitle.Equals(cleanTitle)); } public Series FindByTvdbId(int tvdbId) { - return SingleOrDefault(s => s.TvDbId.Equals(tvdbId)); + return Queryable().SingleOrDefault(s => s.TvDbId.Equals(tvdbId)); } public void SetSeriesType(int seriesId, SeriesTypes seriesType) diff --git a/NzbDrone.Core/packages.config b/NzbDrone.Core/packages.config index 4a760c222..ac76e5c2b 100644 --- a/NzbDrone.Core/packages.config +++ b/NzbDrone.Core/packages.config @@ -4,15 +4,13 @@ + - - - diff --git a/NzbDrone.ncrunchsolution b/NzbDrone.ncrunchsolution index c725a019c..969da6dd4 100644 --- a/NzbDrone.ncrunchsolution +++ b/NzbDrone.ncrunchsolution @@ -2,6 +2,7 @@ 1 True true + true UseDynamicAnalysis Disabled Disabled