From 64df2229d6027ff3df89a5f2fc04f00fc6c4d9bc Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Thu, 27 Jun 2013 17:05:09 -0700 Subject: [PATCH] removed nzbsrus --- .../IndexerTests/IndexerServiceFixture.cs | 21 ++++++++- NzbDrone.Core/Indexers/IndexerService.cs | 22 ++++++++-- NzbDrone.Core/Indexers/NzbsRUs/NzbsRUs.cs | 44 ------------------- .../Indexers/NzbsRUs/NzbsrusParser.cs | 22 ---------- .../Indexers/NzbsRUs/NzbsrusSettings.cs | 22 ---------- NzbDrone.Core/NzbDrone.Core.csproj | 3 -- NzbDrone.ncrunchsolution | 1 + 7 files changed, 39 insertions(+), 96 deletions(-) delete mode 100644 NzbDrone.Core/Indexers/NzbsRUs/NzbsRUs.cs delete mode 100644 NzbDrone.Core/Indexers/NzbsRUs/NzbsrusParser.cs delete mode 100644 NzbDrone.Core/Indexers/NzbsRUs/NzbsrusSettings.cs diff --git a/NzbDrone.Core.Test/IndexerTests/IndexerServiceFixture.cs b/NzbDrone.Core.Test/IndexerTests/IndexerServiceFixture.cs index 369bf6b1a..60ca60b21 100644 --- a/NzbDrone.Core.Test/IndexerTests/IndexerServiceFixture.cs +++ b/NzbDrone.Core.Test/IndexerTests/IndexerServiceFixture.cs @@ -1,13 +1,13 @@ using System; using System.Collections.Generic; using System.Linq; +using FizzWare.NBuilder; using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers.Newznab; using NzbDrone.Core.Indexers.NzbClub; -using NzbDrone.Core.Indexers.NzbsRUs; using NzbDrone.Core.Indexers.Omgwtfnzbs; using NzbDrone.Core.Indexers.Wombles; using NzbDrone.Core.Lifecycle; @@ -25,7 +25,6 @@ public void Setup() _indexers = new List(); _indexers.Add(new Newznab()); - _indexers.Add(new Nzbsrus()); _indexers.Add(new NzbClub()); _indexers.Add(new Omgwtfnzbs()); _indexers.Add(new Wombles()); @@ -67,5 +66,23 @@ public void getting_list_of_indexers() indexers.Select(c => c.Instance).Should().OnlyHaveUniqueItems(); } + + [Test] + public void should_remove_missing_indexers_on_startup() + { + var repo = Mocker.Resolve(); + + Mocker.SetConstant(repo); + + + var existingIndexers = Builder.CreateNew().BuildNew(); + + repo.Insert(existingIndexers); + + + Subject.Handle(new ApplicationStartedEvent()); + + AllStoredModels.Should().NotContain(c => c.Id == existingIndexers.Id); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Indexers/IndexerService.cs b/NzbDrone.Core/Indexers/IndexerService.cs index b65e21dcb..3a4860cbb 100644 --- a/NzbDrone.Core/Indexers/IndexerService.cs +++ b/NzbDrone.Core/Indexers/IndexerService.cs @@ -136,23 +136,39 @@ private Indexer ToIndexer(IndexerDefinition definition) private IIndexer GetInstance(IndexerDefinition indexerDefinition) { - var type = _indexers.Single(c => c.GetType().Name.Equals(indexerDefinition.Implementation, StringComparison.InvariantCultureIgnoreCase)).GetType(); - + var type = GetImplementation(indexerDefinition); var instance = (IIndexer)Activator.CreateInstance(type); - instance.InstanceDefinition = indexerDefinition; return instance; } + private Type GetImplementation(IndexerDefinition indexerDefinition) + { + return _indexers.Select(c => c.GetType()).SingleOrDefault(c => c.Name.Equals(indexerDefinition.Implementation, StringComparison.InvariantCultureIgnoreCase)); + } + public void Handle(ApplicationStartedEvent message) { _logger.Debug("Initializing indexers. Count {0}", _indexers.Count); + RemoveMissingImplementations(); + if (!All().Any()) { var definitions = _indexers.SelectMany(indexer => indexer.DefaultDefinitions); _indexerRepository.InsertMany(definitions.ToList()); } } + + private void RemoveMissingImplementations() + { + var storedIndexers = _indexerRepository.All(); + + foreach (var indexerDefinition in storedIndexers.Where(i => GetImplementation(i) == null)) + { + _logger.Debug("Removing Indexer {0} ", indexerDefinition.Name); + _indexerRepository.Delete(indexerDefinition); + } + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Indexers/NzbsRUs/NzbsRUs.cs b/NzbDrone.Core/Indexers/NzbsRUs/NzbsRUs.cs deleted file mode 100644 index 2d08e190a..000000000 --- a/NzbDrone.Core/Indexers/NzbsRUs/NzbsRUs.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace NzbDrone.Core.Indexers.NzbsRUs -{ - public class Nzbsrus : IndexerWithSetting - { - public override IEnumerable RecentFeed - { - get - { - yield return string.Format("https://www.nzbsrus.com/rssfeed.php?cat=91,75&i={0}&h={1}", - Settings.Uid, - Settings.Hash); - - } - } - - public override string Name - { - get { return "NzbsRUs"; } - } - - public override IEnumerable GetEpisodeSearchUrls(string seriesTitle, int seasonNumber, int episodeNumber) - { - return new List(); - } - - public override IEnumerable GetSeasonSearchUrls(string seriesTitle, int seasonNumber) - { - return new List(); - } - - public override IEnumerable GetDailyEpisodeSearchUrls(string seriesTitle, DateTime date) - { - return new List(); - } - - public override IEnumerable GetPartialSeasonSearchUrls(string seriesTitle, int seasonNumber, int episodeWildcard) - { - return new List(); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Indexers/NzbsRUs/NzbsrusParser.cs b/NzbDrone.Core/Indexers/NzbsRUs/NzbsrusParser.cs deleted file mode 100644 index c4ba74227..000000000 --- a/NzbDrone.Core/Indexers/NzbsRUs/NzbsrusParser.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.ServiceModel.Syndication; -using System.Text.RegularExpressions; -using NzbDrone.Core.Model; -using NzbDrone.Core.Parser; -using NzbDrone.Core.Parser.Model; - -namespace NzbDrone.Core.Indexers.NzbsRUs -{ - public class NzbsrusParser : BasicRssParser - { - protected override ReportInfo PostProcessor(SyndicationItem item, ReportInfo currentResult) - { - if (currentResult != null) - { - var sizeString = Regex.Match(item.Summary.Text, @"\d+\.\d{1,2} \w{3}", RegexOptions.IgnoreCase).Value; - currentResult.Size = GetReportSize(sizeString); - } - - return currentResult; - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core/Indexers/NzbsRUs/NzbsrusSettings.cs b/NzbDrone.Core/Indexers/NzbsRUs/NzbsrusSettings.cs deleted file mode 100644 index f5028c262..000000000 --- a/NzbDrone.Core/Indexers/NzbsRUs/NzbsrusSettings.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using NzbDrone.Core.Annotations; - -namespace NzbDrone.Core.Indexers.NzbsRUs -{ - public class NzbsrusSetting : IIndexerSetting - { - [FieldDefinition(0, Label = "UID")] - public String Uid { get; set; } - - [FieldDefinition(1, Label = "Hash")] - public String Hash { get; set; } - - public bool IsValid - { - get - { - return !string.IsNullOrWhiteSpace(Uid) && !string.IsNullOrWhiteSpace(Hash); - } - } - } -} diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 5c6df3f01..bdeec9ed2 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -298,14 +298,11 @@ - - - diff --git a/NzbDrone.ncrunchsolution b/NzbDrone.ncrunchsolution index 6cb47a29a..444b34b1d 100644 --- a/NzbDrone.ncrunchsolution +++ b/NzbDrone.ncrunchsolution @@ -2,6 +2,7 @@ 1 False true + true UseDynamicAnalysis Disabled Disabled