Small refactorings

pull/794/head
Jamie.Rees 8 years ago
parent 1067b9afd7
commit 83bb1b58e7

@ -33,7 +33,6 @@ namespace PlexRequests.Core.SettingModels
public int EmailPort { get; set; } public int EmailPort { get; set; }
public string EmailSender { get; set; } public string EmailSender { get; set; }
public string EmailUsername { get; set; } public string EmailUsername { get; set; }
public bool Enabled { get; set; }
public bool Authentication { get; set; } public bool Authentication { get; set; }
public bool EnableUserEmailNotifications { get; set; } public bool EnableUserEmailNotifications { get; set; }
public string RecipientEmail { get; set; } public string RecipientEmail { get; set; }

@ -45,6 +45,9 @@ namespace PlexRequests.Core.SettingModels
}; };
} }
public bool Enabled { get; set; }
public List<NotificationMessage> Message { get; set; } public List<NotificationMessage> Message { get; set; }
} }

@ -30,6 +30,5 @@ namespace PlexRequests.Core.SettingModels
{ {
public string AccessToken { get; set; } public string AccessToken { get; set; }
public string DeviceIdentifier { get; set; } public string DeviceIdentifier { get; set; }
public bool Enabled { get; set; }
} }
} }

@ -29,7 +29,6 @@ namespace PlexRequests.Core.SettingModels
public sealed class PushoverNotificationSettings : NotificationSettings public sealed class PushoverNotificationSettings : NotificationSettings
{ {
public string AccessToken { get; set; } public string AccessToken { get; set; }
public bool Enabled { get; set; }
public string UserToken { get; set; } public string UserToken { get; set; }
} }
} }

