using System.Collections.Generic; using System.Linq; using NLog; using NzbDrone.Core.ThingiProvider; namespace NzbDrone.Core.Indexers { public interface IIndexerService : IProviderFactory { } public class IndexerService : ProviderFactory { private readonly IProviderRepository _providerRepository; private readonly IEnumerable _providers; public IndexerService(IProviderRepository providerRepository, IEnumerable 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().ToList()); } } } }