|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using NzbDrone.Api.ClientSchema;
|
|
|
|
|
using NzbDrone.Common.Reflection;
|
|
|
|
|
using NzbDrone.Core.Annotations;
|
|
|
|
|
using NzbDrone.Core.Notifications;
|
|
|
|
|
using Omu.ValueInjecter;
|
|
|
|
|
|
|
|
|
@ -12,7 +14,9 @@ namespace NzbDrone.Api.Notifications
|
|
|
|
|
public NotificationModule(INotificationService notificationService)
|
|
|
|
|
{
|
|
|
|
|
_notificationService = notificationService;
|
|
|
|
|
|
|
|
|
|
GetResourceAll = GetAll;
|
|
|
|
|
UpdateResource = Update;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<NotificationResource> GetAll()
|
|
|
|
@ -23,14 +27,42 @@ namespace NzbDrone.Api.Notifications
|
|
|
|
|
|
|
|
|
|
foreach (var notification in notifications)
|
|
|
|
|
{
|
|
|
|
|
var indexerResource = new NotificationResource();
|
|
|
|
|
indexerResource.InjectFrom(notification);
|
|
|
|
|
indexerResource.Fields = SchemaBuilder.GenerateSchema(notification.Settings);
|
|
|
|
|
var notificationResource = new NotificationResource();
|
|
|
|
|
notificationResource.InjectFrom(notification);
|
|
|
|
|
notificationResource.Fields = SchemaBuilder.GenerateSchema(notification.Settings);
|
|
|
|
|
|
|
|
|
|
result.Add(indexerResource);
|
|
|
|
|
result.Add(notificationResource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private NotificationResource Update(NotificationResource notificationResource)
|
|
|
|
|
{
|
|
|
|
|
//Todo: Convert Resource back to Settings
|
|
|
|
|
|
|
|
|
|
var notification = _notificationService.Get(notificationResource.Id);
|
|
|
|
|
|
|
|
|
|
notification.OnGrab = notificationResource.OnGrab;
|
|
|
|
|
notification.OnDownload = notificationResource.OnDownload;
|
|
|
|
|
|
|
|
|
|
var properties = notification.Settings.GetType().GetSimpleProperties();
|
|
|
|
|
|
|
|
|
|
foreach (var propertyInfo in properties)
|
|
|
|
|
{
|
|
|
|
|
var fieldAttribute = propertyInfo.GetAttribute<FieldDefinitionAttribute>(false);
|
|
|
|
|
|
|
|
|
|
if (fieldAttribute != null)
|
|
|
|
|
{
|
|
|
|
|
//Find coresponding field
|
|
|
|
|
|
|
|
|
|
var field = notificationResource.Fields.Find(f => f.Name == propertyInfo.Name);
|
|
|
|
|
|
|
|
|
|
propertyInfo.SetValue(notification.Settings, field.Value, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return notificationResource;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|