From c8f1bccc507bebe216f0f4b6709f2beeb929914b Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 7 Mar 2012 12:37:36 -0800 Subject: [PATCH] Removed Progress Notification from BannerProvider. --- .../JobTests/BannerDownloadJobTest.cs | 6 +++--- .../ProviderTests/BannerProviderTest.cs | 7 ++----- NzbDrone.Core/Jobs/BannerDownloadJob.cs | 17 +++++++++++++++-- NzbDrone.Core/Providers/BannerProvider.cs | 15 +++++++-------- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs b/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs index c7199f708..9b1b4e481 100644 --- a/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs @@ -30,20 +30,20 @@ namespace NzbDrone.Core.Test.JobTests private void WithSuccessfulDownload() { Mocker.GetMock() - .Setup(s => s.Download(It.IsAny(), It.IsAny())) + .Setup(s => s.Download(It.IsAny())) .Returns(true); } private void WithFailedDownload() { Mocker.GetMock() - .Setup(s => s.Download(It.IsAny(), It.IsAny())) + .Setup(s => s.Download(It.IsAny())) .Returns(false); } private void VerifyDownloadMock(int times) { - Mocker.GetMock().Verify(v => v.Download(_notification, It.IsAny()), Times.Exactly(times)); + Mocker.GetMock().Verify(v => v.Download(It.IsAny()), Times.Exactly(times)); } [Test] diff --git a/NzbDrone.Core.Test/ProviderTests/BannerProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/BannerProviderTest.cs index 33622ed47..a58d32bac 100644 --- a/NzbDrone.Core.Test/ProviderTests/BannerProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/BannerProviderTest.cs @@ -22,7 +22,6 @@ namespace NzbDrone.Core.Test.ProviderTests public class BannerProviderTest : CoreTest { private Series _series; - private ProgressNotification _notification; [SetUp] public void Setup() @@ -33,8 +32,6 @@ namespace NzbDrone.Core.Test.ProviderTests .With(s => s.SeriesId = 12345) .Build(); - _notification = new ProgressNotification("Test"); - var path = @"C:\Windows\Temp"; Mocker.GetMock().Setup(s => s.CreateDirectory(path)); @@ -55,7 +52,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void Download_should_return_true_when_banner_is_downloaded_successfully() { WithSuccessfulDownload(); - var result = Mocker.Resolve().Download(_notification, _series); + var result = Mocker.Resolve().Download(_series); result.Should().BeTrue(); } @@ -63,7 +60,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void Download_should_return_false_when_banner_download_fails() { WithFailedDownload(); - var result = Mocker.Resolve().Download(_notification, _series); + var result = Mocker.Resolve().Download(_series); result.Should().BeFalse(); } diff --git a/NzbDrone.Core/Jobs/BannerDownloadJob.cs b/NzbDrone.Core/Jobs/BannerDownloadJob.cs index 7b1980be2..a23bb7135 100644 --- a/NzbDrone.Core/Jobs/BannerDownloadJob.cs +++ b/NzbDrone.Core/Jobs/BannerDownloadJob.cs @@ -49,7 +49,9 @@ namespace NzbDrone.Core.Jobs var series = _seriesProvider.GetSeries(targetId); if (series != null && !String.IsNullOrEmpty(series.BannerUrl)) - _bannerProvider.Download(notification, series); + { + DownloadBanner(notification, series); + } return; } @@ -58,10 +60,21 @@ namespace NzbDrone.Core.Jobs foreach (var series in seriesInDb.Where(s => !String.IsNullOrEmpty(s.BannerUrl))) { - _bannerProvider.Download(notification, series); + DownloadBanner(notification, series); } Logger.Debug("Finished banner download job"); } + + public virtual void DownloadBanner(ProgressNotification notification, Series series) + { + notification.CurrentMessage = string.Format("Downloading banner for '{0}'", series.Title); + + if (_bannerProvider.Download(series)) + notification.CurrentMessage = string.Format("Successfully download banner for '{0}'", series.Title); + + else + notification.CurrentMessage = string.Format("Failed to download banner for '{0}'", series.Title); + } } } diff --git a/NzbDrone.Core/Providers/BannerProvider.cs b/NzbDrone.Core/Providers/BannerProvider.cs index 39524bd2a..2176e9d7c 100644 --- a/NzbDrone.Core/Providers/BannerProvider.cs +++ b/NzbDrone.Core/Providers/BannerProvider.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Text; using NLog; +using Ninject; using NzbDrone.Common; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Repository; @@ -19,6 +20,7 @@ namespace NzbDrone.Core.Providers private const string BANNER_URL_PREFIX = "http://www.thetvdb.com/banners/"; + [Inject] public BannerProvider(HttpProvider httpProvider, EnvironmentProvider environmentProvider, DiskProvider diskProvider) { @@ -32,28 +34,25 @@ namespace NzbDrone.Core.Providers } - public virtual bool Download(ProgressNotification notification, Series series) + public virtual bool Download(Series series) { - //var bannerPath = _environmentProvider.GetBannerPath(); + var bannerPath = _environmentProvider.GetBannerPath(); - logger.Trace("Ensuring Banner Folder exists: ", _environmentProvider.GetBannerPath()); - _diskProvider.CreateDirectory(_environmentProvider.GetBannerPath()); + logger.Trace("Ensuring Banner Folder exists: ", bannerPath); + _diskProvider.CreateDirectory(bannerPath); - var bannerFilename = Path.Combine(_environmentProvider.GetBannerPath(), series.SeriesId.ToString()) + ".jpg"; + var bannerFilename = Path.Combine(bannerPath, series.SeriesId.ToString()) + ".jpg"; - notification.CurrentMessage = string.Format("Downloading banner for '{0}'", series.Title); logger.Trace("Downloading banner for '{0}'", series.Title); try { _httpProvider.DownloadFile(BANNER_URL_PREFIX + series.BannerUrl, bannerFilename); - notification.CurrentMessage = string.Format("Successfully download banner for '{0}'", series.Title); logger.Trace("Successfully download banner for '{0}'", series.Title); } catch (Exception) { logger.Debug("Failed to download banner for '{0}'", series.Title); - notification.CurrentMessage = string.Format("Failed to download banner for '{0}'", series.Title); return false; }