2011-01-29 06:10:22 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
|
|
|
|
using SubSonic.Repository;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers
|
|
|
|
|
{
|
2011-04-08 23:58:46 +00:00
|
|
|
|
public class HistoryProvider
|
2011-01-29 06:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly IRepository _sonicRepo;
|
|
|
|
|
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
|
|
public HistoryProvider(IRepository sonicRepo)
|
|
|
|
|
{
|
|
|
|
|
_sonicRepo = sonicRepo;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-08 23:58:46 +00:00
|
|
|
|
#region HistoryProvider Members
|
2011-01-29 06:10:22 +00:00
|
|
|
|
|
2011-04-08 23:58:46 +00:00
|
|
|
|
public virtual List<History> AllItems()
|
2011-01-29 06:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
return _sonicRepo.All<History>().ToList();
|
|
|
|
|
}
|
2011-04-08 23:58:46 +00:00
|
|
|
|
|
|
|
|
|
public virtual void Purge()
|
2011-01-29 06:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
var all = _sonicRepo.All<History>();
|
|
|
|
|
_sonicRepo.DeleteMany(all);
|
|
|
|
|
Logger.Info("History has been Purged");
|
|
|
|
|
}
|
2011-04-08 23:58:46 +00:00
|
|
|
|
|
|
|
|
|
public virtual void Trim()
|
2011-01-29 06:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
var old = _sonicRepo.All<History>().Where(h => h.Date < DateTime.Now.AddDays(-30));
|
|
|
|
|
_sonicRepo.DeleteMany(old);
|
|
|
|
|
Logger.Info("History has been trimmed, items older than 30 days have been removed");
|
|
|
|
|
}
|
2011-04-08 23:58:46 +00:00
|
|
|
|
|
|
|
|
|
public virtual void Insert(History item)
|
2011-01-29 06:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
_sonicRepo.Add(item);
|
2011-03-23 05:19:23 +00:00
|
|
|
|
//Logger.Info("Item added to history: {0} - {1}x{2:00}", item.Episode.Series.Title, item.Episode.SeasonNumber, item.Episode.EpisodeNumber);
|
2011-01-29 06:10:22 +00:00
|
|
|
|
}
|
2011-04-08 23:58:46 +00:00
|
|
|
|
|
|
|
|
|
public virtual bool Exists(int episodeId, QualityTypes quality, bool proper)
|
2011-01-29 06:10:22 +00:00
|
|
|
|
{
|
|
|
|
|
//Looks for the existance of this episode in History
|
|
|
|
|
if (_sonicRepo.Exists<History>(h => h.EpisodeId == episodeId && (QualityTypes)h.Quality == quality && h.IsProper == proper))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
Logger.Debug("Episode not in History: {0}", episodeId);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|