diff --git a/server/AyaNova/biz/NotifyEventProcessor.cs b/server/AyaNova/biz/NotifyEventProcessor.cs index 88906a45..167403e8 100644 --- a/server/AyaNova/biz/NotifyEventProcessor.cs +++ b/server/AyaNova/biz/NotifyEventProcessor.cs @@ -15,12 +15,12 @@ namespace AyaNova.Biz { //This class handles word breaking, processing keywords and searching for results - public static class NotifyEventProcessor + internal 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) + internal static async Task AddOpsProblemEvent(string message, Exception ex = null) { if (string.IsNullOrWhiteSpace(message) && ex == null) return; @@ -41,8 +41,9 @@ namespace AyaNova.Biz //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, DefaultNotification, NotifyHealthCheck etc //optional user id to send directly to them - public static async Task AddGeneralNotifyEvent(NotifyEventType eventType, string message, long userId=0) + internal static async Task AddGeneralNotifyEvent(NotifyEventType eventType, string message, long userId = 0) { + log.LogTrace($"AddGeneralNotifyEvent processing: [type:{eventType}, userId:{userId}, message:{message}]"); #if (DEBUG) switch (eventType) { @@ -54,21 +55,47 @@ namespace AyaNova.Biz default://this will likely be a development error, not a production error so no need to log etc throw (new System.NotSupportedException($"NotifyEventProcessor:AddGeneralNotifyEvent - Type of event {eventType} is unexpected and not supported")); } -#endif - //Default notification goes to a specific user only - if(eventType==NotifyEventType.DefaultNotification){ - if(userId==0){ - //this will likely be a development error, not a production error so no need to log etc - throw new System.ArgumentException("NotifyEventProcessor:AddGeneralNotifyEvent: DefaultNotification requires a user id but none was specified"); - } - //create in app - NotifyEvent n=new NotifyEvent(){EventType=eventType,UserId=userId, Message=message} - return; + if (eventType != NotifyEventType.DefaultNotification && userId != 0) + { + throw (new System.NotSupportedException($"NotifyEventProcessor:AddGeneralNotifyEvent - event {eventType} was specified with user id {userId} which is unexpected and not supported")); + } +#endif + + try + { + using (AyContext ct = AyaNova.Util.ServiceProviderProvider.DBContext) + { + + //Default notification goes to a specific user only + //no need to consult subscriptions + if (eventType == NotifyEventType.DefaultNotification) + { + if (userId == 0) + { + //this will likely be a development error, not a production error so no need to log etc + throw new System.ArgumentException("NotifyEventProcessor:AddGeneralNotifyEvent: DefaultNotification requires a user id but none was specified"); + } + NotifyEvent n = new NotifyEvent() { EventType = eventType, UserId = userId, Message = message, SubscriptionId = 0 }; + await ct.NotifyEvent.AddAsync(n); + await ct.SaveChangesAsync(); + return; + } + + + //check subscriptions for event and send accordingly + var subs = ct.NotifySubscription.Where(z => z.EventType == eventType) + + + } + + } + catch (Exception ex) + { + log.LogError(ex, $"Error adding general notify event [type:{eventType}, userId:{userId}, message:{message}]"); } - - } + }//eom //This is told about an event and then determines if there are any subscriptions related to that event and proceses them accordingly @@ -78,7 +105,7 @@ namespace AyaNova.Biz //then *this* code will go through and look for subscriptions related to that event //this way the biz object code can be "dumb" about notifications in general and just let this code handle it as needed //will iterate the subscriptions and see if any apply here - public static async Task HandlePotentialNotificationEvent(AyaType ayaType, AyaEvent ayaEvent, BizObject newObject, BizObject currentObject, ) + internal static async Task HandlePotentialNotificationEvent(AyaType ayaType, AyaEvent ayaEvent, BizObject newObject, BizObject currentObject, ) {