1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

Newznab indexers are tested before creating

This commit is contained in:
Mark McDowall 2013-10-13 23:19:30 -07:00
parent 1689aa4f64
commit 03149b1396
2 changed files with 18 additions and 7 deletions

View File

@ -16,12 +16,14 @@ public class IndexerFactory : ProviderFactory<IIndexer, IndexerDefinition>, IInd
{
private readonly IIndexerRepository _providerRepository;
private readonly IEnumerable<IIndexer> _providers;
private readonly INewznabTestService _newznabTestService;
public IndexerFactory(IIndexerRepository providerRepository, IEnumerable<IIndexer> providers, IContainer container, Logger logger)
public IndexerFactory(IIndexerRepository providerRepository, IEnumerable<IIndexer> providers, IContainer container, INewznabTestService newznabTestService, Logger logger)
: base(providerRepository, providers, container, logger)
{
_providerRepository = providerRepository;
_providers = providers;
_newznabTestService = newznabTestService;
}
protected override void InitializeProviders()
@ -43,5 +45,16 @@ 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);
}
}
}

View File

@ -54,12 +54,12 @@ public TProviderDefinition Get(int id)
return _providerRepository.Get(id);
}
public TProviderDefinition Create(TProviderDefinition provider)
public virtual TProviderDefinition Create(TProviderDefinition definition)
{
return _providerRepository.Insert(provider);
return _providerRepository.Insert(definition);
}
public void Update(TProviderDefinition definition)
public virtual void Update(TProviderDefinition definition)
{
_providerRepository.Update(definition);
}
@ -69,11 +69,9 @@ public void Delete(int id)
_providerRepository.Delete(id);
}
private TProvider GetInstance(TProviderDefinition definition)
protected TProvider GetInstance(TProviderDefinition definition)
{
var type = GetImplementation(definition);
//TODO: This doesn't work for things that have non-parameterless constructors
var instance = (TProvider)_container.Resolve(type);
instance.Definition = definition;
return instance;