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)

View File

@@ -16,14 +16,16 @@ namespace AyaNova.Models
[Required]
public DateTime Processed { get; set; }
public AyaType? AyaType { get; set; }
public long? ObjectId { get; set; }
public AyaType AyaType { get; set; }
public long ObjectId { get; set; }
[Required]
public NotifyEventType EventType { get; set; }
[Required]
public long SubscriptionId { get; set; }
public long? IdValue { get; set; }
public decimal? DecValue { get; set; }
[Required]
public long IdValue { get; set; }
[Required]
public decimal DecValue { get; set; }
[Required]
public long UserId { get; set; }
[Required]
@@ -36,6 +38,10 @@ namespace AyaNova.Models
public NotifyDeliveryLog()
{
Processed = DateTime.UtcNow;
IdValue=0;
DecValue=0;
AyaType=AyaType.NoType;
ObjectId=0;
}
}//eoc

View File

@@ -16,14 +16,15 @@ namespace AyaNova.Models
[Required]
public DateTime Created { get; set; }
public AyaType? AyaType { get; set; }
public long? ObjectId { get; set; }
public AyaType AyaType { get; set; }
public long ObjectId { get; set; }
[Required]
public NotifyEventType EventType { get; set; }
[Required]
public long SubscriptionId { get; set; }//source subscription that triggered this event to be created
public long? IdValue { get; set; }
public decimal? DecValue { get; set; }
[Required]
public long IdValue { get; set; }
public decimal DecValue { get; set; }
public DateTime? EventDate { get; set; }//date of the event actually occuring, e.g. WarrantyExpiry date. Duped with delivery date as source of truth in case edit to advance setting in subscription changes delivery date
public DateTime? DeliverDate { get; set; }//date user wants the event notification delivered, usually same as event date but could be set earlier if Advance setting in effect. This is the date consulted for delivery only.
public string Message { get; set; }
@@ -32,6 +33,10 @@ namespace AyaNova.Models
public NotifyEvent()
{
Created = DateTime.UtcNow;
IdValue = 0;
DecValue = 0;
AyaType=AyaType.NoType;
ObjectId=0;
}
public override string ToString()

View File

@@ -15,27 +15,34 @@ namespace AyaNova.Models
public uint Concurrency { get; set; }
[Required]
public long UserId { get; set; }
public TimeSpan? AdvanceNotice { get; set; } //Note: I've been doing nullable wrong sort of: https://stackoverflow.com/a/29149207/8939
public long? IdValue { get; set; }
public decimal? DecValue { get; set; }
public TimeSpan? AgeValue {get;set;}//for events that depend on an age of something (e.g. WorkorderStatusAge)
public long UserId { get; set; }
public TimeSpan AdvanceNotice { get; set; }
[Required]
public NotifyDeliveryMethod DeliveryMethod { get; set; }
public string DeliveryAddress { get; set; }
public long? AttachReportId { get; set; }
public long AttachReportId { get; set; }
//CONDITIONS - Following fields are all conditions set on whether to notify or not
public AyaType AyaType { get; set; }//Note: must be specific object, not global for any object related stuff to avoid many role issues and also potential overload
[Required]
public NotifyEventType EventType { get; set; }
public NotifyEventType EventType { get; set; }
[Required]
public long IdValue { get; set; }//if required, this must match, default is zero to match to not set
public decimal DecValue { get; set; }//if required this must match or be greater or something
public TimeSpan AgeValue { get; set; }//for events that depend on an age of something (e.g. WorkorderStatusAge)
public List<string> Tags { get; set; }//Tags to filter an event, object *must* have these tags to generate event related to it (AT TIME OF UPDATE)
public NotifySubscription()
{
Tags = new List<string>();
AyaType= AyaType.NoType;
Tags = new List<string>();
AyaType = AyaType.NoType;
IdValue = 0;
DecValue = 0;
AgeValue = new TimeSpan(0, 0, 0);
AdvanceNotice = new TimeSpan(0, 0, 0);
AttachReportId = 0;
}
}//eoc

View File

@@ -684,17 +684,17 @@ $BODY$;
LogUpdateMessage(log);
await ExecQueryAsync("CREATE TABLE anotifysubscription (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, " +
"userid bigint not null, ayatype integer not null, eventtype integer not null, advancenotice interval, " +
"idvalue bigint, decvalue decimal(19,4), agevalue interval, deliverymethod integer not null, deliveryaddress text, attachreportid bigint, tags varchar(255) ARRAY)");
"userid bigint not null, ayatype integer not null, eventtype integer not null, advancenotice interval not null, " +
"idvalue bigint not null, decvalue decimal(19,4) not null, agevalue interval not null, deliverymethod integer not null, deliveryaddress text, attachreportid bigint not null, tags varchar(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE anotifyevent (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, created timestamp not null, " +
"ayatype integer, objectid bigint, eventtype integer not null, subscriptionid bigint not null, idvalue bigint, decvalue decimal(19,4), eventdate timestamp, deliverdate timestamp, message text)");
"ayatype integer not null, objectid bigint not null, eventtype integer not null, subscriptionid bigint not null, idvalue bigint not null, decvalue decimal(19,4) not null, eventdate timestamp, deliverdate timestamp, message text)");
await ExecQueryAsync("CREATE TABLE anotification (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, userid bigint not null, created timestamp not null, ayatype integer, objectid bigint, eventtype integer not null, " +
await ExecQueryAsync("CREATE TABLE anotification (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, userid bigint not null, created timestamp not null, ayatype integer not null, objectid bigint not null, eventtype integer not null, " +
"subscriptionid bigint not null, message text, fetched bool not null)");
await ExecQueryAsync("CREATE TABLE anotifydeliverylog (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, processed timestamp not null, ayatype integer, objectid bigint, " +
"eventtype integer not null, subscriptionid bigint not null, idvalue bigint, decvalue decimal(19,4), userid bigint not null, " +
await ExecQueryAsync("CREATE TABLE anotifydeliverylog (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, processed timestamp not null, ayatype integer not null, objectid bigint not null, " +
"eventtype integer not null, subscriptionid bigint not null, idvalue bigint not null, decvalue decimal(19,4) not null, userid bigint not null, " +
"deliverymethod integer not null, fail bool not null, error text)");
await SetSchemaLevelAsync(++currentSchema);