2013-06-09 20:50:57 +00:00
|
|
|
|
using NLog;
|
2013-04-24 01:56:00 +00:00
|
|
|
|
using NzbDrone.Common.Messaging;
|
2013-04-15 01:41:39 +00:00
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
2013-04-01 06:22:16 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Download
|
|
|
|
|
{
|
|
|
|
|
public interface IDownloadService
|
|
|
|
|
{
|
2013-08-17 23:27:18 +00:00
|
|
|
|
void DownloadReport(RemoteEpisode remoteEpisode);
|
2013-04-01 06:22:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class DownloadService : IDownloadService
|
|
|
|
|
{
|
|
|
|
|
private readonly IProvideDownloadClient _downloadClientProvider;
|
2013-04-24 01:56:00 +00:00
|
|
|
|
private readonly IMessageAggregator _messageAggregator;
|
2013-04-01 06:22:16 +00:00
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
|
2013-05-19 23:17:32 +00:00
|
|
|
|
public DownloadService(IProvideDownloadClient downloadClientProvider,
|
2013-04-24 01:56:00 +00:00
|
|
|
|
IMessageAggregator messageAggregator, Logger logger)
|
2013-04-01 06:22:16 +00:00
|
|
|
|
{
|
|
|
|
|
_downloadClientProvider = downloadClientProvider;
|
2013-04-24 01:56:00 +00:00
|
|
|
|
_messageAggregator = messageAggregator;
|
2013-04-01 06:22:16 +00:00
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-17 23:27:18 +00:00
|
|
|
|
public void DownloadReport(RemoteEpisode remoteEpisode)
|
2013-04-01 06:22:16 +00:00
|
|
|
|
{
|
2013-06-09 20:50:57 +00:00
|
|
|
|
var downloadTitle = remoteEpisode.Report.Title;
|
2013-07-31 05:49:41 +00:00
|
|
|
|
var downloadClient = _downloadClientProvider.GetDownloadClient();
|
2013-04-01 06:22:16 +00:00
|
|
|
|
|
2013-07-31 05:49:41 +00:00
|
|
|
|
if (!downloadClient.IsConfigured)
|
|
|
|
|
{
|
|
|
|
|
_logger.Warn("Download client {0} isn't configured yet.", downloadClient.GetType().Name);
|
2013-08-17 23:27:18 +00:00
|
|
|
|
return;
|
2013-07-31 05:49:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-17 23:27:18 +00:00
|
|
|
|
downloadClient.DownloadNzb(remoteEpisode);
|
2013-04-01 06:22:16 +00:00
|
|
|
|
|
2013-08-17 23:27:18 +00:00
|
|
|
|
_logger.Info("Report sent to download client. {0}", downloadTitle);
|
|
|
|
|
_messageAggregator.PublishEvent(new EpisodeGrabbedEvent(remoteEpisode));
|
2013-04-01 06:22:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|