You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Sonarr/NzbDrone.Core/Indexers/IndexerService.cs

40 lines
1.3 KiB

using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.Indexers
{
public interface IIndexerService : IProviderFactory<IIndexer, IndexerDefinition>
{
}
public class IndexerService : ProviderFactory<IIndexer, IndexerDefinition>
{
private readonly IProviderRepository<IndexerDefinition> _providerRepository;
private readonly IEnumerable<IIndexer> _providers;
public IndexerService(IProviderRepository<IndexerDefinition> providerRepository, IEnumerable<IIndexer> providers, Logger logger)
: base(providerRepository, providers, logger)
{
_providerRepository = providerRepository;
_providers = providers;
}
protected override void InitializeProviders()
{
var definitions = _providers.SelectMany(indexer => indexer.DefaultDefinitions);
var currentProviders = All();
var newProviders = definitions.Where(def => currentProviders.All(c => c.Implementation != def.Implementation)).ToList();
if (newProviders.Any())
{
_providerRepository.InsertMany(newProviders.Cast<IndexerDefinition>().ToList());
}
}
}
}