mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-11 07:46:05 -07:00
Fixed the way we will be using custom messages
This commit is contained in:
parent
8953d4eaa8
commit
fea4dd6309
9 changed files with 223 additions and 115 deletions
|
@ -24,94 +24,36 @@
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
using PlexRequests.Core.Models;
|
|
||||||
using PlexRequests.Core.SettingModels;
|
using PlexRequests.Core.SettingModels;
|
||||||
|
|
||||||
namespace PlexRequests.Core.Tests
|
namespace PlexRequests.Core.Tests
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class NotificationMessageResolverTests
|
public class AuthenticationSettingsTests
|
||||||
{
|
{
|
||||||
[TestCaseSource(nameof(MessageResolver))]
|
[Test, TestCaseSource(nameof(UserData))]
|
||||||
[Ignore("WIP")]
|
public void DeniedUserListTest(string users, string[] expected)
|
||||||
public NotificationMessageResolution Resolve(Dictionary<NotificationType, string> body, Dictionary<string,string> param)
|
|
||||||
{
|
{
|
||||||
var n = new NotificationMessageResolver();
|
var model = new AuthenticationSettings { DeniedUsers = users };
|
||||||
var s = new NotificationSettings
|
|
||||||
|
var result = model.DeniedUserList;
|
||||||
|
|
||||||
|
Assert.That(result.Count, Is.EqualTo(expected.Length));
|
||||||
|
for (var i = 0; i < expected.Length; i++)
|
||||||
{
|
{
|
||||||
Message = body,
|
Assert.That(result[i], Is.EqualTo(expected[i]));
|
||||||
CustomParamaters = param
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static readonly object[] UserData =
|
||||||
|
{
|
||||||
|
new object[] { "john", new [] {"john"} },
|
||||||
|
new object[] { "john , abc ,", new [] {"john", "abc"} },
|
||||||
|
new object[] { "john,, cde", new [] {"john", "cde"} },
|
||||||
|
new object[] { "john,,, aaa , baaa , ", new [] {"john","aaa","baaa"} },
|
||||||
|
new object[] { "john, aaa , baaa , maaa, caaa", new [] {"john","aaa","baaa", "maaa", "caaa"} },
|
||||||
};
|
};
|
||||||
|
|
||||||
return n.ParseMessage(s, NotificationType.NewRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IEnumerable<TestCaseData> MessageResolver
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
yield return new TestCaseData(
|
|
||||||
new Dictionary<NotificationType, string> { { NotificationType.NewRequest, "There has been a new request from {Username}, Title: {Title} for {Type}" } },
|
|
||||||
new Dictionary<string, string>{{"Username", "Jamie" },{"Title", "Finding Dory" },{"Type", "Movie" }})
|
|
||||||
.Returns("There has been a new request from Jamie, Title: Finding Dory for Movie")
|
|
||||||
.SetName("FindingDory");
|
|
||||||
|
|
||||||
yield return new TestCaseData(
|
|
||||||
new Dictionary<NotificationType, string> { { NotificationType.NewRequest, string.Empty } },
|
|
||||||
new Dictionary<string, string>())
|
|
||||||
.Returns(string.Empty)
|
|
||||||
.SetName("Empty Message");
|
|
||||||
|
|
||||||
yield return new TestCaseData(
|
|
||||||
new Dictionary<NotificationType, string> { { NotificationType.NewRequest, "{{Wowwzer}} Damn}{{son}}}}" } },
|
|
||||||
new Dictionary<string, string> { {"son","HEY!"} })
|
|
||||||
.Returns("{{Wowwzer}} Damn}{HEY!}}}")
|
|
||||||
.SetName("Multiple Curlys");
|
|
||||||
|
|
||||||
|
|
||||||
yield return new TestCaseData(
|
|
||||||
new Dictionary<NotificationType, string> { { NotificationType.NewRequest, "This is a message with no curlys" } },
|
|
||||||
new Dictionary<string, string> { { "son", "HEY!" } })
|
|
||||||
.Returns("This is a message with no curlys")
|
|
||||||
.SetName("No Curlys");
|
|
||||||
|
|
||||||
yield return new TestCaseData(
|
|
||||||
new Dictionary<NotificationType, string> { { NotificationType.NewRequest, new string(')', 5000)} },
|
|
||||||
new Dictionary<string, string> { { "son", "HEY!" } })
|
|
||||||
.Returns(new string(')', 5000))
|
|
||||||
.SetName("Long String");
|
|
||||||
|
|
||||||
|
|
||||||
yield return new TestCaseData(
|
|
||||||
new Dictionary<NotificationType, string> { { NotificationType.NewRequest, "This is a {Username} and {Username} Because {Curly}{Curly}" } },
|
|
||||||
new Dictionary<string, string> { { "Username", "HEY!" }, {"Curly","Bob"} })
|
|
||||||
.Returns("This is a HEY! and HEY! Because BobBob")
|
|
||||||
.SetName("Double Curly");
|
|
||||||
|
|
||||||
yield return new TestCaseData(
|
|
||||||
new Dictionary<NotificationType, string> { { NotificationType.NewRequest, "This is a {Username} and {Username} Because {Curly}{Curly}" } },
|
|
||||||
new Dictionary<string, string> { { "username", "HEY!" }, { "Curly", "Bob" } })
|
|
||||||
.Returns("This is a {Username} and {Username} Because BobBob")
|
|
||||||
.SetName("Case sensitive");
|
|
||||||
|
|
||||||
yield return new TestCaseData(
|
|
||||||
new Dictionary<NotificationType, string> { { NotificationType.NewRequest, "{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}{a}" } },
|
|
||||||
new Dictionary<string, string> { { "a", "b" } })
|
|
||||||
.Returns("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
|
|
||||||
.SetName("Lots of curlys");
|
|
||||||
|
|
||||||
yield return new TestCaseData(
|
|
||||||
new Dictionary<NotificationType, string> { { NotificationType.NewRequest, $"{{{new string('b', 10000)}}}" } },
|
|
||||||
new Dictionary<string, string> { { new string('b', 10000), "Hello" } })
|
|
||||||
.Returns("Hello")
|
|
||||||
.SetName("Very long Curly");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,36 +24,123 @@
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
using PlexRequests.Core.Models;
|
||||||
using PlexRequests.Core.SettingModels;
|
using PlexRequests.Core.SettingModels;
|
||||||
|
|
||||||
namespace PlexRequests.Core.Tests
|
namespace PlexRequests.Core.Tests
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class AuthenticationSettingsTests
|
public class NotificationMessageResolverTests
|
||||||
{
|
{
|
||||||
[Test, TestCaseSource(nameof(UserData))]
|
[TestCaseSource(nameof(MessageBodyResolver))]
|
||||||
public void DeniedUserListTest(string users, string[] expected)
|
public string ResolveBody(string body, NotificationMessageCurlys param)
|
||||||
{
|
{
|
||||||
var model = new AuthenticationSettings { DeniedUsers = users };
|
var n = new NotificationMessageResolver();
|
||||||
|
var s = new NotificationSettings
|
||||||
var result = model.DeniedUserList;
|
|
||||||
|
|
||||||
Assert.That(result.Count, Is.EqualTo(expected.Length));
|
|
||||||
for (var i = 0; i < expected.Length; i++)
|
|
||||||
{
|
{
|
||||||
Assert.That(result[i], Is.EqualTo(expected[i]));
|
Message = new Dictionary<NotificationType, NotificationMessageContent> { { NotificationType.NewRequest, new NotificationMessageContent { Body = body } } }
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static readonly object[] UserData =
|
|
||||||
{
|
|
||||||
new object[] { "john", new [] {"john"} },
|
|
||||||
new object[] { "john , abc ,", new [] {"john", "abc"} },
|
|
||||||
new object[] { "john,, cde", new [] {"john", "cde"} },
|
|
||||||
new object[] { "john,,, aaa , baaa , ", new [] {"john","aaa","baaa"} },
|
|
||||||
new object[] { "john, aaa , baaa , maaa, caaa", new [] {"john","aaa","baaa", "maaa", "caaa"} },
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var result = n.ParseMessage(s, NotificationType.NewRequest, param);
|
||||||
|
return result.Body;
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCaseSource(nameof(MessageSubjectResolver))]
|
||||||
|
public string ResolveSubject(string subject, NotificationMessageCurlys param)
|
||||||
|
{
|
||||||
|
var n = new NotificationMessageResolver();
|
||||||
|
var s = new NotificationSettings
|
||||||
|
{
|
||||||
|
Message = new Dictionary<NotificationType, NotificationMessageContent> { { NotificationType.NewRequest, new NotificationMessageContent {Subject = subject} } }
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = n.ParseMessage(s, NotificationType.NewRequest, param);
|
||||||
|
return result.Subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<TestCaseData> MessageSubjectResolver
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
yield return new TestCaseData(
|
||||||
|
"{Username} has requested a {Type}",
|
||||||
|
new NotificationMessageCurlys("Jamie", "Finding Dory", DateTime.Now.ToString(), "Movie", string.Empty))
|
||||||
|
.Returns("Jamie has requested a Movie").SetName("Subject Curlys");
|
||||||
|
|
||||||
|
yield return new TestCaseData(
|
||||||
|
null,
|
||||||
|
new NotificationMessageCurlys("Jamie", "Finding Dory", DateTime.Now.ToString(), "Movie", string.Empty))
|
||||||
|
.Returns(string.Empty).SetName("Empty Subject");
|
||||||
|
|
||||||
|
yield return new TestCaseData(
|
||||||
|
"New Request Incoming!",
|
||||||
|
new NotificationMessageCurlys("Jamie", "Finding Dory", DateTime.Now.ToString(), "Movie", string.Empty))
|
||||||
|
.Returns("New Request Incoming!").SetName("No curlys");
|
||||||
|
|
||||||
|
yield return new TestCaseData(
|
||||||
|
"%$R£%$£^%$&{Username}@{}:§",
|
||||||
|
new NotificationMessageCurlys("Jamie", "Finding Dory", DateTime.Now.ToString(), "Movie", string.Empty))
|
||||||
|
.Returns("%$R£%$£^%$&Jamie@{}:§").SetName("Special Chars");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static IEnumerable<TestCaseData> MessageBodyResolver
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
yield return new TestCaseData(
|
||||||
|
"There has been a new request from {Username}, Title: {Title} for {Type}",
|
||||||
|
new NotificationMessageCurlys("Jamie", "Finding Dory", DateTime.Now.ToString(), "Movie", string.Empty))
|
||||||
|
.Returns("There has been a new request from Jamie, Title: Finding Dory for Movie").SetName("FindingDory");
|
||||||
|
|
||||||
|
yield return new TestCaseData(
|
||||||
|
null,
|
||||||
|
new NotificationMessageCurlys(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty))
|
||||||
|
.Returns(string.Empty)
|
||||||
|
.SetName("Empty Message");
|
||||||
|
|
||||||
|
yield return new TestCaseData(
|
||||||
|
"{{Wowwzer}} Damn}{{Username}}}}",
|
||||||
|
new NotificationMessageCurlys("HEY!", string.Empty, string.Empty, string.Empty, string.Empty))
|
||||||
|
.Returns("{{Wowwzer}} Damn}{HEY!}}}")
|
||||||
|
.SetName("Multiple Curlys");
|
||||||
|
|
||||||
|
|
||||||
|
yield return new TestCaseData(
|
||||||
|
"This is a message with no curlys",
|
||||||
|
new NotificationMessageCurlys("Jamie", "Finding Dory", DateTime.Now.ToString(), "Movie", string.Empty))
|
||||||
|
.Returns("This is a message with no curlys")
|
||||||
|
.SetName("No Curlys");
|
||||||
|
|
||||||
|
yield return new TestCaseData(
|
||||||
|
new string(')', 5000),
|
||||||
|
new NotificationMessageCurlys(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty))
|
||||||
|
.Returns(new string(')', 5000))
|
||||||
|
.SetName("Long String");
|
||||||
|
|
||||||
|
|
||||||
|
yield return new TestCaseData(
|
||||||
|
"This is a {Username} and {Username} Because {Issue}{Issue}",
|
||||||
|
new NotificationMessageCurlys("HEY!", string.Empty, string.Empty, string.Empty, "Bob"))
|
||||||
|
.Returns("This is a HEY! and HEY! Because BobBob")
|
||||||
|
.SetName("Double Curly");
|
||||||
|
|
||||||
|
yield return new TestCaseData(
|
||||||
|
"This is a {username} and {username} Because {Issue}{Issue}",
|
||||||
|
new NotificationMessageCurlys("HEY!", string.Empty, string.Empty, string.Empty, "Bob"))
|
||||||
|
.Returns("This is a {username} and {username} Because BobBob")
|
||||||
|
.SetName("Case sensitive");
|
||||||
|
|
||||||
|
yield return new TestCaseData(
|
||||||
|
"{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}{Date}",
|
||||||
|
new NotificationMessageCurlys("HEY!", string.Empty, "b", string.Empty, "Bob"))
|
||||||
|
.Returns("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
|
||||||
|
.SetName("Lots of curlys");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -59,9 +59,9 @@
|
||||||
<Otherwise />
|
<Otherwise />
|
||||||
</Choose>
|
</Choose>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="NotificationMessageResolverTests.cs" />
|
|
||||||
<Compile Include="StatusCheckerTests.cs" />
|
|
||||||
<Compile Include="AuthenticationSettingsTests.cs" />
|
<Compile Include="AuthenticationSettingsTests.cs" />
|
||||||
|
<Compile Include="StatusCheckerTests.cs" />
|
||||||
|
<Compile Include="NotificationMessageResolverTests.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#region Copyright
|
#region Copyright
|
||||||
// /************************************************************************
|
// /************************************************************************
|
||||||
// Copyright (c) 2016 Jamie Rees
|
// Copyright (c) 2016 Jamie Rees
|
||||||
// File: NotificationMessageResolution.cs
|
// File: NotificationMessageContent.cs
|
||||||
// Created By: Jamie Rees
|
// Created By: Jamie Rees
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
#endregion
|
#endregion
|
||||||
namespace PlexRequests.Core
|
namespace PlexRequests.Core
|
||||||
{
|
{
|
||||||
public class NotificationMessageResolution
|
public class NotificationMessageContent
|
||||||
{
|
{
|
||||||
public string Subject { get; set; }
|
public string Subject { get; set; }
|
||||||
public string Body { get; set; }
|
public string Body { get; set; }
|
57
PlexRequests.Core/NotificationMessageCurlys.cs
Normal file
57
PlexRequests.Core/NotificationMessageCurlys.cs
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
#region Copyright
|
||||||
|
// /************************************************************************
|
||||||
|
// Copyright (c) 2016 Jamie Rees
|
||||||
|
// File: NotificationMessageCurlys.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.Collections.Generic;
|
||||||
|
|
||||||
|
namespace PlexRequests.Core
|
||||||
|
{
|
||||||
|
public class NotificationMessageCurlys
|
||||||
|
{
|
||||||
|
public NotificationMessageCurlys(string username, string title, string dateTime, string type, string issue)
|
||||||
|
{
|
||||||
|
Username = username;
|
||||||
|
Title = title;
|
||||||
|
Date = dateTime;
|
||||||
|
Type = type;
|
||||||
|
Issue = issue;
|
||||||
|
}
|
||||||
|
private string Username { get; }
|
||||||
|
private string Title { get; }
|
||||||
|
private string Date { get; }
|
||||||
|
private string Type { get; }
|
||||||
|
private string Issue { get; }
|
||||||
|
|
||||||
|
public Dictionary<string, string> Curlys => new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{nameof(Username), Username },
|
||||||
|
{nameof(Title), Title },
|
||||||
|
{nameof(Date), Date },
|
||||||
|
{nameof(Type), Type },
|
||||||
|
{nameof(Issue), Issue }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -36,17 +36,17 @@ namespace PlexRequests.Core
|
||||||
{
|
{
|
||||||
private const char StartChar = (char)123;
|
private const char StartChar = (char)123;
|
||||||
private const char EndChar = (char)125;
|
private const char EndChar = (char)125;
|
||||||
public NotificationMessageResolution ParseMessage<T>(T notification, NotificationType type) where T : NotificationSettings
|
public NotificationMessageContent ParseMessage<T>(T notification, NotificationType type, NotificationMessageCurlys c) where T : NotificationSettings
|
||||||
{
|
{
|
||||||
var bodyToParse = notification.Message.FirstOrDefault(x => x.Key == type).Value;
|
var content = notification.Message.FirstOrDefault(x => x.Key == type).Value;
|
||||||
var subjectToParse = notification.Subject.FirstOrDefault(x => x.Key == type).Value;
|
|
||||||
//if (string.IsNullOrEmpty(notificationToParse))
|
//if (string.IsNullOrEmpty(notificationToParse))
|
||||||
// return string.Empty;
|
// return string.Empty;
|
||||||
|
|
||||||
return Resolve(bodyToParse, subjectToParse, notification.CustomParamaters);
|
return Resolve(content.Body, content.Subject, c.Curlys);
|
||||||
}
|
}
|
||||||
|
|
||||||
private NotificationMessageResolution Resolve(string body, string subject, Dictionary<string, string> paramaters)
|
private NotificationMessageContent Resolve(string body, string subject, Dictionary<string, string> paramaters)
|
||||||
{
|
{
|
||||||
|
|
||||||
var bodyFields = FindCurlyFields(body);
|
var bodyFields = FindCurlyFields(body);
|
||||||
|
@ -70,11 +70,15 @@ namespace PlexRequests.Core
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new NotificationMessageResolution { Body = body, Subject = subject };
|
return new NotificationMessageContent { Body = body ?? string.Empty, Subject = subject ?? string.Empty };
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<string> FindCurlyFields(string message)
|
private IEnumerable<string> FindCurlyFields(string message)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(message))
|
||||||
|
{
|
||||||
|
return new List<string>();
|
||||||
|
}
|
||||||
var insideCurly = false;
|
var insideCurly = false;
|
||||||
var fields = new List<string>();
|
var fields = new List<string>();
|
||||||
var currentWord = string.Empty;
|
var currentWord = string.Empty;
|
||||||
|
|
|
@ -71,7 +71,8 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="CacheKeys.cs" />
|
<Compile Include="CacheKeys.cs" />
|
||||||
<Compile Include="NotificationMessageResolution.cs" />
|
<Compile Include="NotificationMessageContent.cs" />
|
||||||
|
<Compile Include="NotificationMessageCurlys.cs" />
|
||||||
<Compile Include="NotificationMessageResolver.cs" />
|
<Compile Include="NotificationMessageResolver.cs" />
|
||||||
<Compile Include="IIssueService.cs" />
|
<Compile Include="IIssueService.cs" />
|
||||||
<Compile Include="IRequestService.cs" />
|
<Compile Include="IRequestService.cs" />
|
||||||
|
|
|
@ -34,18 +34,28 @@ namespace PlexRequests.Core.SettingModels
|
||||||
{
|
{
|
||||||
public NotificationSettings()
|
public NotificationSettings()
|
||||||
{
|
{
|
||||||
CustomParamaters = new Dictionary<string, string>
|
Message = new Dictionary<NotificationType, NotificationMessageContent>
|
||||||
{
|
{
|
||||||
{"Username", string.Empty },
|
{NotificationType.NewRequest, new NotificationMessageContent() },
|
||||||
{"Date", string.Empty },
|
{NotificationType.Issue, new NotificationMessageContent() },
|
||||||
{"Title", string.Empty },
|
{NotificationType.AdminNote, new NotificationMessageContent() },
|
||||||
{"RequestType", string.Empty },
|
{NotificationType.RequestApproved, new NotificationMessageContent() },
|
||||||
{"Issue", string.Empty },
|
{NotificationType.RequestAvailable, new NotificationMessageContent() },
|
||||||
|
{NotificationType.Test, new NotificationMessageContent() },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public Dictionary<NotificationType, string> Message { get; set; }
|
public Dictionary<NotificationType, NotificationMessageContent> Message { get; set; }
|
||||||
public Dictionary<NotificationType, string> Subject { get; set; }
|
}
|
||||||
public Dictionary<string,string> CustomParamaters { get; set; }
|
|
||||||
|
public static class NotificationCurly
|
||||||
|
{
|
||||||
|
public static readonly List<string> Curlys = new List<string>
|
||||||
|
{
|
||||||
|
"Username",
|
||||||
|
"Title",
|
||||||
|
"Date",
|
||||||
|
"Issue",
|
||||||
|
"Type"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -25,6 +25,9 @@
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using MailKit.Security;
|
using MailKit.Security;
|
||||||
|
@ -119,6 +122,10 @@ namespace PlexRequests.Services.Notification
|
||||||
|
|
||||||
private async Task EmailNewRequest(NotificationModel model, EmailNotificationSettings settings)
|
private async Task EmailNewRequest(NotificationModel model, EmailNotificationSettings settings)
|
||||||
{
|
{
|
||||||
|
//var r = new NotificationMessageCurlys(model.User, model.Title, DateTime.Now.ToString(), model.RequestType.ToString(), string.Empty);
|
||||||
|
//var resolver = new NotificationMessageResolver();
|
||||||
|
//var bodyResult = resolver.ParseMessage(settings, NotificationType.NewRequest, r);
|
||||||
|
|
||||||
var message = new MimeMessage
|
var message = new MimeMessage
|
||||||
{
|
{
|
||||||
Body = new TextPart("plain") { Text = $"Hello! The user '{model.User}' has requested the {model.RequestType.GetString()?.ToLower()} '{model.Title}'! Please log in to approve this request. Request Date: {model.DateTime.ToString("f")}" },
|
Body = new TextPart("plain") { Text = $"Hello! The user '{model.User}' has requested the {model.RequestType.GetString()?.ToLower()} '{model.Title}'! Please log in to approve this request. Request Date: {model.DateTime.ToString("f")}" },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue