From 907aa4a0ba0ab9d602c4bab6c1ed69e3760ffa3a Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 29 Nov 2014 18:21:55 -0800 Subject: [PATCH] Use an event to update title mismatches --- .../Scene/SceneMappingService.cs | 4 ++++ .../Scene/SceneMappingsUpdatedEvent.cs | 8 +++++++ .../Download/DownloadTrackingService.cs | 21 +++++++++++++++---- src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingsUpdatedEvent.cs diff --git a/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs index 8128ffe6a..2736ce723 100644 --- a/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs +++ b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingService.cs @@ -27,6 +27,7 @@ public class SceneMappingService : ISceneMappingService, { private readonly ISceneMappingRepository _repository; private readonly IEnumerable _sceneMappingProviders; + private readonly IEventAggregator _eventAggregator; private readonly Logger _logger; private readonly ICached _getTvdbIdCache; private readonly ICached> _findByTvdbIdCache; @@ -34,10 +35,12 @@ public class SceneMappingService : ISceneMappingService, public SceneMappingService(ISceneMappingRepository repository, ICacheManager cacheManager, IEnumerable sceneMappingProviders, + IEventAggregator eventAggregator, Logger logger) { _repository = repository; _sceneMappingProviders = sceneMappingProviders; + _eventAggregator = eventAggregator; _getTvdbIdCache = cacheManager.GetCache(GetType(), "tvdb_id"); _findByTvdbIdCache = cacheManager.GetCache>(GetType(), "find_tvdb_id"); @@ -129,6 +132,7 @@ private void UpdateMappings() } RefreshCache(); + _eventAggregator.PublishEvent(new SceneMappingsUpdatedEvent()); } private SceneMapping FindTvdbId(string title) diff --git a/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingsUpdatedEvent.cs b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingsUpdatedEvent.cs new file mode 100644 index 000000000..06f6d4a3f --- /dev/null +++ b/src/NzbDrone.Core/DataAugmentation/Scene/SceneMappingsUpdatedEvent.cs @@ -0,0 +1,8 @@ +using NzbDrone.Common.Messaging; + +namespace NzbDrone.Core.DataAugmentation.Scene +{ + public class SceneMappingsUpdatedEvent : IEvent + { + } +} diff --git a/src/NzbDrone.Core/Download/DownloadTrackingService.cs b/src/NzbDrone.Core/Download/DownloadTrackingService.cs index ed8f4d156..f107dce25 100644 --- a/src/NzbDrone.Core/Download/DownloadTrackingService.cs +++ b/src/NzbDrone.Core/Download/DownloadTrackingService.cs @@ -5,6 +5,7 @@ using NzbDrone.Common; using NzbDrone.Common.Cache; using NzbDrone.Core.Configuration; +using NzbDrone.Core.DataAugmentation.Scene; using NzbDrone.Core.History; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Events; @@ -25,7 +26,8 @@ public interface IDownloadTrackingService public class DownloadTrackingService : IDownloadTrackingService, IExecute, IHandleAsync, - IHandle + IHandle, + IHandle { private readonly IProvideDownloadClient _downloadClientProvider; private readonly IHistoryService _historyService; @@ -152,8 +154,7 @@ private Boolean UpdateTrackedDownloads(List grabbedHistory) if (newTrackedDownloads.ContainsKey(trackingId)) continue; - //TODO: Rebuilding the tracked download when it is a warning is a total hack to deal with updated scene mappings - if (!oldTrackedDownloads.TryGetValue(trackingId, out trackedDownload) || trackedDownload.Status == TrackedDownloadStatus.Warning) + if (!oldTrackedDownloads.TryGetValue(trackingId, out trackedDownload)) { trackedDownload = GetTrackedDownload(trackingId, downloadClient.Definition.Id, downloadItem, grabbedHistory); @@ -244,7 +245,6 @@ private TrackedDownload GetTrackedDownload(String trackingId, Int32 downloadClie Status = TrackedDownloadStatus.Ok, }; - try { var historyItems = grabbedHistory.Where(h => @@ -298,5 +298,18 @@ public void Handle(EpisodeGrabbedEvent message) { ProcessTrackedDownloads(); } + + public void Handle(SceneMappingsUpdatedEvent message) + { + var grabbedHistory = _historyService.Grabbed(); + + foreach (var trackedDownload in GetTrackedDownloads().Where(t => t.Status == TrackedDownloadStatus.Warning)) + { + var newTrackedDownload = GetTrackedDownload(trackedDownload.TrackingId, trackedDownload.DownloadClient, trackedDownload.DownloadItem, grabbedHistory); + + trackedDownload.Status = newTrackedDownload.Status; + trackedDownload.StatusMessages = newTrackedDownload.StatusMessages; + } + } } } diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 245957df6..93fed1c08 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -135,6 +135,7 @@ +