This commit is contained in:
2020-07-17 20:47:30 +00:00
parent 9782a2086e
commit abed6934e1
2 changed files with 134 additions and 20 deletions

View File

@@ -112,8 +112,6 @@ namespace AyaNova.Biz
//will iterate the subscriptions and see if any apply here
internal static async Task HandlePotentialNotificationEvent(AyaEvent ayaEvent, ICoreBizObjectModel newObject, ICoreBizObjectModel dbObject)
{
log.LogTrace($"HandlePotentialNotificationEvent processing: [AyaType:{newObject.AyaType}, AyaEvent:{ayaEvent}]");
//set to true if any changes are made to the context (NotifyEvent added)
bool SaveContext = false;
@@ -127,6 +125,7 @@ namespace AyaNova.Biz
switch (ayaEvent)
{
case AyaEvent.Created:
#region Created processing
//------------------------------
// AyaType Specific created related subscriptions
//
@@ -137,15 +136,13 @@ namespace AyaNova.Biz
{
//WorkorderStatusChange
{
throw new System.NotImplementedException("Awaiting workorder object completion");
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.WorkorderStatusChange).ToListAsync();
foreach (var sub in subs)
{
if (TagsMatch(newObject.Tags, sub.Tags))
{
//Note: this is a "deadman switch" event
//it will deliver if it's not removed before the age selected
// age is set by advance notice which is consulted by CoreJobNotify in it's run so the deliver date is not required here only the reference EventDate to check for deliver
throw new System.NotImplementedException("Awaiting workorder object completion");
NotifyEvent n = new NotifyEvent()
{
EventType = NotifyEventType.ObjectAge,
@@ -240,10 +237,138 @@ namespace AyaNova.Biz
}
}
}
#endregion created processing
break;
case AyaEvent.Modified:
#region Modified processing
//######## NOTE: Any that don't deliver right away should be removed before re-inserting
//------------------------------
// AyaType Specific modified related subscriptions
//
switch (newObject.AyaType)
{
//AyaTypes with their own special notification related events
case AyaType.WorkOrder:
{
//WorkorderStatusChange
{
throw new System.NotImplementedException("Awaiting workorder object completion");
// if (((WorkOrder)newObject).WorkorderStatusId != ((WorkOrder)dbObject).WorkorderStatusId)
// {
// var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.WorkorderStatusChange).ToListAsync();
// foreach (var sub in subs)
// {
// if (TagsMatch(newObject.Tags, sub.Tags))
// {
// NotifyEvent n = new NotifyEvent()
// {
// EventType = NotifyEventType.ObjectAge,
// UserId = sub.UserId,
// ObjectId = newObject.Id,
// SubscriptionId = sub.Id,
// //TODO: IdValue=((WorkOrder)newObject).WorkorderStatusId
// EventDate = DateTime.UtcNow
// };
// await ct.NotifyEvent.AddAsync(n);
// log.LogTrace($"Adding NotifyEvent: [{n.ToString()}]");
// //Note: in same event but for MODIFY below if need to delete old notifyevent here
// // var deleteEventList = await ct.NotifyEvent.Where(z => z.ObjectId == ev.ObjectId && z.AyaType == ev.AyaType).ToListAsync();
// // ct.NotifyEvent.RemoveRange(deleteEventList);
// SaveContext = true;
// }
// }
// }
}
//ScheduledOnWorkorder (DELETE OLD, USER / DATE COULD CHANGE)
//ScheduledOnWorkorderImminent (DELTE OLD)
//tentative WorkorderCloseByPassed (DELETE OLD)
//OutsideServiceOverdue (ALSO DELETE OLD)
//OutsideServiceReceived
//PartRequestReceived
//CustomerServiceImminent (ALSO DELETE OLD)
//PartRequested
//WorkorderTotalExceedsThreshold
//WorkorderStatusAge (ALSO DELETE OLD)
}
break;
case AyaType.Quote:
//QuoteStatusChange
//QuoteStatusAge (DELETE OLD)
break;
case AyaType.Contract:
//ContractExpiring (DELETE OLD)
break;
case AyaType.Reminder:
//ReminderImminent (DELETE OLD)
break;
case AyaType.Unit:
//UnitWarrantyExpiry (DELTE OLD)
break;
case AyaType.UnitMeterReading:
//UnitMeterReadingMultipleExceeded
break;
}
//------------------------------------------
//ObjectModified
//
{
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ObjectModified && z.AyaType == newObject.AyaType).ToListAsync();
foreach (var sub in subs)
{
if (TagsMatch(newObject.Tags, sub.Tags))
{
NotifyEvent n = new NotifyEvent() { EventType = NotifyEventType.ObjectModified, UserId = sub.UserId, AyaType = newObject.AyaType, ObjectId = newObject.Id, SubscriptionId = sub.Id };
await ct.NotifyEvent.AddAsync(n);
log.LogTrace($"Adding NotifyEvent: [{n.ToString()}]");
SaveContext = true;
}
}
}
#endregion modified processing
break;
case AyaEvent.Deleted:
#region Deleted processing
//------------------------------
// Delete any NotifyEvent records for this exact object
// It's gone and shouldn't have any events left for it
//
{
var deleteList = await ct.NotifyEvent.Where(z => z.ObjectId == newObject.Id && z.AyaType == newObject.AyaType).ToListAsync();
if (deleteList.Count > 0)
{
ct.NotifyEvent.RemoveRange(deleteList);
SaveContext = true;
}
}
//------------------------------------------
//ObjectDeleted notification
//
{
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ObjectDeleted && z.AyaType == newObject.AyaType).ToListAsync();
foreach (var sub in subs)
{
if (TagsMatch(newObject.Tags, sub.Tags))
{
//TODO: On deliver should point to history event log record or take from there and insert into delivery message?
NotifyEvent n = new NotifyEvent() { EventType = NotifyEventType.ObjectDeleted, UserId = sub.UserId, AyaType = newObject.AyaType, ObjectId = newObject.Id, SubscriptionId = sub.Id, Message = newObject.Name };
await ct.NotifyEvent.AddAsync(n);
log.LogTrace($"Adding NotifyEvent: [{n.ToString()}]");
SaveContext = true;
}
}
}
#endregion deleted processing
break;
@@ -253,20 +378,9 @@ namespace AyaNova.Biz
#else
break;
#endif
}
if (SaveContext)
await ct.SaveChangesAsync();
}
}
catch (Exception ex)

