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()
{
Mocker.GetMock<BannerProvider>()
.Setup(s => s.Download(It.IsAny<ProgressNotification>(), It.IsAny<Series>()))
.Setup(s => s.Download(It.IsAny<Series>()))
.Returns(true);
}
private void WithFailedDownload()
{
Mocker.GetMock<BannerProvider>()
.Setup(s => s.Download(It.IsAny<ProgressNotification>(), It.IsAny<Series>()))
.Setup(s => s.Download(It.IsAny<Series>()))
.Returns(false);
}
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]

View File

@ -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<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()
{
WithSuccessfulDownload();
var result = Mocker.Resolve<BannerProvider>().Download(_notification, _series);
var result = Mocker.Resolve<BannerProvider>().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<BannerProvider>().Download(_notification, _series);
var result = Mocker.Resolve<BannerProvider>().Download(_series);
result.Should().BeFalse();
}

View File

@ -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);
}
}
}

View File

@ -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;
}