mirror of
https://github.com/Radarr/Radarr
synced 2024-12-30 20:05:41 +00:00
31 lines
1,007 B
C#
31 lines
1,007 B
C#
|
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);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|