diff --git a/NzbDrone.Api/Commands/CommandModule.cs b/NzbDrone.Api/Commands/CommandModule.cs index bd04e861a..1c0b9a818 100644 --- a/NzbDrone.Api/Commands/CommandModule.cs +++ b/NzbDrone.Api/Commands/CommandModule.cs @@ -16,14 +16,14 @@ namespace NzbDrone.Api.Commands { public class CommandModule : NzbDroneRestModuleWithSignalR, IHandle { - private readonly IMessageAggregator _messageAggregator; + private readonly ICommandExecutor _commandExecutor; private readonly IContainer _container; private readonly ITrackCommands _trackCommands; - public CommandModule(IMessageAggregator messageAggregator, IContainer container, ITrackCommands trackCommands) - : base(messageAggregator) + public CommandModule(ICommandExecutor commandExecutor, IContainer container, ITrackCommands trackCommands) + : base(commandExecutor) { - _messageAggregator = messageAggregator; + _commandExecutor = commandExecutor; _container = container; _trackCommands = trackCommands; @@ -48,7 +48,7 @@ namespace NzbDrone.Api.Commands dynamic command = Request.Body.FromJson(commandType); - var trackedCommand = (Command)_messageAggregator.PublishCommandAsync(command); + var trackedCommand = (Command)_commandExecutor.PublishCommandAsync(command); return trackedCommand.Id; } diff --git a/NzbDrone.Api/Commands/CommandResource.cs b/NzbDrone.Api/Commands/CommandResource.cs index 6b25dd10e..86c1f4b15 100644 --- a/NzbDrone.Api/Commands/CommandResource.cs +++ b/NzbDrone.Api/Commands/CommandResource.cs @@ -1,6 +1,6 @@ using System; using NzbDrone.Api.REST; -using NzbDrone.Core.Messaging.Tracking; +using NzbDrone.Core.Messaging.Commands.Tracking; namespace NzbDrone.Api.Commands { diff --git a/NzbDrone.Api/NancyBootstrapper.cs b/NzbDrone.Api/NancyBootstrapper.cs index a76b1a877..263c4f265 100644 --- a/NzbDrone.Api/NancyBootstrapper.cs +++ b/NzbDrone.Api/NancyBootstrapper.cs @@ -8,6 +8,7 @@ using NzbDrone.Common.Instrumentation; using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; using TinyIoC; namespace NzbDrone.Api @@ -31,7 +32,7 @@ namespace NzbDrone.Api container.Resolve().Register(); container.Resolve().Register(pipelines); - container.Resolve().PublishEvent(new ApplicationStartedEvent()); + container.Resolve().PublishEvent(new ApplicationStartedEvent()); ApplicationPipelines.OnError.AddItemToEndOfPipeline(container.Resolve().HandleException); } diff --git a/NzbDrone.Api/NzbDroneRestModuleWithSignalR.cs b/NzbDrone.Api/NzbDroneRestModuleWithSignalR.cs index 1fb86e41d..3d824790f 100644 --- a/NzbDrone.Api/NzbDroneRestModuleWithSignalR.cs +++ b/NzbDrone.Api/NzbDroneRestModuleWithSignalR.cs @@ -10,11 +10,11 @@ namespace NzbDrone.Api where TResource : RestResource, new() where TModel : ModelBase { - private readonly IMessageAggregator _messageAggregator; + private readonly ICommandExecutor _commandExecutor; - protected NzbDroneRestModuleWithSignalR(IMessageAggregator messageAggregator) + protected NzbDroneRestModuleWithSignalR(ICommandExecutor commandExecutor) { - _messageAggregator = messageAggregator; + _commandExecutor = commandExecutor; } public void Handle(ModelEvent message) @@ -37,7 +37,7 @@ namespace NzbDrone.Api Body = new ResourceChangeMessage(resource, action) }; - _messageAggregator.PublishCommand(new BroadcastSignalRMessage(signalRMessage)); + _commandExecutor.PublishCommand(new BroadcastSignalRMessage(signalRMessage)); } protected void BroadcastResourceChange(ModelAction action) @@ -48,7 +48,7 @@ namespace NzbDrone.Api Body = new ResourceChangeMessage(action) }; - _messageAggregator.PublishCommand(new BroadcastSignalRMessage(signalRMessage)); + _commandExecutor.PublishCommand(new BroadcastSignalRMessage(signalRMessage)); } } } \ No newline at end of file diff --git a/NzbDrone.App.Test/ContainerFixture.cs b/NzbDrone.App.Test/ContainerFixture.cs index a7bcc7891..244901c0a 100644 --- a/NzbDrone.App.Test/ContainerFixture.cs +++ b/NzbDrone.App.Test/ContainerFixture.cs @@ -7,6 +7,8 @@ using NzbDrone.Core.Indexers; using NzbDrone.Core.Jobs; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Host; using NzbDrone.Test.Common; using FluentAssertions; diff --git a/NzbDrone.Common.Test/MessagingTests/MessageAggregatorCommandTests.cs b/NzbDrone.Common.Test/MessagingTests/CommandExecutorFixture.cs similarity index 97% rename from NzbDrone.Common.Test/MessagingTests/MessageAggregatorCommandTests.cs rename to NzbDrone.Common.Test/MessagingTests/CommandExecutorFixture.cs index 42cc682ff..a3f6c3931 100644 --- a/NzbDrone.Common.Test/MessagingTests/MessageAggregatorCommandTests.cs +++ b/NzbDrone.Common.Test/MessagingTests/CommandExecutorFixture.cs @@ -10,7 +10,7 @@ using NzbDrone.Test.Common; namespace NzbDrone.Common.Test.MessagingTests { [TestFixture] - public class MessageAggregatorCommandTests : TestBase + public class CommandExecutorFixture : TestBase { private Mock> _executorA; private Mock> _executorB; diff --git a/NzbDrone.Common.Test/MessagingTests/MessageAggregatorEventTests.cs b/NzbDrone.Common.Test/MessagingTests/MessageAggregatorEventTests.cs index 588beb289..30a177c81 100644 --- a/NzbDrone.Common.Test/MessagingTests/MessageAggregatorEventTests.cs +++ b/NzbDrone.Common.Test/MessagingTests/MessageAggregatorEventTests.cs @@ -6,12 +6,13 @@ using Moq; using NUnit.Framework; using NzbDrone.Common.Messaging; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Test.Common; namespace NzbDrone.Common.Test.MessagingTests { [TestFixture] - public class MessageAggregatorEventTests : TestBase + public class MessageAggregatorEventTests : TestBase { private Mock> HandlerA1; private Mock> HandlerA2; diff --git a/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj index 7795f156f..dc2b6ad13 100644 --- a/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj +++ b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj @@ -68,7 +68,7 @@ - + diff --git a/NzbDrone.Common.Test/ServiceFactoryFixture.cs b/NzbDrone.Common.Test/ServiceFactoryFixture.cs index e84ac5510..7777476ff 100644 --- a/NzbDrone.Common.Test/ServiceFactoryFixture.cs +++ b/NzbDrone.Common.Test/ServiceFactoryFixture.cs @@ -4,6 +4,7 @@ using NUnit.Framework; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Host; using NzbDrone.Test.Common; diff --git a/NzbDrone.Core.Test/Framework/DbTest.cs b/NzbDrone.Core.Test/Framework/DbTest.cs index 25c19a9bc..f8d3a0979 100644 --- a/NzbDrone.Core.Test/Framework/DbTest.cs +++ b/NzbDrone.Core.Test/Framework/DbTest.cs @@ -9,6 +9,7 @@ using NUnit.Framework; using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore.Migration.Framework; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.Test.Framework @@ -148,27 +149,27 @@ namespace NzbDrone.Core.Test.Framework public class TestDatabase : ITestDatabase { private readonly IDatabase _dbConnection; - private IMessageAggregator _messageAggregator; + private IEventAggregator _eventAggregator; public TestDatabase(IDatabase dbConnection) { - _messageAggregator = new Mock().Object; + _eventAggregator = new Mock().Object; _dbConnection = dbConnection; } public void InsertMany(IEnumerable items) where T : ModelBase, new() { - new BasicRepository(_dbConnection, _messageAggregator).InsertMany(items.ToList()); + new BasicRepository(_dbConnection, _eventAggregator).InsertMany(items.ToList()); } public T Insert(T item) where T : ModelBase, new() { - return new BasicRepository(_dbConnection, _messageAggregator).Insert(item); + return new BasicRepository(_dbConnection, _eventAggregator).Insert(item); } public List All() where T : ModelBase, new() { - return new BasicRepository(_dbConnection, _messageAggregator).All().ToList(); + return new BasicRepository(_dbConnection, _eventAggregator).All().ToList(); } public T Single() where T : ModelBase, new() @@ -178,12 +179,12 @@ namespace NzbDrone.Core.Test.Framework public void Update(T childModel) where T : ModelBase, new() { - new BasicRepository(_dbConnection, _messageAggregator).Update(childModel); + new BasicRepository(_dbConnection, _eventAggregator).Update(childModel); } public void Delete(T childModel) where T : ModelBase, new() { - new BasicRepository(_dbConnection, _messageAggregator).Delete(childModel); + new BasicRepository(_dbConnection, _eventAggregator).Delete(childModel); } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs b/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs index 04e208786..b1cab5f58 100644 --- a/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs +++ b/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs @@ -8,6 +8,7 @@ using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles.EpisodeImport; using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Qualities; using NzbDrone.Core.Test.Framework; @@ -103,7 +104,7 @@ namespace NzbDrone.Core.Test.MediaFiles { Subject.Import(new List { _approvedDecisions.First() }, true); - Mocker.GetMock() + Mocker.GetMock() .Verify(v => v.PublishEvent(It.IsAny()), Times.Once()); } @@ -122,7 +123,7 @@ namespace NzbDrone.Core.Test.MediaFiles { Subject.Import(new List { _approvedDecisions.First() }); - Mocker.GetMock() + Mocker.GetMock() .Verify(v => v.PublishEvent(It.IsAny()), Times.Never()); } } diff --git a/NzbDrone.Core.Test/MediaFiles/RenameEpisodeFileServiceFixture.cs b/NzbDrone.Core.Test/MediaFiles/RenameEpisodeFileServiceFixture.cs index ce6b51692..070b4eb03 100644 --- a/NzbDrone.Core.Test/MediaFiles/RenameEpisodeFileServiceFixture.cs +++ b/NzbDrone.Core.Test/MediaFiles/RenameEpisodeFileServiceFixture.cs @@ -6,6 +6,7 @@ using NUnit.Framework; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.MediaFiles.Events; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Messaging; using NzbDrone.Core.Tv; @@ -70,7 +71,7 @@ namespace NzbDrone.Core.Test.MediaFiles Subject.Execute(new RenameSeriesCommand(_series.Id)); - Mocker.GetMock() + Mocker.GetMock() .Verify(v => v.PublishEvent(It.IsAny()), Times.Never()); } @@ -85,7 +86,7 @@ namespace NzbDrone.Core.Test.MediaFiles Subject.Execute(new RenameSeriesCommand(_series.Id)); - Mocker.GetMock() + Mocker.GetMock() .Verify(v => v.PublishEvent(It.IsAny()), Times.Never()); } @@ -97,7 +98,7 @@ namespace NzbDrone.Core.Test.MediaFiles Subject.Execute(new RenameSeriesCommand(_series.Id)); - Mocker.GetMock() + Mocker.GetMock() .Verify(v => v.PublishEvent(It.IsAny()), Times.Once()); } diff --git a/NzbDrone.Core/Configuration/ConfigFileProvider.cs b/NzbDrone.Core/Configuration/ConfigFileProvider.cs index ee5793e95..8389ec658 100644 --- a/NzbDrone.Core/Configuration/ConfigFileProvider.cs +++ b/NzbDrone.Core/Configuration/ConfigFileProvider.cs @@ -10,6 +10,7 @@ using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Core.Configuration.Events; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.Configuration @@ -33,15 +34,15 @@ namespace NzbDrone.Core.Configuration { private const string CONFIG_ELEMENT_NAME = "Config"; - private readonly IMessageAggregator _messageAggregator; + private readonly IEventAggregator _eventAggregator; private readonly ICached _cache; private readonly string _configFile; - public ConfigFileProvider(IAppFolderInfo appFolderInfo, ICacheManger cacheManger, IMessageAggregator messageAggregator) + public ConfigFileProvider(IAppFolderInfo appFolderInfo, ICacheManger cacheManger, IEventAggregator eventAggregator) { _cache = cacheManger.GetCache(GetType()); - _messageAggregator = messageAggregator; + _eventAggregator = eventAggregator; _configFile = appFolderInfo.GetConfigPath(); } @@ -82,7 +83,7 @@ namespace NzbDrone.Core.Configuration } } - _messageAggregator.PublishEvent(new ConfigFileSavedEvent()); + _eventAggregator.PublishEvent(new ConfigFileSavedEvent()); } public int Port diff --git a/NzbDrone.Core/Configuration/ConfigRepository.cs b/NzbDrone.Core/Configuration/ConfigRepository.cs index 57307453c..0b8c3fffb 100644 --- a/NzbDrone.Core/Configuration/ConfigRepository.cs +++ b/NzbDrone.Core/Configuration/ConfigRepository.cs @@ -1,6 +1,7 @@ using System.Linq; using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.Configuration @@ -13,8 +14,8 @@ namespace NzbDrone.Core.Configuration public class ConfigRepository : BasicRepository, IConfigRepository { - public ConfigRepository(IDatabase database, IMessageAggregator messageAggregator) - : base(database, messageAggregator) + public ConfigRepository(IDatabase database, IEventAggregator eventAggregator) + : base(database, eventAggregator) { } diff --git a/NzbDrone.Core/Configuration/ConfigService.cs b/NzbDrone.Core/Configuration/ConfigService.cs index 9c09e7827..1e1af6182 100644 --- a/NzbDrone.Core/Configuration/ConfigService.cs +++ b/NzbDrone.Core/Configuration/ConfigService.cs @@ -7,6 +7,7 @@ using NzbDrone.Core.Download; using NzbDrone.Core.Download.Clients.Nzbget; using NzbDrone.Core.Download.Clients.Sabnzbd; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.Configuration @@ -19,14 +20,14 @@ namespace NzbDrone.Core.Configuration public class ConfigService : IConfigService { private readonly IConfigRepository _repository; - private readonly IMessageAggregator _messageAggregator; + private readonly IEventAggregator _eventAggregator; private readonly Logger _logger; private static Dictionary _cache; - public ConfigService(IConfigRepository repository, IMessageAggregator messageAggregator, Logger logger) + public ConfigService(IConfigRepository repository, IEventAggregator eventAggregator, Logger logger) { _repository = repository; - _messageAggregator = messageAggregator; + _eventAggregator = eventAggregator; _logger = logger; _cache = new Dictionary(); } @@ -69,7 +70,7 @@ namespace NzbDrone.Core.Configuration SetValue(configValue.Key, configValue.Value.ToString()); } - _messageAggregator.PublishEvent(new ConfigSavedEvent()); + _eventAggregator.PublishEvent(new ConfigSavedEvent()); } public String SabHost diff --git a/NzbDrone.Core/DataAugmentation/Scene/SceneMappingRepository.cs b/NzbDrone.Core/DataAugmentation/Scene/SceneMappingRepository.cs index 20226a4d8..5f1ade5c2 100644 --- a/NzbDrone.Core/DataAugmentation/Scene/SceneMappingRepository.cs +++ b/NzbDrone.Core/DataAugmentation/Scene/SceneMappingRepository.cs @@ -1,5 +1,6 @@ using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.DataAugmentation.Scene @@ -11,8 +12,8 @@ namespace NzbDrone.Core.DataAugmentation.Scene public class SceneMappingRepository : BasicRepository, ISceneMappingRepository { - public SceneMappingRepository(IDatabase database, IMessageAggregator messageAggregator) - : base(database, messageAggregator) + public SceneMappingRepository(IDatabase database, IEventAggregator eventAggregator) + : base(database, eventAggregator) { } diff --git a/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs b/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs index ce5e4a9cd..d05dd69fd 100644 --- a/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs +++ b/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs @@ -4,6 +4,8 @@ using NLog; using NzbDrone.Common.Cache; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser; namespace NzbDrone.Core.DataAugmentation.Scene diff --git a/NzbDrone.Core/Datastore/BasicRepository.cs b/NzbDrone.Core/Datastore/BasicRepository.cs index 10d081b23..8552930fd 100644 --- a/NzbDrone.Core/Datastore/BasicRepository.cs +++ b/NzbDrone.Core/Datastore/BasicRepository.cs @@ -7,6 +7,7 @@ using Marr.Data.QGen; using NzbDrone.Core.Datastore.Events; using NzbDrone.Common; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.Datastore @@ -38,17 +39,17 @@ namespace NzbDrone.Core.Datastore public class BasicRepository : IBasicRepository where TModel : ModelBase, new() { private readonly IDatabase _database; - private readonly IMessageAggregator _messageAggregator; + private readonly IEventAggregator _eventAggregator; private IDataMapper DataMapper { get { return _database.GetDataMapper(); } } - public BasicRepository(IDatabase database, IMessageAggregator messageAggregator) + public BasicRepository(IDatabase database, IEventAggregator eventAggregator) { _database = database; - _messageAggregator = messageAggregator; + _eventAggregator = eventAggregator; } protected QueryBuilder Query @@ -240,7 +241,7 @@ namespace NzbDrone.Core.Datastore { if (PublishModelEvents) { - _messageAggregator.PublishEvent(new ModelEvent(model, action)); + _eventAggregator.PublishEvent(new ModelEvent(model, action)); } } diff --git a/NzbDrone.Core/Datastore/DbFactory.cs b/NzbDrone.Core/Datastore/DbFactory.cs index 0c8267f9b..537fec3b0 100644 --- a/NzbDrone.Core/Datastore/DbFactory.cs +++ b/NzbDrone.Core/Datastore/DbFactory.cs @@ -6,6 +6,7 @@ using NzbDrone.Common.Composition; using NzbDrone.Core.Datastore.Migration.Framework; using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.Datastore @@ -38,7 +39,7 @@ namespace NzbDrone.Core.Datastore container.Register(c => { var db = c.Resolve().Create(MigrationType.Log); - return new LogRepository(db, c.Resolve()); + return new LogRepository(db, c.Resolve()); }); } diff --git a/NzbDrone.Core/Download/DownloadService.cs b/NzbDrone.Core/Download/DownloadService.cs index e95b194d0..a1c4f3bf1 100644 --- a/NzbDrone.Core/Download/DownloadService.cs +++ b/NzbDrone.Core/Download/DownloadService.cs @@ -1,6 +1,7 @@ using NLog; using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser.Model; namespace NzbDrone.Core.Download @@ -13,15 +14,15 @@ namespace NzbDrone.Core.Download public class DownloadService : IDownloadService { private readonly IProvideDownloadClient _downloadClientProvider; - private readonly IMessageAggregator _messageAggregator; + private readonly IEventAggregator _eventAggregator; private readonly Logger _logger; public DownloadService(IProvideDownloadClient downloadClientProvider, - IMessageAggregator messageAggregator, Logger logger) + IEventAggregator eventAggregator, Logger logger) { _downloadClientProvider = downloadClientProvider; - _messageAggregator = messageAggregator; + _eventAggregator = eventAggregator; _logger = logger; } @@ -39,7 +40,7 @@ namespace NzbDrone.Core.Download downloadClient.DownloadNzb(remoteEpisode); _logger.ProgressInfo("Report sent to download client. {0}", downloadTitle); - _messageAggregator.PublishEvent(new EpisodeGrabbedEvent(remoteEpisode)); + _eventAggregator.PublishEvent(new EpisodeGrabbedEvent(remoteEpisode)); } } } \ No newline at end of file diff --git a/NzbDrone.Core/History/HistoryRepository.cs b/NzbDrone.Core/History/HistoryRepository.cs index 178b68c4c..096397248 100644 --- a/NzbDrone.Core/History/HistoryRepository.cs +++ b/NzbDrone.Core/History/HistoryRepository.cs @@ -4,6 +4,7 @@ using System.Linq; using Marr.Data.QGen; using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Tv; namespace NzbDrone.Core.History @@ -16,8 +17,8 @@ namespace NzbDrone.Core.History public class HistoryRepository : BasicRepository, IHistoryRepository { - public HistoryRepository(IDatabase database, IMessageAggregator messageAggregator) - : base(database, messageAggregator) + public HistoryRepository(IDatabase database, IEventAggregator eventAggregator) + : base(database, eventAggregator) { } diff --git a/NzbDrone.Core/History/HistoryService.cs b/NzbDrone.Core/History/HistoryService.cs index ff2b5536b..6053541d0 100644 --- a/NzbDrone.Core/History/HistoryService.cs +++ b/NzbDrone.Core/History/HistoryService.cs @@ -6,6 +6,7 @@ using NzbDrone.Core.Datastore; using NzbDrone.Core.Download; using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Tv; namespace NzbDrone.Core.History diff --git a/NzbDrone.Core/IndexerSearch/EpisodeSearchService.cs b/NzbDrone.Core/IndexerSearch/EpisodeSearchService.cs index 6be027121..4f2860eb4 100644 --- a/NzbDrone.Core/IndexerSearch/EpisodeSearchService.cs +++ b/NzbDrone.Core/IndexerSearch/EpisodeSearchService.cs @@ -2,6 +2,7 @@ using NzbDrone.Core.Download; using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.IndexerSearch { diff --git a/NzbDrone.Core/IndexerSearch/SeasonSearchService.cs b/NzbDrone.Core/IndexerSearch/SeasonSearchService.cs index 43d6a2d1e..0e4b67eab 100644 --- a/NzbDrone.Core/IndexerSearch/SeasonSearchService.cs +++ b/NzbDrone.Core/IndexerSearch/SeasonSearchService.cs @@ -2,6 +2,7 @@ using NzbDrone.Core.Download; using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.IndexerSearch { diff --git a/NzbDrone.Core/IndexerSearch/SeriesSearchService.cs b/NzbDrone.Core/IndexerSearch/SeriesSearchService.cs index c073096d6..c87275648 100644 --- a/NzbDrone.Core/IndexerSearch/SeriesSearchService.cs +++ b/NzbDrone.Core/IndexerSearch/SeriesSearchService.cs @@ -3,6 +3,7 @@ using NLog; using NzbDrone.Core.Download; using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Tv; namespace NzbDrone.Core.IndexerSearch diff --git a/NzbDrone.Core/Indexers/IndexerRepository.cs b/NzbDrone.Core/Indexers/IndexerRepository.cs index 82c0c1ba1..fd66a3910 100644 --- a/NzbDrone.Core/Indexers/IndexerRepository.cs +++ b/NzbDrone.Core/Indexers/IndexerRepository.cs @@ -2,6 +2,7 @@ using System.Linq; using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.Indexers @@ -14,8 +15,8 @@ namespace NzbDrone.Core.Indexers public class IndexerRepository : BasicRepository, IIndexerRepository { - public IndexerRepository(IDatabase database, IMessageAggregator messageAggregator) - : base(database, messageAggregator) + public IndexerRepository(IDatabase database, IEventAggregator eventAggregator) + : base(database, eventAggregator) { } diff --git a/NzbDrone.Core/Indexers/IndexerService.cs b/NzbDrone.Core/Indexers/IndexerService.cs index f3261eb3c..d9fc3ba27 100644 --- a/NzbDrone.Core/Indexers/IndexerService.cs +++ b/NzbDrone.Core/Indexers/IndexerService.cs @@ -7,6 +7,7 @@ using NzbDrone.Core.Configuration; using NzbDrone.Core.Indexers.Newznab; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; using Omu.ValueInjecter; namespace NzbDrone.Core.Indexers diff --git a/NzbDrone.Core/Indexers/RssSyncService.cs b/NzbDrone.Core/Indexers/RssSyncService.cs index ed701d0c7..5f9be30a9 100644 --- a/NzbDrone.Core/Indexers/RssSyncService.cs +++ b/NzbDrone.Core/Indexers/RssSyncService.cs @@ -4,6 +4,7 @@ using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.Download; using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Indexers { diff --git a/NzbDrone.Core/Instrumentation/DatabaseTarget.cs b/NzbDrone.Core/Instrumentation/DatabaseTarget.cs index c6ee66ffc..673f4f9d6 100644 --- a/NzbDrone.Core/Instrumentation/DatabaseTarget.cs +++ b/NzbDrone.Core/Instrumentation/DatabaseTarget.cs @@ -5,6 +5,7 @@ using NLog.Layouts; using NLog.Targets; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.Instrumentation { diff --git a/NzbDrone.Core/Instrumentation/DeleteLogFilesService.cs b/NzbDrone.Core/Instrumentation/DeleteLogFilesService.cs index 556eb5b31..3a12cd057 100644 --- a/NzbDrone.Core/Instrumentation/DeleteLogFilesService.cs +++ b/NzbDrone.Core/Instrumentation/DeleteLogFilesService.cs @@ -4,6 +4,7 @@ using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Core.Instrumentation.Commands; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Instrumentation { diff --git a/NzbDrone.Core/Instrumentation/LogRepository.cs b/NzbDrone.Core/Instrumentation/LogRepository.cs index 631133bc8..8259b5cf7 100644 --- a/NzbDrone.Core/Instrumentation/LogRepository.cs +++ b/NzbDrone.Core/Instrumentation/LogRepository.cs @@ -1,6 +1,7 @@ using System; using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.Instrumentation @@ -12,8 +13,8 @@ namespace NzbDrone.Core.Instrumentation public class LogRepository : BasicRepository, ILogRepository { - public LogRepository(IDatabase database, IMessageAggregator messageAggregator) - : base(database, messageAggregator) + public LogRepository(IDatabase database, IEventAggregator eventAggregator) + : base(database, eventAggregator) { } diff --git a/NzbDrone.Core/Instrumentation/LogService.cs b/NzbDrone.Core/Instrumentation/LogService.cs index b0966000e..f46dbf5dd 100644 --- a/NzbDrone.Core/Instrumentation/LogService.cs +++ b/NzbDrone.Core/Instrumentation/LogService.cs @@ -1,6 +1,7 @@ using NzbDrone.Core.Datastore; using NzbDrone.Core.Instrumentation.Commands; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Instrumentation { diff --git a/NzbDrone.Core/Instrumentation/SetLoggingLevel.cs b/NzbDrone.Core/Instrumentation/SetLoggingLevel.cs index 0ce6f1358..61412e8fb 100644 --- a/NzbDrone.Core/Instrumentation/SetLoggingLevel.cs +++ b/NzbDrone.Core/Instrumentation/SetLoggingLevel.cs @@ -7,6 +7,7 @@ using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration.Events; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.Instrumentation { diff --git a/NzbDrone.Core/Jobs/JobRepository.cs b/NzbDrone.Core/Jobs/JobRepository.cs index baf6b8d04..726f06963 100644 --- a/NzbDrone.Core/Jobs/JobRepository.cs +++ b/NzbDrone.Core/Jobs/JobRepository.cs @@ -2,6 +2,7 @@ using System; using System.Linq; using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.Jobs @@ -16,8 +17,8 @@ namespace NzbDrone.Core.Jobs public class ScheduledTaskRepository : BasicRepository, IScheduledTaskRepository { - public ScheduledTaskRepository(IDatabase database, IMessageAggregator messageAggregator) - : base(database, messageAggregator) + public ScheduledTaskRepository(IDatabase database, IEventAggregator eventAggregator) + : base(database, eventAggregator) { } diff --git a/NzbDrone.Core/Jobs/Scheduler.cs b/NzbDrone.Core/Jobs/Scheduler.cs index f51c05cce..770116c1f 100644 --- a/NzbDrone.Core/Jobs/Scheduler.cs +++ b/NzbDrone.Core/Jobs/Scheduler.cs @@ -14,15 +14,15 @@ namespace NzbDrone.Core.Jobs IHandle { private readonly ITaskManager _taskManager; - private readonly IMessageAggregator _messageAggregator; + private readonly ICommandExecutor _commandExecutor; private readonly Logger _logger; private static readonly Timer Timer = new Timer(); private static CancellationTokenSource _cancellationTokenSource; - public Scheduler(ITaskManager taskManager, IMessageAggregator messageAggregator, Logger logger) + public Scheduler(ITaskManager taskManager, ICommandExecutor commandExecutor, Logger logger) { _taskManager = taskManager; - _messageAggregator = messageAggregator; + _commandExecutor = commandExecutor; _logger = logger; } @@ -52,7 +52,7 @@ namespace NzbDrone.Core.Jobs try { - _messageAggregator.PublishCommand(task.TypeName); + _commandExecutor.PublishCommand(task.TypeName); } catch (Exception e) { diff --git a/NzbDrone.Core/MediaCover/MediaCoverService.cs b/NzbDrone.Core/MediaCover/MediaCoverService.cs index b10a744a9..67b0d0b21 100644 --- a/NzbDrone.Core/MediaCover/MediaCoverService.cs +++ b/NzbDrone.Core/MediaCover/MediaCoverService.cs @@ -6,6 +6,7 @@ using NLog; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Tv; using NzbDrone.Core.Tv.Events; diff --git a/NzbDrone.Core/MediaFiles/DiskScanService.cs b/NzbDrone.Core/MediaFiles/DiskScanService.cs index 2d8338192..1467463e8 100644 --- a/NzbDrone.Core/MediaFiles/DiskScanService.cs +++ b/NzbDrone.Core/MediaFiles/DiskScanService.cs @@ -23,25 +23,25 @@ namespace NzbDrone.Core.MediaFiles private readonly IDiskProvider _diskProvider; private readonly IMakeImportDecision _importDecisionMaker; private readonly IImportApprovedEpisodes _importApprovedEpisodes; - private readonly IMessageAggregator _messageAggregator; + private readonly ICommandExecutor _commandExecutor; private readonly Logger _logger; public DiskScanService(IDiskProvider diskProvider, IMakeImportDecision importDecisionMaker, IImportApprovedEpisodes importApprovedEpisodes, - IMessageAggregator messageAggregator, Logger logger) + ICommandExecutor commandExecutor, Logger logger) { _diskProvider = diskProvider; _importDecisionMaker = importDecisionMaker; _importApprovedEpisodes = importApprovedEpisodes; - _messageAggregator = messageAggregator; + _commandExecutor = commandExecutor; _logger = logger; } private void Scan(Series series) { _logger.ProgressInfo("Scanning disk for {0}", series.Title); - _messageAggregator.PublishCommand(new CleanMediaFileDb(series.Id)); + _commandExecutor.PublishCommand(new CleanMediaFileDb(series.Id)); if (!_diskProvider.FolderExists(series.Path)) { diff --git a/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs b/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs index d24d9feb3..55c6f4638 100644 --- a/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs +++ b/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs @@ -9,6 +9,7 @@ using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.MediaFiles.EpisodeImport; using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Parser; using NzbDrone.Core.Tv; diff --git a/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs b/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs index e30bc99af..91157d26a 100644 --- a/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs +++ b/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs @@ -4,6 +4,7 @@ using System.Linq; using NLog; using NzbDrone.Common; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Organizer; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Tv; @@ -20,19 +21,19 @@ namespace NzbDrone.Core.MediaFiles { private readonly IEpisodeService _episodeService; private readonly IBuildFileNames _buildFileNames; - private readonly IMessageAggregator _messageAggregator; + private readonly IEventAggregator _eventAggregator; private readonly IDiskProvider _diskProvider; private readonly Logger _logger; public MoveEpisodeFiles(IEpisodeService episodeService, IBuildFileNames buildFileNames, - IMessageAggregator messageAggregator, + IEventAggregator eventAggregator, IDiskProvider diskProvider, Logger logger) { _episodeService = episodeService; _buildFileNames = buildFileNames; - _messageAggregator = messageAggregator; + _eventAggregator = eventAggregator; _diskProvider = diskProvider; _logger = logger; } diff --git a/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs b/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs index 195b9849d..a9a92bb87 100644 --- a/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs +++ b/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs @@ -6,6 +6,7 @@ using NLog; using NzbDrone.Common; using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.MediaFiles.EpisodeImport @@ -20,19 +21,19 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport private readonly IUpgradeMediaFiles _episodeFileUpgrader; private readonly IMediaFileService _mediaFileService; private readonly IDiskProvider _diskProvider; - private readonly IMessageAggregator _messageAggregator; + private readonly IEventAggregator _eventAggregator; private readonly Logger _logger; public ImportApprovedEpisodes(IUpgradeMediaFiles episodeFileUpgrader, IMediaFileService mediaFileService, IDiskProvider diskProvider, - IMessageAggregator messageAggregator, + IEventAggregator eventAggregator, Logger logger) { _episodeFileUpgrader = episodeFileUpgrader; _mediaFileService = mediaFileService; _diskProvider = diskProvider; - _messageAggregator = messageAggregator; + _eventAggregator = eventAggregator; _logger = logger; } @@ -70,8 +71,8 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport { episodeFile.SceneName = Path.GetFileNameWithoutExtension(localEpisode.Path.CleanFilePath()); episodeFile.Path = _episodeFileUpgrader.UpgradeEpisodeFile(episodeFile, localEpisode); - _messageAggregator.PublishEvent(new EpisodeImportedEvent(localEpisode, episodeFile)); - _messageAggregator.PublishEvent(new EpisodeDownloadedEvent(localEpisode)); + _eventAggregator.PublishEvent(new EpisodeImportedEvent(localEpisode, episodeFile)); + _eventAggregator.PublishEvent(new EpisodeDownloadedEvent(localEpisode)); } _mediaFileService.Add(episodeFile); diff --git a/NzbDrone.Core/MediaFiles/MediaFileRepository.cs b/NzbDrone.Core/MediaFiles/MediaFileRepository.cs index 89ce30571..7a0839594 100644 --- a/NzbDrone.Core/MediaFiles/MediaFileRepository.cs +++ b/NzbDrone.Core/MediaFiles/MediaFileRepository.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.MediaFiles @@ -17,8 +18,8 @@ namespace NzbDrone.Core.MediaFiles public class MediaFileRepository : BasicRepository, IMediaFileRepository { - public MediaFileRepository(IDatabase database, IMessageAggregator messageAggregator) - : base(database, messageAggregator) + public MediaFileRepository(IDatabase database, IEventAggregator eventAggregator) + : base(database, eventAggregator) { } diff --git a/NzbDrone.Core/MediaFiles/MediaFileService.cs b/NzbDrone.Core/MediaFiles/MediaFileService.cs index 5ef3d6831..b963b408e 100644 --- a/NzbDrone.Core/MediaFiles/MediaFileService.cs +++ b/NzbDrone.Core/MediaFiles/MediaFileService.cs @@ -3,6 +3,7 @@ using System.Linq; using NLog; using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Tv.Events; using NzbDrone.Common; @@ -23,21 +24,21 @@ namespace NzbDrone.Core.MediaFiles public class MediaFileService : IMediaFileService, IHandleAsync { - private readonly IMessageAggregator _messageAggregator; + private readonly IEventAggregator _eventAggregator; private readonly IMediaFileRepository _mediaFileRepository; private readonly Logger _logger; - public MediaFileService(IMediaFileRepository mediaFileRepository, IMessageAggregator messageAggregator, Logger logger) + public MediaFileService(IMediaFileRepository mediaFileRepository, IEventAggregator eventAggregator, Logger logger) { _mediaFileRepository = mediaFileRepository; - _messageAggregator = messageAggregator; + _eventAggregator = eventAggregator; _logger = logger; } public EpisodeFile Add(EpisodeFile episodeFile) { var addedFile = _mediaFileRepository.Insert(episodeFile); - _messageAggregator.PublishEvent(new EpisodeFileAddedEvent(addedFile)); + _eventAggregator.PublishEvent(new EpisodeFileAddedEvent(addedFile)); return addedFile; } @@ -50,7 +51,7 @@ namespace NzbDrone.Core.MediaFiles { _mediaFileRepository.Delete(episodeFile); - _messageAggregator.PublishEvent(new EpisodeFileDeletedEvent(episodeFile, forUpgrade)); + _eventAggregator.PublishEvent(new EpisodeFileDeletedEvent(episodeFile, forUpgrade)); } public bool Exists(string path) diff --git a/NzbDrone.Core/MediaFiles/MediaFileTableCleanupService.cs b/NzbDrone.Core/MediaFiles/MediaFileTableCleanupService.cs index 2d0c5ec4d..26c4d1905 100644 --- a/NzbDrone.Core/MediaFiles/MediaFileTableCleanupService.cs +++ b/NzbDrone.Core/MediaFiles/MediaFileTableCleanupService.cs @@ -4,6 +4,7 @@ using NLog; using NzbDrone.Common; using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Tv; namespace NzbDrone.Core.MediaFiles diff --git a/NzbDrone.Core/MediaFiles/RenameEpisodeFileService.cs b/NzbDrone.Core/MediaFiles/RenameEpisodeFileService.cs index df6ab0a00..501963445 100644 --- a/NzbDrone.Core/MediaFiles/RenameEpisodeFileService.cs +++ b/NzbDrone.Core/MediaFiles/RenameEpisodeFileService.cs @@ -6,6 +6,8 @@ using NzbDrone.Core.Instrumentation; using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Tv; namespace NzbDrone.Core.MediaFiles @@ -15,19 +17,19 @@ namespace NzbDrone.Core.MediaFiles private readonly ISeriesService _seriesService; private readonly IMediaFileService _mediaFileService; private readonly IMoveEpisodeFiles _episodeFileMover; - private readonly IMessageAggregator _messageAggregator; + private readonly IEventAggregator _eventAggregator; private readonly Logger _logger; public RenameEpisodeFileService(ISeriesService seriesService, IMediaFileService mediaFileService, IMoveEpisodeFiles episodeFileMover, - IMessageAggregator messageAggregator, + IEventAggregator eventAggregator, Logger logger) { _seriesService = seriesService; _mediaFileService = mediaFileService; _episodeFileMover = episodeFileMover; - _messageAggregator = messageAggregator; + _eventAggregator = eventAggregator; _logger = logger; } @@ -59,7 +61,7 @@ namespace NzbDrone.Core.MediaFiles if (renamed.Any()) { - _messageAggregator.PublishEvent(new SeriesRenamedEvent(series)); + _eventAggregator.PublishEvent(new SeriesRenamedEvent(series)); } } diff --git a/NzbDrone.Core/Messaging/Commands/Command.cs b/NzbDrone.Core/Messaging/Commands/Command.cs index a389c83a5..516464381 100644 --- a/NzbDrone.Core/Messaging/Commands/Command.cs +++ b/NzbDrone.Core/Messaging/Commands/Command.cs @@ -2,7 +2,7 @@ using System; using FluentMigrator.Runner; using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; -using NzbDrone.Core.Messaging.Tracking; +using NzbDrone.Core.Messaging.Commands.Tracking; namespace NzbDrone.Core.Messaging.Commands { diff --git a/NzbDrone.Core/Messaging/MessageAggregator.cs b/NzbDrone.Core/Messaging/Commands/CommandExecutor.cs similarity index 62% rename from NzbDrone.Core/Messaging/MessageAggregator.cs rename to NzbDrone.Core/Messaging/Commands/CommandExecutor.cs index 499bef32a..db14c7aa2 100644 --- a/NzbDrone.Core/Messaging/MessageAggregator.cs +++ b/NzbDrone.Core/Messaging/Commands/CommandExecutor.cs @@ -4,80 +4,33 @@ using System.Threading.Tasks; using NLog; using NzbDrone.Common; using NzbDrone.Common.EnsureThat; -using NzbDrone.Common.Messaging; using NzbDrone.Common.Serializer; using NzbDrone.Common.TPL; -using NzbDrone.Core.Messaging.Commands; +using NzbDrone.Core.Messaging.Commands.Tracking; using NzbDrone.Core.Messaging.Events; -using NzbDrone.Core.Messaging.Tracking; using NzbDrone.Core.ProgressMessaging; -namespace NzbDrone.Core.Messaging +namespace NzbDrone.Core.Messaging.Commands { - public class MessageAggregator : IMessageAggregator + public class CommandExecutor : ICommandExecutor { private readonly Logger _logger; private readonly IServiceFactory _serviceFactory; private readonly ITrackCommands _trackCommands; + private readonly IEventAggregator _eventAggregator; private readonly TaskFactory _taskFactory; - public MessageAggregator(Logger logger, IServiceFactory serviceFactory, ITrackCommands trackCommands) + public CommandExecutor(Logger logger, IServiceFactory serviceFactory, ITrackCommands trackCommands, IEventAggregator eventAggregator) { var scheduler = new LimitedConcurrencyLevelTaskScheduler(3); _logger = logger; _serviceFactory = serviceFactory; _trackCommands = trackCommands; + _eventAggregator = eventAggregator; _taskFactory = new TaskFactory(scheduler); } - public void PublishEvent(TEvent @event) where TEvent : class ,IEvent - { - Ensure.That(() => @event).IsNotNull(); - - var eventName = GetEventName(@event.GetType()); - - _logger.Trace("Publishing {0}", eventName); - - //call synchronous handlers first. - foreach (var handler in _serviceFactory.BuildAll>()) - { - try - { - _logger.Trace("{0} -> {1}", eventName, handler.GetType().Name); - handler.Handle(@event); - _logger.Trace("{0} <- {1}", eventName, handler.GetType().Name); - } - catch (Exception e) - { - _logger.ErrorException(string.Format("{0} failed while processing [{1}]", handler.GetType().Name, eventName), e); - } - } - - foreach (var handler in _serviceFactory.BuildAll>()) - { - var handlerLocal = handler; - - _taskFactory.StartNew(() => - { - _logger.Trace("{0} ~> {1}", eventName, handlerLocal.GetType().Name); - handlerLocal.HandleAsync(@event); - _logger.Trace("{0} <~ {1}", eventName, handlerLocal.GetType().Name); - }, TaskCreationOptions.PreferFairness) - .LogExceptions(); - } - } - - private static string GetEventName(Type eventType) - { - if (!eventType.IsGenericType) - { - return eventType.Name; - } - - return string.Format("{0}<{1}>", eventType.Name.Remove(eventType.Name.IndexOf('`')), eventType.GetGenericArguments()[0].Name); - } - public void PublishCommand(TCommand command) where TCommand : Command { Ensure.That(() => command).IsNotNull(); @@ -148,7 +101,7 @@ namespace NzbDrone.Core.Messaging try { _trackCommands.Start(command); - PublishEvent(new CommandUpdatedEvent(command)); + _eventAggregator.PublishEvent(new CommandUpdatedEvent(command)); if (!MappedDiagnosticsContext.Contains("CommandId") && command.SendUpdatesToClient) { @@ -157,13 +110,10 @@ namespace NzbDrone.Core.Messaging handler.Execute((TCommand)command); _trackCommands.Completed(command); - PublishEvent(new CommandUpdatedEvent(command)); - } catch (Exception e) { _trackCommands.Failed(command, e); - PublishEvent(new CommandUpdatedEvent(command)); throw; } finally @@ -172,11 +122,10 @@ namespace NzbDrone.Core.Messaging { MappedDiagnosticsContext.Remove("CommandId"); } + _eventAggregator.PublishEvent(new CommandUpdatedEvent(command)); + _eventAggregator.PublishEvent(new CommandExecutedEvent(command)); } - PublishEvent(new CommandExecutedEvent(command)); - PublishEvent(new CommandUpdatedEvent(command)); - _logger.Trace("{0} <- {1} [{2}]", command.GetType().Name, handler.GetType().Name, command.Runtime.ToString("")); } } diff --git a/NzbDrone.Core/Messaging/Commands/ICommandExecutor.cs b/NzbDrone.Core/Messaging/Commands/ICommandExecutor.cs new file mode 100644 index 000000000..45d300fcd --- /dev/null +++ b/NzbDrone.Core/Messaging/Commands/ICommandExecutor.cs @@ -0,0 +1,10 @@ +namespace NzbDrone.Core.Messaging.Commands +{ + public interface ICommandExecutor + { + void PublishCommand(TCommand command) where TCommand : Command; + void PublishCommand(string commandTypeName); + Command PublishCommandAsync(TCommand command) where TCommand : Command; + Command PublishCommandAsync(string commandTypeName); + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Messaging/IExecute.cs b/NzbDrone.Core/Messaging/Commands/IExecute.cs similarity index 66% rename from NzbDrone.Core/Messaging/IExecute.cs rename to NzbDrone.Core/Messaging/Commands/IExecute.cs index 43b3dc695..4e058e4d0 100644 --- a/NzbDrone.Core/Messaging/IExecute.cs +++ b/NzbDrone.Core/Messaging/Commands/IExecute.cs @@ -1,6 +1,4 @@ -using NzbDrone.Core.Messaging.Commands; - -namespace NzbDrone.Core.Messaging +namespace NzbDrone.Core.Messaging.Commands { public interface IExecute : IProcessMessage where TCommand : Command { diff --git a/NzbDrone.Core/Messaging/Tracking/CommandStatus.cs b/NzbDrone.Core/Messaging/Commands/Tracking/CommandStatus.cs similarity index 68% rename from NzbDrone.Core/Messaging/Tracking/CommandStatus.cs rename to NzbDrone.Core/Messaging/Commands/Tracking/CommandStatus.cs index 4ed389bf1..26208e9dd 100644 --- a/NzbDrone.Core/Messaging/Tracking/CommandStatus.cs +++ b/NzbDrone.Core/Messaging/Commands/Tracking/CommandStatus.cs @@ -1,4 +1,4 @@ -namespace NzbDrone.Core.Messaging.Tracking +namespace NzbDrone.Core.Messaging.Commands.Tracking { public enum CommandStatus { diff --git a/NzbDrone.Core/Messaging/Tracking/CommandTrackingService.cs b/NzbDrone.Core/Messaging/Commands/Tracking/CommandTrackingService.cs similarity index 96% rename from NzbDrone.Core/Messaging/Tracking/CommandTrackingService.cs rename to NzbDrone.Core/Messaging/Commands/Tracking/CommandTrackingService.cs index df2cbc662..3e5a6c619 100644 --- a/NzbDrone.Core/Messaging/Tracking/CommandTrackingService.cs +++ b/NzbDrone.Core/Messaging/Commands/Tracking/CommandTrackingService.cs @@ -2,9 +2,8 @@ using System; using System.Collections.Generic; using System.Linq; using NzbDrone.Common.Cache; -using NzbDrone.Core.Messaging.Commands; -namespace NzbDrone.Core.Messaging.Tracking +namespace NzbDrone.Core.Messaging.Commands.Tracking { public interface ITrackCommands { diff --git a/NzbDrone.Core/Messaging/Tracking/ExistingCommand.cs b/NzbDrone.Core/Messaging/Commands/Tracking/ExistingCommand.cs similarity index 79% rename from NzbDrone.Core/Messaging/Tracking/ExistingCommand.cs rename to NzbDrone.Core/Messaging/Commands/Tracking/ExistingCommand.cs index f41d8ef56..4fa174d3c 100644 --- a/NzbDrone.Core/Messaging/Tracking/ExistingCommand.cs +++ b/NzbDrone.Core/Messaging/Commands/Tracking/ExistingCommand.cs @@ -1,7 +1,6 @@ using System; -using NzbDrone.Core.Messaging.Commands; -namespace NzbDrone.Core.Messaging.Tracking +namespace NzbDrone.Core.Messaging.Commands.Tracking { public class ExistingCommand { diff --git a/NzbDrone.Core/Messaging/Commands/Tracking/TrackedCommandCleanupCommand.cs b/NzbDrone.Core/Messaging/Commands/Tracking/TrackedCommandCleanupCommand.cs new file mode 100644 index 000000000..744b8a60f --- /dev/null +++ b/NzbDrone.Core/Messaging/Commands/Tracking/TrackedCommandCleanupCommand.cs @@ -0,0 +1,7 @@ +namespace NzbDrone.Core.Messaging.Commands.Tracking +{ + public class TrackedCommandCleanupCommand : Command + { + + } +} diff --git a/NzbDrone.Core/Messaging/Events/EventAggregator.cs b/NzbDrone.Core/Messaging/Events/EventAggregator.cs new file mode 100644 index 000000000..7dbe1a331 --- /dev/null +++ b/NzbDrone.Core/Messaging/Events/EventAggregator.cs @@ -0,0 +1,73 @@ +using System; +using System.Threading.Tasks; +using NLog; +using NzbDrone.Common; +using NzbDrone.Common.EnsureThat; +using NzbDrone.Common.Messaging; +using NzbDrone.Common.TPL; + +namespace NzbDrone.Core.Messaging.Events +{ + public class EventAggregator : IEventAggregator + { + private readonly Logger _logger; + private readonly IServiceFactory _serviceFactory; + private readonly TaskFactory _taskFactory; + + public EventAggregator(Logger logger, IServiceFactory serviceFactory) + { + var scheduler = new LimitedConcurrencyLevelTaskScheduler(3); + + _logger = logger; + _serviceFactory = serviceFactory; + _taskFactory = new TaskFactory(scheduler); + } + + public void PublishEvent(TEvent @event) where TEvent : class ,IEvent + { + Ensure.That(() => @event).IsNotNull(); + + var eventName = GetEventName(@event.GetType()); + + _logger.Trace("Publishing {0}", eventName); + + //call synchronous handlers first. + foreach (var handler in _serviceFactory.BuildAll>()) + { + try + { + _logger.Trace("{0} -> {1}", eventName, handler.GetType().Name); + handler.Handle(@event); + _logger.Trace("{0} <- {1}", eventName, handler.GetType().Name); + } + catch (Exception e) + { + _logger.ErrorException(string.Format("{0} failed while processing [{1}]", handler.GetType().Name, eventName), e); + } + } + + foreach (var handler in _serviceFactory.BuildAll>()) + { + var handlerLocal = handler; + + _taskFactory.StartNew(() => + { + _logger.Trace("{0} ~> {1}", eventName, handlerLocal.GetType().Name); + handlerLocal.HandleAsync(@event); + _logger.Trace("{0} <~ {1}", eventName, handlerLocal.GetType().Name); + }, TaskCreationOptions.PreferFairness) + .LogExceptions(); + } + } + + private static string GetEventName(Type eventType) + { + if (!eventType.IsGenericType) + { + return eventType.Name; + } + + return string.Format("{0}<{1}>", eventType.Name.Remove(eventType.Name.IndexOf('`')), eventType.GetGenericArguments()[0].Name); + } + } +} diff --git a/NzbDrone.Core/Messaging/Events/IEventAggregator.cs b/NzbDrone.Core/Messaging/Events/IEventAggregator.cs new file mode 100644 index 000000000..9df32d66d --- /dev/null +++ b/NzbDrone.Core/Messaging/Events/IEventAggregator.cs @@ -0,0 +1,9 @@ +using NzbDrone.Common.Messaging; + +namespace NzbDrone.Core.Messaging.Events +{ + public interface IEventAggregator + { + void PublishEvent(TEvent @event) where TEvent : class, IEvent; + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Messaging/IHandle.cs b/NzbDrone.Core/Messaging/Events/IHandle.cs similarity index 88% rename from NzbDrone.Core/Messaging/IHandle.cs rename to NzbDrone.Core/Messaging/Events/IHandle.cs index b0c33796a..291e099d2 100644 --- a/NzbDrone.Core/Messaging/IHandle.cs +++ b/NzbDrone.Core/Messaging/Events/IHandle.cs @@ -1,6 +1,6 @@ using NzbDrone.Common.Messaging; -namespace NzbDrone.Core.Messaging +namespace NzbDrone.Core.Messaging.Events { public interface IHandle : IProcessMessage where TEvent : IEvent { diff --git a/NzbDrone.Core/Messaging/IMessageAggregator.cs b/NzbDrone.Core/Messaging/IMessageAggregator.cs deleted file mode 100644 index 5a3d5213f..000000000 --- a/NzbDrone.Core/Messaging/IMessageAggregator.cs +++ /dev/null @@ -1,17 +0,0 @@ -using NzbDrone.Common.Messaging; -using NzbDrone.Core.Messaging.Commands; - -namespace NzbDrone.Core.Messaging -{ - /// - /// Enables loosely-coupled publication of events. - /// - public interface IMessageAggregator - { - void PublishEvent(TEvent @event) where TEvent : class, IEvent; - void PublishCommand(TCommand command) where TCommand : Command; - void PublishCommand(string commandTypeName); - Command PublishCommandAsync(TCommand command) where TCommand : Command; - Command PublishCommandAsync(string commandTypeName); - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Messaging/MessageExtensions.cs b/NzbDrone.Core/Messaging/MessageExtensions.cs deleted file mode 100644 index f44d15d5f..000000000 --- a/NzbDrone.Core/Messaging/MessageExtensions.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using NzbDrone.Core.Messaging.Commands; - -namespace NzbDrone.Core.Messaging -{ - public static class MessageExtensions - { - public static string GetExecutorName(this Type commandType) - { - if (!typeof(Command).IsAssignableFrom(commandType)) - { - throw new ArgumentException("commandType must implement ICommand"); - } - - return string.Format("I{0}Executor", commandType.Name); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Messaging/Tracking/TrackedCommandCleanupCommand.cs b/NzbDrone.Core/Messaging/Tracking/TrackedCommandCleanupCommand.cs deleted file mode 100644 index 3bdb9ec9f..000000000 --- a/NzbDrone.Core/Messaging/Tracking/TrackedCommandCleanupCommand.cs +++ /dev/null @@ -1,9 +0,0 @@ -using NzbDrone.Core.Messaging.Commands; - -namespace NzbDrone.Core.Messaging.Tracking -{ - public class TrackedCommandCleanupCommand : Command - { - - } -} diff --git a/NzbDrone.Core/Notifications/Email/EmailService.cs b/NzbDrone.Core/Notifications/Email/EmailService.cs index 6f7b11e57..5625a9785 100644 --- a/NzbDrone.Core/Notifications/Email/EmailService.cs +++ b/NzbDrone.Core/Notifications/Email/EmailService.cs @@ -3,6 +3,7 @@ using System.Net; using System.Net.Mail; using NLog; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; using Omu.ValueInjecter; namespace NzbDrone.Core.Notifications.Email diff --git a/NzbDrone.Core/Notifications/Growl/GrowlService.cs b/NzbDrone.Core/Notifications/Growl/GrowlService.cs index 5f1e4a37a..5ec00df7c 100644 --- a/NzbDrone.Core/Notifications/Growl/GrowlService.cs +++ b/NzbDrone.Core/Notifications/Growl/GrowlService.cs @@ -5,6 +5,7 @@ using Growl.Connector; using NLog; using NzbDrone.Common.Instrumentation; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; using GrowlNotification = Growl.Connector.Notification; namespace NzbDrone.Core.Notifications.Growl diff --git a/NzbDrone.Core/Notifications/NotificationRepository.cs b/NzbDrone.Core/Notifications/NotificationRepository.cs index cdaa70a1d..79dedcf34 100644 --- a/NzbDrone.Core/Notifications/NotificationRepository.cs +++ b/NzbDrone.Core/Notifications/NotificationRepository.cs @@ -2,6 +2,7 @@ using System.Linq; using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.Notifications @@ -14,8 +15,8 @@ namespace NzbDrone.Core.Notifications public class NotificationRepository : BasicRepository, INotificationRepository { - public NotificationRepository(IDatabase database, IMessageAggregator messageAggregator) - : base(database, messageAggregator) + public NotificationRepository(IDatabase database, IEventAggregator eventAggregator) + : base(database, eventAggregator) { } diff --git a/NzbDrone.Core/Notifications/NotificationService.cs b/NzbDrone.Core/Notifications/NotificationService.cs index 47643093d..366129433 100644 --- a/NzbDrone.Core/Notifications/NotificationService.cs +++ b/NzbDrone.Core/Notifications/NotificationService.cs @@ -7,6 +7,7 @@ using NzbDrone.Common.Serializer; using NzbDrone.Core.Download; using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Tv; using Omu.ValueInjecter; diff --git a/NzbDrone.Core/Notifications/Plex/PlexService.cs b/NzbDrone.Core/Notifications/Plex/PlexService.cs index b994a5ab5..5a5bc82e3 100644 --- a/NzbDrone.Core/Notifications/Plex/PlexService.cs +++ b/NzbDrone.Core/Notifications/Plex/PlexService.cs @@ -5,6 +5,7 @@ using System.Xml.Linq; using NLog; using NzbDrone.Common; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Notifications.Plex { diff --git a/NzbDrone.Core/Notifications/Prowl/ProwlService.cs b/NzbDrone.Core/Notifications/Prowl/ProwlService.cs index 2a9fb8d83..e8c080f75 100644 --- a/NzbDrone.Core/Notifications/Prowl/ProwlService.cs +++ b/NzbDrone.Core/Notifications/Prowl/ProwlService.cs @@ -1,6 +1,7 @@ using System; using NLog; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; using Prowlin; namespace NzbDrone.Core.Notifications.Prowl diff --git a/NzbDrone.Core/Notifications/Pushover/PushoverService.cs b/NzbDrone.Core/Notifications/Pushover/PushoverService.cs index bb4fa9b64..7e5725711 100644 --- a/NzbDrone.Core/Notifications/Pushover/PushoverService.cs +++ b/NzbDrone.Core/Notifications/Pushover/PushoverService.cs @@ -1,4 +1,5 @@ using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; using RestSharp; using NzbDrone.Core.Rest; diff --git a/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs b/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs index 042007638..bbc8a237a 100644 --- a/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs +++ b/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs @@ -7,6 +7,7 @@ using NLog; using NzbDrone.Common; using NzbDrone.Common.Instrumentation; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Tv; using NzbDrone.Core.Model.Xbmc; diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index bcba2a519..568419be9 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -233,6 +233,7 @@ + @@ -246,9 +247,9 @@ - + - + diff --git a/NzbDrone.Core/ProgressMessaging/ProgressMessageTarget.cs b/NzbDrone.Core/ProgressMessaging/ProgressMessageTarget.cs index 2b6b88394..49c20b0b2 100644 --- a/NzbDrone.Core/ProgressMessaging/ProgressMessageTarget.cs +++ b/NzbDrone.Core/ProgressMessaging/ProgressMessageTarget.cs @@ -4,20 +4,21 @@ using NLog.Targets; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Messaging; using NzbDrone.Core.Messaging.Commands; -using NzbDrone.Core.Messaging.Tracking; +using NzbDrone.Core.Messaging.Commands.Tracking; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.ProgressMessaging { public class ProgressMessageTarget : Target, IHandle { - private readonly IMessageAggregator _messageAggregator; + private readonly IEventAggregator _eventAggregator; private readonly ITrackCommands _trackCommands; private static LoggingRule _rule; - public ProgressMessageTarget(IMessageAggregator messageAggregator, ITrackCommands trackCommands) + public ProgressMessageTarget(IEventAggregator eventAggregator, ITrackCommands trackCommands) { - _messageAggregator = messageAggregator; + _eventAggregator = eventAggregator; _trackCommands = trackCommands; } @@ -28,7 +29,7 @@ namespace NzbDrone.Core.ProgressMessaging if (IsClientMessage(logEvent, command)) { command.SetMessage(logEvent.FormattedMessage); - _messageAggregator.PublishEvent(new CommandUpdatedEvent(command)); + _eventAggregator.PublishEvent(new CommandUpdatedEvent(command)); } } diff --git a/NzbDrone.Core/Providers/XemProvider.cs b/NzbDrone.Core/Providers/XemProvider.cs index b8bdbd344..e66000afc 100644 --- a/NzbDrone.Core/Providers/XemProvider.cs +++ b/NzbDrone.Core/Providers/XemProvider.cs @@ -6,6 +6,8 @@ using NzbDrone.Common.Cache; using NzbDrone.Common.Instrumentation; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Tv; using NzbDrone.Core.Tv.Events; diff --git a/NzbDrone.Core/Qualities/QualityProfileRepository.cs b/NzbDrone.Core/Qualities/QualityProfileRepository.cs index c3a412cc6..64e36b70b 100644 --- a/NzbDrone.Core/Qualities/QualityProfileRepository.cs +++ b/NzbDrone.Core/Qualities/QualityProfileRepository.cs @@ -1,5 +1,6 @@ using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.Qualities @@ -11,8 +12,8 @@ namespace NzbDrone.Core.Qualities public class QualityProfileRepository : BasicRepository, IQualityProfileRepository { - public QualityProfileRepository(IDatabase database, IMessageAggregator messageAggregator) - : base(database, messageAggregator) + public QualityProfileRepository(IDatabase database, IEventAggregator eventAggregator) + : base(database, eventAggregator) { } } diff --git a/NzbDrone.Core/Qualities/QualityProfileService.cs b/NzbDrone.Core/Qualities/QualityProfileService.cs index 71e4536b3..de79e36e9 100644 --- a/NzbDrone.Core/Qualities/QualityProfileService.cs +++ b/NzbDrone.Core/Qualities/QualityProfileService.cs @@ -3,6 +3,7 @@ using System.Linq; using NLog; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Tv; diff --git a/NzbDrone.Core/Qualities/QualitySizeRepository.cs b/NzbDrone.Core/Qualities/QualitySizeRepository.cs index a359b8a62..84a21355d 100644 --- a/NzbDrone.Core/Qualities/QualitySizeRepository.cs +++ b/NzbDrone.Core/Qualities/QualitySizeRepository.cs @@ -2,6 +2,7 @@ using System.Linq; using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.Qualities @@ -13,8 +14,8 @@ namespace NzbDrone.Core.Qualities public class QualitySizeRepository : BasicRepository, IQualitySizeRepository { - public QualitySizeRepository(IDatabase database, IMessageAggregator messageAggregator) - : base(database, messageAggregator) + public QualitySizeRepository(IDatabase database, IEventAggregator eventAggregator) + : base(database, eventAggregator) { } diff --git a/NzbDrone.Core/Qualities/QualitySizeService.cs b/NzbDrone.Core/Qualities/QualitySizeService.cs index 4627aba58..c7719ef8b 100644 --- a/NzbDrone.Core/Qualities/QualitySizeService.cs +++ b/NzbDrone.Core/Qualities/QualitySizeService.cs @@ -3,6 +3,7 @@ using System.Linq; using NLog; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.Qualities { diff --git a/NzbDrone.Core/Tv/EpisodeRepository.cs b/NzbDrone.Core/Tv/EpisodeRepository.cs index aeb54788a..3962b5f89 100644 --- a/NzbDrone.Core/Tv/EpisodeRepository.cs +++ b/NzbDrone.Core/Tv/EpisodeRepository.cs @@ -31,8 +31,8 @@ namespace NzbDrone.Core.Tv { private readonly IDatabase _database; - public EpisodeRepository(IDatabase database, IMessageAggregator messageAggregator) - : base(database, messageAggregator) + public EpisodeRepository(IDatabase database, IEventAggregator eventAggregator) + : base(database, eventAggregator) { _database = database; } diff --git a/NzbDrone.Core/Tv/EpisodeService.cs b/NzbDrone.Core/Tv/EpisodeService.cs index 53b30af40..8d3f3ccd2 100644 --- a/NzbDrone.Core/Tv/EpisodeService.cs +++ b/NzbDrone.Core/Tv/EpisodeService.cs @@ -7,6 +7,7 @@ using NzbDrone.Core.Configuration; using NzbDrone.Core.Datastore; using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Tv.Events; namespace NzbDrone.Core.Tv diff --git a/NzbDrone.Core/Tv/RefreshEpisodeService.cs b/NzbDrone.Core/Tv/RefreshEpisodeService.cs index 3ad4ff209..5c4beb1b0 100644 --- a/NzbDrone.Core/Tv/RefreshEpisodeService.cs +++ b/NzbDrone.Core/Tv/RefreshEpisodeService.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using NLog; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Tv.Events; namespace NzbDrone.Core.Tv @@ -15,13 +16,13 @@ namespace NzbDrone.Core.Tv public class RefreshEpisodeService : IRefreshEpisodeService { private readonly IEpisodeService _episodeService; - private readonly IMessageAggregator _messageAggregator; + private readonly IEventAggregator _eventAggregator; private readonly Logger _logger; - public RefreshEpisodeService(IEpisodeService episodeService, IMessageAggregator messageAggregator, Logger logger) + public RefreshEpisodeService(IEpisodeService episodeService, IEventAggregator eventAggregator, Logger logger) { _episodeService = episodeService; - _messageAggregator = messageAggregator; + _eventAggregator = eventAggregator; _logger = logger; } @@ -85,17 +86,17 @@ namespace NzbDrone.Core.Tv if (newList.Any()) { - _messageAggregator.PublishEvent(new EpisodeInfoAddedEvent(newList, series)); + _eventAggregator.PublishEvent(new EpisodeInfoAddedEvent(newList, series)); } if (updateList.Any()) { - _messageAggregator.PublishEvent(new EpisodeInfoUpdatedEvent(updateList)); + _eventAggregator.PublishEvent(new EpisodeInfoUpdatedEvent(updateList)); } if (existingEpisodes.Any()) { - _messageAggregator.PublishEvent(new EpisodeInfoDeletedEvent(updateList)); + _eventAggregator.PublishEvent(new EpisodeInfoDeletedEvent(updateList)); } if (failCount != 0) diff --git a/NzbDrone.Core/Tv/RefreshSeriesService.cs b/NzbDrone.Core/Tv/RefreshSeriesService.cs index 1a8556374..1805bd363 100644 --- a/NzbDrone.Core/Tv/RefreshSeriesService.cs +++ b/NzbDrone.Core/Tv/RefreshSeriesService.cs @@ -18,16 +18,16 @@ namespace NzbDrone.Core.Tv private readonly IProvideSeriesInfo _seriesInfo; private readonly ISeriesService _seriesService; private readonly IRefreshEpisodeService _refreshEpisodeService; - private readonly IMessageAggregator _messageAggregator; + private readonly IEventAggregator _eventAggregator; private readonly IDailySeriesService _dailySeriesService; private readonly Logger _logger; - public RefreshSeriesService(IProvideSeriesInfo seriesInfo, ISeriesService seriesService, IRefreshEpisodeService refreshEpisodeService, IMessageAggregator messageAggregator, IDailySeriesService dailySeriesService, Logger logger) + public RefreshSeriesService(IProvideSeriesInfo seriesInfo, ISeriesService seriesService, IRefreshEpisodeService refreshEpisodeService, IEventAggregator eventAggregator, IDailySeriesService dailySeriesService, Logger logger) { _seriesInfo = seriesInfo; _seriesService = seriesService; _refreshEpisodeService = refreshEpisodeService; - _messageAggregator = messageAggregator; + _eventAggregator = eventAggregator; _dailySeriesService = dailySeriesService; _logger = logger; } @@ -71,7 +71,7 @@ namespace NzbDrone.Core.Tv _refreshEpisodeService.RefreshEpisodeInfo(series, tuple.Item2); _logger.Debug("Finished series refresh for {0}", series.Title); - _messageAggregator.PublishEvent(new SeriesUpdatedEvent(series)); + _eventAggregator.PublishEvent(new SeriesUpdatedEvent(series)); } private List UpdateSeasons(Series series, Series seriesInfo) diff --git a/NzbDrone.Core/Tv/SeasonRepository.cs b/NzbDrone.Core/Tv/SeasonRepository.cs index 1b181cb9c..470c2e5ca 100644 --- a/NzbDrone.Core/Tv/SeasonRepository.cs +++ b/NzbDrone.Core/Tv/SeasonRepository.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.Tv @@ -13,8 +14,8 @@ namespace NzbDrone.Core.Tv public class SeasonRepository : BasicRepository, ISeasonRepository { - public SeasonRepository(IDatabase database, IMessageAggregator messageAggregator) - : base(database, messageAggregator) + public SeasonRepository(IDatabase database, IEventAggregator eventAggregator) + : base(database, eventAggregator) { } diff --git a/NzbDrone.Core/Tv/SeriesRepository.cs b/NzbDrone.Core/Tv/SeriesRepository.cs index c49531faa..161ebbac2 100644 --- a/NzbDrone.Core/Tv/SeriesRepository.cs +++ b/NzbDrone.Core/Tv/SeriesRepository.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.Tv @@ -21,8 +22,8 @@ namespace NzbDrone.Core.Tv public class SeriesRepository : BasicRepository, ISeriesRepository { - public SeriesRepository(IDatabase database, IMessageAggregator messageAggregator) - : base(database, messageAggregator) + public SeriesRepository(IDatabase database, IEventAggregator eventAggregator) + : base(database, eventAggregator) { } diff --git a/NzbDrone.Core/Tv/SeriesService.cs b/NzbDrone.Core/Tv/SeriesService.cs index 1ada36255..9e8d7ba99 100644 --- a/NzbDrone.Core/Tv/SeriesService.cs +++ b/NzbDrone.Core/Tv/SeriesService.cs @@ -7,6 +7,7 @@ using NzbDrone.Common.EnsureThat; using NzbDrone.Core.Configuration; using NzbDrone.Core.DataAugmentation.Scene; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Organizer; using NzbDrone.Core.Tv.Events; @@ -30,21 +31,21 @@ namespace NzbDrone.Core.Tv { private readonly ISeriesRepository _seriesRepository; private readonly IConfigService _configService; - private readonly IMessageAggregator _messageAggregator; + private readonly IEventAggregator _eventAggregator; private readonly ISceneMappingService _sceneMappingService; private readonly IEpisodeService _episodeService; private readonly Logger _logger; public SeriesService(ISeriesRepository seriesRepository, IConfigService configServiceService, - IMessageAggregator messageAggregator, + IEventAggregator eventAggregator, ISceneMappingService sceneMappingService, IEpisodeService episodeService, Logger logger) { _seriesRepository = seriesRepository; _configService = configServiceService; - _messageAggregator = messageAggregator; + _eventAggregator = eventAggregator; _sceneMappingService = sceneMappingService; _episodeService = episodeService; _logger = logger; @@ -73,7 +74,7 @@ namespace NzbDrone.Core.Tv newSeries.SeasonFolder = _configService.UseSeasonFolder; _seriesRepository.Insert(newSeries); - _messageAggregator.PublishEvent(new SeriesAddedEvent(newSeries)); + _eventAggregator.PublishEvent(new SeriesAddedEvent(newSeries)); return newSeries; } @@ -109,7 +110,7 @@ namespace NzbDrone.Core.Tv { var series = _seriesRepository.Get(seriesId); _seriesRepository.Delete(seriesId); - _messageAggregator.PublishEvent(new SeriesDeletedEvent(series, deleteFiles)); + _eventAggregator.PublishEvent(new SeriesDeletedEvent(series, deleteFiles)); } public List GetAllSeries() diff --git a/NzbDrone.Core/Update/InstallUpdateService.cs b/NzbDrone.Core/Update/InstallUpdateService.cs index a11e00fef..fd74f199c 100644 --- a/NzbDrone.Core/Update/InstallUpdateService.cs +++ b/NzbDrone.Core/Update/InstallUpdateService.cs @@ -4,6 +4,7 @@ using NLog; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Update.Commands; using NzbDrone.Core.Instrumentation; diff --git a/NzbDrone.SignalR/NzbDronePersistentConnection.cs b/NzbDrone.SignalR/NzbDronePersistentConnection.cs index 748a11bb5..b9a6f1eed 100644 --- a/NzbDrone.SignalR/NzbDronePersistentConnection.cs +++ b/NzbDrone.SignalR/NzbDronePersistentConnection.cs @@ -1,6 +1,7 @@ using Microsoft.AspNet.SignalR; using Microsoft.AspNet.SignalR.Infrastructure; using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.SignalR { diff --git a/NzbDrone.Test.Common/TestBase.cs b/NzbDrone.Test.Common/TestBase.cs index 1b1ff4cee..976bfc454 100644 --- a/NzbDrone.Test.Common/TestBase.cs +++ b/NzbDrone.Test.Common/TestBase.cs @@ -179,12 +179,12 @@ namespace NzbDrone.Test.Common protected void VerifyEventPublished(Times times) where TEvent : class, IEvent { - Mocker.GetMock().Verify(c => c.PublishEvent(It.IsAny()), times); + Mocker.GetMock().Verify(c => c.PublishEvent(It.IsAny()), times); } protected void VerifyEventNotPublished() where TEvent : class, IEvent { - Mocker.GetMock().Verify(c => c.PublishEvent(It.IsAny()), Times.Never()); + Mocker.GetMock().Verify(c => c.PublishEvent(It.IsAny()), Times.Never()); } } }