2013-07-19 03:47:55 +00:00
|
|
|
|
using System.Linq;
|
2013-04-07 07:30:37 +00:00
|
|
|
|
using NLog;
|
2013-09-02 02:55:45 +00:00
|
|
|
|
using NzbDrone.Common.Instrumentation;
|
2013-04-27 02:03:34 +00:00
|
|
|
|
using NzbDrone.Common.Messaging;
|
2013-04-07 07:30:37 +00:00
|
|
|
|
using NzbDrone.Core.DecisionEngine;
|
|
|
|
|
using NzbDrone.Core.Download;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Indexers
|
|
|
|
|
{
|
2013-04-23 06:06:05 +00:00
|
|
|
|
public interface IRssSyncService
|
2013-04-07 07:30:37 +00:00
|
|
|
|
{
|
|
|
|
|
void Sync();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-27 02:03:34 +00:00
|
|
|
|
public class RssSyncService : IRssSyncService, IExecute<RssSyncCommand>
|
2013-04-07 07:30:37 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly IFetchAndParseRss _rssFetcherAndParser;
|
|
|
|
|
private readonly IMakeDownloadDecision _downloadDecisionMaker;
|
2013-06-19 05:44:50 +00:00
|
|
|
|
private readonly IDownloadApprovedReports _downloadApprovedReports;
|
2013-04-07 07:30:37 +00:00
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
2013-06-19 02:08:29 +00:00
|
|
|
|
public RssSyncService(IFetchAndParseRss rssFetcherAndParser,
|
|
|
|
|
IMakeDownloadDecision downloadDecisionMaker,
|
2013-06-19 05:44:50 +00:00
|
|
|
|
IDownloadApprovedReports downloadApprovedReports,
|
2013-06-19 02:08:29 +00:00
|
|
|
|
Logger logger)
|
2013-04-07 07:30:37 +00:00
|
|
|
|
{
|
|
|
|
|
_rssFetcherAndParser = rssFetcherAndParser;
|
|
|
|
|
_downloadDecisionMaker = downloadDecisionMaker;
|
2013-06-19 05:44:50 +00:00
|
|
|
|
_downloadApprovedReports = downloadApprovedReports;
|
2013-04-07 07:30:37 +00:00
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Sync()
|
|
|
|
|
{
|
2013-09-04 05:01:28 +00:00
|
|
|
|
_logger.Progress("Starting RSS Sync");
|
2013-04-07 07:30:37 +00:00
|
|
|
|
|
2013-04-23 06:14:55 +00:00
|
|
|
|
var reports = _rssFetcherAndParser.Fetch();
|
|
|
|
|
var decisions = _downloadDecisionMaker.GetRssDecision(reports);
|
2013-09-04 05:01:28 +00:00
|
|
|
|
var downloaded = _downloadApprovedReports.DownloadApproved(decisions);
|
2013-04-07 07:30:37 +00:00
|
|
|
|
|
2013-09-04 05:01:28 +00:00
|
|
|
|
_logger.Complete("RSS Sync Completed. Reports found: {0}, Reports downloaded: {1}", reports.Count, downloaded.Count());
|
2013-04-07 07:30:37 +00:00
|
|
|
|
}
|
2013-04-27 02:03:34 +00:00
|
|
|
|
|
|
|
|
|
public void Execute(RssSyncCommand message)
|
|
|
|
|
{
|
|
|
|
|
Sync();
|
|
|
|
|
}
|
2013-04-07 07:30:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|