#96 Email notification test button (others to come)

This commit is contained in:
Drewster727 2016-03-27 23:45:52 -05:00
parent 085c46ce43
commit 4b3f79b4a8
9 changed files with 134 additions and 18 deletions

View file

@ -32,6 +32,7 @@ using System.Threading.Tasks;
using NLog;
using PlexRequests.Services.Interfaces;
using PlexRequests.Core.SettingModels;
namespace PlexRequests.Services.Notification
{
@ -47,6 +48,13 @@ namespace PlexRequests.Services.Notification
await Task.WhenAll(notificationTasks).ConfigureAwait(false);
}
public async Task Publish(NotificationModel model, EmailNotificationSettings settings)
{
var notificationTasks = Observers.Values.Select(notification => NotifyAsync(notification, model, settings));
await Task.WhenAll(notificationTasks).ConfigureAwait(false);
}
public void Subscribe(INotification notification)
{
Observers.TryAdd(notification.NotificationName, notification);
@ -58,10 +66,17 @@ namespace PlexRequests.Services.Notification
}
private static async Task NotifyAsync(INotification notification, NotificationModel model)
{
await NotifyAsync(notification, model, null);
}
private static async Task NotifyAsync(INotification notification, NotificationModel model, EmailNotificationSettings settings)
{
try
{
await notification.NotifyAsync(model).ConfigureAwait(false);
await notification.NotifyAsync(model, settings).ConfigureAwait(false);
}
catch (Exception ex)
{