From ec8579c30d993140e18d9471659e51ff1dee3dbf Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 3 Aug 2020 19:01:39 +0000 Subject: [PATCH] --- .vscode/launch.json | 2 +- server/AyaNova/generator/CoreJobNotify.cs | 52 ++++++++++++++--------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 69b973c3..9efe9077 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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\\" diff --git a/server/AyaNova/generator/CoreJobNotify.cs b/server/AyaNova/generator/CoreJobNotify.cs index d6893d4d..97783226 100644 --- a/server/AyaNova/generator/CoreJobNotify.cs +++ b/server/AyaNova/generator/CoreJobNotify.cs @@ -37,7 +37,8 @@ namespace AyaNova.Biz #endif //temporary list to hold translations as required during delivery - private static Dictionary> _transCache = new Dictionary>(); + private static Dictionary> _NotifyEventTypeTransCache = new Dictionary>(); + private static Dictionary> _AyaTypeTypeTransCache = new Dictionary>(); private static Dictionary _UserTranslationIdCache = new Dictionary(); private static Dictionary _ServerTheWordTranslations = new Dictionary(); @@ -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 {