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

60 lines
2.0 KiB
C#
Raw Normal View History

2013-10-13 05:46:36 +03:00
using System;
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-10-13 05:46:36 +03:00
using NzbDrone.Common.Composition;
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;
private readonly INewznabTestService _newznabTestService;
2013-09-22 23:00:29 +03:00
public IndexerFactory(IIndexerRepository providerRepository, IEnumerable<IIndexer> providers, IContainer container, INewznabTestService newznabTestService, Logger logger)
2013-10-13 05:46:36 +03:00
: base(providerRepository, providers, container, logger)
2013-02-21 10:07:34 +03:00
{
2013-09-22 23:00:29 +03:00
_providerRepository = providerRepository;
_providers = providers;
_newznabTestService = newznabTestService;
2013-09-22 23:00:29 +03:00
}
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-10-13 05:46:36 +03:00
protected override List<IndexerDefinition> Active()
{
return base.Active().Where(c => c.Enable).ToList();
}
public override IndexerDefinition Create(IndexerDefinition definition)
{
if (definition.Implementation == typeof(Newznab.Newznab).Name)
{
var indexer = GetInstance(definition);
_newznabTestService.Test(indexer);
}
return base.Create(definition);
}
2013-02-21 10:07:34 +03:00
}
}