2013-09-19 03:24:50 +03:00
|
|
|
using NzbDrone.Common.Serializer;
|
2013-05-20 02:17:32 +03:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2013-09-19 03:24:50 +03:00
|
|
|
return Json.Deserialize<TSetting>(indexerDef.Settings);
|
2013-05-20 02:17:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|