View File

@@ -9,10 +9,10 @@ namespace AyaNova.Biz
public enum NotifyEventType : int
{
//see core-notifications.txt spec doc for a bit more info on each type (they are named a little bit differently)
//#### NOTE: once event is coded in NotifyEventProcessor I'll mark it with a * in the comment so I know if I miss any
ObjectDeleted = 1,//Deletion of any object of conditional specific AyaType and optionally conditional tags
//#### NOTE: once event is NOTED IN COMMENT (not necessarily coded yet as some can't be yet) in NotifyEventProcessor I'll mark it with a * in the comment so I know if I miss any
ObjectDeleted = 1,//* Deletion of any object of conditional specific AyaType and optionally conditional tags
ObjectCreated = 2,//* creation of any object of conditional specific AyaType and optionally conditional tags
ObjectModified = 3,//Modification / update of any kind of any object of conditional specific AyaType and optionally conditional tags
ObjectModified = 3,//* Modification / update of any kind of any object of conditional specific AyaType and optionally conditional tags
WorkorderStatusChange = 4,//Workorder object, any *change* of status including from no status (new) to a specific conditional status ID value
ContractExpiring = 5,//Contract object, aged notification with optional advance notice for expiration date of contract. Customer version and User version deliveries possible.
CSRAccepted = 6,//CustomerServiceRequest object, saved with ACCEPTED status, delivered to Customer only