removed some unneeded injection dependencies. renamed dependency fields to be standard across the app.

pull/7/merge
kay.one 14 years ago
parent c8252495af
commit 17c8b8803b

@ -10,16 +10,16 @@ namespace NzbDrone.Core.Providers.Core
public class ConfigProvider public class ConfigProvider
{ {
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly IRepository _sonicRepo; private readonly IRepository _repository;
public ConfigProvider(IRepository dataRepository) public ConfigProvider(IRepository repository)
{ {
_sonicRepo = dataRepository; _repository = repository;
} }
public IList<Config> All() public IList<Config> All()
{ {
return _sonicRepo.All<Config>().ToList(); return _repository.All<Config>().ToList();
} }
public ConfigProvider() public ConfigProvider()
@ -220,7 +220,7 @@ namespace NzbDrone.Core.Providers.Core
{ {
string value; string value;
var dbValue = _sonicRepo.Single<Config>(key); var dbValue = _repository.Single<Config>(key);
if (dbValue != null && !String.IsNullOrEmpty(dbValue.Value)) if (dbValue != null && !String.IsNullOrEmpty(dbValue.Value))
return dbValue.Value; return dbValue.Value;
@ -252,11 +252,11 @@ namespace NzbDrone.Core.Providers.Core
Logger.Debug("Writing Setting to file. Key:'{0}' Value:'{1}'", key, value); Logger.Debug("Writing Setting to file. Key:'{0}' Value:'{1}'", key, value);
var dbValue = _sonicRepo.Single<Config>(key); var dbValue = _repository.Single<Config>(key);
if (dbValue == null) if (dbValue == null)
{ {
_sonicRepo.Add(new Config _repository.Add(new Config
{ {
Key = key, Key = key,
Value = value Value = value
@ -265,7 +265,7 @@ namespace NzbDrone.Core.Providers.Core
else else
{ {
dbValue.Value = value; dbValue.Value = value;
_sonicRepo.Update(dbValue); _repository.Update(dbValue);
} }
} }
} }

@ -12,21 +12,15 @@ namespace NzbDrone.Core.Providers
public class EpisodeProvider public class EpisodeProvider
{ {
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly QualityProvider _qualityProvider; private readonly SeasonProvider _seasonsProvider;
private readonly SeasonProvider _seasons; private readonly IRepository _repository;
private readonly SeriesProvider _series; private readonly TvDbProvider _tvDbProvider;
private readonly IRepository _sonicRepo;
private readonly TvDbProvider _tvDb; public EpisodeProvider(IRepository repository, SeasonProvider seasonProviderProvider, TvDbProvider tvDbProviderProvider)
public EpisodeProvider(IRepository sonicRepo, SeriesProvider seriesProvider,
SeasonProvider seasonProvider, TvDbProvider tvDbProvider,
QualityProvider qualityProvider)
{ {
_sonicRepo = sonicRepo; _repository = repository;
_series = seriesProvider; _tvDbProvider = tvDbProviderProvider;
_tvDb = tvDbProvider; _seasonsProvider = seasonProviderProvider;
_seasons = seasonProvider;
_qualityProvider = qualityProvider;
} }
public EpisodeProvider() public EpisodeProvider()
@ -35,36 +29,36 @@ namespace NzbDrone.Core.Providers
public virtual Episode GetEpisode(long id) public virtual Episode GetEpisode(long id)
{ {
return _sonicRepo.Single<Episode>(id); return _repository.Single<Episode>(id);
} }
public virtual Episode GetEpisode(int seriesId, int seasonNumber, int episodeNumber) public virtual Episode GetEpisode(int seriesId, int seasonNumber, int episodeNumber)
{ {
return return
_sonicRepo.Single<Episode>( _repository.Single<Episode>(
c => c.SeriesId == seriesId && c.SeasonNumber == seasonNumber && c.EpisodeNumber == episodeNumber); c => c.SeriesId == seriesId && c.SeasonNumber == seasonNumber && c.EpisodeNumber == episodeNumber);
} }
public virtual Episode GetEpisode(int seriesId, DateTime date) public virtual Episode GetEpisode(int seriesId, DateTime date)
{ {
return return
_sonicRepo.Single<Episode>( _repository.Single<Episode>(
c => c.SeriesId == seriesId && c.AirDate == date.Date); c => c.SeriesId == seriesId && c.AirDate == date.Date);
} }
public virtual IList<Episode> GetEpisodeBySeries(long seriesId) public virtual IList<Episode> GetEpisodeBySeries(long seriesId)
{ {
return _sonicRepo.Find<Episode>(e => e.SeriesId == seriesId); return _repository.Find<Episode>(e => e.SeriesId == seriesId);
} }
public virtual IList<Episode> GetEpisodeBySeason(long seasonId) public virtual IList<Episode> GetEpisodeBySeason(long seasonId)
{ {
return _sonicRepo.Find<Episode>(e => e.SeasonId == seasonId); return _repository.Find<Episode>(e => e.SeasonId == seasonId);
} }
public virtual IList<Episode> GetEpisodeByParseResult(EpisodeParseResult parseResult) public virtual IList<Episode> GetEpisodeByParseResult(EpisodeParseResult parseResult)
{ {
var seasonEpisodes = _sonicRepo.All<Episode>().Where(e => var seasonEpisodes = _repository.All<Episode>().Where(e =>
e.SeriesId == parseResult.SeriesId && e.SeriesId == parseResult.SeriesId &&
e.SeasonNumber == parseResult.SeasonNumber).ToList(); e.SeasonNumber == parseResult.SeasonNumber).ToList();
@ -102,7 +96,7 @@ namespace NzbDrone.Core.Providers
Language = "en" Language = "en"
}; };
_sonicRepo.Add(episodeInfo); _repository.Add(episodeInfo);
} }
@ -151,7 +145,7 @@ namespace NzbDrone.Core.Providers
Logger.Info("Starting episode info refresh for series:{0}", seriesId); Logger.Info("Starting episode info refresh for series:{0}", seriesId);
int successCount = 0; int successCount = 0;
int failCount = 0; int failCount = 0;
var targetSeries = _tvDb.GetSeries(seriesId, true); var targetSeries = _tvDbProvider.GetSeries(seriesId, true);
var updateList = new List<Episode>(); var updateList = new List<Episode>();
var newList = new List<Episode>(); var newList = new List<Episode>();
@ -159,7 +153,7 @@ namespace NzbDrone.Core.Providers
Logger.Debug("Updating season info for series:{0}", targetSeries.SeriesName); Logger.Debug("Updating season info for series:{0}", targetSeries.SeriesName);
targetSeries.Episodes.Select(e => new { e.SeasonId, e.SeasonNumber }) targetSeries.Episodes.Select(e => new { e.SeasonId, e.SeasonNumber })
.Distinct().ToList() .Distinct().ToList()
.ForEach(s => _seasons.EnsureSeason(seriesId, s.SeasonId, s.SeasonNumber)); .ForEach(s => _seasonsProvider.EnsureSeason(seriesId, s.SeasonId, s.SeasonNumber));
foreach (var episode in targetSeries.Episodes) foreach (var episode in targetSeries.Episodes)
{ {
@ -214,8 +208,8 @@ namespace NzbDrone.Core.Providers
} }
} }
_sonicRepo.AddMany(newList); _repository.AddMany(newList);
_sonicRepo.UpdateMany(updateList); _repository.UpdateMany(updateList);
Logger.Debug("Finished episode refresh for series:{0}. Successful:{1} - Failed:{2} ", Logger.Debug("Finished episode refresh for series:{0}. Successful:{1} - Failed:{2} ",
targetSeries.SeriesName, successCount, failCount); targetSeries.SeriesName, successCount, failCount);
@ -223,12 +217,12 @@ namespace NzbDrone.Core.Providers
public virtual void DeleteEpisode(int episodeId) public virtual void DeleteEpisode(int episodeId)
{ {
_sonicRepo.Delete<Episode>(episodeId); _repository.Delete<Episode>(episodeId);
} }
public virtual void UpdateEpisode(Episode episode) public virtual void UpdateEpisode(Episode episode)
{ {
_sonicRepo.Update(episode); _repository.Update(episode);
} }
} }
} }

