From d3be516fb22ed80c781b179e5976b3e51622af3b Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Fri, 3 Jun 2011 18:56:53 -0700 Subject: [PATCH 1/3] removed Season/SeasonProvider, updated dbBenchmark tests. --- NzbDrone.Core.Test/DownloadProviderTest.cs | 3 +- NzbDrone.Core.Test/EpisodeProviderTest.cs | 34 ----- NzbDrone.Core.Test/EpisodeStatusTest.cs | 26 +--- .../Framework/AutoMoq/AutoMoqerTest.cs | 3 +- NzbDrone.Core.Test/Framework/MockLib.cs | 1 - NzbDrone.Core.Test/HistoryProviderTest.cs | 3 - .../InventoryProvider_IsMonitoredTest.cs | 36 +---- NzbDrone.Core.Test/MediaFileProviderTests.cs | 43 +++--- NzbDrone.Core.Test/QualityTest.cs | 3 +- NzbDrone.Core.Test/RepoTest.cs | 1 - NzbDrone.Core.Test/RepositoryProviderTest.cs | 4 +- NzbDrone.Core.Test/dbBenchmark.cs | 144 +++++++++++------- NzbDrone.Core/CentralDispatch.cs | 2 - NzbDrone.Core/Datastore/Migrations.cs | 17 +++ NzbDrone.Core/Instrumentation/NlogWriter.cs | 2 +- NzbDrone.Core/NzbDrone.Core.csproj | 2 - NzbDrone.Core/Providers/EpisodeProvider.cs | Bin 10186 -> 10741 bytes NzbDrone.Core/Providers/InventoryProvider.cs | 10 +- .../Providers/Jobs/ImportNewSeriesJob.cs | 25 ++- NzbDrone.Core/Providers/MediaFileProvider.cs | 21 +-- NzbDrone.Core/Providers/RenameProvider.cs | 33 +--- NzbDrone.Core/Providers/SeasonProvider.cs | 92 ----------- NzbDrone.Core/Providers/SeriesProvider.cs | 8 +- NzbDrone.Core/Repository/Episode.cs | 11 +- NzbDrone.Core/Repository/EpisodeFile.cs | 1 + .../Repository/Quality/QualityProfile.cs | 2 - NzbDrone.Core/Repository/Season.cs | 26 ---- NzbDrone.Core/Repository/Series.cs | 3 - NzbDrone.Web/Controllers/SeriesController.cs | 58 ++++--- NzbDrone.Web/Models/SeasonEditModel.cs | 2 +- NzbDrone.Web/Models/SeriesModel.cs | 3 +- NzbDrone.Web/Views/Series/Details.cshtml | 92 ++++++----- NzbDrone.Web/Views/Series/SingleSeason.cshtml | 2 +- .../Views/Settings/QualityProfileItem.cshtml | 51 ++++--- 34 files changed, 298 insertions(+), 466 deletions(-) delete mode 100644 NzbDrone.Core/Providers/SeasonProvider.cs delete mode 100644 NzbDrone.Core/Repository/Season.cs diff --git a/NzbDrone.Core.Test/DownloadProviderTest.cs b/NzbDrone.Core.Test/DownloadProviderTest.cs index 90123ef86..049c15b40 100644 --- a/NzbDrone.Core.Test/DownloadProviderTest.cs +++ b/NzbDrone.Core.Test/DownloadProviderTest.cs @@ -9,13 +9,14 @@ using NzbDrone.Core.Model; using NzbDrone.Core.Providers; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; +using NzbDrone.Core.Test.Framework; // ReSharper disable InconsistentNaming namespace NzbDrone.Core.Test { [TestFixture] - public class DownloadProviderTest + public class DownloadProviderTest : TestBase { [Test] public void Download_report_should_send_to_sab_and_add_to_history() diff --git a/NzbDrone.Core.Test/EpisodeProviderTest.cs b/NzbDrone.Core.Test/EpisodeProviderTest.cs index bde298464..35dfd4f0e 100644 --- a/NzbDrone.Core.Test/EpisodeProviderTest.cs +++ b/NzbDrone.Core.Test/EpisodeProviderTest.cs @@ -60,40 +60,6 @@ namespace NzbDrone.Core.Test } - [Test] - public void EnsureSeason_is_called_once_per_season() - { - const int seriesId = 71663; - var fakeEpisodes = Builder.CreateNew() - .With(c => c.Episodes = new List(Builder.CreateListOfSize(6). - WhereAll().Have( - l => l.Language = new TvdbLanguage(0, "eng", "a")) - .WhereTheFirst(3).Have(d => d.SeasonNumber = 1).And( - d => d.SeasonId = 11) - .AndTheRemaining().Have(d => d.SeasonNumber = 2).And( - d => d.SeasonId = 22) - .Build()) - ).With(c => c.Id = seriesId).Build(); - - var fakeSeries = Builder.CreateNew().With(c => c.SeriesId = seriesId).Build(); - - - var mocker = new AutoMoqer(); - - mocker.GetMock(MockBehavior.Strict) - .Setup(c => c.GetSeries(seriesId, true)) - .Returns(fakeEpisodes); - - mocker.Resolve().RefreshEpisodeInfo(fakeSeries); - - - mocker.GetMock().Verify(c => c.EnsureSeason(seriesId, 11, 1), Times.Once()); - mocker.GetMock().Verify(c => c.EnsureSeason(seriesId, 22, 2), Times.Once()); - - mocker.VerifyAllMocks(); - } - - [Test] public void new_episodes_only_calls_AddMany() { diff --git a/NzbDrone.Core.Test/EpisodeStatusTest.cs b/NzbDrone.Core.Test/EpisodeStatusTest.cs index 666b793e5..56bca1510 100644 --- a/NzbDrone.Core.Test/EpisodeStatusTest.cs +++ b/NzbDrone.Core.Test/EpisodeStatusTest.cs @@ -21,8 +21,6 @@ namespace NzbDrone.Core.Test public void no_grab_date(int offsetDays, bool hasEpisodes, bool ignored, EpisodeStatusType status) { Episode episode = Builder.CreateNew() - .With(e => e.Season = Builder.CreateNew() - .With(s => s.Monitored = true).Build()) .With(e => e.AirDate = DateTime.Now.AddDays(offsetDays)) .With(e => e.Ignored = ignored) .With(e => e.EpisodeFileId = 0) @@ -39,7 +37,7 @@ namespace NzbDrone.Core.Test [Test] - [TestCase(1, false, false, EpisodeStatusType.NotAired)] + [TestCase(1, false, false, EpisodeStatusType.Missing)] [TestCase(-2, false, false, EpisodeStatusType.Missing)] [TestCase(1, true, false, EpisodeStatusType.Ready)] [TestCase(1, false, true, EpisodeStatusType.Ignored)] @@ -47,10 +45,7 @@ namespace NzbDrone.Core.Test EpisodeStatusType status) { Episode episode = Builder.CreateNew() - .With(e => e.Season = Builder.CreateNew() - .With(s => s.Monitored = true).Build()).With( - e => e.AirDate = DateTime.Now.AddDays(offsetDays)) - .With(e => e.Ignored = ignored) + .With(e => e.Ignored = ignored) .With(e => e.EpisodeFileId = 0) .With(e => e.GrabDate = DateTime.Now.AddDays(-1).AddHours(-1)) .Build(); @@ -74,9 +69,7 @@ namespace NzbDrone.Core.Test EpisodeStatusType status) { Episode episode = Builder.CreateNew() - .With(e => e.Season = Builder.CreateNew() - .With(s => s.Monitored = true).Build()) - .With(e => e.AirDate = DateTime.Now.AddDays(offsetDays)) + .With(e => e.AirDate = DateTime.Now.AddDays(offsetDays)) .With(e => e.Ignored = ignored) .With(e => e.EpisodeFileId = 0) .With(e => e.GrabDate = DateTime.Now.AddDays(-1)) @@ -91,19 +84,16 @@ namespace NzbDrone.Core.Test } [Test] - [TestCase(1, false, false, EpisodeStatusType.Ignored)] - [TestCase(-2, false, false, EpisodeStatusType.Ignored)] - [TestCase(1, false, true, EpisodeStatusType.Ignored)] - public void skipped_season(int offsetDays, bool hasEpisodes, bool ignored, EpisodeStatusType status) + [TestCase(1, true, false, EpisodeStatusType.Ignored)] + [TestCase(-2, true, false, EpisodeStatusType.Ignored)] + [TestCase(1, true, true, EpisodeStatusType.Ready)] + public void ignored_episode(int offsetDays, bool ignored, bool hasEpisodes, EpisodeStatusType status) { Episode episode = Builder.CreateNew() .With(e => e.AirDate = DateTime.Now.AddDays(offsetDays)) .With(e => e.Ignored = ignored) .With(e => e.EpisodeFileId = 0) .With(e => e.GrabDate = null) - .With(e => e.Season = Builder.CreateNew() - .With(s => s.Monitored == false).Build()) - .Build(); if (hasEpisodes) @@ -123,8 +113,6 @@ namespace NzbDrone.Core.Test .With(e => e.Ignored = false) .With(e => e.EpisodeFileId = 0) .With(e => e.GrabDate = null) - .With(e => e.Season = Builder.CreateNew() - .With(s => s.Monitored = true).Build()) .Build(); diff --git a/NzbDrone.Core.Test/Framework/AutoMoq/AutoMoqerTest.cs b/NzbDrone.Core.Test/Framework/AutoMoq/AutoMoqerTest.cs index 481e9b1e2..d2f9cab5d 100644 --- a/NzbDrone.Core.Test/Framework/AutoMoq/AutoMoqerTest.cs +++ b/NzbDrone.Core.Test/Framework/AutoMoq/AutoMoqerTest.cs @@ -3,6 +3,7 @@ using AutoMoq; using Moq; using System; using NUnit.Framework; +using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test { @@ -103,7 +104,7 @@ namespace NzbDrone.Core.Test //Arrange var mocker = new AutoMoqer(); - var constant = new VirtualDependency {PropValue = Guid.NewGuid().ToString()}; + var constant = new VirtualDependency { PropValue = Guid.NewGuid().ToString() }; mocker.SetConstant(constant); diff --git a/NzbDrone.Core.Test/Framework/MockLib.cs b/NzbDrone.Core.Test/Framework/MockLib.cs index 774a4448e..91d316551 100644 --- a/NzbDrone.Core.Test/Framework/MockLib.cs +++ b/NzbDrone.Core.Test/Framework/MockLib.cs @@ -99,7 +99,6 @@ namespace NzbDrone.Core.Test.Framework private static void ForceMigration(IRepository repository) { repository.All().Count(); - repository.All().Count(); repository.All().Count(); repository.All().Count(); repository.All().Count(); diff --git a/NzbDrone.Core.Test/HistoryProviderTest.cs b/NzbDrone.Core.Test/HistoryProviderTest.cs index 96a2fbc42..256e926ad 100644 --- a/NzbDrone.Core.Test/HistoryProviderTest.cs +++ b/NzbDrone.Core.Test/HistoryProviderTest.cs @@ -23,7 +23,6 @@ namespace NzbDrone.Core.Test public void AllItems() { //Setup - Season season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true }; var episode = new Episode { AirDate = DateTime.Today.AddDays(-1), @@ -31,8 +30,6 @@ namespace NzbDrone.Core.Test EpisodeNumber = 5, Overview = "This is an Overview", SeasonNumber = 1, - SeasonId = 4321, - Season = season, SeriesId = 5656 }; diff --git a/NzbDrone.Core.Test/InventoryProvider_IsMonitoredTest.cs b/NzbDrone.Core.Test/InventoryProvider_IsMonitoredTest.cs index 4703a181b..b27526b7a 100644 --- a/NzbDrone.Core.Test/InventoryProvider_IsMonitoredTest.cs +++ b/NzbDrone.Core.Test/InventoryProvider_IsMonitoredTest.cs @@ -116,28 +116,7 @@ namespace NzbDrone.Core.Test mocker.VerifyAllMocks(); } - [Test] - public void ignored_season_should_be_skipped() - { - var mocker = new AutoMoqer(MockBehavior.Strict); - - mocker.GetMock() - .Setup(p => p.FindSeries(It.IsAny())) - .Returns(series); - - mocker.GetMock() - .Setup(p => p.IsIgnored(series.SeriesId, parseResultMulti.SeasonNumber)) - .Returns(true); - - //Act - var result = mocker.Resolve().IsMonitored(parseResultMulti); - - //Assert - Assert.IsFalse(result); - Assert.AreSame(series, parseResultMulti.Series); - mocker.VerifyAllMocks(); - } - + [Test] public void IsMonitored_dailyshow_should_do_daily_lookup() { @@ -155,12 +134,6 @@ namespace NzbDrone.Core.Test .Setup(p => p.GetEpisode(episode.SeriesId, episode.AirDate)) .Returns(episode); - - mocker.GetMock() - .Setup(p => p.IsIgnored(series.SeriesId, parseResultSingle.SeasonNumber)) - .Returns(false); - - var result = mocker.Resolve().IsMonitored(parseResultSingle); //Assert @@ -178,10 +151,6 @@ namespace NzbDrone.Core.Test .Setup(p => p.FindSeries(It.IsAny())) .Returns(series); - mocker.GetMock() - .Setup(p => p.IsIgnored(series.SeriesId, parseResultSingle.SeasonNumber)) - .Returns(false); - mocker.GetMock() .Setup(p => p.GetEpisode(episode.SeriesId, episode.SeasonNumber, episode.EpisodeNumber)) .Returns(null); @@ -191,8 +160,7 @@ namespace NzbDrone.Core.Test .Returns(null); mocker.GetMock() - .Setup(p => p.AddEpisode(It.IsAny())) - .Returns(12); + .Setup(p => p.AddEpisode(It.IsAny())); //Act var result = mocker.Resolve().IsMonitored(parseResultSingle); diff --git a/NzbDrone.Core.Test/MediaFileProviderTests.cs b/NzbDrone.Core.Test/MediaFileProviderTests.cs index 9d48434f8..eb5417aa7 100644 --- a/NzbDrone.Core.Test/MediaFileProviderTests.cs +++ b/NzbDrone.Core.Test/MediaFileProviderTests.cs @@ -38,7 +38,10 @@ namespace NzbDrone.Core.Test //Fakes var fakeSeries = Builder.CreateNew().Build(); - var fakeEpisode = Builder.CreateNew().With(c => c.SeriesId = fakeSeries.SeriesId).Build(); + var fakeEpisode = Builder.CreateNew() + .With(c => c.SeriesId = fakeSeries.SeriesId) + .With(c => c.SeasonNumber = seasonNumber) + .Build(); //Mocks var mocker = new AutoMoqer(); @@ -66,6 +69,8 @@ namespace NzbDrone.Core.Test mocker.GetMock().Verify(r => r.Add(result), Times.Once()); mocker.VerifyAllMocks(); + result.SeasonNumber.Should().Be(fakeEpisode.SeasonNumber); + Assert.AreEqual(fakeEpisode.SeriesId, result.SeriesId); Assert.AreEqual(QualityTypes.DVD, result.Quality); Assert.AreEqual(Parser.NormalizePath(fileName), result.Path); @@ -148,10 +153,6 @@ namespace NzbDrone.Core.Test mocker.GetMock(MockBehavior.Strict) .Setup(r => r.Exists(It.IsAny>>())).Returns(true).Verifiable(); - //mocker.GetMock() - // .Setup(e => e.GetEpisode(fakeSeries.SeriesId, seasonNumber, episodeNumner)).Returns(fakeEpisode) - // .Verifiable(); - mocker.GetMock() .Setup(e => e.GetSize(fileName)).Returns(size).Verifiable(); @@ -161,7 +162,7 @@ namespace NzbDrone.Core.Test //Assert mocker.VerifyAllMocks(); - Assert.IsNull(result); + result.Should().BeNull(); } @@ -341,30 +342,24 @@ namespace NzbDrone.Core.Test } [Test] - public void get_season_files() + public void get_series_files() { - var episodes = Builder.CreateListOfSize(20) - .WhereTheFirst(8) - .Has(c => c.EpisodeFile = new EpisodeFile()) - .AndTheRemaining() - .Has(c => c.EpisodeFile = null) - .Build().ToList(); + var firstSeriesFiles = Builder.CreateListOfSize(10) + .WhereAll().Have(s => s.SeriesId = 12).Build(); - var mocker = new AutoMoqer(); - mocker.GetMock() - .Setup(c => c.GetSeason(12)) - .Returns(Builder.CreateNew().With(c => c.Episodes = episodes).Build()) - .Verifiable(); - - - var result = mocker.Resolve().GetSeasonFiles(12); + var secondSeriesFiles = Builder.CreateListOfSize(10) + .WhereAll().Have(s => s.SeriesId = 20).Build(); + var mocker = new AutoMoqer(); + var repo = MockLib.GetEmptyRepository(true); + repo.AddMany(firstSeriesFiles); + repo.AddMany(secondSeriesFiles); + mocker.SetConstant(repo); - result.Should().HaveCount(8); - result.Should().NotContainNulls(); - mocker.VerifyAllMocks(); + var result = mocker.Resolve().GetSeriesFiles(12); + result.Should().HaveSameCount(firstSeriesFiles); } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/QualityTest.cs b/NzbDrone.Core.Test/QualityTest.cs index d401260af..af41c12ae 100644 --- a/NzbDrone.Core.Test/QualityTest.cs +++ b/NzbDrone.Core.Test/QualityTest.cs @@ -5,12 +5,13 @@ using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.Model; using NzbDrone.Core.Repository.Quality; +using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test { [TestFixture] // ReSharper disable InconsistentNaming - public class QualityTest + public class QualityTest : TestBase { [Test] [Ignore("No supported asserts are available")] diff --git a/NzbDrone.Core.Test/RepoTest.cs b/NzbDrone.Core.Test/RepoTest.cs index 95f49703a..ba5470f35 100644 --- a/NzbDrone.Core.Test/RepoTest.cs +++ b/NzbDrone.Core.Test/RepoTest.cs @@ -95,7 +95,6 @@ namespace NzbDrone.Core.Test public void enteties_toString() { Console.WriteLine(new Episode().ToString()); - Console.WriteLine(new Season().ToString()); Console.WriteLine(new Series().ToString()); Console.WriteLine(new EpisodeFile().ToString()); } diff --git a/NzbDrone.Core.Test/RepositoryProviderTest.cs b/NzbDrone.Core.Test/RepositoryProviderTest.cs index e6a524b54..2d856576a 100644 --- a/NzbDrone.Core.Test/RepositoryProviderTest.cs +++ b/NzbDrone.Core.Test/RepositoryProviderTest.cs @@ -20,7 +20,7 @@ namespace NzbDrone.Core.Test { [TestFixture] // ReSharper disable InconsistentNaming - public class RepositoryProviderTest + public class RepositoryProviderTest : TestBase { [Test] public void Get_Assembly_repos() @@ -36,8 +36,6 @@ namespace NzbDrone.Core.Test types.Should().Contain(typeof(IndexerSetting)); types.Should().Contain(typeof(JobSetting)); types.Should().Contain(typeof(RootDir)); - types.Should().Contain(typeof(Season)); - types.Should().Contain(typeof(Season)); types.Should().Contain(typeof(Series)); types.Should().Contain(typeof(QualityProfile)); diff --git a/NzbDrone.Core.Test/dbBenchmark.cs b/NzbDrone.Core.Test/dbBenchmark.cs index 5be00367a..0adf347bb 100644 --- a/NzbDrone.Core.Test/dbBenchmark.cs +++ b/NzbDrone.Core.Test/dbBenchmark.cs @@ -1,117 +1,153 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Linq; -using System.Text; using System.Threading; using FizzWare.NBuilder; +using FluentAssertions; using NUnit.Framework; +using NzbDrone.Core.Providers; using NzbDrone.Core.Repository; using NzbDrone.Core.Test.Framework; +using SubSonic.Repository; namespace NzbDrone.Core.Test { [TestFixture] // ReSharper disable InconsistentNaming - public class DbBenchmark + public class DbBenchmark : TestBase { - const int COUNT = 10000; - private List episodes; - private List files; - - - [SetUp] - public void Setup() + const int Episodes_Per_Season = 20; + private readonly List seasonsNumbers = new List { 1, 2, 3, 4, 5, 6, 7, 8 }; + private readonly List seriesIds = new List { 1, 2, 3, 4, 5, 6, 7, 8 }; + private readonly List episodes = new List(); + private readonly List files = new List(); + private readonly IRepository repo = MockLib.GetEmptyRepository(); + + [TestFixtureSetUp] + public new void Setup() { - episodes = new List(COUNT); - files = new List(COUNT); + base.Setup(); - for (int i = 10; i < COUNT + 10; i++) + foreach (var _seriesId in seriesIds) { - var file = Builder.CreateNew().With(c => c.EpisodeFileId = i).Build(); - files.Add(file); - - var episode = Builder.CreateNew() - .With(c => c.EpisodeId = i) - .And(c => c.EpisodeFileId = i) - .And(c => c.Title = DateTime.Now.ToLongTimeString()) - .And( - c => - c.Overview = - @"This adds support for silverlight. Both the 3.5 CLR and a Silverlight 3 - version are included in the zip file. Also includes some other very minor bug fixes.").Build(); - - episodes.Add(episode); + int seriesId = _seriesId; + var series = Builder.CreateNew() + .With(s => s.SeriesId = seriesId) + .With(s => s.Monitored = true) + .Build(); + + repo.Add(series); + + foreach (var _seasonNumber in seasonsNumbers) + { + for (int i = 1; i <= Episodes_Per_Season; i++) + { + var episode = Builder.CreateNew() + .With(e => e.SeriesId = seriesId) + .And(e => e.SeasonNumber = _seasonNumber) + .And(e => e.EpisodeNumber = i) + .And(e => e.Ignored = false) + .And(e => e.TvDbEpisodeId = episodes.Count + 1) + .And(e => e.AirDate = DateTime.Today.AddDays(-20)) + .Build(); + + episodes.Add(episode); + + if (i < 10) + { + var epFile = Builder.CreateNew() + .With(e => e.SeriesId = seriesId) + .And(e => e.SeasonNumber = _seasonNumber) + .And(e => e.Path = Guid.NewGuid().ToString()) + .Build(); + + files.Add(epFile); + } + } + } + + repo.AddMany(episodes); + repo.AddMany(files); + } } - [Test] - public void Insert_into_episodes() + public void get_episode_by_series_seasons_episode_x1000() { - var repo = MockLib.GetEmptyRepository(); + var epProvider = new EpisodeProvider(repo, null); + Thread.Sleep(1000); + + + var random = new Random(); + Console.WriteLine("Starting Test"); + var sw = Stopwatch.StartNew(); - repo.AddMany(episodes); + for (int i = 0; i < 1000; i++) + { + epProvider.GetEpisode(6, random.Next(2, 5), random.Next(2, Episodes_Per_Season - 10)).Should().NotBeNull(); + } + + sw.Stop(); - Console.WriteLine("Adding " + COUNT + " items at once took " + sw.Elapsed); + Console.WriteLine("Took " + sw.Elapsed); } - [Test] - public void Insert_into_episodes_single() + public void get_episode_by_series_seasons_x500() { - var repo = MockLib.GetEmptyRepository(); + var epProvider = new EpisodeProvider(repo, null); + Thread.Sleep(1000); - var sw = Stopwatch.StartNew(); - for (int i = 0; i < 100; i++) + + var random = new Random(); + Console.WriteLine("Starting Test"); + + var sw = Stopwatch.StartNew(); + for (int i = 0; i < 500; i++) { - repo.Add(episodes[i]); + epProvider.GetEpisodesBySeason(6, random.Next(2, 5)).Should().NotBeNull(); } + sw.Stop(); - Console.WriteLine("Adding " + 100 + " single items took " + sw.Elapsed); + Console.WriteLine("Took " + sw.Elapsed); } - [Test] - public void get_episode_file() + public void get_episode_file_count_x50() { - var repo = MockLib.GetEmptyRepository(); - - repo.AddMany(episodes); - repo.AddMany(files); + var mocker = new AutoMoq.AutoMoqer(); + mocker.SetConstant(repo); + mocker.SetConstant(mocker.Resolve()); + var mediaProvider = mocker.Resolve(); - //var repoEpisodes = repo.All().ToList(); Thread.Sleep(1000); - var count = 0; var random = new Random(); + Console.WriteLine("Starting Test"); var sw = Stopwatch.StartNew(); - - - - for (int i = 5000; i < 5000 + 1000; i++) + for (int i = 0; i < 50; i++) { - count++; - var file = repo.Single(random.Next(10, COUNT - 100)).EpisodeFile; + mediaProvider.GetEpisodeFilesCount(random.Next(1, 5)).Should().NotBeNull(); } sw.Stop(); - Console.WriteLine("Getting " + count + " episode files took " + sw.Elapsed); + Console.WriteLine("Took " + sw.Elapsed); } } } diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index 6efed79d7..36e0d53ae 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -78,7 +78,6 @@ namespace NzbDrone.Core _kernel.Bind().ToSelf().InTransientScope(); _kernel.Bind().ToSelf().InSingletonScope(); _kernel.Bind().ToSelf().InSingletonScope(); - _kernel.Bind().ToSelf().InSingletonScope(); _kernel.Bind().ToSelf().InSingletonScope(); _kernel.Bind().ToSelf().InSingletonScope(); _kernel.Bind().ToSelf().InSingletonScope(); @@ -138,7 +137,6 @@ namespace NzbDrone.Core private static void ForceMigration(IRepository repository) { repository.All().Count(); - repository.All().Count(); repository.All().Count(); repository.All().Count(); repository.All().Count(); diff --git a/NzbDrone.Core/Datastore/Migrations.cs b/NzbDrone.Core/Datastore/Migrations.cs index 09e361954..4ce5a02be 100644 --- a/NzbDrone.Core/Datastore/Migrations.cs +++ b/NzbDrone.Core/Datastore/Migrations.cs @@ -98,6 +98,23 @@ namespace NzbDrone.Core.Datastore var jobTable = repoProvider.GetSchemaFromType(typeof(JobSetting)); Database.RemoveTable(jobTable.Name); + } + + public override void Down() + { + throw new NotImplementedException(); + } + } + + [Migration(20110603)] + public class Migration20110603 : Migration + { + public override void Up() + { + if(Database.TableExists("Seasons")) + { + Database.RemoveTable("Seasons"); + } Migrations.RemoveDeletedColumns(Database); Migrations.AddNewColumns(Database); diff --git a/NzbDrone.Core/Instrumentation/NlogWriter.cs b/NzbDrone.Core/Instrumentation/NlogWriter.cs index c0329f6f5..4e0d50705 100644 --- a/NzbDrone.Core/Instrumentation/NlogWriter.cs +++ b/NzbDrone.Core/Instrumentation/NlogWriter.cs @@ -26,7 +26,7 @@ namespace NzbDrone.Core.Instrumentation private static void DbAction(string value) { - Logger.Trace(value); + Logger.Trace(value.Replace("`t0`.", "")); } } } \ No newline at end of file diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index d188be0dd..fb3009a98 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -231,14 +231,12 @@ - - diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index 945908caf4846433c619d9d5a77db2e134ab7734..816a323c1472f15f43f785b9c3ce5d28272ccce2 100644 GIT binary patch delta 737 zcmb7C&q^CX7$@0H)|h`n16ge)Us@`=kgioq50=Ct6^TeKL?0mTPST~@owBp3hOqQp zdT8aldFc}f!d`mt3EGp02M<1i-n=PvHe+IX$f0wZ;rsago!^_+jiVrjzhYnUeS9B3 zNCljZPvN$-h*N3;zez7}UCo5&(t-4Zt#lit$*8M2)NKPJo=sTYs(|hK{1r{`k35Gr z$(Q&pA*;j?>u)R{C5s!R;Aiwny9BQB%{Ys444OcTO{%sx&frEfLv zbPGXZsB@_fF@23ewFc}T;kxmL6WcDI>c*yL5pSidnbDr98(VaP4>hFfv*pHsSST8w zk_e;%eY5t^?1?;s-_r^%Pby!C&l%fb_j7=j(`*BEK}cWfJrDRb%6qA|5P(miw-`LG zj5H$J81M`!^jFzQ7&)Jt9*|EqqZZ-DqvTe_Yv#V|`1pmT*%ToOYc1-H@y0r)Nf>K&9H-0u`Tt=yyi_l8 Fe*p_H{Sp8G delta 493 zcmewwe9C`AEu(yJYGQGIUO-WPS!POVkwSbim|qMNn4HMCR25APL12O4c6JTVyb@z0&CP1e%a}!-Dk0Wrfih?cNtU@v2$vK>oliAq#H!oo?XP#^;$*$>=npB#up%hw>l30=n zH$@>cFD+joEx!n8YEfotu~oIf2IzlV3?{Z8qj!!Y&F5 j4uw>R)8XnTf8-aRY$wG&c^*H<<_kgwESuG(&+!2Od7rD< diff --git a/NzbDrone.Core/Providers/InventoryProvider.cs b/NzbDrone.Core/Providers/InventoryProvider.cs index 893027350..4c81bba73 100644 --- a/NzbDrone.Core/Providers/InventoryProvider.cs +++ b/NzbDrone.Core/Providers/InventoryProvider.cs @@ -10,16 +10,14 @@ namespace NzbDrone.Core.Providers public class InventoryProvider { private readonly SeriesProvider _seriesProvider; - private readonly SeasonProvider _seasonProvider; private readonly EpisodeProvider _episodeProvider; private readonly HistoryProvider _historyProvider; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public InventoryProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, EpisodeProvider episodeProvider, HistoryProvider historyProvider) + public InventoryProvider(SeriesProvider seriesProvider, EpisodeProvider episodeProvider, HistoryProvider historyProvider) { _seriesProvider = seriesProvider; - _seasonProvider = seasonProvider; _episodeProvider = episodeProvider; _historyProvider = historyProvider; } @@ -49,12 +47,6 @@ namespace NzbDrone.Core.Providers return false; } - if (_seasonProvider.IsIgnored(series.SeriesId, parseResult.SeasonNumber)) - { - Logger.Debug("Season {0} is currently set to ignore. skipping.", parseResult.SeasonNumber); - return false; - } - foreach (var episodeNumber in parseResult.EpisodeNumbers) { var episodeInfo = _episodeProvider.GetEpisode(series.SeriesId, parseResult.SeasonNumber, episodeNumber); diff --git a/NzbDrone.Core/Providers/Jobs/ImportNewSeriesJob.cs b/NzbDrone.Core/Providers/Jobs/ImportNewSeriesJob.cs index 8f9ab8a88..1f349d934 100644 --- a/NzbDrone.Core/Providers/Jobs/ImportNewSeriesJob.cs +++ b/NzbDrone.Core/Providers/Jobs/ImportNewSeriesJob.cs @@ -16,7 +16,6 @@ namespace NzbDrone.Core.Providers.Jobs { private readonly SeriesProvider _seriesProvider; private readonly MediaFileProvider _mediaFileProvider; - private readonly SeasonProvider _seasonProvider; private readonly UpdateInfoJob _updateInfoJob; private readonly DiskScanJob _diskScanJob; @@ -24,13 +23,12 @@ namespace NzbDrone.Core.Providers.Jobs private List _attemptedSeries; - public ImportNewSeriesJob(SeriesProvider seriesProvider, SeasonProvider seasonProvider, + public ImportNewSeriesJob(SeriesProvider seriesProvider, MediaFileProvider mediaFileProvider, UpdateInfoJob updateInfoJob, DiskScanJob diskScanJob) { _seriesProvider = seriesProvider; _mediaFileProvider = mediaFileProvider; - _seasonProvider = seasonProvider; - _updateInfoJob = updateInfoJob; + _updateInfoJob = updateInfoJob; _diskScanJob = diskScanJob; } @@ -84,9 +82,22 @@ namespace NzbDrone.Core.Providers.Jobs private void AutoIgnoreSeasons(Series updatedSeries) { - if (_mediaFileProvider.GetSeriesFiles(updatedSeries.SeriesId).Count() != 0) + var episodeFiles = _mediaFileProvider.GetSeriesFiles(updatedSeries.SeriesId); + var episodes = updatedSeries.Episodes; + if (episodeFiles.Count() != 0) { - Logger.Debug("Looking for seasons to ignore"); + var seasons = episodes.Select(c => c.SeasonNumber).Distinct(); + var currentSeasons = seasons.Max(); + + foreach (var season in seasons) + { + if (season!=currentSeasons ) + { + + } + } + + /* Logger.Debug("Looking for seasons to ignore"); foreach (var season in updatedSeries.Seasons) { if (season.SeasonNumber != updatedSeries.Seasons.Max(s => s.SeasonNumber) && _mediaFileProvider.GetSeasonFiles(season.SeasonId).Count() == 0) @@ -95,7 +106,7 @@ namespace NzbDrone.Core.Providers.Jobs season.Monitored = false; _seasonProvider.SaveSeason(season); } - } + }*/ } } } diff --git a/NzbDrone.Core/Providers/MediaFileProvider.cs b/NzbDrone.Core/Providers/MediaFileProvider.cs index 363e3029f..250e2efc1 100644 --- a/NzbDrone.Core/Providers/MediaFileProvider.cs +++ b/NzbDrone.Core/Providers/MediaFileProvider.cs @@ -16,17 +16,15 @@ namespace NzbDrone.Core.Providers private readonly DiskProvider _diskProvider; private readonly EpisodeProvider _episodeProvider; private readonly SeriesProvider _seriesProvider; - private readonly SeasonProvider _seasonProvider; private readonly IRepository _repository; public MediaFileProvider(IRepository repository, DiskProvider diskProvider, - EpisodeProvider episodeProvider, SeriesProvider seriesProvider, SeasonProvider seasonProvider) + EpisodeProvider episodeProvider, SeriesProvider seriesProvider) { _repository = repository; _diskProvider = diskProvider; _episodeProvider = episodeProvider; _seriesProvider = seriesProvider; - _seasonProvider = seasonProvider; } public MediaFileProvider() { } @@ -125,6 +123,7 @@ namespace NzbDrone.Core.Providers episodeFile.Size = size; episodeFile.Quality = parseResult.Quality.QualityType; episodeFile.Proper = parseResult.Quality.Proper; + episodeFile.SeasonNumber = parseResult.SeasonNumber; var fileId = (int)_repository.Add(episodeFile); //This is for logging + updating the episodes that are linked to this EpisodeFile @@ -183,25 +182,19 @@ namespace NzbDrone.Core.Providers return _repository.All().ToList(); } - public virtual IEnumerable GetSeasonFiles(int seasonId) - { - return _seasonProvider.GetSeason(seasonId).Episodes.Where(c => c.EpisodeFile != null).Select(c => c.EpisodeFile); - } - public virtual IEnumerable GetSeriesFiles(int seriesId) { - return _seriesProvider.GetSeries(seriesId).Episodes.Where(c => c.EpisodeFile != null).Select(c => c.EpisodeFile); + return _repository.All().Where(c => c.SeriesId == seriesId); } public virtual Tuple GetEpisodeFilesCount(int seriesId) { - var series = _seriesProvider.GetSeries(seriesId); + var allEpisodes = _episodeProvider.GetEpisodeBySeries(seriesId); - var monitoredSeasons = series.Seasons.Where(e => e.Monitored).Select(e => e.SeasonId); - var episodeTotal = series.Episodes.Where(e => monitoredSeasons.Contains(e.SeasonId) && e.AirDate <= DateTime.Today && e.AirDate > new DateTime(1899, 12, 31)); - var episodes = episodeTotal.Where(e => e.EpisodeFileId > 0); + var episodeTotal = allEpisodes.Where(e => !e.Ignored && e.AirDate <= DateTime.Today && e.AirDate.Year > 1900).ToList(); + var avilableEpisodes = episodeTotal.Where(e => e.EpisodeFileId > 0); - return new Tuple(episodeTotal.Count(), episodes.Count()); + return new Tuple(episodeTotal.Count, avilableEpisodes.Count()); } private List GetMediaFileList(string path) diff --git a/NzbDrone.Core/Providers/RenameProvider.cs b/NzbDrone.Core/Providers/RenameProvider.cs index f4284c606..012de3068 100644 --- a/NzbDrone.Core/Providers/RenameProvider.cs +++ b/NzbDrone.Core/Providers/RenameProvider.cs @@ -19,19 +19,17 @@ namespace NzbDrone.Core.Providers private readonly DiskProvider _diskProvider; private readonly EpisodeProvider _episodeProvider; private readonly MediaFileProvider _mediaFileProvider; - private readonly SeasonProvider _seasonProvider; private readonly SeriesProvider _seriesProvider; private readonly List _epsToRename = new List(); private Thread _renameThread; - public RenameProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, + public RenameProvider(SeriesProvider seriesProvider, EpisodeProvider episodeProvider, MediaFileProvider mediaFileProvider, DiskProvider diskProvider, ConfigProvider configProvider) { _seriesProvider = seriesProvider; - _seasonProvider = seasonProvider; _episodeProvider = episodeProvider; _mediaFileProvider = mediaFileProvider; _diskProvider = diskProvider; @@ -45,7 +43,7 @@ namespace NzbDrone.Core.Providers foreach (var episodeFile in _mediaFileProvider.GetEpisodeFiles()) { var series = _seriesProvider.GetSeries(episodeFile.SeriesId); - var erm = new EpisodeRenameModel {SeriesName = series.Title, Folder = series.Path}; + var erm = new EpisodeRenameModel { SeriesName = series.Title, Folder = series.Path }; if (series.SeasonFolder) erm.Folder += Path.DirectorySeparatorChar + @@ -68,7 +66,7 @@ namespace NzbDrone.Core.Providers foreach (var episodeFile in _mediaFileProvider.GetEpisodeFiles().Where(s => s.SeriesId == seriesId)) { - var erm = new EpisodeRenameModel {SeriesName = series.Title, Folder = series.Path}; + var erm = new EpisodeRenameModel { SeriesName = series.Title, Folder = series.Path }; if (series.SeasonFolder) erm.Folder += Path.DirectorySeparatorChar + @@ -85,26 +83,7 @@ namespace NzbDrone.Core.Providers public virtual void RenameSeason(int seasonId) { - //Get a list of all applicable episode files/episodes and rename them - var season = _seasonProvider.GetSeason(seasonId); - var series = _seriesProvider.GetSeries(season.SeriesId); - - foreach ( - var episodeFile in _mediaFileProvider.GetEpisodeFiles().Where(s => s.Episodes[0].SeasonId == seasonId)) - { - var erm = new EpisodeRenameModel {SeriesName = series.Title, Folder = series.Path}; - - if (series.SeasonFolder) - erm.Folder += Path.DirectorySeparatorChar + - EpisodeRenameHelper.GetSeasonFolder(episodeFile.Episodes[0].SeasonNumber, - _configProvider.GetValue( - "Sorting_SeasonFolderFormat", "Season %s", - true)); - - erm.EpisodeFile = episodeFile; - _epsToRename.Add(erm); - StartRename(); - } + throw new NotImplementedException(); } public virtual void RenameEpisode(int episodeId) @@ -116,7 +95,7 @@ namespace NzbDrone.Core.Providers var episodeFile = _mediaFileProvider.GetEpisodeFiles().Where(s => s.Episodes.Contains(episode)).FirstOrDefault(); - var erm = new EpisodeRenameModel {SeriesName = series.Title, Folder = series.Path}; + var erm = new EpisodeRenameModel { SeriesName = series.Title, Folder = series.Path }; if (series.SeasonFolder) erm.Folder += Path.DirectorySeparatorChar + @@ -135,7 +114,7 @@ namespace NzbDrone.Core.Providers var episodeFile = _mediaFileProvider.GetEpisodeFile(episodeFileId); var series = _seriesProvider.GetSeries(episodeFile.Series.SeriesId); - var erm = new EpisodeRenameModel {SeriesName = series.Title, Folder = series.Path}; + var erm = new EpisodeRenameModel { SeriesName = series.Title, Folder = series.Path }; if (series.SeasonFolder) erm.Folder += Path.DirectorySeparatorChar + diff --git a/NzbDrone.Core/Providers/SeasonProvider.cs b/NzbDrone.Core/Providers/SeasonProvider.cs deleted file mode 100644 index b1f337a36..000000000 --- a/NzbDrone.Core/Providers/SeasonProvider.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NLog; -using NzbDrone.Core.Repository; -using SubSonic.Repository; - -namespace NzbDrone.Core.Providers -{ - public class SeasonProvider - { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - private readonly IRepository _repository; - - public SeasonProvider(IRepository repository) - { - _repository = repository; - } - - public SeasonProvider() - { - } - - public virtual Season GetSeason(int seasonId) - { - return _repository.Single(seasonId); - } - - public virtual Season GetSeason(int seriesId, int seasonNumber) - { - return _repository.Single(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber); - } - - public virtual List GetSeasons(int seriesId) - { - return _repository.All().Where(s => s.SeriesId == seriesId).ToList(); - } - - public virtual Season GetLatestSeason(int seriesId) - { - return _repository.All().Where(s => s.SeriesId == seriesId).OrderBy(s => s.SeasonNumber).Last(); - } - - public virtual void EnsureSeason(int seriesId, int seasonId, int seasonNumber) - { - if (_repository.Exists(s => s.SeasonId == seasonId)) - return; - //TODO: Calculate Season Folder - Logger.Trace("Adding Season To DB. [SeriesID:{0} SeasonID:{1} SeasonNumber:{2}]", seriesId, seasonId, - seasonNumber, "????"); - - var newSeason = new Season - { - Monitored = true, - SeasonId = seasonId, - SeasonNumber = seasonNumber, - SeriesId = seriesId - }; - _repository.Add(newSeason); - } - - public virtual int SaveSeason(Season season) - { - if (_repository.Exists(s => s.SeasonId == season.SeasonId)) - { - return _repository.Update(season); - } - - return (int)_repository.Add(season); - } - - public virtual bool IsIgnored(int seasonId) - { - if (_repository.Single(seasonId).Monitored) - return false; - - Logger.Debug("Season {0} is not wanted."); - return true; - } - - public virtual bool IsIgnored(int seriesId, int seasonNumber) - { - var season = _repository.Single(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber); - return !season.Monitored; - } - - public void DeleteSeason(int seasonId) - { - _repository.Delete(seasonId); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Providers/SeriesProvider.cs b/NzbDrone.Core/Providers/SeriesProvider.cs index 079d823cc..c164cb32e 100644 --- a/NzbDrone.Core/Providers/SeriesProvider.cs +++ b/NzbDrone.Core/Providers/SeriesProvider.cs @@ -41,7 +41,7 @@ namespace NzbDrone.Core.Providers public virtual Series GetSeries(int seriesId) { - return _repository.Single(s => s.SeriesId == seriesId); + return _repository.Single(seriesId); } /// @@ -124,7 +124,7 @@ namespace NzbDrone.Core.Providers Logger.Warn("Deleting Series [{0}]", seriesId); var series = _repository.Single(seriesId); - //Delete Files, Episdes, Seasons then the Series + //Delete Files, Episodes, Seasons then the Series //Can't use providers because episode provider needs series provider - Cyclic Dependency Injection, this will work //Delete History Items for any episodes that belong to this series @@ -140,10 +140,6 @@ namespace NzbDrone.Core.Providers Logger.Debug("Deleting Episodes from DB for Series: {0}", series.SeriesId); _repository.DeleteMany(series.Episodes); - //Delete seasons for this series from the DB - Logger.Debug("Deleting Seasons from DB for Series: {0}", series.SeriesId); - _repository.DeleteMany(series.Seasons); - //Delete the Series Logger.Debug("Deleting Series from DB {0}", series.Title); _repository.Delete(seriesId); diff --git a/NzbDrone.Core/Repository/Episode.cs b/NzbDrone.Core/Repository/Episode.cs index fad97ee6a..008850fb2 100644 --- a/NzbDrone.Core/Repository/Episode.cs +++ b/NzbDrone.Core/Repository/Episode.cs @@ -6,7 +6,7 @@ using SubSonic.SqlGeneration.Schema; namespace NzbDrone.Core.Repository { - public class Episode + public class Episode { [SubSonicPrimaryKey] public virtual int EpisodeId { get; set; } @@ -15,7 +15,6 @@ namespace NzbDrone.Core.Repository public virtual int SeriesId { get; set; } public virtual int EpisodeFileId { get; set; } - public virtual int SeasonId { get; set; } public virtual int SeasonNumber { get; set; } public virtual int EpisodeNumber { get; set; } public virtual string Title { get; set; } @@ -56,10 +55,9 @@ namespace NzbDrone.Core.Repository if (EpisodeFileId != 0) return EpisodeStatusType.Ready; - var season = Season; - if (Ignored || (season != null && !season.Monitored)) return EpisodeStatusType.Ignored; - + if (Ignored) return EpisodeStatusType.Ignored; + if (AirDate.Date.Year > 1900 && DateTime.Now.Date >= AirDate.Date) { return EpisodeStatusType.Missing; @@ -69,9 +67,6 @@ namespace NzbDrone.Core.Repository } } - [SubSonicToOneRelation(ThisClassContainsJoinKey = true)] - public virtual Season Season { get; set; } - [SubSonicToOneRelation(ThisClassContainsJoinKey = true)] public virtual Series Series { get; set; } diff --git a/NzbDrone.Core/Repository/EpisodeFile.cs b/NzbDrone.Core/Repository/EpisodeFile.cs index f2c23a60c..8e4a6433f 100644 --- a/NzbDrone.Core/Repository/EpisodeFile.cs +++ b/NzbDrone.Core/Repository/EpisodeFile.cs @@ -11,6 +11,7 @@ namespace NzbDrone.Core.Repository public virtual int EpisodeFileId { get; set; } public virtual int SeriesId { get; set; } + public virtual int SeasonNumber { get; set; } public string Path { get; set; } public QualityTypes Quality { get; set; } public bool Proper { get; set; } diff --git a/NzbDrone.Core/Repository/Quality/QualityProfile.cs b/NzbDrone.Core/Repository/Quality/QualityProfile.cs index d9dbf9f3e..ec50f0f90 100644 --- a/NzbDrone.Core/Repository/Quality/QualityProfile.cs +++ b/NzbDrone.Core/Repository/Quality/QualityProfile.cs @@ -16,8 +16,6 @@ namespace NzbDrone.Core.Repository.Quality [DisplayFormat(ConvertEmptyStringToNull = false)] public string Name { get; set; } - public bool UserProfile { get; set; } //Allows us to tell the difference between default and user profiles - [SubSonicIgnore] [DisplayName("Allowed Qualities")] public List Allowed { get; set; } diff --git a/NzbDrone.Core/Repository/Season.cs b/NzbDrone.Core/Repository/Season.cs deleted file mode 100644 index bb1561dfd..000000000 --- a/NzbDrone.Core/Repository/Season.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using SubSonic.SqlGeneration.Schema; - -namespace NzbDrone.Core.Repository -{ - public class Season - { - [SubSonicPrimaryKey(false)] - public virtual int SeasonId { get; set; } - - public virtual int SeriesId { get; set; } - public virtual int SeasonNumber { get; set; } - public bool Monitored { get; set; } - - public DayOfWeek? LastInfoSync { get; set; } - - public DayOfWeek? LastDiskSync { get; set; } - - [SubSonicToManyRelation] - public virtual IList Episodes { get; set; } - - [SubSonicToOneRelation(ThisClassContainsJoinKey = true)] - public virtual Series Series { get; set; } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Repository/Series.cs b/NzbDrone.Core/Repository/Series.cs index 09757c92a..fe1c62d88 100644 --- a/NzbDrone.Core/Repository/Series.cs +++ b/NzbDrone.Core/Repository/Series.cs @@ -56,9 +56,6 @@ namespace NzbDrone.Core.Repository [SubSonicToOneRelation(ThisClassContainsJoinKey = true, JoinKeyName = "QualityProfileId")] public virtual QualityProfile QualityProfile { get; set; } - [SubSonicToManyRelation] - public virtual IList Seasons { get; protected set; } - [SubSonicToManyRelation] public virtual IList Episodes { get; set; } diff --git a/NzbDrone.Web/Controllers/SeriesController.cs b/NzbDrone.Web/Controllers/SeriesController.cs index 0d162be05..2441d0162 100644 --- a/NzbDrone.Web/Controllers/SeriesController.cs +++ b/NzbDrone.Web/Controllers/SeriesController.cs @@ -20,7 +20,6 @@ namespace NzbDrone.Web.Controllers private readonly SeriesProvider _seriesProvider; private readonly TvDbProvider _tvDbProvider; private readonly JobProvider _jobProvider; - private readonly SeasonProvider _seasonProvider; private readonly MediaFileProvider _mediaFileProvider; // // GET: /Series/ @@ -31,7 +30,6 @@ namespace NzbDrone.Web.Controllers RenameProvider renameProvider, TvDbProvider tvDbProvider, JobProvider jobProvider, - SeasonProvider seasonProvider, MediaFileProvider mediaFileProvider) { _seriesProvider = seriesProvider; @@ -40,7 +38,6 @@ namespace NzbDrone.Web.Controllers _renameProvider = renameProvider; _tvDbProvider = tvDbProvider; _jobProvider = jobProvider; - _seasonProvider = seasonProvider; _mediaFileProvider = mediaFileProvider; } @@ -60,14 +57,21 @@ namespace NzbDrone.Web.Controllers public ActionResult SeasonEditor(int seriesId) { - var model = - _seriesProvider.GetSeries(seriesId).Seasons.Select(s => new SeasonEditModel - { - SeasonId = s.SeasonId, - SeasonNumber = s.SeasonNumber, - SeasonString = GetSeasonString(s.SeasonNumber), - Monitored = s.Monitored - }).OrderBy(s => s.SeasonNumber).ToList(); + var model = new List(); + + var seasons = _episodeProvider.GetSeasons(seriesId); + + foreach (var season in seasons) + { + var seasonEdit = new SeasonEditModel(); + seasonEdit.Monitored = !_episodeProvider.IsIgnored(seriesId, season); + seasonEdit.SeasonNumber = season; + seasonEdit.SeriesId = seriesId; + seasonEdit.SeasonString = GetSeasonString(season); + + model.Add(seasonEdit); + } + return View(model); } @@ -117,9 +121,9 @@ namespace NzbDrone.Web.Controllers } [GridAction] - public ActionResult _AjaxSeasonGrid(int seasonId) + public ActionResult _AjaxSeasonGrid(int seriesId, int seasonNumber) { - var episodes = _episodeProvider.GetEpisodeBySeason(seasonId).Select(c => new EpisodeModel + var episodes = _episodeProvider.GetEpisodesBySeason(seriesId, seasonNumber).Select(c => new EpisodeModel { EpisodeId = c.EpisodeId, EpisodeNumber = c.EpisodeNumber, @@ -190,9 +194,10 @@ namespace NzbDrone.Web.Controllers { foreach (var season in seasons) { - var seasonInDb = _seasonProvider.GetSeason(season.SeasonId); - seasonInDb.Monitored = season.Monitored; - _seasonProvider.SaveSeason(seasonInDb); + if (_episodeProvider.IsIgnored(season.SeriesId, season.SeasonNumber) != !season.Monitored) + { + _episodeProvider.SetSeasonIgnore(season.SeriesId, season.SeasonNumber, !season.Monitored); + } } return Content("Saved"); @@ -201,7 +206,23 @@ namespace NzbDrone.Web.Controllers public ActionResult Details(int seriesId) { var series = _seriesProvider.GetSeries(seriesId); - return View(series); + + var model = new SeriesModel(); + + if (series.AirsDayOfWeek != null) + { + model.AirsDayOfWeek = series.AirsDayOfWeek.Value.ToString(); + } + else + { + model.AirsDayOfWeek = "N/A"; + } + model.Overview = series.Overview; + model.Seasons = _episodeProvider.GetSeasons(seriesId); + model.Title = series.Status; + model.SeriesId = series.SeriesId; + + return View(model); } public ActionResult SyncEpisodesOnDisk(int seriesId) @@ -261,11 +282,8 @@ namespace NzbDrone.Web.Controllers Path = s.Path, QualityProfileId = s.QualityProfileId, QualityProfileName = s.QualityProfile.Name, - SeasonsCount = s.Seasons.Where(x => x.SeasonNumber > 0).Count(), SeasonFolder = s.SeasonFolder, Status = s.Status, - Episodes = 0, - EpisodeTotal = 0 }); } diff --git a/NzbDrone.Web/Models/SeasonEditModel.cs b/NzbDrone.Web/Models/SeasonEditModel.cs index ab55f3bf1..4d3ea8c65 100644 --- a/NzbDrone.Web/Models/SeasonEditModel.cs +++ b/NzbDrone.Web/Models/SeasonEditModel.cs @@ -7,7 +7,7 @@ namespace NzbDrone.Web.Models { public class SeasonEditModel { - public int SeasonId { get; set; } + public int SeriesId { get; set; } public int SeasonNumber { get; set; } public string SeasonString { get; set; } public bool Monitored { get; set; } diff --git a/NzbDrone.Web/Models/SeriesModel.cs b/NzbDrone.Web/Models/SeriesModel.cs index d2b03473e..2fce11b30 100644 --- a/NzbDrone.Web/Models/SeriesModel.cs +++ b/NzbDrone.Web/Models/SeriesModel.cs @@ -19,7 +19,8 @@ namespace NzbDrone.Web.Models public string QualityProfileName { get; set; } public string Overview { get; set; } public int Episodes { get; set; } - public int EpisodeTotal { get; set; } + + public IList Seasons { get; set; } //View & Edit [DisplayName("Path")] diff --git a/NzbDrone.Web/Views/Series/Details.cshtml b/NzbDrone.Web/Views/Series/Details.cshtml index 4d317fe1f..3d2747b53 100644 --- a/NzbDrone.Web/Views/Series/Details.cshtml +++ b/NzbDrone.Web/Views/Series/Details.cshtml @@ -1,4 +1,4 @@ -@model NzbDrone.Core.Repository.Series +@model NzbDrone.Web.Models.SeriesModel @using NzbDrone.Core.Repository @using NzbDrone.Web.Models @section TitleContent{ @@ -31,68 +31,66 @@
AirTimes
- @Model.AirTimes
+ @Model.AirsDayOfWeek.ToString()
Language
-
- @Model.Language.ToUpper()
Location
@Model.Path
- @*Todo: This breaks when using SQLServer... thoughts?*@ - @foreach (var season in Model.Seasons.Where(s => s.SeasonNumber > 0).Reverse()) + @*Todo: This breaks when using SQLServer... thoughts?*@ @*Easy, don't use SQL Server!!!*@ + @foreach (var season in Model.Seasons.Where(s => s > 0).Reverse()) {

