2013-06-09 23:50:57 +03:00
|
|
|
using NLog;
|
2013-09-20 10:49:36 +03:00
|
|
|
using NzbDrone.Common.EnsureThat;
|
2013-09-11 09:33:47 +03:00
|
|
|
using NzbDrone.Core.Instrumentation;
|
2013-09-14 09:36:07 +03:00
|
|
|
using NzbDrone.Core.Messaging.Events;
|
2013-04-15 04:41:39 +03:00
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-04-01 09:22:16 +03:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Download
|
|
|
|
{
|
|
|
|
public interface IDownloadService
|
|
|
|
{
|
2013-08-18 02:27:18 +03:00
|
|
|
void DownloadReport(RemoteEpisode remoteEpisode);
|
2013-04-01 09:22:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public class DownloadService : IDownloadService
|
|
|
|
{
|
|
|
|
private readonly IProvideDownloadClient _downloadClientProvider;
|
2013-09-14 09:36:07 +03:00
|
|
|
private readonly IEventAggregator _eventAggregator;
|
2013-04-01 09:22:16 +03:00
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
2013-05-20 02:17:32 +03:00
|
|
|
public DownloadService(IProvideDownloadClient downloadClientProvider,
|
2013-09-14 09:36:07 +03:00
|
|
|
IEventAggregator eventAggregator, Logger logger)
|
2013-04-01 09:22:16 +03:00
|
|
|
{
|
|
|
|
_downloadClientProvider = downloadClientProvider;
|
2013-09-14 09:36:07 +03:00
|
|
|
_eventAggregator = eventAggregator;
|
2013-04-01 09:22:16 +03:00
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2013-08-18 02:27:18 +03:00
|
|
|
public void DownloadReport(RemoteEpisode remoteEpisode)
|
2013-04-01 09:22:16 +03:00
|
|
|
{
|
2013-09-20 10:49:36 +03:00
|
|
|
Ensure.That(() => remoteEpisode.Series).IsNotNull();
|
|
|
|
Ensure.That(() => remoteEpisode.Episodes).HasItems();
|
|
|
|
|
2013-09-14 02:17:58 +03:00
|
|
|
var downloadTitle = remoteEpisode.Release.Title;
|
2013-07-31 08:49:41 +03:00
|
|
|
var downloadClient = _downloadClientProvider.GetDownloadClient();
|
2013-04-01 09:22:16 +03:00
|
|
|
|
2013-07-31 08:49:41 +03:00
|
|
|
if (!downloadClient.IsConfigured)
|
|
|
|
{
|
|
|
|
_logger.Warn("Download client {0} isn't configured yet.", downloadClient.GetType().Name);
|
2013-08-18 02:27:18 +03:00
|
|
|
return;
|
2013-07-31 08:49:41 +03:00
|
|
|
}
|
|
|
|
|
2013-08-18 02:27:18 +03:00
|
|
|
downloadClient.DownloadNzb(remoteEpisode);
|
2013-04-01 09:22:16 +03:00
|
|
|
|
2013-09-11 09:33:47 +03:00
|
|
|
_logger.ProgressInfo("Report sent to download client. {0}", downloadTitle);
|
2013-09-14 09:36:07 +03:00
|
|
|
_eventAggregator.PublishEvent(new EpisodeGrabbedEvent(remoteEpisode));
|
2013-04-01 09:22:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|