2013-09-22 08:20:26 +03:00
|
|
|
using System.Collections.Generic;
|
2013-09-22 23:00:29 +03:00
|
|
|
using System.Linq;
|
2013-02-21 10:07:34 +03:00
|
|
|
using NLog;
|
2013-09-21 10:09:26 +03:00
|
|
|
using NzbDrone.Core.ThingiProvider;
|
2013-03-02 21:25:39 +03:00
|
|
|
|
2013-02-21 10:07:34 +03:00
|
|
|
namespace NzbDrone.Core.Indexers
|
|
|
|
{
|
2013-09-25 02:42:55 +03:00
|
|
|
public interface IIndexerFactory : IProviderFactory<IIndexer, IndexerDefinition>
|
2013-05-02 04:59:09 +03:00
|
|
|
{
|
|
|
|
|
2013-02-21 10:07:34 +03:00
|
|
|
}
|
|
|
|
|
2013-09-25 02:42:55 +03:00
|
|
|
public class IndexerFactory : ProviderFactory<IIndexer, IndexerDefinition>, IIndexerFactory
|
2013-02-21 10:07:34 +03:00
|
|
|
{
|
2013-09-22 23:06:11 +03:00
|
|
|
private readonly IIndexerRepository _providerRepository;
|
2013-09-22 23:00:29 +03:00
|
|
|
private readonly IEnumerable<IIndexer> _providers;
|
|
|
|
|
2013-09-25 02:42:55 +03:00
|
|
|
public IndexerFactory(IIndexerRepository providerRepository, IEnumerable<IIndexer> providers, Logger logger)
|
2013-09-22 08:20:26 +03:00
|
|
|
: base(providerRepository, providers, logger)
|
2013-02-21 10:07:34 +03:00
|
|
|
{
|
2013-09-22 23:00:29 +03: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 03:05:09 +03:00
|
|
|
}
|
2013-02-21 10:07:34 +03:00
|
|
|
}
|
|
|
|
}
|