1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-09-20 08:21:46 +02:00
Radarr/NzbDrone.Core/Notifications/NotificationSettingsProvider.cs

31 lines
1007 B
C#
Raw Normal View History

2013-05-20 01:17:32 +02:00
using Newtonsoft.Json;
namespace NzbDrone.Core.Notifications
{
public interface INotificationSettingsProvider
{
TSetting Get<TSetting>(INotification indexer) where TSetting : INotifcationSettings, new();
}
public class NotificationSettingsProvider : INotificationSettingsProvider
{
private readonly INotificationRepository _notificationRepository;
public NotificationSettingsProvider(INotificationRepository notificationRepository)
{
_notificationRepository = notificationRepository;
}
public TSetting Get<TSetting>(INotification indexer) where TSetting : INotifcationSettings, new()
{
var indexerDef = _notificationRepository.Find(indexer.Name);
if (indexerDef == null || string.IsNullOrWhiteSpace(indexerDef.Settings))
{
return new TSetting();
}
return JsonConvert.DeserializeObject<TSetting>(indexerDef.Settings);
}
}
}