From 25e2c98c45c99bbada47780f4fb86c2854f071e9 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Tue, 10 Sep 2013 23:33:47 -0700 Subject: [PATCH] signalr cleanup --- .../MappingTests/ResourceMappingFixture.cs | 15 +- NzbDrone.Api/Commands/CommandConnection.cs | 42 --- NzbDrone.Api/Commands/CommandModule.cs | 51 ++-- NzbDrone.Api/Commands/CommandResource.cs | 11 +- NzbDrone.Api/Episodes/EpisodeConnection.cs | 24 -- NzbDrone.Api/NancyBootstrapper.cs | 2 +- NzbDrone.Api/NzbDrone.Api.csproj | 20 +- NzbDrone.Api/NzbDroneRestModule.cs | 5 +- NzbDrone.Api/NzbDroneRestModuleWithSignalR.cs | 54 ++++ .../ProgressMessageConnection.cs | 24 -- .../ProgressMessageModule.cs | 21 -- .../ProgressMessageResource.cs | 12 - NzbDrone.Api/REST/RestModule.cs | 2 +- NzbDrone.Api/ResourceChangeMessage.cs | 29 +++ .../RootFolders/RootFolderConnection.cs | 13 - NzbDrone.Api/Series/SeriesConnection.cs | 12 - .../SignalR/BasicResourceConnection.cs | 37 --- .../SignalR/NzbDronePersistentConnection.cs | 9 - NzbDrone.Api/Update/UpdateModule.cs | 2 - .../Validation/RuleBuilderExtensions.cs | 5 + NzbDrone.App.Test/ContainerFixture.cs | 2 +- .../MessagingTests/CommandBaseFixture.cs | 20 ++ .../CommandEqualityComparerFixture.cs | 27 +- .../MessageAggregatorCommandTests.cs | 34 +-- .../MessageAggregatorEventTests.cs | 7 +- .../NzbDrone.Common.Test.csproj | 5 +- NzbDrone.Common.Test/ServiceFactoryFixture.cs | 2 +- .../Instrumentation/ExceptronTarget.cs | 4 - .../Instrumentation/LoggerExtensions.cs | 53 ---- .../Messaging/CommandEqualityComparer.cs | 44 ---- .../Messaging/Events/CommandCompletedEvent.cs | 14 - .../Messaging/Events/CommandExecutedEvent.cs | 14 - .../Messaging/Events/CommandFailedEvent.cs | 17 -- .../Messaging/Events/CommandStartedEvent.cs | 14 - NzbDrone.Common/Messaging/ICommand.cs | 10 - NzbDrone.Common/Messaging/IEvent.cs | 2 +- NzbDrone.Common/Messaging/TestCommand.cs | 15 -- .../Messaging/TestCommandExecutor.cs | 12 - .../Tracking/CommandTrackingService.cs | 127 --------- .../Messaging/Tracking/ExistingCommand.cs | 19 -- .../Messaging/Tracking/ProcessState.cs | 14 - .../Messaging/Tracking/TrackedCommand.cs | 30 --- .../Tracking/TrackedCommandCleanupCommand.cs | 17 -- NzbDrone.Common/NzbDrone.Common.csproj | 26 +- NzbDrone.Core.Test/Framework/DbTest.cs | 3 +- .../ImportApprovedEpisodesFixture.cs | 2 +- .../RenameEpisodeFileServiceFixture.cs | 2 +- .../TvTests/RefreshEpisodeServiceFixture.cs | Bin 5947 -> 6758 bytes .../UpdatePackageProviderFixture.cs | 14 +- .../Configuration/ConfigFileProvider.cs | 3 +- .../Configuration/ConfigRepository.cs | 3 +- NzbDrone.Core/Configuration/ConfigService.cs | 3 +- .../Events/ConfigFileSavedEvent.cs | 1 + .../Configuration/Events/ConfigSavedEvent.cs | 1 + .../Scene/SceneMappingRepository.cs | 3 +- .../Scene/SceneMappingService.cs | 2 +- .../Scene/UpdateSceneMappingCommand.cs | 10 +- NzbDrone.Core/Datastore/BasicRepository.cs | 30 ++- .../Datastore/CachedBasicRepository.cs | 40 --- NzbDrone.Core/Datastore/DbFactory.cs | 2 +- NzbDrone.Core/Datastore/Events/ModelEvent.cs | 14 +- ...per (vaio's conflicted copy 2013-09-04).cs | 241 ++++++++++++++++++ .../DecisionEngine/DownloadDecisionMaker.cs | 9 +- NzbDrone.Core/Download/DownloadService.cs | 5 +- NzbDrone.Core/Download/EpisodeGrabbedEvent.cs | 1 + NzbDrone.Core/History/HistoryRepository.cs | 2 +- NzbDrone.Core/History/HistoryService.cs | 2 +- .../IndexerSearch/EpisodeSearchCommand.cs | 17 +- .../IndexerSearch/EpisodeSearchService.cs | 5 +- .../IndexerSearch/NzbSearchService.cs | 3 +- .../IndexerSearch/SeasonSearchCommand.cs | 13 +- .../IndexerSearch/SeasonSearchService.cs | 5 +- .../IndexerSearch/SeriesSearchCommand.cs | 13 +- .../IndexerSearch/SeriesSearchService.cs | 5 +- NzbDrone.Core/Indexers/IndexerRepository.cs | 3 +- NzbDrone.Core/Indexers/IndexerService.cs | 2 +- .../Indexers/IndexerSettingUpdatedEvent.cs | 1 + NzbDrone.Core/Indexers/RssSyncCommand.cs | 14 +- NzbDrone.Core/Indexers/RssSyncService.cs | 7 +- .../Commands/ClearLogCommand.cs | 14 +- .../Commands/DeleteLogFilesCommand.cs | 14 +- .../Commands/TrimLogCommand.cs | 11 +- .../Instrumentation/DatabaseTarget.cs | 2 +- .../Instrumentation/DeleteLogFilesService.cs | 2 +- .../Instrumentation/LogRepository.cs | 3 +- NzbDrone.Core/Instrumentation/LogService.cs | 2 +- .../Instrumentation/LoggerExtensions.cs | 34 +++ .../Instrumentation/SetLoggingLevel.cs | 2 +- NzbDrone.Core/Jobs/JobRepository.cs | 3 +- NzbDrone.Core/Jobs/Scheduler.cs | 2 +- NzbDrone.Core/Jobs/TaskManager.cs | 8 +- .../Lifecycle/ApplicationShutdownRequested.cs | 1 + .../Lifecycle/ApplicationStartedEvent.cs | 1 + NzbDrone.Core/MediaCover/MediaCoverService.cs | 2 +- .../Commands/BackendCommandAttribute.cs | 8 + .../MediaFiles/Commands/CleanMediaFileDb.cs | 12 +- .../Commands/CleanUpRecycleBinCommand.cs | 11 +- .../Commands/DownloadedEpisodesScanCommand.cs | 11 +- .../Commands/RenameSeasonCommand.cs | 17 +- .../Commands/RenameSeriesCommand.cs | 18 +- NzbDrone.Core/MediaFiles/DiskScanService.cs | 7 +- .../DownloadedEpisodesImportService.cs | 2 +- .../MediaFiles/EpisodeFileMovingService.cs | 2 +- .../EpisodeImport/ImportApprovedEpisodes.cs | 3 +- .../Events/EpisodeDownloadedEvent.cs | 1 + .../Events/EpisodeFileAddedEvent.cs | 1 + .../Events/EpisodeFileDeletedEvent.cs | 1 + .../MediaFiles/Events/EpisodeImportedEvent.cs | 1 + .../MediaFiles/Events/SeriesRenamedEvent.cs | 1 + .../MediaFiles/MediaFileRepository.cs | 3 +- NzbDrone.Core/MediaFiles/MediaFileService.cs | 2 +- .../MediaFileTableCleanupService.cs | 2 +- .../MediaFiles/RecycleBinProvider.cs | 2 +- .../MediaFiles/RenameEpisodeFileService.cs | 11 +- .../Commands/BackendCommandAttribute.cs | 8 + NzbDrone.Core/Messaging/Commands/Command.cs | 82 ++++++ .../Commands/CommandEqualityComparer.cs | 61 +++++ .../Messaging/Commands/TestCommand.cs | 20 ++ .../Messaging/Commands/TestCommandExecutor.cs | 23 ++ .../Messaging/Events/CommandCreatedEvent.cs | 15 ++ .../Messaging/Events/CommandExecutedEvent.cs | 15 ++ .../Messaging/IExecute.cs | 6 +- .../Messaging/IHandle.cs | 4 +- .../Messaging/IMessageAggregator.cs | 11 +- .../Messaging/IProcessMessage.cs | 2 +- .../Messaging/MessageAggregator.cs | 92 +++---- .../Messaging/MessageExtensions.cs | 7 +- .../Messaging/Tracking/CommandStatus.cs | 10 + .../Tracking/CommandTrackingService.cs | 86 +++++++ .../Messaging/Tracking/ExistingCommand.cs | 17 ++ .../Tracking/TrackedCommandCleanupCommand.cs | 9 + .../Notifications/Email/EmailService.cs | 2 +- .../Notifications/Email/TestEmailCommand.cs | 13 +- .../Notifications/Growl/GrowlService.cs | 2 +- .../Notifications/Growl/TestGrowlCommand.cs | 11 +- .../Notifications/NotificationRepository.cs | 3 +- .../Notifications/NotificationService.cs | 2 +- .../Notifications/Plex/PlexService.cs | 2 +- .../Plex/TestPlexClientCommand.cs | 11 +- .../Plex/TestPlexServerCommand.cs | 11 +- .../Notifications/Prowl/ProwlService.cs | 2 +- .../Notifications/Prowl/TestProwlCommand.cs | 11 +- .../Notifications/Pushover/PushoverService.cs | 2 +- .../Pushover/TestPushoverCommand.cs | 11 +- .../Notifications/Xbmc/TestXbmcCommand.cs | 11 +- .../Notifications/Xbmc/XbmcService.cs | 2 +- NzbDrone.Core/NzbDrone.Core.csproj | 25 +- .../NewProgressMessageEvent.cs | 18 -- .../ProgressMessaging/ProgressMessage.cs | 13 - .../ProgressMessageTarget.cs | 94 +++---- .../Providers/UpdateXemMappingsCommand.cs | 7 +- NzbDrone.Core/Providers/XemProvider.cs | 2 +- .../Qualities/QualityProfileRepository.cs | 5 +- .../Qualities/QualityProfileService.cs | 2 +- .../Qualities/QualitySizeRepository.cs | 3 +- NzbDrone.Core/Qualities/QualitySizeService.cs | 2 +- .../Tv/Commands/RefreshSeriesCommand.cs | 17 +- NzbDrone.Core/Tv/EpisodeRepository.cs | 2 +- NzbDrone.Core/Tv/EpisodeService.cs | 2 +- .../Tv/Events/EpisodeInfoAddedEvent.cs | 1 + .../Tv/Events/EpisodeInfoDeletedEvent.cs | 1 + .../Tv/Events/EpisodeInfoUpdatedEvent.cs | 1 + NzbDrone.Core/Tv/Events/SeriesAddedEvent.cs | 1 + NzbDrone.Core/Tv/Events/SeriesDeletedEvent.cs | 1 + NzbDrone.Core/Tv/Events/SeriesUpdatedEvent.cs | 1 + NzbDrone.Core/Tv/RefreshEpisodeService.cs | 4 +- NzbDrone.Core/Tv/RefreshSeriesService.cs | 7 +- NzbDrone.Core/Tv/SeasonRepository.cs | 2 +- NzbDrone.Core/Tv/SeasonService.cs | Bin 4634 -> 4633 bytes NzbDrone.Core/Tv/SeriesRepository.cs | 3 +- NzbDrone.Core/Tv/SeriesService.cs | 2 +- .../Commands/ApplicationUpdateCommand.cs | 14 +- NzbDrone.Core/Update/InstallUpdateService.cs | 12 +- NzbDrone.Core/Update/UpdateCheckService.cs | 10 +- NzbDrone.Core/Update/UpdatePackage.cs | 5 +- .../Update/UpdatePackageAvailable.cs | 3 - NzbDrone.Core/Update/UpdatePackageProvider.cs | 30 +-- .../progressmessaging/CommandUpdatedEvent.cs | 15 ++ NzbDrone.Host/MainAppContainerBuilder.cs | 8 +- NzbDrone.Host/NzbDrone.Host.csproj | 7 + .../Owin/MiddleWare/SignalRMiddleWare.cs | 16 +- NzbDrone.Host/Owin/NlogTextWriter.cs | 16 +- .../CommandIntegerationTests.cs | 7 +- NzbDrone.SignalR/BroadcastSignalRMessage.cs | 12 + .../NoOpPerformanceCounterManager.cs | 2 +- NzbDrone.SignalR/NzbDrone.SignalR.csproj | 80 ++++++ .../NzbDronePersistentConnection.cs | 23 ++ NzbDrone.SignalR/Properties/AssemblyInfo.cs | 11 + .../Serializer.cs | 2 +- NzbDrone.SignalR/SignalRMessage.cs | 8 + .../SignalrDependencyResolver.cs | 2 +- NzbDrone.SignalR/packages.config | 5 + NzbDrone.Test.Common/TestBase.cs | 1 + NzbDrone.sln | 138 +++++++++- UI/AddSeries/AddSeriesTemplate.html | 8 +- UI/Commands/CommandCollection.js | 13 +- UI/Commands/CommandController.js | 27 +- UI/Commands/CommandMessengerCollectionView.js | 15 ++ UI/Commands/CommandMessengerItemView.js | 48 ++++ UI/Commands/CommandModel.js | 25 ++ UI/Controller.js | 3 +- UI/Episode/Search/Layout.js | 22 +- UI/Mixins/backbone.signalr.mixin.js | 52 +--- .../ProgressMessageCollection.js | 35 +-- UI/ProgressMessaging/ProgressMessageModel.js | 8 - UI/Router.js | 13 +- UI/SeasonPass/SeriesLayout.js | 4 +- UI/Series/Details/SeasonLayoutTemplate.html | 32 ++- UI/Series/Details/SeriesDetailsLayout.js | 87 ++++--- UI/Series/Details/SeriesDetailsTemplate.html | 21 +- UI/Series/series.less | 58 +++-- UI/Shared/Actioneer.js | 52 +++- UI/Shared/LoadingView.js | 2 +- UI/Shared/Messenger.js | 6 +- UI/Shared/SignalRBroadcaster.js | 51 ++++ UI/Shared/Toolbar/Button/ButtonView.js | 50 ++-- UI/System/Layout.js | 24 +- UI/app.js | 5 +- UI/jQuery/jquery.spin.js | 45 ++++ 219 files changed, 2035 insertions(+), 1495 deletions(-) delete mode 100644 NzbDrone.Api/Commands/CommandConnection.cs delete mode 100644 NzbDrone.Api/Episodes/EpisodeConnection.cs create mode 100644 NzbDrone.Api/NzbDroneRestModuleWithSignalR.cs delete mode 100644 NzbDrone.Api/ProgressMessaging/ProgressMessageConnection.cs delete mode 100644 NzbDrone.Api/ProgressMessaging/ProgressMessageModule.cs delete mode 100644 NzbDrone.Api/ProgressMessaging/ProgressMessageResource.cs create mode 100644 NzbDrone.Api/ResourceChangeMessage.cs delete mode 100644 NzbDrone.Api/RootFolders/RootFolderConnection.cs delete mode 100644 NzbDrone.Api/Series/SeriesConnection.cs delete mode 100644 NzbDrone.Api/SignalR/BasicResourceConnection.cs delete mode 100644 NzbDrone.Api/SignalR/NzbDronePersistentConnection.cs create mode 100644 NzbDrone.Common.Test/MessagingTests/CommandBaseFixture.cs rename NzbDrone.Common.Test/{EventingTests => MessagingTests}/MessageAggregatorCommandTests.cs (65%) rename NzbDrone.Common.Test/{EventingTests => MessagingTests}/MessageAggregatorEventTests.cs (96%) delete mode 100644 NzbDrone.Common/Instrumentation/LoggerExtensions.cs delete mode 100644 NzbDrone.Common/Messaging/CommandEqualityComparer.cs delete mode 100644 NzbDrone.Common/Messaging/Events/CommandCompletedEvent.cs delete mode 100644 NzbDrone.Common/Messaging/Events/CommandExecutedEvent.cs delete mode 100644 NzbDrone.Common/Messaging/Events/CommandFailedEvent.cs delete mode 100644 NzbDrone.Common/Messaging/Events/CommandStartedEvent.cs delete mode 100644 NzbDrone.Common/Messaging/ICommand.cs delete mode 100644 NzbDrone.Common/Messaging/TestCommand.cs delete mode 100644 NzbDrone.Common/Messaging/TestCommandExecutor.cs delete mode 100644 NzbDrone.Common/Messaging/Tracking/CommandTrackingService.cs delete mode 100644 NzbDrone.Common/Messaging/Tracking/ExistingCommand.cs delete mode 100644 NzbDrone.Common/Messaging/Tracking/ProcessState.cs delete mode 100644 NzbDrone.Common/Messaging/Tracking/TrackedCommand.cs delete mode 100644 NzbDrone.Common/Messaging/Tracking/TrackedCommandCleanupCommand.cs delete mode 100644 NzbDrone.Core/Datastore/CachedBasicRepository.cs create mode 100644 NzbDrone.Core/Datastore/Migration/Framework/SQLiteMigrationHelper (vaio's conflicted copy 2013-09-04).cs create mode 100644 NzbDrone.Core/Instrumentation/LoggerExtensions.cs create mode 100644 NzbDrone.Core/MediaFiles/Commands/BackendCommandAttribute.cs create mode 100644 NzbDrone.Core/Messaging/Commands/BackendCommandAttribute.cs create mode 100644 NzbDrone.Core/Messaging/Commands/Command.cs create mode 100644 NzbDrone.Core/Messaging/Commands/CommandEqualityComparer.cs create mode 100644 NzbDrone.Core/Messaging/Commands/TestCommand.cs create mode 100644 NzbDrone.Core/Messaging/Commands/TestCommandExecutor.cs create mode 100644 NzbDrone.Core/Messaging/Events/CommandCreatedEvent.cs create mode 100644 NzbDrone.Core/Messaging/Events/CommandExecutedEvent.cs rename {NzbDrone.Common => NzbDrone.Core}/Messaging/IExecute.cs (52%) rename {NzbDrone.Common => NzbDrone.Core}/Messaging/IHandle.cs (80%) rename {NzbDrone.Common => NzbDrone.Core}/Messaging/IMessageAggregator.cs (55%) rename {NzbDrone.Common => NzbDrone.Core}/Messaging/IProcessMessage.cs (86%) rename {NzbDrone.Common => NzbDrone.Core}/Messaging/MessageAggregator.cs (63%) rename {NzbDrone.Common => NzbDrone.Core}/Messaging/MessageExtensions.cs (68%) create mode 100644 NzbDrone.Core/Messaging/Tracking/CommandStatus.cs create mode 100644 NzbDrone.Core/Messaging/Tracking/CommandTrackingService.cs create mode 100644 NzbDrone.Core/Messaging/Tracking/ExistingCommand.cs create mode 100644 NzbDrone.Core/Messaging/Tracking/TrackedCommandCleanupCommand.cs delete mode 100644 NzbDrone.Core/ProgressMessaging/NewProgressMessageEvent.cs delete mode 100644 NzbDrone.Core/ProgressMessaging/ProgressMessage.cs create mode 100644 NzbDrone.Core/progressmessaging/CommandUpdatedEvent.cs create mode 100644 NzbDrone.SignalR/BroadcastSignalRMessage.cs rename {NzbDrone.Api/SignalR => NzbDrone.SignalR}/NoOpPerformanceCounterManager.cs (99%) create mode 100644 NzbDrone.SignalR/NzbDrone.SignalR.csproj create mode 100644 NzbDrone.SignalR/NzbDronePersistentConnection.cs create mode 100644 NzbDrone.SignalR/Properties/AssemblyInfo.cs rename {NzbDrone.Api/SignalR => NzbDrone.SignalR}/Serializer.cs (95%) create mode 100644 NzbDrone.SignalR/SignalRMessage.cs rename {NzbDrone.Api/SignalR => NzbDrone.SignalR}/SignalrDependencyResolver.cs (96%) create mode 100644 NzbDrone.SignalR/packages.config create mode 100644 UI/Commands/CommandMessengerCollectionView.js create mode 100644 UI/Commands/CommandMessengerItemView.js delete mode 100644 UI/ProgressMessaging/ProgressMessageModel.js create mode 100644 UI/Shared/SignalRBroadcaster.js create mode 100644 UI/jQuery/jquery.spin.js diff --git a/NzbDrone.Api.Test/MappingTests/ResourceMappingFixture.cs b/NzbDrone.Api.Test/MappingTests/ResourceMappingFixture.cs index 2aaf97b79..b6a3f9fe6 100644 --- a/NzbDrone.Api.Test/MappingTests/ResourceMappingFixture.cs +++ b/NzbDrone.Api.Test/MappingTests/ResourceMappingFixture.cs @@ -4,6 +4,7 @@ using FizzWare.NBuilder; using FluentAssertions; using Marr.Data; using NUnit.Framework; +using NzbDrone.Api.Commands; using NzbDrone.Api.Config; using NzbDrone.Api.Episodes; using NzbDrone.Api.History; @@ -17,12 +18,15 @@ using NzbDrone.Api.Update; using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.Indexers; using NzbDrone.Core.Instrumentation; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Organizer; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Qualities; using NzbDrone.Core.RootFolders; using NzbDrone.Core.Tv; using NzbDrone.Core.Update; +using NzbDrone.Core.Update.Commands; using NzbDrone.Test.Common; using System.Linq; @@ -40,9 +44,9 @@ namespace NzbDrone.Api.Test.MappingTests [TestCase(typeof(ParsedEpisodeInfo), typeof(ReleaseResource))] [TestCase(typeof(DownloadDecision), typeof(ReleaseResource))] [TestCase(typeof(Core.History.History), typeof(HistoryResource))] - [TestCase(typeof(UpdatePackage), typeof(UpdateResource))] [TestCase(typeof(Quality), typeof(QualityResource))] [TestCase(typeof(Log), typeof(LogResource))] + [TestCase(typeof(Command), typeof(CommandResource))] public void matching_fields(Type modelType, Type resourceType) { MappingValidation.ValidateMapping(modelType, resourceType); @@ -116,6 +120,15 @@ namespace NzbDrone.Api.Test.MappingTests profileResource.InjectTo(); } + + + + [Test] + public void should_map_tracked_command() + { + var profileResource = new ApplicationUpdateCommand(); + profileResource.InjectTo(); + } } public class ModelWithLazy diff --git a/NzbDrone.Api/Commands/CommandConnection.cs b/NzbDrone.Api/Commands/CommandConnection.cs deleted file mode 100644 index 227c69bec..000000000 --- a/NzbDrone.Api/Commands/CommandConnection.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using Microsoft.AspNet.SignalR; -using Microsoft.AspNet.SignalR.Infrastructure; -using NzbDrone.Api.SignalR; -using NzbDrone.Common.Messaging; -using NzbDrone.Common.Messaging.Events; -using NzbDrone.Common.Messaging.Tracking; - -namespace NzbDrone.Api.Commands -{ - public class CommandConnection : NzbDronePersistentConnection, - IHandleAsync, - IHandleAsync, - IHandleAsync - { - public override string Resource - { - get { return "/Command"; } - } - - public void HandleAsync(CommandStartedEvent message) - { - BroadcastMessage(message.TrackedCommand); - } - - public void HandleAsync(CommandCompletedEvent message) - { - BroadcastMessage(message.TrackedCommand); - } - - public void HandleAsync(CommandFailedEvent message) - { - BroadcastMessage(message.TrackedCommand); - } - - private void BroadcastMessage(TrackedCommand trackedCommand) - { - var context = ((ConnectionManager)GlobalHost.ConnectionManager).GetConnection(GetType()); - context.Connection.Broadcast(trackedCommand); - } - } -} diff --git a/NzbDrone.Api/Commands/CommandModule.cs b/NzbDrone.Api/Commands/CommandModule.cs index 8ad4a5475..bd04e861a 100644 --- a/NzbDrone.Api/Commands/CommandModule.cs +++ b/NzbDrone.Api/Commands/CommandModule.cs @@ -1,47 +1,68 @@ using System; +using System.Collections.Generic; using System.Linq; -using Nancy; using NzbDrone.Api.Extensions; using NzbDrone.Api.Mapping; +using NzbDrone.Api.Validation; using NzbDrone.Common.Composition; -using NzbDrone.Common.Messaging; -using NzbDrone.Common.Messaging.Tracking; +using NzbDrone.Core.Datastore.Events; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; +using NzbDrone.Core.Messaging.Tracking; +using NzbDrone.Core.ProgressMessaging; + namespace NzbDrone.Api.Commands { - public class CommandModule : NzbDroneRestModule + public class CommandModule : NzbDroneRestModuleWithSignalR, IHandle { private readonly IMessageAggregator _messageAggregator; private readonly IContainer _container; private readonly ITrackCommands _trackCommands; public CommandModule(IMessageAggregator messageAggregator, IContainer container, ITrackCommands trackCommands) + : base(messageAggregator) { _messageAggregator = messageAggregator; _container = container; _trackCommands = trackCommands; - Post["/"] = x => RunCommand(ReadResourceFromRequest()); - Get["/"] = x => GetAllCommands(); + GetResourceById = GetCommand; + CreateResource = StartCommand; + GetResourceAll = GetAllCommands; + + PostValidator.RuleFor(c => c.Name).NotBlank(); } - private Response RunCommand(CommandResource resource) + private CommandResource GetCommand(int id) + { + return _trackCommands.GetById(id).InjectTo(); + } + + private int StartCommand(CommandResource commandResource) { var commandType = - _container.GetImplementations(typeof(ICommand)) - .Single(c => c.Name.Replace("Command", "") - .Equals(resource.Command, StringComparison.InvariantCultureIgnoreCase)); + _container.GetImplementations(typeof(Command)) + .Single(c => c.Name.Replace("Command", "") + .Equals(commandResource.Name, StringComparison.InvariantCultureIgnoreCase)); dynamic command = Request.Body.FromJson(commandType); - var response = (TrackedCommand) _messageAggregator.PublishCommandAsync(command); - - return response.AsResponse(HttpStatusCode.Created); + var trackedCommand = (Command)_messageAggregator.PublishCommandAsync(command); + return trackedCommand.Id; } - private Response GetAllCommands() + private List GetAllCommands() { - return _trackCommands.AllTracked().AsResponse(); + return ToListResource(_trackCommands.RunningCommands); + } + + public void Handle(CommandUpdatedEvent message) + { + if (message.Command.SendUpdatesToClient) + { + BroadcastResourceChange(ModelAction.Updated, message.Command.Id); + } } } } \ No newline at end of file diff --git a/NzbDrone.Api/Commands/CommandResource.cs b/NzbDrone.Api/Commands/CommandResource.cs index e71a0d08f..6b25dd10e 100644 --- a/NzbDrone.Api/Commands/CommandResource.cs +++ b/NzbDrone.Api/Commands/CommandResource.cs @@ -1,9 +1,16 @@ -using NzbDrone.Api.REST; +using System; +using NzbDrone.Api.REST; +using NzbDrone.Core.Messaging.Tracking; namespace NzbDrone.Api.Commands { public class CommandResource : RestResource { - public string Command { get; set; } + public String Name { get; set; } + public String Message { get; set; } + public DateTime StartedOn { get; set; } + public DateTime StateChangeTime { get; set; } + public Boolean SendUpdatesToClient { get; set; } + public CommandStatus State { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Api/Episodes/EpisodeConnection.cs b/NzbDrone.Api/Episodes/EpisodeConnection.cs deleted file mode 100644 index 814c6dc84..000000000 --- a/NzbDrone.Api/Episodes/EpisodeConnection.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using Microsoft.AspNet.SignalR; -using Microsoft.AspNet.SignalR.Infrastructure; -using NzbDrone.Api.SignalR; -using NzbDrone.Common.Messaging; -using NzbDrone.Core.Download; -using NzbDrone.Core.Tv; - -namespace NzbDrone.Api.Episodes -{ - public class EpisodeConnection : BasicResourceConnection, IHandleAsync - { - public override string Resource - { - get { return "/Episodes"; } - } - - public void HandleAsync(EpisodeGrabbedEvent message) - { - var context = ((ConnectionManager)GlobalHost.ConnectionManager).GetConnection(GetType()); - context.Connection.Broadcast(message); - } - } -} diff --git a/NzbDrone.Api/NancyBootstrapper.cs b/NzbDrone.Api/NancyBootstrapper.cs index 61c311471..f4f0b1de4 100644 --- a/NzbDrone.Api/NancyBootstrapper.cs +++ b/NzbDrone.Api/NancyBootstrapper.cs @@ -7,9 +7,9 @@ using NzbDrone.Api.ErrorManagement; using NzbDrone.Api.Extensions; using NzbDrone.Api.Extensions.Pipelines; using NzbDrone.Common.Instrumentation; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Messaging; using NzbDrone.Core.ProgressMessaging; using TinyIoC; diff --git a/NzbDrone.Api/NzbDrone.Api.csproj b/NzbDrone.Api/NzbDrone.Api.csproj index 6d918a2ef..a4fb4ee50 100644 --- a/NzbDrone.Api/NzbDrone.Api.csproj +++ b/NzbDrone.Api/NzbDrone.Api.csproj @@ -83,19 +83,14 @@ - - - - - @@ -127,6 +122,8 @@ + + @@ -139,8 +136,6 @@ - - @@ -158,11 +153,6 @@ - - - - - @@ -185,6 +175,10 @@ {ff5ee3b6-913b-47ce-9ceb-11c51b4e1205} NzbDrone.Core + + {7c2cc69f-5ca0-4e5c-85cb-983f9f6c3b36} + NzbDrone.SignalR + @@ -196,4 +190,4 @@ --> - \ No newline at end of file + diff --git a/NzbDrone.Api/NzbDroneRestModule.cs b/NzbDrone.Api/NzbDroneRestModule.cs index b4b01aee5..5c297e331 100644 --- a/NzbDrone.Api/NzbDroneRestModule.cs +++ b/NzbDrone.Api/NzbDroneRestModule.cs @@ -9,6 +9,8 @@ namespace NzbDrone.Api { public abstract class NzbDroneRestModule : RestModule where TResource : RestResource, new() { + protected string Resource { get; private set; } + protected NzbDroneRestModule() : this(new TResource().ResourceName) { @@ -17,6 +19,7 @@ namespace NzbDrone.Api protected NzbDroneRestModule(string resource) : base("/api/" + resource.Trim('/')) { + Resource = resource; PostValidator.RuleFor(r => r.Id).IsZero(); PutValidator.RuleFor(r => r.Id).ValidId(); } @@ -28,7 +31,7 @@ namespace NzbDrone.Api return model.Id; } - protected List ToListResource(Func> function) where TModel : ModelBase, new() + protected List ToListResource(Func> function) where TModel : class { var modelList = function(); return modelList.InjectTo>(); diff --git a/NzbDrone.Api/NzbDroneRestModuleWithSignalR.cs b/NzbDrone.Api/NzbDroneRestModuleWithSignalR.cs new file mode 100644 index 000000000..1fb86e41d --- /dev/null +++ b/NzbDrone.Api/NzbDroneRestModuleWithSignalR.cs @@ -0,0 +1,54 @@ +using NzbDrone.Api.REST; +using NzbDrone.Core.Datastore; +using NzbDrone.Core.Datastore.Events; +using NzbDrone.Core.Messaging; +using NzbDrone.SignalR; + +namespace NzbDrone.Api +{ + public abstract class NzbDroneRestModuleWithSignalR : NzbDroneRestModule, IHandle> + where TResource : RestResource, new() + where TModel : ModelBase + { + private readonly IMessageAggregator _messageAggregator; + + protected NzbDroneRestModuleWithSignalR(IMessageAggregator messageAggregator) + { + _messageAggregator = messageAggregator; + } + + public void Handle(ModelEvent message) + { + if (message.Action == ModelAction.Deleted || message.Action == ModelAction.Sync) + { + BroadcastResourceChange(message.Action); + } + + BroadcastResourceChange(message.Action, message.Model.Id); + } + + protected void BroadcastResourceChange(ModelAction action, int id) + { + var resource = GetResourceById(id); + + var signalRMessage = new SignalRMessage + { + Name = Resource, + Body = new ResourceChangeMessage(resource, action) + }; + + _messageAggregator.PublishCommand(new BroadcastSignalRMessage(signalRMessage)); + } + + protected void BroadcastResourceChange(ModelAction action) + { + var signalRMessage = new SignalRMessage + { + Name = Resource, + Body = new ResourceChangeMessage(action) + }; + + _messageAggregator.PublishCommand(new BroadcastSignalRMessage(signalRMessage)); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Api/ProgressMessaging/ProgressMessageConnection.cs b/NzbDrone.Api/ProgressMessaging/ProgressMessageConnection.cs deleted file mode 100644 index a5b4afdb0..000000000 --- a/NzbDrone.Api/ProgressMessaging/ProgressMessageConnection.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using Microsoft.AspNet.SignalR; -using Microsoft.AspNet.SignalR.Infrastructure; -using NzbDrone.Api.SignalR; -using NzbDrone.Common.Messaging; -using NzbDrone.Core.ProgressMessaging; - -namespace NzbDrone.Api.ProgressMessaging -{ - public class ProgressMessageConnection : NzbDronePersistentConnection, - IHandleAsync - { - public override string Resource - { - get { return "/ProgressMessage"; } - } - - public void HandleAsync(NewProgressMessageEvent message) - { - var context = ((ConnectionManager)GlobalHost.ConnectionManager).GetConnection(GetType()); - context.Connection.Broadcast(message.ProgressMessage); - } - } -} diff --git a/NzbDrone.Api/ProgressMessaging/ProgressMessageModule.cs b/NzbDrone.Api/ProgressMessaging/ProgressMessageModule.cs deleted file mode 100644 index a06db9c24..000000000 --- a/NzbDrone.Api/ProgressMessaging/ProgressMessageModule.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Nancy; -using NzbDrone.Api.Extensions; - -namespace NzbDrone.Api.ProgressMessaging -{ - public class ProgressMessageModule : NzbDroneRestModule - { - public ProgressMessageModule() - { - Get["/"] = x => GetAllMessages(); - } - - private Response GetAllMessages() - { - return new List().AsResponse(); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Api/ProgressMessaging/ProgressMessageResource.cs b/NzbDrone.Api/ProgressMessaging/ProgressMessageResource.cs deleted file mode 100644 index 3117eb142..000000000 --- a/NzbDrone.Api/ProgressMessaging/ProgressMessageResource.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using NzbDrone.Api.REST; - -namespace NzbDrone.Api.ProgressMessaging -{ - public class ProgressMessageResource : RestResource - { - public DateTime Time { get; set; } - public String CommandId { get; set; } - public String Message { get; set; } - } -} \ No newline at end of file diff --git a/NzbDrone.Api/REST/RestModule.cs b/NzbDrone.Api/REST/RestModule.cs index 2b19bcc17..9a576d360 100644 --- a/NzbDrone.Api/REST/RestModule.cs +++ b/NzbDrone.Api/REST/RestModule.cs @@ -61,7 +61,7 @@ namespace NzbDrone.Api.REST protected Func GetResourceById { - private get { return _getResourceById; } + get { return _getResourceById; } set { _getResourceById = value; diff --git a/NzbDrone.Api/ResourceChangeMessage.cs b/NzbDrone.Api/ResourceChangeMessage.cs new file mode 100644 index 000000000..6b7efb50a --- /dev/null +++ b/NzbDrone.Api/ResourceChangeMessage.cs @@ -0,0 +1,29 @@ +using System; +using NzbDrone.Api.REST; +using NzbDrone.Core.Datastore.Events; + +namespace NzbDrone.Api +{ + public class ResourceChangeMessage where TResource : RestResource + { + public TResource Resource { get; private set; } + public ModelAction Action { get; private set; } + + public ResourceChangeMessage(ModelAction action) + { + if (action != ModelAction.Deleted || action != ModelAction.Sync) + { + throw new InvalidOperationException("Resource message without a resource needs to have Delete or Sync as action"); + } + + Action = action; + } + + public ResourceChangeMessage(TResource resource, ModelAction action) + { + Resource = resource; + Action = action; + } + } + +} \ No newline at end of file diff --git a/NzbDrone.Api/RootFolders/RootFolderConnection.cs b/NzbDrone.Api/RootFolders/RootFolderConnection.cs deleted file mode 100644 index 0068cc972..000000000 --- a/NzbDrone.Api/RootFolders/RootFolderConnection.cs +++ /dev/null @@ -1,13 +0,0 @@ -using NzbDrone.Api.SignalR; -using NzbDrone.Core.RootFolders; - -namespace NzbDrone.Api.RootFolders -{ - public class RootFolderConnection : BasicResourceConnection - { - public override string Resource - { - get { return "RootFolder"; } - } - } -} diff --git a/NzbDrone.Api/Series/SeriesConnection.cs b/NzbDrone.Api/Series/SeriesConnection.cs deleted file mode 100644 index 4de76e7e6..000000000 --- a/NzbDrone.Api/Series/SeriesConnection.cs +++ /dev/null @@ -1,12 +0,0 @@ -using NzbDrone.Api.SignalR; - -namespace NzbDrone.Api.Series -{ - public class SeriesConnection : BasicResourceConnection - { - public override string Resource - { - get { return "/Series"; } - } - } -} diff --git a/NzbDrone.Api/SignalR/BasicResourceConnection.cs b/NzbDrone.Api/SignalR/BasicResourceConnection.cs deleted file mode 100644 index 4166b07cb..000000000 --- a/NzbDrone.Api/SignalR/BasicResourceConnection.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Threading.Tasks; -using Microsoft.AspNet.SignalR; -using Microsoft.AspNet.SignalR.Infrastructure; -using NLog; -using NzbDrone.Common.Instrumentation; -using NzbDrone.Common.Messaging; -using NzbDrone.Core.Datastore; -using NzbDrone.Core.Datastore.Events; - -namespace NzbDrone.Api.SignalR -{ - public abstract class BasicResourceConnection : - NzbDronePersistentConnection, - IHandleAsync> - where T : ModelBase - { - private readonly Logger _logger; - - - public BasicResourceConnection() - { - _logger = NzbDroneLogger.GetLogger(this); - } - - protected override Task OnConnected(IRequest request, string connectionId) - { - _logger.Trace("SignalR client connected. ID:{0}", connectionId); - return base.OnConnected(request, connectionId); - } - - public void HandleAsync(ModelEvent message) - { - var context = ((ConnectionManager)GlobalHost.ConnectionManager).GetConnection(GetType()); - context.Connection.Broadcast(message); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Api/SignalR/NzbDronePersistentConnection.cs b/NzbDrone.Api/SignalR/NzbDronePersistentConnection.cs deleted file mode 100644 index 2e4c8444d..000000000 --- a/NzbDrone.Api/SignalR/NzbDronePersistentConnection.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Microsoft.AspNet.SignalR; - -namespace NzbDrone.Api.SignalR -{ - public abstract class NzbDronePersistentConnection : PersistentConnection - { - public abstract string Resource { get; } - } -} \ No newline at end of file diff --git a/NzbDrone.Api/Update/UpdateModule.cs b/NzbDrone.Api/Update/UpdateModule.cs index 8a95efa4b..fbe13bd8e 100644 --- a/NzbDrone.Api/Update/UpdateModule.cs +++ b/NzbDrone.Api/Update/UpdateModule.cs @@ -33,8 +33,6 @@ namespace NzbDrone.Api.Update public class UpdateResource : RestResource { - public String Id { get; set; } - [JsonConverter(typeof(Newtonsoft.Json.Converters.VersionConverter))] public Version Version { get; set; } diff --git a/NzbDrone.Api/Validation/RuleBuilderExtensions.cs b/NzbDrone.Api/Validation/RuleBuilderExtensions.cs index b142f5a56..0374d8a96 100644 --- a/NzbDrone.Api/Validation/RuleBuilderExtensions.cs +++ b/NzbDrone.Api/Validation/RuleBuilderExtensions.cs @@ -27,5 +27,10 @@ namespace NzbDrone.Api.Validation { return ruleBuilder.SetValidator(new PathValidator()); } + + public static IRuleBuilderOptions NotBlank(this IRuleBuilder ruleBuilder) + { + return ruleBuilder.SetValidator(new NotNullValidator()).SetValidator(new NotEmptyValidator("")); + } } } \ No newline at end of file diff --git a/NzbDrone.App.Test/ContainerFixture.cs b/NzbDrone.App.Test/ContainerFixture.cs index d4322719f..030cb5cae 100644 --- a/NzbDrone.App.Test/ContainerFixture.cs +++ b/NzbDrone.App.Test/ContainerFixture.cs @@ -2,12 +2,12 @@ using NUnit.Framework; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; using NzbDrone.Core.Download; using NzbDrone.Core.Indexers; using NzbDrone.Core.Jobs; using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Messaging; using NzbDrone.Host; using NzbDrone.Test.Common; using FluentAssertions; diff --git a/NzbDrone.Common.Test/MessagingTests/CommandBaseFixture.cs b/NzbDrone.Common.Test/MessagingTests/CommandBaseFixture.cs new file mode 100644 index 000000000..bca26ed90 --- /dev/null +++ b/NzbDrone.Common.Test/MessagingTests/CommandBaseFixture.cs @@ -0,0 +1,20 @@ +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Core.Update.Commands; + +namespace NzbDrone.Common.Test.MessagingTests +{ + [TestFixture] + public class CommandBaseFixture + { + [Test] + public void default_values() + { + var command = new ApplicationUpdateCommand(); + + command.Id.Should().NotBe(0); + command.Name.Should().Be("ApplicationUpdate"); + } + + } +} \ No newline at end of file diff --git a/NzbDrone.Common.Test/MessagingTests/CommandEqualityComparerFixture.cs b/NzbDrone.Common.Test/MessagingTests/CommandEqualityComparerFixture.cs index 2b2deadea..0056cd6b2 100644 --- a/NzbDrone.Common.Test/MessagingTests/CommandEqualityComparerFixture.cs +++ b/NzbDrone.Common.Test/MessagingTests/CommandEqualityComparerFixture.cs @@ -1,12 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using FluentAssertions; +using FluentAssertions; using NUnit.Framework; -using NzbDrone.Common.Messaging; using NzbDrone.Core.IndexerSearch; using NzbDrone.Core.MediaFiles.Commands; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Common.Test.MessagingTests { @@ -18,9 +15,8 @@ namespace NzbDrone.Common.Test.MessagingTests { var command1 = new DownloadedEpisodesScanCommand(); var command2 = new DownloadedEpisodesScanCommand(); - var comparer = new CommandEqualityComparer(); - comparer.Equals(command1, command2).Should().BeTrue(); + CommandEqualityComparer.Instance.Equals(command1, command2).Should().BeTrue(); } [Test] @@ -28,9 +24,8 @@ namespace NzbDrone.Common.Test.MessagingTests { var command1 = new EpisodeSearchCommand { EpisodeId = 1 }; var command2 = new EpisodeSearchCommand { EpisodeId = 1 }; - var comparer = new CommandEqualityComparer(); - comparer.Equals(command1, command2).Should().BeTrue(); + CommandEqualityComparer.Instance.Equals(command1, command2).Should().BeTrue(); } [Test] @@ -38,9 +33,8 @@ namespace NzbDrone.Common.Test.MessagingTests { var command1 = new SeasonSearchCommand { SeriesId = 1, SeasonNumber = 1 }; var command2 = new SeasonSearchCommand { SeriesId = 1, SeasonNumber = 1 }; - var comparer = new CommandEqualityComparer(); - comparer.Equals(command1, command2).Should().BeTrue(); + CommandEqualityComparer.Instance.Equals(command1, command2).Should().BeTrue(); } [Test] @@ -48,9 +42,8 @@ namespace NzbDrone.Common.Test.MessagingTests { var command1 = new EpisodeSearchCommand { EpisodeId = 1 }; var command2 = new EpisodeSearchCommand { EpisodeId = 2 }; - var comparer = new CommandEqualityComparer(); - comparer.Equals(command1, command2).Should().BeFalse(); + CommandEqualityComparer.Instance.Equals(command1, command2).Should().BeFalse(); } [Test] @@ -58,9 +51,8 @@ namespace NzbDrone.Common.Test.MessagingTests { var command1 = new SeasonSearchCommand { SeriesId = 1, SeasonNumber = 1 }; var command2 = new SeasonSearchCommand { SeriesId = 1, SeasonNumber = 2 }; - var comparer = new CommandEqualityComparer(); - comparer.Equals(command1, command2).Should().BeFalse(); + CommandEqualityComparer.Instance.Equals(command1, command2).Should().BeFalse(); } [Test] @@ -68,9 +60,8 @@ namespace NzbDrone.Common.Test.MessagingTests { var command1 = new SeasonSearchCommand { SeriesId = 1, SeasonNumber = 1 }; var command2 = new SeasonSearchCommand { SeriesId = 2, SeasonNumber = 2 }; - var comparer = new CommandEqualityComparer(); - comparer.Equals(command1, command2).Should().BeFalse(); + CommandEqualityComparer.Instance.Equals(command1, command2).Should().BeFalse(); } } } diff --git a/NzbDrone.Common.Test/EventingTests/MessageAggregatorCommandTests.cs b/NzbDrone.Common.Test/MessagingTests/MessageAggregatorCommandTests.cs similarity index 65% rename from NzbDrone.Common.Test/EventingTests/MessageAggregatorCommandTests.cs rename to NzbDrone.Common.Test/MessagingTests/MessageAggregatorCommandTests.cs index b5c45bef0..42cc682ff 100644 --- a/NzbDrone.Common.Test/EventingTests/MessageAggregatorCommandTests.cs +++ b/NzbDrone.Common.Test/MessagingTests/MessageAggregatorCommandTests.cs @@ -2,11 +2,12 @@ using System.Collections.Generic; using Moq; using NUnit.Framework; -using NzbDrone.Common.Messaging; -using NzbDrone.Common.Messaging.Tracking; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; +using NzbDrone.Core.Messaging.Tracking; using NzbDrone.Test.Common; -namespace NzbDrone.Common.Test.EventingTests +namespace NzbDrone.Common.Test.MessagingTests { [TestFixture] public class MessageAggregatorCommandTests : TestBase @@ -28,13 +29,10 @@ namespace NzbDrone.Common.Test.EventingTests .Setup(c => c.Build(typeof(IExecute))) .Returns(_executorB.Object); - Mocker.GetMock() - .Setup(c => c.TrackIfNew(It.IsAny())) - .Returns(new TrackedCommand(new CommandA(), ProcessState.Running)); Mocker.GetMock() - .Setup(c => c.TrackIfNew(It.IsAny())) - .Returns(new TrackedCommand(new CommandB(), ProcessState.Running)); + .Setup(c => c.FindExisting(It.IsAny())) + .Returns(null); } [Test] @@ -42,10 +40,6 @@ namespace NzbDrone.Common.Test.EventingTests { var commandA = new CommandA(); - Mocker.GetMock() - .Setup(c => c.TrackIfNew(commandA)) - .Returns(new TrackedCommand(commandA, ProcessState.Running)); - Subject.PublishCommand(commandA); _executorA.Verify(c => c.Execute(commandA), Times.Once()); @@ -54,7 +48,7 @@ namespace NzbDrone.Common.Test.EventingTests [Test] public void should_publish_command_by_with_optional_arg_using_name() { - Mocker.GetMock().Setup(c => c.GetImplementations(typeof(ICommand))) + Mocker.GetMock().Setup(c => c.GetImplementations(typeof(Command))) .Returns(new List { typeof(CommandA), typeof(CommandB) }); Subject.PublishCommand(typeof(CommandA).FullName); @@ -67,10 +61,6 @@ namespace NzbDrone.Common.Test.EventingTests { var commandA = new CommandA(); - Mocker.GetMock() - .Setup(c => c.TrackIfNew(commandA)) - .Returns(new TrackedCommand(commandA, ProcessState.Running)); - Subject.PublishCommand(commandA); _executorA.Verify(c => c.Execute(commandA), Times.Once()); @@ -89,24 +79,18 @@ namespace NzbDrone.Common.Test.EventingTests } } - public class CommandA : ICommand + public class CommandA : Command { - public String CommandId { get; private set; } -// ReSharper disable UnusedParameter.Local public CommandA(int id = 0) -// ReSharper restore UnusedParameter.Local { - CommandId = HashUtil.GenerateCommandId(); } } - public class CommandB : ICommand + public class CommandB : Command { - public String CommandId { get; private set; } public CommandB() { - CommandId = HashUtil.GenerateCommandId(); } } diff --git a/NzbDrone.Common.Test/EventingTests/MessageAggregatorEventTests.cs b/NzbDrone.Common.Test/MessagingTests/MessageAggregatorEventTests.cs similarity index 96% rename from NzbDrone.Common.Test/EventingTests/MessageAggregatorEventTests.cs rename to NzbDrone.Common.Test/MessagingTests/MessageAggregatorEventTests.cs index b41f81124..588beb289 100644 --- a/NzbDrone.Common.Test/EventingTests/MessageAggregatorEventTests.cs +++ b/NzbDrone.Common.Test/MessagingTests/MessageAggregatorEventTests.cs @@ -1,13 +1,14 @@ using System; using System.Collections.Generic; using System.Threading; +using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; using NzbDrone.Test.Common; -using FluentAssertions; -namespace NzbDrone.Common.Test.EventingTests +namespace NzbDrone.Common.Test.MessagingTests { [TestFixture] public class MessageAggregatorEventTests : TestBase @@ -127,7 +128,7 @@ namespace NzbDrone.Common.Test.EventingTests counter.WaitForAllItems(); - counter.MaxThreads.Should().Be(2); + counter.MaxThreads.Should().Be(3); } } diff --git a/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj index 8fd34cbf6..7795f156f 100644 --- a/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj +++ b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj @@ -67,8 +67,9 @@ - - + + + diff --git a/NzbDrone.Common.Test/ServiceFactoryFixture.cs b/NzbDrone.Common.Test/ServiceFactoryFixture.cs index 4d83d0b3c..e84ac5510 100644 --- a/NzbDrone.Common.Test/ServiceFactoryFixture.cs +++ b/NzbDrone.Common.Test/ServiceFactoryFixture.cs @@ -2,8 +2,8 @@ using FluentAssertions; using NUnit.Framework; using NzbDrone.Common.EnvironmentInfo; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Messaging; using NzbDrone.Host; using NzbDrone.Test.Common; diff --git a/NzbDrone.Common/Instrumentation/ExceptronTarget.cs b/NzbDrone.Common/Instrumentation/ExceptronTarget.cs index 89208be7a..f824a5ac4 100644 --- a/NzbDrone.Common/Instrumentation/ExceptronTarget.cs +++ b/NzbDrone.Common/Instrumentation/ExceptronTarget.cs @@ -4,7 +4,6 @@ using Exceptron.Client; using Exceptron.Client.Configuration; using NLog; using NLog.Common; -using NLog.Config; using NLog.Layouts; using NLog.Targets; using NzbDrone.Common.EnvironmentInfo; @@ -23,9 +22,6 @@ namespace NzbDrone.Common.Instrumentation /// public IExceptronClient ExceptronClient { get; internal set; } - - - protected override void InitializeTarget() { var config = new ExceptronConfiguration diff --git a/NzbDrone.Common/Instrumentation/LoggerExtensions.cs b/NzbDrone.Common/Instrumentation/LoggerExtensions.cs deleted file mode 100644 index 305b3f610..000000000 --- a/NzbDrone.Common/Instrumentation/LoggerExtensions.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using NLog; -using NzbDrone.Common.Messaging.Tracking; - -namespace NzbDrone.Common.Instrumentation -{ - public static class LoggerExtensions - { - public static void Progress(this Logger logger, string message) - { - LogProgressMessage(logger, message, ProcessState.Running); - } - - public static void Progress(this Logger logger, string message, params object[] args) - { - var formattedMessage = String.Format(message, args); - Progress(logger, formattedMessage); - } - - public static void Complete(this Logger logger, string message) - { - LogProgressMessage(logger, message, ProcessState.Completed); - } - - public static void Complete(this Logger logger, string message, params object[] args) - { - var formattedMessage = String.Format(message, args); - Complete(logger, formattedMessage); - } - - public static void Failed(this Logger logger, string message) - { - LogProgressMessage(logger, message, ProcessState.Failed); - } - - public static void Failed(this Logger logger, string message, params object[] args) - { - var formattedMessage = String.Format(message, args); - Failed(logger, formattedMessage); - } - - private static void LogProgressMessage(Logger logger, string message, ProcessState state) - { - var logEvent = new LogEventInfo(LogLevel.Info, logger.Name, message); - logEvent.Properties.Add("Status", state); - - logger.Log(logEvent); - } - } -} diff --git a/NzbDrone.Common/Messaging/CommandEqualityComparer.cs b/NzbDrone.Common/Messaging/CommandEqualityComparer.cs deleted file mode 100644 index 390319704..000000000 --- a/NzbDrone.Common/Messaging/CommandEqualityComparer.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using NzbDrone.Common.EnvironmentInfo; - -namespace NzbDrone.Common.Messaging -{ - public class CommandEqualityComparer : IEqualityComparer - { - public bool Equals(ICommand x, ICommand y) - { - var xProperties = x.GetType().GetProperties(); - var yProperties = y.GetType().GetProperties(); - - foreach (var xProperty in xProperties) - { - if (xProperty.Name == "CommandId") - { - continue; - } - - var yProperty = yProperties.SingleOrDefault(p => p.Name == xProperty.Name); - - if (yProperty == null) - { - continue; - } - - if (!xProperty.GetValue(x, null).Equals(yProperty.GetValue(y, null))) - { - return false; - } - } - - return true; - } - - public int GetHashCode(ICommand obj) - { - return obj.CommandId.GetHashCode(); - } - } -} diff --git a/NzbDrone.Common/Messaging/Events/CommandCompletedEvent.cs b/NzbDrone.Common/Messaging/Events/CommandCompletedEvent.cs deleted file mode 100644 index f4831361e..000000000 --- a/NzbDrone.Common/Messaging/Events/CommandCompletedEvent.cs +++ /dev/null @@ -1,14 +0,0 @@ -using NzbDrone.Common.Messaging.Tracking; - -namespace NzbDrone.Common.Messaging.Events -{ - public class CommandCompletedEvent : IEvent - { - public TrackedCommand TrackedCommand { get; private set; } - - public CommandCompletedEvent(TrackedCommand trackedCommand) - { - TrackedCommand = trackedCommand; - } - } -} \ No newline at end of file diff --git a/NzbDrone.Common/Messaging/Events/CommandExecutedEvent.cs b/NzbDrone.Common/Messaging/Events/CommandExecutedEvent.cs deleted file mode 100644 index b93a5597c..000000000 --- a/NzbDrone.Common/Messaging/Events/CommandExecutedEvent.cs +++ /dev/null @@ -1,14 +0,0 @@ -using NzbDrone.Common.Messaging.Tracking; - -namespace NzbDrone.Common.Messaging.Events -{ - public class CommandExecutedEvent : IEvent - { - public TrackedCommand TrackedCommand { get; private set; } - - public CommandExecutedEvent(TrackedCommand trackedCommand) - { - TrackedCommand = trackedCommand; - } - } -} \ No newline at end of file diff --git a/NzbDrone.Common/Messaging/Events/CommandFailedEvent.cs b/NzbDrone.Common/Messaging/Events/CommandFailedEvent.cs deleted file mode 100644 index 5749ca00a..000000000 --- a/NzbDrone.Common/Messaging/Events/CommandFailedEvent.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using NzbDrone.Common.Messaging.Tracking; - -namespace NzbDrone.Common.Messaging.Events -{ - public class CommandFailedEvent : IEvent - { - public TrackedCommand TrackedCommand { get; private set; } - public Exception Exception { get; private set; } - - public CommandFailedEvent(TrackedCommand trackedCommand, Exception exception) - { - TrackedCommand = trackedCommand; - Exception = exception; - } - } -} \ No newline at end of file diff --git a/NzbDrone.Common/Messaging/Events/CommandStartedEvent.cs b/NzbDrone.Common/Messaging/Events/CommandStartedEvent.cs deleted file mode 100644 index 9247fbd45..000000000 --- a/NzbDrone.Common/Messaging/Events/CommandStartedEvent.cs +++ /dev/null @@ -1,14 +0,0 @@ -using NzbDrone.Common.Messaging.Tracking; - -namespace NzbDrone.Common.Messaging.Events -{ - public class CommandStartedEvent : IEvent - { - public TrackedCommand TrackedCommand { get; private set; } - - public CommandStartedEvent(TrackedCommand trackedCommand) - { - TrackedCommand = trackedCommand; - } - } -} \ No newline at end of file diff --git a/NzbDrone.Common/Messaging/ICommand.cs b/NzbDrone.Common/Messaging/ICommand.cs deleted file mode 100644 index e93f1ccaa..000000000 --- a/NzbDrone.Common/Messaging/ICommand.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace NzbDrone.Common.Messaging -{ - public interface ICommand : IMessage - { - String CommandId { get; } - } -} \ No newline at end of file diff --git a/NzbDrone.Common/Messaging/IEvent.cs b/NzbDrone.Common/Messaging/IEvent.cs index 953709c13..00f40b449 100644 --- a/NzbDrone.Common/Messaging/IEvent.cs +++ b/NzbDrone.Common/Messaging/IEvent.cs @@ -1,4 +1,4 @@ -namespace NzbDrone.Common.Messaging +namespace NzbDrone.Common.Messaging { public interface IEvent : IMessage { diff --git a/NzbDrone.Common/Messaging/TestCommand.cs b/NzbDrone.Common/Messaging/TestCommand.cs deleted file mode 100644 index c24a89780..000000000 --- a/NzbDrone.Common/Messaging/TestCommand.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace NzbDrone.Common.Messaging -{ - public class TestCommand : ICommand - { - public int Duration { get; set; } - public String CommandId { get; private set; } - - public TestCommand() - { - Duration = 4000; - } - } -} \ No newline at end of file diff --git a/NzbDrone.Common/Messaging/TestCommandExecutor.cs b/NzbDrone.Common/Messaging/TestCommandExecutor.cs deleted file mode 100644 index be0ea4ea4..000000000 --- a/NzbDrone.Common/Messaging/TestCommandExecutor.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Threading; - -namespace NzbDrone.Common.Messaging -{ - public class TestCommandExecutor : IExecute - { - public void Execute(TestCommand message) - { - Thread.Sleep(message.Duration); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Common/Messaging/Tracking/CommandTrackingService.cs b/NzbDrone.Common/Messaging/Tracking/CommandTrackingService.cs deleted file mode 100644 index 27c0c8bf1..000000000 --- a/NzbDrone.Common/Messaging/Tracking/CommandTrackingService.cs +++ /dev/null @@ -1,127 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Remoting; -using NzbDrone.Common.Cache; - -namespace NzbDrone.Common.Messaging.Tracking -{ - public interface ITrackCommands - { - TrackedCommand TrackIfNew(ICommand command); - ExistingCommand TrackNewOrGet(ICommand command); - TrackedCommand Completed(TrackedCommand trackedCommand, TimeSpan runtime); - TrackedCommand Failed(TrackedCommand trackedCommand, Exception e); - List AllTracked(); - Boolean ExistingCommand(ICommand command); - TrackedCommand FindExisting(ICommand command); - } - - public class TrackCommands : ITrackCommands, IExecute - { - private readonly ICached _cache; - - public TrackCommands(ICacheManger cacheManger) - { - _cache = cacheManger.GetCache(GetType()); - } - - public TrackedCommand TrackIfNew(ICommand command) - { - if (ExistingCommand(command)) - { - return null; - } - - var trackedCommand = new TrackedCommand(command, ProcessState.Running); - Store(trackedCommand); - - return trackedCommand; - } - - public ExistingCommand TrackNewOrGet(ICommand command) - { - var trackedCommand = FindExisting(command); - - if (trackedCommand == null) - { - trackedCommand = new TrackedCommand(command, ProcessState.Running); - Store(trackedCommand); - - return new ExistingCommand(false, trackedCommand); - } - - return new ExistingCommand(true, trackedCommand); - } - - public TrackedCommand Completed(TrackedCommand trackedCommand, TimeSpan runtime) - { - trackedCommand.StateChangeTime = DateTime.UtcNow; - trackedCommand.State = ProcessState.Completed; - trackedCommand.Runtime = runtime; - - Store(trackedCommand); - - return trackedCommand; - } - - public TrackedCommand Failed(TrackedCommand trackedCommand, Exception e) - { - trackedCommand.StateChangeTime = DateTime.UtcNow; - trackedCommand.State = ProcessState.Failed; - trackedCommand.Exception = e; - - Store(trackedCommand); - - return trackedCommand; - } - - public List AllTracked() - { - return _cache.Values.ToList(); - } - - public bool ExistingCommand(ICommand command) - { - return FindExisting(command) != null; - } - - public TrackedCommand FindExisting(ICommand command) - { - var comparer = new CommandEqualityComparer(); - return Running(command.GetType()).SingleOrDefault(t => comparer.Equals(t.Command, command)); - } - - private List Running(Type type = null) - { - var running = AllTracked().Where(i => i.State == ProcessState.Running); - - if (type != null) - { - return running.Where(t => t.Type == type.FullName).ToList(); - } - - return running.ToList(); - } - - private void Store(TrackedCommand trackedCommand) - { - if (trackedCommand.Command.GetType() == typeof(TrackedCommandCleanupCommand)) - { - return; - } - - _cache.Set(trackedCommand.Command.CommandId, trackedCommand); - } - - public void Execute(TrackedCommandCleanupCommand message) - { - var old = AllTracked().Where(c => c.State != ProcessState.Running && c.StateChangeTime < DateTime.UtcNow.AddMinutes(-5)); - - foreach (var trackedCommand in old) - { - _cache.Remove(trackedCommand.Command.CommandId); - } - } - } -} diff --git a/NzbDrone.Common/Messaging/Tracking/ExistingCommand.cs b/NzbDrone.Common/Messaging/Tracking/ExistingCommand.cs deleted file mode 100644 index 7005585ef..000000000 --- a/NzbDrone.Common/Messaging/Tracking/ExistingCommand.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace NzbDrone.Common.Messaging.Tracking -{ - public class ExistingCommand - { - public Boolean Existing { get; set; } - public TrackedCommand TrackedCommand { get; set; } - - public ExistingCommand(Boolean exisitng, TrackedCommand trackedCommand) - { - Existing = exisitng; - TrackedCommand = trackedCommand; - } - } -} diff --git a/NzbDrone.Common/Messaging/Tracking/ProcessState.cs b/NzbDrone.Common/Messaging/Tracking/ProcessState.cs deleted file mode 100644 index dc79c37f4..000000000 --- a/NzbDrone.Common/Messaging/Tracking/ProcessState.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace NzbDrone.Common.Messaging.Tracking -{ - public enum ProcessState - { - Running, - Completed, - Failed - } -} diff --git a/NzbDrone.Common/Messaging/Tracking/TrackedCommand.cs b/NzbDrone.Common/Messaging/Tracking/TrackedCommand.cs deleted file mode 100644 index 35b0e05ac..000000000 --- a/NzbDrone.Common/Messaging/Tracking/TrackedCommand.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; - -namespace NzbDrone.Common.Messaging.Tracking -{ - public class TrackedCommand - { - public String Id { get; private set; } - public String Name { get; private set; } - public String Type { get; private set; } - public ICommand Command { get; private set; } - public ProcessState State { get; set; } - public DateTime StateChangeTime { get; set; } - public TimeSpan Runtime { get; set; } - public Exception Exception { get; set; } - - public TrackedCommand() - { - } - - public TrackedCommand(ICommand command, ProcessState state) - { - Id = command.CommandId; - Name = command.GetType().Name; - Type = command.GetType().FullName; - Command = command; - State = state; - StateChangeTime = DateTime.UtcNow; - } - } -} diff --git a/NzbDrone.Common/Messaging/Tracking/TrackedCommandCleanupCommand.cs b/NzbDrone.Common/Messaging/Tracking/TrackedCommandCleanupCommand.cs deleted file mode 100644 index 830ba7fb5..000000000 --- a/NzbDrone.Common/Messaging/Tracking/TrackedCommandCleanupCommand.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace NzbDrone.Common.Messaging.Tracking -{ - public class TrackedCommandCleanupCommand : ICommand - { - public string CommandId { get; private set; } - - public TrackedCommandCleanupCommand() - { - CommandId = HashUtil.GenerateCommandId(); - } - } -} diff --git a/NzbDrone.Common/NzbDrone.Common.csproj b/NzbDrone.Common/NzbDrone.Common.csproj index 6a4006315..d55670a61 100644 --- a/NzbDrone.Common/NzbDrone.Common.csproj +++ b/NzbDrone.Common/NzbDrone.Common.csproj @@ -92,16 +92,11 @@ + - - - - - - - - + + @@ -109,20 +104,8 @@ - - - - - - - - - - - - @@ -130,9 +113,6 @@ - - - diff --git a/NzbDrone.Core.Test/Framework/DbTest.cs b/NzbDrone.Core.Test/Framework/DbTest.cs index 561283875..84956ef47 100644 --- a/NzbDrone.Core.Test/Framework/DbTest.cs +++ b/NzbDrone.Core.Test/Framework/DbTest.cs @@ -6,9 +6,10 @@ using FluentMigrator.Runner; using Marr.Data; using Moq; using NUnit.Framework; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore.Migration.Framework; +using NzbDrone.Core.Messaging; + namespace NzbDrone.Core.Test.Framework { diff --git a/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs b/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs index 223685cb5..04e208786 100644 --- a/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs +++ b/NzbDrone.Core.Test/MediaFiles/ImportApprovedEpisodesFixture.cs @@ -4,10 +4,10 @@ using FizzWare.NBuilder; using FluentAssertions; using Moq; using NUnit.Framework; -using NzbDrone.Common.Messaging; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles.EpisodeImport; using NzbDrone.Core.MediaFiles.Events; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Qualities; using NzbDrone.Core.Test.Framework; diff --git a/NzbDrone.Core.Test/MediaFiles/RenameEpisodeFileServiceFixture.cs b/NzbDrone.Core.Test/MediaFiles/RenameEpisodeFileServiceFixture.cs index 341b2e957..ce6b51692 100644 --- a/NzbDrone.Core.Test/MediaFiles/RenameEpisodeFileServiceFixture.cs +++ b/NzbDrone.Core.Test/MediaFiles/RenameEpisodeFileServiceFixture.cs @@ -3,11 +3,11 @@ using System.Linq; using FizzWare.NBuilder; using Moq; using NUnit.Framework; -using NzbDrone.Common.Messaging; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Tv; namespace NzbDrone.Core.Test.MediaFiles diff --git a/NzbDrone.Core.Test/TvTests/RefreshEpisodeServiceFixture.cs b/NzbDrone.Core.Test/TvTests/RefreshEpisodeServiceFixture.cs index 428568e8d18d450e3166b1b8a97e468fd88727a6..a88d832eac9103b30f7371e042f752c0b2409914 100644 GIT binary patch delta 255 zcmdn3_snF1HFt1jaY<^fo=;|8;YOn=e3mJxIjJS7@hPPRIho0cC8;U#sRfzE`6;Qz z@kxorKyH3sd~s@GF_3~v#OIafCZ!fl-pC|vQ>r;GS9n<7sH>1!rd# zXqam1g(PODY8V0Oe4otXlF1)goF>N$+Uue!4$aHV&(pv#6sBtux5#7zL4nB<9FHeE ga7s?@=Z>44&&MZ>slj@(BD45pJ|5-G$M{M)02U8iJpcdz delta 15 WcmaE6vRiM0^+x}0zRe#6OE~~Jzy_KC diff --git a/NzbDrone.Core.Test/UpdateTests/UpdatePackageProviderFixture.cs b/NzbDrone.Core.Test/UpdateTests/UpdatePackageProviderFixture.cs index 138e3b404..3176da8eb 100644 --- a/NzbDrone.Core.Test/UpdateTests/UpdatePackageProviderFixture.cs +++ b/NzbDrone.Core.Test/UpdateTests/UpdatePackageProviderFixture.cs @@ -1,22 +1,26 @@ +using System; using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.Configuration; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Update; -using System.Linq; namespace NzbDrone.Core.Test.UpdateTests { public class UpdatePackageProviderFixture : CoreTest { [Test] - public void should_get_list_of_available_updates() + public void no_update_when_version_higher() { UseRealHttp(); + Subject.GetLatestUpdate("master", new Version(10,0)).Should().BeNull(); + } - Mocker.GetMock().SetupGet(c => c.Branch).Returns("master"); - - Subject.GetLatestUpdate().Should().BeNull(); + [Test] + public void finds_update_when_version_lower() + { + UseRealHttp(); + Subject.GetLatestUpdate("master", new Version(1, 0)).Should().NotBeNull(); } } } diff --git a/NzbDrone.Core/Configuration/ConfigFileProvider.cs b/NzbDrone.Core/Configuration/ConfigFileProvider.cs index 15c45ac5a..0676891cf 100644 --- a/NzbDrone.Core/Configuration/ConfigFileProvider.cs +++ b/NzbDrone.Core/Configuration/ConfigFileProvider.cs @@ -7,9 +7,10 @@ using System.Xml.Linq; using NzbDrone.Common; using NzbDrone.Common.Cache; using NzbDrone.Common.EnvironmentInfo; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Configuration.Events; using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Messaging; + namespace NzbDrone.Core.Configuration { diff --git a/NzbDrone.Core/Configuration/ConfigRepository.cs b/NzbDrone.Core/Configuration/ConfigRepository.cs index b0665445e..57307453c 100644 --- a/NzbDrone.Core/Configuration/ConfigRepository.cs +++ b/NzbDrone.Core/Configuration/ConfigRepository.cs @@ -1,6 +1,7 @@ using System.Linq; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Messaging; + namespace NzbDrone.Core.Configuration { diff --git a/NzbDrone.Core/Configuration/ConfigService.cs b/NzbDrone.Core/Configuration/ConfigService.cs index e3ca0317b..9c09e7827 100644 --- a/NzbDrone.Core/Configuration/ConfigService.cs +++ b/NzbDrone.Core/Configuration/ConfigService.cs @@ -2,11 +2,12 @@ using System.Collections.Generic; using System.Linq; using NLog; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Configuration.Events; using NzbDrone.Core.Download; using NzbDrone.Core.Download.Clients.Nzbget; using NzbDrone.Core.Download.Clients.Sabnzbd; +using NzbDrone.Core.Messaging; + namespace NzbDrone.Core.Configuration { diff --git a/NzbDrone.Core/Configuration/Events/ConfigFileSavedEvent.cs b/NzbDrone.Core/Configuration/Events/ConfigFileSavedEvent.cs index 55b245855..6dc4ad63c 100644 --- a/NzbDrone.Core/Configuration/Events/ConfigFileSavedEvent.cs +++ b/NzbDrone.Core/Configuration/Events/ConfigFileSavedEvent.cs @@ -1,4 +1,5 @@ using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Configuration.Events { diff --git a/NzbDrone.Core/Configuration/Events/ConfigSavedEvent.cs b/NzbDrone.Core/Configuration/Events/ConfigSavedEvent.cs index 3700833e4..3220e8023 100644 --- a/NzbDrone.Core/Configuration/Events/ConfigSavedEvent.cs +++ b/NzbDrone.Core/Configuration/Events/ConfigSavedEvent.cs @@ -1,4 +1,5 @@ using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Configuration.Events { diff --git a/NzbDrone.Core/DataAugmentation/Scene/SceneMappingRepository.cs b/NzbDrone.Core/DataAugmentation/Scene/SceneMappingRepository.cs index 417b6cf11..20226a4d8 100644 --- a/NzbDrone.Core/DataAugmentation/Scene/SceneMappingRepository.cs +++ b/NzbDrone.Core/DataAugmentation/Scene/SceneMappingRepository.cs @@ -1,5 +1,6 @@ -using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Messaging; + namespace NzbDrone.Core.DataAugmentation.Scene { diff --git a/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs b/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs index e857f5373..ce5e4a9cd 100644 --- a/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs +++ b/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs @@ -2,8 +2,8 @@ using System; using System.Linq; using NLog; using NzbDrone.Common.Cache; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Parser; namespace NzbDrone.Core.DataAugmentation.Scene diff --git a/NzbDrone.Core/DataAugmentation/Scene/UpdateSceneMappingCommand.cs b/NzbDrone.Core/DataAugmentation/Scene/UpdateSceneMappingCommand.cs index 8b886d009..7baf42311 100644 --- a/NzbDrone.Core/DataAugmentation/Scene/UpdateSceneMappingCommand.cs +++ b/NzbDrone.Core/DataAugmentation/Scene/UpdateSceneMappingCommand.cs @@ -1,16 +1,12 @@ using System; using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.DataAugmentation.Scene { - public class UpdateSceneMappingCommand : ICommand + public class UpdateSceneMappingCommand : Command { - public String CommandId { get; private set; } - public UpdateSceneMappingCommand() - { - CommandId = HashUtil.GenerateCommandId(); - } } } \ No newline at end of file diff --git a/NzbDrone.Core/Datastore/BasicRepository.cs b/NzbDrone.Core/Datastore/BasicRepository.cs index daefd7eac..10d081b23 100644 --- a/NzbDrone.Core/Datastore/BasicRepository.cs +++ b/NzbDrone.Core/Datastore/BasicRepository.cs @@ -4,9 +4,9 @@ using System.Linq; using System.Linq.Expressions; using Marr.Data; using Marr.Data.QGen; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore.Events; using NzbDrone.Common; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Datastore @@ -115,7 +115,6 @@ namespace NzbDrone.Core.Datastore } DataMapper.Insert(model); - PublishModelEvent(model, RepositoryAction.Created); return model; } @@ -222,7 +221,22 @@ namespace NzbDrone.Core.Datastore DataMapper.Delete(c => c.Id > 0); } - private void PublishModelEvent(TModel model, RepositoryAction action) + protected void ModelCreated(TModel model) + { + PublishModelEvent(model, ModelAction.Created); + } + + protected void ModelUpdated(TModel model) + { + PublishModelEvent(model, ModelAction.Updated); + } + + protected void ModelDeleted(TModel model) + { + PublishModelEvent(model, ModelAction.Deleted); + } + + private void PublishModelEvent(TModel model, ModelAction action) { if (PublishModelEvents) { @@ -230,16 +244,6 @@ namespace NzbDrone.Core.Datastore } } - protected virtual void OnModelChanged(IEnumerable models) - { - - } - - protected virtual void OnModelDeleted(IEnumerable models) - { - - } - protected virtual bool PublishModelEvents { get { return false; } diff --git a/NzbDrone.Core/Datastore/CachedBasicRepository.cs b/NzbDrone.Core/Datastore/CachedBasicRepository.cs deleted file mode 100644 index 1938af390..000000000 --- a/NzbDrone.Core/Datastore/CachedBasicRepository.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Collections.Generic; -using NzbDrone.Common.Cache; -using NzbDrone.Common.Messaging; - -namespace NzbDrone.Core.Datastore -{ - public abstract class CachedBasicRepository : BasicRepository where TModel : ModelBase, new() - { - private readonly ICacheManger _cacheManger; - - protected CachedBasicRepository(IDatabase database, IMessageAggregator messageAggregator) - : base(database, messageAggregator) - { - _cacheManger = new CacheManger(); - } - - protected ICached GetCache(string name) - { - return _cacheManger.GetCache(GetType(), name); - } - - protected override void OnModelChanged(IEnumerable models) - { - PurgeCache(); - } - - protected override void OnModelDeleted(IEnumerable models) - { - PurgeCache(); - } - - private void PurgeCache() - { - foreach (var model in _cacheManger.Caches) - { - model.Clear(); - } - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Datastore/DbFactory.cs b/NzbDrone.Core/Datastore/DbFactory.cs index 48fe63bbf..0c8267f9b 100644 --- a/NzbDrone.Core/Datastore/DbFactory.cs +++ b/NzbDrone.Core/Datastore/DbFactory.cs @@ -3,9 +3,9 @@ using System.Data.SQLite; using Marr.Data; using Marr.Data.Reflection; using NzbDrone.Common.Composition; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore.Migration.Framework; using NzbDrone.Core.Instrumentation; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Datastore diff --git a/NzbDrone.Core/Datastore/Events/ModelEvent.cs b/NzbDrone.Core/Datastore/Events/ModelEvent.cs index 30b9af580..3cabd3a69 100644 --- a/NzbDrone.Core/Datastore/Events/ModelEvent.cs +++ b/NzbDrone.Core/Datastore/Events/ModelEvent.cs @@ -2,23 +2,25 @@ namespace NzbDrone.Core.Datastore.Events { - public class ModelEvent : IEvent where T : ModelBase + public class ModelEvent : IEvent { - public T Model { get; set; } - public RepositoryAction Action { get; set; } + public TModel Model { get; set; } + public ModelAction Action { get; set; } - public ModelEvent(T model, RepositoryAction action) + public ModelEvent(TModel model, ModelAction action) { Model = model; Action = action; } } - public enum RepositoryAction + public enum ModelAction { + Unknow = 0, Created = 1, Updated = 2, - Deleted = 3 + Deleted = 3, + Sync = 4 } diff --git a/NzbDrone.Core/Datastore/Migration/Framework/SQLiteMigrationHelper (vaio's conflicted copy 2013-09-04).cs b/NzbDrone.Core/Datastore/Migration/Framework/SQLiteMigrationHelper (vaio's conflicted copy 2013-09-04).cs new file mode 100644 index 000000000..0cbf55e4c --- /dev/null +++ b/NzbDrone.Core/Datastore/Migration/Framework/SQLiteMigrationHelper (vaio's conflicted copy 2013-09-04).cs @@ -0,0 +1,241 @@ +using System; +using System.Collections.Generic; +using System.Data.SQLite; +using System.Linq; +using System.Text.RegularExpressions; +using NLog; + +namespace NzbDrone.Core.Datastore.Migration.Framework +{ + public interface ISQLiteMigrationHelper + { + Dictionary GetColumns(string tableName); + void CreateTable(string tableName, IEnumerable values, IEnumerable indexes); + void CopyData(string sourceTable, string destinationTable, IEnumerable columns); + void DropTable(string tableName); + void RenameTable(string tableName, string newName); + List GetDuplicates(string tableName, string columnName); + SQLiteTransaction BeginTransaction(); + List GetIndexes(string tableName); + } + + public class SQLiteMigrationHelper : ISQLiteMigrationHelper + { + private readonly SQLiteConnection _connection; + + private static readonly Regex SchemaRegex = new Regex(@"['\""\[](?\w+)['\""\]]\s(?[\w-\s]+)", + RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Multiline); + + private static readonly Regex IndexRegex = new Regex(@"\(""(?.*)""\s(?ASC|DESC)\)$", + RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Multiline); + + public SQLiteMigrationHelper(IConnectionStringFactory connectionStringFactory, Logger logger) + { + try + { + _connection = new SQLiteConnection(connectionStringFactory.MainDbConnectionString); + _connection.Open(); + } + catch (Exception e) + { + logger.ErrorException("Couldn't open database " + connectionStringFactory.MainDbConnectionString, e); + throw; + } + + } + + private string GetOriginalSql(string tableName) + { + var command = + new SQLiteCommand(string.Format("SELECT sql FROM sqlite_master WHERE type='table' AND name ='{0}'", + tableName)); + + command.Connection = _connection; + + return (string)command.ExecuteScalar(); + } + + public Dictionary GetColumns(string tableName) + { + var originalSql = GetOriginalSql(tableName); + + var matches = SchemaRegex.Matches(originalSql); + + return matches.Cast().ToDictionary( + match => match.Groups["name"].Value.Trim(), + match => new SQLiteColumn + { + Name = match.Groups["name"].Value.Trim(), + Schema = match.Groups["schema"].Value.Trim() + }); + } + + + private static IEnumerable ReadArray(SQLiteDataReader reader) + { + while (reader.Read()) + { + yield return (T)Convert.ChangeType(reader[0], typeof(T)); + } + } + + public List GetIndexes(string tableName) + { + var command = new SQLiteCommand(string.Format("SELECT sql FROM sqlite_master WHERE type='index' AND tbl_name ='{0}'", tableName)); + command.Connection = _connection; + + var reader = command.ExecuteReader(); + var sqls = ReadArray(reader).ToList(); + + + var indexes = new List(); + + foreach (var indexSql in sqls) + { + var newIndex = new SQLiteIndex(); + var matches = IndexRegex.Match(indexSql); + + newIndex.Column = matches.Groups["col"].Value; + newIndex.Unique = indexSql.Contains("UNIQUE"); + newIndex.Table = tableName; + + indexes.Add(newIndex); + } + + return indexes; + } + + public void CreateTable(string tableName, IEnumerable values, IEnumerable indexes) + { + var columns = String.Join(",", values.Select(c => c.ToString())); + + ExecuteNonQuery("CREATE TABLE [{0}] ({1})", tableName, columns); + + foreach (var index in indexes) + { + ExecuteNonQuery("DROP INDEX {0}", index.IndexName); + ExecuteNonQuery(index.CreateSql(tableName)); + } + } + + public void CopyData(string sourceTable, string destinationTable, IEnumerable columns) + { + var originalCount = GetRowCount(sourceTable); + + var columnsToTransfer = String.Join(",", columns.Select(c => c.Name)); + + var transferCommand = BuildCommand("INSERT INTO {0} SELECT {1} FROM {2};", destinationTable, columnsToTransfer, sourceTable); + + transferCommand.ExecuteNonQuery(); + + var transferredRows = GetRowCount(destinationTable); + + + if (transferredRows != originalCount) + { + throw new ApplicationException(string.Format("Expected {0} rows to be copied from [{1}] to [{2}]. But only copied {3}", originalCount, sourceTable, destinationTable, transferredRows)); + } + } + + + public void DropTable(string tableName) + { + var dropCommand = BuildCommand("DROP TABLE {0};", tableName); + dropCommand.ExecuteNonQuery(); + } + + + public void RenameTable(string tableName, string newName) + { + var renameCommand = BuildCommand("ALTER TABLE {0} RENAME TO {1};", tableName, newName); + renameCommand.ExecuteNonQuery(); + } + + public Dictionary GetDuplicates(string tableName, string columnName) + { + var dupCommand = BuildCommand("select id, {0} from {1}", columnName, tableName); + + var result = new Dictionary(); + using (var reader = dupCommand.ExecuteReader()) + { + while (reader.Read()) + { + + } + } + + + return ReadArray().ToList(); + } + + public int GetRowCount(string tableName) + { + var countCommand = BuildCommand("SELECT COUNT(*) FROM {0};", tableName); + return Convert.ToInt32(countCommand.ExecuteScalar()); + } + + + public SQLiteTransaction BeginTransaction() + { + return _connection.BeginTransaction(); + } + + private SQLiteCommand BuildCommand(string format, params string[] args) + { + var command = new SQLiteCommand(string.Format(format, args)); + command.Connection = _connection; + return command; + } + + + + private void ExecuteNonQuery(string command, params string[] args) + { + var sqLiteCommand = new SQLiteCommand(string.Format(command, args)) + { + Connection = _connection + }; + + sqLiteCommand.ExecuteNonQuery(); + } + + + public class SQLiteColumn + { + public string Name { get; set; } + public string Schema { get; set; } + + public override string ToString() + { + return string.Format("[{0}] {1}", Name, Schema); + } + } + + public class SQLiteIndex + { + public string Column { get; set; } + public string Table { get; set; } + public bool Unique { get; set; } + + public override string ToString() + { + return string.Format("[{0}] Unique: {1}", Column, Unique); + } + + public string IndexName + { + get + { + return string.Format("IX_{0}_{1}", Table, Column); + } + } + + public string CreateSql(string tableName) + { + return string.Format(@"CREATE UNIQUE INDEX ""{2}"" ON ""{0}"" (""{1}"" ASC)", tableName, Column, IndexName); + } + } + } + + +} \ No newline at end of file diff --git a/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs b/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs index 8cad64704..f627a36c0 100644 --- a/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs +++ b/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs @@ -2,9 +2,8 @@ using System; using System.Collections.Generic; using System.Linq; using NLog; -using NzbDrone.Common.Instrumentation; -using NzbDrone.Core.DecisionEngine.Specifications.Search; using NzbDrone.Core.IndexerSearch.Definitions; +using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; using NzbDrone.Common.Serializer; @@ -44,12 +43,12 @@ namespace NzbDrone.Core.DecisionEngine { if (reports.Any()) { - _logger.Progress("Processing {0} reports", reports.Count); + _logger.ProgressInfo("Processing {0} reports", reports.Count); } else { - _logger.Progress("No reports found"); + _logger.ProgressInfo("No reports found"); } var reportNumber = 1; @@ -57,7 +56,7 @@ namespace NzbDrone.Core.DecisionEngine foreach (var report in reports) { DownloadDecision decision = null; - _logger.Progress("Processing report {0}/{1}", reportNumber, reports.Count); + _logger.ProgressTrace("Processing report {0}/{1}", reportNumber, reports.Count); try { diff --git a/NzbDrone.Core/Download/DownloadService.cs b/NzbDrone.Core/Download/DownloadService.cs index 2c3d15f5c..09186fc29 100644 --- a/NzbDrone.Core/Download/DownloadService.cs +++ b/NzbDrone.Core/Download/DownloadService.cs @@ -1,6 +1,7 @@ using NLog; using NzbDrone.Common.Instrumentation; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Instrumentation; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Parser.Model; namespace NzbDrone.Core.Download @@ -38,7 +39,7 @@ namespace NzbDrone.Core.Download downloadClient.DownloadNzb(remoteEpisode); - _logger.Progress("Report sent to download client. {0}", downloadTitle); + _logger.ProgressInfo("Report sent to download client. {0}", downloadTitle); _messageAggregator.PublishEvent(new EpisodeGrabbedEvent(remoteEpisode)); } } diff --git a/NzbDrone.Core/Download/EpisodeGrabbedEvent.cs b/NzbDrone.Core/Download/EpisodeGrabbedEvent.cs index cd6fc46cc..e55e163c5 100644 --- a/NzbDrone.Core/Download/EpisodeGrabbedEvent.cs +++ b/NzbDrone.Core/Download/EpisodeGrabbedEvent.cs @@ -1,4 +1,5 @@ using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Parser.Model; namespace NzbDrone.Core.Download diff --git a/NzbDrone.Core/History/HistoryRepository.cs b/NzbDrone.Core/History/HistoryRepository.cs index ca436d153..178b68c4c 100644 --- a/NzbDrone.Core/History/HistoryRepository.cs +++ b/NzbDrone.Core/History/HistoryRepository.cs @@ -2,8 +2,8 @@ using System.Collections.Generic; using System.Linq; using Marr.Data.QGen; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Tv; namespace NzbDrone.Core.History diff --git a/NzbDrone.Core/History/HistoryService.cs b/NzbDrone.Core/History/HistoryService.cs index c0752eb2a..5c7c9df2a 100644 --- a/NzbDrone.Core/History/HistoryService.cs +++ b/NzbDrone.Core/History/HistoryService.cs @@ -3,10 +3,10 @@ using System.Collections.Generic; using System.IO; using System.Linq; using NLog; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; using NzbDrone.Core.Download; using NzbDrone.Core.MediaFiles.Events; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Tv; namespace NzbDrone.Core.History diff --git a/NzbDrone.Core/IndexerSearch/EpisodeSearchCommand.cs b/NzbDrone.Core/IndexerSearch/EpisodeSearchCommand.cs index 720955178..d3173ec28 100644 --- a/NzbDrone.Core/IndexerSearch/EpisodeSearchCommand.cs +++ b/NzbDrone.Core/IndexerSearch/EpisodeSearchCommand.cs @@ -1,17 +1,18 @@ -using System; -using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.IndexerSearch { - public class EpisodeSearchCommand : ICommand + public class EpisodeSearchCommand : Command { - public String CommandId { get; private set; } public int EpisodeId { get; set; } - - public EpisodeSearchCommand() + + public override bool SendUpdatesToClient { - CommandId = HashUtil.GenerateCommandId(); + get + { + return true; + } } } } \ No newline at end of file diff --git a/NzbDrone.Core/IndexerSearch/EpisodeSearchService.cs b/NzbDrone.Core/IndexerSearch/EpisodeSearchService.cs index 476178f36..c016e2082 100644 --- a/NzbDrone.Core/IndexerSearch/EpisodeSearchService.cs +++ b/NzbDrone.Core/IndexerSearch/EpisodeSearchService.cs @@ -1,8 +1,9 @@ using System.Linq; using NLog; using NzbDrone.Common.Instrumentation; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Download; +using NzbDrone.Core.Instrumentation; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.IndexerSearch { @@ -26,7 +27,7 @@ namespace NzbDrone.Core.IndexerSearch var decisions = _nzbSearchService.EpisodeSearch(message.EpisodeId); var downloaded = _downloadApprovedReports.DownloadApproved(decisions); - _logger.Complete("Episode search completed. {0} reports downloaded.", downloaded.Count); + _logger.ProgressInfo("Episode search completed. {0} reports downloaded.", downloaded.Count); } } } diff --git a/NzbDrone.Core/IndexerSearch/NzbSearchService.cs b/NzbDrone.Core/IndexerSearch/NzbSearchService.cs index b17d9ea55..0aceb55a8 100644 --- a/NzbDrone.Core/IndexerSearch/NzbSearchService.cs +++ b/NzbDrone.Core/IndexerSearch/NzbSearchService.cs @@ -8,6 +8,7 @@ using NzbDrone.Core.DataAugmentation.Scene; using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.IndexerSearch.Definitions; using NzbDrone.Core.Indexers; +using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Tv; using System.Linq; @@ -131,7 +132,7 @@ namespace NzbDrone.Core.IndexerSearch { var indexers = _indexerService.GetAvailableIndexers().ToList(); - _logger.Progress("Searching {0} indexers for {1}", indexers.Count, criteriaBase); + _logger.ProgressInfo("Searching {0} indexers for {1}", indexers.Count, criteriaBase); var reports = new List(); var taskList = new List(); diff --git a/NzbDrone.Core/IndexerSearch/SeasonSearchCommand.cs b/NzbDrone.Core/IndexerSearch/SeasonSearchCommand.cs index 749fefae9..8f5c82fdd 100644 --- a/NzbDrone.Core/IndexerSearch/SeasonSearchCommand.cs +++ b/NzbDrone.Core/IndexerSearch/SeasonSearchCommand.cs @@ -1,18 +1,21 @@ using System; using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.IndexerSearch { - public class SeasonSearchCommand : ICommand + public class SeasonSearchCommand : Command { - public String CommandId { get; private set; } public int SeriesId { get; set; } public int SeasonNumber { get; set; } - public SeasonSearchCommand() + public override bool SendUpdatesToClient { - CommandId = HashUtil.GenerateCommandId(); + get + { + return true; + } } } } \ No newline at end of file diff --git a/NzbDrone.Core/IndexerSearch/SeasonSearchService.cs b/NzbDrone.Core/IndexerSearch/SeasonSearchService.cs index f1a7a1e71..a464f2984 100644 --- a/NzbDrone.Core/IndexerSearch/SeasonSearchService.cs +++ b/NzbDrone.Core/IndexerSearch/SeasonSearchService.cs @@ -1,7 +1,8 @@ using NLog; using NzbDrone.Common.Instrumentation; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Download; +using NzbDrone.Core.Instrumentation; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.IndexerSearch { @@ -25,7 +26,7 @@ namespace NzbDrone.Core.IndexerSearch var decisions = _nzbSearchService.SeasonSearch(message.SeriesId, message.SeasonNumber); var downloaded = _downloadApprovedReports.DownloadApproved(decisions); - _logger.Complete("Season search completed. {0} reports downloaded.", downloaded.Count); + _logger.ProgressInfo("Season search completed. {0} reports downloaded.", downloaded.Count); } } } diff --git a/NzbDrone.Core/IndexerSearch/SeriesSearchCommand.cs b/NzbDrone.Core/IndexerSearch/SeriesSearchCommand.cs index 8a8de6184..da918d19a 100644 --- a/NzbDrone.Core/IndexerSearch/SeriesSearchCommand.cs +++ b/NzbDrone.Core/IndexerSearch/SeriesSearchCommand.cs @@ -1,17 +1,20 @@ using System; using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.IndexerSearch { - public class SeriesSearchCommand : ICommand + public class SeriesSearchCommand : Command { - public String CommandId { get; private set; } public int SeriesId { get; set; } - public SeriesSearchCommand() + public override bool SendUpdatesToClient { - CommandId = HashUtil.GenerateCommandId(); + get + { + return true; + } } } } \ No newline at end of file diff --git a/NzbDrone.Core/IndexerSearch/SeriesSearchService.cs b/NzbDrone.Core/IndexerSearch/SeriesSearchService.cs index 14da8c84d..deb0c6247 100644 --- a/NzbDrone.Core/IndexerSearch/SeriesSearchService.cs +++ b/NzbDrone.Core/IndexerSearch/SeriesSearchService.cs @@ -1,8 +1,9 @@ using System.Linq; using NLog; using NzbDrone.Common.Instrumentation; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Download; +using NzbDrone.Core.Instrumentation; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Tv; namespace NzbDrone.Core.IndexerSearch @@ -40,7 +41,7 @@ namespace NzbDrone.Core.IndexerSearch downloadedCount += _downloadApprovedReports.DownloadApproved(decisions).Count; } - _logger.Complete("Series search completed. {0} reports downloaded.", downloadedCount); + _logger.ProgressInfo("Series search completed. {0} reports downloaded.", downloadedCount); } } } diff --git a/NzbDrone.Core/Indexers/IndexerRepository.cs b/NzbDrone.Core/Indexers/IndexerRepository.cs index 678c26fd6..82c0c1ba1 100644 --- a/NzbDrone.Core/Indexers/IndexerRepository.cs +++ b/NzbDrone.Core/Indexers/IndexerRepository.cs @@ -1,7 +1,8 @@ using System; using System.Linq; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Messaging; + namespace NzbDrone.Core.Indexers { diff --git a/NzbDrone.Core/Indexers/IndexerService.cs b/NzbDrone.Core/Indexers/IndexerService.cs index 168835ffa..aad4bf889 100644 --- a/NzbDrone.Core/Indexers/IndexerService.cs +++ b/NzbDrone.Core/Indexers/IndexerService.cs @@ -2,10 +2,10 @@ using System.Collections.Generic; using System.Linq; using NLog; -using NzbDrone.Common.Messaging; using NzbDrone.Common.Serializer; using NzbDrone.Core.Indexers.Newznab; using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Messaging; using Omu.ValueInjecter; namespace NzbDrone.Core.Indexers diff --git a/NzbDrone.Core/Indexers/IndexerSettingUpdatedEvent.cs b/NzbDrone.Core/Indexers/IndexerSettingUpdatedEvent.cs index 8b3edc513..7508f989d 100644 --- a/NzbDrone.Core/Indexers/IndexerSettingUpdatedEvent.cs +++ b/NzbDrone.Core/Indexers/IndexerSettingUpdatedEvent.cs @@ -1,4 +1,5 @@ using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Indexers { diff --git a/NzbDrone.Core/Indexers/RssSyncCommand.cs b/NzbDrone.Core/Indexers/RssSyncCommand.cs index 0d073c977..b435905a1 100644 --- a/NzbDrone.Core/Indexers/RssSyncCommand.cs +++ b/NzbDrone.Core/Indexers/RssSyncCommand.cs @@ -1,16 +1,20 @@ using System; using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Indexers { - public class RssSyncCommand : ICommand + public class RssSyncCommand : Command { - public String CommandId { get; private set; } - public RssSyncCommand() + public override bool SendUpdatesToClient { - CommandId = HashUtil.GenerateCommandId(); + get + { + return true; + } } + } } \ No newline at end of file diff --git a/NzbDrone.Core/Indexers/RssSyncService.cs b/NzbDrone.Core/Indexers/RssSyncService.cs index 3362bcc56..14335929b 100644 --- a/NzbDrone.Core/Indexers/RssSyncService.cs +++ b/NzbDrone.Core/Indexers/RssSyncService.cs @@ -1,9 +1,10 @@ using System.Linq; using NLog; using NzbDrone.Common.Instrumentation; -using NzbDrone.Common.Messaging; using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.Download; +using NzbDrone.Core.Instrumentation; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Indexers { @@ -33,13 +34,13 @@ namespace NzbDrone.Core.Indexers public void Sync() { - _logger.Progress("Starting RSS Sync"); + _logger.ProgressInfo("Starting RSS Sync"); var reports = _rssFetcherAndParser.Fetch(); var decisions = _downloadDecisionMaker.GetRssDecision(reports); var downloaded = _downloadApprovedReports.DownloadApproved(decisions); - _logger.Complete("RSS Sync Completed. Reports found: {0}, Reports downloaded: {1}", reports.Count, downloaded.Count()); + _logger.ProgressInfo("RSS Sync Completed. Reports found: {0}, Reports downloaded: {1}", reports.Count, downloaded.Count()); } public void Execute(RssSyncCommand message) diff --git a/NzbDrone.Core/Instrumentation/Commands/ClearLogCommand.cs b/NzbDrone.Core/Instrumentation/Commands/ClearLogCommand.cs index cabaffcb5..3d7db50f1 100644 --- a/NzbDrone.Core/Instrumentation/Commands/ClearLogCommand.cs +++ b/NzbDrone.Core/Instrumentation/Commands/ClearLogCommand.cs @@ -1,16 +1,18 @@ using System; using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Instrumentation.Commands { - public class ClearLogCommand : ICommand + public class ClearLogCommand : Command { - public String CommandId { get; private set; } - - public ClearLogCommand() + public override bool SendUpdatesToClient { - CommandId = HashUtil.GenerateCommandId(); + get + { + return true; + } } } } \ No newline at end of file diff --git a/NzbDrone.Core/Instrumentation/Commands/DeleteLogFilesCommand.cs b/NzbDrone.Core/Instrumentation/Commands/DeleteLogFilesCommand.cs index 8ae4d03d1..101e3eeb1 100644 --- a/NzbDrone.Core/Instrumentation/Commands/DeleteLogFilesCommand.cs +++ b/NzbDrone.Core/Instrumentation/Commands/DeleteLogFilesCommand.cs @@ -1,16 +1,18 @@ using System; using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Instrumentation.Commands { - public class DeleteLogFilesCommand : ICommand + public class DeleteLogFilesCommand : Command { - public String CommandId { get; private set; } - - public DeleteLogFilesCommand() + public override bool SendUpdatesToClient { - CommandId = HashUtil.GenerateCommandId(); + get + { + return true; + } } } } \ No newline at end of file diff --git a/NzbDrone.Core/Instrumentation/Commands/TrimLogCommand.cs b/NzbDrone.Core/Instrumentation/Commands/TrimLogCommand.cs index 7e710f294..c50d8e5bf 100644 --- a/NzbDrone.Core/Instrumentation/Commands/TrimLogCommand.cs +++ b/NzbDrone.Core/Instrumentation/Commands/TrimLogCommand.cs @@ -1,16 +1,11 @@ using System; using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Instrumentation.Commands { - public class TrimLogCommand : ICommand + public class TrimLogCommand : Command { - public String CommandId { get; private set; } - - public TrimLogCommand() - { - CommandId = HashUtil.GenerateCommandId(); - } } } \ No newline at end of file diff --git a/NzbDrone.Core/Instrumentation/DatabaseTarget.cs b/NzbDrone.Core/Instrumentation/DatabaseTarget.cs index 779643240..c6ee66ffc 100644 --- a/NzbDrone.Core/Instrumentation/DatabaseTarget.cs +++ b/NzbDrone.Core/Instrumentation/DatabaseTarget.cs @@ -3,8 +3,8 @@ using NLog.Config; using NLog; using NLog.Layouts; using NLog.Targets; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Instrumentation { diff --git a/NzbDrone.Core/Instrumentation/DeleteLogFilesService.cs b/NzbDrone.Core/Instrumentation/DeleteLogFilesService.cs index 5c98646ad..46c8f1572 100644 --- a/NzbDrone.Core/Instrumentation/DeleteLogFilesService.cs +++ b/NzbDrone.Core/Instrumentation/DeleteLogFilesService.cs @@ -5,8 +5,8 @@ using System.Linq; using NLog; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Instrumentation.Commands; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Instrumentation { diff --git a/NzbDrone.Core/Instrumentation/LogRepository.cs b/NzbDrone.Core/Instrumentation/LogRepository.cs index 0a00aa27b..631133bc8 100644 --- a/NzbDrone.Core/Instrumentation/LogRepository.cs +++ b/NzbDrone.Core/Instrumentation/LogRepository.cs @@ -1,6 +1,7 @@ using System; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Messaging; + namespace NzbDrone.Core.Instrumentation { diff --git a/NzbDrone.Core/Instrumentation/LogService.cs b/NzbDrone.Core/Instrumentation/LogService.cs index 5e5717571..29582722d 100644 --- a/NzbDrone.Core/Instrumentation/LogService.cs +++ b/NzbDrone.Core/Instrumentation/LogService.cs @@ -1,7 +1,7 @@ using System; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; using NzbDrone.Core.Instrumentation.Commands; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Instrumentation { diff --git a/NzbDrone.Core/Instrumentation/LoggerExtensions.cs b/NzbDrone.Core/Instrumentation/LoggerExtensions.cs new file mode 100644 index 000000000..82ece28d2 --- /dev/null +++ b/NzbDrone.Core/Instrumentation/LoggerExtensions.cs @@ -0,0 +1,34 @@ +using System; +using NLog; + +namespace NzbDrone.Core.Instrumentation +{ + public static class LoggerExtensions + { + public static void ProgressInfo(this Logger logger, string message, params object[] args) + { + var formattedMessage = String.Format(message, args); + LogProgressMessage(logger, LogLevel.Info, formattedMessage); + } + + public static void ProgressDebug(this Logger logger, string message, params object[] args) + { + var formattedMessage = String.Format(message, args); + LogProgressMessage(logger, LogLevel.Debug, formattedMessage); + } + + public static void ProgressTrace(this Logger logger, string message, params object[] args) + { + var formattedMessage = String.Format(message, args); + LogProgressMessage(logger, LogLevel.Trace, formattedMessage); + } + + private static void LogProgressMessage(Logger logger, LogLevel level, string message) + { + var logEvent = new LogEventInfo(level, logger.Name, message); + logEvent.Properties.Add("Status", ""); + + logger.Log(logEvent); + } + } +} diff --git a/NzbDrone.Core/Instrumentation/SetLoggingLevel.cs b/NzbDrone.Core/Instrumentation/SetLoggingLevel.cs index 1792a8b3c..0ce6f1358 100644 --- a/NzbDrone.Core/Instrumentation/SetLoggingLevel.cs +++ b/NzbDrone.Core/Instrumentation/SetLoggingLevel.cs @@ -3,10 +3,10 @@ using System.Linq; using NLog; using NLog.Config; using NLog.Targets; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration.Events; using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Instrumentation { diff --git a/NzbDrone.Core/Jobs/JobRepository.cs b/NzbDrone.Core/Jobs/JobRepository.cs index 700b8674e..baf6b8d04 100644 --- a/NzbDrone.Core/Jobs/JobRepository.cs +++ b/NzbDrone.Core/Jobs/JobRepository.cs @@ -1,7 +1,8 @@ using System; using System.Linq; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Messaging; + namespace NzbDrone.Core.Jobs { diff --git a/NzbDrone.Core/Jobs/Scheduler.cs b/NzbDrone.Core/Jobs/Scheduler.cs index 20ed73489..f51c05cce 100644 --- a/NzbDrone.Core/Jobs/Scheduler.cs +++ b/NzbDrone.Core/Jobs/Scheduler.cs @@ -2,8 +2,8 @@ using System.Threading; using System.Threading.Tasks; using NLog; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Messaging; using Timer = System.Timers.Timer; using NzbDrone.Common.TPL; diff --git a/NzbDrone.Core/Jobs/TaskManager.cs b/NzbDrone.Core/Jobs/TaskManager.cs index 4dcfdd56c..723eaea25 100644 --- a/NzbDrone.Core/Jobs/TaskManager.cs +++ b/NzbDrone.Core/Jobs/TaskManager.cs @@ -2,15 +2,15 @@ using System; using System.Collections.Generic; using System.Linq; using NLog; -using NzbDrone.Common.Messaging; -using NzbDrone.Common.Messaging.Events; -using NzbDrone.Common.Messaging.Tracking; using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration.Events; using NzbDrone.Core.Indexers; using NzbDrone.Core.Instrumentation.Commands; using NzbDrone.Core.Lifecycle; using NzbDrone.Core.MediaFiles.Commands; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Events; +using NzbDrone.Core.Messaging.Tracking; using NzbDrone.Core.Providers; using NzbDrone.Core.Tv.Commands; using NzbDrone.Core.Update.Commands; @@ -79,7 +79,7 @@ namespace NzbDrone.Core.Jobs public void HandleAsync(CommandExecutedEvent message) { - var scheduledTask = _scheduledTaskRepository.All().SingleOrDefault(c => c.TypeName == message.TrackedCommand.Command.GetType().FullName); + var scheduledTask = _scheduledTaskRepository.All().SingleOrDefault(c => c.TypeName == message.Command.GetType().FullName); if (scheduledTask != null) { diff --git a/NzbDrone.Core/Lifecycle/ApplicationShutdownRequested.cs b/NzbDrone.Core/Lifecycle/ApplicationShutdownRequested.cs index 6c343546e..de5e6af52 100644 --- a/NzbDrone.Core/Lifecycle/ApplicationShutdownRequested.cs +++ b/NzbDrone.Core/Lifecycle/ApplicationShutdownRequested.cs @@ -1,4 +1,5 @@ using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Lifecycle { diff --git a/NzbDrone.Core/Lifecycle/ApplicationStartedEvent.cs b/NzbDrone.Core/Lifecycle/ApplicationStartedEvent.cs index f66622dd3..a2880b498 100644 --- a/NzbDrone.Core/Lifecycle/ApplicationStartedEvent.cs +++ b/NzbDrone.Core/Lifecycle/ApplicationStartedEvent.cs @@ -1,4 +1,5 @@ using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Lifecycle { diff --git a/NzbDrone.Core/MediaCover/MediaCoverService.cs b/NzbDrone.Core/MediaCover/MediaCoverService.cs index e3d247bfa..b10a744a9 100644 --- a/NzbDrone.Core/MediaCover/MediaCoverService.cs +++ b/NzbDrone.Core/MediaCover/MediaCoverService.cs @@ -5,7 +5,7 @@ using System.Net; using NLog; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Tv; using NzbDrone.Core.Tv.Events; diff --git a/NzbDrone.Core/MediaFiles/Commands/BackendCommandAttribute.cs b/NzbDrone.Core/MediaFiles/Commands/BackendCommandAttribute.cs new file mode 100644 index 000000000..7e8347897 --- /dev/null +++ b/NzbDrone.Core/MediaFiles/Commands/BackendCommandAttribute.cs @@ -0,0 +1,8 @@ +using System; + +namespace NzbDrone.Core.MediaFiles.Commands +{ + public class BackendCommandAttribute : Attribute + { + } +} \ No newline at end of file diff --git a/NzbDrone.Core/MediaFiles/Commands/CleanMediaFileDb.cs b/NzbDrone.Core/MediaFiles/Commands/CleanMediaFileDb.cs index 7a195685a..b64eae600 100644 --- a/NzbDrone.Core/MediaFiles/Commands/CleanMediaFileDb.cs +++ b/NzbDrone.Core/MediaFiles/Commands/CleanMediaFileDb.cs @@ -1,22 +1,16 @@ using System; using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.MediaFiles.Commands { - public class CleanMediaFileDb : ICommand + public class CleanMediaFileDb : Command { - public String CommandId { get; private set; } public int SeriesId { get; private set; } - public CleanMediaFileDb() - { - CommandId = HashUtil.GenerateCommandId(); - } - public CleanMediaFileDb(int seriesId) { - CommandId = HashUtil.GenerateCommandId(); SeriesId = seriesId; } } diff --git a/NzbDrone.Core/MediaFiles/Commands/CleanUpRecycleBinCommand.cs b/NzbDrone.Core/MediaFiles/Commands/CleanUpRecycleBinCommand.cs index ef27ad213..574b7af0c 100644 --- a/NzbDrone.Core/MediaFiles/Commands/CleanUpRecycleBinCommand.cs +++ b/NzbDrone.Core/MediaFiles/Commands/CleanUpRecycleBinCommand.cs @@ -1,16 +1,11 @@ using System; using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.MediaFiles.Commands { - public class CleanUpRecycleBinCommand : ICommand + public class CleanUpRecycleBinCommand : Command { - public String CommandId { get; private set; } - - public CleanUpRecycleBinCommand() - { - CommandId = HashUtil.GenerateCommandId(); - } } } \ No newline at end of file diff --git a/NzbDrone.Core/MediaFiles/Commands/DownloadedEpisodesScanCommand.cs b/NzbDrone.Core/MediaFiles/Commands/DownloadedEpisodesScanCommand.cs index a6caf5bee..c9abe533a 100644 --- a/NzbDrone.Core/MediaFiles/Commands/DownloadedEpisodesScanCommand.cs +++ b/NzbDrone.Core/MediaFiles/Commands/DownloadedEpisodesScanCommand.cs @@ -1,16 +1,9 @@ -using System; -using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.MediaFiles.Commands { - public class DownloadedEpisodesScanCommand : ICommand + public class DownloadedEpisodesScanCommand : Command { - public String CommandId { get; private set; } - public DownloadedEpisodesScanCommand() - { - CommandId = HashUtil.GenerateCommandId(); - } } } \ No newline at end of file diff --git a/NzbDrone.Core/MediaFiles/Commands/RenameSeasonCommand.cs b/NzbDrone.Core/MediaFiles/Commands/RenameSeasonCommand.cs index 5a61e100a..b2eb9ba6d 100644 --- a/NzbDrone.Core/MediaFiles/Commands/RenameSeasonCommand.cs +++ b/NzbDrone.Core/MediaFiles/Commands/RenameSeasonCommand.cs @@ -1,24 +1,23 @@ -using System; -using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.MediaFiles.Commands { - public class RenameSeasonCommand : ICommand + public class RenameSeasonCommand : Command { public int SeriesId { get; set; } public int SeasonNumber { get; set; } - public String CommandId { get; private set; } - - public RenameSeasonCommand() + public override bool SendUpdatesToClient { - CommandId = HashUtil.GenerateCommandId(); + get + { + return true; + } } public RenameSeasonCommand(int seriesId, int seasonNumber) { - CommandId = HashUtil.GenerateCommandId(); SeriesId = seriesId; SeasonNumber = seasonNumber; } diff --git a/NzbDrone.Core/MediaFiles/Commands/RenameSeriesCommand.cs b/NzbDrone.Core/MediaFiles/Commands/RenameSeriesCommand.cs index f7e99512f..af63bfe79 100644 --- a/NzbDrone.Core/MediaFiles/Commands/RenameSeriesCommand.cs +++ b/NzbDrone.Core/MediaFiles/Commands/RenameSeriesCommand.cs @@ -1,22 +1,26 @@ -using System; -using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.MediaFiles.Commands { - public class RenameSeriesCommand : ICommand + public class RenameSeriesCommand : Command { - public String CommandId { get; private set; } public int SeriesId { get; set; } + public override bool SendUpdatesToClient + { + get + { + return true; + } + } + public RenameSeriesCommand() { - CommandId = HashUtil.GenerateCommandId(); } public RenameSeriesCommand(int seriesId) { - CommandId = HashUtil.GenerateCommandId(); SeriesId = seriesId; } } diff --git a/NzbDrone.Core/MediaFiles/DiskScanService.cs b/NzbDrone.Core/MediaFiles/DiskScanService.cs index fc5aade8e..53fbfecb3 100644 --- a/NzbDrone.Core/MediaFiles/DiskScanService.cs +++ b/NzbDrone.Core/MediaFiles/DiskScanService.cs @@ -4,9 +4,10 @@ using System.Linq; using NLog; using NzbDrone.Common; using NzbDrone.Common.Instrumentation; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Instrumentation; using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.MediaFiles.EpisodeImport; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Tv; using NzbDrone.Core.Tv.Events; @@ -53,7 +54,7 @@ namespace NzbDrone.Core.MediaFiles private void Scan(Series series) { - _logger.Progress("Starting disk scan for {0}", series.Title); + _logger.ProgressInfo("Scanning disk for {0}", series.Title); _messageAggregator.PublishCommand(new CleanMediaFileDb(series.Id)); if (!_diskProvider.FolderExists(series.Path)) @@ -66,8 +67,6 @@ namespace NzbDrone.Core.MediaFiles var decisions = _importDecisionMaker.GetImportDecisions(mediaFileList, series, false); _importApprovedEpisodes.Import(decisions); - - _logger.Complete("Completed disk scan for {0}", series.Title); } public string[] GetVideoFiles(string path, bool allDirectories = true) diff --git a/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs b/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs index 19b947cc2..119379bba 100644 --- a/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs +++ b/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs @@ -4,11 +4,11 @@ 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.MediaFiles.EpisodeImport; using NzbDrone.Core.MediaFiles.EpisodeImport.Specifications; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Parser; using NzbDrone.Core.Tv; diff --git a/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs b/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs index ef230443b..6bec88c86 100644 --- a/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs +++ b/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs @@ -3,8 +3,8 @@ using System.IO; using System.Linq; using NLog; using NzbDrone.Common; -using NzbDrone.Common.Messaging; using NzbDrone.Core.MediaFiles.Events; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Organizer; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Tv; diff --git a/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs b/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs index 733b8580d..195b9849d 100644 --- a/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs +++ b/NzbDrone.Core/MediaFiles/EpisodeImport/ImportApprovedEpisodes.cs @@ -4,8 +4,9 @@ using System.IO; using System.Linq; using NLog; using NzbDrone.Common; -using NzbDrone.Common.Messaging; using NzbDrone.Core.MediaFiles.Events; +using NzbDrone.Core.Messaging; + namespace NzbDrone.Core.MediaFiles.EpisodeImport { diff --git a/NzbDrone.Core/MediaFiles/Events/EpisodeDownloadedEvent.cs b/NzbDrone.Core/MediaFiles/Events/EpisodeDownloadedEvent.cs index b7b80e4fd..1cd3f34bd 100644 --- a/NzbDrone.Core/MediaFiles/Events/EpisodeDownloadedEvent.cs +++ b/NzbDrone.Core/MediaFiles/Events/EpisodeDownloadedEvent.cs @@ -1,4 +1,5 @@ using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Parser.Model; namespace NzbDrone.Core.MediaFiles.Events diff --git a/NzbDrone.Core/MediaFiles/Events/EpisodeFileAddedEvent.cs b/NzbDrone.Core/MediaFiles/Events/EpisodeFileAddedEvent.cs index 83ea2a908..6a1b0d484 100644 --- a/NzbDrone.Core/MediaFiles/Events/EpisodeFileAddedEvent.cs +++ b/NzbDrone.Core/MediaFiles/Events/EpisodeFileAddedEvent.cs @@ -1,4 +1,5 @@ using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.MediaFiles.Events { diff --git a/NzbDrone.Core/MediaFiles/Events/EpisodeFileDeletedEvent.cs b/NzbDrone.Core/MediaFiles/Events/EpisodeFileDeletedEvent.cs index 65548c6bb..5ceafc60e 100644 --- a/NzbDrone.Core/MediaFiles/Events/EpisodeFileDeletedEvent.cs +++ b/NzbDrone.Core/MediaFiles/Events/EpisodeFileDeletedEvent.cs @@ -1,5 +1,6 @@ using System; using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.MediaFiles.Events { diff --git a/NzbDrone.Core/MediaFiles/Events/EpisodeImportedEvent.cs b/NzbDrone.Core/MediaFiles/Events/EpisodeImportedEvent.cs index 2f166b069..4b841834f 100644 --- a/NzbDrone.Core/MediaFiles/Events/EpisodeImportedEvent.cs +++ b/NzbDrone.Core/MediaFiles/Events/EpisodeImportedEvent.cs @@ -1,4 +1,5 @@ using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Parser.Model; namespace NzbDrone.Core.MediaFiles.Events diff --git a/NzbDrone.Core/MediaFiles/Events/SeriesRenamedEvent.cs b/NzbDrone.Core/MediaFiles/Events/SeriesRenamedEvent.cs index 8cfe96b89..2f04cf961 100644 --- a/NzbDrone.Core/MediaFiles/Events/SeriesRenamedEvent.cs +++ b/NzbDrone.Core/MediaFiles/Events/SeriesRenamedEvent.cs @@ -1,4 +1,5 @@ using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Tv; namespace NzbDrone.Core.MediaFiles.Events diff --git a/NzbDrone.Core/MediaFiles/MediaFileRepository.cs b/NzbDrone.Core/MediaFiles/MediaFileRepository.cs index 406bd9669..89ce30571 100644 --- a/NzbDrone.Core/MediaFiles/MediaFileRepository.cs +++ b/NzbDrone.Core/MediaFiles/MediaFileRepository.cs @@ -1,7 +1,8 @@ using System.Collections.Generic; using System.Linq; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Messaging; + namespace NzbDrone.Core.MediaFiles { diff --git a/NzbDrone.Core/MediaFiles/MediaFileService.cs b/NzbDrone.Core/MediaFiles/MediaFileService.cs index 54501c859..54de646d9 100644 --- a/NzbDrone.Core/MediaFiles/MediaFileService.cs +++ b/NzbDrone.Core/MediaFiles/MediaFileService.cs @@ -2,8 +2,8 @@ using System; using System.Collections.Generic; using System.Linq; using NLog; -using NzbDrone.Common.Messaging; using NzbDrone.Core.MediaFiles.Events; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Tv.Events; using NzbDrone.Common; diff --git a/NzbDrone.Core/MediaFiles/MediaFileTableCleanupService.cs b/NzbDrone.Core/MediaFiles/MediaFileTableCleanupService.cs index b72f03b4f..2d0c5ec4d 100644 --- a/NzbDrone.Core/MediaFiles/MediaFileTableCleanupService.cs +++ b/NzbDrone.Core/MediaFiles/MediaFileTableCleanupService.cs @@ -2,8 +2,8 @@ using System; using System.Linq; using NLog; using NzbDrone.Common; -using NzbDrone.Common.Messaging; using NzbDrone.Core.MediaFiles.Commands; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Tv; namespace NzbDrone.Core.MediaFiles diff --git a/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs b/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs index 17f286c71..0888d0ef5 100644 --- a/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs +++ b/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs @@ -4,9 +4,9 @@ using NLog; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Instrumentation; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Configuration; using NzbDrone.Core.MediaFiles.Commands; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Tv.Events; namespace NzbDrone.Core.MediaFiles diff --git a/NzbDrone.Core/MediaFiles/RenameEpisodeFileService.cs b/NzbDrone.Core/MediaFiles/RenameEpisodeFileService.cs index 5a3dc563e..756776fdd 100644 --- a/NzbDrone.Core/MediaFiles/RenameEpisodeFileService.cs +++ b/NzbDrone.Core/MediaFiles/RenameEpisodeFileService.cs @@ -3,9 +3,10 @@ using System.Collections.Generic; using System.Linq; using NLog; using NzbDrone.Common.Instrumentation; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Instrumentation; using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.MediaFiles.Events; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Tv; namespace NzbDrone.Core.MediaFiles @@ -68,9 +69,9 @@ namespace NzbDrone.Core.MediaFiles var series = _seriesService.GetSeries(message.SeriesId); var episodeFiles = _mediaFileService.GetFilesBySeason(message.SeriesId, message.SeasonNumber); - _logger.Progress("Renaming {0} files for {1} season {2}", episodeFiles.Count, series.Title, message.SeasonNumber); + _logger.ProgressInfo("Renaming {0} files for {1} season {2}", episodeFiles.Count, series.Title, message.SeasonNumber); RenameFiles(episodeFiles, series); - _logger.Complete("Episode Fies renamed for {0} season {1}", series.Title, message.SeasonNumber); + _logger.ProgressInfo("Episode Fies renamed for {0} season {1}", series.Title, message.SeasonNumber); } public void Execute(RenameSeriesCommand message) @@ -78,9 +79,9 @@ namespace NzbDrone.Core.MediaFiles var series = _seriesService.GetSeries(message.SeriesId); var episodeFiles = _mediaFileService.GetFilesBySeries(message.SeriesId); - _logger.Progress("Renaming {0} files for {1}", episodeFiles.Count, series.Title); + _logger.ProgressInfo("Renaming {0} files for {1}", episodeFiles.Count, series.Title); RenameFiles(episodeFiles, series); - _logger.Complete("Episode Fies renamed for {0}", series.Title); + _logger.ProgressInfo("Episode Fies renamed for {0}", series.Title); } } } diff --git a/NzbDrone.Core/Messaging/Commands/BackendCommandAttribute.cs b/NzbDrone.Core/Messaging/Commands/BackendCommandAttribute.cs new file mode 100644 index 000000000..b40f64f9c --- /dev/null +++ b/NzbDrone.Core/Messaging/Commands/BackendCommandAttribute.cs @@ -0,0 +1,8 @@ +using System; + +namespace NzbDrone.Core.Messaging.Commands +{ + public class BackendCommandAttribute : Attribute + { + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Messaging/Commands/Command.cs b/NzbDrone.Core/Messaging/Commands/Command.cs new file mode 100644 index 000000000..a389c83a5 --- /dev/null +++ b/NzbDrone.Core/Messaging/Commands/Command.cs @@ -0,0 +1,82 @@ +using System; +using FluentMigrator.Runner; +using NzbDrone.Common.Messaging; +using NzbDrone.Core.Datastore; +using NzbDrone.Core.Messaging.Tracking; + +namespace NzbDrone.Core.Messaging.Commands +{ + public abstract class Command : ModelBase, IMessage + { + private static readonly object Mutex = new object(); + private static int _idCounter; + private readonly StopWatch _stopWatch; + + public CommandStatus State { get; private set; } + public DateTime StateChangeTime { get; private set; } + + public virtual bool SendUpdatesToClient + { + get + { + return false; + } + } + + public TimeSpan Runtime + { + get + { + return _stopWatch.ElapsedTime(); + } + } + + public Exception Exception { get; private set; } + public string Message { get; private set; } + + public string Name { get; private set; } + + protected Command() + { + Name = GetType().Name.Replace("Command", ""); + StateChangeTime = DateTime.UtcNow; + State = CommandStatus.Pending; + _stopWatch = new StopWatch(); + + lock (Mutex) + { + Id = ++_idCounter; + } + } + + public void Start() + { + _stopWatch.Start(); + StateChangeTime = DateTime.UtcNow; + State = CommandStatus.Running; + SetMessage("Starting"); + } + + public void Failed(Exception exception) + { + _stopWatch.Stop(); + StateChangeTime = DateTime.UtcNow; + State = CommandStatus.Failed; + Exception = exception; + SetMessage("Failed"); + } + + public void Completed() + { + _stopWatch.Stop(); + StateChangeTime = DateTime.UtcNow; + State = CommandStatus.Completed; + SetMessage("Completed"); + } + + public void SetMessage(string message) + { + Message = message; + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Messaging/Commands/CommandEqualityComparer.cs b/NzbDrone.Core/Messaging/Commands/CommandEqualityComparer.cs new file mode 100644 index 000000000..d6af0276d --- /dev/null +++ b/NzbDrone.Core/Messaging/Commands/CommandEqualityComparer.cs @@ -0,0 +1,61 @@ +using System.Collections.Generic; +using System.Linq; + +namespace NzbDrone.Core.Messaging.Commands +{ + public class CommandEqualityComparer : IEqualityComparer + { + public static readonly CommandEqualityComparer Instance = new CommandEqualityComparer(); + + private CommandEqualityComparer() + { + + } + + public bool Equals(Command x, Command y) + { + var xProperties = x.GetType().GetProperties(); + var yProperties = y.GetType().GetProperties(); + + foreach (var xProperty in xProperties) + { + if (xProperty.Name == "Id") + { + continue; + } + + var yProperty = yProperties.SingleOrDefault(p => p.Name == xProperty.Name); + + if (yProperty == null) + { + continue; + } + + var xValue = xProperty.GetValue(x, null); + var yValue = yProperty.GetValue(y, null); + + if (xValue == null && yValue == null) + { + return true; + } + + if (xValue == null || yValue == null) + { + return false; + } + + if (!xValue.Equals(yValue)) + { + return false; + } + } + + return true; + } + + public int GetHashCode(Command obj) + { + return obj.Id.GetHashCode(); + } + } +} diff --git a/NzbDrone.Core/Messaging/Commands/TestCommand.cs b/NzbDrone.Core/Messaging/Commands/TestCommand.cs new file mode 100644 index 000000000..616c99ee7 --- /dev/null +++ b/NzbDrone.Core/Messaging/Commands/TestCommand.cs @@ -0,0 +1,20 @@ +namespace NzbDrone.Core.Messaging.Commands +{ + public class TestCommand : Command + { + public int Duration { get; set; } + + public override bool SendUpdatesToClient + { + get + { + return true; + } + } + + public TestCommand() + { + Duration = 4000; + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Messaging/Commands/TestCommandExecutor.cs b/NzbDrone.Core/Messaging/Commands/TestCommandExecutor.cs new file mode 100644 index 000000000..8e0ebfb71 --- /dev/null +++ b/NzbDrone.Core/Messaging/Commands/TestCommandExecutor.cs @@ -0,0 +1,23 @@ +using System.Threading; +using NLog; +using NzbDrone.Core.Instrumentation; + +namespace NzbDrone.Core.Messaging.Commands +{ + public class TestCommandExecutor : IExecute + { + private readonly Logger _logger; + + public TestCommandExecutor(Logger logger) + { + _logger = logger; + } + + public void Execute(TestCommand message) + { + _logger.ProgressInfo("Starting Test command. duration {0}", message.Duration); + Thread.Sleep(message.Duration); + _logger.ProgressInfo("Completed Test command"); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Messaging/Events/CommandCreatedEvent.cs b/NzbDrone.Core/Messaging/Events/CommandCreatedEvent.cs new file mode 100644 index 000000000..5224e2671 --- /dev/null +++ b/NzbDrone.Core/Messaging/Events/CommandCreatedEvent.cs @@ -0,0 +1,15 @@ +using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging.Commands; + +namespace NzbDrone.Core.Messaging.Events +{ + public class CommandCreatedEvent : IEvent + { + public Command Command { get; private set; } + + public CommandCreatedEvent(Command trackedCommand) + { + Command = trackedCommand; + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Messaging/Events/CommandExecutedEvent.cs b/NzbDrone.Core/Messaging/Events/CommandExecutedEvent.cs new file mode 100644 index 000000000..83fb2abdb --- /dev/null +++ b/NzbDrone.Core/Messaging/Events/CommandExecutedEvent.cs @@ -0,0 +1,15 @@ +using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging.Commands; + +namespace NzbDrone.Core.Messaging.Events +{ + public class CommandExecutedEvent : IEvent + { + public Command Command { get; private set; } + + public CommandExecutedEvent(Command trackedCommand) + { + Command = trackedCommand; + } + } +} \ No newline at end of file diff --git a/NzbDrone.Common/Messaging/IExecute.cs b/NzbDrone.Core/Messaging/IExecute.cs similarity index 52% rename from NzbDrone.Common/Messaging/IExecute.cs rename to NzbDrone.Core/Messaging/IExecute.cs index a065e0828..43b3dc695 100644 --- a/NzbDrone.Common/Messaging/IExecute.cs +++ b/NzbDrone.Core/Messaging/IExecute.cs @@ -1,6 +1,8 @@ -namespace NzbDrone.Common.Messaging +using NzbDrone.Core.Messaging.Commands; + +namespace NzbDrone.Core.Messaging { - public interface IExecute : IProcessMessage where TCommand : ICommand + public interface IExecute : IProcessMessage where TCommand : Command { void Execute(TCommand message); } diff --git a/NzbDrone.Common/Messaging/IHandle.cs b/NzbDrone.Core/Messaging/IHandle.cs similarity index 80% rename from NzbDrone.Common/Messaging/IHandle.cs rename to NzbDrone.Core/Messaging/IHandle.cs index ae40448d4..b0c33796a 100644 --- a/NzbDrone.Common/Messaging/IHandle.cs +++ b/NzbDrone.Core/Messaging/IHandle.cs @@ -1,4 +1,6 @@ -namespace NzbDrone.Common.Messaging +using NzbDrone.Common.Messaging; + +namespace NzbDrone.Core.Messaging { public interface IHandle : IProcessMessage where TEvent : IEvent { diff --git a/NzbDrone.Common/Messaging/IMessageAggregator.cs b/NzbDrone.Core/Messaging/IMessageAggregator.cs similarity index 55% rename from NzbDrone.Common/Messaging/IMessageAggregator.cs rename to NzbDrone.Core/Messaging/IMessageAggregator.cs index 9edd5b165..5a3d5213f 100644 --- a/NzbDrone.Common/Messaging/IMessageAggregator.cs +++ b/NzbDrone.Core/Messaging/IMessageAggregator.cs @@ -1,6 +1,7 @@ -using NzbDrone.Common.Messaging.Tracking; +using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging.Commands; -namespace NzbDrone.Common.Messaging +namespace NzbDrone.Core.Messaging { /// /// Enables loosely-coupled publication of events. @@ -8,9 +9,9 @@ namespace NzbDrone.Common.Messaging public interface IMessageAggregator { void PublishEvent(TEvent @event) where TEvent : class, IEvent; - void PublishCommand(TCommand command) where TCommand : class, ICommand; + void PublishCommand(TCommand command) where TCommand : Command; void PublishCommand(string commandTypeName); - TrackedCommand PublishCommandAsync(TCommand command) where TCommand : class, ICommand; - TrackedCommand PublishCommandAsync(string commandTypeName); + Command PublishCommandAsync(TCommand command) where TCommand : Command; + Command PublishCommandAsync(string commandTypeName); } } \ No newline at end of file diff --git a/NzbDrone.Common/Messaging/IProcessMessage.cs b/NzbDrone.Core/Messaging/IProcessMessage.cs similarity index 86% rename from NzbDrone.Common/Messaging/IProcessMessage.cs rename to NzbDrone.Core/Messaging/IProcessMessage.cs index d22eeea64..2207e803d 100644 --- a/NzbDrone.Common/Messaging/IProcessMessage.cs +++ b/NzbDrone.Core/Messaging/IProcessMessage.cs @@ -1,4 +1,4 @@ -namespace NzbDrone.Common.Messaging +namespace NzbDrone.Core.Messaging { public interface IProcessMessage { } diff --git a/NzbDrone.Common/Messaging/MessageAggregator.cs b/NzbDrone.Core/Messaging/MessageAggregator.cs similarity index 63% rename from NzbDrone.Common/Messaging/MessageAggregator.cs rename to NzbDrone.Core/Messaging/MessageAggregator.cs index 750e7d9cd..4d3ed0433 100644 --- a/NzbDrone.Common/Messaging/MessageAggregator.cs +++ b/NzbDrone.Core/Messaging/MessageAggregator.cs @@ -1,15 +1,18 @@ -using System; -using System.Diagnostics; +using System; using System.Linq; using System.Threading.Tasks; using NLog; +using NzbDrone.Common; using NzbDrone.Common.EnsureThat; -using NzbDrone.Common.Messaging.Events; -using NzbDrone.Common.Messaging.Tracking; +using NzbDrone.Common.Messaging; using NzbDrone.Common.Serializer; using NzbDrone.Common.TPL; +using NzbDrone.Core.Messaging.Commands; +using NzbDrone.Core.Messaging.Events; +using NzbDrone.Core.Messaging.Tracking; +using NzbDrone.Core.ProgressMessaging; -namespace NzbDrone.Common.Messaging +namespace NzbDrone.Core.Messaging { public class MessageAggregator : IMessageAggregator { @@ -20,10 +23,11 @@ namespace NzbDrone.Common.Messaging public MessageAggregator(Logger logger, IServiceFactory serviceFactory, ITrackCommands trackCommands) { + var scheduler = new LimitedConcurrencyLevelTaskScheduler(3); + _logger = logger; _serviceFactory = serviceFactory; _trackCommands = trackCommands; - var scheduler = new LimitedConcurrencyLevelTaskScheduler(2); _taskFactory = new TaskFactory(scheduler); } @@ -40,9 +44,9 @@ namespace NzbDrone.Common.Messaging { try { - _logger.Debug("{0} -> {1}", eventName, handler.GetType().Name); + _logger.Trace("{0} -> {1}", eventName, handler.GetType().Name); handler.Handle(@event); - _logger.Debug("{0} <- {1}", eventName, handler.GetType().Name); + _logger.Trace("{0} <- {1}", eventName, handler.GetType().Name); } catch (Exception e) { @@ -56,9 +60,9 @@ namespace NzbDrone.Common.Messaging _taskFactory.StartNew(() => { - _logger.Debug("{0} ~> {1}", eventName, handlerLocal.GetType().Name); + _logger.Trace("{0} ~> {1}", eventName, handlerLocal.GetType().Name); handlerLocal.HandleAsync(@event); - _logger.Debug("{0} <~ {1}", eventName, handlerLocal.GetType().Name); + _logger.Trace("{0} <~ {1}", eventName, handlerLocal.GetType().Name); }, TaskCreationOptions.PreferFairness) .LogExceptions(); } @@ -74,21 +78,21 @@ namespace NzbDrone.Common.Messaging return string.Format("{0}<{1}>", eventType.Name.Remove(eventType.Name.IndexOf('`')), eventType.GetGenericArguments()[0].Name); } - public void PublishCommand(TCommand command) where TCommand : class, ICommand + public void PublishCommand(TCommand command) where TCommand : Command { Ensure.That(() => command).IsNotNull(); _logger.Trace("Publishing {0}", command.GetType().Name); - var trackedCommand = _trackCommands.TrackIfNew(command); - - if (trackedCommand == null) + if (_trackCommands.FindExisting(command) != null) { - _logger.Info("Command is already in progress: {0}", command.GetType().Name); + _logger.Debug("Command is already in progress: {0}", command.GetType().Name); return; } - ExecuteCommand(trackedCommand); + _trackCommands.Store(command); + + ExecuteCommand(command); } public void PublishCommand(string commandTypeName) @@ -97,28 +101,30 @@ namespace NzbDrone.Common.Messaging PublishCommand(command); } - public TrackedCommand PublishCommandAsync(TCommand command) where TCommand : class, ICommand + public Command PublishCommandAsync(TCommand command) where TCommand : Command { Ensure.That(() => command).IsNotNull(); _logger.Trace("Publishing {0}", command.GetType().Name); - var existingCommand = _trackCommands.TrackNewOrGet(command); + var existingCommand = _trackCommands.FindExisting(command); - if (existingCommand.Existing) + if (existingCommand != null) { - _logger.Info("Command is already in progress: {0}", command.GetType().Name); - return existingCommand.TrackedCommand; + _logger.Debug("Command is already in progress: {0}", command.GetType().Name); + return existingCommand; } - _taskFactory.StartNew(() => ExecuteCommand(existingCommand.TrackedCommand) + _trackCommands.Store(command); + + _taskFactory.StartNew(() => ExecuteCommand(command) , TaskCreationOptions.PreferFairness) .LogExceptions(); - return existingCommand.TrackedCommand; + return command; } - public TrackedCommand PublishCommandAsync(string commandTypeName) + public Command PublishCommandAsync(string commandTypeName) { dynamic command = GetCommand(commandTypeName); return PublishCommandAsync(command); @@ -126,49 +132,45 @@ namespace NzbDrone.Common.Messaging private dynamic GetCommand(string commandTypeName) { - var commandType = _serviceFactory.GetImplementations(typeof(ICommand)) + var commandType = _serviceFactory.GetImplementations(typeof(Command)) .Single(c => c.FullName.Equals(commandTypeName, StringComparison.InvariantCultureIgnoreCase)); return Json.Deserialize("{}", commandType); } - private void ExecuteCommand(TrackedCommand trackedCommand) where TCommand : class, ICommand + private void ExecuteCommand(Command command) where TCommand : Command { - var command = (TCommand)trackedCommand.Command; - var handlerContract = typeof(IExecute<>).MakeGenericType(command.GetType()); var handler = (IExecute)_serviceFactory.Build(handlerContract); - _logger.Debug("{0} -> {1}", command.GetType().Name, handler.GetType().Name); - - var sw = Stopwatch.StartNew(); + _logger.Trace("{0} -> {1}", command.GetType().Name, handler.GetType().Name); try { - if (!MappedDiagnosticsContext.Contains("CommandId")) + _trackCommands.Start(command); + PublishEvent(new CommandUpdatedEvent(command)); + + if (!MappedDiagnosticsContext.Contains("CommandId") && command.SendUpdatesToClient) { - MappedDiagnosticsContext.Set("CommandId", trackedCommand.Command.CommandId); + MappedDiagnosticsContext.Set("CommandId", command.Id.ToString()); } - PublishEvent(new CommandStartedEvent(trackedCommand)); - handler.Execute(command); - sw.Stop(); + handler.Execute((TCommand)command); + _trackCommands.Completed(command); + PublishEvent(new CommandUpdatedEvent(command)); - _trackCommands.Completed(trackedCommand, sw.Elapsed); - PublishEvent(new CommandCompletedEvent(trackedCommand)); } catch (Exception e) { - _trackCommands.Failed(trackedCommand, e); - PublishEvent(new CommandFailedEvent(trackedCommand, e)); + _trackCommands.Failed(command, e); + PublishEvent(new CommandUpdatedEvent(command)); throw; } - finally - { - PublishEvent(new CommandExecutedEvent(trackedCommand)); - } - _logger.Debug("{0} <- {1} [{2}]", command.GetType().Name, handler.GetType().Name, sw.Elapsed.ToString("")); + 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.Common/Messaging/MessageExtensions.cs b/NzbDrone.Core/Messaging/MessageExtensions.cs similarity index 68% rename from NzbDrone.Common/Messaging/MessageExtensions.cs rename to NzbDrone.Core/Messaging/MessageExtensions.cs index 302aad869..f44d15d5f 100644 --- a/NzbDrone.Common/Messaging/MessageExtensions.cs +++ b/NzbDrone.Core/Messaging/MessageExtensions.cs @@ -1,12 +1,13 @@ -using System; +using System; +using NzbDrone.Core.Messaging.Commands; -namespace NzbDrone.Common.Messaging +namespace NzbDrone.Core.Messaging { public static class MessageExtensions { public static string GetExecutorName(this Type commandType) { - if (!typeof(ICommand).IsAssignableFrom(commandType)) + if (!typeof(Command).IsAssignableFrom(commandType)) { throw new ArgumentException("commandType must implement ICommand"); } diff --git a/NzbDrone.Core/Messaging/Tracking/CommandStatus.cs b/NzbDrone.Core/Messaging/Tracking/CommandStatus.cs new file mode 100644 index 000000000..4ed389bf1 --- /dev/null +++ b/NzbDrone.Core/Messaging/Tracking/CommandStatus.cs @@ -0,0 +1,10 @@ +namespace NzbDrone.Core.Messaging.Tracking +{ + public enum CommandStatus + { + Pending, + Running, + Completed, + Failed + } +} diff --git a/NzbDrone.Core/Messaging/Tracking/CommandTrackingService.cs b/NzbDrone.Core/Messaging/Tracking/CommandTrackingService.cs new file mode 100644 index 000000000..df2cbc662 --- /dev/null +++ b/NzbDrone.Core/Messaging/Tracking/CommandTrackingService.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using NzbDrone.Common.Cache; +using NzbDrone.Core.Messaging.Commands; + +namespace NzbDrone.Core.Messaging.Tracking +{ + public interface ITrackCommands + { + Command GetById(int id); + Command GetById(string id); + void Completed(Command trackedCommand); + void Failed(Command trackedCommand, Exception e); + IEnumerable RunningCommands(); + Command FindExisting(Command command); + void Store(Command command); + void Start(Command command); + } + + public class CommandTrackingService : ITrackCommands, IExecute + { + private readonly ICached _cache; + + public CommandTrackingService(ICacheManger cacheManger) + { + _cache = cacheManger.GetCache(GetType()); + } + + public Command GetById(int id) + { + return _cache.Find(id.ToString()); + } + + public Command GetById(string id) + { + return _cache.Find(id); + } + + public void Start(Command command) + { + command.Start(); + } + + public void Completed(Command trackedCommand) + { + trackedCommand.Completed(); + } + + public void Failed(Command trackedCommand, Exception e) + { + trackedCommand.Failed(e); + } + + public IEnumerable RunningCommands() + { + return _cache.Values.Where(c => c.State == CommandStatus.Running); + } + + public Command FindExisting(Command command) + { + return RunningCommands().Where(c => c.GetType() == command.GetType()) + .SingleOrDefault(t => CommandEqualityComparer.Instance.Equals(t, command)); + } + + public void Store(Command command) + { + if (command.GetType() == typeof(TrackedCommandCleanupCommand)) + { + return; + } + + _cache.Set(command.Id.ToString(), command); + } + + public void Execute(TrackedCommandCleanupCommand message) + { + var old = _cache.Values.Where(c => c.State != CommandStatus.Running && c.StateChangeTime < DateTime.UtcNow.AddMinutes(-5)); + + foreach (var trackedCommand in old) + { + _cache.Remove(trackedCommand.Id.ToString()); + } + } + } +} diff --git a/NzbDrone.Core/Messaging/Tracking/ExistingCommand.cs b/NzbDrone.Core/Messaging/Tracking/ExistingCommand.cs new file mode 100644 index 000000000..f41d8ef56 --- /dev/null +++ b/NzbDrone.Core/Messaging/Tracking/ExistingCommand.cs @@ -0,0 +1,17 @@ +using System; +using NzbDrone.Core.Messaging.Commands; + +namespace NzbDrone.Core.Messaging.Tracking +{ + public class ExistingCommand + { + public Boolean Existing { get; set; } + public Command Command { get; set; } + + public ExistingCommand(Boolean exisitng, Command trackedCommand) + { + Existing = exisitng; + Command = trackedCommand; + } + } +} diff --git a/NzbDrone.Core/Messaging/Tracking/TrackedCommandCleanupCommand.cs b/NzbDrone.Core/Messaging/Tracking/TrackedCommandCleanupCommand.cs new file mode 100644 index 000000000..3bdb9ec9f --- /dev/null +++ b/NzbDrone.Core/Messaging/Tracking/TrackedCommandCleanupCommand.cs @@ -0,0 +1,9 @@ +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 38c37086d..6f7b11e57 100644 --- a/NzbDrone.Core/Notifications/Email/EmailService.cs +++ b/NzbDrone.Core/Notifications/Email/EmailService.cs @@ -2,7 +2,7 @@ using System.Net; using System.Net.Mail; using NLog; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; using Omu.ValueInjecter; namespace NzbDrone.Core.Notifications.Email diff --git a/NzbDrone.Core/Notifications/Email/TestEmailCommand.cs b/NzbDrone.Core/Notifications/Email/TestEmailCommand.cs index 26bf91c94..f197bd287 100644 --- a/NzbDrone.Core/Notifications/Email/TestEmailCommand.cs +++ b/NzbDrone.Core/Notifications/Email/TestEmailCommand.cs @@ -1,12 +1,10 @@ -using System; -using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Notifications.Email { - public class TestEmailCommand : ICommand + public class TestEmailCommand : Command { - public String CommandId { get; private set; } public string Server { get; set; } public int Port { get; set; } public bool Ssl { get; set; } @@ -14,10 +12,5 @@ namespace NzbDrone.Core.Notifications.Email public string Password { get; set; } public string From { get; set; } public string To { get; set; } - - public TestEmailCommand() - { - CommandId = HashUtil.GenerateCommandId(); - } } } diff --git a/NzbDrone.Core/Notifications/Growl/GrowlService.cs b/NzbDrone.Core/Notifications/Growl/GrowlService.cs index 55d3fad78..5f1e4a37a 100644 --- a/NzbDrone.Core/Notifications/Growl/GrowlService.cs +++ b/NzbDrone.Core/Notifications/Growl/GrowlService.cs @@ -4,7 +4,7 @@ using System.Linq; using Growl.Connector; using NLog; using NzbDrone.Common.Instrumentation; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; using GrowlNotification = Growl.Connector.Notification; namespace NzbDrone.Core.Notifications.Growl diff --git a/NzbDrone.Core/Notifications/Growl/TestGrowlCommand.cs b/NzbDrone.Core/Notifications/Growl/TestGrowlCommand.cs index 8494e0d9d..fac4c70a2 100644 --- a/NzbDrone.Core/Notifications/Growl/TestGrowlCommand.cs +++ b/NzbDrone.Core/Notifications/Growl/TestGrowlCommand.cs @@ -1,19 +1,14 @@ using System; using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Notifications.Growl { - public class TestGrowlCommand : ICommand + public class TestGrowlCommand : Command { - public String CommandId { get; private set; } public string Host { get; set; } public int Port { get; set; } public string Password { get; set; } - - public TestGrowlCommand() - { - CommandId = HashUtil.GenerateCommandId(); - } } } diff --git a/NzbDrone.Core/Notifications/NotificationRepository.cs b/NzbDrone.Core/Notifications/NotificationRepository.cs index f9f9feb0d..cdaa70a1d 100644 --- a/NzbDrone.Core/Notifications/NotificationRepository.cs +++ b/NzbDrone.Core/Notifications/NotificationRepository.cs @@ -1,7 +1,8 @@ using System; using System.Linq; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Messaging; + namespace NzbDrone.Core.Notifications { diff --git a/NzbDrone.Core/Notifications/NotificationService.cs b/NzbDrone.Core/Notifications/NotificationService.cs index d48398898..47643093d 100644 --- a/NzbDrone.Core/Notifications/NotificationService.cs +++ b/NzbDrone.Core/Notifications/NotificationService.cs @@ -3,10 +3,10 @@ using System.Collections.Generic; using System.Linq; using NLog; using NzbDrone.Common.Composition; -using NzbDrone.Common.Messaging; using NzbDrone.Common.Serializer; using NzbDrone.Core.Download; using NzbDrone.Core.MediaFiles.Events; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Tv; using Omu.ValueInjecter; diff --git a/NzbDrone.Core/Notifications/Plex/PlexService.cs b/NzbDrone.Core/Notifications/Plex/PlexService.cs index 15e01420c..b994a5ab5 100644 --- a/NzbDrone.Core/Notifications/Plex/PlexService.cs +++ b/NzbDrone.Core/Notifications/Plex/PlexService.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Xml.Linq; using NLog; using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Notifications.Plex { diff --git a/NzbDrone.Core/Notifications/Plex/TestPlexClientCommand.cs b/NzbDrone.Core/Notifications/Plex/TestPlexClientCommand.cs index 365add8a2..9c4c6b4aa 100644 --- a/NzbDrone.Core/Notifications/Plex/TestPlexClientCommand.cs +++ b/NzbDrone.Core/Notifications/Plex/TestPlexClientCommand.cs @@ -1,20 +1,15 @@ using System; using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Notifications.Plex { - public class TestPlexClientCommand : ICommand + public class TestPlexClientCommand : Command { - public String CommandId { get; private set; } public string Host { get; set; } public int Port { get; set; } public string Username { get; set; } public string Password { get; set; } - - public TestPlexClientCommand() - { - CommandId = HashUtil.GenerateCommandId(); - } } } diff --git a/NzbDrone.Core/Notifications/Plex/TestPlexServerCommand.cs b/NzbDrone.Core/Notifications/Plex/TestPlexServerCommand.cs index 7306e5a10..c32f5c1b0 100644 --- a/NzbDrone.Core/Notifications/Plex/TestPlexServerCommand.cs +++ b/NzbDrone.Core/Notifications/Plex/TestPlexServerCommand.cs @@ -1,18 +1,13 @@ using System; using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Notifications.Plex { - public class TestPlexServerCommand : ICommand + public class TestPlexServerCommand : Command { - public String CommandId { get; private set; } public string Host { get; set; } public int Port { get; set; } - - public TestPlexServerCommand() - { - CommandId = HashUtil.GenerateCommandId(); - } } } diff --git a/NzbDrone.Core/Notifications/Prowl/ProwlService.cs b/NzbDrone.Core/Notifications/Prowl/ProwlService.cs index bf850215f..2a9fb8d83 100644 --- a/NzbDrone.Core/Notifications/Prowl/ProwlService.cs +++ b/NzbDrone.Core/Notifications/Prowl/ProwlService.cs @@ -1,6 +1,6 @@ using System; using NLog; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; using Prowlin; namespace NzbDrone.Core.Notifications.Prowl diff --git a/NzbDrone.Core/Notifications/Prowl/TestProwlCommand.cs b/NzbDrone.Core/Notifications/Prowl/TestProwlCommand.cs index 869123be0..51b5e2a84 100644 --- a/NzbDrone.Core/Notifications/Prowl/TestProwlCommand.cs +++ b/NzbDrone.Core/Notifications/Prowl/TestProwlCommand.cs @@ -1,18 +1,13 @@ using System; using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Notifications.Prowl { - public class TestProwlCommand : ICommand + public class TestProwlCommand : Command { - public String CommandId { get; private set; } public string ApiKey { get; set; } public int Priority { get; set; } - - public TestProwlCommand() - { - CommandId = HashUtil.GenerateCommandId(); - } } } diff --git a/NzbDrone.Core/Notifications/Pushover/PushoverService.cs b/NzbDrone.Core/Notifications/Pushover/PushoverService.cs index cab9639bb..bb4fa9b64 100644 --- a/NzbDrone.Core/Notifications/Pushover/PushoverService.cs +++ b/NzbDrone.Core/Notifications/Pushover/PushoverService.cs @@ -1,4 +1,4 @@ -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; using RestSharp; using NzbDrone.Core.Rest; diff --git a/NzbDrone.Core/Notifications/Pushover/TestPushoverCommand.cs b/NzbDrone.Core/Notifications/Pushover/TestPushoverCommand.cs index 0c6ec8912..01a909cda 100644 --- a/NzbDrone.Core/Notifications/Pushover/TestPushoverCommand.cs +++ b/NzbDrone.Core/Notifications/Pushover/TestPushoverCommand.cs @@ -1,18 +1,13 @@ using System; using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Notifications.Pushover { - public class TestPushoverCommand : ICommand + public class TestPushoverCommand : Command { - public String CommandId { get; private set; } public string UserKey { get; set; } public int Priority { get; set; } - - public TestPushoverCommand() - { - CommandId = HashUtil.GenerateCommandId(); - } } } diff --git a/NzbDrone.Core/Notifications/Xbmc/TestXbmcCommand.cs b/NzbDrone.Core/Notifications/Xbmc/TestXbmcCommand.cs index 02c594e8d..983cb2ba6 100644 --- a/NzbDrone.Core/Notifications/Xbmc/TestXbmcCommand.cs +++ b/NzbDrone.Core/Notifications/Xbmc/TestXbmcCommand.cs @@ -1,21 +1,16 @@ using System; using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Notifications.Xbmc { - public class TestXbmcCommand : ICommand + public class TestXbmcCommand : Command { - public String CommandId { get; private set; } public string Host { get; set; } public int Port { get; set; } public string Username { get; set; } public string Password { get; set; } public int DisplayTime { get; set; } - - public TestXbmcCommand() - { - CommandId = HashUtil.GenerateCommandId(); - } } } diff --git a/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs b/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs index 6df04e75b..042007638 100644 --- a/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs +++ b/NzbDrone.Core/Notifications/Xbmc/XbmcService.cs @@ -6,7 +6,7 @@ using Newtonsoft.Json.Linq; using NLog; using NzbDrone.Common; using NzbDrone.Common.Instrumentation; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Tv; using NzbDrone.Core.Model.Xbmc; diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index fe1b6b6de..742a9141c 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -131,7 +131,6 @@ - @@ -230,8 +229,26 @@ - - + + + + + + + + + + + + + + + + + + + + @@ -578,4 +595,4 @@ --> - \ No newline at end of file + diff --git a/NzbDrone.Core/ProgressMessaging/NewProgressMessageEvent.cs b/NzbDrone.Core/ProgressMessaging/NewProgressMessageEvent.cs deleted file mode 100644 index 0b2905312..000000000 --- a/NzbDrone.Core/ProgressMessaging/NewProgressMessageEvent.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using NzbDrone.Common.Messaging; - -namespace NzbDrone.Core.ProgressMessaging -{ - public class NewProgressMessageEvent : IEvent - { - public ProgressMessage ProgressMessage { get; set; } - - public NewProgressMessageEvent(ProgressMessage progressMessage) - { - ProgressMessage = progressMessage; - } - } -} diff --git a/NzbDrone.Core/ProgressMessaging/ProgressMessage.cs b/NzbDrone.Core/ProgressMessaging/ProgressMessage.cs deleted file mode 100644 index b9bc8fc6d..000000000 --- a/NzbDrone.Core/ProgressMessaging/ProgressMessage.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using NzbDrone.Common.Messaging.Tracking; - -namespace NzbDrone.Core.ProgressMessaging -{ - public class ProgressMessage - { - public DateTime Time { get; set; } - public String CommandId { get; set; } - public String Message { get; set; } - public ProcessState Status { get; set; } - } -} diff --git a/NzbDrone.Core/ProgressMessaging/ProgressMessageTarget.cs b/NzbDrone.Core/ProgressMessaging/ProgressMessageTarget.cs index d11d33bd0..2b6b88394 100644 --- a/NzbDrone.Core/ProgressMessaging/ProgressMessageTarget.cs +++ b/NzbDrone.Core/ProgressMessaging/ProgressMessageTarget.cs @@ -1,91 +1,67 @@ -using System; -using NLog.Config; +using NLog.Config; using NLog; -using NLog.Layouts; using NLog.Targets; -using NzbDrone.Common.Messaging; -using NzbDrone.Common.Messaging.Tracking; using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; +using NzbDrone.Core.Messaging.Tracking; namespace NzbDrone.Core.ProgressMessaging { - public class ProgressMessageTarget : TargetWithLayout, IHandle, IHandle + public class ProgressMessageTarget : Target, IHandle { private readonly IMessageAggregator _messageAggregator; - public LoggingRule Rule { get; set; } + private readonly ITrackCommands _trackCommands; + private static LoggingRule _rule; - public ProgressMessageTarget(IMessageAggregator messageAggregator) + public ProgressMessageTarget(IMessageAggregator messageAggregator, ITrackCommands trackCommands) { _messageAggregator = messageAggregator; - } - - public void Register() - { - Layout = new SimpleLayout("${callsite:className=false:fileName=false:includeSourcePath=false:methodName=true}"); - - Rule = new LoggingRule("*", this); - Rule.EnableLoggingForLevel(LogLevel.Info); - - LogManager.Configuration.AddTarget("ProgressMessagingLogger", this); - LogManager.Configuration.LoggingRules.Add(Rule); - LogManager.ConfigurationReloaded += OnLogManagerOnConfigurationReloaded; - LogManager.ReconfigExistingLoggers(); - } - - public void UnRegister() - { - LogManager.ConfigurationReloaded -= OnLogManagerOnConfigurationReloaded; - LogManager.Configuration.RemoveTarget("ProgressMessagingLogger"); - LogManager.Configuration.LoggingRules.Remove(Rule); - LogManager.ReconfigExistingLoggers(); - Dispose(); - } - - private void OnLogManagerOnConfigurationReloaded(object sender, LoggingConfigurationReloadedEventArgs args) - { - Register(); + _trackCommands = trackCommands; } protected override void Write(LogEventInfo logEvent) + { + var command = GetCurrentCommand(); + + if (IsClientMessage(logEvent, command)) + { + command.SetMessage(logEvent.FormattedMessage); + _messageAggregator.PublishEvent(new CommandUpdatedEvent(command)); + } + } + + + private Command GetCurrentCommand() { var commandId = MappedDiagnosticsContext.Get("CommandId"); - if (String.IsNullOrWhiteSpace(commandId)) + if (string.IsNullOrWhiteSpace(commandId)) { - return; + return null; } - if (!logEvent.Properties.ContainsKey("Status")) + return _trackCommands.GetById(commandId); + } + + private bool IsClientMessage(LogEventInfo logEvent, Command command) + { + if (command == null || !command.SendUpdatesToClient) { - return; + return false; } - var status = (ProcessState)logEvent.Properties["Status"]; - - var message = new ProgressMessage(); - message.Time = logEvent.TimeStamp; - message.CommandId = commandId; - message.Message = logEvent.FormattedMessage; - message.Status = status; - - _messageAggregator.PublishEvent(new NewProgressMessageEvent(message)); + return logEvent.Properties.ContainsKey("Status"); } public void Handle(ApplicationStartedEvent message) { - if (!LogManager.Configuration.LoggingRules.Contains(Rule)) - { - Register(); - } - } + _rule = new LoggingRule("*", LogLevel.Trace, this); - public void Handle(ApplicationShutdownRequested message) - { - if (LogManager.Configuration.LoggingRules.Contains(Rule)) - { - UnRegister(); - } + LogManager.Configuration.AddTarget("ProgressMessagingLogger", this); + LogManager.Configuration.LoggingRules.Add(_rule); + LogManager.ReconfigExistingLoggers(); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/UpdateXemMappingsCommand.cs b/NzbDrone.Core/Providers/UpdateXemMappingsCommand.cs index 0dd28372d..75669489b 100644 --- a/NzbDrone.Core/Providers/UpdateXemMappingsCommand.cs +++ b/NzbDrone.Core/Providers/UpdateXemMappingsCommand.cs @@ -1,17 +1,16 @@ using System; using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Providers { - public class UpdateXemMappingsCommand : ICommand + public class UpdateXemMappingsCommand : Command { - public String CommandId { get; private set; } public int? SeriesId { get; set; } public UpdateXemMappingsCommand(int? seriesId) { - CommandId = HashUtil.GenerateCommandId(); SeriesId = seriesId; } } diff --git a/NzbDrone.Core/Providers/XemProvider.cs b/NzbDrone.Core/Providers/XemProvider.cs index 0cb1aded7..b8bdbd344 100644 --- a/NzbDrone.Core/Providers/XemProvider.cs +++ b/NzbDrone.Core/Providers/XemProvider.cs @@ -4,8 +4,8 @@ using System.Linq; using NLog; using NzbDrone.Common.Cache; using NzbDrone.Common.Instrumentation; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Tv; using NzbDrone.Core.Tv.Events; diff --git a/NzbDrone.Core/Qualities/QualityProfileRepository.cs b/NzbDrone.Core/Qualities/QualityProfileRepository.cs index fcb70f3ff..c3a412cc6 100644 --- a/NzbDrone.Core/Qualities/QualityProfileRepository.cs +++ b/NzbDrone.Core/Qualities/QualityProfileRepository.cs @@ -1,5 +1,6 @@ -using NzbDrone.Common.Messaging; -using NzbDrone.Core.Datastore; +using NzbDrone.Core.Datastore; +using NzbDrone.Core.Messaging; + namespace NzbDrone.Core.Qualities { diff --git a/NzbDrone.Core/Qualities/QualityProfileService.cs b/NzbDrone.Core/Qualities/QualityProfileService.cs index fb96cee99..71e4536b3 100644 --- a/NzbDrone.Core/Qualities/QualityProfileService.cs +++ b/NzbDrone.Core/Qualities/QualityProfileService.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.Linq; using NLog; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Tv; diff --git a/NzbDrone.Core/Qualities/QualitySizeRepository.cs b/NzbDrone.Core/Qualities/QualitySizeRepository.cs index ef4bb4138..a359b8a62 100644 --- a/NzbDrone.Core/Qualities/QualitySizeRepository.cs +++ b/NzbDrone.Core/Qualities/QualitySizeRepository.cs @@ -1,7 +1,8 @@ using System; using System.Linq; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Messaging; + namespace NzbDrone.Core.Qualities { diff --git a/NzbDrone.Core/Qualities/QualitySizeService.cs b/NzbDrone.Core/Qualities/QualitySizeService.cs index d3dce3199..4627aba58 100644 --- a/NzbDrone.Core/Qualities/QualitySizeService.cs +++ b/NzbDrone.Core/Qualities/QualitySizeService.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.Linq; using NLog; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Qualities { diff --git a/NzbDrone.Core/Tv/Commands/RefreshSeriesCommand.cs b/NzbDrone.Core/Tv/Commands/RefreshSeriesCommand.cs index a58fca783..a0ebe1c6d 100644 --- a/NzbDrone.Core/Tv/Commands/RefreshSeriesCommand.cs +++ b/NzbDrone.Core/Tv/Commands/RefreshSeriesCommand.cs @@ -1,24 +1,29 @@ using System; using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Tv.Commands { - public class RefreshSeriesCommand : ICommand + public class RefreshSeriesCommand : Command { - public String CommandId { get; private set; } public int? SeriesId { get; set; } public RefreshSeriesCommand() { - CommandId = HashUtil.GenerateCommandId(); } public RefreshSeriesCommand(int? seriesId) { - CommandId = HashUtil.GenerateCommandId(); - SeriesId = seriesId; } + + public override bool SendUpdatesToClient + { + get + { + return true; + } + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Tv/EpisodeRepository.cs b/NzbDrone.Core/Tv/EpisodeRepository.cs index 280dec96e..aeb54788a 100644 --- a/NzbDrone.Core/Tv/EpisodeRepository.cs +++ b/NzbDrone.Core/Tv/EpisodeRepository.cs @@ -2,8 +2,8 @@ using System.Collections.Generic; using System.Linq; using Marr.Data.QGen; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Tv diff --git a/NzbDrone.Core/Tv/EpisodeService.cs b/NzbDrone.Core/Tv/EpisodeService.cs index 11a345c46..53b30af40 100644 --- a/NzbDrone.Core/Tv/EpisodeService.cs +++ b/NzbDrone.Core/Tv/EpisodeService.cs @@ -3,10 +3,10 @@ using System.Collections.Generic; using System.Linq; using NLog; using NzbDrone.Common.Instrumentation; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Configuration; using NzbDrone.Core.Datastore; using NzbDrone.Core.MediaFiles.Events; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Tv.Events; namespace NzbDrone.Core.Tv diff --git a/NzbDrone.Core/Tv/Events/EpisodeInfoAddedEvent.cs b/NzbDrone.Core/Tv/Events/EpisodeInfoAddedEvent.cs index ff6353b9c..84d66398f 100644 --- a/NzbDrone.Core/Tv/Events/EpisodeInfoAddedEvent.cs +++ b/NzbDrone.Core/Tv/Events/EpisodeInfoAddedEvent.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Tv.Events { diff --git a/NzbDrone.Core/Tv/Events/EpisodeInfoDeletedEvent.cs b/NzbDrone.Core/Tv/Events/EpisodeInfoDeletedEvent.cs index 864445e58..362db8416 100644 --- a/NzbDrone.Core/Tv/Events/EpisodeInfoDeletedEvent.cs +++ b/NzbDrone.Core/Tv/Events/EpisodeInfoDeletedEvent.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Tv.Events { diff --git a/NzbDrone.Core/Tv/Events/EpisodeInfoUpdatedEvent.cs b/NzbDrone.Core/Tv/Events/EpisodeInfoUpdatedEvent.cs index 310e0d85d..a555ac562 100644 --- a/NzbDrone.Core/Tv/Events/EpisodeInfoUpdatedEvent.cs +++ b/NzbDrone.Core/Tv/Events/EpisodeInfoUpdatedEvent.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Tv.Events { diff --git a/NzbDrone.Core/Tv/Events/SeriesAddedEvent.cs b/NzbDrone.Core/Tv/Events/SeriesAddedEvent.cs index 1038b0926..1c6537aa3 100644 --- a/NzbDrone.Core/Tv/Events/SeriesAddedEvent.cs +++ b/NzbDrone.Core/Tv/Events/SeriesAddedEvent.cs @@ -1,4 +1,5 @@ using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Tv.Events { diff --git a/NzbDrone.Core/Tv/Events/SeriesDeletedEvent.cs b/NzbDrone.Core/Tv/Events/SeriesDeletedEvent.cs index e04d8f60e..40e288ffd 100644 --- a/NzbDrone.Core/Tv/Events/SeriesDeletedEvent.cs +++ b/NzbDrone.Core/Tv/Events/SeriesDeletedEvent.cs @@ -1,4 +1,5 @@ using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Tv.Events { diff --git a/NzbDrone.Core/Tv/Events/SeriesUpdatedEvent.cs b/NzbDrone.Core/Tv/Events/SeriesUpdatedEvent.cs index 8dafe0563..cd2c3750e 100644 --- a/NzbDrone.Core/Tv/Events/SeriesUpdatedEvent.cs +++ b/NzbDrone.Core/Tv/Events/SeriesUpdatedEvent.cs @@ -1,4 +1,5 @@ using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Tv.Events { diff --git a/NzbDrone.Core/Tv/RefreshEpisodeService.cs b/NzbDrone.Core/Tv/RefreshEpisodeService.cs index be0e6c190..e5d63d3ad 100644 --- a/NzbDrone.Core/Tv/RefreshEpisodeService.cs +++ b/NzbDrone.Core/Tv/RefreshEpisodeService.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using NLog; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Tv.Events; namespace NzbDrone.Core.Tv @@ -44,7 +44,7 @@ namespace NzbDrone.Core.Tv { try { - var episodeToUpdate = existingEpisodes.SingleOrDefault(e => e.SeasonNumber == episode.SeasonNumber && e.EpisodeNumber == episode.EpisodeNumber); + var episodeToUpdate = existingEpisodes.FirstOrDefault(e => e.SeasonNumber == episode.SeasonNumber && e.EpisodeNumber == episode.EpisodeNumber); if (episodeToUpdate != null) { diff --git a/NzbDrone.Core/Tv/RefreshSeriesService.cs b/NzbDrone.Core/Tv/RefreshSeriesService.cs index e776a4a18..683ad936e 100644 --- a/NzbDrone.Core/Tv/RefreshSeriesService.cs +++ b/NzbDrone.Core/Tv/RefreshSeriesService.cs @@ -4,8 +4,9 @@ using System.IO; using System.Linq; using NLog; using NzbDrone.Common.Instrumentation; -using NzbDrone.Common.Messaging; using NzbDrone.Core.DataAugmentation.DailySeries; +using NzbDrone.Core.Instrumentation; +using NzbDrone.Core.Messaging; using NzbDrone.Core.MetadataSource; using NzbDrone.Core.Tv.Commands; using NzbDrone.Core.Tv.Events; @@ -34,7 +35,7 @@ namespace NzbDrone.Core.Tv private void RefreshSeriesInfo(Series series) { - _logger.Progress("Starting Series Refresh for {0}", series.Title); + _logger.ProgressInfo("Updating Info for {0}", series.Title); var tuple = _seriesInfo.GetSeriesInfo(series.TvdbId); var seriesInfo = tuple.Item1; @@ -70,7 +71,7 @@ namespace NzbDrone.Core.Tv _seriesService.UpdateSeries(series); _refreshEpisodeService.RefreshEpisodeInfo(series, tuple.Item2); - _logger.Complete("Finished series refresh for {0}", series.Title); + _logger.Debug("Finished series refresh for {0}", series.Title); _messageAggregator.PublishEvent(new SeriesUpdatedEvent(series)); } diff --git a/NzbDrone.Core/Tv/SeasonRepository.cs b/NzbDrone.Core/Tv/SeasonRepository.cs index 5b9b41bfc..1b181cb9c 100644 --- a/NzbDrone.Core/Tv/SeasonRepository.cs +++ b/NzbDrone.Core/Tv/SeasonRepository.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Messaging; namespace NzbDrone.Core.Tv diff --git a/NzbDrone.Core/Tv/SeasonService.cs b/NzbDrone.Core/Tv/SeasonService.cs index f6a459f9739c96b92dd1958cc1a5021e5ad7ff7c..c3c6142ca2aabedb1366e80622a6654919940a3e 100644 GIT binary patch delta 19 bcmbQGGE-$j%EUJFiJ1x;_r?e^@p1tGPBsS2 delta 23 fcmbQKGD~Gb3QKNoe%{1ciWAdKHtvoQWMlvUZ5jxD diff --git a/NzbDrone.Core/Tv/SeriesRepository.cs b/NzbDrone.Core/Tv/SeriesRepository.cs index 83fac8844..c49531faa 100644 --- a/NzbDrone.Core/Tv/SeriesRepository.cs +++ b/NzbDrone.Core/Tv/SeriesRepository.cs @@ -1,8 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Datastore; +using NzbDrone.Core.Messaging; + namespace NzbDrone.Core.Tv { diff --git a/NzbDrone.Core/Tv/SeriesService.cs b/NzbDrone.Core/Tv/SeriesService.cs index 27aab2b7e..ec7d12899 100644 --- a/NzbDrone.Core/Tv/SeriesService.cs +++ b/NzbDrone.Core/Tv/SeriesService.cs @@ -4,9 +4,9 @@ using System.IO; using System.Linq; using NLog; using NzbDrone.Common.EnsureThat; -using NzbDrone.Common.Messaging; using NzbDrone.Core.Configuration; using NzbDrone.Core.DataAugmentation.Scene; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Organizer; using NzbDrone.Core.Tv.Events; diff --git a/NzbDrone.Core/Update/Commands/ApplicationUpdateCommand.cs b/NzbDrone.Core/Update/Commands/ApplicationUpdateCommand.cs index dd1b97d6b..f8d36a88a 100644 --- a/NzbDrone.Core/Update/Commands/ApplicationUpdateCommand.cs +++ b/NzbDrone.Core/Update/Commands/ApplicationUpdateCommand.cs @@ -1,16 +1,18 @@ using System; using NzbDrone.Common; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Update.Commands { - public class ApplicationUpdateCommand : ICommand + public class ApplicationUpdateCommand : Command { - public String CommandId { get; private set; } - - public ApplicationUpdateCommand() + public override bool SendUpdatesToClient { - CommandId = HashUtil.GenerateCommandId(); + get + { + return true; + } } } } \ No newline at end of file diff --git a/NzbDrone.Core/Update/InstallUpdateService.cs b/NzbDrone.Core/Update/InstallUpdateService.cs index d204bcab3..a11e00fef 100644 --- a/NzbDrone.Core/Update/InstallUpdateService.cs +++ b/NzbDrone.Core/Update/InstallUpdateService.cs @@ -3,8 +3,9 @@ using System.IO; using NLog; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; -using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; using NzbDrone.Core.Update.Commands; +using NzbDrone.Core.Instrumentation; namespace NzbDrone.Core.Update { @@ -36,6 +37,7 @@ namespace NzbDrone.Core.Update public void Execute(ApplicationUpdateCommand message) { + _logger.ProgressDebug("Checking for updates"); var latestAvailable = _checkUpdateService.AvailableUpdate(); if (latestAvailable != null) @@ -58,11 +60,11 @@ namespace NzbDrone.Core.Update _diskProvider.DeleteFolder(updateSandboxFolder, true); } - _logger.Info("Downloading update package from [{0}] to [{1}]", updatePackage.Url, packageDestination); + _logger.ProgressInfo("Downloading Updated {0} [{1}]", updatePackage.Version, updatePackage.Branch); + _logger.Debug("Downloading update package from [{0}] to [{1}]", updatePackage.Url, packageDestination); _httpProvider.DownloadFile(updatePackage.Url, packageDestination); - _logger.Info("Download completed for update package from [{0}]", updatePackage.FileName); - _logger.Info("Extracting Update package"); + _logger.ProgressInfo("Extracting Update package"); _archiveService.Extract(packageDestination, updateSandboxFolder); _logger.Info("Update package extracted successfully"); @@ -72,6 +74,8 @@ namespace NzbDrone.Core.Update _logger.Info("Starting update client {0}", _appFolderInfo.GetUpdateClientExePath()); + _logger.ProgressInfo("NzbDrone will restart shortly."); + _processProvider.Start(_appFolderInfo.GetUpdateClientExePath(), _processProvider.GetCurrentProcess().Id.ToString()); } catch (Exception ex) diff --git a/NzbDrone.Core/Update/UpdateCheckService.cs b/NzbDrone.Core/Update/UpdateCheckService.cs index 313f1ef58..402ba850c 100644 --- a/NzbDrone.Core/Update/UpdateCheckService.cs +++ b/NzbDrone.Core/Update/UpdateCheckService.cs @@ -1,5 +1,7 @@ using NLog; using NzbDrone.Common.EnvironmentInfo; +using NzbDrone.Core.Configuration; +using NzbDrone.Core.Instrumentation; namespace NzbDrone.Core.Update { @@ -12,23 +14,25 @@ namespace NzbDrone.Core.Update public class CheckUpdateService : ICheckUpdateService { private readonly IUpdatePackageProvider _updatePackageProvider; + private readonly IConfigFileProvider _configFileProvider; private readonly Logger _logger; - public CheckUpdateService(IUpdatePackageProvider updatePackageProvider, Logger logger) + public CheckUpdateService(IUpdatePackageProvider updatePackageProvider, IConfigFileProvider configFileProvider, Logger logger) { _updatePackageProvider = updatePackageProvider; + _configFileProvider = configFileProvider; _logger = logger; } public UpdatePackage AvailableUpdate() { - var latestAvailable = _updatePackageProvider.GetLatestUpdate(); + var latestAvailable = _updatePackageProvider.GetLatestUpdate(_configFileProvider.Branch, BuildInfo.Version); if (latestAvailable == null) { - _logger.Debug("No update available."); + _logger.ProgressDebug("No update available."); return null; } diff --git a/NzbDrone.Core/Update/UpdatePackage.cs b/NzbDrone.Core/Update/UpdatePackage.cs index ce038ac99..70ca40b87 100644 --- a/NzbDrone.Core/Update/UpdatePackage.cs +++ b/NzbDrone.Core/Update/UpdatePackage.cs @@ -1,13 +1,14 @@ using System; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace NzbDrone.Core.Update { public class UpdatePackage { - public String Id { get; set; } + public string Id { get; set; } - [JsonConverter(typeof(Newtonsoft.Json.Converters.VersionConverter))] + [JsonConverter(typeof(VersionConverter))] public Version Version { get; set; } public String Branch { get; set; } diff --git a/NzbDrone.Core/Update/UpdatePackageAvailable.cs b/NzbDrone.Core/Update/UpdatePackageAvailable.cs index 1d76e22d7..c6b99b446 100644 --- a/NzbDrone.Core/Update/UpdatePackageAvailable.cs +++ b/NzbDrone.Core/Update/UpdatePackageAvailable.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace NzbDrone.Core.Update { diff --git a/NzbDrone.Core/Update/UpdatePackageProvider.cs b/NzbDrone.Core/Update/UpdatePackageProvider.cs index e045a89fd..e6b138e5a 100644 --- a/NzbDrone.Core/Update/UpdatePackageProvider.cs +++ b/NzbDrone.Core/Update/UpdatePackageProvider.cs @@ -1,37 +1,29 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.RegularExpressions; -using Newtonsoft.Json; -using NLog; using NzbDrone.Common; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Core.Configuration; +using RestSharp; +using NzbDrone.Core.Rest; namespace NzbDrone.Core.Update { public interface IUpdatePackageProvider { - UpdatePackage GetLatestUpdate(); + UpdatePackage GetLatestUpdate(string branch, Version currentVersion); } public class UpdatePackageProvider : IUpdatePackageProvider { - private readonly IConfigFileProvider _configFileProvider; - private readonly IHttpProvider _httpProvider; - private readonly Logger _logger; - - public UpdatePackageProvider(IConfigFileProvider configFileProvider, IHttpProvider httpProvider, Logger logger) + public UpdatePackage GetLatestUpdate(string branch, Version currentVersion) { - _configFileProvider = configFileProvider; - _httpProvider = httpProvider; - _logger = logger; - } + var restClient = new RestClient(Services.RootUrl); - public UpdatePackage GetLatestUpdate() - { - var url = String.Format("{0}/v1/update/{1}?version={2}", Services.RootUrl, _configFileProvider.Branch, BuildInfo.Version); - var update = JsonConvert.DeserializeObject(_httpProvider.DownloadString(url)); + var request = new RestRequest("/v1/update/{branch}"); + + request.AddParameter("version", currentVersion); + request.AddUrlSegment("branch", branch); + + var update = restClient.ExecuteAndValidate(request); if (!update.Available) return null; diff --git a/NzbDrone.Core/progressmessaging/CommandUpdatedEvent.cs b/NzbDrone.Core/progressmessaging/CommandUpdatedEvent.cs new file mode 100644 index 000000000..2d8c93269 --- /dev/null +++ b/NzbDrone.Core/progressmessaging/CommandUpdatedEvent.cs @@ -0,0 +1,15 @@ +using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging.Commands; + +namespace NzbDrone.Core.ProgressMessaging +{ + public class CommandUpdatedEvent : IEvent + { + public Command Command { get; set; } + + public CommandUpdatedEvent(Command command) + { + Command = command; + } + } +} diff --git a/NzbDrone.Host/MainAppContainerBuilder.cs b/NzbDrone.Host/MainAppContainerBuilder.cs index e12fc9153..299de7925 100644 --- a/NzbDrone.Host/MainAppContainerBuilder.cs +++ b/NzbDrone.Host/MainAppContainerBuilder.cs @@ -1,13 +1,11 @@ -using System; -using Nancy.Bootstrapper; +using Nancy.Bootstrapper; using NzbDrone.Api; -using NzbDrone.Api.SignalR; using NzbDrone.Common.Composition; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Core.Datastore; using NzbDrone.Core.Organizer; using NzbDrone.Core.RootFolders; -using NzbDrone.Host.Owin; +using NzbDrone.SignalR; namespace NzbDrone.Host { @@ -19,7 +17,7 @@ namespace NzbDrone.Host } private MainAppContainerBuilder(StartupArguments args) - : base(args, "NzbDrone.Host", "NzbDrone.Common", "NzbDrone.Core", "NzbDrone.Api") + : base(args, "NzbDrone.Host", "NzbDrone.Common", "NzbDrone.Core", "NzbDrone.Api", "NzbDrone.SignalR") { AutoRegisterImplementations(); diff --git a/NzbDrone.Host/NzbDrone.Host.csproj b/NzbDrone.Host/NzbDrone.Host.csproj index ad7214da7..7ecf58a13 100644 --- a/NzbDrone.Host/NzbDrone.Host.csproj +++ b/NzbDrone.Host/NzbDrone.Host.csproj @@ -185,6 +185,13 @@ {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205} NzbDrone.Core + + {7C2CC69F-5CA0-4E5C-85CB-983F9F6C3B36} + NzbDrone.SignalR + + + + diff --git a/NzbDrone.Host/Owin/MiddleWare/SignalRMiddleWare.cs b/NzbDrone.Host/Owin/MiddleWare/SignalRMiddleWare.cs index 61c7cd92a..cf4396edf 100644 --- a/NzbDrone.Host/Owin/MiddleWare/SignalRMiddleWare.cs +++ b/NzbDrone.Host/Owin/MiddleWare/SignalRMiddleWare.cs @@ -1,22 +1,17 @@ using System; -using System.Collections.Generic; using Microsoft.AspNet.SignalR; -using NzbDrone.Api.SignalR; using NzbDrone.Common.Composition; +using NzbDrone.SignalR; using Owin; namespace NzbDrone.Host.Owin.MiddleWare { public class SignalRMiddleWare : IOwinMiddleWare { - private readonly IEnumerable _persistentConnections; - public int Order { get { return 0; } } - public SignalRMiddleWare(IEnumerable persistentConnections, IContainer container) + public SignalRMiddleWare(IContainer container) { - _persistentConnections = persistentConnections; - SignalrDependencyResolver.Register(container); GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(300000); @@ -24,12 +19,7 @@ namespace NzbDrone.Host.Owin.MiddleWare public void Attach(IAppBuilder appBuilder) { - foreach (var nzbDronePersistentConnection in _persistentConnections) - { - var url = string.Format("signalr/{0}", nzbDronePersistentConnection.Resource.Trim('/')); - appBuilder.MapConnection(url, nzbDronePersistentConnection.GetType(), new ConnectionConfiguration { EnableCrossDomain = true }); - } - + appBuilder.MapConnection("signalr", typeof(NzbDronePersistentConnection), new ConnectionConfiguration { EnableCrossDomain = true }); } } } \ No newline at end of file diff --git a/NzbDrone.Host/Owin/NlogTextWriter.cs b/NzbDrone.Host/Owin/NlogTextWriter.cs index fb912893f..d5b4d04aa 100644 --- a/NzbDrone.Host/Owin/NlogTextWriter.cs +++ b/NzbDrone.Host/Owin/NlogTextWriter.cs @@ -7,7 +7,7 @@ namespace NzbDrone.Host.Owin { public class NlogTextWriter : TextWriter { - private readonly Logger logger = NzbDroneLogger.GetLogger(); + private readonly Logger _logger = NzbDroneLogger.GetLogger(); public override Encoding Encoding @@ -18,25 +18,23 @@ namespace NzbDrone.Host.Owin } } - public override void Write(char value) + public override void Write(char[] buffer, int index, int count) { - logger.Trace(value); + Write(buffer); } - public override void Write(char[] buffer) { - logger.Trace(buffer); + Write(new string(buffer)); } public override void Write(string value) { - logger.Trace(value); + _logger.Trace(value); } - public override void Write(char[] buffer, int index, int count) + public override void Write(char value) { - logger.Trace(buffer); + _logger.Trace(value); } - } } \ No newline at end of file diff --git a/NzbDrone.Integration.Test/CommandIntegerationTests.cs b/NzbDrone.Integration.Test/CommandIntegerationTests.cs index cfd89178e..1dbe33b67 100644 --- a/NzbDrone.Integration.Test/CommandIntegerationTests.cs +++ b/NzbDrone.Integration.Test/CommandIntegerationTests.cs @@ -2,7 +2,6 @@ using FluentAssertions; using NUnit.Framework; using NzbDrone.Api.Commands; -using NzbDrone.Common.Messaging.Tracking; using NzbDrone.Common.Serializer; using RestSharp; @@ -21,7 +20,7 @@ namespace NzbDrone.Integration.Test Method = Method.POST }; - request.AddBody(new CommandResource {Command = "rsssync"}); + request.AddBody(new CommandResource { Name = "rsssync" }); var restClient = new RestClient("http://localhost:8989/api"); var response = restClient.Execute(request); @@ -34,8 +33,8 @@ namespace NzbDrone.Integration.Test response.ErrorMessage.Should().BeBlank(); response.StatusCode.Should().Be(HttpStatusCode.Created); - var trackedCommand = Json.Deserialize(response.Content); - trackedCommand.Id.Should().NotBeNullOrEmpty(); + var trackedCommand = Json.Deserialize(response.Content); + trackedCommand.Id.Should().NotBe(0); } } } \ No newline at end of file diff --git a/NzbDrone.SignalR/BroadcastSignalRMessage.cs b/NzbDrone.SignalR/BroadcastSignalRMessage.cs new file mode 100644 index 000000000..d540ab6fc --- /dev/null +++ b/NzbDrone.SignalR/BroadcastSignalRMessage.cs @@ -0,0 +1,12 @@ +namespace NzbDrone.SignalR +{ + public class BroadcastSignalRMessage : Core.Messaging.Commands.Command + { + public SignalRMessage Body { get; private set; } + + public BroadcastSignalRMessage(SignalRMessage body) + { + Body = body; + } + } +} \ No newline at end of file diff --git a/NzbDrone.Api/SignalR/NoOpPerformanceCounterManager.cs b/NzbDrone.SignalR/NoOpPerformanceCounterManager.cs similarity index 99% rename from NzbDrone.Api/SignalR/NoOpPerformanceCounterManager.cs rename to NzbDrone.SignalR/NoOpPerformanceCounterManager.cs index a3e3d7c1f..2eec1b004 100644 --- a/NzbDrone.Api/SignalR/NoOpPerformanceCounterManager.cs +++ b/NzbDrone.SignalR/NoOpPerformanceCounterManager.cs @@ -2,7 +2,7 @@ using System.Threading; using Microsoft.AspNet.SignalR.Infrastructure; -namespace NzbDrone.Api.SignalR +namespace NzbDrone.SignalR { public class NoOpPerformanceCounterManager : IPerformanceCounterManager { diff --git a/NzbDrone.SignalR/NzbDrone.SignalR.csproj b/NzbDrone.SignalR/NzbDrone.SignalR.csproj new file mode 100644 index 000000000..859651305 --- /dev/null +++ b/NzbDrone.SignalR/NzbDrone.SignalR.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {7C2CC69F-5CA0-4E5C-85CB-983F9F6C3B36} + Library + Properties + NzbDrone.SignalR + NzbDrone.SignalR + v4.0 + 512 + ..\ + true + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + + + + ..\packages\Microsoft.AspNet.SignalR.Core.1.1.3\lib\net40\Microsoft.AspNet.SignalR.Core.dll + + + ..\packages\Newtonsoft.Json.5.0.6\lib\net40\Newtonsoft.Json.dll + + + + + + + + Properties\SharedAssemblyInfo.cs + + + + + + + + + + + + + + + {f2be0fdf-6e47-4827-a420-dd4ef82407f8} + NzbDrone.Common + + + {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205} + NzbDrone.Core + + + + + + \ No newline at end of file diff --git a/NzbDrone.SignalR/NzbDronePersistentConnection.cs b/NzbDrone.SignalR/NzbDronePersistentConnection.cs new file mode 100644 index 000000000..748a11bb5 --- /dev/null +++ b/NzbDrone.SignalR/NzbDronePersistentConnection.cs @@ -0,0 +1,23 @@ +using Microsoft.AspNet.SignalR; +using Microsoft.AspNet.SignalR.Infrastructure; +using NzbDrone.Core.Messaging; + +namespace NzbDrone.SignalR +{ + public sealed class NzbDronePersistentConnection : PersistentConnection, IExecute + { + private IPersistentConnectionContext Context + { + get + { + return ((ConnectionManager)GlobalHost.ConnectionManager).GetConnection(GetType()); + } + } + + + public void Execute(BroadcastSignalRMessage message) + { + Context.Connection.Broadcast(message.Body); + } + } +} \ No newline at end of file diff --git a/NzbDrone.SignalR/Properties/AssemblyInfo.cs b/NzbDrone.SignalR/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..ffaa67fdd --- /dev/null +++ b/NzbDrone.SignalR/Properties/AssemblyInfo.cs @@ -0,0 +1,11 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("NzbDrone.SignalR")] +[assembly: Guid("98bd985a-4f23-4201-8ed3-f6f3d7f2a5fe")] + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/NzbDrone.Api/SignalR/Serializer.cs b/NzbDrone.SignalR/Serializer.cs similarity index 95% rename from NzbDrone.Api/SignalR/Serializer.cs rename to NzbDrone.SignalR/Serializer.cs index 4ab2bfc01..e631ef146 100644 --- a/NzbDrone.Api/SignalR/Serializer.cs +++ b/NzbDrone.SignalR/Serializer.cs @@ -3,7 +3,7 @@ using System.IO; using Microsoft.AspNet.SignalR.Json; using NzbDrone.Common.Serializer; -namespace NzbDrone.Api.SignalR +namespace NzbDrone.SignalR { public class Serializer : IJsonSerializer { diff --git a/NzbDrone.SignalR/SignalRMessage.cs b/NzbDrone.SignalR/SignalRMessage.cs new file mode 100644 index 000000000..e8993c286 --- /dev/null +++ b/NzbDrone.SignalR/SignalRMessage.cs @@ -0,0 +1,8 @@ +namespace NzbDrone.SignalR +{ + public class SignalRMessage + { + public object Body { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/NzbDrone.Api/SignalR/SignalrDependencyResolver.cs b/NzbDrone.SignalR/SignalrDependencyResolver.cs similarity index 96% rename from NzbDrone.Api/SignalR/SignalrDependencyResolver.cs rename to NzbDrone.SignalR/SignalrDependencyResolver.cs index f95f9ae5a..a3633cbae 100644 --- a/NzbDrone.Api/SignalR/SignalrDependencyResolver.cs +++ b/NzbDrone.SignalR/SignalrDependencyResolver.cs @@ -3,7 +3,7 @@ using Microsoft.AspNet.SignalR; using Microsoft.AspNet.SignalR.Infrastructure; using NzbDrone.Common.Composition; -namespace NzbDrone.Api.SignalR +namespace NzbDrone.SignalR { public class SignalrDependencyResolver : DefaultDependencyResolver { diff --git a/NzbDrone.SignalR/packages.config b/NzbDrone.SignalR/packages.config new file mode 100644 index 000000000..f82b57a29 --- /dev/null +++ b/NzbDrone.SignalR/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/NzbDrone.Test.Common/TestBase.cs b/NzbDrone.Test.Common/TestBase.cs index 266de4463..2b3d8ec47 100644 --- a/NzbDrone.Test.Common/TestBase.cs +++ b/NzbDrone.Test.Common/TestBase.cs @@ -9,6 +9,7 @@ using NzbDrone.Common; using NzbDrone.Common.Cache; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Messaging; +using NzbDrone.Core.Messaging; using NzbDrone.Test.Common.AutoMoq; namespace NzbDrone.Test.Common diff --git a/NzbDrone.sln b/NzbDrone.sln index 4fa697bac..f118155ff 100644 --- a/NzbDrone.sln +++ b/NzbDrone.sln @@ -56,92 +56,228 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Host", "NzbDrone.H EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Host", "Host", "{486ADF86-DD89-4E19-B805-9D94F19800D9}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.SignalR", "NzbDrone.SignalR\NzbDrone.SignalR.csproj", "{7C2CC69F-5CA0-4E5C-85CB-983F9F6C3B36}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|Mixed Platforms = Debug|Mixed Platforms Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|Mixed Platforms = Release|Mixed Platforms Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Debug|Any CPU.ActiveCfg = Debug|x86 + {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Debug|Mixed Platforms.Build.0 = Debug|x86 {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Debug|x86.ActiveCfg = Debug|x86 {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Debug|x86.Build.0 = Debug|x86 + {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Release|Any CPU.ActiveCfg = Release|x86 + {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Release|Mixed Platforms.Build.0 = Release|x86 {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Release|x86.ActiveCfg = Release|x86 {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Release|x86.Build.0 = Release|x86 + {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}.Debug|Any CPU.ActiveCfg = Debug|x86 + {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}.Debug|Mixed Platforms.Build.0 = Debug|x86 {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}.Debug|x86.ActiveCfg = Debug|x86 {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}.Debug|x86.Build.0 = Debug|x86 + {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}.Release|Any CPU.ActiveCfg = Release|x86 + {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}.Release|Mixed Platforms.Build.0 = Release|x86 {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}.Release|x86.ActiveCfg = Release|x86 {FF5EE3B6-913B-47CE-9CEB-11C51B4E1205}.Release|x86.Build.0 = Release|x86 + {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|Any CPU.ActiveCfg = Debug|x86 + {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|Mixed Platforms.Build.0 = Debug|x86 {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|x86.ActiveCfg = Debug|x86 {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|x86.Build.0 = Debug|x86 + {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Release|Any CPU.ActiveCfg = Release|x86 + {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Release|Mixed Platforms.Build.0 = Release|x86 {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Release|x86.ActiveCfg = Release|x86 {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Release|x86.Build.0 = Release|x86 + {C0EA1A40-91AD-4EEB-BD16-2DDDEBD20AE5}.Debug|Any CPU.ActiveCfg = Debug|x86 + {C0EA1A40-91AD-4EEB-BD16-2DDDEBD20AE5}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {C0EA1A40-91AD-4EEB-BD16-2DDDEBD20AE5}.Debug|Mixed Platforms.Build.0 = Debug|x86 {C0EA1A40-91AD-4EEB-BD16-2DDDEBD20AE5}.Debug|x86.ActiveCfg = Debug|x86 {C0EA1A40-91AD-4EEB-BD16-2DDDEBD20AE5}.Debug|x86.Build.0 = Debug|x86 + {C0EA1A40-91AD-4EEB-BD16-2DDDEBD20AE5}.Release|Any CPU.ActiveCfg = Release|x86 + {C0EA1A40-91AD-4EEB-BD16-2DDDEBD20AE5}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {C0EA1A40-91AD-4EEB-BD16-2DDDEBD20AE5}.Release|Mixed Platforms.Build.0 = Release|x86 {C0EA1A40-91AD-4EEB-BD16-2DDDEBD20AE5}.Release|x86.ActiveCfg = Release|x86 {C0EA1A40-91AD-4EEB-BD16-2DDDEBD20AE5}.Release|x86.Build.0 = Release|x86 + {FAFB5948-A222-4CF6-AD14-026BE7564802}.Debug|Any CPU.ActiveCfg = Debug|x86 + {FAFB5948-A222-4CF6-AD14-026BE7564802}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {FAFB5948-A222-4CF6-AD14-026BE7564802}.Debug|Mixed Platforms.Build.0 = Debug|x86 {FAFB5948-A222-4CF6-AD14-026BE7564802}.Debug|x86.ActiveCfg = Debug|x86 {FAFB5948-A222-4CF6-AD14-026BE7564802}.Debug|x86.Build.0 = Debug|x86 + {FAFB5948-A222-4CF6-AD14-026BE7564802}.Release|Any CPU.ActiveCfg = Release|x86 + {FAFB5948-A222-4CF6-AD14-026BE7564802}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {FAFB5948-A222-4CF6-AD14-026BE7564802}.Release|Mixed Platforms.Build.0 = Release|x86 {FAFB5948-A222-4CF6-AD14-026BE7564802}.Release|x86.ActiveCfg = Release|x86 {FAFB5948-A222-4CF6-AD14-026BE7564802}.Release|x86.Build.0 = Release|x86 + {4CCC53CD-8D5E-4CC4-97D2-5C9312AC2BD7}.Debug|Any CPU.ActiveCfg = Debug|x86 + {4CCC53CD-8D5E-4CC4-97D2-5C9312AC2BD7}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {4CCC53CD-8D5E-4CC4-97D2-5C9312AC2BD7}.Debug|Mixed Platforms.Build.0 = Debug|x86 {4CCC53CD-8D5E-4CC4-97D2-5C9312AC2BD7}.Debug|x86.ActiveCfg = Debug|x86 {4CCC53CD-8D5E-4CC4-97D2-5C9312AC2BD7}.Debug|x86.Build.0 = Debug|x86 + {4CCC53CD-8D5E-4CC4-97D2-5C9312AC2BD7}.Release|Any CPU.ActiveCfg = Release|x86 + {4CCC53CD-8D5E-4CC4-97D2-5C9312AC2BD7}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {4CCC53CD-8D5E-4CC4-97D2-5C9312AC2BD7}.Release|Mixed Platforms.Build.0 = Release|x86 {4CCC53CD-8D5E-4CC4-97D2-5C9312AC2BD7}.Release|x86.ActiveCfg = Release|x86 {4CCC53CD-8D5E-4CC4-97D2-5C9312AC2BD7}.Release|x86.Build.0 = Release|x86 + {35388E8E-0CDB-4A84-AD16-E4B6EFDA5D97}.Debug|Any CPU.ActiveCfg = Debug|x86 + {35388E8E-0CDB-4A84-AD16-E4B6EFDA5D97}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {35388E8E-0CDB-4A84-AD16-E4B6EFDA5D97}.Debug|Mixed Platforms.Build.0 = Debug|x86 {35388E8E-0CDB-4A84-AD16-E4B6EFDA5D97}.Debug|x86.ActiveCfg = Debug|x86 {35388E8E-0CDB-4A84-AD16-E4B6EFDA5D97}.Debug|x86.Build.0 = Debug|x86 + {35388E8E-0CDB-4A84-AD16-E4B6EFDA5D97}.Release|Any CPU.ActiveCfg = Release|x86 + {35388E8E-0CDB-4A84-AD16-E4B6EFDA5D97}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {35388E8E-0CDB-4A84-AD16-E4B6EFDA5D97}.Release|Mixed Platforms.Build.0 = Release|x86 {35388E8E-0CDB-4A84-AD16-E4B6EFDA5D97}.Release|x86.ActiveCfg = Release|x86 {35388E8E-0CDB-4A84-AD16-E4B6EFDA5D97}.Release|x86.Build.0 = Release|x86 + {F2BE0FDF-6E47-4827-A420-DD4EF82407F8}.Debug|Any CPU.ActiveCfg = Debug|x86 + {F2BE0FDF-6E47-4827-A420-DD4EF82407F8}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {F2BE0FDF-6E47-4827-A420-DD4EF82407F8}.Debug|Mixed Platforms.Build.0 = Debug|x86 {F2BE0FDF-6E47-4827-A420-DD4EF82407F8}.Debug|x86.ActiveCfg = Debug|x86 {F2BE0FDF-6E47-4827-A420-DD4EF82407F8}.Debug|x86.Build.0 = Debug|x86 + {F2BE0FDF-6E47-4827-A420-DD4EF82407F8}.Release|Any CPU.ActiveCfg = Release|x86 + {F2BE0FDF-6E47-4827-A420-DD4EF82407F8}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {F2BE0FDF-6E47-4827-A420-DD4EF82407F8}.Release|Mixed Platforms.Build.0 = Release|x86 {F2BE0FDF-6E47-4827-A420-DD4EF82407F8}.Release|x86.ActiveCfg = Release|x86 {F2BE0FDF-6E47-4827-A420-DD4EF82407F8}.Release|x86.Build.0 = Release|x86 + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Debug|Any CPU.ActiveCfg = Debug|x86 + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Debug|Mixed Platforms.Build.0 = Debug|x86 {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Debug|x86.ActiveCfg = Debug|x86 {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Debug|x86.Build.0 = Debug|x86 + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Release|Any CPU.ActiveCfg = Release|x86 + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Release|Mixed Platforms.Build.0 = Release|x86 {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Release|x86.ActiveCfg = Release|x86 {BEC74619-DDBB-4FBA-B517-D3E20AFC9997}.Release|x86.Build.0 = Release|x86 + {CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Debug|Any CPU.ActiveCfg = Debug|x86 + {CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Debug|Mixed Platforms.Build.0 = Debug|x86 {CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Debug|x86.ActiveCfg = Debug|x86 {CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Debug|x86.Build.0 = Debug|x86 + {CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Release|Any CPU.ActiveCfg = Release|x86 + {CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Release|Mixed Platforms.Build.0 = Release|x86 {CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Release|x86.ActiveCfg = Release|x86 {CADDFCE0-7509-4430-8364-2074E1EEFCA2}.Release|x86.Build.0 = Release|x86 + {6BCE712F-846D-4846-9D1B-A66B858DA755}.Debug|Any CPU.ActiveCfg = Debug|x86 + {6BCE712F-846D-4846-9D1B-A66B858DA755}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {6BCE712F-846D-4846-9D1B-A66B858DA755}.Debug|Mixed Platforms.Build.0 = Debug|x86 {6BCE712F-846D-4846-9D1B-A66B858DA755}.Debug|x86.ActiveCfg = Debug|x86 {6BCE712F-846D-4846-9D1B-A66B858DA755}.Debug|x86.Build.0 = Debug|x86 + {6BCE712F-846D-4846-9D1B-A66B858DA755}.Release|Any CPU.ActiveCfg = Release|x86 + {6BCE712F-846D-4846-9D1B-A66B858DA755}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {6BCE712F-846D-4846-9D1B-A66B858DA755}.Release|Mixed Platforms.Build.0 = Release|x86 {6BCE712F-846D-4846-9D1B-A66B858DA755}.Release|x86.ActiveCfg = Release|x86 {6BCE712F-846D-4846-9D1B-A66B858DA755}.Release|x86.Build.0 = Release|x86 + {700D0B95-95CD-43F3-B6C9-FAA0FC1358D4}.Debug|Any CPU.ActiveCfg = Debug|x86 + {700D0B95-95CD-43F3-B6C9-FAA0FC1358D4}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {700D0B95-95CD-43F3-B6C9-FAA0FC1358D4}.Debug|Mixed Platforms.Build.0 = Debug|x86 {700D0B95-95CD-43F3-B6C9-FAA0FC1358D4}.Debug|x86.ActiveCfg = Debug|x86 {700D0B95-95CD-43F3-B6C9-FAA0FC1358D4}.Debug|x86.Build.0 = Debug|x86 + {700D0B95-95CD-43F3-B6C9-FAA0FC1358D4}.Release|Any CPU.ActiveCfg = Release|x86 + {700D0B95-95CD-43F3-B6C9-FAA0FC1358D4}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {700D0B95-95CD-43F3-B6C9-FAA0FC1358D4}.Release|Mixed Platforms.Build.0 = Release|x86 {700D0B95-95CD-43F3-B6C9-FAA0FC1358D4}.Release|x86.ActiveCfg = Release|x86 {700D0B95-95CD-43F3-B6C9-FAA0FC1358D4}.Release|x86.Build.0 = Release|x86 + {FD286DF8-2D3A-4394-8AD5-443FADE55FB2}.Debug|Any CPU.ActiveCfg = Debug|x86 + {FD286DF8-2D3A-4394-8AD5-443FADE55FB2}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {FD286DF8-2D3A-4394-8AD5-443FADE55FB2}.Debug|Mixed Platforms.Build.0 = Debug|x86 {FD286DF8-2D3A-4394-8AD5-443FADE55FB2}.Debug|x86.ActiveCfg = Debug|x86 {FD286DF8-2D3A-4394-8AD5-443FADE55FB2}.Debug|x86.Build.0 = Debug|x86 + {FD286DF8-2D3A-4394-8AD5-443FADE55FB2}.Release|Any CPU.ActiveCfg = Release|x86 + {FD286DF8-2D3A-4394-8AD5-443FADE55FB2}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {FD286DF8-2D3A-4394-8AD5-443FADE55FB2}.Release|Mixed Platforms.Build.0 = Release|x86 {FD286DF8-2D3A-4394-8AD5-443FADE55FB2}.Release|x86.ActiveCfg = Release|x86 {FD286DF8-2D3A-4394-8AD5-443FADE55FB2}.Release|x86.Build.0 = Release|x86 + {3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Debug|Any CPU.ActiveCfg = Debug|x86 + {3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Debug|Mixed Platforms.Build.0 = Debug|x86 {3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Debug|x86.ActiveCfg = Debug|x86 {3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Debug|x86.Build.0 = Debug|x86 + {3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Release|Any CPU.ActiveCfg = Release|x86 + {3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Release|Mixed Platforms.Build.0 = Release|x86 {3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Release|x86.ActiveCfg = Release|x86 {3DCA7B58-B8B3-49AC-9D9E-56F4A0460976}.Release|x86.Build.0 = Release|x86 + {D18A5DEB-5102-4775-A1AF-B75DAAA8907B}.Debug|Any CPU.ActiveCfg = Debug|x86 + {D18A5DEB-5102-4775-A1AF-B75DAAA8907B}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {D18A5DEB-5102-4775-A1AF-B75DAAA8907B}.Debug|Mixed Platforms.Build.0 = Debug|x86 {D18A5DEB-5102-4775-A1AF-B75DAAA8907B}.Debug|x86.ActiveCfg = Debug|x86 {D18A5DEB-5102-4775-A1AF-B75DAAA8907B}.Debug|x86.Build.0 = Debug|x86 + {D18A5DEB-5102-4775-A1AF-B75DAAA8907B}.Release|Any CPU.ActiveCfg = Release|x86 + {D18A5DEB-5102-4775-A1AF-B75DAAA8907B}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {D18A5DEB-5102-4775-A1AF-B75DAAA8907B}.Release|Mixed Platforms.Build.0 = Release|x86 {D18A5DEB-5102-4775-A1AF-B75DAAA8907B}.Release|x86.ActiveCfg = Release|x86 {D18A5DEB-5102-4775-A1AF-B75DAAA8907B}.Release|x86.Build.0 = Release|x86 + {F6FC6BE7-0847-4817-A1ED-223DC647C3D7}.Debug|Any CPU.ActiveCfg = Debug|x86 + {F6FC6BE7-0847-4817-A1ED-223DC647C3D7}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {F6FC6BE7-0847-4817-A1ED-223DC647C3D7}.Debug|Mixed Platforms.Build.0 = Debug|x86 {F6FC6BE7-0847-4817-A1ED-223DC647C3D7}.Debug|x86.ActiveCfg = Debug|x86 {F6FC6BE7-0847-4817-A1ED-223DC647C3D7}.Debug|x86.Build.0 = Debug|x86 + {F6FC6BE7-0847-4817-A1ED-223DC647C3D7}.Release|Any CPU.ActiveCfg = Release|x86 + {F6FC6BE7-0847-4817-A1ED-223DC647C3D7}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {F6FC6BE7-0847-4817-A1ED-223DC647C3D7}.Release|Mixed Platforms.Build.0 = Release|x86 {F6FC6BE7-0847-4817-A1ED-223DC647C3D7}.Release|x86.ActiveCfg = Release|x86 {F6FC6BE7-0847-4817-A1ED-223DC647C3D7}.Release|x86.Build.0 = Release|x86 + {CBF6B8B0-A015-413A-8C86-01238BB45770}.Debug|Any CPU.ActiveCfg = Debug|x86 + {CBF6B8B0-A015-413A-8C86-01238BB45770}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {CBF6B8B0-A015-413A-8C86-01238BB45770}.Debug|Mixed Platforms.Build.0 = Debug|x86 {CBF6B8B0-A015-413A-8C86-01238BB45770}.Debug|x86.ActiveCfg = Debug|x86 {CBF6B8B0-A015-413A-8C86-01238BB45770}.Debug|x86.Build.0 = Debug|x86 + {CBF6B8B0-A015-413A-8C86-01238BB45770}.Release|Any CPU.ActiveCfg = Release|x86 + {CBF6B8B0-A015-413A-8C86-01238BB45770}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {CBF6B8B0-A015-413A-8C86-01238BB45770}.Release|Mixed Platforms.Build.0 = Release|x86 {CBF6B8B0-A015-413A-8C86-01238BB45770}.Release|x86.ActiveCfg = Release|x86 {CBF6B8B0-A015-413A-8C86-01238BB45770}.Release|x86.Build.0 = Release|x86 + {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Debug|Any CPU.ActiveCfg = Debug|x86 + {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Debug|Mixed Platforms.Build.0 = Debug|x86 {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Debug|x86.ActiveCfg = Debug|x86 {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Debug|x86.Build.0 = Debug|x86 + {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Release|Any CPU.ActiveCfg = Release|x86 + {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Release|Mixed Platforms.Build.0 = Release|x86 {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Release|x86.ActiveCfg = Release|x86 {8CEFECD0-A6C2-498F-98B1-3FBE5820F9AB}.Release|x86.Build.0 = Release|x86 + {B1784698-592E-4132-BDFA-9817409E3A96}.Debug|Any CPU.ActiveCfg = Debug|x86 + {B1784698-592E-4132-BDFA-9817409E3A96}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {B1784698-592E-4132-BDFA-9817409E3A96}.Debug|Mixed Platforms.Build.0 = Debug|x86 {B1784698-592E-4132-BDFA-9817409E3A96}.Debug|x86.ActiveCfg = Debug|x86 {B1784698-592E-4132-BDFA-9817409E3A96}.Debug|x86.Build.0 = Debug|x86 + {B1784698-592E-4132-BDFA-9817409E3A96}.Release|Any CPU.ActiveCfg = Release|x86 + {B1784698-592E-4132-BDFA-9817409E3A96}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {B1784698-592E-4132-BDFA-9817409E3A96}.Release|Mixed Platforms.Build.0 = Release|x86 {B1784698-592E-4132-BDFA-9817409E3A96}.Release|x86.ActiveCfg = Release|x86 {B1784698-592E-4132-BDFA-9817409E3A96}.Release|x86.Build.0 = Release|x86 + {95C11A9E-56ED-456A-8447-2C89C1139266}.Debug|Any CPU.ActiveCfg = Debug|x86 + {95C11A9E-56ED-456A-8447-2C89C1139266}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {95C11A9E-56ED-456A-8447-2C89C1139266}.Debug|Mixed Platforms.Build.0 = Debug|x86 {95C11A9E-56ED-456A-8447-2C89C1139266}.Debug|x86.ActiveCfg = Debug|x86 {95C11A9E-56ED-456A-8447-2C89C1139266}.Debug|x86.Build.0 = Debug|x86 + {95C11A9E-56ED-456A-8447-2C89C1139266}.Release|Any CPU.ActiveCfg = Release|x86 + {95C11A9E-56ED-456A-8447-2C89C1139266}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {95C11A9E-56ED-456A-8447-2C89C1139266}.Release|Mixed Platforms.Build.0 = Release|x86 {95C11A9E-56ED-456A-8447-2C89C1139266}.Release|x86.ActiveCfg = Release|x86 {95C11A9E-56ED-456A-8447-2C89C1139266}.Release|x86.Build.0 = Release|x86 + {7C2CC69F-5CA0-4E5C-85CB-983F9F6C3B36}.Debug|Any CPU.ActiveCfg = Debug|x86 + {7C2CC69F-5CA0-4E5C-85CB-983F9F6C3B36}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {7C2CC69F-5CA0-4E5C-85CB-983F9F6C3B36}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {7C2CC69F-5CA0-4E5C-85CB-983F9F6C3B36}.Debug|x86.ActiveCfg = Debug|x86 + {7C2CC69F-5CA0-4E5C-85CB-983F9F6C3B36}.Debug|x86.Build.0 = Debug|x86 + {7C2CC69F-5CA0-4E5C-85CB-983F9F6C3B36}.Release|Any CPU.ActiveCfg = Release|x86 + {7C2CC69F-5CA0-4E5C-85CB-983F9F6C3B36}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {7C2CC69F-5CA0-4E5C-85CB-983F9F6C3B36}.Release|Mixed Platforms.Build.0 = Release|x86 + {7C2CC69F-5CA0-4E5C-85CB-983F9F6C3B36}.Release|x86.ActiveCfg = Release|x86 + {7C2CC69F-5CA0-4E5C-85CB-983F9F6C3B36}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -159,9 +295,9 @@ Global {CADDFCE0-7509-4430-8364-2074E1EEFCA2} = {47697CDB-27B6-4B05-B4F8-0CBE6F6EDF97} {6BCE712F-846D-4846-9D1B-A66B858DA755} = {F9E67978-5CD6-4A5F-827B-4249711C0B02} {700D0B95-95CD-43F3-B6C9-FAA0FC1358D4} = {F9E67978-5CD6-4A5F-827B-4249711C0B02} - {D12F7F2F-8A3C-415F-88FA-6DD061A84869} = {486ADF86-DD89-4E19-B805-9D94F19800D9} {3DCA7B58-B8B3-49AC-9D9E-56F4A0460976} = {486ADF86-DD89-4E19-B805-9D94F19800D9} {95C11A9E-56ED-456A-8447-2C89C1139266} = {486ADF86-DD89-4E19-B805-9D94F19800D9} + {D12F7F2F-8A3C-415F-88FA-6DD061A84869} = {486ADF86-DD89-4E19-B805-9D94F19800D9} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EnterpriseLibraryConfigurationToolBinariesPath = packages\Unity.2.1.505.0\lib\NET35;packages\Unity.2.1.505.2\lib\NET35 diff --git a/UI/AddSeries/AddSeriesTemplate.html b/UI/AddSeries/AddSeriesTemplate.html index 87715f2b1..696eb92f7 100644 --- a/UI/AddSeries/AddSeriesTemplate.html +++ b/UI/AddSeries/AddSeriesTemplate.html @@ -1,9 +1,9 @@ {{#if folder.path}} -
-
- {{folder.path}} -
+
+
+ {{folder.path}}
+
{{/if}}