1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-21 01:49:57 +02:00
Sonarr/src/NzbDrone.Core/Indexers/IndexerFactory.cs

40 lines
1.3 KiB
C#
Raw Normal View History

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;
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-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()
{
2013-10-01 22:33:48 +03:00
var definitions = _providers.Where(c => c.Protocol == DownloadProtocol.Usenet)
.SelectMany(indexer => indexer.DefaultDefinitions);
2013-09-22 23:00:29 +03:00
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
}
}