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