From 613a49c3ea9102e3fd40500ea0b22d77c67d4492 Mon Sep 17 00:00:00 2001 From: Keivan Date: Mon, 28 Mar 2011 14:57:06 -0700 Subject: [PATCH] Refactored BacklogProvider Fixed some issues with root folder and settings controller --- IISExpress/AppServer/applicationhost.config | 2 +- NzbDrone.Core/Providers/BacklogProvider.cs | 147 +++++++++--------- .../Controllers/SettingsController.cs | 43 ++--- NzbDrone/ProcessAttacher.cs | 11 +- NzbDrone/app.config | 2 +- 5 files changed, 107 insertions(+), 98 deletions(-) diff --git a/IISExpress/AppServer/applicationhost.config b/IISExpress/AppServer/applicationhost.config index 6c56a7b72..ffcf44ec6 100644 --- a/IISExpress/AppServer/applicationhost.config +++ b/IISExpress/AppServer/applicationhost.config @@ -148,7 +148,7 @@ - + diff --git a/NzbDrone.Core/Providers/BacklogProvider.cs b/NzbDrone.Core/Providers/BacklogProvider.cs index f32b8f808..a4bda3e4b 100644 --- a/NzbDrone.Core/Providers/BacklogProvider.cs +++ b/NzbDrone.Core/Providers/BacklogProvider.cs @@ -121,78 +121,7 @@ namespace NzbDrone.Core.Providers foreach (var series in _seriesList) { - try - { - //Do the searching here - _backlogSearchNotification.CurrentStatus = String.Format("Backlog Searching For: {0}", series.Title); - - var sceneNames = SceneNameHelper.FindById(series.SeriesId); - - if (sceneNames.Count < 1) - sceneNames.Add(series.Title); - - foreach (var season in series.Seasons) - { - var episodesWithoutFiles = season.Episodes.Where(e => e.EpisodeFileId == 0); - - if (season.Episodes.Count() == episodesWithoutFiles.Count()) - { - //Whole season needs to be grabbed, look for the whole season first - //Lookup scene name using seriesId - - foreach (var sceneName in sceneNames) - { - var searchString = String.Format("{0} Season {1}", sceneName, - season.SeasonNumber); - - foreach (var i in _indexerProvider.EnabledIndexers()) - { - //Get the users URL - GetUsersUrl(i, searchString); - - //If the url still contains '{' & '}' the user probably hasn't configured the indexer settings - if (i.ApiUrl.Contains("{") && i.ApiUrl.Contains("}")) - { - Logger.Debug("Unable to Sync {0}. User Information has not been configured.", i.IndexerName); - continue; //Skip this indexer - } - - var indexer = new FeedInfoModel(i.IndexerName, i.ApiUrl); - - var feedItems = _rssProvider.GetFeed(indexer); - - if (feedItems.Count() == 0) - { - Logger.Debug("Failed to download Backlog Search URL: {0}", indexer.Name); - continue; //No need to process anything else - } - - foreach (RssItem item in feedItems) - { - NzbInfoModel nzb = Parser.ParseNzbInfo(indexer, item); - QueueSeasonIfWanted(nzb, i); - } - - } - } - } - - else - { - //Grab the episodes 1-by-1 (or in smaller chunks) - - } - - } - //Done searching for each episode - } - - catch (Exception ex) - { - Logger.WarnException(ex.Message, ex); - } - - _backlogSearchNotification.ProgressValue++; + BackLogSeries(series); } _backlogSearchNotification.CurrentStatus = "Backlog Search Completed"; @@ -208,6 +137,80 @@ namespace NzbDrone.Core.Providers } } + private void BackLogSeries(Series series) + { + try + { + //Do the searching here + _backlogSearchNotification.CurrentStatus = String.Format("Backlog Searching For: {0}", series.Title); + + var sceneNames = SceneNameHelper.FindById(series.SeriesId); + + if (sceneNames.Count < 1) + sceneNames.Add(series.Title); + + foreach (var season in series.Seasons) + { + BackLogSeason(sceneNames, season); + } + //Done searching for each episode + } + + catch (Exception ex) + { + Logger.WarnException(ex.Message, ex); + } + + _backlogSearchNotification.ProgressValue++; + } + + private void BackLogSeason(List sceneNames, Season season) + { + var episodesWithoutFiles = season.Episodes.Where(e => e.EpisodeFileId == 0); + + if (season.Episodes.Count() == episodesWithoutFiles.Count()) + { + //Whole season needs to be grabbed, look for the whole season first + //Lookup scene name using seriesId + + foreach (var sceneName in sceneNames) + { + var searchString = String.Format("{0} Season {1}", sceneName, + season.SeasonNumber); + + foreach (var i in _indexerProvider.EnabledIndexers()) + { + //Get the users URL + GetUsersUrl(i, searchString); + + //If the url still contains '{' & '}' the user probably hasn't configured the indexer settings + if (i.ApiUrl.Contains("{") && i.ApiUrl.Contains("}")) + { + Logger.Debug("Unable to Sync {0}. User Information has not been configured.", i.IndexerName); + continue; //Skip this indexer + } + + var indexer = new FeedInfoModel(i.IndexerName, i.ApiUrl); + + var feedItems = _rssProvider.GetFeed(indexer); + + if (feedItems.Count() == 0) + { + Logger.Debug("Failed to download Backlog Search URL: {0}", indexer.Name); + continue; //No need to process anything else + } + + foreach (RssItem item in feedItems) + { + NzbInfoModel nzb = Parser.ParseNzbInfo(indexer, item); + QueueSeasonIfWanted(nzb, i); + } + + } + } + } + } + private void GetUsersUrl(Indexer indexer, string searchString) { if (indexer.IndexerName == "NzbMatrix") diff --git a/NzbDrone.Web/Controllers/SettingsController.cs b/NzbDrone.Web/Controllers/SettingsController.cs index af85a78bd..8a3e2667f 100644 --- a/NzbDrone.Web/Controllers/SettingsController.cs +++ b/NzbDrone.Web/Controllers/SettingsController.cs @@ -24,8 +24,8 @@ namespace NzbDrone.Web.Controllers private IRootDirProvider _rootDirProvider; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - private string _settingsSaved = "Settings Saved."; - private string _settingsFailed = "Error Saving Settings, please fix any errors"; + private const string SETTINGS_SAVED = "Settings Saved."; + private const string SETTINGS_FAILED = "Error Saving Settings, please fix any errors"; public SettingsController(IConfigProvider configProvider, IIndexerProvider indexerProvider, IQualityProvider qualityProvider, IRootDirProvider rootDirProvider) @@ -50,10 +50,10 @@ namespace NzbDrone.Web.Controllers public ActionResult General() { ViewData["viewName"] = "General"; - + return View("Index", new SettingsModel { - Directories = new List() + Directories = _rootDirProvider.GetAll() }); } @@ -211,11 +211,14 @@ namespace NzbDrone.Web.Controllers [HttpPost] public ActionResult SaveGeneral(SettingsModel data) { - if (data.Directories.Count > 0) + if (data.Directories != null && data.Directories.Count > 0) { //If the Javascript was beaten we need to return an error - if (!data.Directories.Exists(d => d.Default)) - return Content(_settingsFailed); + + /* + * Kay.one: I can't see what its doing, all it does it dooesn't let me s. + * if (!data.Directories.Exists(d => d.Default)) + return Content(SETTINGS_FAILED);*/ var currentRootDirs = _rootDirProvider.GetAll(); @@ -235,10 +238,10 @@ namespace NzbDrone.Web.Controllers _rootDirProvider.Update(dir); } - return Content(_settingsSaved); + return Content(SETTINGS_SAVED); } - return Content(_settingsFailed); + return Content(SETTINGS_FAILED); } [HttpPost] @@ -257,10 +260,10 @@ namespace NzbDrone.Web.Controllers _configProvider.SetValue("NzbsrusUId", data.NzbsrusUId); _configProvider.SetValue("NzbsrusHash", data.NzbsrusHash); - return Content(_settingsSaved); + return Content(SETTINGS_SAVED); } - return Content(_settingsFailed); + return Content(SETTINGS_FAILED); } [HttpPost] @@ -281,10 +284,10 @@ namespace NzbDrone.Web.Controllers _configProvider.SetValue("UseBlackhole", data.UseBlackHole.ToString()); _configProvider.SetValue("BlackholeDirectory", data.BlackholeDirectory); - return Content(_settingsSaved); + return Content(SETTINGS_SAVED); } - return Content(_settingsFailed); + return Content(SETTINGS_FAILED); } [HttpPost] @@ -296,7 +299,7 @@ namespace NzbDrone.Web.Controllers //Saves only the Default Quality, skips User Profiles since none exist if (data.UserProfiles == null) - return Content(_settingsSaved); + return Content(SETTINGS_SAVED); foreach (var dbProfile in _qualityProvider.GetAllProfiles().Where(q => q.UserProfile)) { @@ -326,11 +329,11 @@ namespace NzbDrone.Web.Controllers else _qualityProvider.Add(profile); - return Content(_settingsSaved); + return Content(SETTINGS_SAVED); } } - return Content(_settingsFailed); + return Content(SETTINGS_FAILED); } [HttpPost] @@ -353,10 +356,10 @@ namespace NzbDrone.Web.Controllers _configProvider.SetValue("XbmcUsername", data.XbmcUsername); _configProvider.SetValue("XbmcPassword", data.XbmcPassword); - return Content(_settingsSaved); + return Content(SETTINGS_SAVED); } - return Content(_settingsFailed); + return Content(SETTINGS_FAILED); } [HttpPost] @@ -375,10 +378,10 @@ namespace NzbDrone.Web.Controllers _configProvider.SetValue("Sorting_NumberStyle", data.NumberStyle.ToString()); _configProvider.SetValue("Sorting_MultiEpisodeStyle", data.MultiEpisodeStyle.ToString()); - return Content(_settingsSaved); + return Content(SETTINGS_SAVED); } - return Content(_settingsFailed); + return Content(SETTINGS_FAILED); } } } diff --git a/NzbDrone/ProcessAttacher.cs b/NzbDrone/ProcessAttacher.cs index 53b0028cb..c1cabb76a 100644 --- a/NzbDrone/ProcessAttacher.cs +++ b/NzbDrone/ProcessAttacher.cs @@ -7,6 +7,7 @@ #if DEBUG using System; using System.Collections.Generic; +using EnvDTE; using EnvDTE80; namespace NzbDrone @@ -21,6 +22,8 @@ namespace NzbDrone ManagedAndNative } + + private enum AttachResult { Attached, @@ -40,7 +43,7 @@ namespace NzbDrone } -#region private + #region private private readonly Dictionary _attachTypesMap; private readonly DTE2 _dte; @@ -49,7 +52,7 @@ namespace NzbDrone #endregion -#region ctor + #region ctor private ProcessAttacher(DTE2 dte, string processName, int waitTimeout) { @@ -63,7 +66,7 @@ namespace NzbDrone #endregion -#region private methods + #region private methods private AttachResult Attach(AttachType attachType) { @@ -130,7 +133,7 @@ namespace NzbDrone #endregion -#region public methods + #region public methods public void OptimisticAttachManaged() diff --git a/NzbDrone/app.config b/NzbDrone/app.config index 81d395705..c0e72973b 100644 --- a/NzbDrone/app.config +++ b/NzbDrone/app.config @@ -4,6 +4,6 @@ - + \ No newline at end of file