using System.Collections.Generic; using System.Linq; using NzbDrone.Core.Configuration; using NzbDrone.Core.Profiles.Delay; namespace NzbDrone.Core.DecisionEngine { public interface IPrioritizeDownloadDecision { List PrioritizeDecisions(List decisions); } public class DownloadDecisionPriorizationService : IPrioritizeDownloadDecision { private readonly IConfigService _configService; private readonly IDelayProfileService _delayProfileService; public DownloadDecisionPriorizationService(IConfigService configService, IDelayProfileService delayProfileService) { _configService = configService; _delayProfileService = delayProfileService; } public List PrioritizeDecisions(List decisions) { return decisions.Where(c => c.RemoteAlbum.DownloadAllowed) .GroupBy(c => c.RemoteAlbum.Artist.Id, (artistId, downloadDecisions) => { return downloadDecisions.OrderByDescending(decision => decision, new DownloadDecisionComparer(_configService, _delayProfileService)); }) .SelectMany(c => c) .Union(decisions.Where(c => !c.RemoteAlbum.DownloadAllowed)) .ToList(); } } }