This commit is contained in:
@@ -8,6 +8,7 @@ using AyaNova.Models;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Biz;
|
||||
using AyaNova.Util;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace AyaNova.Api.Controllers
|
||||
@@ -48,17 +49,54 @@ namespace AyaNova.Api.Controllers
|
||||
/// <param name="enumkey">The key name of the enumerated type</param>
|
||||
/// <returns>List</returns>
|
||||
[HttpGet("list/{enumkey}")]
|
||||
public ActionResult GetList([FromRoute] string enumkey)
|
||||
public async Task<IActionResult> GetList([FromRoute] string enumkey)
|
||||
{
|
||||
if (serverState.IsClosed)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
|
||||
long TranslationId = UserTranslationIdFromContext.Id(HttpContext.Items);
|
||||
|
||||
var ret = await GetEnumList(enumkey, TranslationId);
|
||||
|
||||
return Ok(ApiOkResponse.Response(ret));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get all possible enumerated values list key names
|
||||
/// </summary>
|
||||
/// <returns>List of AyaNova enumerated type list key names that can be fetched from the GetList Route</returns>
|
||||
[HttpGet("listkeys")]
|
||||
public ActionResult GetTypesList()
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
|
||||
List<KeyValuePair<string, string>> ret = new List<KeyValuePair<string, string>>();
|
||||
ret.Add(new KeyValuePair<string, string>(StringUtil.TrimTypeName(typeof(UserType).ToString()), "AyaNova user account types"));
|
||||
ret.Add(new KeyValuePair<string, string>(StringUtil.TrimTypeName(typeof(AuthorizationRoles).ToString()), "AyaNova user account role types"));
|
||||
ret.Add(new KeyValuePair<string, string>(StringUtil.TrimTypeName(typeof(AyaType).ToString()), "All AyaNova object types"));
|
||||
ret.Add(new KeyValuePair<string, string>("Core", "All Core AyaNova business object types"));
|
||||
ret.Add(new KeyValuePair<string, string>(StringUtil.TrimTypeName(typeof(UiFieldDataType).ToString()), "Types of data used in AyaNova for display and formatting UI purposes"));
|
||||
ret.Add(new KeyValuePair<string, string>(StringUtil.TrimTypeName(typeof(NotifyEventType).ToString()), "Notification event types"));
|
||||
ret.Add(new KeyValuePair<string, string>(StringUtil.TrimTypeName(typeof(NotifyDeliveryMethod).ToString()), "Notification delivery methods"));
|
||||
ret.Add(new KeyValuePair<string, string>(StringUtil.TrimTypeName(typeof(NotifyMailSecurity).ToString()), "Notification SMTP mail server security method"));
|
||||
|
||||
return Ok(ApiOkResponse.Response(ret));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static async Task<List<NameIdItem>> GetEnumList(string enumKey, long translationId)
|
||||
{
|
||||
|
||||
List<string> TranslationKeysToFetch = new List<string>();
|
||||
|
||||
List<NameIdItem> ReturnList = new List<NameIdItem>();
|
||||
|
||||
var keyNameInLowerCase = enumkey.ToLowerInvariant();
|
||||
var keyNameInLowerCase = enumKey.ToLowerInvariant();
|
||||
|
||||
|
||||
if (keyNameInLowerCase == StringUtil.TrimTypeName(typeof(UiFieldDataType).ToString()).ToLowerInvariant())
|
||||
@@ -83,7 +121,7 @@ namespace AyaNova.Api.Controllers
|
||||
TranslationKeysToFetch.Add(t.ToString());
|
||||
}
|
||||
}
|
||||
var LT = TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, TranslationId).Result;
|
||||
var LT = await TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, translationId);
|
||||
|
||||
foreach (AyaType t in values)
|
||||
{
|
||||
@@ -112,7 +150,7 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
foreach (AyaType t in values)
|
||||
TranslationKeysToFetch.Add(t.ToString());
|
||||
var LT = TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, TranslationId).Result;
|
||||
var LT = await TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, translationId);
|
||||
|
||||
foreach (AyaType t in values)
|
||||
{
|
||||
@@ -138,7 +176,7 @@ namespace AyaNova.Api.Controllers
|
||||
TranslationKeysToFetch.Add("UserTypeHeadOffice");
|
||||
TranslationKeysToFetch.Add("UserTypeServiceContractor");
|
||||
TranslationKeysToFetch.Add("UserTypeUtility");
|
||||
var LT = TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, TranslationId).Result;
|
||||
var LT = await TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, translationId);
|
||||
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["UserTypeAdministrator"], Id = (long)UserType.Administrator });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["UserTypeService"], Id = (long)UserType.Service });
|
||||
@@ -165,7 +203,7 @@ namespace AyaNova.Api.Controllers
|
||||
TranslationKeysToFetch.Add("AdminEraseDatabase");
|
||||
TranslationKeysToFetch.Add("EventResetSerial");
|
||||
TranslationKeysToFetch.Add("EventUtilityFileDownload");
|
||||
var LT = TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, TranslationId).Result;
|
||||
var LT = await TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, translationId);
|
||||
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["EventDeleted"], Id = (long)AyaEvent.Deleted });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["EventCreated"], Id = (long)AyaEvent.Created });
|
||||
@@ -205,7 +243,7 @@ namespace AyaNova.Api.Controllers
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleSalesLimited");
|
||||
TranslationKeysToFetch.Add("AuthorizationRoleSalesFull");
|
||||
// TranslationKeysToFetch.Add("AuthorizationRoleAll");
|
||||
var LT = TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, TranslationId).Result;
|
||||
var LT = await TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, translationId);
|
||||
|
||||
// ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleNoRole"], Id = (long)AuthorizationRoles.NoRole });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["AuthorizationRoleBizAdminLimited"], Id = (long)AuthorizationRoles.BizAdminLimited });
|
||||
@@ -259,7 +297,7 @@ namespace AyaNova.Api.Controllers
|
||||
TranslationKeysToFetch.Add("NotifyEventUnitMeterReadingMultipleExceeded");
|
||||
TranslationKeysToFetch.Add("NotifyEventServerOperationsProblem");
|
||||
|
||||
var LT = TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, TranslationId).Result;
|
||||
var LT = await TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, translationId);
|
||||
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["NotifyEventObjectDeleted"], Id = (long)NotifyEventType.ObjectDeleted });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["NotifyEventObjectCreated"], Id = (long)NotifyEventType.ObjectCreated });
|
||||
@@ -296,7 +334,7 @@ namespace AyaNova.Api.Controllers
|
||||
TranslationKeysToFetch.Add("NotifyDeliveryMethodApp");
|
||||
TranslationKeysToFetch.Add("NotifyDeliveryMethodSMTP");
|
||||
|
||||
var LT = TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, TranslationId).Result;
|
||||
var LT = await TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, translationId);
|
||||
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["NotifyDeliveryMethodApp"], Id = (long)NotifyDeliveryMethod.App });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["NotifyDeliveryMethodSMTP"], Id = (long)NotifyDeliveryMethod.SMTP });
|
||||
@@ -307,7 +345,7 @@ namespace AyaNova.Api.Controllers
|
||||
TranslationKeysToFetch.Add("NotifyMailSecuritySSLTLS");
|
||||
TranslationKeysToFetch.Add("NotifyMailSecurityStartTls");
|
||||
|
||||
var LT = TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, TranslationId).Result;
|
||||
var LT = await TranslationBiz.GetSubsetStaticAsync(TranslationKeysToFetch, translationId);
|
||||
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["NotifyMailSecurityNone"], Id = (long)NotifyMailSecurity.None });
|
||||
ReturnList.Add(new NameIdItem() { Name = LT["NotifyMailSecuritySSLTLS"], Id = (long)NotifyMailSecurity.SSLTLS });
|
||||
@@ -315,42 +353,13 @@ namespace AyaNova.Api.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
ReturnList.Add(new NameIdItem() { Name = $"Unknown enum type list key value {enumkey}", Id = (long)UserType.Administrator });
|
||||
ReturnList.Add(new NameIdItem() { Name = $"Unknown enum type list key value {enumKey}", Id = (long)UserType.Administrator });
|
||||
}
|
||||
|
||||
return ReturnList;
|
||||
|
||||
|
||||
return Ok(ApiOkResponse.Response(ReturnList));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get all possible enumerated values list key names
|
||||
/// </summary>
|
||||
/// <returns>List of AyaNova enumerated type list key names that can be fetched from the GetList Route</returns>
|
||||
[HttpGet("listkeys")]
|
||||
public ActionResult GetTypesList()
|
||||
{
|
||||
if (!serverState.IsOpen)
|
||||
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||
|
||||
List<KeyValuePair<string, string>> ret = new List<KeyValuePair<string, string>>();
|
||||
ret.Add(new KeyValuePair<string, string>(StringUtil.TrimTypeName(typeof(UserType).ToString()), "AyaNova user account types"));
|
||||
ret.Add(new KeyValuePair<string, string>(StringUtil.TrimTypeName(typeof(AuthorizationRoles).ToString()), "AyaNova user account role types"));
|
||||
ret.Add(new KeyValuePair<string, string>(StringUtil.TrimTypeName(typeof(AyaType).ToString()), "All AyaNova object types"));
|
||||
ret.Add(new KeyValuePair<string, string>("Core", "All Core AyaNova business object types"));
|
||||
ret.Add(new KeyValuePair<string, string>(StringUtil.TrimTypeName(typeof(UiFieldDataType).ToString()), "Types of data used in AyaNova for display and formatting UI purposes"));
|
||||
ret.Add(new KeyValuePair<string, string>(StringUtil.TrimTypeName(typeof(NotifyEventType).ToString()), "Notification event types"));
|
||||
ret.Add(new KeyValuePair<string, string>(StringUtil.TrimTypeName(typeof(NotifyDeliveryMethod).ToString()), "Notification delivery methods"));
|
||||
ret.Add(new KeyValuePair<string, string>(StringUtil.TrimTypeName(typeof(NotifyMailSecurity).ToString()), "Notification SMTP mail server security method"));
|
||||
|
||||
return Ok(ApiOkResponse.Response(ret));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}//eoc
|
||||
}//ens
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -33,6 +34,10 @@ namespace AyaNova.Biz
|
||||
private static TimeSpan DELETE_AFTER_AGE = new TimeSpan(90, 0, 0, 0);
|
||||
private static TimeSpan RUN_EVERY_INTERVAL = new TimeSpan(0, 2, 0);//no more frequently than once every 2 minutes
|
||||
#endif
|
||||
|
||||
//temporary list to hold translations as required during delivery
|
||||
private static Dictionary<long, List<NameIdItem>> _transCache = new Dictionary<long, List<NameIdItem>>();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// DoSweep
|
||||
//
|
||||
@@ -150,6 +155,14 @@ namespace AyaNova.Biz
|
||||
|
||||
}
|
||||
|
||||
//cache any translations required for email notification
|
||||
private static async Task CacheNotifyEventTypeTranslations(long translationId){
|
||||
if(_transCache.ContainsKey(translationId)){
|
||||
return;
|
||||
}
|
||||
_transCache.Add(translationId,AyaNova.Api.Controllers.EnumListController.GetEnumList("NotifyEventType",translationId));
|
||||
}
|
||||
|
||||
private static async Task DeliverInApp(NotifyEvent ne, AyContext ct)
|
||||
{
|
||||
log.LogTrace($"DeliverInApp deliving notify event: {ne}");
|
||||
@@ -158,10 +171,23 @@ namespace AyaNova.Biz
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private static async Task DeliverSMTP(NotifyEvent ne, AyContext ct)
|
||||
private static async Task DeliverSMTP(NotifyEvent ne, string toAddress, AyContext ct)
|
||||
{
|
||||
log.LogTrace($"DeliverSMTP deliving notify event: {ne}");
|
||||
|
||||
var subject = $"Notification: {ne.EventType.ToString()}";
|
||||
|
||||
IMailer m = AyaNova.Util.ServiceProviderProvider.Mailer;
|
||||
try
|
||||
{
|
||||
await m.SendEmailAsync(toAddress, subject, "This is a test to confirm notification system is working", ServerGlobalOpsSettingsCache.Notify);
|
||||
return "ok";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ExceptionUtil.ExtractAllExceptionMessages(ex);
|
||||
}
|
||||
|
||||
//todo: //Open question: what to do with failed deliveries?
|
||||
//we dont' want them piling up but we don't want to just dump them do we?
|
||||
//it should be only mail ones that fail, not app ones, there's no way for an app delivery to fail as it's just put in a table
|
||||
|
||||
@@ -19,12 +19,23 @@ namespace AyaNova.Models
|
||||
{
|
||||
SmtpDeliveryActive = true;
|
||||
Id = 1;
|
||||
SmtpServerAddress="mail.example.com";
|
||||
|
||||
#if (DEBUG)
|
||||
SmtpServerAddress = "mail.ayanova.com";
|
||||
SmtpAccount = "support@ayanova.com";
|
||||
SmtpPassword = "e527b6c5a00c27bb61ca694b3de0ee178cbe3f1541a772774762ed48e9caf5ce";
|
||||
ConnectionSecurity = NotifyMailSecurity.StartTls;
|
||||
SmtpServerPort = 465;
|
||||
NotifyFromAddress = "support@ayanova.com";
|
||||
#else
|
||||
SmtpServerAddress="mail.example.com";
|
||||
SmtpAccount="notifydeliverfromaccount@example.com";
|
||||
SmtpPassword="examplepassword";
|
||||
ConnectionSecurity= NotifyMailSecurity.SSLTLS;
|
||||
SmtpServerPort=587;
|
||||
NotifyFromAddress="noreply@example.com";
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user