parent
02d842a2b2
commit
ef5f565a4d
@ -1,54 +0,0 @@
|
||||
using NLog;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine
|
||||
{
|
||||
public class AllowedDownloadSpecification
|
||||
{
|
||||
private readonly QualityAllowedByProfileSpecification _qualityAllowedByProfileSpecification;
|
||||
private readonly UpgradeDiskSpecification _upgradeDiskSpecification;
|
||||
private readonly AcceptableSizeSpecification _acceptableSizeSpecification;
|
||||
private readonly NotInQueueSpecification _notInQueueSpecification;
|
||||
private readonly RetentionSpecification _retentionSpecification;
|
||||
private readonly AllowedReleaseGroupSpecification _allowedReleaseGroupSpecification;
|
||||
private readonly CustomStartDateSpecification _customStartDateSpecification;
|
||||
private readonly LanguageSpecification _languageSpecification;
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public AllowedDownloadSpecification(QualityAllowedByProfileSpecification qualityAllowedByProfileSpecification,
|
||||
UpgradeDiskSpecification upgradeDiskSpecification, AcceptableSizeSpecification acceptableSizeSpecification,
|
||||
NotInQueueSpecification notInQueueSpecification, RetentionSpecification retentionSpecification,
|
||||
AllowedReleaseGroupSpecification allowedReleaseGroupSpecification, CustomStartDateSpecification customStartDateSpecification,
|
||||
LanguageSpecification languageSpecification)
|
||||
{
|
||||
_qualityAllowedByProfileSpecification = qualityAllowedByProfileSpecification;
|
||||
_upgradeDiskSpecification = upgradeDiskSpecification;
|
||||
_acceptableSizeSpecification = acceptableSizeSpecification;
|
||||
_notInQueueSpecification = notInQueueSpecification;
|
||||
_retentionSpecification = retentionSpecification;
|
||||
_allowedReleaseGroupSpecification = allowedReleaseGroupSpecification;
|
||||
_customStartDateSpecification = customStartDateSpecification;
|
||||
_languageSpecification = languageSpecification;
|
||||
}
|
||||
|
||||
public AllowedDownloadSpecification()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual ReportRejectionReasons IsSatisfiedBy(EpisodeParseResult subject)
|
||||
{
|
||||
if (!_qualityAllowedByProfileSpecification.IsSatisfiedBy(subject)) return ReportRejectionReasons.QualityNotWanted;
|
||||
if (!_customStartDateSpecification.IsSatisfiedBy(subject)) return ReportRejectionReasons.AiredAfterCustomStartDate;
|
||||
if (!_upgradeDiskSpecification.IsSatisfiedBy(subject)) return ReportRejectionReasons.ExistingQualityIsEqualOrBetter;
|
||||
if (!_languageSpecification.IsSatisfiedBy(subject)) return ReportRejectionReasons.LanguageNotWanted;
|
||||
if (!_retentionSpecification.IsSatisfiedBy(subject)) return ReportRejectionReasons.Retention;
|
||||
if (!_acceptableSizeSpecification.IsSatisfiedBy(subject)) return ReportRejectionReasons.Size;
|
||||
if (!_allowedReleaseGroupSpecification.IsSatisfiedBy(subject)) return ReportRejectionReasons.ReleaseGroupNotWanted;
|
||||
if (!_notInQueueSpecification.IsSatisfiedBy(subject)) return ReportRejectionReasons.AlreadyInQueue;
|
||||
|
||||
logger.Debug("Episode {0} is needed", subject);
|
||||
return ReportRejectionReasons.None;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine
|
||||
{
|
||||
public class DownloadDecision
|
||||
{
|
||||
public IEnumerable<string> Rejections { get; private set; }
|
||||
public bool Approved
|
||||
{
|
||||
get
|
||||
{
|
||||
return !Rejections.Any();
|
||||
}
|
||||
}
|
||||
|
||||
public DownloadDecision(params string[] rejections)
|
||||
{
|
||||
Rejections = rejections.ToList();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Model;
|
||||
|
||||
namespace NzbDrone.Core.DecisionEngine
|
||||
{
|
||||
public interface IDownloadDirector
|
||||
{
|
||||
DownloadDecision GetDownloadDecision(EpisodeParseResult episodeParseResult);
|
||||
}
|
||||
|
||||
public class DownloadDirector : IDownloadDirector
|
||||
{
|
||||
private readonly IEnumerable<IFetchableSpecification> _specifications;
|
||||
|
||||
public DownloadDirector(IEnumerable<IFetchableSpecification> specifications)
|
||||
{
|
||||
_specifications = specifications;
|
||||
}
|
||||
|
||||
public DownloadDecision GetDownloadDecision(EpisodeParseResult episodeParseResult)
|
||||
{
|
||||
var rejections = _specifications
|
||||
.Where(spec => !spec.IsSatisfiedBy(episodeParseResult))
|
||||
.Select(spec => spec.RejectionReason).ToArray();
|
||||
|
||||
episodeParseResult.Decision = new DownloadDecision(rejections);
|
||||
|
||||
return episodeParseResult.Decision;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue