using System; using System.Linq; using System.Globalization; using System.Text; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.EntityFrameworkCore; using AyaNova.Util; using AyaNova.Models; //using System.Diagnostics; namespace AyaNova.Biz { //This class handles word breaking, processing keywords and searching for results public static class NotifyEventProcessor { private static ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("NotifyEventProcessor"); //Add operations message public static async Task AddOpsProblemEvent(string message, Exception ex = null) { if (string.IsNullOrWhiteSpace(message) && ex == null) return; //Log as a backup in case there is no one to notify and also for the record and support if (ex != null) { log.LogError(ex, $"Ops problem notification: \"{message}\""); message += $"\nException error: {ExceptionUtil.ExtractAllExceptionMessages(ex)}"; } else log.LogWarning($"Ops problem notification: \"{message}\""); await AddEvent(new NotifyEvent() { EventType = NotifyEventType.ServerOperationsProblem, Message = message }); } public static async Task AddEvent(NotifyEvent ev) { //iterate subs, figure out who gets this event //add to table for any that do try { log.LogTrace("Notify set to RUNNING state and starting now"); using (AyContext ct = AyaNova.Util.ServiceProviderProvider.DBContext) { //select all jobs with no deliver date or deliver date no longer in future //### PLAN if it's an smtp delivery that fails and it's to someone who can be delivered in app then it should send an inapp notification of //delivery failure and still delete the smtp delivery //If it's not possible to notify the person via in app of the failed smtp then perhaps it notifies OPS personnel and biz admin personnel //NEW NOTIFICATION SUBSCRIPTION EVENT TYPE: //OPERATIONS_PROBLEMS - backup, notifications, out of memory, what have you, anyone can subscribe to it regardless of rights //this is just to let people know there is a problem } } catch (Exception ex) { } finally { log.LogTrace("Notify is done setting to not running state and tagging lastRun timestamp"); lastRun = DateTime.UtcNow; NotifyIsRunning = false; } } }//eoc }//eons