This commit is contained in:
@@ -181,11 +181,13 @@ namespace AyaNova.Api.Controllers
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
var message = $"{UserNameFromContext.Name(HttpContext.Items)}: \"{notifyDirectMessage.Message}\"";
|
||||
|
||||
foreach (long l in notifyDirectMessage.Users)
|
||||
{
|
||||
if (l != 0)
|
||||
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.GeneralNotification, message, null, l);
|
||||
await NotifyEventProcessor.AddGeneralNotifyEvent(
|
||||
NotifyEventType.GeneralNotification, notifyDirectMessage.Message, UserNameFromContext.Name(HttpContext.Items), null, l
|
||||
);
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
|
||||
@@ -13,8 +13,7 @@ using AyaNova.Models;
|
||||
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
|
||||
//This class handles word breaking, processing keywords and searching for results
|
||||
|
||||
internal static class NotifyEventProcessor
|
||||
{
|
||||
private static ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("NotifyEventProcessor");
|
||||
@@ -34,14 +33,14 @@ namespace AyaNova.Biz
|
||||
else
|
||||
log.LogWarning($"Ops problem notification: \"{message}\"");
|
||||
|
||||
await AddGeneralNotifyEvent(NotifyEventType.ServerOperationsProblem, message);
|
||||
await AddGeneralNotifyEvent(NotifyEventType.ServerOperationsProblem, message,"OPS");
|
||||
}
|
||||
|
||||
|
||||
//This handles general notification events not requiring a decision or tied to an object that are basically just a immediate message to the user
|
||||
//e.g. ops problems, GeneralNotification, NotifyHealthCheck etc
|
||||
//optional user id to send directly to them
|
||||
internal static async Task AddGeneralNotifyEvent(NotifyEventType eventType, string message, Exception except = null, long userId = 0)
|
||||
internal static async Task AddGeneralNotifyEvent(NotifyEventType eventType, string message, string name, Exception except = null, long userId = 0)
|
||||
{
|
||||
log.LogTrace($"AddGeneralNotifyEvent processing: [type:{eventType}, userId:{userId}, message:{message}]");
|
||||
#if (DEBUG)
|
||||
@@ -88,7 +87,12 @@ namespace AyaNova.Biz
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
|
||||
NotifyEvent n = new NotifyEvent() { EventType = eventType, UserId = userId, Message = message, NotifySubscriptionId = defaultsub.Id, Name = UserName };
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
name = UserName;
|
||||
}
|
||||
|
||||
NotifyEvent n = new NotifyEvent() { EventType = eventType, UserId = userId, Message = message, NotifySubscriptionId = defaultsub.Id, Name = name };
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
await ct.SaveChangesAsync();
|
||||
return;
|
||||
@@ -101,9 +105,9 @@ namespace AyaNova.Biz
|
||||
//append exception message if not null
|
||||
if (except != null)
|
||||
message += $"\nException error: {ExceptionUtil.ExtractAllExceptionMessages(except)}";
|
||||
|
||||
|
||||
foreach (var sub in subs)
|
||||
{
|
||||
{
|
||||
//note flag ~SERVER~ means to client to substitute "Server" translation key text instead
|
||||
NotifyEvent n = new NotifyEvent() { EventType = eventType, UserId = sub.UserId, Message = message, NotifySubscriptionId = sub.Id, Name = "~SERVER~" };
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace AyaNova.Biz
|
||||
var msg = $"Error during data backup \"{Result}\"";
|
||||
await JobsBiz.LogJobAsync(Guid.Empty, msg);
|
||||
log.LogError($"BACKUP ERROR: {Result}");
|
||||
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, msg);
|
||||
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, msg,"Backup");
|
||||
}
|
||||
|
||||
//DO FILE BACKUP IF ATTACHMENTS BACKED UP
|
||||
@@ -110,14 +110,14 @@ namespace AyaNova.Biz
|
||||
|
||||
log.LogDebug("Backup completed");
|
||||
var duration=DateTime.Now - dtStartBackup;
|
||||
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, $"Backup ({(OnDemand ? "manual / on demand" : "scheduled")}) completed successfully, duration (h:m:s.ms): {duration.ToString()}, server re-opened");
|
||||
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, $"Backup ({(OnDemand ? "manual / on demand" : "scheduled")}) completed successfully, duration (h:m:s.ms): {duration.ToString()}, server re-opened","Backup");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await JobsBiz.LogJobAsync(Guid.Empty, "Backup failed with errors:");
|
||||
await JobsBiz.LogJobAsync(Guid.Empty, ExceptionUtil.ExtractAllExceptionMessages(ex));
|
||||
log.LogError(ex, "Backup failed");
|
||||
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, "Backup failed", ex);
|
||||
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.BackupStatus, "Backup failed","Backup", ex);
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -73,7 +73,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;
|
||||
}
|
||||
}
|
||||
@@ -206,7 +206,7 @@ namespace AyaNova.Biz
|
||||
log.LogTrace($"DeliverSMTP delivering notify event: {ne}");
|
||||
if (string.IsNullOrWhiteSpace(ne.NotifySubscription.DeliveryAddress))
|
||||
{
|
||||
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.GeneralNotification, $"Error: no email address is set in subscription to deliver email notification for this event:{ne}", 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -233,7 +233,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}", 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 +244,7 @@ namespace AyaNova.Biz
|
||||
catch (Exception ex)
|
||||
{
|
||||
await NotifyEventProcessor.AddOpsProblemEvent("SMTP Notification failed", ex);
|
||||
await NotifyEventProcessor.AddGeneralNotifyEvent(NotifyEventType.GeneralNotification, $"Error: an error prevented delivering the following notification via email. System operator users have been notified:{ne}", 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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user