2013-04-07 07:30:37 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using NzbDrone.Core.DecisionEngine.Specifications.Search;
|
|
|
|
using NzbDrone.Core.IndexerSearch.Definitions;
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.DecisionEngine
|
|
|
|
{
|
|
|
|
public interface IMakeDownloadDecision
|
|
|
|
{
|
2013-04-07 19:01:24 +00:00
|
|
|
IEnumerable<DownloadDecision> GetRssDecision(IEnumerable<IndexerParseResult> episodeParseResults);
|
|
|
|
IEnumerable<DownloadDecision> GetSearchDecision(IEnumerable<IndexerParseResult> episodeParseResult, SearchDefinitionBase searchDefinitionBase);
|
2013-04-07 07:30:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public class DownloadDecisionMaker : IMakeDownloadDecision
|
|
|
|
{
|
|
|
|
private readonly IEnumerable<IRejectWithReason> _specifications;
|
|
|
|
|
|
|
|
public DownloadDecisionMaker(IEnumerable<IRejectWithReason> specifications)
|
|
|
|
{
|
|
|
|
_specifications = specifications;
|
|
|
|
}
|
|
|
|
|
2013-04-07 19:01:24 +00:00
|
|
|
public IEnumerable<DownloadDecision> GetRssDecision(IEnumerable<IndexerParseResult> episodeParseResults)
|
2013-04-07 07:30:37 +00:00
|
|
|
{
|
|
|
|
foreach (var parseResult in episodeParseResults)
|
|
|
|
{
|
|
|
|
parseResult.Decision = new DownloadDecision(parseResult, GetGeneralRejectionReasons(parseResult).ToArray());
|
|
|
|
yield return parseResult.Decision;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-04-07 19:01:24 +00:00
|
|
|
public IEnumerable<DownloadDecision> GetSearchDecision(IEnumerable<IndexerParseResult> episodeParseResults, SearchDefinitionBase searchDefinitionBase)
|
2013-04-07 07:30:37 +00:00
|
|
|
{
|
|
|
|
foreach (var parseResult in episodeParseResults)
|
|
|
|
{
|
|
|
|
var generalReasons = GetGeneralRejectionReasons(parseResult);
|
|
|
|
var searchReasons = GetSearchRejectionReasons(parseResult, searchDefinitionBase);
|
|
|
|
|
|
|
|
parseResult.Decision = new DownloadDecision(parseResult, generalReasons.Union(searchReasons).ToArray());
|
|
|
|
|
|
|
|
yield return parseResult.Decision;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-07 19:01:24 +00:00
|
|
|
private IEnumerable<string> GetGeneralRejectionReasons(IndexerParseResult indexerParseResult)
|
2013-04-07 07:30:37 +00:00
|
|
|
{
|
|
|
|
return _specifications
|
|
|
|
.OfType<IDecisionEngineSpecification>()
|
2013-04-07 19:01:24 +00:00
|
|
|
.Where(spec => !spec.IsSatisfiedBy(indexerParseResult))
|
2013-04-07 07:30:37 +00:00
|
|
|
.Select(spec => spec.RejectionReason);
|
|
|
|
}
|
|
|
|
|
2013-04-07 19:01:24 +00:00
|
|
|
private IEnumerable<string> GetSearchRejectionReasons(IndexerParseResult indexerParseResult, SearchDefinitionBase searchDefinitionBase)
|
2013-04-07 07:30:37 +00:00
|
|
|
{
|
|
|
|
return _specifications
|
|
|
|
.OfType<IDecisionEngineSearchSpecification>()
|
2013-04-07 19:01:24 +00:00
|
|
|
.Where(spec => !spec.IsSatisfiedBy(indexerParseResult, searchDefinitionBase))
|
2013-04-07 07:30:37 +00:00
|
|
|
.Select(spec => spec.RejectionReason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|