2013-09-22 05:20:26 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-09-22 20:00:29 +00:00
|
|
|
|
using System.Linq;
|
2013-02-21 07:07:34 +00:00
|
|
|
|
using NLog;
|
2013-09-21 07:09:26 +00:00
|
|
|
|
using NzbDrone.Core.ThingiProvider;
|
2013-03-02 18:25:39 +00:00
|
|
|
|
|
2013-02-21 07:07:34 +00:00
|
|
|
|
namespace NzbDrone.Core.Indexers
|
|
|
|
|
{
|
2013-09-22 05:20:26 +00:00
|
|
|
|
public interface IIndexerService : IProviderFactory<IIndexer, IndexerDefinition>
|
2013-05-02 01:59:09 +00:00
|
|
|
|
{
|
|
|
|
|
|
2013-02-21 07:07:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-09-22 05:20:26 +00:00
|
|
|
|
public class IndexerService : ProviderFactory<IIndexer, IndexerDefinition>
|
2013-02-21 07:07:34 +00:00
|
|
|
|
{
|
2013-09-22 20:00:29 +00:00
|
|
|
|
private readonly IProviderRepository<IndexerDefinition> _providerRepository;
|
|
|
|
|
private readonly IEnumerable<IIndexer> _providers;
|
|
|
|
|
|
2013-09-22 05:20:26 +00:00
|
|
|
|
public IndexerService(IProviderRepository<IndexerDefinition> providerRepository, IEnumerable<IIndexer> providers, Logger logger)
|
|
|
|
|
: base(providerRepository, providers, logger)
|
2013-02-21 07:07:34 +00:00
|
|
|
|
{
|
2013-09-22 20:00:29 +00:00
|
|
|
|
_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());
|
|
|
|
|
}
|
2013-06-28 00:05:09 +00:00
|
|
|
|
}
|
2013-02-21 07:07:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|