From a7780fab673c8a58162d78922628d4535522cd78 Mon Sep 17 00:00:00 2001 From: markus101 Date: Tue, 15 Feb 2011 23:58:39 -0800 Subject: [PATCH] Issue with overwriting user settings for Indexers resolved. Reworked RssSyncProvider to make it cleaner. SeasonProvider was returning the reveresed boolean result Indexer changed to not store empty strings as null when saving config (ApiUrl). --- NzbDrone.Core/CentralDispatch.cs | 38 +++++++++++++--------- NzbDrone.Core/Providers/RssSyncProvider.cs | 21 ++++++------ NzbDrone.Core/Providers/SeasonProvider.cs | 8 ++--- NzbDrone.Core/Repository/Indexer.cs | 4 ++- 4 files changed, 40 insertions(+), 31 deletions(-) diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index c1b6faaf6..732fd253c 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -66,7 +66,7 @@ namespace NzbDrone.Core _kernel.Bind().To().InSingletonScope(); _kernel.Bind().To().InSingletonScope(); _kernel.Bind().To().InSingletonScope(); - _kernel.Bind().To().InSingletonScope();; + _kernel.Bind().To().InSingletonScope(); ; _kernel.Bind().To().InSingletonScope(); _kernel.Bind().To().InSingletonScope(); _kernel.Bind().To().InSingletonScope(); @@ -176,7 +176,6 @@ namespace NzbDrone.Core IndexerName = "NzbMatrix", RssUrl = nzbMatrixRss, ApiUrl = String.Empty, - Enabled = false, Order = 1 }; @@ -185,7 +184,6 @@ namespace NzbDrone.Core IndexerName = "NzbsOrg", RssUrl = nzbsOrgRss, ApiUrl = String.Empty, - Enabled = false, Order = 2 }; @@ -194,13 +192,13 @@ namespace NzbDrone.Core IndexerName = "Nzbsrus", RssUrl = nzbsrusRss, ApiUrl = String.Empty, - Enabled = false, Order = 3 }; //NzbMatrix Logger.Debug("Checking for NzbMatrix Indexer"); - if (!repository.Exists(i => i.IndexerName == "NzbMatrix")) + var nzbMatix = repository.Single("NzbMatrix"); + if (nzbMatix == null) { Logger.Debug("Adding new Indexer: NzbMatrix"); repository.Add(nzbMatrixIndexer); @@ -209,12 +207,15 @@ namespace NzbDrone.Core else { Logger.Debug("Updating Indexer: NzbMatrix"); - repository.Update(nzbMatrixIndexer); + nzbMatix.RssUrl = nzbMatrixIndexer.RssUrl; + nzbMatix.ApiUrl = nzbMatrixIndexer.ApiUrl; + repository.Update(nzbMatix); } //Nzbs.org Logger.Debug("Checking for Nzbs.org"); - if (!repository.Exists(i => i.IndexerName == "NzbsOrg")) + var nzbsOrg = repository.Single("NzbsOrg"); + if (nzbsOrg == null) { Logger.Debug("Adding new Indexer: Nzbs.org"); repository.Add(nzbsOrgIndexer); @@ -223,12 +224,15 @@ namespace NzbDrone.Core else { Logger.Debug("Updating Indexer: Nzbs.org"); - repository.Update(nzbsOrgIndexer); + nzbsOrg.RssUrl = nzbsOrgIndexer.RssUrl; + nzbsOrg.ApiUrl = nzbsOrgIndexer.ApiUrl; + repository.Update(nzbsOrg); } //Nzbsrus Logger.Debug("Checking for Nzbsrus"); - if (!repository.Exists(i => i.IndexerName == "Nzbsrus")) + var nzbsrus = repository.Single("Nzbsrus"); + if (nzbsrus == null) { Logger.Debug("Adding new Indexer: Nzbsrus"); repository.Add(nzbsrusIndexer); @@ -237,7 +241,9 @@ namespace NzbDrone.Core else { Logger.Debug("Updating Indexer: Nzbsrus"); - repository.Update(nzbsrusIndexer); + nzbsrus.RssUrl = nzbsOrgIndexer.RssUrl; + nzbsrus.ApiUrl = nzbsOrgIndexer.ApiUrl; + repository.Update(nzbsrus); } } @@ -246,42 +252,42 @@ namespace NzbDrone.Core var sdtv = new QualityProfile { Name = "SDTV", - Allowed = new List {QualityTypes.TV}, + Allowed = new List { QualityTypes.TV }, Cutoff = QualityTypes.TV }; var dvd = new QualityProfile { Name = "DVD SD", - Allowed = new List {QualityTypes.DVD}, + Allowed = new List { QualityTypes.DVD }, Cutoff = QualityTypes.DVD }; var bdrip = new QualityProfile { Name = "BDRip", - Allowed = new List {QualityTypes.BDRip}, + Allowed = new List { QualityTypes.BDRip }, Cutoff = QualityTypes.BDRip }; var hdtv = new QualityProfile { Name = "HDTV", - Allowed = new List {QualityTypes.HDTV}, + Allowed = new List { QualityTypes.HDTV }, Cutoff = QualityTypes.HDTV }; var webdl = new QualityProfile { Name = "WEBDL", - Allowed = new List {QualityTypes.WEBDL}, + Allowed = new List { QualityTypes.WEBDL }, Cutoff = QualityTypes.WEBDL }; var bluray = new QualityProfile { Name = "Bluray", - Allowed = new List {QualityTypes.Bluray}, + Allowed = new List { QualityTypes.Bluray }, Cutoff = QualityTypes.Bluray }; diff --git a/NzbDrone.Core/Providers/RssSyncProvider.cs b/NzbDrone.Core/Providers/RssSyncProvider.cs index 468662930..83eb9fa50 100644 --- a/NzbDrone.Core/Providers/RssSyncProvider.cs +++ b/NzbDrone.Core/Providers/RssSyncProvider.cs @@ -87,9 +87,10 @@ namespace NzbDrone.Core.Providers { Logger.Info("Starting RSS Sync for: {0}", i.IndexerName); //Need to insert the users information in the the URL before trying to use it - i.RssUrl = GetUsersUrl(i); //Get the new users specific url (with their information) to use for the Sync + GetUsersUrl(i); //Get the new users specific url (with their information) to use for the Sync - if (i.RssUrl == null) + //If the url still contains '{' & '}' the user probably hasn't configured the indexer settings + if (i.RssUrl.Contains("{") && i.RssUrl.Contains("}")) { Logger.Debug("Unable to Sync {0}. User Information has not been configured.", i.IndexerName); continue; //Skip this indexer @@ -200,7 +201,7 @@ namespace NzbDrone.Core.Providers return String.Format("{0} - {1}{2} - {3}", series.Title, seasonNumber, episodeNumbers, episodeTitles); } - private string GetUsersUrl(Indexer indexer) + private void GetUsersUrl(Indexer indexer) { if (indexer.IndexerName == "NzbMatrix") { @@ -208,10 +209,10 @@ namespace NzbDrone.Core.Providers var nzbMatrixApiKey = _configProvider.GetValue("NzbMatrixApiKey", String.Empty, false); if (!String.IsNullOrEmpty(nzbMatrixUsername) && !String.IsNullOrEmpty(nzbMatrixApiKey)) - return indexer.RssUrl.Replace("{USERNAME}", nzbMatrixUsername).Replace("{APIKEY}", nzbMatrixApiKey); + indexer.RssUrl = indexer.RssUrl.Replace("{USERNAME}", nzbMatrixUsername).Replace("{APIKEY}", nzbMatrixApiKey); //Todo: Perform validation at the config level so a user is unable to enable a provider until user details are provided - return null; //Return Null if Provider is enabled, but user information is not supplied. + return; } if (indexer.IndexerName == "NzbsOrg") @@ -220,10 +221,10 @@ namespace NzbDrone.Core.Providers var nzbsOrgHash = _configProvider.GetValue("NzbsOrgHash", String.Empty, false); if (!String.IsNullOrEmpty(nzbsOrgUId) && !String.IsNullOrEmpty(nzbsOrgHash)) - return indexer.RssUrl.Replace("{UID}", nzbsOrgUId).Replace("{HASH}", nzbsOrgHash); + indexer.RssUrl = indexer.RssUrl.Replace("{UID}", nzbsOrgUId).Replace("{HASH}", nzbsOrgHash); //Todo: Perform validation at the config level so a user is unable to enable a provider until user details are provided - return null; //Return Null if Provider is enabled, but user information is not supplied. + return; } if (indexer.IndexerName == "NzbsOrg") @@ -232,13 +233,13 @@ namespace NzbDrone.Core.Providers var nzbsrusHash = _configProvider.GetValue("NzbsrusHash", String.Empty, false); if (!String.IsNullOrEmpty(nzbsrusUId) && !String.IsNullOrEmpty(nzbsrusHash)) - return indexer.RssUrl.Replace("{UID}", nzbsrusUId).Replace("{HASH}", nzbsrusHash); + indexer.RssUrl = indexer.RssUrl.Replace("{UID}", nzbsrusUId).Replace("{HASH}", nzbsrusHash); //Todo: Perform validation at the config level so a user is unable to enable a provider until user details are provided - return null; //Return Null if Provider is enabled, but user information is not supplied. + return; } - return indexer.RssUrl; //Currently other providers do not require user information to be substituted, simply return the RssUrl + return; //Currently other providers do not require user information to be substituted, simply return } } } diff --git a/NzbDrone.Core/Providers/SeasonProvider.cs b/NzbDrone.Core/Providers/SeasonProvider.cs index e3c610e42..c43f0a194 100644 --- a/NzbDrone.Core/Providers/SeasonProvider.cs +++ b/NzbDrone.Core/Providers/SeasonProvider.cs @@ -57,19 +57,19 @@ namespace NzbDrone.Core.Providers public bool IsIgnored(int seasonId) { if (_sonicRepo.Single(seasonId).Monitored) - return true; + return false; Logger.Debug("Season {0} is not wanted."); - return false; + return true; } public bool IsIgnored(int seriesId, int seasonNumber) { if (_sonicRepo.Single(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber).Monitored) - return true; + return false; Logger.Debug("Season: {0} is not wanted for Series: {1}", seasonNumber, seriesId); - return false; + return true; } } } \ No newline at end of file diff --git a/NzbDrone.Core/Repository/Indexer.cs b/NzbDrone.Core/Repository/Indexer.cs index b8730ce07..5aea5e64c 100644 --- a/NzbDrone.Core/Repository/Indexer.cs +++ b/NzbDrone.Core/Repository/Indexer.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using SubSonic.SqlGeneration.Schema; @@ -9,11 +10,12 @@ namespace NzbDrone.Core.Repository { public class Indexer { - [SubSonicPrimaryKey (true)] + [SubSonicPrimaryKey(true)] public string IndexerName { get; set; } public string RssUrl { get; set; } [SubSonicNullStringAttribute] + [DisplayFormat(ConvertEmptyStringToNull = false)] public string ApiUrl { get; set; } public bool Enabled { get; set; } public int Order { get; set; }