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