Lidarr/src/NzbDrone.Core/Download/DownloadService.cs

49 lines
1.6 KiB
C#
Raw Normal View History

using NLog;
using NzbDrone.Common.EnsureThat;
2013-09-11 06:33:47 +00:00
using NzbDrone.Core.Instrumentation;
using NzbDrone.Core.Messaging.Events;
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;
private readonly IEventAggregator _eventAggregator;
2013-04-01 06:22:16 +00:00
private readonly Logger _logger;
2013-05-19 23:17:32 +00:00
public DownloadService(IProvideDownloadClient downloadClientProvider,
IEventAggregator eventAggregator, Logger logger)
2013-04-01 06:22:16 +00:00
{
_downloadClientProvider = downloadClientProvider;
_eventAggregator = eventAggregator;
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
{
Ensure.That(() => remoteEpisode.Series).IsNotNull();
Ensure.That(() => remoteEpisode.Episodes).HasItems();
2013-09-13 23:17:58 +00:00
var downloadTitle = remoteEpisode.Release.Title;
var downloadClient = _downloadClientProvider.GetDownloadClient();
2013-04-01 06:22:16 +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-08-17 23:27:18 +00:00
downloadClient.DownloadNzb(remoteEpisode);
2013-04-01 06:22:16 +00:00
2013-09-11 06:33:47 +00:00
_logger.ProgressInfo("Report sent to download client. {0}", downloadTitle);
_eventAggregator.PublishEvent(new EpisodeGrabbedEvent(remoteEpisode));
2013-04-01 06:22:16 +00:00
}
}
}