This commit is contained in:
2020-07-16 19:32:59 +00:00
parent 9f0944d37b
commit 2ddc4029fb
5 changed files with 78 additions and 39 deletions

View File

@@ -34,34 +34,55 @@ namespace AyaNova.Biz
else
log.LogWarning($"Ops problem notification: \"{message}\"");
await AddEvent(new NotifyEvent() { EventType = NotifyEventType.ServerOperationsProblem, Message = message });
await UpsertEvent(new NotifyEvent() { EventType = NotifyEventType.ServerOperationsProblem, Message = message });
}
//Add event if there are subscribers
public static async Task AddEvent(NotifyEvent ev, List<string> inTags = null)
//several optional conditional parameters
public static async Task UpsertEvent(NotifyEvent ev, List<string> inTags = null, long? IdValue=null,TimeSpan? AgeValue=null,decimal? DecValue=null)
{
log.LogTrace($"AddEvent processing: [{ev.ToString()}]");
log.LogTrace($"UpsertEvent processing: [{ev.ToString()}]");
try
{
List<NotifySubscription> subs = new List<NotifySubscription>();
// List<NotifySubscription> subs = new List<NotifySubscription>();
//Widget.updated.tags=yellow
//find subs where widget.updated and either no tags or tags=yellow if tags
//do I really need to remove old events? They should be zipping out the door pretty quickly.
//only I guess if it's delayed like a time delayed one or send later kind of situation?
var HasTags = inTags != null && inTags.Count > 0;
using (AyContext ct = AyaNova.Util.ServiceProviderProvider.DBContext)
{
//iterate subs, figure out who gets this event
//add to table for any that do
if (inTags == null || inTags.Count==0)
//find all the 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)
{
//No tags
subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == ev.EventType && z.AyaType == ev.AyaType).ToListAsync();
}
else
{
//In tags
//Final condition if tags are specified
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;
}
//Here we know the sub matches so create the NotifyEvent here
NotifyEvent ne=new NotifyEvent(){};
}
}
}
catch (Exception ex)