2013-02-24 22:18:48 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2013-02-24 00:29:22 +03:00
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
2013-02-24 22:18:48 +03:00
|
|
|
using NzbDrone.Common.Eventing;
|
|
|
|
using NzbDrone.Core.Download;
|
2013-02-24 00:29:22 +03:00
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.History
|
|
|
|
{
|
2013-02-24 22:18:48 +03:00
|
|
|
public interface IHistoryService
|
|
|
|
{
|
|
|
|
List<History> All();
|
|
|
|
void Purge();
|
|
|
|
void Trim();
|
|
|
|
QualityModel GetBestQualityInHistory(int seriesId, int seasonNumber, int episodeNumber);
|
|
|
|
}
|
2013-02-24 00:29:22 +03:00
|
|
|
|
2013-02-24 22:18:48 +03:00
|
|
|
public class HistoryService : IHistoryService, IHandle<EpisodeGrabbedEvent>
|
2013-02-24 00:29:22 +03:00
|
|
|
{
|
|
|
|
private readonly IHistoryRepository _historyRepository;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
|
|
public HistoryService(IHistoryRepository historyRepository, Logger logger)
|
|
|
|
{
|
|
|
|
_historyRepository = historyRepository;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<History> All()
|
|
|
|
{
|
|
|
|
return _historyRepository.All().ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Purge()
|
|
|
|
{
|
|
|
|
_historyRepository.Purge();
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void Trim()
|
|
|
|
{
|
|
|
|
_historyRepository.Trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual QualityModel GetBestQualityInHistory(int seriesId, int seasonNumber, int episodeNumber)
|
|
|
|
{
|
|
|
|
return _historyRepository.GetBestQualityInHistory(seriesId, seasonNumber, episodeNumber);
|
|
|
|
}
|
|
|
|
|
2013-02-24 22:18:48 +03:00
|
|
|
public void Handle(EpisodeGrabbedEvent message)
|
|
|
|
{
|
|
|
|
foreach (var episode in message.ParseResult.Episodes)
|
|
|
|
{
|
|
|
|
var history = new History
|
|
|
|
{
|
|
|
|
Date = DateTime.Now,
|
|
|
|
Indexer = message.ParseResult.Indexer,
|
|
|
|
Quality = message.ParseResult.Quality,
|
|
|
|
NzbTitle = message.ParseResult.OriginalString,
|
|
|
|
Episode = episode,
|
|
|
|
NzbInfoUrl = message.ParseResult.NzbInfoUrl,
|
|
|
|
ReleaseGroup = message.ParseResult.ReleaseGroup,
|
|
|
|
};
|
|
|
|
|
|
|
|
_historyRepository.Insert(history);
|
|
|
|
}
|
|
|
|
}
|
2013-02-24 00:29:22 +03:00
|
|
|
}
|
|
|
|
}
|