Notification schema added to server side.

This commit is contained in:
Mark McDowall 2013-05-24 18:51:25 -07:00
parent fea10997ad
commit 482cbc20a3
6 changed files with 152 additions and 1 deletions

View file

@ -15,6 +15,7 @@ namespace NzbDrone.Core.Notifications
{
List<Notification> All();
Notification Get(int id);
List<Notification> Schema();
}
public class NotificationService
@ -49,6 +50,32 @@ namespace NzbDrone.Core.Notifications
return ToNotification(_notificationRepository.Get(id));
}
public List<Notification> Schema()
{
var notifications = new List<Notification>();
int i = 1;
foreach (var notification in _notifications)
{
i++;
var type = notification.GetType();
var newNotification = new Notification();
newNotification.Instance = (INotification)_container.Resolve(type);
newNotification.Id = i;
newNotification.Name = notification.Name;
var instanceType = newNotification.Instance.GetType();
var baseGenArgs = instanceType.BaseType.GetGenericArguments();
newNotification.Settings = (INotifcationSettings) Activator.CreateInstance(baseGenArgs[0]);
newNotification.Implementation = type.Name;
notifications.Add(newNotification);
}
return notifications;
}
private Notification ToNotification(NotificationDefinition definition)
{
var notification = new Notification();