@ -6,7 +6,6 @@ namespace PlexRequests.Core.SettingModels
{ {
public sealed class SlackNotificationSettings : NotificationSettings public sealed class SlackNotificationSettings : NotificationSettings
{ {
public bool Enabled { get; set; }
public string WebhookUrl { get; set; } public string WebhookUrl { get; set; }
public string Channel { get; set; } public string Channel { get; set; }
public string Username { get; set; } public string Username { get; set; }

@ -31,13 +31,11 @@ using System.Net;
using Mono.Data.Sqlite; using Mono.Data.Sqlite;
using Nancy; using Nancy;
using Nancy.Authentication.Forms;
using Nancy.Bootstrapper; using Nancy.Bootstrapper;
using Nancy.Bootstrappers.Ninject; using Nancy.Bootstrappers.Ninject;
using Nancy.Conventions; using Nancy.Conventions;
using Nancy.Cryptography; using Nancy.Cryptography;
using Nancy.Diagnostics; using Nancy.Diagnostics;
using Nancy.Hosting.Self;
using Nancy.Session; using Nancy.Session;
using PlexRequests.Api.Interfaces; using PlexRequests.Api.Interfaces;
@ -105,9 +103,6 @@ namespace PlexRequests.UI
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
ServicePointManager.ServerCertificateValidationCallback += ServicePointManager.ServerCertificateValidationCallback +=
(sender, certificate, chain, sslPolicyErrors) => true; (sender, certificate, chain, sslPolicyErrors) => true;
SubscribeAllObservers(container);
} }
#if DEBUG #if DEBUG
@ -142,39 +137,6 @@ namespace PlexRequests.UI
protected override DiagnosticsConfiguration DiagnosticsConfiguration => new DiagnosticsConfiguration { Password = @"password" }; protected override DiagnosticsConfiguration DiagnosticsConfiguration => new DiagnosticsConfiguration { Password = @"password" };
private void SubscribeAllObservers(IKernel container)
{
var notificationService = container.Get<INotificationService>();
var emailSettingsService = container.Get<ISettingsService<EmailNotificationSettings>>();
var emailSettings = emailSettingsService.GetSettings();
if (emailSettings.Enabled)
{
notificationService.Subscribe(new EmailMessageNotification(emailSettingsService));
}
var pushbulletService = container.Get<ISettingsService<PushbulletNotificationSettings>>();
var pushbulletSettings = pushbulletService.GetSettings();
if (pushbulletSettings.Enabled)
{
notificationService.Subscribe(new PushbulletNotification(container.Get<IPushbulletApi>(), pushbulletService));
}
var pushoverService = container.Get<ISettingsService<PushoverNotificationSettings>>();
var pushoverSettings = pushoverService.GetSettings();
if (pushoverSettings.Enabled)
{
notificationService.Subscribe(new PushoverNotification(container.Get<IPushoverApi>(), pushoverService));
}
var slackService = container.Get<ISettingsService<SlackNotificationSettings>>();
var slackSettings = slackService.GetSettings();
if (slackSettings.Enabled)
{
notificationService.Subscribe(new SlackNotification(container.Get<ISlackApi>(), slackService));
}
}
protected override void RequestStartup(IKernel container, IPipelines pipelines, NancyContext context) protected override void RequestStartup(IKernel container, IPipelines pipelines, NancyContext context)
{ {
//CORS Enable //CORS Enable

@ -28,13 +28,17 @@ using System;
using System.Diagnostics; using System.Diagnostics;
using Ninject; using Ninject;
using Ninject.Planning.Bindings.Resolvers; using Ninject.Planning.Bindings.Resolvers;
using Ninject.Syntax;
using NLog; using NLog;
using Owin; using Owin;
using PlexRequests.Api.Interfaces;
using PlexRequests.Core; using PlexRequests.Core;
using PlexRequests.Core.Migration; using PlexRequests.Core.Migration;
using PlexRequests.Core.SettingModels;
using PlexRequests.Services.Interfaces;
using PlexRequests.Services.Jobs; using PlexRequests.Services.Jobs;
using PlexRequests.Services.Notification;
using PlexRequests.Store.Models; using PlexRequests.Store.Models;
using PlexRequests.Store.Repository; using PlexRequests.Store.Repository;
using PlexRequests.UI.Helpers; using PlexRequests.UI.Helpers;
@ -90,9 +94,7 @@ namespace PlexRequests.UI
} }
scheduler.StartScheduler(); scheduler.StartScheduler();
SubscribeAllObservers(kernel);
} }
catch (Exception exception) catch (Exception exception)
@ -101,5 +103,37 @@ namespace PlexRequests.UI
throw; throw;
} }
} }
private void SubscribeAllObservers(IResolutionRoot container)
{
var notificationService = container.Get<INotificationService>();
var emailSettingsService = container.Get<ISettingsService<EmailNotificationSettings>>();
var emailSettings = emailSettingsService.GetSettings();
SubScribeOvserver(emailSettings, notificationService ,new EmailMessageNotification(emailSettingsService));
var pushbulletService = container.Get<ISettingsService<PushbulletNotificationSettings>>();
var pushbulletSettings = pushbulletService.GetSettings();
SubScribeOvserver(pushbulletSettings, notificationService, new PushbulletNotification(container.Get<IPushbulletApi>(), pushbulletService));
var pushoverService = container.Get<ISettingsService<PushoverNotificationSettings>>();
var pushoverSettings = pushoverService.GetSettings();
SubScribeOvserver(pushoverSettings, notificationService, new PushoverNotification(container.Get<IPushoverApi>(), pushoverService));
var slackService = container.Get<ISettingsService<SlackNotificationSettings>>();
var slackSettings = slackService.GetSettings();
SubScribeOvserver(slackSettings, notificationService, new SlackNotification(container.Get<ISlackApi>(), slackService));
}
private void SubScribeOvserver<T>(T settings, INotificationService notificationService, INotification notification)
where T : NotificationSettings
{
if (settings.Enabled)
{
notificationService.Subscribe(notification);
}
}
} }
} }
Loading…
Cancel
Save