Moved indexers to ObjectDb

pull/2/head
Mark McDowall 12 years ago
parent d373a07edc
commit 43a7d6239e

@ -7,10 +7,11 @@ using FluentAssertions;
using NCrunch.Framework;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Providers;
using NzbDrone.Core.Jobs;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.ExternalNotification;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Providers.Metadata;
using NzbDrone.Core.Test.Framework;
@ -112,7 +113,7 @@ namespace NzbDrone.Core.Test
[Test]
public void indexers_are_initialized()
{
kernel.Resolve<IndexerProvider>().All().Select(c => c.IndexProviderType).Should().BeEquivalentTo(indexers);
kernel.Resolve<IIndexerService>().All().Select(c => c.Type).Should().BeEquivalentTo(indexers);
}
[Test]

@ -10,13 +10,15 @@ using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Providers;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Test.Indexers;
using NzbDrone.Core.Test.ProviderTests;
using NzbDrone.Test.Common;
@ -54,8 +56,8 @@ namespace NzbDrone.Core.Test.IndexerTests
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(OpenRead("Files", "Rss", fileName));
var fakeSettings = Builder<IndexerDefinition>.CreateNew().Build();
Mocker.GetMock<IndexerProvider>()
var fakeSettings = Builder<Indexer>.CreateNew().Build();
Mocker.GetMock<IIndexerService>()
.Setup(c => c.GetSettings(It.IsAny<Type>()))
.Returns(fakeSettings);
@ -75,7 +77,7 @@ namespace NzbDrone.Core.Test.IndexerTests
}
[Test]
public void custome_parser_partial_success()
public void custom_parser_partial_success()
{
const string title = "Adventure.Inc.S03E19.DVDRip.XviD-OSiTV";
const int season = 3;
@ -84,8 +86,8 @@ namespace NzbDrone.Core.Test.IndexerTests
const string summary = "My fake summary";
var fakeSettings = Builder<IndexerDefinition>.CreateNew().Build();
Mocker.GetMock<IndexerProvider>()
var fakeSettings = Builder<Indexer>.CreateNew().Build();
Mocker.GetMock<IIndexerService>()
.Setup(c => c.GetSettings(It.IsAny<Type>()))
.Returns(fakeSettings);
@ -104,12 +106,12 @@ namespace NzbDrone.Core.Test.IndexerTests
}
[TestCase("Adventure.Inc.DVDRip.XviD-OSiTV")]
public void custome_parser_full_parse(string title)
public void custom_parser_full_parse(string title)
{
const string summary = "My fake summary";
var fakeSettings = Builder<IndexerDefinition>.CreateNew().Build();
Mocker.GetMock<IndexerProvider>()
var fakeSettings = Builder<Indexer>.CreateNew().Build();
Mocker.GetMock<IIndexerService>()
.Setup(c => c.GetSettings(It.IsAny<Type>()))
.Returns(fakeSettings);
@ -275,8 +277,8 @@ namespace NzbDrone.Core.Test.IndexerTests
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(OpenRead("Files", "Rss", "newznab.xml"));
var fakeSettings = Builder<IndexerDefinition>.CreateNew().Build();
Mocker.GetMock<IndexerProvider>()
var fakeSettings = Builder<Indexer>.CreateNew().Build();
Mocker.GetMock<IIndexerService>()
.Setup(c => c.GetSettings(It.IsAny<Type>()))
.Returns(fakeSettings);
@ -306,8 +308,8 @@ namespace NzbDrone.Core.Test.IndexerTests
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
.Returns(OpenRead("Files", "Rss", "" + fileName));
var fakeSettings = Builder<IndexerDefinition>.CreateNew().Build();
Mocker.GetMock<IndexerProvider>()
var fakeSettings = Builder<Indexer>.CreateNew().Build();
Mocker.GetMock<IIndexerService>()
.Setup(c => c.GetSettings(It.IsAny<Type>()))
.Returns(fakeSettings);

@ -10,10 +10,10 @@ using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Indexers.Providers;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;

@ -4,94 +4,77 @@ using System;
using System.Collections.Generic;
using System.Net;
using System.ServiceModel.Syndication;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Providers;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.ProviderTests
namespace NzbDrone.Core.Test.Indexers
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class IndexerProviderTest : SqlCeTest
public class IndexerServiceTest : CoreTest
{
[Test]
public void Init_indexer_test()
{
WithRealDb();
Mocker.SetConstant<IEnumerable<IndexerBase>>(new List<IndexerBase> { Mocker.Resolve<MockIndexer>() });
var indexerProvider = Mocker.Resolve<IndexerProvider>();
var settings = indexerProvider.GetSettings(typeof(MockIndexer));
settings.Enable = true;
indexerProvider.SaveSettings(settings);
//Mocker.GetMock<IIndexerRepository>()
// .Setup(s => s.Find(typeof(MockIndexer)))
// .Returns()
indexerProvider.All();
Mocker.Resolve<IndexerService>();
indexerProvider.All().Should().HaveCount(1);
indexerProvider.GetEnabledIndexers().Should().HaveCount(1);
Mocker.GetMock<IIndexerRepository>()
.Verify(v => v.Insert(It.IsAny<Indexer>()), Times.Once());
}
[Test]
public void Init_indexer_with_disabled_job()
public void getEnabled_should_not_return_any_when_no_indexers_are_enabled()
{
WithRealDb();
Mocker.SetConstant<IEnumerable<IndexerBase>>(new List<IndexerBase> { Mocker.Resolve<MockIndexer>() });
var indexerProvider = Mocker.Resolve<IndexerProvider>();
Mocker.GetMock<IIndexerRepository>()
.Setup(s => s.All())
.Returns(new List<Indexer> {new Indexer {OID = 1, Type = "", Enable = false, Name = "Fake Indexer"}});
var settings = indexerProvider.GetSettings(typeof(MockIndexer));
settings.Enable = false;
indexerProvider.SaveSettings(settings);
indexerProvider.All().Should().HaveCount(1);
indexerProvider.GetEnabledIndexers().Should().BeEmpty();
Mocker.Resolve<IndexerService>().GetEnabledIndexers().Should().BeEmpty();
}
[Test]
public void Init_indexer_should_enable_indexer_that_is_enabled_by_default()
{
WithRealDb();
Mocker.SetConstant<IEnumerable<IndexerBase>>(new List<IndexerBase> { Mocker.Resolve<DefaultEnabledIndexer>() });
var indexerProvider = Mocker.Resolve<IndexerProvider>();
Mocker.Resolve<IndexerService>();
Mocker.GetMock<IIndexerRepository>()
.Verify(v => v.Insert(It.Is<Indexer>(indexer => indexer.Enable)), Times.Once());
indexerProvider.All();
indexerProvider.All().Should().HaveCount(1);
indexerProvider.GetEnabledIndexers().Should().HaveCount(1);
indexerProvider.GetSettings(typeof(DefaultEnabledIndexer)).Enable.Should().BeTrue();
Mocker.GetMock<IIndexerRepository>()
.Verify(v => v.Insert(It.Is<Indexer>(indexer => !indexer.Enable)), Times.Never());
}
[Test]
public void Init_indexer_should_not_enable_indexer_that_is_not_enabled_by_default()
{
WithRealDb();
Mocker.SetConstant<IEnumerable<IndexerBase>>(new List<IndexerBase> { Mocker.Resolve<MockIndexer>() });
var indexerProvider = Mocker.Resolve<IndexerProvider>();
Mocker.Resolve<IndexerService>();
Mocker.GetMock<IIndexerRepository>()
.Verify(v => v.Insert(It.Is<Indexer>(indexer => indexer.Enable)), Times.Never());
indexerProvider.All();
indexerProvider.All().Should().HaveCount(1);
indexerProvider.GetEnabledIndexers().Should().HaveCount(0);
indexerProvider.GetSettings(typeof(MockIndexer)).Enable.Should().BeFalse();
Mocker.GetMock<IIndexerRepository>()
.Verify(v => v.Insert(It.Is<Indexer>(indexer => !indexer.Enable)), Times.Once());
}
}

@ -247,7 +247,7 @@
<Compile Include="JobTests\JobControllerFixture.cs" />
<Compile Include="QualityTest.cs" />
<Compile Include="RootFolderTests\RootFolderServiceFixture.cs" />
<Compile Include="ProviderTests\IndexerProviderTest.cs" />
<Compile Include="Indexers\IndexerServiceTest.cs" />
<Compile Include="ProviderTests\HistoryProviderTest.cs" />
<Compile Include="ProviderTests\MediaFileProviderTest.cs" />
<Compile Include="ProviderTests\ConfigProviderTests\ConfigProviderFixture.cs" />

@ -9,7 +9,6 @@ using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Providers.Search;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Search;

@ -9,7 +9,6 @@ using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Providers.Search;
using NzbDrone.Core.Repository;
using NzbDrone.Test.Common;

@ -9,7 +9,6 @@ using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Providers.Search;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Search;

@ -9,7 +9,6 @@ using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Providers.Search;
using NzbDrone.Core.Repository;
using NzbDrone.Test.Common;

@ -9,7 +9,6 @@ using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Providers.Search;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Search;

@ -9,7 +9,6 @@ using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Providers.Search;
using NzbDrone.Core.Repository;
using NzbDrone.Test.Common;

@ -5,11 +5,12 @@ using System.Text;
using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Indexers.Providers;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Repository;
using NzbDrone.Test.Common;
@ -56,7 +57,7 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchTests
_indexer2 = new Mock<IndexerBase>();
_indexers = new List<IndexerBase> { _indexer1.Object, _indexer2.Object };
Mocker.GetMock<IndexerProvider>()
Mocker.GetMock<IIndexerService>()
.Setup(c => c.GetEnabledIndexers())
.Returns(_indexers);
}

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NLog;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
@ -18,9 +19,9 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchTests
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public TestSearch(ISeriesService seriesService, EpisodeService episodeService, DownloadProvider downloadProvider,
IndexerProvider indexerProvider, SceneMappingProvider sceneMappingProvider,
IndexerService indexerService, SceneMappingProvider sceneMappingProvider,
AllowedDownloadSpecification allowedDownloadSpecification, SearchHistoryProvider searchHistoryProvider,ISeriesRepository seriesRepository)
: base(seriesService, seriesRepository, episodeService, downloadProvider, indexerProvider, sceneMappingProvider,
: base(seriesService, seriesRepository, episodeService, downloadProvider, indexerService, sceneMappingProvider,
allowedDownloadSpecification, searchHistoryProvider)
{
}
@ -38,7 +39,7 @@ namespace NzbDrone.Core.Test.ProviderTests.SearchTests
var seasonNumber = options.Episode.SeasonNumber;
var episodeNumber = options.Episode.EpisodeNumber;
Parallel.ForEach(_indexerProvider.GetEnabledIndexers(), indexer =>
Parallel.ForEach(_indexerService.GetEnabledIndexers(), indexer =>
{
try
{

@ -6,9 +6,9 @@ using Autofac.Core;
using NLog;
using NzbDrone.Common;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Indexers.Providers;
using NzbDrone.Core.Instrumentation;
using NzbDrone.Core.Providers.ExternalNotification;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Providers.Metadata;
using NzbDrone.Core.Providers.Search;
using PetaPoco;

@ -0,0 +1,13 @@
using System;
using NzbDrone.Core.Datastore;
using PetaPoco;
namespace NzbDrone.Core.Indexers
{
public class Indexer : ModelBase
{
public Boolean Enable { get; set; }
public String Type { get; set; }
public String Name { get; set; }
}
}

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Indexers
{
public interface IIndexerRepository : IBasicRepository<Indexer>
{
Indexer Find(Type type);
}
public class IndexerRepository : BasicRepository<Indexer>, IIndexerRepository
{
public IndexerRepository(IObjectDatabase objectDatabase)
: base(objectDatabase)
{
}
public Indexer Find(Type type)
{
return Queryable.Single(i => i.Type == type.ToString());
}
}
}

@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Core.Indexers.Providers;
using PetaPoco;
namespace NzbDrone.Core.Indexers
{
public interface IIndexerService
{
List<Indexer> All();
List<IndexerBase> GetEnabledIndexers();
void SaveSettings(Indexer indexer);
Indexer GetSettings(Type type);
}
public class IndexerService : IIndexerService
{
private readonly IIndexerRepository _indexerRepository;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private IList<IndexerBase> _indexers;
public IndexerService(IIndexerRepository indexerRepository, IEnumerable<IndexerBase> indexers)
{
_indexerRepository = indexerRepository;
_indexers = indexers.ToList();
InitializeIndexers();
}
public List<Indexer> All()
{
return _indexerRepository.All().ToList();
}
public List<IndexerBase> GetEnabledIndexers()
{
var all = All();
return _indexers.Where(i => all.Exists(c => c.Type == i.GetType().ToString() && c.Enable)).ToList();
}
public void SaveSettings(Indexer indexer)
{
if (indexer.OID == 0)
{
Logger.Debug("Adding Indexer definitions for {0}", indexer.Name);
_indexerRepository.Insert(indexer);
}
else
{
Logger.Debug("Updating Indexer definitions for {0}", indexer.Name);
_indexerRepository.Update(indexer);
}
}
public Indexer GetSettings(Type type)
{
return _indexerRepository.Find(type);
}
private void InitializeIndexers()
{
Logger.Debug("Initializing indexers. Count {0}", _indexers.Count);
var currentIndexers = All();
foreach (var feedProvider in _indexers)
{
IndexerBase indexerLocal = feedProvider;
if (!currentIndexers.Exists(c => c.Type == indexerLocal.GetType().ToString()))
{
var settings = new Indexer
{
Enable = indexerLocal.EnabledByDefault,
Type = indexerLocal.GetType().ToString(),
Name = indexerLocal.Name
};
SaveSettings(settings);
}
}
}
}
}

@ -1,12 +1,12 @@
using System;
using System.Linq;
using System;
using System.Collections.Generic;
using System.ServiceModel.Syndication;
using System.Text.RegularExpressions;
using NzbDrone.Common;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Providers.Indexer
namespace NzbDrone.Core.Indexers.Providers
{
public class FileSharingTalk : IndexerBase
{

@ -9,7 +9,7 @@ using NzbDrone.Common;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Providers.Indexer
namespace NzbDrone.Core.Indexers.Providers
{
public abstract class IndexerBase
{

@ -1,12 +1,14 @@
using System;
using System.Linq;
using System;
using System.Collections.Generic;
using System.ServiceModel.Syndication;
using System.Text.RegularExpressions;
using NzbDrone.Common;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Providers.Indexer
namespace NzbDrone.Core.Indexers.Providers
{
public class Newznab : IndexerBase
{

@ -1,4 +1,5 @@
using System;
using System.Linq;
using System;
using System.Collections.Generic;
using System.ServiceModel.Syndication;
using System.Text.RegularExpressions;
@ -6,7 +7,7 @@ using NzbDrone.Common;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Providers.Indexer
namespace NzbDrone.Core.Indexers.Providers
{
public class NzbClub : IndexerBase
{

@ -1,4 +1,5 @@
using System;
using System.Linq;
using System;
using System.Collections.Generic;
using System.ServiceModel.Syndication;
using System.Text.RegularExpressions;
@ -6,7 +7,7 @@ using NzbDrone.Common;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Providers.Indexer
namespace NzbDrone.Core.Indexers.Providers
{
public class NzbIndex : IndexerBase
{

@ -1,4 +1,5 @@
using System;
using System.Linq;
using System;
using System.Collections.Generic;
using System.ServiceModel.Syndication;
using System.Text.RegularExpressions;
@ -6,7 +7,7 @@ using NzbDrone.Common;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Providers.Indexer
namespace NzbDrone.Core.Indexers.Providers
{
public class NzbsRUs : IndexerBase
{

@ -3,15 +3,13 @@ using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.ServiceModel.Syndication;
using System.Text;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using NzbDrone.Common;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Nzbx;
using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Providers.Indexer
namespace NzbDrone.Core.Indexers.Providers
{
class Nzbx : IndexerBase
{

@ -2,13 +2,12 @@
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Syndication;
using System.Text;
using System.Text.RegularExpressions;
using NzbDrone.Common;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Providers.Indexer
namespace NzbDrone.Core.Indexers.Providers
{
class Omgwtfnzbs : IndexerBase
{

@ -2,8 +2,6 @@
//https://connect.microsoft.com/VisualStudio/feedback/details/325421/syndicationfeed-load-fails-to-parse-datetime-against-a-real-world-feeds-ie7-can-read
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
@ -13,7 +11,7 @@ using System.Threading;
using System.Xml;
using NLog;
namespace NzbDrone.Core.Providers.Indexer
namespace NzbDrone.Core.Indexers.Providers
{
public class SyndicationFeedXmlReader : XmlTextReader
{

@ -1,12 +1,12 @@
using System;
using System.Linq;
using System;
using System.Collections.Generic;
using System.ServiceModel.Syndication;
using System.Text.RegularExpressions;
using NzbDrone.Common;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
namespace NzbDrone.Core.Providers.Indexer
namespace NzbDrone.Core.Indexers.Providers
{
public class Wombles : IndexerBase
{

@ -3,19 +3,19 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NLog;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Providers.Indexer;
namespace NzbDrone.Core.Jobs
{
public class RssSyncJob : IJob
{
private readonly DownloadProvider _downloadProvider;
private readonly IndexerProvider _indexerProvider;
private readonly IndexerService _indexerService;
private readonly MonitoredEpisodeSpecification _isMonitoredEpisodeSpecification;
private readonly AllowedDownloadSpecification _allowedDownloadSpecification;
private readonly UpgradeHistorySpecification _upgradeHistorySpecification;
@ -24,12 +24,12 @@ namespace NzbDrone.Core.Jobs
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public RssSyncJob(DownloadProvider downloadProvider, IndexerProvider indexerProvider,
public RssSyncJob(DownloadProvider downloadProvider, IndexerService indexerService,
MonitoredEpisodeSpecification isMonitoredEpisodeSpecification, AllowedDownloadSpecification allowedDownloadSpecification,
UpgradeHistorySpecification upgradeHistorySpecification, ConfigProvider configProvider)
{
_downloadProvider = downloadProvider;
_indexerProvider = indexerProvider;
_indexerService = indexerService;
_isMonitoredEpisodeSpecification = isMonitoredEpisodeSpecification;
_allowedDownloadSpecification = allowedDownloadSpecification;
_upgradeHistorySpecification = upgradeHistorySpecification;
@ -52,7 +52,7 @@ namespace NzbDrone.Core.Jobs
notification.CurrentMessage = "Fetching RSS";
Parallel.ForEach(_indexerProvider.GetEnabledIndexers(), indexer =>
Parallel.ForEach(_indexerService.GetEnabledIndexers(), indexer =>
{
try
{

@ -268,6 +268,7 @@
<Compile Include="Helpers\SortHelper.cs" />
<Compile Include="Helpers\SabnzbdPriorityTypeConverter.cs" />
<Compile Include="Helpers\XElementHelper.cs" />
<Compile Include="Indexers\IndexerRepository.cs" />
<Compile Include="Instrumentation\LogInjectionModule.cs" />
<Compile Include="Jobs\CleanupRecycleBinJob.cs" />
<Compile Include="Jobs\JobRepository.cs" />
@ -340,13 +341,13 @@
<Compile Include="DecisionEngine\AllowedReleaseGroupSpecification.cs" />
<Compile Include="DecisionEngine\CustomStartDateSpecification.cs" />
<Compile Include="Providers\DownloadClients\PneumaticProvider.cs" />
<Compile Include="Providers\Indexer\Nzbx.cs" />
<Compile Include="Indexers\Providers\Nzbx.cs" />
<Compile Include="Providers\Hubs\EpisodeHub.cs" />
<Compile Include="Providers\Indexer\NzbClub.cs" />
<Compile Include="Providers\Indexer\NzbIndex.cs" />
<Compile Include="Providers\Indexer\FileSharingTalk.cs" />
<Compile Include="Providers\Indexer\Omgwtfnzbs.cs" />
<Compile Include="Providers\Indexer\Wombles.cs" />
<Compile Include="Indexers\Providers\NzbClub.cs" />
<Compile Include="Indexers\Providers\NzbIndex.cs" />
<Compile Include="Indexers\Providers\FileSharingTalk.cs" />
<Compile Include="Indexers\Providers\Omgwtfnzbs.cs" />
<Compile Include="Indexers\Providers\Wombles.cs" />
<Compile Include="Providers\MetadataProvider.cs" />
<Compile Include="Providers\Metadata\MetadataBase.cs" />
<Compile Include="Providers\Metadata\Xbmc.cs" />
@ -490,19 +491,19 @@
<Compile Include="Providers\HistoryProvider.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Providers\IndexerProvider.cs">
<Compile Include="Indexers\IndexerService.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Providers\Indexer\IndexerBase.cs">
<Compile Include="Indexers\Providers\IndexerBase.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Providers\Indexer\Newznab.cs">
<Compile Include="Indexers\Providers\Newznab.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Providers\Indexer\NzbsRUs.cs">
<Compile Include="Indexers\Providers\NzbsRUs.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Providers\Indexer\SyndicationFeedXmlReader.cs">
<Compile Include="Indexers\Providers\SyndicationFeedXmlReader.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Providers\MediaFileProvider.cs">
@ -576,7 +577,7 @@
<Compile Include="Repository\NewznabDefinition.cs" />
<Compile Include="Repository\ExternalNotificationDefinition.cs" />
<Compile Include="Jobs\JobDefinition.cs" />
<Compile Include="Repository\IndexerDefinition.cs" />
<Compile Include="Indexers\Indexer.cs" />
<Compile Include="Model\EpisodeParseResult.cs" />
<Compile Include="Model\EpisodeSortingType.cs" />
<Compile Include="Model\EpisodeStatusType.cs" />

@ -1,85 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Repository;
using PetaPoco;
namespace NzbDrone.Core.Providers
{
public class IndexerProvider
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly IDatabase _database;
private IList<IndexerBase> _indexers;
public IndexerProvider(IDatabase database, IEnumerable<IndexerBase> indexers)
{
_database = database;
_indexers = indexers.ToList();
InitializeIndexers();
}
public IndexerProvider()
{
}
public virtual IList<IndexerBase> GetEnabledIndexers()
{
var all = All();
return _indexers.Where(i => all.Exists(c => c.IndexProviderType == i.GetType().ToString() && c.Enable)).ToList();
}
public virtual List<IndexerDefinition> All()
{
return _database.Fetch<IndexerDefinition>();
}
public virtual void SaveSettings(IndexerDefinition definitions)
{
if (definitions.Id == 0)
{
Logger.Debug("Adding Indexer definitions for {0}", definitions.Name);
_database.Insert(definitions);
}
else
{
Logger.Debug("Updating Indexer definitions for {0}", definitions.Name);
_database.Update(definitions);
}
}
public virtual IndexerDefinition GetSettings(Type type)
{
return _database.Single<IndexerDefinition>("WHERE IndexProviderType = @0", type.ToString());
}
private void InitializeIndexers()
{
Logger.Debug("Initializing indexers. Count {0}", _indexers.Count);
var currentIndexers = All();
foreach (var feedProvider in _indexers)
{
IndexerBase indexerLocal = feedProvider;
if (!currentIndexers.Exists(c => c.IndexProviderType == indexerLocal.GetType().ToString()))
{
var settings = new IndexerDefinition
{
Enable = indexerLocal.EnabledByDefault,
IndexProviderType = indexerLocal.GetType().ToString(),
Name = indexerLocal.Name
};
SaveSettings(settings);
}
}
}
}
}

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NLog;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
@ -18,10 +19,10 @@ namespace NzbDrone.Core.Providers.Search
private readonly ISeriesRepository _seriesRepository;
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public DailyEpisodeSearch(ISeriesService seriesService, EpisodeService episodeService, DownloadProvider downloadProvider, IndexerProvider indexerProvider,
public DailyEpisodeSearch(ISeriesService seriesService, EpisodeService episodeService, DownloadProvider downloadProvider, IndexerService indexerService,
SceneMappingProvider sceneMappingProvider, AllowedDownloadSpecification allowedDownloadSpecification,
SearchHistoryProvider searchHistoryProvider, ISeriesRepository seriesRepository)
: base(seriesService, seriesRepository, episodeService, downloadProvider, indexerProvider, sceneMappingProvider,
: base(seriesService, seriesRepository, episodeService, downloadProvider, indexerService, sceneMappingProvider,
allowedDownloadSpecification, searchHistoryProvider)
{
_seriesRepository = seriesRepository;
@ -41,7 +42,7 @@ namespace NzbDrone.Core.Providers.Search
var reports = new List<EpisodeParseResult>();
var title = GetSearchTitle(series);
Parallel.ForEach(_indexerProvider.GetEnabledIndexers(), indexer =>
Parallel.ForEach(_indexerService.GetEnabledIndexers(), indexer =>
{
try
{

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NLog;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
@ -17,10 +18,10 @@ namespace NzbDrone.Core.Providers.Search
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public EpisodeSearch(ISeriesService seriesService, EpisodeService episodeService, DownloadProvider downloadProvider, IndexerProvider indexerProvider,
public EpisodeSearch(ISeriesService seriesService, EpisodeService episodeService, DownloadProvider downloadProvider, IndexerService indexerService,
SceneMappingProvider sceneMappingProvider, AllowedDownloadSpecification allowedDownloadSpecification,
SearchHistoryProvider searchHistoryProvider, ISeriesRepository seriesRepository)
: base(seriesService,seriesRepository, episodeService, downloadProvider, indexerProvider, sceneMappingProvider,
: base(seriesService,seriesRepository, episodeService, downloadProvider, indexerService, sceneMappingProvider,
allowedDownloadSpecification, searchHistoryProvider)
{
}
@ -55,7 +56,7 @@ namespace NzbDrone.Core.Providers.Search
}
}
Parallel.ForEach(_indexerProvider.GetEnabledIndexers(), indexer =>
Parallel.ForEach(_indexerService.GetEnabledIndexers(), indexer =>
{
try
{

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NLog;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
@ -17,10 +18,10 @@ namespace NzbDrone.Core.Providers.Search
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public PartialSeasonSearch(ISeriesService seriesService, EpisodeService episodeService, DownloadProvider downloadProvider, IndexerProvider indexerProvider,
public PartialSeasonSearch(ISeriesService seriesService, EpisodeService episodeService, DownloadProvider downloadProvider, IndexerService indexerService,
SceneMappingProvider sceneMappingProvider, AllowedDownloadSpecification allowedDownloadSpecification,
SearchHistoryProvider searchHistoryProvider,ISeriesRepository seriesRepository)
: base(seriesService, seriesRepository, episodeService, downloadProvider, indexerProvider, sceneMappingProvider,
: base(seriesService, seriesRepository, episodeService, downloadProvider, indexerService, sceneMappingProvider,
allowedDownloadSpecification, searchHistoryProvider)
{
}
@ -54,7 +55,7 @@ namespace NzbDrone.Core.Providers.Search
{
var prefix = p;
Parallel.ForEach(_indexerProvider.GetEnabledIndexers(), indexer =>
Parallel.ForEach(_indexerService.GetEnabledIndexers(), indexer =>
{
try
{

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using NLog;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
@ -17,7 +18,7 @@ namespace NzbDrone.Core.Providers.Search
private readonly ISeriesRepository _seriesRepository;
protected readonly EpisodeService _episodeService;
protected readonly DownloadProvider _downloadProvider;
protected readonly IndexerProvider _indexerProvider;
protected readonly IndexerService _indexerService;
protected readonly SceneMappingProvider _sceneMappingProvider;
protected readonly AllowedDownloadSpecification _allowedDownloadSpecification;
protected readonly SearchHistoryProvider _searchHistoryProvider;
@ -25,7 +26,7 @@ namespace NzbDrone.Core.Providers.Search
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
protected SearchBase(ISeriesService seriesService,ISeriesRepository seriesRepository, EpisodeService episodeService, DownloadProvider downloadProvider,
IndexerProvider indexerProvider, SceneMappingProvider sceneMappingProvider,
IndexerService indexerService, SceneMappingProvider sceneMappingProvider,
AllowedDownloadSpecification allowedDownloadSpecification,
SearchHistoryProvider searchHistoryProvider)
{
@ -33,7 +34,7 @@ namespace NzbDrone.Core.Providers.Search
_seriesRepository = seriesRepository;
_episodeService = episodeService;
_downloadProvider = downloadProvider;
_indexerProvider = indexerProvider;
_indexerService = indexerService;
_sceneMappingProvider = sceneMappingProvider;
_allowedDownloadSpecification = allowedDownloadSpecification;
_searchHistoryProvider = searchHistoryProvider;

@ -1,18 +0,0 @@
using System;
using PetaPoco;
namespace NzbDrone.Core.Repository
{
[TableName("IndexerDefinitions")]
[PrimaryKey("Id", autoIncrement = true)]
public class IndexerDefinition
{
public int Id { get; set; }
public Boolean Enable { get; set; }
public String IndexProviderType { get; set; }
public String Name { get; set; }
}
}

Binary file not shown.
Loading…
Cancel
Save