This commit is contained in:
2020-08-03 19:01:39 +00:00
parent 56a278f3a8
commit ec8579c30d
2 changed files with 34 additions and 20 deletions

2
.vscode/launch.json vendored
View File

@@ -51,7 +51,7 @@
"AYANOVA_USE_URLS": "http://*:7575;",
"AYANOVA_FOLDER_USER_FILES": "c:\\temp\\RavenTestData\\userfiles",
"AYANOVA_FOLDER_BACKUP_FILES": "c:\\temp\\RavenTestData\\backupfiles",
"AYANOVA_SERVER_TEST_MODE":"true",
"AYANOVA_SERVER_TEST_MODE":"false",
"AYANOVA_SERVER_TEST_MODE_SEEDLEVEL":"small",
"AYANOVA_SERVER_TEST_MODE_TZ_OFFSET":"-7",
"AYANOVA_BACKUP_PG_DUMP_PATH":"C:\\data\\code\\PostgreSQLPortable_12.0\\App\\PgSQL\\bin\\"

View File

@@ -37,7 +37,8 @@ namespace AyaNova.Biz
#endif
//temporary list to hold translations as required during delivery
private static Dictionary<long, List<NameIdItem>> _transCache = new Dictionary<long, List<NameIdItem>>();
private static Dictionary<long, List<NameIdItem>> _NotifyEventTypeTransCache = new Dictionary<long, List<NameIdItem>>();
private static Dictionary<long, List<NameIdItem>> _AyaTypeTypeTransCache = new Dictionary<long, List<NameIdItem>>();
private static Dictionary<long, long> _UserTranslationIdCache = new Dictionary<long, long>();
private static Dictionary<long, string> _ServerTheWordTranslations = new Dictionary<long, string>();
@@ -73,7 +74,7 @@ namespace AyaNova.Biz
if (dtNowLocal.Hour > 6 && dtNowLocal.Hour < 10)
{
log.LogTrace("Notify health check submitted to subscribers");
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.NotifyHealthCheck, "OK","");
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.NotifyHealthCheck, "OK", "");
lastNotifyHealthCheckSentLocal = dtNowLocal;
}
}
@@ -116,7 +117,7 @@ namespace AyaNova.Biz
{
long transId = (await ct.UserOptions.SingleAsync(z => z.UserId == userid)).TranslationId;
_UserTranslationIdCache.Add(userid, transId);
await CacheNotifyEventTypeTranslations(transId);
await CacheTranslations(transId);
}
//cache all translations of the word "Server" for server notifications
_ServerTheWordTranslations = await TranslationBiz.GetAllTranslationsForKey("Server");
@@ -167,7 +168,8 @@ namespace AyaNova.Biz
{
log.LogTrace("Notify is done setting to not running state and tagging lastRun timestamp");
_UserTranslationIdCache.Clear();
_transCache.Clear();
_NotifyEventTypeTransCache.Clear();
_AyaTypeTypeTransCache.Clear();
lastRun = DateTime.UtcNow;
NotifyIsRunning = false;
@@ -176,19 +178,25 @@ namespace AyaNova.Biz
}
//cache any translations required for email notification
private static async Task CacheNotifyEventTypeTranslations(long translationId)
private static async Task CacheTranslations(long translationId)
{
if (_transCache.ContainsKey(translationId))
{
return;
}
_transCache.Add(translationId, await AyaNova.Api.Controllers.EnumListController.GetEnumList("NotifyEventType", translationId));
if (!_NotifyEventTypeTransCache.ContainsKey(translationId))
_NotifyEventTypeTransCache.Add(translationId, await AyaNova.Api.Controllers.EnumListController.GetEnumList("NotifyEventType", translationId));
if (!_AyaTypeTypeTransCache.ContainsKey(translationId))
_AyaTypeTypeTransCache.Add(translationId, await AyaNova.Api.Controllers.EnumListController.GetEnumList("AyaType", translationId));
}
//Used for subject of email and message deliveries
private static string GetTranslatedNotifyEventName(NotifyEventType net, long translationId)
{
return _transCache.First(z => z.Key == translationId).Value.First(z => z.Id == (int)net).Name;
return _NotifyEventTypeTransCache.First(z => z.Key == translationId).Value.First(z => z.Id == (int)net).Name;
}
private static string GetTranslatedAyaTypeName(AyaType at, long translationId)
{
return _AyaTypeTypeTransCache.First(z => z.Key == translationId).Value.First(z => z.Id == (int)at).Name;
}
private static async Task DeliverInApp(NotifyEvent ne, AyContext ct)
@@ -205,19 +213,25 @@ namespace AyaNova.Biz
{
log.LogTrace($"DeliverSMTP delivering notify event: {ne}");
if (string.IsNullOrWhiteSpace(ne.NotifySubscription.DeliveryAddress))
{
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.GeneralNotification, $"No email address is set in subscription to deliver email notification for this event:{ne}","Error", null, ne.UserId);
}
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.GeneralNotification, $"No email address is set in subscription to deliver email notification for this event:{ne}", "Error", null, ne.UserId);
var transid = _UserTranslationIdCache[ne.NotifySubscription.UserId];
var name = ne.Name;
if (name == "~SERVER~")
{
name = _ServerTheWordTranslations.First(z => z.Key == transid).Value;
}
var subject = $"AY:{GetTranslatedNotifyEventName(ne.EventType, transid)}:{name}";
//AyaType translation
var AyaTypeTranslated = string.Empty;
if (ne.AyaType != AyaType.NoType)
AyaTypeTranslated = $":{GetTranslatedAyaTypeName(ne.AyaType, transid)}";
var subject = $"AY{AyaTypeTranslated}:{GetTranslatedNotifyEventName(ne.EventType, transid)}:{name}";
IMailer m = AyaNova.Util.ServiceProviderProvider.Mailer;
try
@@ -233,7 +247,7 @@ namespace AyaNova.Biz
if (!ServerGlobalOpsSettingsCache.Notify.SmtpDeliveryActive)
{
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.GeneralNotification, $"Email notifications are set to OFF at server, unable to send email notification for this event:{ne}","Error", null, ne.UserId);
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.GeneralNotification, $"Email notifications are set to OFF at server, unable to send email notification for this event:{ne}", "Error", null, ne.UserId);
log.LogInformation($"** WARNING: SMTP notification is currently set to Active=False; unable to deliver email notification, re-routed to in-app notification instead [UserId={ne.UserId}, Notify subscription={ne.NotifySubscriptionId}]. Change this setting or have users remove email delivery notifications if this is permanent **");
}
else
@@ -244,7 +258,7 @@ namespace AyaNova.Biz
catch (Exception ex)
{
await NotifyEventProcessor.AddOpsProblemEvent("SMTP Notification failed", ex);
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.GeneralNotification, $"An error prevented delivering the following notification via email. System operator users have been notified:{ne}","Error", null, ne.UserId);
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.GeneralNotification, $"An error prevented delivering the following notification via email. System operator users have been notified:{ne}", "Error", null, ne.UserId);
}
finally
{