2013-02-24 19:18:48 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2013-02-23 21:29:22 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using NLog;
|
2013-04-24 01:56:00 +00:00
|
|
|
|
using NzbDrone.Common.Messaging;
|
2013-02-24 19:18:48 +00:00
|
|
|
|
using NzbDrone.Core.Download;
|
2013-02-23 21:29:22 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.History
|
|
|
|
|
{
|
2013-02-24 19:18:48 +00:00
|
|
|
|
public interface IHistoryService
|
|
|
|
|
{
|
|
|
|
|
List<History> All();
|
|
|
|
|
void Purge();
|
|
|
|
|
void Trim();
|
2013-03-25 01:38:11 +00:00
|
|
|
|
QualityModel GetBestQualityInHistory(int episodeId);
|
2013-02-24 19:18:48 +00:00
|
|
|
|
}
|
2013-02-23 21:29:22 +00:00
|
|
|
|
|
2013-02-24 19:18:48 +00:00
|
|
|
|
public class HistoryService : IHistoryService, IHandle<EpisodeGrabbedEvent>
|
2013-02-23 21:29:22 +00: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();
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-25 01:38:11 +00:00
|
|
|
|
public virtual QualityModel GetBestQualityInHistory(int episodeId)
|
2013-02-23 21:29:22 +00:00
|
|
|
|
{
|
2013-03-25 01:38:11 +00:00
|
|
|
|
return _historyRepository.GetBestQualityInHistory(episodeId);
|
2013-02-23 21:29:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-24 19:18:48 +00:00
|
|
|
|
public void Handle(EpisodeGrabbedEvent message)
|
|
|
|
|
{
|
2013-04-15 01:41:39 +00:00
|
|
|
|
foreach (var episode in message.Episode.Episodes)
|
2013-02-24 19:18:48 +00:00
|
|
|
|
{
|
|
|
|
|
var history = new History
|
|
|
|
|
{
|
|
|
|
|
Date = DateTime.Now,
|
2013-04-15 01:41:39 +00:00
|
|
|
|
Indexer = message.Episode.Report.Indexer,
|
|
|
|
|
Quality = message.Episode.Quality,
|
|
|
|
|
NzbTitle = message.Episode.Report.Title,
|
2013-03-25 01:38:11 +00:00
|
|
|
|
EpisodeId = episode.Id,
|
2013-04-15 01:41:39 +00:00
|
|
|
|
NzbInfoUrl = message.Episode.Report.NzbInfoUrl,
|
|
|
|
|
ReleaseGroup = message.Episode.Report.ReleaseGroup,
|
2013-02-24 19:18:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_historyRepository.Insert(history);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-23 21:29:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|