|
|
@ -2,6 +2,7 @@
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
|
|
|
using NLog;
|
|
|
|
|
|
|
|
using NzbDrone.Common.Composition;
|
|
|
|
using NzbDrone.Core.Lifecycle;
|
|
|
|
using NzbDrone.Core.Lifecycle;
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
|
|
|
|
|
|
|
|
@ -12,13 +13,18 @@ namespace NzbDrone.Core.ThingiProvider
|
|
|
|
where TProvider : IProvider
|
|
|
|
where TProvider : IProvider
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly IProviderRepository<TProviderDefinition> _providerRepository;
|
|
|
|
private readonly IProviderRepository<TProviderDefinition> _providerRepository;
|
|
|
|
|
|
|
|
private readonly IContainer _container;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
|
|
private readonly List<TProvider> _providers;
|
|
|
|
private readonly List<TProvider> _providers;
|
|
|
|
|
|
|
|
|
|
|
|
protected ProviderFactory(IProviderRepository<TProviderDefinition> providerRepository, IEnumerable<TProvider> providers, Logger logger)
|
|
|
|
protected ProviderFactory(IProviderRepository<TProviderDefinition> providerRepository,
|
|
|
|
|
|
|
|
IEnumerable<TProvider> providers,
|
|
|
|
|
|
|
|
IContainer container,
|
|
|
|
|
|
|
|
Logger logger)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_providerRepository = providerRepository;
|
|
|
|
_providerRepository = providerRepository;
|
|
|
|
|
|
|
|
_container = container;
|
|
|
|
_providers = providers.ToList();
|
|
|
|
_providers = providers.ToList();
|
|
|
|
_logger = logger;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -40,8 +46,7 @@ namespace NzbDrone.Core.ThingiProvider
|
|
|
|
|
|
|
|
|
|
|
|
public List<TProvider> GetAvailableProviders()
|
|
|
|
public List<TProvider> GetAvailableProviders()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return All().Where(c => c.Settings.Validate().IsValid)
|
|
|
|
return Active().Select(GetInstance).ToList();
|
|
|
|
.Select(GetInstance).ToList();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public TProviderDefinition Get(int id)
|
|
|
|
public TProviderDefinition Get(int id)
|
|
|
@ -67,7 +72,9 @@ namespace NzbDrone.Core.ThingiProvider
|
|
|
|
private TProvider GetInstance(TProviderDefinition definition)
|
|
|
|
private TProvider GetInstance(TProviderDefinition definition)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var type = GetImplementation(definition);
|
|
|
|
var type = GetImplementation(definition);
|
|
|
|
var instance = (TProvider)Activator.CreateInstance(type);
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: This doesn't work for things that have non-parameterless constructors
|
|
|
|
|
|
|
|
var instance = (TProvider)_container.Resolve(type);
|
|
|
|
instance.Definition = definition;
|
|
|
|
instance.Definition = definition;
|
|
|
|
return instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -90,6 +97,11 @@ namespace NzbDrone.Core.ThingiProvider
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual List<TProviderDefinition> Active()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return All().Where(c => c.Settings.Validate().IsValid).ToList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void RemoveMissingImplementations()
|
|
|
|
private void RemoveMissingImplementations()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var storedProvider = _providerRepository.All();
|
|
|
|
var storedProvider = _providerRepository.All();
|
|
|
|