1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-30 19:56:54 +00:00
Sonarr/NzbDrone.Core/Indexers/IndexerSettingProvider.cs

31 lines
923 B
C#
Raw Normal View History

2013-04-07 07:30:37 +00:00
using Newtonsoft.Json;
namespace NzbDrone.Core.Indexers
{
public interface IProviderIndexerSetting
{
TSetting Get<TSetting>(IIndexer indexer) where TSetting : IIndexerSetting, new();
2013-04-07 07:30:37 +00:00
}
public class IndexerSettingProvider : IProviderIndexerSetting
{
private readonly IIndexerRepository _indexerRepository;
public IndexerSettingProvider(IIndexerRepository indexerRepository)
{
_indexerRepository = indexerRepository;
}
public TSetting Get<TSetting>(IIndexer indexer) where TSetting : IIndexerSetting, new()
2013-04-07 07:30:37 +00:00
{
2013-04-10 23:44:48 +00: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 07:30:37 +00:00
}
}
}