- Season @season.SeasonNumber

+ Season @season
- @{Season season1 = season; - Html.Telerik().Grid().Name("seasons_" + season.SeasonNumber) - .TableHtmlAttributes(new { @class = "Grid" }) - .Columns(columns => - { - columns.Bound(o => o.EpisodeId) - .ClientTemplate( - "") - .Title("") - .Width(1) - .HtmlAttributes(new { style = "text-align:center" }); + @{ + Html.Telerik().Grid().Name("seasons_" + season) + .TableHtmlAttributes(new { @class = "Grid" }) + .Columns(columns => + { + columns.Bound(o => o.EpisodeId) + .ClientTemplate( + "") + .Title("") + .Width(1) + .HtmlAttributes(new { style = "text-align:center" }); - columns.Bound(c => c.EpisodeNumber).Width(0).Title("Episode"); - columns.Bound(c => c.Title).Title("Title"); - columns.Bound(c => c.AirDate).Format("{0:d}").Width(0); - columns.Bound(c => c.Quality).Width(0); - columns.Bound(c => c.Status).Width(0); - columns.Bound(o => o.EpisodeId).Title("") - .ClientTemplate("'); return false;\" >Search"); - }) - .DetailView(detailView => detailView.ClientTemplate("
<#= Overview #>
<#= Path #>
")) - .ClientEvents(clientEvents => - { - clientEvents.OnDataBinding("grid_bind"); - clientEvents.OnDataBound("grid_bound"); - }) - .Sortable(rows => rows.OrderBy(epSort => epSort.Add(c => c.EpisodeNumber).Descending()).Enabled(true)) - .Footer(true) - .DataBinding( - d => - d.Ajax().Select("_AjaxSeasonGrid", "Series", - new RouteValueDictionary { { "seasonId", season1.SeasonId.ToString() } })) - .ToolBar( - c => - c.Custom().Text("Rename Season").Action("RenameSeason", "Series", new { seasonId = season1.SeasonId }) - .ButtonType(GridButtonType.Text)) - .Render();} + columns.Bound(c => c.EpisodeNumber).Width(0).Title("Episode"); + columns.Bound(c => c.Title).Title("Title"); + columns.Bound(c => c.AirDate).Format("{0:d}").Width(0); + columns.Bound(c => c.Quality).Width(0); + columns.Bound(c => c.Status).Width(0); + columns.Bound(o => o.EpisodeId).Title("") + .ClientTemplate("'); return false;\" >Search"); + }) + .DetailView(detailView => detailView.ClientTemplate("
<#= Overview #>
<#= Path #>
")) + .ClientEvents(clientEvents => + { + clientEvents.OnDataBinding("grid_bind"); + clientEvents.OnDataBound("grid_bound"); + }) + .Sortable(rows => rows.OrderBy(epSort => epSort.Add(c => c.EpisodeNumber).Descending()).Enabled(true)) + .Footer(true) + .DataBinding( + d => + d.Ajax().Select("_AjaxSeasonGrid", "Series", + new RouteValueDictionary { { "seriesId", Model.SeriesId }, { "seasonNumber", season } })) + .ToolBar( + c => + c.Custom().Text("Rename Season").Action("RenameSeason", "Series", new { seasonId = season }) + .ButtonType(GridButtonType.Text)) + .Render();} Loading Loading...
} - @{var specialSeasons = Model.Seasons.Where(s => s.SeasonNumber == 0).FirstOrDefault();} - @if (specialSeasons != null) + @{var specialSeason = Model.Seasons.Where(s => s == 0).FirstOrDefault();} + @if (specialSeason != null) {
@@ -127,8 +125,8 @@ .DataBinding( d => d.Ajax().Select("_AjaxSeasonGrid", "Series", - new RouteValueDictionary { { "seasonId", specialSeasons.SeasonId.ToString() } })) - .Render(); } + new RouteValueDictionary { { "seriesId", Model.SeriesId }, { "seasonNumber", specialSeason } } + )).Render(); } Loading Loading... diff --git a/NzbDrone.Web/Views/Series/SingleSeason.cshtml b/NzbDrone.Web/Views/Series/SingleSeason.cshtml index e59c63dd9..707ae438b 100644 --- a/NzbDrone.Web/Views/Series/SingleSeason.cshtml +++ b/NzbDrone.Web/Views/Series/SingleSeason.cshtml @@ -8,7 +8,7 @@ @Html.DisplayFor(m => m.SeasonString) @Html.CheckBoxFor(m => m.Monitored, new { @class = "chkbox" }) - @Html.HiddenFor(m => m.SeasonId) + @Html.HiddenFor(m => m.SeasonNumber) @Html.HiddenFor(m => m.SeasonNumber) } diff --git a/NzbDrone.Web/Views/Settings/QualityProfileItem.cshtml b/NzbDrone.Web/Views/Settings/QualityProfileItem.cshtml index f641a3a9d..0a96eac48 100644 --- a/NzbDrone.Web/Views/Settings/QualityProfileItem.cshtml +++ b/NzbDrone.Web/Views/Settings/QualityProfileItem.cshtml @@ -2,17 +2,30 @@ @using System.Collections @using NzbDrone.Core.Repository.Quality @using NzbDrone.Web.Helpers - @{ Layout = null; } - - @using (Html.BeginCollectionItem("Profiles")) { var idClean = ViewData.TemplateInfo.HtmlFieldPrefix.Replace('[', '_').Replace(']', '_'); @@ -25,27 +38,26 @@ string cutoff = String.Format("{0}_Cutoff", idClean);
- -
+
-

@{Html.DisplayTextFor(m => m.Name);}

- Delete +

+ @{Html.DisplayTextFor(m => m.Name);} +

+ + Delete
-
@Html.LabelFor(x => x.Name)
@Html.TextBoxFor(x => x.Name, new { maxlength = 15 })
@Html.ValidationMessageFor(x => x.Name)
-
@Html.LabelFor(x => x.Cutoff)
@Html.DropDownListFor(m => m.Cutoff, new SelectList(Model.Allowed, Model.Cutoff))
@Html.ValidationMessageFor(x => x.Cutoff)
-
+
-
@{var qualitiesList = (List)ViewData["Qualities"];} @@ -55,12 +67,12 @@ { continue; } - + if (Model.Allowed != null) { if (Model.Allowed.Contains(qualitiesList[i])) { -
@qualitiesList[i].ToString()
+
@qualitiesList[i].ToString()
continue; } } @@ -69,10 +81,8 @@ }
-
@Html.HiddenFor(x => x.QualityProfileId) - @Html.HiddenFor(x => x.UserProfile) @Html.HiddenFor(m => m.AllowedString)
@@ -100,13 +110,12 @@ }).keyup(); $('#@selectable .quality-selectee').click(function () { - if ($(this).hasClass('quality-selected')) - { + if ($(this).hasClass('quality-selected')) { $(this).removeClass('quality-selected'); var toRemove = this.firstChild.data; $('#@cutoff option').each(function () { if ($(this).text().indexOf(toRemove) > -1) $('#@cutoff option').remove(':contains("' + $(this).text() + '")'); }); } - + else { $(this).addClass('quality-selected'); $('').appendTo('#@cutoff'); From a6fe8b276b8f4618dde67f1226c3a82d4e3a464f Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 4 Jun 2011 10:59:09 -0700 Subject: [PATCH 2/3] minor updates to test project --- NzbDrone.Core.Test/App.config | 4 ++ NzbDrone.Core.Test/Framework/MockLib.cs | 7 ++- NzbDrone.Core.Test/RepoTest.cs | 60 ++++++++++++++----------- 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/NzbDrone.Core.Test/App.config b/NzbDrone.Core.Test/App.config index a67132955..6e63be8ce 100644 --- a/NzbDrone.Core.Test/App.config +++ b/NzbDrone.Core.Test/App.config @@ -1,5 +1,9 @@  + + + + diff --git a/NzbDrone.Core.Test/Framework/MockLib.cs b/NzbDrone.Core.Test/Framework/MockLib.cs index 91d316551..08e9aba04 100644 --- a/NzbDrone.Core.Test/Framework/MockLib.cs +++ b/NzbDrone.Core.Test/Framework/MockLib.cs @@ -44,12 +44,15 @@ namespace NzbDrone.Core.Test.Framework Console.WriteLine("Creating an empty SQLite database"); var provider = ProviderFactory.GetProvider("Data Source=" + Guid.NewGuid() + ".db;Version=3;New=True", "System.Data.SQLite"); + + var repo = new SimpleRepository(provider, SimpleRepositoryOptions.RunMigrations); + ForceMigration(repo); + if (enableLogging) { provider.Log = new NlogWriter(); } - var repo = new SimpleRepository(provider, SimpleRepositoryOptions.RunMigrations); - ForceMigration(repo); + return repo; } diff --git a/NzbDrone.Core.Test/RepoTest.cs b/NzbDrone.Core.Test/RepoTest.cs index ba5470f35..55852a919 100644 --- a/NzbDrone.Core.Test/RepoTest.cs +++ b/NzbDrone.Core.Test/RepoTest.cs @@ -25,7 +25,7 @@ namespace NzbDrone.Core.Test var fakeEpisode = Builder.CreateNew().With(c => c.SeriesId = 69).Build(); //Act - var repo = MockLib.GetEmptyRepository(); + var repo = MockLib.GetEmptyRepository(true); repo.Add(fakeSeries); repo.Add(fakeEpisode); var fetchedSeries = repo.Single(fakeSeries.SeriesId); @@ -42,32 +42,40 @@ namespace NzbDrone.Core.Test } [Test] - public void ToString_test_over_castle_proxy() + [Ignore] + public void query_scratch_pad() { - //Arrange - var fakeSeries = Builder.CreateNew().With(s => s.SeriesId = 69).Build(); - var fakeEpisode = Builder.CreateNew().With(c => c.SeriesId = 69).Build(); - //Act var repo = MockLib.GetEmptyRepository(true); - repo.Add(fakeSeries); - repo.Add(fakeEpisode); - Console.WriteLine("Getting single"); - var fetchedEpisode = repo.Single(fakeEpisode.EpisodeId); + + repo.All().Where(e => !e.Ignored && e.AirDate <= DateTime.Today && e.AirDate.Year > 1900).Select( + s => s.Title).ToList(); + } + + + [Test] + [Ignore] + public void episode_proxy_to_string() + { + var episode = Builder.CreateNew() + .Build(); + var series = Builder.CreateNew() + .With(s => s.SeriesId = episode.SeriesId) + .Build(); + + var repo = MockLib.GetEmptyRepository(true); + repo.Add(episode); + repo.Add(series); + + //Act + + var result = repo.Single(episode.EpisodeId).ToString(); //Assert - Console.WriteLine("Doing assert"); - Assert.AreEqual(fakeEpisode.EpisodeId, fetchedEpisode.EpisodeId); - Console.WriteLine("Doing assert"); - Assert.AreEqual(fakeEpisode.Title, fetchedEpisode.Title); - - Console.WriteLine("======================="); - var ttt = fetchedEpisode.Series; - Console.WriteLine("======================="); - var tttd = fetchedEpisode.Series; - Console.WriteLine("======================="); - - //Assert.Contains(fetchedEpisode.ToString(), fakeSeries.Title); + Console.WriteLine(result); + result.Should().Contain(series.Title); + result.Should().Contain(episode.EpisodeNumber.ToString()); + result.Should().Contain(episode.SeasonNumber.ToString()); } @@ -78,7 +86,7 @@ namespace NzbDrone.Core.Test public void tvdbid_is_preserved() { //Arrange - var sonicRepo = MockLib.GetEmptyRepository(); + var sonicRepo = MockLib.GetEmptyRepository(true); var series = Builder.CreateNew().With(c => c.SeriesId = 18).Build(); //Act @@ -105,7 +113,7 @@ namespace NzbDrone.Core.Test //setup var message = Guid.NewGuid().ToString(); - var sonicRepo = MockLib.GetEmptyRepository(); + var sonicRepo = MockLib.GetEmptyRepository(true); var sonicTarget = new SubsonicTarget(sonicRepo); @@ -138,7 +146,7 @@ namespace NzbDrone.Core.Test //setup var message = Guid.NewGuid().ToString(); - var sonicRepo = MockLib.GetEmptyRepository(); + var sonicRepo = MockLib.GetEmptyRepository(true); var sonicTarget = new SubsonicTarget(sonicRepo); LogManager.Configuration.AddTarget("DbLogger", sonicTarget); @@ -171,7 +179,7 @@ namespace NzbDrone.Core.Test //setup var message = String.Empty; - var sonicRepo = MockLib.GetEmptyRepository(); + var sonicRepo = MockLib.GetEmptyRepository(true); var sonicTarget = new SubsonicTarget(sonicRepo); LogManager.Configuration.AddTarget("DbLogger", sonicTarget); From a1653022ad280c8aed28dbeae8f6b1e15ec5ada4 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 4 Jun 2011 11:19:22 -0700 Subject: [PATCH 3/3] refactored Migrations --- NzbDrone.Core/CentralDispatch.cs | 8 +-- NzbDrone.Core/Datastore/Connection.cs | 66 +++---------------- NzbDrone.Core/Datastore/Migrations.cs | 13 ++-- NzbDrone.Core/Datastore/RepositoryProvider.cs | 2 +- 4 files changed, 20 insertions(+), 69 deletions(-) diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index 36e0d53ae..c5a4f887a 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -56,7 +56,7 @@ namespace NzbDrone.Core LogConfiguration.Setup(); - Migrations.Run(); + Migrations.Run(Connection.MainConnectionString); ForceMigration(_kernel.Get()); SetupDefaultQualityProfiles(_kernel.Get()); //Setup the default QualityProfiles on start-up @@ -97,9 +97,9 @@ namespace NzbDrone.Core _kernel.Bind().ToSelf().InSingletonScope(); _kernel.Bind().ToSelf().InSingletonScope(); - _kernel.Bind().ToConstant(Connection.MainDataRepository).InSingletonScope(); - _kernel.Bind().ToConstant(Connection.LogDataRepository).WhenInjectedInto().InSingletonScope(); - _kernel.Bind().ToConstant(Connection.LogDataRepository).WhenInjectedInto().InSingletonScope(); + _kernel.Bind().ToConstant(Connection.CreateSimpleRepository(Connection.MainConnectionString)).InSingletonScope(); + _kernel.Bind().ToConstant(Connection.CreateSimpleRepository(Connection.LogConnectionString)).WhenInjectedInto().InSingletonScope(); + _kernel.Bind().ToConstant(Connection.CreateSimpleRepository(Connection.LogConnectionString)).WhenInjectedInto().InSingletonScope(); } } diff --git a/NzbDrone.Core/Datastore/Connection.cs b/NzbDrone.Core/Datastore/Connection.cs index e8e7b6a10..40a5f56cc 100644 --- a/NzbDrone.Core/Datastore/Connection.cs +++ b/NzbDrone.Core/Datastore/Connection.cs @@ -18,82 +18,36 @@ namespace NzbDrone.Core.Datastore } - public static String MainConnectionString - { - get - { - return String.Format("Data Source={0};Version=3;", Path.Combine(AppDataPath.FullName, "nzbdrone.db")); - } - } - - public static String LogConnectionString + public static string GetConnectionString(string path) { - get - { - return String.Format("Data Source={0};Version=3;", Path.Combine(AppDataPath.FullName, "log.db")); - } + return String.Format("Data Source={0};Version=3;", path); } - - private static IDataProvider _mainDataProvider; - public static IDataProvider MainDataProvider + public static String MainConnectionString { get { - if (_mainDataProvider == null) - { - _mainDataProvider = ProviderFactory.GetProvider(Connection.MainConnectionString, "System.Data.SQLite"); - } - return _mainDataProvider; + return GetConnectionString(Path.Combine(AppDataPath.FullName, "nzbdrone.db")); } - } - private static IDataProvider _logDataProvider; - public static IDataProvider LogDataProvider + public static String LogConnectionString { get { - if (_logDataProvider == null) - { - _logDataProvider = ProviderFactory.GetProvider(Connection.LogConnectionString, "System.Data.SQLite"); - } - return _logDataProvider; + return GetConnectionString(Path.Combine(AppDataPath.FullName, "log.db")); } - } - - private static SimpleRepository _mainDataRepository; - public static SimpleRepository MainDataRepository + public static IDataProvider GetDataProvider(string connectionString) { - get - { - if (_mainDataRepository == null) - { - _mainDataRepository = new SimpleRepository(MainDataProvider, SimpleRepositoryOptions.RunMigrations); - } - - return _mainDataRepository; - } - + return ProviderFactory.GetProvider(connectionString, "System.Data.SQLite"); } - private static SimpleRepository _logDataRepository; - public static SimpleRepository LogDataRepository + public static IRepository CreateSimpleRepository(string connectionString) { - get - { - if (_logDataRepository == null) - { - _logDataRepository = new SimpleRepository(LogDataProvider, SimpleRepositoryOptions.RunMigrations); - } - return _logDataRepository; - } - + return new SimpleRepository(GetDataProvider(connectionString), SimpleRepositoryOptions.RunMigrations); } - - } } diff --git a/NzbDrone.Core/Datastore/Migrations.cs b/NzbDrone.Core/Datastore/Migrations.cs index 4ce5a02be..ae677b957 100644 --- a/NzbDrone.Core/Datastore/Migrations.cs +++ b/NzbDrone.Core/Datastore/Migrations.cs @@ -16,16 +16,16 @@ namespace NzbDrone.Core.Datastore { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public static void Run() + public static void Run(string connetionString) { - Logger.Info("Preparing to migrate databse"); + Logger.Info("Preparing run database migration"); try { - var mig = new Migrator.Migrator("Sqlite", Connection.MainConnectionString, + var migrator = new Migrator.Migrator("Sqlite", connetionString, Assembly.GetAssembly(typeof(Migrations)), true, new MigrationLogger()); - mig.MigrateToLastVersion(); + migrator.MigrateToLastVersion(); Logger.Info("Database migration completed"); } @@ -111,10 +111,7 @@ namespace NzbDrone.Core.Datastore { public override void Up() { - if(Database.TableExists("Seasons")) - { - Database.RemoveTable("Seasons"); - } + Database.RemoveTable("Seasons"); Migrations.RemoveDeletedColumns(Database); Migrations.AddNewColumns(Database); diff --git a/NzbDrone.Core/Datastore/RepositoryProvider.cs b/NzbDrone.Core/Datastore/RepositoryProvider.cs index 7861b9526..11006811d 100644 --- a/NzbDrone.Core/Datastore/RepositoryProvider.cs +++ b/NzbDrone.Core/Datastore/RepositoryProvider.cs @@ -26,7 +26,7 @@ namespace NzbDrone.Core.Datastore public virtual ITable GetSchemaFromType(Type type) { - return type.ToSchemaTable(Connection.MainDataProvider); + return type.ToSchemaTable(Connection.GetDataProvider(Connection.MainConnectionString)); } public virtual Column[] GetColumnsFromDatabase(ITransformationProvider database, string tableName)