This commit is contained in:
2020-07-20 19:05:28 +00:00
parent 0842ce025e
commit ab65e15d99
7 changed files with 69 additions and 26 deletions

View File

@@ -76,7 +76,7 @@ namespace AyaNova.Biz
//this will likely be a development error, not a production error so no need to log etc
throw new System.ArgumentException("NotifyEventProcessor:AddGeneralNotifyEvent: DefaultNotification requires a user id but none was specified");
}
NotifyEvent n = new NotifyEvent() { EventType = eventType, UserId = userId, Message = message, SubscriptionId = 0 };
NotifyEvent n = new NotifyEvent() { EventType = eventType, UserId = userId, Message = message, NotifySubscriptionId = 0 };
await ct.NotifyEvent.AddAsync(n);
await ct.SaveChangesAsync();
return;
@@ -87,7 +87,7 @@ namespace AyaNova.Biz
var subs = await ct.NotifySubscription.Where(z => z.EventType == eventType).ToListAsync();
foreach (var sub in subs)
{
NotifyEvent n = new NotifyEvent() { EventType = eventType, UserId = sub.UserId, Message = message, SubscriptionId = sub.Id };
NotifyEvent n = new NotifyEvent() { EventType = eventType, UserId = sub.UserId, Message = message, NotifySubscriptionId = sub.Id };
await ct.NotifyEvent.AddAsync(n);
}
if (subs.Count > 0)
@@ -148,7 +148,7 @@ namespace AyaNova.Biz
EventType = NotifyEventType.ObjectAge,
UserId = sub.UserId,
ObjectId = newObject.Id,
SubscriptionId = sub.Id,
NotifySubscriptionId = sub.Id,
//TODO: IdValue=((WorkOrder)newObject).WorkorderStatusId
EventDate = DateTime.UtcNow
};
@@ -206,13 +206,16 @@ namespace AyaNova.Biz
if (TagsMatch(newObject.Tags, sub.Tags))
{
//Note: 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
//ObjectAge is determined by subscription AgeValue in combo with the EventDate NotifyEvent parameter which together determines at what age from notifyevent.EventDate it's considered for the event to have officially occured
//However delivery is determined by sub.advancenotice so all three values play a part
//
NotifyEvent n = new NotifyEvent()
{
EventType = NotifyEventType.ObjectAge,
UserId = sub.UserId,
AyaType = newObject.AyaType,
ObjectId = newObject.Id,
SubscriptionId = sub.Id,
NotifySubscriptionId = sub.Id,
EventDate = DateTime.UtcNow
};
await ct.NotifyEvent.AddAsync(n);
@@ -230,7 +233,7 @@ namespace AyaNova.Biz
{
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 };
NotifyEvent n = new NotifyEvent() { EventType = NotifyEventType.ObjectCreated, UserId = sub.UserId, AyaType = newObject.AyaType, ObjectId = newObject.Id, NotifySubscriptionId = sub.Id };
await ct.NotifyEvent.AddAsync(n);
log.LogTrace($"Adding NotifyEvent: [{n.ToString()}]");
SaveContext = true;
@@ -266,7 +269,7 @@ namespace AyaNova.Biz
// EventType = NotifyEventType.ObjectAge,
// UserId = sub.UserId,
// ObjectId = newObject.Id,
// SubscriptionId = sub.Id,
// NotifySubscriptionId = sub.Id,
// //TODO: IdValue=((WorkOrder)newObject).WorkorderStatusId
// EventDate = DateTime.UtcNow
// };
@@ -333,7 +336,7 @@ namespace AyaNova.Biz
{
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 };
NotifyEvent n = new NotifyEvent() { EventType = NotifyEventType.ObjectModified, UserId = sub.UserId, AyaType = newObject.AyaType, ObjectId = newObject.Id, NotifySubscriptionId = sub.Id };
await ct.NotifyEvent.AddAsync(n);
log.LogTrace($"Adding NotifyEvent: [{n.ToString()}]");
SaveContext = true;
@@ -368,7 +371,7 @@ namespace AyaNova.Biz
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 };
NotifyEvent n = new NotifyEvent() { EventType = NotifyEventType.ObjectDeleted, UserId = sub.UserId, AyaType = newObject.AyaType, ObjectId = newObject.Id, NotifySubscriptionId = sub.Id, Message = newObject.Name };
await ct.NotifyEvent.AddAsync(n);
log.LogTrace($"Adding NotifyEvent: [{n.ToString()}]");
SaveContext = true;

View File

