Merge pull request #1246 from tidusjar/dev

A fix to the about page and also started to rework the notification b…
pull/1300/head
Jamie 8 years ago committed by GitHub
commit 1bd026b9d9

@ -162,7 +162,7 @@ namespace Ombi.Core.StatusChecker
}
var downloadLink = $"{AppveyorApiUrl}/buildjobs/{jobId}/artifacts/{artifactResult.fileName}";
var branchDisplay = EnumHelper<Branches>.GetDisplayValue(branch);
var branchDisplay = EnumHelper<Branches>.GetBranchValue<BranchAttribute>(branch).DisplayName;
var fileversion = AssemblyHelper.GetFileVersion();
var model = new StatusModel

@ -0,0 +1,116 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2017 Jamie Rees
// File: BaseNotification.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using System.Threading.Tasks;
using NLog;
using Ombi.Core;
using Ombi.Core.Models;
using Ombi.Core.SettingModels;
using Ombi.Services.Interfaces;
namespace Ombi.Services.Notification
{
public abstract class BaseNotification<T,U> : INotification where T : Settings, new() where U : new()
{
protected BaseNotification(ISettingsService<T> settings)
{
Settings = settings;
}
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
protected ISettingsService<T> Settings { get; }
public abstract string NotificationName { get; }
public async Task NotifyAsync(NotificationModel model)
{
var configuration = GetConfiguration();
await NotifyAsync(model, configuration);
}
public async Task NotifyAsync(NotificationModel model, Settings settings)
{
if (settings == null) await NotifyAsync(model);
var notificationSettings = (T)settings;
if (!ValidateConfiguration(notificationSettings))
{
return;
}
switch (model.NotificationType)
{
case NotificationType.NewRequest:
await EmailNewRequest(model, notificationSettings);
break;
case NotificationType.Issue:
await EmailIssue(model, notificationSettings);
break;
case NotificationType.RequestAvailable:
await EmailAvailableRequest(model, notificationSettings);
break;
case NotificationType.RequestApproved:
await EmailRequestApproved(model, notificationSettings);
break;
case NotificationType.AdminNote:
throw new NotImplementedException();
case NotificationType.Test:
await EmailTest(model, notificationSettings);
break;
case NotificationType.RequestDeclined:
await EmailRequestDeclined(model, notificationSettings);
break;
case NotificationType.ItemAddedToFaultQueue:
await EmailAddedToRequestQueue(model, notificationSettings);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
private T GetConfiguration()
{
var settings = Settings.GetSettings();
return settings;
}
protected abstract bool ValidateConfiguration(T settings);
protected abstract Task EmailNewRequest(NotificationModel model, T settings);
protected abstract Task EmailIssue(NotificationModel model, T settings);
protected abstract Task EmailAddedToRequestQueue(NotificationModel model, T settings);
protected abstract Task EmailRequestDeclined(NotificationModel model, T settings);
protected abstract Task EmailRequestApproved(NotificationModel model, T settings);
protected abstract Task EmailAvailableRequest(NotificationModel model, T settings);
protected abstract Task Send(U message, T settings);
protected abstract Task EmailTest(NotificationModel model, T settings);
}
}

@ -30,82 +30,23 @@ using System.Threading.Tasks;
using MimeKit;
using NLog;
using Ombi.Core;
using Ombi.Core.Models;
using Ombi.Core.Notification.Templates;
using Ombi.Core.SettingModels;
using Ombi.Services.Interfaces;
using Ombi.Store;
using SmtpClient = MailKit.Net.Smtp.SmtpClient;
namespace Ombi.Services.Notification
{
public class EmailMessageNotification : INotification
public class EmailMessageNotification : BaseNotification<EmailNotificationSettings, MimeMessage>
{
public EmailMessageNotification(ISettingsService<EmailNotificationSettings> settings)
public EmailMessageNotification(ISettingsService<EmailNotificationSettings> settings) : base(settings)
{
EmailNotificationSettings = settings;
}
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
private ISettingsService<EmailNotificationSettings> EmailNotificationSettings { get; }
public string NotificationName => "EmailMessageNotification";
public override string NotificationName => "EmailMessageNotification";
public async Task NotifyAsync(NotificationModel model)
{
var configuration = GetConfiguration();
await NotifyAsync(model, configuration);
}
public async Task NotifyAsync(NotificationModel model, Settings settings)
{
if (settings == null) await NotifyAsync(model);
var emailSettings = (EmailNotificationSettings)settings;
if (!ValidateConfiguration(emailSettings))
{
return;
}
switch (model.NotificationType)
{
case NotificationType.NewRequest:
await EmailNewRequest(model, emailSettings);
break;
case NotificationType.Issue:
await EmailIssue(model, emailSettings);
break;
case NotificationType.RequestAvailable:
await EmailAvailableRequest(model, emailSettings);
break;
case NotificationType.RequestApproved:
await EmailRequestApproved(model, emailSettings);
break;
case NotificationType.AdminNote:
throw new NotImplementedException();
case NotificationType.Test:
await EmailTest(model, emailSettings);
break;
case NotificationType.RequestDeclined:
await EmailRequestDeclined(model, emailSettings);
break;
case NotificationType.ItemAddedToFaultQueue:
await EmailAddedToRequestQueue(model, emailSettings);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
private EmailNotificationSettings GetConfiguration()
{
var settings = EmailNotificationSettings.GetSettings();
return settings;
}
private bool ValidateConfiguration(EmailNotificationSettings settings)
protected override bool ValidateConfiguration(EmailNotificationSettings settings)
{
if (settings.Authentication)
{
@ -122,7 +63,7 @@ namespace Ombi.Services.Notification
return true;
}
private async Task EmailNewRequest(NotificationModel model, EmailNotificationSettings settings)
protected override async Task EmailNewRequest(NotificationModel model, EmailNotificationSettings settings)
{
var email = new EmailBasicTemplate();
var html = email.LoadTemplate(
@ -143,7 +84,7 @@ namespace Ombi.Services.Notification
await Send(message, settings);
}
private async Task EmailIssue(NotificationModel model, EmailNotificationSettings settings)
protected override async Task EmailIssue(NotificationModel model, EmailNotificationSettings settings)
{
var email = new EmailBasicTemplate();
var html = email.LoadTemplate(
@ -164,7 +105,7 @@ namespace Ombi.Services.Notification
await Send(message, settings);
}
private async Task EmailAddedToRequestQueue(NotificationModel model, EmailNotificationSettings settings)
protected override async Task EmailAddedToRequestQueue(NotificationModel model, EmailNotificationSettings settings)
{
var email = new EmailBasicTemplate();
var html = email.LoadTemplate(
@ -185,7 +126,7 @@ namespace Ombi.Services.Notification
await Send(message, settings);
}
private async Task EmailRequestDeclined(NotificationModel model, EmailNotificationSettings settings)
protected override async Task EmailRequestDeclined(NotificationModel model, EmailNotificationSettings settings)
{
var email = new EmailBasicTemplate();
var html = email.LoadTemplate(
@ -206,7 +147,7 @@ namespace Ombi.Services.Notification
await Send(message, settings);
}
private async Task EmailRequestApproved(NotificationModel model, EmailNotificationSettings settings)
protected override async Task EmailRequestApproved(NotificationModel model, EmailNotificationSettings settings)
{
var email = new EmailBasicTemplate();
var html = email.LoadTemplate(
@ -227,7 +168,7 @@ namespace Ombi.Services.Notification
await Send(message, settings);
}
private async Task EmailAvailableRequest(NotificationModel model, EmailNotificationSettings settings)
protected override async Task EmailAvailableRequest(NotificationModel model, EmailNotificationSettings settings)
{
var email = new EmailBasicTemplate();
var html = email.LoadTemplate(
@ -247,7 +188,7 @@ namespace Ombi.Services.Notification
await Send(message, settings);
}
private async Task Send(MimeMessage message, EmailNotificationSettings settings)
protected override async Task Send(MimeMessage message, EmailNotificationSettings settings)
{
try
{
@ -274,7 +215,7 @@ namespace Ombi.Services.Notification
}
}
private async Task EmailTest(NotificationModel model, EmailNotificationSettings settings)
protected override async Task EmailTest(NotificationModel model, EmailNotificationSettings settings)
{
var email = new EmailBasicTemplate();
var html = email.LoadTemplate(

@ -144,6 +144,7 @@
<Compile Include="Interfaces\INotification.cs" />
<Compile Include="Interfaces\INotificationService.cs" />
<Compile Include="Models\SonarrCachedResult.cs" />
<Compile Include="Notification\BaseNotification.cs" />
<Compile Include="Notification\EmailMessageNotification.cs" />
<Compile Include="Notification\EmbyNotificationEngine.cs" />
<Compile Include="Notification\PlexNotificationEngine.cs" />

@ -112,7 +112,7 @@ namespace Ombi.UI.Modules.Admin
vm.DbLocation = SqlConfig.CurrentPath;
vm.ApplicationVersion = AssemblyHelper.GetFileVersion();
vm.Branch = EnumHelper<Branches>.GetDisplayValue(systemSettings.Branch);
vm.Branch = EnumHelper<Branches>.GetBranchValue<BranchAttribute>(systemSettings.Branch).DisplayName;
vm.LogLevel = LogManager.Configuration.LoggingRules.FirstOrDefault(x => x.NameMatches("database"))?.Levels?.FirstOrDefault()?.Name ?? "Unknown";
return vm;

@ -142,7 +142,7 @@ namespace Ombi.UI.Modules.Admin
var settings = this.Bind<SystemSettings>();
Analytics.TrackEventAsync(Category.Admin, Action.Update, $"Updated Branch {EnumHelper<Branches>.GetDisplayValue(settings.Branch)}", Username, CookieHelper.GetAnalyticClientId(Cookies));
Analytics.TrackEventAsync(Category.Admin, Action.Update, $"Updated Branch {EnumHelper<Branches>.GetBranchValue<BranchAttribute>(settings.Branch).DisplayName}", Username, CookieHelper.GetAnalyticClientId(Cookies));
await SystemSettings.SaveSettingsAsync(settings);
// Clear the cache

Loading…
Cancel
Save