This commit is contained in:
@@ -127,6 +127,7 @@ namespace AyaNova.Biz
|
||||
switch (ayaEvent)
|
||||
{
|
||||
case AyaEvent.Created:
|
||||
//Specific created related subscriptions for AyaType
|
||||
switch (newObject.AyaType)
|
||||
{
|
||||
//AyaTypes with their own special notification related events
|
||||
@@ -138,22 +139,19 @@ namespace AyaNova.Biz
|
||||
break;
|
||||
|
||||
}
|
||||
//ObjectCreated subscriptions
|
||||
//General ObjectCreated subscriptions
|
||||
{
|
||||
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.ObjectCreated && z.AyaType == newObject.AyaType).ToListAsync();
|
||||
foreach (var sub in subs)
|
||||
{
|
||||
//todo: match tags if necessary
|
||||
if (TagsMatch(newObject.Tags, sub.Tags))
|
||||
{
|
||||
NotifyEvent n = new NotifyEvent() { EventType = NotifyEventType.ObjectCreated, 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
case AyaEvent.Modified:
|
||||
@@ -200,88 +198,88 @@ namespace AyaNova.Biz
|
||||
|
||||
|
||||
|
||||
//################### FIRST ATTEMPT STUFF
|
||||
// //find all the Notification subscription subs that are relevant
|
||||
// //this first query ensures that the equality matching conditions of AyaType and EventType and idValue are matched leaving only more complex matches to rectify below
|
||||
// var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == ev.EventType && z.AyaType == ev.AyaType && z.IdValue == ev.IdValue).ToListAsync();
|
||||
// foreach (var sub in subs)
|
||||
// {
|
||||
// //CONDITION CHECK Tags condition
|
||||
// if (sub.Tags.Count > 0)
|
||||
// {
|
||||
// if (!HasTags)
|
||||
// continue;//not a match, this sub needs tags and we don't have any
|
||||
//################### FIRST ATTEMPT STUFF
|
||||
// //find all the Notification subscription subs that are relevant
|
||||
// //this first query ensures that the equality matching conditions of AyaType and EventType and idValue are matched leaving only more complex matches to rectify below
|
||||
// var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == ev.EventType && z.AyaType == ev.AyaType && z.IdValue == ev.IdValue).ToListAsync();
|
||||
// foreach (var sub in subs)
|
||||
// {
|
||||
// //CONDITION CHECK Tags condition
|
||||
// if (sub.Tags.Count > 0)
|
||||
// {
|
||||
// if (!HasTags)
|
||||
// continue;//not a match, this sub needs tags and we don't have any
|
||||
|
||||
// //bool existsCheck = list1.All(x => list2.Any(y => x.SupplierId == y.SupplierId));
|
||||
// //would tell you if all of list1's items are in list2.
|
||||
// if (!sub.Tags.All(z => inTags.Any(x => x == z)))
|
||||
// continue;
|
||||
// }
|
||||
// //bool existsCheck = list1.All(x => list2.Any(y => x.SupplierId == y.SupplierId));
|
||||
// //would tell you if all of list1's items are in list2.
|
||||
// if (!sub.Tags.All(z => inTags.Any(x => x == z)))
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// //CONDITION CHECK Decimal value, so far only for "The Andy" so the only condition is that the event value be greater than or equal to subscription setting
|
||||
// if (ev.EventType == NotifyEventType.WorkorderTotalExceedsThreshold && ev.DecValue < sub.DecValue)
|
||||
// continue;
|
||||
// //CONDITION CHECK Decimal value, so far only for "The Andy" so the only condition is that the event value be greater than or equal to subscription setting
|
||||
// if (ev.EventType == NotifyEventType.WorkorderTotalExceedsThreshold && ev.DecValue < sub.DecValue)
|
||||
// continue;
|
||||
|
||||
// //Here ready for delivery
|
||||
// //Here ready for delivery
|
||||
|
||||
// //HANDLE RELATED INDIRECT EVENTS AND CLEANUP
|
||||
// //some event types create related events here automatically (e.g. WorkorderStatusChange in turn will trigger workorderstatusage if subbed here)
|
||||
// //Deleting an object or changing status etc will affect other events in turn so clean up for them here
|
||||
// switch (ev.EventType)
|
||||
// {
|
||||
// case NotifyEventType.ObjectDeleted:
|
||||
// {
|
||||
// //object is deleted so remove any other events pending for it
|
||||
// //current working concept is there is no reason to keep any event related to a freshly deleted object
|
||||
// var deleteEventList = await ct.NotifyEvent.Where(z => z.ObjectId == ev.ObjectId && z.AyaType == ev.AyaType).ToListAsync();
|
||||
// ct.NotifyEvent.RemoveRange(deleteEventList);
|
||||
// await ct.SaveChangesAsync();
|
||||
// //HANDLE RELATED INDIRECT EVENTS AND CLEANUP
|
||||
// //some event types create related events here automatically (e.g. WorkorderStatusChange in turn will trigger workorderstatusage if subbed here)
|
||||
// //Deleting an object or changing status etc will affect other events in turn so clean up for them here
|
||||
// switch (ev.EventType)
|
||||
// {
|
||||
// case NotifyEventType.ObjectDeleted:
|
||||
// {
|
||||
// //object is deleted so remove any other events pending for it
|
||||
// //current working concept is there is no reason to keep any event related to a freshly deleted object
|
||||
// var deleteEventList = await ct.NotifyEvent.Where(z => z.ObjectId == ev.ObjectId && z.AyaType == ev.AyaType).ToListAsync();
|
||||
// ct.NotifyEvent.RemoveRange(deleteEventList);
|
||||
// await ct.SaveChangesAsync();
|
||||
|
||||
// }
|
||||
// break;
|
||||
// case NotifyEventType.WorkorderStatusChange:
|
||||
// {
|
||||
// //Workorder status changed so remove any other prior workorderstatuschanged events and
|
||||
// //remove any prior workorderstatusAge events for this object id
|
||||
// }
|
||||
// break;
|
||||
// case NotifyEventType.WorkorderStatusChange:
|
||||
// {
|
||||
// //Workorder status changed so remove any other prior workorderstatuschanged events and
|
||||
// //remove any prior workorderstatusAge events for this object id
|
||||
|
||||
// var deleteEventList = await ct.NotifyEvent.Where(z => z.ObjectId == ev.ObjectId && z.AyaType == ev.AyaType && ev.EventType == NotifyEventType.WorkorderStatusChange).ToListAsync();
|
||||
// ct.NotifyEvent.RemoveRange(deleteEventList);
|
||||
// await ct.SaveChangesAsync();
|
||||
// var deleteEventList = await ct.NotifyEvent.Where(z => z.ObjectId == ev.ObjectId && z.AyaType == ev.AyaType && ev.EventType == NotifyEventType.WorkorderStatusChange).ToListAsync();
|
||||
// ct.NotifyEvent.RemoveRange(deleteEventList);
|
||||
// await ct.SaveChangesAsync();
|
||||
|
||||
// }
|
||||
// break;
|
||||
// case NotifyEventType.WorkorderStatusAge://delete any workorder status age ones because there is potentially a new status invalidating the old status
|
||||
// case NotifyEventType.QuoteStatusAge:
|
||||
// //Delete any existing ones
|
||||
// var StaleAgedEvents = await ct.NotifyEvent.Where(z => z.EventType == ev.EventType && z.ObjectId == ev.ObjectId && z.AyaType == ev.AyaType).ToListAsync();
|
||||
// }
|
||||
// break;
|
||||
// case NotifyEventType.WorkorderStatusAge://delete any workorder status age ones because there is potentially a new status invalidating the old status
|
||||
// case NotifyEventType.QuoteStatusAge:
|
||||
// //Delete any existing ones
|
||||
// var StaleAgedEvents = await ct.NotifyEvent.Where(z => z.EventType == ev.EventType && z.ObjectId == ev.ObjectId && z.AyaType == ev.AyaType).ToListAsync();
|
||||
|
||||
// break;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// //AgeValue refresh?
|
||||
// //Age based ones need to replace any prior existing age based ones made for the same object as they are the only ones that can sit in the queue for any length of time
|
||||
// //and become invalidated (i.e. deadman type deliveries that sb removed if no longer applicable e.g. WorkorderStatusAge)
|
||||
// switch (ev.EventType)
|
||||
// {
|
||||
// case NotifyEventType.ObjectAge://this is set on creation so it will never change unless the object is deleted
|
||||
// case NotifyEventType.WorkorderStatusAge://delete any workorder status age ones because there is potentially a new status invalidating the old status
|
||||
// case NotifyEventType.QuoteStatusAge:
|
||||
// //Delete any existing ones
|
||||
// var StaleAgedEvents = await ct.NotifyEvent.Where(z => z.EventType == ev.EventType && z.ObjectId == ev.ObjectId && z.AyaType == ev.AyaType).ToListAsync();
|
||||
// //AgeValue refresh?
|
||||
// //Age based ones need to replace any prior existing age based ones made for the same object as they are the only ones that can sit in the queue for any length of time
|
||||
// //and become invalidated (i.e. deadman type deliveries that sb removed if no longer applicable e.g. WorkorderStatusAge)
|
||||
// switch (ev.EventType)
|
||||
// {
|
||||
// case NotifyEventType.ObjectAge://this is set on creation so it will never change unless the object is deleted
|
||||
// case NotifyEventType.WorkorderStatusAge://delete any workorder status age ones because there is potentially a new status invalidating the old status
|
||||
// case NotifyEventType.QuoteStatusAge:
|
||||
// //Delete any existing ones
|
||||
// var StaleAgedEvents = await ct.NotifyEvent.Where(z => z.EventType == ev.EventType && z.ObjectId == ev.ObjectId && z.AyaType == ev.AyaType).ToListAsync();
|
||||
|
||||
// break;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
|
||||
|
||||
// //Here we know the sub matches the event and passes all the conditions so set the deliver date if necessary and save the NotifyEvent here
|
||||
// //todo: create message here (delivery thing?)
|
||||
// //todo: Attach report here or is that a delivery thing (delivery thing)
|
||||
// //Here we know the sub matches the event and passes all the conditions so set the deliver date if necessary and save the NotifyEvent here
|
||||
// //todo: create message here (delivery thing?)
|
||||
// //todo: Attach report here or is that a delivery thing (delivery thing)
|
||||
|
||||
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
private static bool TagsMatch(List<string> objectTags, List<string> subTags)
|
||||
{
|
||||
|
||||
@@ -10,18 +10,18 @@ namespace AyaNova.Biz
|
||||
{
|
||||
//see core-notifications.txt spec doc for a bit more info on each type (they are named a little bit differently)
|
||||
|
||||
ObjectDeleted = 1,
|
||||
ObjectCreated = 2,
|
||||
ObjectModified = 3,
|
||||
WorkorderStatusChange = 4,
|
||||
ContractExpiring = 5,
|
||||
CSRAccepted = 6,
|
||||
CSRRejected = 7,
|
||||
WorkorderClosed = 8,//Deprecated? Now fulfilled by workorder status specifically, or.. perhaps this still exists but as when wo set to any closed type status? There is a todo in client end related to thsi
|
||||
QuoteStatusChange = 9,//quote created / modified
|
||||
ObjectAge = 10,//upon object created, conditional on AgeValue
|
||||
ServiceBankDepleted = 11,//any change to service bank triggers this check
|
||||
ReminderImminent = 12,
|
||||
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
|
||||
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
|
||||
CSRRejected = 7,//CustomerServiceRequest object, saved with REJECTED status, delivered to Customer only
|
||||
DEPRECATED_8 = 8,//UNUSED, FILL IN LATER WITH NEXT NEW NOTIFICATION EVENT
|
||||
QuoteStatusChange = 9,//Quote object, any *change* of status including from no status (new) to a specific conditional status ID value
|
||||
ObjectAge = 10,//Any object, Age (conditional on AgeValue) after creation event of any object of conditional specific AyaType and optionally conditional tags
|
||||
ServiceBankDepleted = 11,//ServiceBank object, any change to balance triggers this check, conditional on decvalue as remaining balance left to trigger this notification
|
||||
ReminderImminent = 12,//Reminder object
|
||||
ScheduledOnWorkorder = 13,
|
||||
ScheduledOnWorkorderImminent = 14,
|
||||
WorkorderCloseByPassed = 15,
|
||||
|
||||
Reference in New Issue
Block a user