2013-04-07 09:30:37 +02:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Indexers
|
|
|
|
|
{
|
|
|
|
|
public interface IProviderIndexerSetting
|
|
|
|
|
{
|
2013-05-02 03:59:09 +02:00
|
|
|
|
TSetting Get<TSetting>(IIndexer indexer) where TSetting : IIndexerSetting, new();
|
2013-04-07 09:30:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class IndexerSettingProvider : IProviderIndexerSetting
|
|
|
|
|
{
|
|
|
|
|
private readonly IIndexerRepository _indexerRepository;
|
|
|
|
|
|
|
|
|
|
public IndexerSettingProvider(IIndexerRepository indexerRepository)
|
|
|
|
|
{
|
|
|
|
|
_indexerRepository = indexerRepository;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-02 03:59:09 +02:00
|
|
|
|
public TSetting Get<TSetting>(IIndexer indexer) where TSetting : IIndexerSetting, new()
|
2013-04-07 09:30:37 +02:00
|
|
|
|
{
|
2013-04-11 01:44:48 +02:00
|
|
|
|
var indexerDef = _indexerRepository.Find(indexer.Name);
|
|
|
|
|
|
|
|
|
|
if (indexerDef == null || string.IsNullOrWhiteSpace(indexerDef.Settings))
|
|
|
|
|
{
|
|
|
|
|
return new TSetting();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return JsonConvert.DeserializeObject<TSetting>(indexerDef.Settings);
|
2013-04-07 09:30:37 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|