diff --git a/NzbDrone.Core.Test/RootDirProviderTest.cs b/NzbDrone.Core.Test/RootDirProviderTest.cs index 796709dc2..e00c606bb 100644 --- a/NzbDrone.Core.Test/RootDirProviderTest.cs +++ b/NzbDrone.Core.Test/RootDirProviderTest.cs @@ -18,20 +18,20 @@ namespace NzbDrone.Core.Test public class RootDirProviderTest : TestBase { - [Test] public void GetRootDirs() { //Setup - var sonicRepo = MockLib.GetEmptyRepository(); - sonicRepo.Add(new RootDir { Path = @"C:\TV" }); - sonicRepo.Add(new RootDir { Path = @"C:\TV2" }); - var mocker = new AutoMoqer(); - mocker.GetMock() - .Setup(f => f.All()) - .Returns(sonicRepo.All); + var emptyDatabase = MockLib.GetEmptyDatabase(); + mocker.SetConstant(emptyDatabase); + emptyDatabase.Insert(new RootDir { Path = @"C:\TV" }); + emptyDatabase.Insert(new RootDir { Path = @"C:\TV2" }); + + //mocker.GetMock() + // .Setup(f => f.All()) + // .Returns(sonicRepo.All); //Act var result = mocker.Resolve().GetAll(); @@ -46,7 +46,7 @@ namespace NzbDrone.Core.Test { //Setup var mocker = new AutoMoqer(); - mocker.SetConstant(MockLib.GetEmptyRepository()); + mocker.SetConstant(MockLib.GetEmptyDatabase()); //Act var rootDirProvider = mocker.Resolve(); @@ -68,7 +68,7 @@ namespace NzbDrone.Core.Test { //Setup var mocker = new AutoMoqer(); - mocker.SetConstant(MockLib.GetEmptyRepository()); + mocker.SetConstant(MockLib.GetEmptyDatabase()); //Act @@ -88,7 +88,7 @@ namespace NzbDrone.Core.Test { //Setup var mocker = new AutoMoqer(); - mocker.SetConstant(MockLib.GetEmptyRepository()); + mocker.SetConstant(MockLib.GetEmptyDatabase()); //Act var rootDirProvider = mocker.Resolve(); @@ -105,7 +105,7 @@ namespace NzbDrone.Core.Test { //Setup var mocker = new AutoMoqer(); - mocker.SetConstant(MockLib.GetEmptyRepository()); + mocker.SetConstant(MockLib.GetEmptyDatabase()); const int id = 1; const string path = @"C:\TV"; diff --git a/NzbDrone.Core/Datastore/Migrations/Migration.cs b/NzbDrone.Core/Datastore/Migrations/Migration.cs index b26e4cd12..b9a527c9b 100644 --- a/NzbDrone.Core/Datastore/Migrations/Migration.cs +++ b/NzbDrone.Core/Datastore/Migrations/Migration.cs @@ -91,7 +91,7 @@ namespace NzbDrone.Core.Datastore.Migrations new Column("Value", DbType.String, ColumnProperty.NotNull), }); - Database.AddTable("EpisodeFiles", "SQLite", new[] + Database.AddTable("History", "SQLite", new[] { new Column("HistoryId", DbType.Int64, ColumnProperty.NotNull), new Column("EpisodeId", DbType.Int32, ColumnProperty.NotNull), @@ -102,6 +102,12 @@ namespace NzbDrone.Core.Datastore.Migrations new Column("IsProper", DbType.Boolean, ColumnProperty.NotNull), new Column("Indexer", DbType.String, ColumnProperty.NotNull) }); + + Database.AddTable("RootDirs", "SQLite", new[] + { + new Column("Id", DbType.Int32, ColumnProperty.PrimaryKey), + new Column("Path", DbType.String, ColumnProperty.NotNull), + }); } public override void Down() diff --git a/NzbDrone.Core/Providers/RootDirProvider.cs b/NzbDrone.Core/Providers/RootDirProvider.cs index 801267912..5fd0bbc4d 100644 --- a/NzbDrone.Core/Providers/RootDirProvider.cs +++ b/NzbDrone.Core/Providers/RootDirProvider.cs @@ -6,21 +6,22 @@ using Ninject; using NLog; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; +using PetaPoco; using SubSonic.Repository; namespace NzbDrone.Core.Providers { public class RootDirProvider { - private readonly IRepository _repository; + private readonly IDatabase _database; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private readonly DiskProvider _diskProvider; private readonly SeriesProvider _seriesProvider; [Inject] - public RootDirProvider(IRepository repository, SeriesProvider seriesProvider, DiskProvider diskProvider) + public RootDirProvider(IDatabase database, SeriesProvider seriesProvider, DiskProvider diskProvider) { - _repository = repository; + _database = database; _diskProvider = diskProvider; _seriesProvider = seriesProvider; } @@ -29,26 +30,25 @@ namespace NzbDrone.Core.Providers public virtual List GetAll() { - return _repository.All().ToList(); + return _database.Fetch(); } public virtual int Add(RootDir rootDir) { ValidatePath(rootDir); - - return (int)_repository.Add(rootDir); + return Convert.ToInt32(_database.Insert(rootDir)); } public virtual void Remove(int rootDirId) { - _repository.Delete(rootDirId); + _database.Delete(rootDirId); } public virtual void Update(RootDir rootDir) { ValidatePath(rootDir); - _repository.Update(rootDir); + _database.Update(rootDir); } private static void ValidatePath(RootDir rootDir) @@ -61,7 +61,7 @@ namespace NzbDrone.Core.Providers public virtual RootDir GetRootDir(int rootDirId) { - return _repository.Single(rootDirId); + return _database.SingleOrDefault(rootDirId); } public List GetUnmappedFolders(string path) @@ -78,7 +78,6 @@ namespace NzbDrone.Core.Providers return results; } - foreach (string seriesFolder in _diskProvider.GetDirectories(path)) { var cleanPath = Parser.NormalizePath(new DirectoryInfo(seriesFolder).FullName); diff --git a/NzbDrone.Core/Repository/EpisodeFile.cs b/NzbDrone.Core/Repository/EpisodeFile.cs index 386abfbc6..3665a3ca9 100644 --- a/NzbDrone.Core/Repository/EpisodeFile.cs +++ b/NzbDrone.Core/Repository/EpisodeFile.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using NzbDrone.Core.Repository.Quality; using PetaPoco; -using SubSonic.SqlGeneration.Schema; namespace NzbDrone.Core.Repository { @@ -10,7 +9,6 @@ namespace NzbDrone.Core.Repository [PrimaryKey("EpisodeFileId", autoIncrement = true)] public class EpisodeFile { - [SubSonicPrimaryKey] public virtual int EpisodeFileId { get; set; } public virtual int SeriesId { get; set; } @@ -21,11 +19,9 @@ namespace NzbDrone.Core.Repository public long Size { get; set; } public DateTime DateAdded { get; set; } - [SubSonicToManyRelation] [Ignore] public virtual IList Episodes { get; set; } - [SubSonicToOneRelation(ThisClassContainsJoinKey = true)] [Ignore] public virtual Series Series { get; set; } } diff --git a/NzbDrone.Core/Repository/RootDir.cs b/NzbDrone.Core/Repository/RootDir.cs index f06bb2b44..bb93f636c 100644 --- a/NzbDrone.Core/Repository/RootDir.cs +++ b/NzbDrone.Core/Repository/RootDir.cs @@ -1,10 +1,11 @@ -using SubSonic.SqlGeneration.Schema; +using PetaPoco; namespace NzbDrone.Core.Repository { + [TableName("RootDirs")] + [PrimaryKey("Id", autoIncrement = true)] public class RootDir { - [SubSonicPrimaryKey] public virtual int Id { get; set; } public string Path { get; set; } diff --git a/NzbDrone.Core/Repository/SceneMapping.cs b/NzbDrone.Core/Repository/SceneMapping.cs index c7a988368..d51c823d9 100644 --- a/NzbDrone.Core/Repository/SceneMapping.cs +++ b/NzbDrone.Core/Repository/SceneMapping.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; using PetaPoco; -using SubSonic.SqlGeneration.Schema; namespace NzbDrone.Core.Repository { @@ -11,7 +10,6 @@ namespace NzbDrone.Core.Repository [PrimaryKey("CleanTitle", autoIncrement = false)] public class SceneMapping { - [SubSonicPrimaryKey] public virtual string CleanTitle { get; set; } public virtual int SeriesId { get; set; }