1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 10:32:35 +01:00
Radarr/NzbDrone.Core/History/HistoryService.cs

70 lines
1.9 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
2013-02-23 22:29:22 +01:00
using System.Linq;
using NLog;
using NzbDrone.Common.Eventing;
using NzbDrone.Core.Download;
2013-02-23 22:29:22 +01:00
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.History
{
public interface IHistoryService
{
List<History> All();
void Purge();
void Trim();
2013-03-25 02:38:11 +01:00
QualityModel GetBestQualityInHistory(int episodeId);
}
2013-02-23 22:29:22 +01:00
public class HistoryService : IHistoryService, IHandle<EpisodeGrabbedEvent>
2013-02-23 22:29:22 +01: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 02:38:11 +01:00
public virtual QualityModel GetBestQualityInHistory(int episodeId)
2013-02-23 22:29:22 +01:00
{
2013-03-25 02:38:11 +01:00
return _historyRepository.GetBestQualityInHistory(episodeId);
2013-02-23 22:29:22 +01: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,
2013-03-25 02:38:11 +01:00
EpisodeId = episode.Id,
NzbInfoUrl = message.ParseResult.NzbInfoUrl,
ReleaseGroup = message.ParseResult.ReleaseGroup,
};
_historyRepository.Insert(history);
}
}
2013-02-23 22:29:22 +01:00
}
}