1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-30 23:42:33 +01:00
Sonarr/NzbDrone.Core/Providers/HistoryProvider.cs

67 lines
1.9 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
2011-05-28 21:23:35 +02:00
using NzbDrone.Core.Model;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using SubSonic.Repository;
namespace NzbDrone.Core.Providers
{
2011-04-09 01:58:46 +02:00
public class HistoryProvider
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly IRepository _repository;
public HistoryProvider(IRepository repository)
{
_repository = repository;
}
public HistoryProvider()
{
}
public virtual IQueryable<History> AllItems()
{
return _repository.All<History>();
}
2011-04-09 01:58:46 +02:00
public virtual void Purge()
{
_repository.DeleteMany(AllItems());
Logger.Info("History has been Purged");
}
2011-04-09 01:58:46 +02:00
public virtual void Trim()
{
var old = AllItems().Where(h => h.Date < DateTime.Now.AddDays(-30));
_repository.DeleteMany(old);
Logger.Info("History has been trimmed, items older than 30 days have been removed");
}
2011-04-22 22:14:02 +02:00
public virtual void Add(History item)
{
_repository.Add(item);
2011-04-22 22:14:02 +02:00
Logger.Debug("Item added to history: {0}", item.NzbTitle);
}
2011-05-28 21:23:35 +02:00
public virtual Quality GetBestQualityInHistory(long episodeId)
{
2011-06-05 21:15:46 +02:00
var history = AllItems().Where(c => c.EpisodeId == episodeId).ToList().Select(d => new Quality(d.Quality, d.IsProper));
history.OrderBy(q => q);
2011-05-28 21:23:35 +02:00
return history.FirstOrDefault();
}
public virtual void Delete(int historyId)
{
_repository.Delete<History>(historyId);
}
public virtual void DeleteForEpisode(int episodeId)
{
_repository.DeleteMany<History>(h => h.EpisodeId == episodeId);
}
}
2011-04-10 04:44:01 +02:00
}