1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-25 17:27:18 +00:00

Removed Progress Notification from BannerProvider.

This commit is contained in:
Mark McDowall 2012-03-07 12:37:36 -08:00
parent 861f6c1a0c
commit c8f1bccc50
4 changed files with 27 additions and 18 deletions

View file

@ -30,20 +30,20 @@ namespace NzbDrone.Core.Test.JobTests
private void WithSuccessfulDownload() private void WithSuccessfulDownload()
{ {
Mocker.GetMock<BannerProvider>() Mocker.GetMock<BannerProvider>()
.Setup(s => s.Download(It.IsAny<ProgressNotification>(), It.IsAny<Series>())) .Setup(s => s.Download(It.IsAny<Series>()))
.Returns(true); .Returns(true);
} }
private void WithFailedDownload() private void WithFailedDownload()
{ {
Mocker.GetMock<BannerProvider>() Mocker.GetMock<BannerProvider>()
.Setup(s => s.Download(It.IsAny<ProgressNotification>(), It.IsAny<Series>())) .Setup(s => s.Download(It.IsAny<Series>()))
.Returns(false); .Returns(false);
} }
private void VerifyDownloadMock(int times) private void VerifyDownloadMock(int times)
{ {
Mocker.GetMock<BannerProvider>().Verify(v => v.Download(_notification, It.IsAny<Series>()), Times.Exactly(times)); Mocker.GetMock<BannerProvider>().Verify(v => v.Download(It.IsAny<Series>()), Times.Exactly(times));
} }
[Test] [Test]

View file

@ -22,7 +22,6 @@ namespace NzbDrone.Core.Test.ProviderTests
public class BannerProviderTest : CoreTest public class BannerProviderTest : CoreTest
{ {
private Series _series; private Series _series;
private ProgressNotification _notification;
[SetUp] [SetUp]
public void Setup() public void Setup()
@ -33,8 +32,6 @@ namespace NzbDrone.Core.Test.ProviderTests
.With(s => s.SeriesId = 12345) .With(s => s.SeriesId = 12345)
.Build(); .Build();
_notification = new ProgressNotification("Test");
var path = @"C:\Windows\Temp"; var path = @"C:\Windows\Temp";
Mocker.GetMock<DiskProvider>().Setup(s => s.CreateDirectory(path)); Mocker.GetMock<DiskProvider>().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() public void Download_should_return_true_when_banner_is_downloaded_successfully()
{ {
WithSuccessfulDownload(); WithSuccessfulDownload();
var result = Mocker.Resolve<BannerProvider>().Download(_notification, _series); var result = Mocker.Resolve<BannerProvider>().Download(_series);
result.Should().BeTrue(); result.Should().BeTrue();
} }
@ -63,7 +60,7 @@ namespace NzbDrone.Core.Test.ProviderTests
public void Download_should_return_false_when_banner_download_fails() public void Download_should_return_false_when_banner_download_fails()
{ {
WithFailedDownload(); WithFailedDownload();
var result = Mocker.Resolve<BannerProvider>().Download(_notification, _series); var result = Mocker.Resolve<BannerProvider>().Download(_series);
result.Should().BeFalse(); result.Should().BeFalse();
} }

View file

@ -49,7 +49,9 @@ namespace NzbDrone.Core.Jobs
var series = _seriesProvider.GetSeries(targetId); var series = _seriesProvider.GetSeries(targetId);
if (series != null && !String.IsNullOrEmpty(series.BannerUrl)) if (series != null && !String.IsNullOrEmpty(series.BannerUrl))
_bannerProvider.Download(notification, series); {
DownloadBanner(notification, series);
}
return; return;
} }
@ -58,10 +60,21 @@ namespace NzbDrone.Core.Jobs
foreach (var series in seriesInDb.Where(s => !String.IsNullOrEmpty(s.BannerUrl))) foreach (var series in seriesInDb.Where(s => !String.IsNullOrEmpty(s.BannerUrl)))
{ {
_bannerProvider.Download(notification, series); DownloadBanner(notification, series);
} }
Logger.Debug("Finished banner download job"); 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);
}
} }
} }

View file

@ -4,6 +4,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using NLog; using NLog;
using Ninject;
using NzbDrone.Common; using NzbDrone.Common;
using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Repository; using NzbDrone.Core.Repository;
@ -19,6 +20,7 @@ namespace NzbDrone.Core.Providers
private const string BANNER_URL_PREFIX = "http://www.thetvdb.com/banners/"; private const string BANNER_URL_PREFIX = "http://www.thetvdb.com/banners/";
[Inject]
public BannerProvider(HttpProvider httpProvider, EnvironmentProvider environmentProvider, public BannerProvider(HttpProvider httpProvider, EnvironmentProvider environmentProvider,
DiskProvider diskProvider) 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()); logger.Trace("Ensuring Banner Folder exists: ", bannerPath);
_diskProvider.CreateDirectory(_environmentProvider.GetBannerPath()); _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); logger.Trace("Downloading banner for '{0}'", series.Title);
try try
{ {
_httpProvider.DownloadFile(BANNER_URL_PREFIX + series.BannerUrl, bannerFilename); _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); logger.Trace("Successfully download banner for '{0}'", series.Title);
} }
catch (Exception) catch (Exception)
{ {
logger.Debug("Failed to download banner for '{0}'", series.Title); logger.Debug("Failed to download banner for '{0}'", series.Title);
notification.CurrentMessage = string.Format("Failed to download banner for '{0}'", series.Title);
return false; return false;
} }