1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 00:12:30 +01:00
Sonarr/NzbDrone.Core/DecisionEngine/Specifications/UpgradeHistorySpecification.cs

45 lines
1.6 KiB
C#
Raw Normal View History

using NLog;
using NzbDrone.Core.History;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.DecisionEngine.Specifications
{
2013-04-07 09:30:37 +02:00
public class UpgradeHistorySpecification : IDecisionEngineSpecification
{
private readonly IHistoryService _historyService;
private readonly QualityUpgradableSpecification _qualityUpgradableSpecification;
private readonly Logger _logger;
public UpgradeHistorySpecification(IHistoryService historyService, QualityUpgradableSpecification qualityUpgradableSpecification, Logger logger)
{
_historyService = historyService;
_qualityUpgradableSpecification = qualityUpgradableSpecification;
_logger = logger;
}
public string RejectionReason
{
get
{
return "Higher quality report exists in history";
}
}
public virtual bool IsSatisfiedBy(RemoteEpisode subject)
{
foreach (var episode in subject.Episodes)
{
2013-03-25 02:38:11 +01:00
var bestQualityInHistory = _historyService.GetBestQualityInHistory(episode.Id);
if (bestQualityInHistory != null)
{
_logger.Trace("Comparing history quality with report. History is {0}", bestQualityInHistory);
if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.QualityProfile, bestQualityInHistory, subject.ParsedEpisodeInfo.Quality))
return false;
}
}
return true;
}
}
}