diff --git a/Libraries/DeskMetrics/DeskMetrics.NET.dll b/Libraries/DeskMetrics/DeskMetrics.NET.dll index 41126e811..23f6703d5 100644 Binary files a/Libraries/DeskMetrics/DeskMetrics.NET.dll and b/Libraries/DeskMetrics/DeskMetrics.NET.dll differ diff --git a/Libraries/DeskMetrics/DeskMetrics.NET.pdb b/Libraries/DeskMetrics/DeskMetrics.NET.pdb index 2fdd501fb..058e84073 100644 Binary files a/Libraries/DeskMetrics/DeskMetrics.NET.pdb and b/Libraries/DeskMetrics/DeskMetrics.NET.pdb differ diff --git a/NzbDrone.Core.Test/IndexerTests.cs b/NzbDrone.Core.Test/IndexerTests.cs index 45ab32ad7..eafb494b3 100644 --- a/NzbDrone.Core.Test/IndexerTests.cs +++ b/NzbDrone.Core.Test/IndexerTests.cs @@ -30,8 +30,6 @@ public class IndexerTests : CoreTest [TestCase("nzbmatrix.xml", 2)] public void parse_feed_xml(string fileName, int warns) { - - Mocker.GetMock() .Setup(h => h.DownloadStream(It.IsAny(), It.IsAny())) .Returns(File.OpenRead(".\\Files\\Rss\\" + fileName)); @@ -58,10 +56,25 @@ public void parse_feed_xml(string fileName, int warns) ExceptionVerification.ExpectedWarns(warns); } + private void WithConfiguredIndexers() + { + Mocker.GetMock().SetupGet(c => c.NzbMatrixApiKey).Returns("MockedConfigValue"); + Mocker.GetMock().SetupGet(c => c.NzbMatrixUsername).Returns("MockedConfigValue"); + + Mocker.GetMock().SetupGet(c => c.NewzbinUsername).Returns("MockedConfigValue"); + Mocker.GetMock().SetupGet(c => c.NewzbinPassword).Returns("MockedConfigValue"); + + Mocker.GetMock().SetupGet(c => c.NzbsOrgHash).Returns("MockedConfigValue"); + Mocker.GetMock().SetupGet(c => c.NzbsOrgUId).Returns("MockedConfigValue"); + + Mocker.GetMock().SetupGet(c => c.NzbsrusHash).Returns("MockedConfigValue"); + Mocker.GetMock().SetupGet(c => c.NzbsrusUId).Returns("MockedConfigValue"); + } + [Test] public void newzbin_parses_languae() { - + WithConfiguredIndexers(); Mocker.GetMock() .Setup(h => h.DownloadStream(It.IsAny(), It.IsAny())) @@ -169,7 +182,7 @@ public void custome_parser_full_parse(string title) [Test] public void downloadFeed() { - Mocker.SetConstant(new HttpProvider()); + Mocker.Resolve(); var fakeSettings = Builder.CreateNew().Build(); Mocker.GetMock() @@ -198,7 +211,7 @@ public void nzbsorg_search_returns_valid_results(string title, int season, int e Mocker.Resolve(); var result = Mocker.Resolve().FetchEpisode(title, season, episode); - + Mark500Inconclusive(); result.Should().NotBeEmpty(); @@ -228,13 +241,8 @@ public void newzbin_search_returns_valid_results(string title, int season, int e [Test] public void nzbmatrix_search_returns_valid_results() { - Mocker.GetMock() - .SetupGet(c => c.NzbMatrixUsername) - .Returns(""); + WithConfiguredIndexers(); - Mocker.GetMock() - .SetupGet(c => c.NzbMatrixApiKey) - .Returns(""); Mocker.Resolve(); @@ -249,13 +257,7 @@ public void nzbmatrix_search_returns_valid_results() [Test] public void nzbmatrix_multi_word_search_returns_valid_results() { - Mocker.GetMock() - .SetupGet(c => c.NzbMatrixUsername) - .Returns(""); - - Mocker.GetMock() - .SetupGet(c => c.NzbMatrixApiKey) - .Returns(""); + WithConfiguredIndexers(); Mocker.Resolve(); @@ -280,6 +282,8 @@ public void get_query_title(string raw, string clean) [Test] public void size_newzbin() { + WithConfiguredIndexers(); + Mocker.GetMock() .Setup(h => h.DownloadStream(It.IsAny(), It.IsAny())) .Returns(File.OpenRead(".\\Files\\Rss\\SizeParsing\\newzbin.xml")); @@ -294,8 +298,7 @@ public void size_newzbin() [Test] public void size_nzbmatrix() { - //Setup - + WithConfiguredIndexers(); Mocker.GetMock() .Setup(h => h.DownloadStream(It.IsAny(), It.IsAny())) @@ -311,8 +314,7 @@ public void size_nzbmatrix() [Test] public void size_nzbsorg() { - //Setup - + WithConfiguredIndexers(); Mocker.GetMock() .Setup(h => h.DownloadStream(It.IsAny(), It.IsAny())) @@ -328,8 +330,7 @@ public void size_nzbsorg() [Test] public void size_nzbsrus() { - //Setup - + WithConfiguredIndexers(); Mocker.GetMock() .Setup(h => h.DownloadStream(It.IsAny(), It.IsAny())) @@ -359,6 +360,8 @@ public void Server_Unavailable_503_should_not_log_exception() [Test] public void none_503_server_error_should_still_log_error() { + WithConfiguredIndexers(); + Mocker.GetMock() .Setup(h => h.DownloadStream(It.IsAny(), It.IsAny())) .Throws(new WebException("some other server error")); @@ -369,6 +372,17 @@ public void none_503_server_error_should_still_log_error() ExceptionVerification.ExpectedWarns(0); } + [Test] + public void indexer_that_isnt_configured_shouldnt_make_an_http_call() + { + Mocker.Resolve().FetchRss(); + + Mocker.GetMock() + .Verify(c => c.DownloadFile(It.IsAny(), It.IsAny()), Times.Never()); + + ExceptionVerification.ExpectedWarns(1); + } + private static void Mark500Inconclusive() { ExceptionVerification.MarkInconclusive(typeof(WebException)); diff --git a/NzbDrone.Core.Test/ProviderTests/IndexerProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/IndexerProviderTest.cs index 39ff34cb8..b84bd2051 100644 --- a/NzbDrone.Core.Test/ProviderTests/IndexerProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/IndexerProviderTest.cs @@ -23,7 +23,7 @@ public class IndexerProviderTest : CoreTest [Test] public void Init_indexer_test() { - + Mocker.SetConstant(TestDbHelper.GetEmptyDatabase()); @@ -45,8 +45,6 @@ public void Init_indexer_test() [Test] public void Init_indexer_with_disabled_job() { - - Mocker.SetConstant(TestDbHelper.GetEmptyDatabase()); //Act @@ -75,6 +73,11 @@ protected override string[] Urls get { return new[] { "www.google.com" }; } } + public override bool IsConfigured + { + get { return true; } + } + protected override NetworkCredential Credentials { get { return null; } @@ -129,6 +132,11 @@ protected override string[] Urls get { return new[] { "http://rss.nzbmatrix.com/rss.php?cat=TV" }; } } + public override bool IsConfigured + { + get { return true; } + } + protected override IList GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber) { throw new NotImplementedException(); @@ -172,6 +180,11 @@ protected override string[] Urls get { return new[] { "http://www.google.com" }; } } + public override bool IsConfigured + { + get { return true; } + } + protected override IList GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber) { throw new NotImplementedException(); @@ -205,4 +218,52 @@ protected override EpisodeParseResult CustomParser(SyndicationItem item, Episode } } + public class NotConfiguredIndexer : IndexerBase + { + public NotConfiguredIndexer(HttpProvider httpProvider, ConfigProvider configProvider) + : base(httpProvider, configProvider) + { + } + + public override string Name + { + get { return "NotConfiguredIndexer"; } + } + + protected override string[] Urls + { + get { return new[] { "http://rss.nzbmatrix.com/rss.php?cat=TV" }; } + } + + public override bool IsConfigured + { + get { return false; } + } + + protected override IList GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber) + { + throw new NotImplementedException(); + } + + protected override IList GetDailyEpisodeSearchUrls(string seriesTitle, DateTime date) + { + throw new NotImplementedException(); + } + + protected override IList GetSeasonSearchUrls(string seriesTitle, int seasonNumber) + { + throw new NotImplementedException(); + } + + protected override IList GetPartialSeasonSearchUrls(string seriesTitle, int seasonNumber, int episodeWildcard) + { + throw new NotImplementedException(); + } + + protected override string NzbDownloadUrl(SyndicationItem item) + { + throw new NotImplementedException(); + } + } + } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/Indexer/IndexerBase.cs b/NzbDrone.Core/Providers/Indexer/IndexerBase.cs index 3b4db2811..576b41356 100644 --- a/NzbDrone.Core/Providers/Indexer/IndexerBase.cs +++ b/NzbDrone.Core/Providers/Indexer/IndexerBase.cs @@ -44,6 +44,9 @@ public IndexerBase() protected abstract string[] Urls { get; } + public abstract bool IsConfigured { get; } + + /// /// Gets the credential. /// @@ -147,6 +150,12 @@ private List Fetch(IEnumerable urls) { var result = new List(); + if (!IsConfigured) + { + _logger.Warn("Indexer '{0}' isn't configured correctly. please reconfigure the indexer in settings page.", Name); + return result; + } + foreach (var url in urls) { try @@ -178,11 +187,11 @@ private List Fetch(IEnumerable urls) } } - catch(WebException webException) + catch (WebException webException) { if (webException.Message.Contains("503")) { - _logger.Warn("{0} server is currently unbelievable. {1}", Name, webException.Message); + _logger.Warn("{0} server is currently unbelievable. {1}", Name, webException.Message); } else { diff --git a/NzbDrone.Core/Providers/Indexer/Newzbin.cs b/NzbDrone.Core/Providers/Indexer/Newzbin.cs index 7b6196a69..f925fc4e9 100644 --- a/NzbDrone.Core/Providers/Indexer/Newzbin.cs +++ b/NzbDrone.Core/Providers/Indexer/Newzbin.cs @@ -30,7 +30,14 @@ protected override string[] Urls } } - + public override bool IsConfigured + { + get + { + return !string.IsNullOrWhiteSpace(_configProvider.NewzbinUsername) && + !string.IsNullOrWhiteSpace(_configProvider.NewzbinPassword); + } + } protected override NetworkCredential Credentials diff --git a/NzbDrone.Core/Providers/Indexer/Newznab.cs b/NzbDrone.Core/Providers/Indexer/Newznab.cs index a364ef743..581ed42bb 100644 --- a/NzbDrone.Core/Providers/Indexer/Newznab.cs +++ b/NzbDrone.Core/Providers/Indexer/Newznab.cs @@ -24,6 +24,11 @@ protected override string[] Urls get { return GetUrls(); } } + public override bool IsConfigured + { + get { return true; } + } + protected override IList GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber) { var searchUrls = new List(); diff --git a/NzbDrone.Core/Providers/Indexer/NzbMatrix.cs b/NzbDrone.Core/Providers/Indexer/NzbMatrix.cs index b6de2c9e7..14f6de51b 100644 --- a/NzbDrone.Core/Providers/Indexer/NzbMatrix.cs +++ b/NzbDrone.Core/Providers/Indexer/NzbMatrix.cs @@ -30,6 +30,15 @@ protected override string[] Urls } } + public override bool IsConfigured + { + get + { + return !string.IsNullOrWhiteSpace(_configProvider.NzbMatrixUsername) && + !string.IsNullOrWhiteSpace(_configProvider.NzbMatrixApiKey); + } + } + protected override IList GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber) { var searchUrls = new List(); diff --git a/NzbDrone.Core/Providers/Indexer/NzbsOrg.cs b/NzbDrone.Core/Providers/Indexer/NzbsOrg.cs index fef01d9e7..fc8fa0d87 100644 --- a/NzbDrone.Core/Providers/Indexer/NzbsOrg.cs +++ b/NzbDrone.Core/Providers/Indexer/NzbsOrg.cs @@ -28,6 +28,15 @@ protected override string[] Urls } } + public override bool IsConfigured + { + get + { + return !string.IsNullOrWhiteSpace(_configProvider.NzbsOrgUId) && + !string.IsNullOrWhiteSpace(_configProvider.NzbsOrgHash); + } + } + protected override IList GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber) { var searchUrls = new List(); diff --git a/NzbDrone.Core/Providers/Indexer/NzbsRUs.cs b/NzbDrone.Core/Providers/Indexer/NzbsRUs.cs index c621c7b7e..61d43b58e 100644 --- a/NzbDrone.Core/Providers/Indexer/NzbsRUs.cs +++ b/NzbDrone.Core/Providers/Indexer/NzbsRUs.cs @@ -29,6 +29,15 @@ protected override string[] Urls } } + public override bool IsConfigured + { + get + { + return !string.IsNullOrWhiteSpace(_configProvider.NzbsrusUId) && + !string.IsNullOrWhiteSpace(_configProvider.NzbsrusHash); + } + } + public override string Name { get { return "NzbsRUs"; } diff --git a/NzbDrone.Core/Providers/NewznzbProvider.cs b/NzbDrone.Core/Providers/NewznzbProvider.cs index 820d5806b..5741a258a 100644 --- a/NzbDrone.Core/Providers/NewznzbProvider.cs +++ b/NzbDrone.Core/Providers/NewznzbProvider.cs @@ -47,11 +47,8 @@ public virtual int Save(NewznabDefinition definition) return Convert.ToInt32(_database.Insert(definition)); } - else - { - Logger.Debug("Updating Newznab definitions for {0}", definition.Name); - return _database.Update(definition); - } + Logger.Debug("Updating Newznab definitions for {0}", definition.Name); + return _database.Update(definition); } public virtual void SaveAll(IEnumerable definitions) diff --git a/NzbDrone/Providers/MonitoringProvider.cs b/NzbDrone/Providers/MonitoringProvider.cs index cbf1adc2b..97070022f 100644 --- a/NzbDrone/Providers/MonitoringProvider.cs +++ b/NzbDrone/Providers/MonitoringProvider.cs @@ -47,7 +47,7 @@ public void Start() prioCheckTimer.Elapsed += EnsurePriority; prioCheckTimer.Enabled = true; - _pingTimer = new Timer(120000) { AutoReset = true }; + _pingTimer = new Timer(180000) { AutoReset = true }; _pingTimer.Elapsed += (PingServer); _pingTimer.Start(); } @@ -94,9 +94,10 @@ public virtual void PingServer(object sender, ElapsedEventArgs e) { _pingFailCounter++; Logger.ErrorException("Application pool is not responding. Count " + _pingFailCounter, ex); - if (_pingFailCounter > 2) + if (_pingFailCounter > 4) { - _iisProvider.RestartServer(); + _pingFailCounter = 0; + //_iisProvider.RestartServer(); } } }