This commit is contained in:
@@ -115,6 +115,8 @@ namespace AyaNova.Biz
|
||||
|
||||
|
||||
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;
|
||||
try
|
||||
{
|
||||
|
||||
@@ -142,16 +144,16 @@ namespace AyaNova.Biz
|
||||
foreach (var sub in subs)
|
||||
{
|
||||
//todo: match tags if necessary
|
||||
if (sub.Tags.Count > 0)
|
||||
if (TagsMatch(newObject.Tags, sub.Tags))
|
||||
{
|
||||
if (!sub.Tags.All(z => newObject.Tags.Any(x => x == z)))
|
||||
continue;
|
||||
NotifyEvent n = new NotifyEvent() { EventType = NotifyEventType.ObjectCreated, UserId = sub.UserId, AyaType = newObject.AyaType, ObjectId = newObject.Id, SubscriptionId = sub.Id };
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
SaveContext = true;
|
||||
}
|
||||
NotifyEvent n = new NotifyEvent() { EventType = NotifyEventType.ObjectCreated, UserId = sub.UserId, AyaType = newObject.AyaType, ObjectId = newObject.Id, SubscriptionId = sub.Id };
|
||||
await ct.NotifyEvent.AddAsync(n);
|
||||
|
||||
}
|
||||
if (subs.Count > 0)
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
case AyaEvent.Modified:
|
||||
@@ -176,6 +178,28 @@ namespace AyaNova.Biz
|
||||
|
||||
|
||||
|
||||
if (SaveContext)
|
||||
await ct.SaveChangesAsync();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.LogError(ex, $"Error processing event");
|
||||
}
|
||||
finally
|
||||
{
|
||||
log.LogTrace($"Notify event processing completed");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}//eom
|
||||
|
||||
|
||||
|
||||
|
||||
//################### 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
|
||||
@@ -259,36 +283,19 @@ namespace AyaNova.Biz
|
||||
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.LogError(ex, $"Error processing event");
|
||||
}
|
||||
finally
|
||||
{
|
||||
log.LogTrace($"Notify event processing completed");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}//eom
|
||||
|
||||
|
||||
private static bool TagsMatch(List<string> objectTags, List<string> subTags){
|
||||
private static bool TagsMatch(List<string> objectTags, List<string> subTags)
|
||||
{
|
||||
//no subscription tags? Then it always will match
|
||||
if(subTags.Count==0) return true;
|
||||
if (subTags.Count == 0) return true;
|
||||
//have sub tags but object has none? Then it's never going to match
|
||||
if(objectTags.Count==0) return false;
|
||||
if (objectTags.Count == 0) return false;
|
||||
|
||||
//not enought tags on object to match sub tags?
|
||||
if(subTags.Count > objectTags.Count) return false;
|
||||
if (subTags.Count > objectTags.Count) return false;
|
||||
|
||||
//ok, here it's worth checking it out
|
||||
if (!sub.Tags.All(z => newObject.Tags.Any(x => x == z)))
|
||||
continue;
|
||||
|
||||
return subTags.All(z => objectTags.Any(x => x == z));
|
||||
|
||||
}
|
||||
|
||||
}//eoc
|
||||
|
||||
Reference in New Issue
Block a user