2010-10-05 08:21:18 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2011-04-10 04:44:01 +02:00
|
|
|
|
using System.Linq;
|
2010-10-05 08:21:18 +02:00
|
|
|
|
using NLog;
|
2010-10-21 03:49:23 +02:00
|
|
|
|
using NzbDrone.Core.Repository;
|
2010-10-05 08:21:18 +02:00
|
|
|
|
using SubSonic.Repository;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers
|
|
|
|
|
{
|
2011-04-10 03:34:36 +02:00
|
|
|
|
public class SeasonProvider
|
2010-10-05 08:21:18 +02:00
|
|
|
|
{
|
2011-01-29 07:10:22 +01:00
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
2011-04-26 02:28:33 +02:00
|
|
|
|
private readonly IRepository _repository;
|
2010-10-05 08:21:18 +02:00
|
|
|
|
|
2011-04-26 02:28:33 +02:00
|
|
|
|
public SeasonProvider(IRepository repository)
|
2010-10-05 08:21:18 +02:00
|
|
|
|
{
|
2011-04-26 02:28:33 +02:00
|
|
|
|
_repository = repository;
|
2010-10-05 08:21:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-10 03:34:36 +02:00
|
|
|
|
public SeasonProvider()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual Season GetSeason(int seasonId)
|
2010-10-05 08:21:18 +02:00
|
|
|
|
{
|
2011-04-26 02:28:33 +02:00
|
|
|
|
return _repository.Single<Season>(seasonId);
|
2010-10-05 08:21:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-10 03:34:36 +02:00
|
|
|
|
public virtual Season GetSeason(int seriesId, int seasonNumber)
|
2011-03-26 20:16:53 +01:00
|
|
|
|
{
|
2011-04-26 02:28:33 +02:00
|
|
|
|
return _repository.Single<Season>(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber);
|
2011-03-26 20:16:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-10 03:34:36 +02:00
|
|
|
|
public virtual List<Season> GetSeasons(int seriesId)
|
2010-10-05 08:21:18 +02:00
|
|
|
|
{
|
2011-04-26 02:28:33 +02:00
|
|
|
|
return _repository.All<Season>().Where(s => s.SeriesId == seriesId).ToList();
|
2010-10-05 08:21:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-10 03:34:36 +02:00
|
|
|
|
public virtual Season GetLatestSeason(int seriesId)
|
2011-02-10 07:41:24 +01:00
|
|
|
|
{
|
2011-04-26 02:28:33 +02:00
|
|
|
|
return _repository.All<Season>().Where(s => s.SeriesId == seriesId).OrderBy(s => s.SeasonNumber).Last();
|
2011-02-10 07:41:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-10 03:34:36 +02:00
|
|
|
|
public virtual void EnsureSeason(int seriesId, int seasonId, int seasonNumber)
|
2010-10-05 08:21:18 +02:00
|
|
|
|
{
|
2011-04-26 02:28:33 +02:00
|
|
|
|
if (_repository.Exists<Season>(s => s.SeasonId == seasonId))
|
2010-10-05 08:21:18 +02:00
|
|
|
|
return;
|
|
|
|
|
//TODO: Calculate Season Folder
|
2011-04-10 04:44:01 +02:00
|
|
|
|
Logger.Trace("Adding Season To DB. [SeriesID:{0} SeasonID:{1} SeasonNumber:{2}]", seriesId, seasonId,
|
|
|
|
|
seasonNumber, "????");
|
|
|
|
|
|
|
|
|
|
var newSeason = new Season
|
|
|
|
|
{
|
|
|
|
|
Monitored = true,
|
|
|
|
|
SeasonId = seasonId,
|
|
|
|
|
SeasonNumber = seasonNumber,
|
|
|
|
|
SeriesId = seriesId
|
|
|
|
|
};
|
2011-04-26 02:28:33 +02:00
|
|
|
|
_repository.Add(newSeason);
|
2010-10-05 08:21:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-10 03:34:36 +02:00
|
|
|
|
public virtual int SaveSeason(Season season)
|
2010-10-05 08:21:18 +02:00
|
|
|
|
{
|
2011-05-16 08:27:02 +02:00
|
|
|
|
if (_repository.Exists<Season>(s => s.SeasonId == season.SeasonId))
|
|
|
|
|
{
|
|
|
|
|
return _repository.Update(season);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (int)_repository.Add(season);
|
2010-10-05 08:21:18 +02:00
|
|
|
|
}
|
2011-01-29 07:10:22 +01:00
|
|
|
|
|
2011-04-10 03:34:36 +02:00
|
|
|
|
public virtual bool IsIgnored(int seasonId)
|
2011-01-29 07:10:22 +01:00
|
|
|
|
{
|
2011-04-26 02:28:33 +02:00
|
|
|
|
if (_repository.Single<Season>(seasonId).Monitored)
|
2011-02-16 08:58:39 +01:00
|
|
|
|
return false;
|
2011-01-29 07:10:22 +01:00
|
|
|
|
|
|
|
|
|
Logger.Debug("Season {0} is not wanted.");
|
2011-02-16 08:58:39 +01:00
|
|
|
|
return true;
|
2011-01-29 07:10:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-10 03:34:36 +02:00
|
|
|
|
public virtual bool IsIgnored(int seriesId, int seasonNumber)
|
2011-01-29 07:10:22 +01:00
|
|
|
|
{
|
2011-04-26 02:28:33 +02:00
|
|
|
|
var season = _repository.Single<Season>(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber);
|
2011-03-26 20:16:53 +01:00
|
|
|
|
return !season.Monitored;
|
2011-01-29 07:10:22 +01:00
|
|
|
|
}
|
2011-02-18 07:49:23 +01:00
|
|
|
|
|
|
|
|
|
public void DeleteSeason(int seasonId)
|
|
|
|
|
{
|
2011-04-26 02:28:33 +02:00
|
|
|
|
_repository.Delete<Season>(seasonId);
|
2011-02-18 07:49:23 +01:00
|
|
|
|
}
|
2010-10-05 08:21:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|