1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 10:32:35 +01:00
Radarr/NzbDrone.Core/Indexers/IndexerSettingProvider.cs
2013-04-10 16:44:59 -07:00

31 lines
931 B
C#

using Newtonsoft.Json;
namespace NzbDrone.Core.Indexers
{
public interface IProviderIndexerSetting
{
TSetting Get<TSetting>(IIndexerBase indexer) where TSetting : IIndexerSetting, new();
}
public class IndexerSettingProvider : IProviderIndexerSetting
{
private readonly IIndexerRepository _indexerRepository;
public IndexerSettingProvider(IIndexerRepository indexerRepository)
{
_indexerRepository = indexerRepository;
}
public TSetting Get<TSetting>(IIndexerBase indexer) where TSetting : IIndexerSetting, new()
{
var indexerDef = _indexerRepository.Find(indexer.Name);
if (indexerDef == null || string.IsNullOrWhiteSpace(indexerDef.Settings))
{
return new TSetting();
}
return JsonConvert.DeserializeObject<TSetting>(indexerDef.Settings);
}
}
}