From 5a5512a1cd34aad163201a82be3db89e3bfe193e Mon Sep 17 00:00:00 2001 From: Drewster727 Date: Tue, 29 Mar 2016 11:38:22 -0500 Subject: [PATCH] #96 fix up notification test feature --- PlexRequests.UI/Modules/AdminModule.cs | 51 +++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/PlexRequests.UI/Modules/AdminModule.cs b/PlexRequests.UI/Modules/AdminModule.cs index df9bfef0d..87bc29da9 100644 --- a/PlexRequests.UI/Modules/AdminModule.cs +++ b/PlexRequests.UI/Modules/AdminModule.cs @@ -397,8 +397,21 @@ namespace PlexRequests.UI.Modules NotificationType = NotificationType.Test, DateTime = DateTime.Now }; - NotificationService.Publish(notificationModel, settings); - Log.Info("Sent email notification test"); + try + { + NotificationService.Subscribe(new EmailMessageNotification(EmailService)); + settings.Enabled = true; + NotificationService.Publish(notificationModel, settings); + Log.Info("Sent email notification test"); + } + catch (Exception) + { + Log.Error("Failed to subscribe and publish test Email Notification"); + } + finally + { + NotificationService.UnSubscribe(new EmailMessageNotification(EmailService)); + } return Response.AsJson(new JsonResponseModel { Result = true, Message = "Successfully sent a test Email Notification!" }); } @@ -483,8 +496,21 @@ namespace PlexRequests.UI.Modules NotificationType = NotificationType.Test, DateTime = DateTime.Now }; - NotificationService.Publish(notificationModel, settings); - Log.Info("Sent pushbullet notification test"); + try + { + NotificationService.Subscribe(new PushbulletNotification(PushbulletApi, PushbulletService)); + settings.Enabled = true; + NotificationService.Publish(notificationModel, settings); + Log.Info("Sent pushbullet notification test"); + } + catch (Exception) + { + Log.Error("Failed to subscribe and publish test Pushbullet Notification"); + } + finally + { + NotificationService.UnSubscribe(new PushbulletNotification(PushbulletApi, PushbulletService)); + } return Response.AsJson(new JsonResponseModel { Result = true, Message = "Successfully sent a test Pushbullet Notification!" }); } @@ -533,8 +559,21 @@ namespace PlexRequests.UI.Modules NotificationType = NotificationType.Test, DateTime = DateTime.Now }; - NotificationService.Publish(notificationModel, settings); - Log.Info("Sent pushover notification test"); + try + { + NotificationService.Subscribe(new PushoverNotification(PushoverApi, PushoverService)); + settings.Enabled = true; + NotificationService.Publish(notificationModel, settings); + Log.Info("Sent pushover notification test"); + } + catch (Exception) + { + Log.Error("Failed to subscribe and publish test Pushover Notification"); + } + finally + { + NotificationService.UnSubscribe(new PushoverNotification(PushoverApi, PushoverService)); + } return Response.AsJson(new JsonResponseModel { Result = true, Message = "Successfully sent a test Pushover Notification!" }); }