@ -11,11 +11,11 @@ namespace NzbDrone.Core.Providers
public class HistoryProvider public class HistoryProvider
{ {
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly IRepository _sonicRepo; private readonly IRepository _repository;
public HistoryProvider(IRepository sonicRepo) public HistoryProvider(IRepository repository)
{ {
_sonicRepo = sonicRepo; _repository = repository;
} }
public HistoryProvider() public HistoryProvider()
@ -24,32 +24,32 @@ namespace NzbDrone.Core.Providers
public virtual IQueryable<History> AllItems() public virtual IQueryable<History> AllItems()
{ {
return _sonicRepo.All<History>(); return _repository.All<History>();
} }
public virtual void Purge() public virtual void Purge()
{ {
_sonicRepo.DeleteMany(AllItems()); _repository.DeleteMany(AllItems());
Logger.Info("History has been Purged"); Logger.Info("History has been Purged");
} }
public virtual void Trim() public virtual void Trim()
{ {
var old = AllItems().Where(h => h.Date < DateTime.Now.AddDays(-30)); var old = AllItems().Where(h => h.Date < DateTime.Now.AddDays(-30));
_sonicRepo.DeleteMany(old); _repository.DeleteMany(old);
Logger.Info("History has been trimmed, items older than 30 days have been removed"); Logger.Info("History has been trimmed, items older than 30 days have been removed");
} }
public virtual void Add(History item) public virtual void Add(History item)
{ {
_sonicRepo.Add(item); _repository.Add(item);
Logger.Debug("Item added to history: {0}", item.NzbTitle); Logger.Debug("Item added to history: {0}", item.NzbTitle);
} }
public virtual bool Exists(int episodeId, QualityTypes quality, bool proper) public virtual bool Exists(int episodeId, QualityTypes quality, bool proper)
{ {
//Looks for the existence of this episode in History //Looks for the existence of this episode in History
if (_sonicRepo.Exists<History>(h => h.EpisodeId == episodeId && h.Quality == quality && h.IsProper == proper)) if (_repository.Exists<History>(h => h.EpisodeId == episodeId && h.Quality == quality && h.IsProper == proper))
return true; return true;
Logger.Debug("Episode not in History. ID:{0} Q:{1} Proper:{2}", episodeId, quality, proper); Logger.Debug("Episode not in History. ID:{0} Q:{1} Proper:{2}", episodeId, quality, proper);

@ -159,6 +159,7 @@ namespace NzbDrone.Core.Providers
/// <param name = "files">list of files to verify</param> /// <param name = "files">list of files to verify</param>
public void CleanUp(List<EpisodeFile> files) public void CleanUp(List<EpisodeFile> files)
{ {
//TODO: remove orphaned files. in files table but not linked to from episode table.
foreach (var episodeFile in files) foreach (var episodeFile in files)
{ {
if (!_diskProvider.FileExists(episodeFile.Path)) if (!_diskProvider.FileExists(episodeFile.Path))

@ -10,48 +10,48 @@ namespace NzbDrone.Core.Providers
public class QualityProvider public class QualityProvider
{ {
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly IRepository _sonicRepo; private readonly IRepository _repository;
public QualityProvider() public QualityProvider()
{ {
} }
public QualityProvider(IRepository sonicRepo) public QualityProvider(IRepository repository)
{ {
_sonicRepo = sonicRepo; _repository = repository;
} }
public virtual int Add(QualityProfile profile) public virtual int Add(QualityProfile profile)
{ {
return Convert.ToInt32(_sonicRepo.Add(profile)); return Convert.ToInt32(_repository.Add(profile));
} }
public virtual void Update(QualityProfile profile) public virtual void Update(QualityProfile profile)
{ {
if (!_sonicRepo.Exists<QualityProfile>(q => q.QualityProfileId == profile.QualityProfileId)) if (!_repository.Exists<QualityProfile>(q => q.QualityProfileId == profile.QualityProfileId))
{ {
Logger.Error("Unable to update non-existing profile"); Logger.Error("Unable to update non-existing profile");
throw new InvalidOperationException("Unable to update non-existing profile"); throw new InvalidOperationException("Unable to update non-existing profile");
} }
_sonicRepo.Update(profile); _repository.Update(profile);
} }
public virtual void Delete(int profileId) public virtual void Delete(int profileId)
{ {
_sonicRepo.Delete<QualityProfile>(profileId); _repository.Delete<QualityProfile>(profileId);
} }
public virtual List<QualityProfile> GetAllProfiles() public virtual List<QualityProfile> GetAllProfiles()
{ {
var profiles = _sonicRepo.All<QualityProfile>().ToList(); var profiles = _repository.All<QualityProfile>().ToList();
return profiles; return profiles;
} }
public virtual QualityProfile Find(int profileId) public virtual QualityProfile Find(int profileId)
{ {
return _sonicRepo.Single<QualityProfile>(q => q.QualityProfileId == profileId); return _repository.Single<QualityProfile>(q => q.QualityProfileId == profileId);
} }
} }
} }

@ -12,16 +12,19 @@ namespace NzbDrone.Core.Providers
{ {
public class RenameProvider public class RenameProvider
{ {
//TODO: Remove some of these dependencies. we shouldn't have a single class with dependency on the whole app!
//TODO: Also upgrade to a job that can run on background thread.
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly ConfigProvider _configProvider; private readonly ConfigProvider _configProvider;
private readonly DiskProvider _diskProvider; private readonly DiskProvider _diskProvider;
private readonly EpisodeProvider _episodeProvider; private readonly EpisodeProvider _episodeProvider;
private readonly List<EpisodeRenameModel> _epsToRename = new List<EpisodeRenameModel>();
private readonly ExternalNotificationProvider _externalNotificationProvider; private readonly ExternalNotificationProvider _externalNotificationProvider;
private readonly MediaFileProvider _mediaFileProvider; private readonly MediaFileProvider _mediaFileProvider;
private readonly SeasonProvider _seasonProvider; private readonly SeasonProvider _seasonProvider;
private readonly SeriesProvider _seriesProvider; private readonly SeriesProvider _seriesProvider;
private readonly List<EpisodeRenameModel> _epsToRename = new List<EpisodeRenameModel>();
private Thread _renameThread; private Thread _renameThread;
public RenameProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider, public RenameProvider(SeriesProvider seriesProvider, SeasonProvider seasonProvider,

@ -13,25 +13,25 @@ namespace NzbDrone.Core.Providers
public class SabProvider public class SabProvider
{ {
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly ConfigProvider _config; private readonly ConfigProvider _configProvider;
private readonly HttpProvider _http; private readonly HttpProvider _httpProvider;
public SabProvider() public SabProvider()
{ {
} }
public SabProvider(ConfigProvider config, HttpProvider http) public SabProvider(ConfigProvider configProvider, HttpProvider httpProvider)
{ {
_config = config; _configProvider = configProvider;
_http = http; _httpProvider = httpProvider;
} }
public virtual bool AddByUrl(string url, string title) public virtual bool AddByUrl(string url, string title)
{ {
const string mode = "addurl"; const string mode = "addurl";
string cat = _config.GetValue("SabTvCategory", String.Empty, true); string cat = _configProvider.GetValue("SabTvCategory", String.Empty, true);
//string cat = "tv"; //string cat = "tv";
string priority = _config.GetValue("SabTvPriority", String.Empty, false); string priority = _configProvider.GetValue("SabTvPriority", String.Empty, false);
string name = url.Replace("&", "%26"); string name = url.Replace("&", "%26");
string nzbName = HttpUtility.UrlEncode(title); string nzbName = HttpUtility.UrlEncode(title);
@ -41,7 +41,7 @@ namespace NzbDrone.Core.Providers
Logger.Debug("Adding report [{0}] to the queue.", nzbName); Logger.Debug("Adding report [{0}] to the queue.", nzbName);
string response = _http.DownloadString(request).Replace("\n", String.Empty); string response = _httpProvider.DownloadString(request).Replace("\n", String.Empty);
Logger.Debug("Queue Repsonse: [{0}]", response); Logger.Debug("Queue Repsonse: [{0}]", response);
if (response == "ok") if (response == "ok")
@ -54,7 +54,7 @@ namespace NzbDrone.Core.Providers
{ {
const string action = "mode=queue&output=xml"; const string action = "mode=queue&output=xml";
string request = GetSabRequest(action); string request = GetSabRequest(action);
string response = _http.DownloadString(request); string response = _httpProvider.DownloadString(request);
XDocument xDoc = XDocument.Parse(response); XDocument xDoc = XDocument.Parse(response);
@ -84,9 +84,9 @@ namespace NzbDrone.Core.Providers
//mode=addid&name=333333&pp=3&script=customscript.cmd&cat=Example&priority=-1 //mode=addid&name=333333&pp=3&script=customscript.cmd&cat=Example&priority=-1
const string mode = "addid"; const string mode = "addid";
string cat = _config.GetValue("SabTvCategory", String.Empty, true); string cat = _configProvider.GetValue("SabTvCategory", String.Empty, true);
//string cat = "tv"; //string cat = "tv";
string priority = _config.GetValue("SabTvPriority", String.Empty, false); string priority = _configProvider.GetValue("SabTvPriority", String.Empty, false);
string nzbName = HttpUtility.UrlEncode(title); string nzbName = HttpUtility.UrlEncode(title);
string action = string.Format("mode={0}&name={1}&priority={2}&cat={3}&nzbname={4}", mode, id, priority, cat, string action = string.Format("mode={0}&name={1}&priority={2}&cat={3}&nzbname={4}", mode, id, priority, cat,
@ -95,7 +95,7 @@ namespace NzbDrone.Core.Providers
Logger.Debug("Adding report [{0}] to the queue.", nzbName); Logger.Debug("Adding report [{0}] to the queue.", nzbName);
string response = _http.DownloadString(request).Replace("\n", String.Empty); string response = _httpProvider.DownloadString(request).Replace("\n", String.Empty);
Logger.Debug("Queue Repsonse: [{0}]", response); Logger.Debug("Queue Repsonse: [{0}]", response);
if (response == "ok") if (response == "ok")
@ -106,11 +106,11 @@ namespace NzbDrone.Core.Providers
private string GetSabRequest(string action) private string GetSabRequest(string action)
{ {
string sabnzbdInfo = _config.GetValue("SabHost", String.Empty, false) + ":" + string sabnzbdInfo = _configProvider.GetValue("SabHost", String.Empty, false) + ":" +
_config.GetValue("SabPort", String.Empty, false); _configProvider.GetValue("SabPort", String.Empty, false);
string username = _config.GetValue("SabUsername", String.Empty, false); string username = _configProvider.GetValue("SabUsername", String.Empty, false);
string password = _config.GetValue("SabPassword", String.Empty, false); string password = _configProvider.GetValue("SabPassword", String.Empty, false);
string apiKey = _config.GetValue("SabApiKey", String.Empty, false); string apiKey = _configProvider.GetValue("SabApiKey", String.Empty, false);
return return
string.Format(@"http://{0}/api?$Action&apikey={1}&ma_username={2}&ma_password={3}", sabnzbdInfo, apiKey, string.Format(@"http://{0}/api?$Action&apikey={1}&ma_username={2}&ma_password={3}", sabnzbdInfo, apiKey,

@ -10,11 +10,11 @@ namespace NzbDrone.Core.Providers
public class SeasonProvider public class SeasonProvider
{ {
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly IRepository _sonicRepo; private readonly IRepository _repository;
public SeasonProvider(IRepository dataRepository) public SeasonProvider(IRepository repository)
{ {
_sonicRepo = dataRepository; _repository = repository;
} }
public SeasonProvider() public SeasonProvider()
@ -23,27 +23,27 @@ namespace NzbDrone.Core.Providers
public virtual Season GetSeason(int seasonId) public virtual Season GetSeason(int seasonId)
{ {
return _sonicRepo.Single<Season>(seasonId); return _repository.Single<Season>(seasonId);
} }
public virtual Season GetSeason(int seriesId, int seasonNumber) public virtual Season GetSeason(int seriesId, int seasonNumber)
{ {
return _sonicRepo.Single<Season>(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber); return _repository.Single<Season>(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber);
} }
public virtual List<Season> GetSeasons(int seriesId) public virtual List<Season> GetSeasons(int seriesId)
{ {
return _sonicRepo.All<Season>().Where(s => s.SeriesId == seriesId).ToList(); return _repository.All<Season>().Where(s => s.SeriesId == seriesId).ToList();
} }
public virtual Season GetLatestSeason(int seriesId) public virtual Season GetLatestSeason(int seriesId)
{ {
return _sonicRepo.All<Season>().Where(s => s.SeriesId == seriesId).OrderBy(s => s.SeasonNumber).Last(); return _repository.All<Season>().Where(s => s.SeriesId == seriesId).OrderBy(s => s.SeasonNumber).Last();
} }
public virtual void EnsureSeason(int seriesId, int seasonId, int seasonNumber) public virtual void EnsureSeason(int seriesId, int seasonId, int seasonNumber)
{ {
if (_sonicRepo.Exists<Season>(s => s.SeasonId == seasonId)) if (_repository.Exists<Season>(s => s.SeasonId == seasonId))
return; return;
//TODO: Calculate Season Folder //TODO: Calculate Season Folder
Logger.Trace("Adding Season To DB. [SeriesID:{0} SeasonID:{1} SeasonNumber:{2}]", seriesId, seasonId, Logger.Trace("Adding Season To DB. [SeriesID:{0} SeasonID:{1} SeasonNumber:{2}]", seriesId, seasonId,
@ -56,7 +56,7 @@ namespace NzbDrone.Core.Providers
SeasonNumber = seasonNumber, SeasonNumber = seasonNumber,
SeriesId = seriesId SeriesId = seriesId
}; };
_sonicRepo.Add(newSeason); _repository.Add(newSeason);
} }
public virtual int SaveSeason(Season season) public virtual int SaveSeason(Season season)
@ -66,7 +66,7 @@ namespace NzbDrone.Core.Providers
public virtual bool IsIgnored(int seasonId) public virtual bool IsIgnored(int seasonId)
{ {
if (_sonicRepo.Single<Season>(seasonId).Monitored) if (_repository.Single<Season>(seasonId).Monitored)
return false; return false;
Logger.Debug("Season {0} is not wanted."); Logger.Debug("Season {0} is not wanted.");
@ -75,13 +75,13 @@ namespace NzbDrone.Core.Providers
public virtual bool IsIgnored(int seriesId, int seasonNumber) public virtual bool IsIgnored(int seriesId, int seasonNumber)
{ {
var season = _sonicRepo.Single<Season>(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber); var season = _repository.Single<Season>(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber);
return !season.Monitored; return !season.Monitored;
} }
public void DeleteSeason(int seasonId) public void DeleteSeason(int seasonId)
{ {
_sonicRepo.Delete<Season>(seasonId); _repository.Delete<Season>(seasonId);
} }
} }
} }

@ -13,22 +13,18 @@ namespace NzbDrone.Core.Providers
public class SeriesProvider public class SeriesProvider
{ {
//TODO: Remove parsing of rest of tv show info we just need the show name //TODO: Remove parsing of rest of tv show info we just need the show name
//Trims all white spaces and separators from the end of the title. //Trims all white spaces and separators from the end of the title.
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly ConfigProvider _config; private readonly IRepository _repository;
private readonly QualityProvider _quality; private readonly ConfigProvider _configProvider;
private readonly IRepository _sonioRepo; private readonly TvDbProvider _tvDbProvider;
private readonly TvDbProvider _tvDb;
public SeriesProvider(ConfigProvider configProvider, public SeriesProvider(ConfigProvider configProviderProvider, IRepository repository, TvDbProvider tvDbProviderProvider)
IRepository dataRepository, TvDbProvider tvDbProvider, QualityProvider quality)
{ {
_config = configProvider; _configProvider = configProviderProvider;
_sonioRepo = dataRepository; _repository = repository;
_tvDb = tvDbProvider; _tvDbProvider = tvDbProviderProvider;
_quality = quality;
} }
public SeriesProvider() public SeriesProvider()
@ -37,12 +33,12 @@ namespace NzbDrone.Core.Providers
public virtual IQueryable<Series> GetAllSeries() public virtual IQueryable<Series> GetAllSeries()
{ {
return _sonioRepo.All<Series>(); return _repository.All<Series>();
} }
public virtual Series GetSeries(int seriesId) public virtual Series GetSeries(int seriesId)
{ {
return _sonioRepo.Single<Series>(s => s.SeriesId == seriesId); return _repository.Single<Series>(s => s.SeriesId == seriesId);
} }
/// <summary> /// <summary>
@ -52,12 +48,12 @@ namespace NzbDrone.Core.Providers
/// <returns>Whether or not the show is monitored</returns> /// <returns>Whether or not the show is monitored</returns>
public virtual bool IsMonitored(long id) public virtual bool IsMonitored(long id)
{ {
return _sonioRepo.Exists<Series>(c => c.SeriesId == id && c.Monitored); return _repository.Exists<Series>(c => c.SeriesId == id && c.Monitored);
} }
public virtual bool QualityWanted(int seriesId, QualityTypes quality) public virtual bool QualityWanted(int seriesId, QualityTypes quality)
{ {
var series = _sonioRepo.Single<Series>(seriesId); var series = _repository.Single<Series>(seriesId);
Logger.Trace("Series {0} is using quality profile {1}", seriesId, series.QualityProfile.Name); Logger.Trace("Series {0} is using quality profile {1}", seriesId, series.QualityProfile.Name);
return series.QualityProfile.Allowed.Contains(quality); return series.QualityProfile.Allowed.Contains(quality);
} }
@ -65,17 +61,17 @@ namespace NzbDrone.Core.Providers
public virtual TvdbSeries MapPathToSeries(string path) public virtual TvdbSeries MapPathToSeries(string path)
{ {
var seriesPath = new DirectoryInfo(path); var seriesPath = new DirectoryInfo(path);
var searchResults = _tvDb.GetSeries(seriesPath.Name); var searchResults = _tvDbProvider.GetSeries(seriesPath.Name);
if (searchResults == null) if (searchResults == null)
return null; return null;
return _tvDb.GetSeries(searchResults.Id, false); return _tvDbProvider.GetSeries(searchResults.Id, false);
} }
public virtual Series UpdateSeriesInfo(int seriesId) public virtual Series UpdateSeriesInfo(int seriesId)
{ {
var tvDbSeries = _tvDb.GetSeries(seriesId, true); var tvDbSeries = _tvDbProvider.GetSeries(seriesId, true);
var series = GetSeries(seriesId); var series = GetSeries(seriesId);
series.SeriesId = tvDbSeries.Id; series.SeriesId = tvDbSeries.Id;
@ -102,22 +98,22 @@ namespace NzbDrone.Core.Providers
repoSeries.Monitored = true; //New shows should be monitored repoSeries.Monitored = true; //New shows should be monitored
repoSeries.QualityProfileId = qualityProfileId; repoSeries.QualityProfileId = qualityProfileId;
if (qualityProfileId == 0) if (qualityProfileId == 0)
repoSeries.QualityProfileId = Convert.ToInt32(_config.GetValue("DefaultQualityProfile", "1", true)); repoSeries.QualityProfileId = Convert.ToInt32(_configProvider.GetValue("DefaultQualityProfile", "1", true));
repoSeries.SeasonFolder = _config.UseSeasonFolder; repoSeries.SeasonFolder = _configProvider.UseSeasonFolder;
_sonioRepo.Add(repoSeries); _repository.Add(repoSeries);
} }
public virtual Series FindSeries(string title) public virtual Series FindSeries(string title)
{ {
var normalizeTitle = Parser.NormalizeTitle(title); var normalizeTitle = Parser.NormalizeTitle(title);
return _sonioRepo.Single<Series>(s => s.CleanTitle == normalizeTitle); return _repository.Single<Series>(s => s.CleanTitle == normalizeTitle);
} }
public virtual void UpdateSeries(Series series) public virtual void UpdateSeries(Series series)
{ {
_sonioRepo.Update(series); _repository.Update(series);
} }
public virtual void DeleteSeries(int seriesId) public virtual void DeleteSeries(int seriesId)
@ -126,22 +122,22 @@ namespace NzbDrone.Core.Providers
try try
{ {
var series = _sonioRepo.Single<Series>(seriesId); var series = _repository.Single<Series>(seriesId);
//Delete Files, Episdes, Seasons then the Series //Delete Files, Episdes, Seasons then the Series
//Can't use providers because episode provider needs series provider - Cyclic Dependency Injection, this will work //Can't use providers because episode provider needs series provider - Cyclic Dependency Injection, this will work
Logger.Debug("Deleting EpisodeFiles from DB for Series: {0}", series.SeriesId); Logger.Debug("Deleting EpisodeFiles from DB for Series: {0}", series.SeriesId);
_sonioRepo.DeleteMany(series.EpisodeFiles); _repository.DeleteMany(series.EpisodeFiles);
Logger.Debug("Deleting Episodes from DB for Series: {0}", series.SeriesId); Logger.Debug("Deleting Episodes from DB for Series: {0}", series.SeriesId);
_sonioRepo.DeleteMany(series.Episodes); _repository.DeleteMany(series.Episodes);
Logger.Debug("Deleting Seasons from DB for Series: {0}", series.SeriesId); Logger.Debug("Deleting Seasons from DB for Series: {0}", series.SeriesId);
_sonioRepo.DeleteMany(series.Seasons); _repository.DeleteMany(series.Seasons);
Logger.Debug("Deleting Series from DB {0}", series.Title); Logger.Debug("Deleting Series from DB {0}", series.Title);
_sonioRepo.Delete<Series>(seriesId); _repository.Delete<Series>(seriesId);
Logger.Info("Successfully deleted Series [{0}]", seriesId); Logger.Info("Successfully deleted Series [{0}]", seriesId);
} }
@ -154,7 +150,7 @@ namespace NzbDrone.Core.Providers
public virtual bool SeriesPathExists(string cleanPath) public virtual bool SeriesPathExists(string cleanPath)
{ {
if (_sonioRepo.Exists<Series>(s => s.Path == cleanPath)) if (_repository.Exists<Series>(s => s.Path == cleanPath))
return true; return true;
return false; return false;

@ -9,17 +9,17 @@ namespace NzbDrone.Core.Providers
{ {
public class UpcomingEpisodesProvider public class UpcomingEpisodesProvider
{ {
private readonly IRepository _sonicRepo; private readonly IRepository _repository;
public UpcomingEpisodesProvider(IRepository sonicRepo) public UpcomingEpisodesProvider(IRepository repository)
{ {
_sonicRepo = sonicRepo; _repository = repository;
} }
public virtual UpcomingEpisodesModel Upcoming() public virtual UpcomingEpisodesModel Upcoming()
{ {
var allEps = var allEps =
_sonicRepo.All<Episode>().Where( _repository.All<Episode>().Where(
e => e.AirDate >= DateTime.Today.AddDays(-1) && e.AirDate < DateTime.Today.AddDays(8)); e => e.AirDate >= DateTime.Today.AddDays(-1) && e.AirDate < DateTime.Today.AddDays(8));
var yesterday = allEps.Where(e => e.AirDate == DateTime.Today.AddDays(-1)).ToList(); var yesterday = allEps.Where(e => e.AirDate == DateTime.Today.AddDays(-1)).ToList();
@ -31,18 +31,18 @@ namespace NzbDrone.Core.Providers
public virtual List<Episode> Yesterday() public virtual List<Episode> Yesterday()
{ {
return _sonicRepo.All<Episode>().Where(e => e.AirDate == DateTime.Today.AddDays(-1)).ToList(); return _repository.All<Episode>().Where(e => e.AirDate == DateTime.Today.AddDays(-1)).ToList();
} }
public virtual List<Episode> Today() public virtual List<Episode> Today()
{ {
return _sonicRepo.All<Episode>().Where(e => e.AirDate == DateTime.Today).ToList(); return _repository.All<Episode>().Where(e => e.AirDate == DateTime.Today).ToList();
} }
public virtual List<Episode> Week() public virtual List<Episode> Week()
{ {
return return
_sonicRepo.All<Episode>().Where(e => e.AirDate > DateTime.Today && e.AirDate < DateTime.Today.AddDays(8)) _repository.All<Episode>().Where(e => e.AirDate > DateTime.Today && e.AirDate < DateTime.Today.AddDays(8))
.ToList(); .ToList();
} }
} }

Loading…
Cancel
Save