diff --git a/src/NzbDrone.Core.Test/Download/FailedDownloadServiceFixture.cs b/src/NzbDrone.Core.Test/Download/FailedDownloadServiceFixture.cs index 6d2149386..73d503a4b 100644 --- a/src/NzbDrone.Core.Test/Download/FailedDownloadServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Download/FailedDownloadServiceFixture.cs @@ -68,7 +68,6 @@ public void should_not_fail_if_matching_history_is_not_found() AssertDownloadNotFailed(); } - [Test] public void should_mark_failed_if_encrypted() { @@ -79,7 +78,6 @@ public void should_mark_failed_if_encrypted() AssertDownloadFailed(); } - [Test] public void should_mark_failed_if_download_item_is_failed() { @@ -90,6 +88,18 @@ public void should_mark_failed_if_download_item_is_failed() AssertDownloadFailed(); } + [Test] + public void should_include_tracked_download_in_message() + { + _trackedDownload.DownloadItem.Status = DownloadItemStatus.Failed; + + Subject.Process(_trackedDownload); + + Mocker.GetMock() + .Verify(v => v.PublishEvent(It.Is(c => c.TrackedDownload != null)), Times.Once()); + + AssertDownloadFailed(); + } private void AssertDownloadNotFailed() { diff --git a/src/NzbDrone.Core/Download/DownloadEventHub.cs b/src/NzbDrone.Core/Download/DownloadEventHub.cs index ed9d19a80..e00e87bc6 100644 --- a/src/NzbDrone.Core/Download/DownloadEventHub.cs +++ b/src/NzbDrone.Core/Download/DownloadEventHub.cs @@ -22,17 +22,14 @@ public class DownloadEventHub : IHandle, { private readonly IConfigService _configService; private readonly IProvideDownloadClient _downloadClientProvider; - private readonly ITrackedDownloadService _trackedDownloadService; private readonly Logger _logger; public DownloadEventHub(IConfigService configService, IProvideDownloadClient downloadClientProvider, - ITrackedDownloadService trackedDownloadService, Logger logger) { _configService = configService; _downloadClientProvider = downloadClientProvider; - _trackedDownloadService = trackedDownloadService; _logger = logger; } @@ -48,8 +45,7 @@ public void Handle(DownloadCompletedEvent message) public void Handle(DownloadFailedEvent message) { - var trackedDownload = _trackedDownloadService.Find(message.DownloadId); - + var trackedDownload = message.TrackedDownload; if (trackedDownload == null || trackedDownload.DownloadItem.IsReadOnly || _configService.RemoveFailedDownloads == false) { diff --git a/src/NzbDrone.Core/Download/DownloadFailedEvent.cs b/src/NzbDrone.Core/Download/DownloadFailedEvent.cs index 5dd90ea6f..f6cd06c59 100644 --- a/src/NzbDrone.Core/Download/DownloadFailedEvent.cs +++ b/src/NzbDrone.Core/Download/DownloadFailedEvent.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using NzbDrone.Common.Messaging; +using NzbDrone.Core.Download.TrackedDownloads; using NzbDrone.Core.Qualities; namespace NzbDrone.Core.Download @@ -20,5 +21,6 @@ public DownloadFailedEvent() public String DownloadId { get; set; } public String Message { get; set; } public Dictionary Data { get; set; } + public TrackedDownload TrackedDownload { get; set; } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/Download/FailedDownloadService.cs b/src/NzbDrone.Core/Download/FailedDownloadService.cs index 363ccfe44..898345f46 100644 --- a/src/NzbDrone.Core/Download/FailedDownloadService.cs +++ b/src/NzbDrone.Core/Download/FailedDownloadService.cs @@ -55,16 +55,16 @@ public void Process(TrackedDownload trackedDownload) if (trackedDownload.DownloadItem.IsEncrypted) { trackedDownload.State = TrackedDownloadStage.DownloadFailed; - PublishDownloadFailedEvent(grabbedItems, "Encrypted download detected"); + PublishDownloadFailedEvent(grabbedItems, "Encrypted download detected", trackedDownload); } else if (trackedDownload.DownloadItem.Status == DownloadItemStatus.Failed) { trackedDownload.State = TrackedDownloadStage.DownloadFailed; - PublishDownloadFailedEvent(grabbedItems, trackedDownload.DownloadItem.Message); + PublishDownloadFailedEvent(grabbedItems, trackedDownload.DownloadItem.Message, trackedDownload); } } - private void PublishDownloadFailedEvent(List historyItems, string message) + private void PublishDownloadFailedEvent(List historyItems, string message, TrackedDownload trackedDownload = null) { var historyItem = historyItems.First(); @@ -77,12 +77,11 @@ private void PublishDownloadFailedEvent(List historyItems, stri DownloadClient = historyItem.Data.GetValueOrDefault(History.History.DOWNLOAD_CLIENT), DownloadId = historyItem.DownloadId, Message = message, - Data = historyItem.Data + Data = historyItem.Data, + TrackedDownload = trackedDownload }; _eventAggregator.PublishEvent(downloadFailedEvent); } - - } } diff --git a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs index 7dbb036eb..e3c3ac547 100644 --- a/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs +++ b/src/NzbDrone.Core/Download/TrackedDownloads/TrackedDownloadService.cs @@ -95,6 +95,5 @@ private static TrackedDownloadStage GetStateFromHistory(HistoryEventType eventTy return TrackedDownloadStage.Downloading; } } - } -} \ No newline at end of file +}