diff --git a/NzbDrone.Common/Messaging/MessageAggregator.cs b/NzbDrone.Common/Messaging/MessageAggregator.cs index dd88ff283..6089dd4ec 100644 --- a/NzbDrone.Common/Messaging/MessageAggregator.cs +++ b/NzbDrone.Common/Messaging/MessageAggregator.cs @@ -9,20 +9,24 @@ namespace NzbDrone.Common.Messaging public class MessageAggregator : IMessageAggregator { private readonly Logger _logger; - private readonly Func> _handlers; + private readonly Func> _handlerFactory; public MessageAggregator(Logger logger, Func> handlers) { _logger = logger; - _handlers = handlers; + _handlerFactory = handlers; } public void PublishEvent(TEvent @event) where TEvent : IEvent { _logger.Trace("Publishing {0}", @event.GetType().Name); + + var handlers = _handlerFactory().ToList(); + + //call synchronous handlers first. - foreach (var handler in _handlers().OfType>()) + foreach (var handler in handlers.OfType>()) { try { @@ -36,7 +40,7 @@ namespace NzbDrone.Common.Messaging } } - foreach (var handler in _handlers().OfType>()) + foreach (var handler in handlers.OfType>()) { var handlerLocal = handler; Task.Factory.StartNew(() => @@ -52,7 +56,7 @@ namespace NzbDrone.Common.Messaging public void PublishCommand(TCommand command) where TCommand : ICommand { _logger.Trace("Publishing {0}", command.GetType().Name); - var handler = _handlers().OfType>().Single(); + var handler = _handlerFactory().OfType>().Single(); _logger.Debug("{0} -> {1}", command.GetType().Name, handler.GetType().Name); handler.Execute(command); _logger.Debug("{0} <- {1}", command.GetType().Name, handler.GetType().Name); diff --git a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs index b305d21cd..c991a3860 100644 --- a/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs +++ b/NzbDrone.Core.Test/Datastore/ObjectDatabaseFixture.cs @@ -106,21 +106,19 @@ namespace NzbDrone.Core.Test.Datastore { var childModel = new JobDefinition { - Type = "Address", - Name = "Name", + Name = "Address", Interval = 12 }; Subject.Insert(childModel); - childModel.Type = "A"; - childModel.Name = "B"; + childModel.Name = "A"; childModel.Interval = 0; Subject.SetFields(childModel, t => t.Name); - Db.All().Single().Type.Should().Be("Address"); + Db.All().Single().Name.Should().Be("Address"); Db.All().Single().Name.Should().Be("B"); Db.All().Single().Interval.Should().Be(12); } diff --git a/NzbDrone.Core.Test/JobTests/DiskScanJobTest.cs b/NzbDrone.Core.Test/JobTests/DiskScanJobTest.cs deleted file mode 100644 index 4017bc35b..000000000 --- a/NzbDrone.Core.Test/JobTests/DiskScanJobTest.cs +++ /dev/null @@ -1,111 +0,0 @@ - - -using System; -using System.Collections.Generic; - -using FizzWare.NBuilder; -using Moq; -using NUnit.Framework; -using NzbDrone.Core.Jobs.Implementations; -using NzbDrone.Core.MediaFiles; -using NzbDrone.Core.Tv; -using NzbDrone.Core.Jobs; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Providers; - -using NzbDrone.Core.Test.Framework; -using NzbDrone.Test.Common; -using NzbDrone.Test.Common.AutoMoq; -using System.Linq; - -namespace NzbDrone.Core.Test.JobTests -{ - [TestFixture] - - public class DiskScanJobTest : CoreTest - { - [Test] - public void series_specific_scan_should_scan_series() - { - var series = Builder.CreateNew() - .With(s => s.Id = 12) - .Build(); - - Mocker.GetMock() - .Setup(p => p.Get(series.Id)) - .Returns(series); - - - Mocker.Resolve().Start(new ProgressNotification("Test"), new { SeriesId = series.Id }); - - - Mocker.VerifyAllMocks(); - } - - - - [Test] - public void job_with_no_target_should_scan_all_series() - { - var series = Builder.CreateListOfSize(2) - .TheFirst(1).With(s => s.Id = 12) - .TheNext(1).With(s => s.Id = 15) - .Build().ToList(); - - Mocker.GetMock() - .Setup(p => p.All()) - .Returns(series); - - - Mocker.Resolve().Start(new ProgressNotification("Test"), null); - - - Mocker.VerifyAllMocks(); - } - - [Test] - public void failed_scan_should_not_terminated_job() - { - var series = Builder.CreateListOfSize(2) - .TheFirst(1).With(s => s.Id = 12) - .TheNext(1).With(s => s.Id = 15) - .Build().ToList(); - - Mocker.GetMock() - .Setup(p => p.All()) - .Returns(series); - - Mocker.GetMock() - .Setup(s => s.Scan(series[0])) - .Throws(new InvalidOperationException("Bad Job")); - - Mocker.GetMock() - .Setup(s => s.Scan(series[1])) - .Throws(new InvalidOperationException("Bad Job")); - - Mocker.Resolve().Start(new ProgressNotification("Test"), null); - - - Mocker.VerifyAllMocks(); - ExceptionVerification.ExpectedErrors(2); - } - - [Test] - public void job_with_no_target_should_scan_series_with_episodes() - { - var series = Builder.CreateListOfSize(2) - .TheFirst(1).With(s => s.Id = 12) - .TheNext(1).With(s => s.Id = 15) - .Build().ToList(); - - Mocker.GetMock() - .Setup(p => p.All()) - .Returns(series); - - Mocker.Resolve().Start(new ProgressNotification("Test"), null); - - Mocker.VerifyAllMocks(); - Mocker.GetMock().Verify(s => s.Scan(It.IsAny()), Times.Exactly(2)); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core.Test/JobTests/JobControllerFixture.cs b/NzbDrone.Core.Test/JobTests/JobControllerFixture.cs deleted file mode 100644 index 578ddb3ab..000000000 --- a/NzbDrone.Core.Test/JobTests/JobControllerFixture.cs +++ /dev/null @@ -1,232 +0,0 @@ -/* -using System.Linq; -using System; -using System.Collections.Generic; -using System.Threading; -using FluentAssertions; -using Moq; -using NCrunch.Framework; -using NUnit.Framework; -using NzbDrone.Core.Jobs; -using NzbDrone.Core.Jobs.Implementations; -using NzbDrone.Core.Model; -using NzbDrone.Core.Test.Framework; -using NzbDrone.Test.Common; - -namespace NzbDrone.Core.Test.JobTests -{ - /* [TestFixture] - [ExclusivelyUses("JOB_PROVIDER")] - public class JobControllerFixture : CoreTest - { - - FakeJob _fakeJob; - SlowJob _slowJob; - SlowJob2 _slowJob2; - BrokenJob _brokenJob; - DisabledJob _disabledJob; - - - private JobDefinition _updatedJob = null; - - [SetUp] - public void Setup() - { - _fakeJob = new FakeJob(); - _slowJob = new SlowJob(); - _slowJob2 = new SlowJob2(); - _brokenJob = new BrokenJob(); - _disabledJob = new DisabledJob(); - _updatedJob = null; - - IEnumerable jobs = new List { _fakeJob, _slowJob, _slowJob2, _brokenJob, _disabledJob }; - - Mocker.SetConstant(jobs); - - Mocker.GetMock() - .Setup(c => c.Update(It.IsAny())) - .Callback(c => _updatedJob = c); - - - Mocker.GetMock() - .Setup(c => c.GetDefinition(It.IsAny())) - .Returns(new JobDefinition()); - } - - - private void GivenPendingJob(IList jobDefinition) - { - Mocker.GetMock().Setup(c => c.GetPendingJobs()).Returns(jobDefinition); - } - - [TearDown] - public void TearDown() - { - Subject.Queue.Should().BeEmpty(); - } - - private void WaitForQueue() - { - Console.WriteLine("Waiting for queue to clear."); - var queue = Mocker.Resolve().Queue; - - while (Subject.IsProcessing) - { - Thread.Sleep(100); - } - } - - [Test] - public void running_scheduled_jobs_should_updates_last_execution_time() - { - GivenPendingJob(new List { new JobDefinition { Type = _fakeJob.GetType().FullName } }); - - Subject.EnqueueScheduled(); - WaitForQueue(); - - _updatedJob.LastExecution.Should().BeWithin(TimeSpan.FromSeconds(10)); - _updatedJob.LastExecution.Should().BeWithin(TimeSpan.FromSeconds(10)); - _fakeJob.ExecutionCount.Should().Be(1); - } - - [Test] - public void failing_scheduled_job_should_mark_job_as_failed() - { - GivenPendingJob(new List { new JobDefinition { Type = _brokenJob.GetType().FullName } }); - - Subject.EnqueueScheduled(); - WaitForQueue(); - - _updatedJob.LastExecution.Should().BeWithin(TimeSpan.FromSeconds(10)); - _updatedJob.Success.Should().BeFalse(); - _brokenJob.ExecutionCount.Should().Be(1); - ExceptionVerification.ExpectedErrors(1); - } - - [Test] - public void can_run_job_again() - { - Subject.Enqueue(typeof(FakeJob)); - WaitForQueue(); - Subject.Enqueue(typeof(FakeJob)); - WaitForQueue(); - - Subject.Queue.Should().BeEmpty(); - _fakeJob.ExecutionCount.Should().Be(2); - } - - [Test] - public void should_ignore_job_with_same_arg() - { - Subject.Enqueue(typeof(SlowJob2), 1); - Subject.Enqueue(typeof(FakeJob), 1); - Subject.Enqueue(typeof(FakeJob), 1); - - WaitForQueue(); - - Subject.Queue.Should().BeEmpty(); - _fakeJob.ExecutionCount.Should().Be(1); - ExceptionVerification.AssertNoUnexcpectedLogs(); - } - - - [Test] - public void can_run_broken_job_again() - { - Subject.Enqueue(typeof(BrokenJob)); - WaitForQueue(); - - Subject.Enqueue(typeof(BrokenJob)); - WaitForQueue(); - - - _brokenJob.ExecutionCount.Should().Be(2); - ExceptionVerification.ExpectedErrors(2); - } - - [Test] - public void schedule_hit_should_be_ignored_if_queue_is_running() - { - Subject.Enqueue(typeof(SlowJob)); - Subject.EnqueueScheduled(); - WaitForQueue(); - - _slowJob.ExecutionCount.Should().Be(1); - _fakeJob.ExecutionCount.Should().Be(0); - } - - - [Test] - public void can_queue_jobs_at_the_same_time() - { - - Subject.Enqueue(typeof(SlowJob)); - var thread1 = new Thread(() => Subject.Enqueue(typeof(FakeJob))); - var thread2 = new Thread(() => Subject.Enqueue(typeof(FakeJob))); - - thread1.Start(); - thread2.Start(); - - thread1.Join(); - thread2.Join(); - - WaitForQueue(); - - _fakeJob.ExecutionCount.Should().Be(1); - _slowJob.ExecutionCount.Should().Be(1); - Subject.Queue.Should().BeEmpty(); - } - - - [Test] - public void job_with_specific_target_should_not_update_status() - { - Subject.Enqueue(typeof(FakeJob), 10); - - WaitForQueue(); - - Mocker.GetMock().Verify(c => c.Update(It.IsAny()), Times.Never()); - _updatedJob.Should().BeNull(); - } - - - - [Test] - public void Item_added_to_queue_while_scheduler_runs_should_be_executed() - { - GivenPendingJob(new List { new JobDefinition { Type = _slowJob.GetType().FullName } }); - - var jobThread = new Thread(Subject.EnqueueScheduled); - jobThread.Start(); - - Thread.Sleep(200); - - Subject.Enqueue(typeof(DisabledJob), 12); - - WaitForQueue(); - - _slowJob.ExecutionCount.Should().Be(1); - _disabledJob.ExecutionCount.Should().Be(1); - } - - [Test] - public void trygin_to_queue_unregistered_job_should_fail() - { - Subject.Enqueue(typeof(UpdateInfoJob)); - WaitForQueue(); - ExceptionVerification.ExpectedErrors(1); - } - - [Test] - public void scheduled_job_should_have_scheduler_as_source() - { - GivenPendingJob(new List { new JobDefinition { Type = _slowJob.GetType().FullName }, new JobDefinition { Type = _slowJob2.GetType().FullName } }); - Subject.EnqueueScheduled(); - - Subject.Queue.Should().OnlyContain(c => c.Source == JobQueueItem.JobSourceType.Scheduler); - - WaitForQueue(); - }#1# - } -} -*/ diff --git a/NzbDrone.Core.Test/JobTests/JobRepositoryFixture.cs b/NzbDrone.Core.Test/JobTests/JobRepositoryFixture.cs index c6e615da4..471a99177 100644 --- a/NzbDrone.Core.Test/JobTests/JobRepositoryFixture.cs +++ b/NzbDrone.Core.Test/JobTests/JobRepositoryFixture.cs @@ -1,4 +1,4 @@ -using System.Linq; +/* using System; using System.Collections.Generic; using FizzWare.NBuilder; @@ -42,11 +42,10 @@ namespace NzbDrone.Core.Test.JobTests Storage.All().Should().HaveCount(1); StoredModel.Interval.Should().Be((Int32)_fakeJob.DefaultInterval.TotalMinutes); StoredModel.Name.Should().Be(_fakeJob.Name); - StoredModel.Type.Should().Be(_fakeJob.GetType().ToString()); + StoredModel.Name.Should().Be(_fakeJob.GetType().ToString()); StoredModel.LastExecution.Should().HaveYear(DateTime.Now.Year); StoredModel.LastExecution.Should().HaveMonth(DateTime.Now.Month); StoredModel.LastExecution.Should().HaveDay(DateTime.Today.Day); - StoredModel.Enable.Should().BeTrue(); } [Test] @@ -63,13 +62,13 @@ namespace NzbDrone.Core.Test.JobTests //Make sure deleted job is stored AllStoredModels.Should().HaveCount(1); - AllStoredModels.Should().Contain(c => c.Type == deletedJob.Type); + AllStoredModels.Should().Contain(c => c.Name == deletedJob.Name); Initialize(); //Make sure init has cleaned up the deleted job AllStoredModels.Should().HaveCount(1); - AllStoredModels.Should().NotContain(c => c.Type == deletedJob.Type); + AllStoredModels.Should().NotContain(c => c.Name == deletedJob.Name); } [Test] @@ -87,13 +86,13 @@ namespace NzbDrone.Core.Test.JobTests //Make sure deleted job is stored AllStoredModels.Should().HaveCount(1); - AllStoredModels.Should().Contain(c => c.Type == deletedJob.Type); + AllStoredModels.Should().Contain(c => c.Name == deletedJob.Name); Initialize(); //Make sure init has cleaned up the deleted job AllStoredModels.Should().HaveCount(1); - AllStoredModels.Should().NotContain(c => c.Type == deletedJob.Type); + AllStoredModels.Should().NotContain(c => c.Name == deletedJob.Name); } [Test] @@ -103,9 +102,8 @@ namespace NzbDrone.Core.Test.JobTests var oldJob = Builder.CreateNew() .With(c => c.Id = 0) .With(c => c.Name = "OldName") - .With(c => c.Type = typeof(FakeJob).ToString()) + .With(c => c.Name = typeof(FakeJob).ToString()) .With(c => c.Interval = 0) - .With(c => c.Enable = true) .With(c => c.Success = true) .With(c => c.LastExecution = DateTime.Now.AddDays(-7).Date) .Build(); @@ -121,27 +119,13 @@ namespace NzbDrone.Core.Test.JobTests AllStoredModels.Should().HaveCount(1); - StoredModel.Type.Should().Be(newJob.GetType().FullName); + StoredModel.Name.Should().Be(newJob.GetType().FullName); StoredModel.Name.Should().Be(newJob.Name); StoredModel.Interval.Should().Be((int)newJob.DefaultInterval.TotalMinutes); - StoredModel.Enable.Should().Be(true); StoredModel.Success.Should().Be(oldJob.Success); StoredModel.LastExecution.Should().Be(oldJob.LastExecution); } - [Test] - public void jobs_with_zero_interval_are_registered_as_disabled() - { - IEnumerable fakeJobs = new List { _disabledJob }; - Mocker.SetConstant(fakeJobs); - - Initialize(); - - - Storage.All().Should().HaveCount(1); - Storage.All().First().Enable.Should().BeFalse(); - } - [Test] public void pending_job_should_get_jobs_that_have_matured() @@ -149,7 +133,6 @@ namespace NzbDrone.Core.Test.JobTests var oldJob = Builder.CreateNew() .With(c => c.Id = 0) .With(c => c.Interval = 1) - .With(c => c.Enable = true) .With(c => c.Success = true) .With(c => c.LastExecution = DateTime.Now.AddMinutes(-5)) .Build(); @@ -168,7 +151,6 @@ namespace NzbDrone.Core.Test.JobTests var recent = Builder.CreateNew() .With(c => c.Id = 0) .With(c => c.Interval = 60) - .With(c => c.Enable = true) .With(c => c.Success = true) .With(c => c.LastExecution = DateTime.Now.AddMinutes(-5)) .Build(); @@ -193,7 +175,8 @@ namespace NzbDrone.Core.Test.JobTests disabledJob.ExecutionCount.Should().Be(0); - }*/ + }#1# } } +*/ diff --git a/NzbDrone.Core.Test/JobTests/PostDownloadScanJobFixture.cs b/NzbDrone.Core.Test/JobTests/PostDownloadScanJobFixture.cs deleted file mode 100644 index 521fb1ec1..000000000 --- a/NzbDrone.Core.Test/JobTests/PostDownloadScanJobFixture.cs +++ /dev/null @@ -1,65 +0,0 @@ -using Moq; -using NUnit.Framework; -using NzbDrone.Common; -using NzbDrone.Core.Configuration; -using NzbDrone.Core.Jobs.Implementations; -using NzbDrone.Core.Providers; -using NzbDrone.Core.Test.Framework; - -namespace NzbDrone.Core.Test.JobTests -{ - [TestFixture] - public class PostDownloadScanJobFixture : CoreTest - { - [SetUp] - public void Setup() - { - Mocker.GetMock().Setup(s => s.FolderExists(It.IsAny())).Returns(true); - } - - [Test] - public void should_use_options_Path_when_provided() - { - var path = @"C:\Test\Unsorted TV"; - - Mocker.GetMock().Setup(s => s.ProcessDropFolder(path)); - Subject.Start(MockNotification, new { Path = path }); - - Mocker.GetMock().Verify(s => s.ProcessDropFolder(path), Times.Once()); - } - - [Test] - public void should_not_get_sabDropDir_when_path_is_supplied() - { - var path = @"C:\Test\Unsorted TV"; - - Mocker.GetMock().Setup(s => s.ProcessDropFolder(path)); - Subject.Start(MockNotification, new { Path = path }); - - Mocker.GetMock().Verify(s => s.DownloadClientTvDirectory, Times.Never()); - } - - [Test] - public void should_get_sabDropDir_when_path_is_not_supplied() - { - var path = @"C:\Test\Unsorted TV"; - - Mocker.GetMock().SetupGet(s => s.DownloadClientTvDirectory).Returns(path); - Subject.Start(MockNotification, null); - - Mocker.GetMock().Verify(s => s.DownloadClientTvDirectory, Times.Once()); - } - - [Test] - public void should_use_sabDropDir_when_options_Path_is_not_provided() - { - var path = @"C:\Test\Unsorted TV"; - - Mocker.GetMock().SetupGet(s => s.DownloadClientTvDirectory).Returns(path); - - Subject.Start(MockNotification, null); - - Mocker.GetMock().Verify(s => s.ProcessDropFolder(path), Times.Once()); - } - } -} diff --git a/NzbDrone.Core.Test/JobTests/RenameSeasonJobFixture.cs b/NzbDrone.Core.Test/JobTests/RenameSeasonJobFixture.cs deleted file mode 100644 index 45b7a80a6..000000000 --- a/NzbDrone.Core.Test/JobTests/RenameSeasonJobFixture.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using FizzWare.NBuilder; -using NUnit.Framework; -using NzbDrone.Core.Jobs.Implementations; -using NzbDrone.Core.MediaFiles; -using NzbDrone.Core.Tv; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Test.Common; - -namespace NzbDrone.Core.Test.JobTests -{ - [TestFixture] - public class RenameSeasonJobFixture : TestBase - { - private ProgressNotification _testNotification; - private Series _series; - private IList _episodeFiles; - - [SetUp] - public void Setup() - { - _testNotification = new ProgressNotification("TEST"); - - _series = Builder - .CreateNew() - .Build(); - - _episodeFiles = Builder - .CreateListOfSize(5) - .All() - .With(e => e.SeasonNumber = 5) - .Build(); - - Mocker.GetMock() - .Setup(s => s.Get(_series.Id)) - .Returns(_series); - - Mocker.GetMock() - .Setup(s => s.GetFilesBySeason(_series.Id, 5)) - .Returns(_episodeFiles.ToList()); - } - - - [Test] - public void should_throw_if_seriesId_is_zero() - { - Assert.Throws(() => - Mocker.Resolve().Start(_testNotification, new { SeriesId = 0, SeasonNumber = 10 })); - } - - [Test] - public void should_throw_if_seasonId_is_less_than_zero() - { - Assert.Throws(() => - Mocker.Resolve().Start(_testNotification, new { SeriesId = _series.Id, SeasonNumber = -10 })); - } - - [Test] - public void should_log_warning_if_no_episode_files_are_found() - { - Mocker.Resolve().Start(_testNotification, new { SeriesId = _series.Id, SeasonNumber = 10 }); - - ExceptionVerification.ExpectedWarns(1); - } - - - } -} diff --git a/NzbDrone.Core.Test/JobTests/TestJobs.cs b/NzbDrone.Core.Test/JobTests/TestJobs.cs index fe3a05ca0..06d5f32b9 100644 --- a/NzbDrone.Core.Test/JobTests/TestJobs.cs +++ b/NzbDrone.Core.Test/JobTests/TestJobs.cs @@ -1,4 +1,5 @@ -using System; +/* +using System; using System.Linq; using System.Threading; using NzbDrone.Core.Jobs; @@ -66,3 +67,4 @@ namespace NzbDrone.Core.Test.JobTests } } } +*/ diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 45e176593..f80bf9d4b 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -137,8 +137,8 @@ - + @@ -148,7 +148,6 @@ - @@ -174,7 +173,6 @@ - @@ -193,9 +191,7 @@ - - diff --git a/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/CleanupFixture.cs b/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/CleanupFixture.cs index b1f8c4c1d..41d35a3d2 100644 --- a/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/CleanupFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/CleanupFixture.cs @@ -4,6 +4,7 @@ using Moq; using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Core.Configuration; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Providers; using NzbDrone.Core.Test.Framework; diff --git a/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteDirectoryFixture.cs b/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteDirectoryFixture.cs index 331280199..d1efd6d27 100644 --- a/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteDirectoryFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteDirectoryFixture.cs @@ -11,6 +11,7 @@ using Moq; using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Core.Configuration; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; diff --git a/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteFileFixture.cs b/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteFileFixture.cs index 58a9e5211..ec8d8229c 100644 --- a/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteFileFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteFileFixture.cs @@ -11,6 +11,7 @@ using Moq; using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Core.Configuration; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; diff --git a/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/EmptyFixture.cs b/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/EmptyFixture.cs index 3f26467d2..bf6fca51d 100644 --- a/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/EmptyFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/EmptyFixture.cs @@ -11,6 +11,7 @@ using Moq; using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Core.Configuration; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Model; using NzbDrone.Core.Providers; diff --git a/NzbDrone.Core/DataAugmentation/DailySeries/DailySeriesService.cs b/NzbDrone.Core/DataAugmentation/DailySeries/DailySeriesService.cs index 1992a94dd..8aac187fc 100644 --- a/NzbDrone.Core/DataAugmentation/DailySeries/DailySeriesService.cs +++ b/NzbDrone.Core/DataAugmentation/DailySeries/DailySeriesService.cs @@ -4,6 +4,8 @@ namespace NzbDrone.Core.DataAugmentation.DailySeries { public class DailySeriesService { + //TODO: add timer command + private readonly IDailySeriesDataProxy _proxy; private readonly ISeriesService _seriesService; diff --git a/NzbDrone.Core/Datastore/Migration/Migration20130324.cs b/NzbDrone.Core/Datastore/Migration/Migration20130324.cs index 440a110d3..3feca052d 100644 --- a/NzbDrone.Core/Datastore/Migration/Migration20130324.cs +++ b/NzbDrone.Core/Datastore/Migration/Migration20130324.cs @@ -92,8 +92,6 @@ namespace NzbDrone.Core.Datastore.Migration .WithColumn("Name").AsString().Unique(); Create.TableForModel("JobDefinitions") - .WithColumn("Enable").AsBoolean() - .WithColumn("Type").AsString().Unique() .WithColumn("Name").AsString().Unique() .WithColumn("Interval").AsInt32() .WithColumn("LastExecution").AsDateTime() diff --git a/NzbDrone.Core/Instrumentation/TrimLogsJob.cs b/NzbDrone.Core/Instrumentation/TrimLogsJob.cs deleted file mode 100644 index f25ff4dda..000000000 --- a/NzbDrone.Core/Instrumentation/TrimLogsJob.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Linq; -using NzbDrone.Core.Jobs; -using NzbDrone.Core.Model.Notification; - -namespace NzbDrone.Core.Instrumentation -{ - public class TrimLogsJob : IJob - { - private readonly LogService _logService; - - public TrimLogsJob(LogService logService) - { - _logService = logService; - } - - public string Name - { - get { return "Trim Logs Job"; } - } - - public TimeSpan DefaultInterval - { - get { return TimeSpan.FromDays(1); } - } - - public virtual void Start(ProgressNotification notification, dynamic options) - { - _logService.Trim(); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/IJob.cs b/NzbDrone.Core/Jobs/IJob.cs deleted file mode 100644 index bb4d238a4..000000000 --- a/NzbDrone.Core/Jobs/IJob.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Linq; -using NzbDrone.Core.Model.Notification; - -namespace NzbDrone.Core.Jobs -{ - public interface IJob - { - /// - /// Name of the timer. - /// This is the name that will be visible in all UI elements - /// \\\ - string Name { get; } - - - /// - /// Default Interval that this job should run at. In seconds. - /// - /// Setting this value to 0 means the job will not be - /// executed by the schedule and is only triggered manually. - TimeSpan DefaultInterval { get; } - - - /// - /// Starts the job - /// - /// Notification object that is passed in by JobProvider. - /// this object should be used to update the progress on the UI - /// The that should be used to limit the target of this job - /// /// The that should be used to limit the target of this job - void Start(ProgressNotification notification, dynamic options); - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/Implementations/CleanupRecycleBinJob.cs b/NzbDrone.Core/Jobs/Implementations/CleanupRecycleBinJob.cs deleted file mode 100644 index deb5bf06a..000000000 --- a/NzbDrone.Core/Jobs/Implementations/CleanupRecycleBinJob.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Linq; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Providers; - -namespace NzbDrone.Core.Jobs.Implementations -{ - public class CleanupRecycleBinJob : IJob - { - private readonly RecycleBinProvider _recycleBinProvider; - - public CleanupRecycleBinJob(RecycleBinProvider recycleBinProvider) - { - _recycleBinProvider = recycleBinProvider; - } - - public string Name - { - get { return "Cleanup Recycle Bin"; } - } - - public TimeSpan DefaultInterval - { - get { return TimeSpan.FromDays(24); } - } - - public void Start(ProgressNotification notification, dynamic options) - { - _recycleBinProvider.Cleanup(); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/Implementations/ConvertEpisodeJob.cs b/NzbDrone.Core/Jobs/Implementations/ConvertEpisodeJob.cs deleted file mode 100644 index de67936b9..000000000 --- a/NzbDrone.Core/Jobs/Implementations/ConvertEpisodeJob.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Linq; -using NLog; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Providers.Converting; -using NzbDrone.Core.Tv; - -namespace NzbDrone.Core.Jobs.Implementations -{ - public class ConvertEpisodeJob : IJob - { - private readonly HandbrakeProvider _handbrakeProvider; - private readonly AtomicParsleyProvider _atomicParsleyProvider; - private readonly IEpisodeService _episodeService; - - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - - public ConvertEpisodeJob(HandbrakeProvider handbrakeProvider, AtomicParsleyProvider atomicParsleyProvider, - IEpisodeService episodeService) - { - _handbrakeProvider = handbrakeProvider; - _atomicParsleyProvider = atomicParsleyProvider; - _episodeService = episodeService; - } - - public string Name - { - get { return "Convert Episode"; } - } - - public TimeSpan DefaultInterval - { - get { return TimeSpan.FromTicks(0); } - } - - public void Start(ProgressNotification notification, dynamic options) - { - - if (options == null || options.EpisodeId <= 0) - throw new ArgumentNullException(options); - - Episode episode = _episodeService.GetEpisode((int)options.EpisodeId); - notification.CurrentMessage = String.Format("Starting Conversion for {0}", episode); - var outputFile = _handbrakeProvider.ConvertFile(episode, notification); - - if (String.IsNullOrEmpty(outputFile)) - notification.CurrentMessage = String.Format("Conversion failed for {0}", episode); - - _atomicParsleyProvider.RunAtomicParsley(episode, outputFile); - - notification.CurrentMessage = String.Format("Conversion completed for {0}", episode); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/Implementations/DiskScanJob.cs b/NzbDrone.Core/Jobs/Implementations/DiskScanJob.cs deleted file mode 100644 index 0a9daa5b7..000000000 --- a/NzbDrone.Core/Jobs/Implementations/DiskScanJob.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NLog; -using NzbDrone.Core.Configuration; -using NzbDrone.Core.Helpers; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Providers; -using NzbDrone.Core.Tv; - -namespace NzbDrone.Core.Jobs.Implementations -{ - public class DiskScanJob : IJob - { - private readonly IDiskScanService _diskScanService; - private readonly IConfigService _configService; - private readonly ISeriesRepository _seriesRepository; - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - - public DiskScanJob(IDiskScanService diskScanService, - IConfigService configService, ISeriesRepository seriesRepository) - { - _diskScanService = diskScanService; - _configService = configService; - _seriesRepository = seriesRepository; - } - - public string Name - { - get { return "Media File Scan"; } - } - - public TimeSpan DefaultInterval - { - get { return TimeSpan.FromHours(6); } - } - - public virtual void Start(ProgressNotification notification, dynamic options) - { - IList seriesToScan; - if (options == null || options.SeriesId == 0) - { - if (_configService.IgnoreArticlesWhenSortingSeries) - seriesToScan = _seriesRepository.All().OrderBy(o => o.Title.IgnoreArticles()).ToList(); - - else - seriesToScan = _seriesRepository.All().OrderBy(o => o.Title).ToList(); - } - else - { - seriesToScan = new List() { _seriesRepository.Get((int)options.SeriesId) }; - } - - foreach (var series in seriesToScan) - { - try - { - notification.CurrentMessage = string.Format("Scanning disk for '{0}'", series.Title); - _diskScanService.Scan(series); - notification.CurrentMessage = string.Format("Disk Scan completed for '{0}'", series.Title); - } - catch (Exception e) - { - Logger.ErrorException("An error has occurred while scanning " + series.Title, e); - } - } - } - } -} diff --git a/NzbDrone.Core/Jobs/Implementations/EmptyRecycleBinJob.cs b/NzbDrone.Core/Jobs/Implementations/EmptyRecycleBinJob.cs deleted file mode 100644 index 78736706d..000000000 --- a/NzbDrone.Core/Jobs/Implementations/EmptyRecycleBinJob.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Linq; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Providers; - -namespace NzbDrone.Core.Jobs.Implementations -{ - public class EmptyRecycleBinJob : IJob - { - private readonly RecycleBinProvider _recycleBinProvider; - - public EmptyRecycleBinJob(RecycleBinProvider recycleBinProvider) - { - _recycleBinProvider = recycleBinProvider; - } - - public string Name - { - get { return "Empty Recycle Bin"; } - } - - public TimeSpan DefaultInterval - { - get { return TimeSpan.FromTicks(0); } - } - - public void Start(ProgressNotification notification, dynamic options) - { - _recycleBinProvider.Empty(); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/Implementations/PostDownloadScanJob.cs b/NzbDrone.Core/Jobs/Implementations/PostDownloadScanJob.cs deleted file mode 100644 index b81a94ec3..000000000 --- a/NzbDrone.Core/Jobs/Implementations/PostDownloadScanJob.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Linq; -using NLog; -using NzbDrone.Common; -using NzbDrone.Core.Configuration; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Providers; - -namespace NzbDrone.Core.Jobs.Implementations -{ - public class PostDownloadScanJob : IJob - { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - - private readonly IDropFolderImportService _dropFolderImportService; - private readonly IConfigService _configService; - private readonly DiskProvider _diskProvider; - - public PostDownloadScanJob(IDropFolderImportService dropFolderImportService,IConfigService configService, DiskProvider diskProvider) - { - _dropFolderImportService = dropFolderImportService; - _configService = configService; - _diskProvider = diskProvider; - } - - public string Name - { - get { return "Drop folder monitor"; } - } - - public TimeSpan DefaultInterval - { - get { return TimeSpan.FromMinutes(1); } - } - - public virtual void Start(ProgressNotification notification, dynamic options) - { - string dropFolder; - - if (options != null && !String.IsNullOrWhiteSpace(options.Path)) - dropFolder = options.Path; - - else - dropFolder = _configService.DownloadClientTvDirectory; - - if (String.IsNullOrWhiteSpace(dropFolder)) - { - Logger.Debug("No drop folder is defined. Skipping."); - return; - } - - if (!_diskProvider.FolderExists(dropFolder)) - { - Logger.Warn("Unable to Scan for New Downloads - folder Doesn't exist: [{0}]", dropFolder); - return; - } - - _dropFolderImportService.ProcessDropFolder(dropFolder); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/Implementations/RefreshEpisodeMetadata.cs b/NzbDrone.Core/Jobs/Implementations/RefreshEpisodeMetadata.cs deleted file mode 100644 index 95a80051e..000000000 --- a/NzbDrone.Core/Jobs/Implementations/RefreshEpisodeMetadata.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NLog; -using NzbDrone.Core.MediaFiles; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Tv; - -namespace NzbDrone.Core.Jobs.Implementations -{ - public class RefreshEpisodeMetadata : IJob - { - private readonly IMediaFileService _mediaFileService; - private readonly ISeriesRepository _seriesRepository; - - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - - public RefreshEpisodeMetadata(IMediaFileService mediaFileService, ISeriesRepository seriesRepository) - { - _mediaFileService = mediaFileService; - _seriesRepository = seriesRepository; - } - - public string Name - { - get { return "Refresh Episode Metadata"; } - } - - public TimeSpan DefaultInterval - { - get { return TimeSpan.FromTicks(0); } - } - - public void Start(ProgressNotification notification, dynamic options) - { - List seriesToRefresh; - - if (options == null || options.SeriesId <= 0) - seriesToRefresh = _seriesRepository.All().ToList(); - - else - seriesToRefresh = new List { _seriesRepository.Get(options.SeriesId) }; - - foreach (var series in seriesToRefresh) - { - RefreshMetadata(notification, series); - } - } - - private void RefreshMetadata(ProgressNotification notification, Series series) - { - notification.CurrentMessage = String.Format("Refreshing episode metadata for '{0}'", series.Title); - - Logger.Debug("Getting episodes from database for series: {0}", series.Id); - var episodeFiles = _mediaFileService.GetFilesBySeries(series.Id); - - if (episodeFiles == null || episodeFiles.Count == 0) - { - Logger.Warn("No episodes in database found for series: {0}", series.Id); - return; - } - - notification.CurrentMessage = String.Format("Episode metadata refresh completed for {0}", series.Title); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/Implementations/RenameSeasonJob.cs b/NzbDrone.Core/Jobs/Implementations/RenameSeasonJob.cs deleted file mode 100644 index c4624f78d..000000000 --- a/NzbDrone.Core/Jobs/Implementations/RenameSeasonJob.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NLog; -using NzbDrone.Common.Messaging; -using NzbDrone.Core.Download; -using NzbDrone.Core.MediaFiles; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Tv; - -namespace NzbDrone.Core.Jobs.Implementations -{ - public class RenameSeasonJob : IJob - { - private readonly IMediaFileService _mediaFileService; - private readonly ISeriesRepository _seriesRepository; - private readonly IMessageAggregator _messageAggregator; - private readonly IMoveEpisodeFiles _episodeFilesMover; - - private static readonly Logger logger = LogManager.GetCurrentClassLogger(); - - public RenameSeasonJob(IMediaFileService mediaFileService, ISeriesRepository seriesRepository, IMessageAggregator messageAggregator, IMoveEpisodeFiles episodeFilesMover) - { - _mediaFileService = mediaFileService; - _seriesRepository = seriesRepository; - _messageAggregator = messageAggregator; - _episodeFilesMover = episodeFilesMover; - } - - public string Name - { - get { return "Rename Season"; } - } - - public TimeSpan DefaultInterval - { - get { return TimeSpan.FromTicks(0); } - } - - public void Start(ProgressNotification notification, dynamic options) - { - if (options == null || options.SeriesId <= 0) - throw new ArgumentException("options"); - - if (options.SeasonNumber < 0) - throw new ArgumentException("options.SeasonNumber"); - - var series = _seriesRepository.Get((int)options.SeriesId); - - notification.CurrentMessage = String.Format("Renaming episodes for {0} Season {1}", series.Title, options.SeasonNumber); - - logger.Debug("Getting episodes from database for series: {0} and season: {1}", options.SeriesId, options.SeasonNumber); - IList episodeFiles = _mediaFileService.GetFilesBySeason((int)options.SeriesId, (int)options.SeasonNumber); - - if (episodeFiles == null || !episodeFiles.Any()) - { - logger.Warn("No episodes in database found for series: {0} and season: {1}.", options.SeriesId, options.SeasonNumber); - return; - } - - var newEpisodeFiles = new List(); - var oldEpisodeFiles = new List(); - - foreach (var episodeFile in episodeFiles) - { - try - { - var oldFile = new EpisodeFile(episodeFile); - var newFile = _episodeFilesMover.MoveEpisodeFile(episodeFile); - - if (newFile != null) - { - newEpisodeFiles.Add(newFile); - oldEpisodeFiles.Add(oldFile); - } - } - - catch (Exception e) - { - logger.WarnException("An error has occurred while renaming file", e); - } - } - - if (!oldEpisodeFiles.Any()) - { - logger.Trace("No episodes were renamed for: {0} Season {1}, no changes were made", series.Title, - options.SeasonNumber); - notification.CurrentMessage = String.Format("Rename completed for: {0} Season {1}, no changes were made", series.Title, options.SeasonNumber); - return; - } - - //Start AfterRename - _messageAggregator.PublishEvent(new SeriesRenamedEvent(series)); - - notification.CurrentMessage = String.Format("Rename completed for {0} Season {1}", series.Title, options.SeasonNumber); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/Implementations/RenameSeriesJob.cs b/NzbDrone.Core/Jobs/Implementations/RenameSeriesJob.cs deleted file mode 100644 index ca441fdca..000000000 --- a/NzbDrone.Core/Jobs/Implementations/RenameSeriesJob.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NLog; -using NzbDrone.Common.Messaging; -using NzbDrone.Core.Download; -using NzbDrone.Core.MediaFiles; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Tv; - -namespace NzbDrone.Core.Jobs.Implementations -{ - public class RenameSeriesJob : IJob - { - private readonly IMediaFileService _mediaFileService; - private readonly ISeriesRepository _seriesRepository; - private readonly IMessageAggregator _messageAggregator; - private readonly IMoveEpisodeFiles _moveEpisodeFiles; - - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - - public RenameSeriesJob(IMediaFileService mediaFileService, ISeriesRepository seriesRepository, IMessageAggregator messageAggregator, IMoveEpisodeFiles moveEpisodeFiles) - { - _mediaFileService = mediaFileService; - _seriesRepository = seriesRepository; - _messageAggregator = messageAggregator; - _moveEpisodeFiles = moveEpisodeFiles; - } - - public string Name - { - get { return "Rename Series"; } - } - - public TimeSpan DefaultInterval - { - get { return TimeSpan.FromTicks(0); } - } - - public void Start(ProgressNotification notification, dynamic options) - { - List seriesToRename; - - if (options == null || options.SeriesId <= 0) - { - seriesToRename = _seriesRepository.All().ToList(); - } - - else - { - seriesToRename = new List { _seriesRepository.Get((int)options.SeriesId) }; - } - - foreach (var series in seriesToRename) - { - notification.CurrentMessage = String.Format("Renaming episodes for '{0}'", series.Title); - - Logger.Debug("Getting episodes from database for series: {0}", series.Id); - var episodeFiles = _mediaFileService.GetFilesBySeries(series.Id); - - if (episodeFiles == null || episodeFiles.Count == 0) - { - Logger.Warn("No episodes in database found for series: {0}", series.Id); - return; - } - - var newEpisodeFiles = new List(); - var oldEpisodeFiles = new List(); - - foreach (var episodeFile in episodeFiles) - { - try - { - var oldFile = new EpisodeFile(episodeFile); - var newFile = _moveEpisodeFiles.MoveEpisodeFile(episodeFile); - - if (newFile != null) - { - newEpisodeFiles.Add(newFile); - oldEpisodeFiles.Add(oldFile); - } - } - - catch (Exception e) - { - Logger.WarnException("An error has occurred while renaming file", e); - } - } - - //Start AfterRename - - _messageAggregator.PublishEvent(new SeriesRenamedEvent(series)); - - notification.CurrentMessage = String.Format("Rename completed for {0}", series.Title); - } - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/Implementations/RssSyncJob.cs b/NzbDrone.Core/Jobs/Implementations/RssSyncJob.cs deleted file mode 100644 index 72b8ca6c9..000000000 --- a/NzbDrone.Core/Jobs/Implementations/RssSyncJob.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using NzbDrone.Core.Configuration; -using NzbDrone.Core.Indexers; -using NzbDrone.Core.Model.Notification; - -namespace NzbDrone.Core.Jobs.Implementations -{ - public class RssSyncJob : IJob - { - private readonly IRssSyncService _rssSyncServiceService; - private readonly IConfigService _configService; - - - public RssSyncJob(IRssSyncService rssSyncServiceService, IConfigService configService) - { - _rssSyncServiceService = rssSyncServiceService; - _configService = configService; - } - - public string Name - { - get { return "RSS Sync"; } - } - - public TimeSpan DefaultInterval - { - get { return TimeSpan.FromMinutes(_configService.RssSyncInterval); } - } - - public void Start(ProgressNotification notification, dynamic options) - { - _rssSyncServiceService.Sync(); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/Implementations/UpdateInfoJob.cs b/NzbDrone.Core/Jobs/Implementations/UpdateInfoJob.cs deleted file mode 100644 index eb1b5b1c2..000000000 --- a/NzbDrone.Core/Jobs/Implementations/UpdateInfoJob.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using NLog; -using NzbDrone.Core.Configuration; -using NzbDrone.Core.DataAugmentation.DailySeries; -using NzbDrone.Core.Helpers; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Tv; - -namespace NzbDrone.Core.Jobs.Implementations -{ - public class UpdateInfoJob : IJob - { - private readonly ISeriesService _seriesService; - private readonly IEpisodeService _episodeService; - private readonly DailySeriesService _dailySeriesService; - private readonly IConfigService _configService; - private readonly ISeriesRepository _seriesRepository; - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - - public UpdateInfoJob(ISeriesService seriesService, IEpisodeService episodeService, - DailySeriesService dailySeriesService, IConfigService configService, ISeriesRepository seriesRepository) - { - _seriesService = seriesService; - _episodeService = episodeService; - _dailySeriesService = dailySeriesService; - _configService = configService; - _seriesRepository = seriesRepository; - } - - public string Name - { - get { return "Update Episode Info"; } - } - - public TimeSpan DefaultInterval - { - get { return TimeSpan.FromHours(12); } - } - - public virtual void Start(ProgressNotification notification, dynamic options) - { - IList listOfSeriesToUpdate; - if (options == null || options.SeriesId == 0) - { - if (_configService.IgnoreArticlesWhenSortingSeries) - { - listOfSeriesToUpdate = _seriesRepository.All().OrderBy(o => o.Title.IgnoreArticles()).ToList(); - } - else - { - listOfSeriesToUpdate = _seriesRepository.All().OrderBy(o => o.Title).ToList(); - } - } - else - { - listOfSeriesToUpdate = new List - { - _seriesRepository.Get((int) options.SeriesId) - }; - } - - //Update any Daily Series in the DB with the IsDaily flag - _dailySeriesService.UpdateDailySeries(); - - foreach (var seriesToUpdate in listOfSeriesToUpdate) - { - var series = seriesToUpdate; - - try - { - notification.CurrentMessage = "Updating " + series.Title; - series = _seriesService.UpdateSeriesInfo(series.Id); - _episodeService.RefreshEpisodeInfo(series); - notification.CurrentMessage = "Update completed for " + series.Title; - } - - catch (Exception ex) - { - Logger.ErrorException("Failed to update episode info for series: " + series.Title, ex); - } - - } - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/Implementations/XemUpdateJob.cs b/NzbDrone.Core/Jobs/Implementations/XemUpdateJob.cs deleted file mode 100644 index 80d3aecbb..000000000 --- a/NzbDrone.Core/Jobs/Implementations/XemUpdateJob.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Linq; -using NLog; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Providers; - -namespace NzbDrone.Core.Jobs.Implementations -{ - public class XemUpdateJob : IJob - { - private readonly XemProvider _xemProvider; - - private static readonly Logger _logger = LogManager.GetCurrentClassLogger(); - - public XemUpdateJob(XemProvider xemProvider) - { - _xemProvider = xemProvider; - } - - public string Name - { - get { return "XEM Update"; } - } - - public TimeSpan DefaultInterval - { - get { return TimeSpan.FromHours(12); } - } - - public virtual void Start(ProgressNotification notification, dynamic options) - { - if (options == null || options.SeriesId == 0) - { - _logger.Trace("Starting XEM Update for all series"); - _xemProvider.UpdateMappings(); - } - - else - { - _logger.Trace("Starting XEM Update for series: {0}", options.SeriesId); - _xemProvider.UpdateMappings((int)options.SeriesId); - } - - _logger.Trace("XEM Update complete"); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/JobController.cs b/NzbDrone.Core/Jobs/JobController.cs deleted file mode 100644 index 9dff23b99..000000000 --- a/NzbDrone.Core/Jobs/JobController.cs +++ /dev/null @@ -1,188 +0,0 @@ -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using NLog; -using NzbDrone.Common.Messaging; -using NzbDrone.Core.Lifecycle; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Providers; - -namespace NzbDrone.Core.Jobs -{ - public interface IJobController - { - bool IsProcessing { get; } - IEnumerable Queue { get; } - void EnqueueScheduled(); - void Enqueue(Type jobType, dynamic options = null, JobQueueItem.JobSourceType source = JobQueueItem.JobSourceType.User); - bool Enqueue(string jobTypeString); - } - - public class JobController : IJobController, IHandle - { - private readonly NotificationProvider _notificationProvider; - private readonly IEnumerable _jobs; - private readonly IJobRepository _jobRepository; - private readonly Logger _logger; - - private readonly BlockingCollection _queue = new BlockingCollection(); - - private ProgressNotification _notification; - private readonly CancellationTokenSource _cancellationTokenSource; - - public JobController(NotificationProvider notificationProvider, IEnumerable jobs, IJobRepository jobRepository, Logger logger) - { - _notificationProvider = notificationProvider; - _jobs = jobs; - _jobRepository = jobRepository; - _logger = logger; - _cancellationTokenSource = new CancellationTokenSource(); - Task.Factory.StartNew(ProcessQueue, _cancellationTokenSource.Token); - } - - public bool IsProcessing { get; private set; } - - public IEnumerable Queue - { - get - { - return _queue; - } - } - - public void EnqueueScheduled() - { - if (IsProcessing) - { - _logger.Trace("Queue is already running. Ignoring scheduler request."); - return; - } - - var pendingJobs = _jobRepository.GetPendingJobs() - .Select(c => _jobs.Single(t => t.GetType().ToString() == c.Type) - .GetType()).ToList(); - - - pendingJobs.ForEach(jobType => Enqueue(jobType, source: JobQueueItem.JobSourceType.Scheduler)); - _logger.Trace("{0} Scheduled tasks have been added to the queue", pendingJobs.Count); - } - - public void Enqueue(Type jobType, dynamic options = null, JobQueueItem.JobSourceType source = JobQueueItem.JobSourceType.User) - { - IsProcessing = true; - - var queueItem = new JobQueueItem - { - JobType = jobType, - Options = options, - Source = source - }; - - _logger.Debug("Attempting to queue {0}", queueItem); - - lock (_queue) - { - if (!_queue.Contains(queueItem)) - { - _queue.Add(queueItem); - _logger.Trace("Job {0} added to the queue. current items in queue: {1}", queueItem, _queue.Count); - } - else - { - _logger.Info("{0} already exists in the queue. Skipping. current items in queue: {1}", queueItem, _queue.Count); - } - } - - } - - public bool Enqueue(string jobTypeString) - { - var type = Type.GetType(jobTypeString); - - if (type == null) - return false; - - Enqueue(type); - return true; - } - - private void ProcessQueue() - { - while (true) - { - try - { - IsProcessing = false; - var item = _queue.Take(); - Execute(item); - } - catch (ThreadAbortException e) - { - _logger.Warn(e.Message); - } - catch (Exception e) - { - _logger.ErrorException("Error has occurred in queue processor thread", e); - } - } - } - - private void Execute(JobQueueItem queueItem) - { - IsProcessing = true; - - var jobImplementation = _jobs.SingleOrDefault(t => t.GetType() == queueItem.JobType); - if (jobImplementation == null) - { - _logger.Error("Unable to locate implementation for '{0}'. Make sure it is properly registered.", queueItem.JobType); - return; - } - - var jobDefinition = _jobRepository.GetDefinition(queueItem.JobType); - using (_notification = new ProgressNotification(jobImplementation.Name)) - { - try - { - _logger.Debug("Starting {0}. Last execution {1}", queueItem, jobDefinition.LastExecution); - - var sw = Stopwatch.StartNew(); - - _notificationProvider.Register(_notification); - jobImplementation.Start(_notification, queueItem.Options); - _notification.Status = ProgressNotificationStatus.Completed; - - jobDefinition.LastExecution = DateTime.Now; - jobDefinition.Success = true; - - sw.Stop(); - _logger.Debug("Job {0} successfully completed in {1:0}.{2} seconds.", queueItem, sw.Elapsed.TotalSeconds, sw.Elapsed.Milliseconds / 100, - sw.Elapsed.Seconds); - } - catch (Exception e) - { - _logger.ErrorException("An error has occurred while executing job [" + jobImplementation.Name + "].", e); - _notification.Status = ProgressNotificationStatus.Failed; - _notification.CurrentMessage = jobImplementation.Name + " Failed."; - - jobDefinition.LastExecution = DateTime.Now; - jobDefinition.Success = false; - } - } - - //Only update last execution status if was triggered by the scheduler - if (queueItem.Options == null) - { - _jobRepository.Update(jobDefinition); - } - } - - public void Handle(ApplicationShutdownRequested message) - { - _cancellationTokenSource.Cancel(); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/JobDefinition.cs b/NzbDrone.Core/Jobs/JobDefinition.cs index bd557526d..44d81eed4 100644 --- a/NzbDrone.Core/Jobs/JobDefinition.cs +++ b/NzbDrone.Core/Jobs/JobDefinition.cs @@ -5,8 +5,6 @@ namespace NzbDrone.Core.Jobs { public class JobDefinition : ModelBase { - public Boolean Enable { get; set; } - public String Type { get; set; } public String Name { get; set; } public Int32 Interval { get; set; } public DateTime LastExecution { get; set; } diff --git a/NzbDrone.Core/Jobs/JobRepository.cs b/NzbDrone.Core/Jobs/JobRepository.cs index 7ed7ea466..0a449cbe4 100644 --- a/NzbDrone.Core/Jobs/JobRepository.cs +++ b/NzbDrone.Core/Jobs/JobRepository.cs @@ -4,7 +4,9 @@ using System.Linq; using NLog; using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Indexers; using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Providers; namespace NzbDrone.Core.Jobs { @@ -16,60 +18,60 @@ namespace NzbDrone.Core.Jobs public class JobRepository : BasicRepository, IJobRepository, IHandle { - private readonly IEnumerable _jobs; private readonly Logger _logger; - public JobRepository(IDatabase database, IEnumerable jobs, Logger logger, IMessageAggregator messageAggregator) + public JobRepository(IDatabase database, Logger logger, IMessageAggregator messageAggregator) : base(database, messageAggregator) { - _jobs = jobs; _logger = logger; } public JobDefinition GetDefinition(Type type) { - return Query.Single(c => c.Type == type.FullName); + return Query.Single(c => c.Name == type.FullName); } public IList GetPendingJobs() { - return Query.Where(c => c.Enable == true && c.Interval != 2).ToList().Where(c => c.LastExecution < DateTime.Now.AddMinutes(-c.Interval)).ToList(); + return Query.Where(c => c.Interval != 0).ToList().Where(c => c.LastExecution < DateTime.Now.AddMinutes(-c.Interval)).ToList(); } public void Handle(ApplicationStartedEvent message) { var currentJobs = All().ToList(); - _logger.Debug("Initializing jobs. Available: {0} Existing:{1}", _jobs.Count(), currentJobs.Count()); - foreach (var currentJob in currentJobs) + + var timers = new[] + { + new JobDefinition{ Interval = 25, Name = typeof(RssSyncCommand).FullName}, + new JobDefinition{ Interval = 24*60, Name = typeof(UpdateXemMappings).FullName} + }; + + + _logger.Debug("Initializing jobs. Available: {0} Existing:{1}", timers.Count(), currentJobs.Count()); + + foreach (var job in currentJobs) { - if (_jobs.All(c => c.GetType().ToString() != currentJob.Type)) + if (!timers.Any(c => c.Name == job.Name)) { - _logger.Debug("Removing job from database '{0}'", currentJob.Name); - Delete(currentJob.Id); + _logger.Debug("Removing job from database '{0}'", job.Name); + Delete(job.Id); } } - foreach (var job in _jobs) + foreach (var job in timers) { - var jobDefinition = currentJobs.SingleOrDefault(c => c.Type == job.GetType().ToString()); + var currentDefinition = currentJobs.SingleOrDefault(c => c.Name == job.GetType().ToString()); - if (jobDefinition == null) + if (currentDefinition == null) { - jobDefinition = new JobDefinition - { - Type = job.GetType().ToString(), - LastExecution = DateTime.Now - }; + currentDefinition = job; } - jobDefinition.Enable = job.DefaultInterval.TotalSeconds > 0; - jobDefinition.Name = job.Name; - - jobDefinition.Interval = Convert.ToInt32(job.DefaultInterval.TotalMinutes); + currentDefinition.Interval = job.Interval; - Upsert(jobDefinition); + Upsert(currentDefinition); } } } diff --git a/NzbDrone.Core/Jobs/JobTimer.cs b/NzbDrone.Core/Jobs/JobTimer.cs index 86022bdd9..876ed1e53 100644 --- a/NzbDrone.Core/Jobs/JobTimer.cs +++ b/NzbDrone.Core/Jobs/JobTimer.cs @@ -1,4 +1,5 @@ -using System.Timers; +using System; +using System.Timers; using NzbDrone.Common.Messaging; using NzbDrone.Core.Lifecycle; @@ -8,23 +9,37 @@ namespace NzbDrone.Core.Jobs IHandle, IHandle { - private readonly IJobController _jobController; + private readonly IJobRepository _jobRepository; + private readonly IMessageAggregator _messageAggregator; private readonly Timer _timer; - public JobTimer(IJobController jobController) + public JobTimer(IJobRepository jobRepository, IMessageAggregator messageAggregator) { - _jobController = jobController; + _jobRepository = jobRepository; + _messageAggregator = messageAggregator; _timer = new Timer(); - } public void Handle(ApplicationStartedEvent message) { _timer.Interval = 1000 * 30; - _timer.Elapsed += (o, args) => _jobController.EnqueueScheduled(); + _timer.Elapsed += (o, args) => ExecuteCommands(); _timer.Start(); } + private void ExecuteCommands() + { + var jobs = _jobRepository.GetPendingJobs(); + + foreach (var jobDefinition in jobs) + { + var commandType = Type.GetType(jobDefinition.Name); + var command = (ICommand)Activator.CreateInstance(commandType); + + _messageAggregator.PublishCommand(command); + } + } + public void Handle(ApplicationShutdownRequested message) { _timer.Stop(); diff --git a/NzbDrone.Core/Lifecycle/AppShutdownJob.cs b/NzbDrone.Core/Lifecycle/AppShutdownJob.cs deleted file mode 100644 index f088249bc..000000000 --- a/NzbDrone.Core/Lifecycle/AppShutdownJob.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using NLog; -using NzbDrone.Common; -using NzbDrone.Core.Jobs; -using NzbDrone.Core.Model.Notification; - -namespace NzbDrone.Core.Lifecycle -{ - public class AppShutdownJob : IJob - { - private readonly ProcessProvider _processProvider; - private readonly ServiceProvider _serviceProvider; - private readonly Logger _logger; - - - public AppShutdownJob(ProcessProvider processProvider, ServiceProvider serviceProvider, Logger logger) - { - _processProvider = processProvider; - _serviceProvider = serviceProvider; - _logger = logger; - } - - public string Name - { - get { return "Shutdown NzbDrone"; } - } - - public TimeSpan DefaultInterval - { - get { return TimeSpan.FromTicks(0); } - } - - public virtual void Start(ProgressNotification notification, dynamic options) - { - notification.CurrentMessage = "Shutting down NzbDrone"; - _logger.Info("Shutting down NzbDrone"); - - if (_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME) - && _serviceProvider.IsServiceRunning(ServiceProvider.NZBDRONE_SERVICE_NAME)) - { - _logger.Debug("Stopping NzbDrone Service"); - _serviceProvider.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME); - } - - else - { - _logger.Debug("Stopping NzbDrone console"); - - var currentProcess = _processProvider.GetCurrentProcess(); - _processProvider.Kill(currentProcess.Id); - } - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/MediaFiles/Commands/CleanUpRecycleBinCommand.cs b/NzbDrone.Core/MediaFiles/Commands/CleanUpRecycleBinCommand.cs new file mode 100644 index 000000000..b2d16f231 --- /dev/null +++ b/NzbDrone.Core/MediaFiles/Commands/CleanUpRecycleBinCommand.cs @@ -0,0 +1,8 @@ +using NzbDrone.Common.Messaging; + +namespace NzbDrone.Core.MediaFiles.Commands +{ + public class CleanUpRecycleBinCommand : ICommand + { + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Providers/RecycleBinProvider.cs b/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs similarity index 93% rename from NzbDrone.Core/Providers/RecycleBinProvider.cs rename to NzbDrone.Core/MediaFiles/RecycleBinProvider.cs index 4a7b0b952..fcd8e2485 100644 --- a/NzbDrone.Core/Providers/RecycleBinProvider.cs +++ b/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs @@ -1,15 +1,15 @@ using System; using System.IO; -using System.Linq; using NLog; using NzbDrone.Common; using NzbDrone.Common.Messaging; using NzbDrone.Core.Configuration; +using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.Tv.Events; -namespace NzbDrone.Core.Providers +namespace NzbDrone.Core.MediaFiles { - public class RecycleBinProvider : IHandleAsync + public class RecycleBinProvider : IHandleAsync, IExecute { private readonly DiskProvider _diskProvider; private readonly IConfigService _configService; @@ -139,7 +139,15 @@ namespace NzbDrone.Core.Providers public void HandleAsync(SeriesDeletedEvent message) { - DeleteDirectory(message.Series.Path); + if (message.DeleteFiles) + { + DeleteDirectory(message.Series.Path); + } + } + + public void Execute(CleanUpRecycleBinCommand message) + { + Cleanup(); } } } diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 4a44cb647..0f83ea277 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -244,6 +244,7 @@ + @@ -283,24 +284,10 @@ - - - - - - - - - - - - - - @@ -348,6 +335,7 @@ + @@ -386,13 +374,11 @@ - + - - diff --git a/NzbDrone.Core/Providers/UpdateXemMappings.cs b/NzbDrone.Core/Providers/UpdateXemMappings.cs new file mode 100644 index 000000000..7b4b416a0 --- /dev/null +++ b/NzbDrone.Core/Providers/UpdateXemMappings.cs @@ -0,0 +1,8 @@ +using NzbDrone.Common.Messaging; + +namespace NzbDrone.Core.Providers +{ + public class UpdateXemMappings : ICommand + { + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Providers/XemProvider.cs b/NzbDrone.Core/Providers/XemProvider.cs index 5029778e2..6707ccd9b 100644 --- a/NzbDrone.Core/Providers/XemProvider.cs +++ b/NzbDrone.Core/Providers/XemProvider.cs @@ -2,11 +2,12 @@ using System.Collections.Generic; using System.Linq; using NLog; +using NzbDrone.Common.Messaging; using NzbDrone.Core.Tv; namespace NzbDrone.Core.Providers { - public class XemProvider + public class XemProvider :IExecute { private readonly IEpisodeService _episodeService; private readonly XemCommunicationProvider _xemCommunicationProvider; @@ -117,5 +118,10 @@ namespace NzbDrone.Core.Providers _logger.WarnException("Error updating scene numbering mappings for: " + series, ex); } } + + public void Execute(UpdateXemMappings message) + { + UpdateMappings(); + } } } diff --git a/NzbDrone.Core/Update/AppUpdateJob.cs b/NzbDrone.Core/Update/AppUpdateJob.cs deleted file mode 100644 index e1fc402ae..000000000 --- a/NzbDrone.Core/Update/AppUpdateJob.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using NzbDrone.Core.Jobs; -using NzbDrone.Core.Model.Notification; - -namespace NzbDrone.Core.Update -{ - public class AppUpdateJob : IJob - { - private readonly IUpdateService _updateService; - - public AppUpdateJob(IUpdateService updateService) - { - _updateService = updateService; - } - - public string Name - { - get { return "Update Application Job"; } - } - - public TimeSpan DefaultInterval - { - get { return TimeSpan.FromDays(2); } - } - - public virtual void Start(ProgressNotification notification, dynamic options) - { - _updateService.InstallAvailableUpdate(); - } - } -} \ No newline at end of file diff --git a/NzbDrone/NLog.config b/NzbDrone/NLog.config index e45e521a2..a5d313b44 100644 --- a/NzbDrone/NLog.config +++ b/NzbDrone/NLog.config @@ -25,8 +25,8 @@ layout="${date:format=yy-M-d HH\:mm\:ss.f}|${logger}}|${level}|${message}|${exception:format=ToString}"/> - - + + \ No newline at end of file diff --git a/NzbDrone/NzbDrone.csproj b/NzbDrone/NzbDrone.csproj index a6e64ec6c..bf691f15e 100644 --- a/NzbDrone/NzbDrone.csproj +++ b/NzbDrone/NzbDrone.csproj @@ -1,4 +1,4 @@ - + Debug @@ -92,7 +92,7 @@ ..\packages\FluentMigrator.1.0.6.0\tools\FluentMigrator.Runner.dll - ..\packages\Microsoft.AspNet.SignalR.Core.1.0.1\lib\net40\Microsoft.AspNet.SignalR.Core.dll + ..\NzbDrone.Api\bin\x86\Debug\Microsoft.AspNet.SignalR.Core.dll ..\packages\Microsoft.AspNet.SignalR.Owin.1.0.1\lib\net40\Microsoft.AspNet.SignalR.Owin.dll diff --git a/UI/.idea/jsLibraryMappings.xml b/UI/.idea/jsLibraryMappings.xml index c09b6ec1f..c932efdc1 100644 --- a/UI/.idea/jsLibraryMappings.xml +++ b/UI/.idea/jsLibraryMappings.xml @@ -1,7 +1,7 @@ - +