@@ -3,12 +3,23 @@ using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using AyaNova.Models;
using System;
using System.Linq;
using System.Globalization;
using System.Text;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
using AyaNova.Util;
using AyaNova.Models;
namespace AyaNova.Biz
{
/// <summary>
/// Notification processor
/// turn notifyEvent records into notifications for in app and deliver smtp
///
/// </summary>
internal static class CoreJobNotify
@@ -84,6 +95,24 @@ namespace AyaNova.Biz
//todo: create message here if not already set?
//todo: generate and attach report here?
//All items have an event date, for non time delayed events it's just the moment it was created
//which will predate this moment now if it's pre-existing
var items = await ct.NotifyEvent.Include(z => z.NotifySubscription).ToListAsync();
//iterate and deliver
foreach(var item in items){
//Time delayed ones:
//when to deliver formula: NotifyEvent "EventDate"+NotifySubscription.AgeValue timespan - NotifySubscription AdvanceNotice timespan > utcNow
if(item.)
//Immediate delivery items
//
if(item.EventDate)
}
//turn notifyEvent records into notifications for in app and deliver smtp
}
}

View File

@@ -23,7 +23,7 @@ namespace AyaNova.Models
[Required]
public NotifyEventType EventType { get; set; }
[Required]
public long SubscriptionId { get; set; }
public long NotifySubscriptionId { get; set; }
public string Message { get; set; }
[Required]
public bool Fetched { get; set; }
@@ -34,6 +34,9 @@ namespace AyaNova.Models
Fetched = false;
}
//linked entity
public NotifySubscription NotifySubscription { get; set; }
}//eoc
}//eons

View File

@@ -21,10 +21,10 @@ namespace AyaNova.Models
[Required]
public NotifyEventType EventType { get; set; }
[Required]
public long SubscriptionId { get; set; }
[Required]
public long NotifySubscriptionId { get; set; }
[Required]
public long IdValue { get; set; }
[Required]
[Required]
public decimal DecValue { get; set; }
[Required]
public long UserId { get; set; }
@@ -38,12 +38,15 @@ namespace AyaNova.Models
public NotifyDeliveryLog()
{
Processed = DateTime.UtcNow;
IdValue=0;
DecValue=0;
AyaType=AyaType.NoType;
ObjectId=0;
IdValue = 0;
DecValue = 0;
AyaType = AyaType.NoType;
ObjectId = 0;
}
//linked entity
public NotifySubscription NotifySubscription { get; set; }
}//eoc
}//eons

View File

@@ -23,13 +23,14 @@ namespace AyaNova.Models
[Required]
public long UserId { get; set; }
[Required]
public long SubscriptionId { get; set; }//source subscription that triggered this event to be created
public long NotifySubscriptionId { get; set; }//source subscription that triggered this event to be created
[Required]
public long IdValue { get; set; }
[Required]
public decimal DecValue { get; set; }
[Required]
public TimeSpan AgeValue { get; set; }
// [Required]// public TimeSpan AgeValue { get; set; }
//date of the event actually occuring, e.g. WarrantyExpiry date. Compared with subscription to determine if deliverable or not
public DateTime? EventDate { get; set; }
//NO: Delivery code consults subscription instead of this
@@ -42,7 +43,7 @@ namespace AyaNova.Models
Created = DateTime.UtcNow;
IdValue = 0;
DecValue = 0;
AgeValue = new TimeSpan(0, 0, 0);
// AgeValue = new TimeSpan(0, 0, 0);
AyaType = AyaType.NoType;
ObjectId = 0;
}
@@ -52,6 +53,9 @@ namespace AyaNova.Models
return JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.None);
}
//linked entity
public NotifySubscription NotifySubscription { get; set; }
}//eoc
}//eons

View File

@@ -34,7 +34,7 @@ namespace AyaNova.Models
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)
//DELIVERY CONDITIONS - following are all conditions on *whether* to deliver the existing notify event or not
public TimeSpan AgeValue { get; set; }//for events that depend on an age of something (e.g. WorkorderStatusAge)
public TimeSpan AgeValue { get; set; }//for events that depend on an age of something (e.g. WorkorderStatusAge), This value determines when event has "come of age" but advancenotice controls how far in advance of this delivery is made
public NotifySubscription()
{

View File

@@ -22,7 +22,7 @@ namespace AyaNova.Util
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!!
private const int DESIRED_SCHEMA_LEVEL = 12;
internal const long EXPECTED_COLUMN_COUNT = 381;
internal const long EXPECTED_COLUMN_COUNT = 380;
internal const long EXPECTED_INDEX_COUNT = 139;
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!!
@@ -689,15 +689,16 @@ $BODY$;
"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 not null, objectid bigint not null, eventtype integer not null, subscriptionid bigint not null, userid bigint not null, " +
"idvalue bigint not null, decvalue decimal(19,4) not null, agevalue interval not null, eventdate timestamp, message text)");
"ayatype integer not null, objectid bigint not null, eventtype integer not null, notifysubscriptionid bigint not null references anotifysubscription(id) on delete cascade, " +
"userid bigint not null, idvalue bigint not null, decvalue decimal(19,4) not null, eventdate 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 not null, objectid bigint not null, eventtype integer not null, " +
"subscriptionid bigint not null, message text, fetched bool not null)");
"notifysubscriptionid bigint not null references anotifysubscription(id) on delete cascade, 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 not null, objectid bigint not null, eventtype integer not null, subscriptionid bigint not null, idvalue bigint not null, "+
"ayatype integer not null, objectid bigint not null, eventtype integer not null, notifysubscriptionid 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);