This commit is contained in:
2020-07-20 19:32:38 +00:00
parent ab65e15d99
commit 84785dd6b9
3 changed files with 54 additions and 19 deletions

View File

@@ -97,28 +97,49 @@ namespace AyaNova.Biz
//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();
var events = await ct.NotifyEvent.Include(z => z.NotifySubscription).ToListAsync();
log.LogTrace($"Found {events.Count} NotifyEvents to examine for potential delivery");
//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)
foreach (var notifyevent in events)
{
//TIME DELAYED AGED EVENT?
//when to time delay deliver formula:If sub.agevalue!= timespan.zero then deliver on =
//NotifyEvent "EventDate"+NotifySubscription.AgeValue timespan - NotifySubscription AdvanceNotice timespan > utcNow
//Is it time delayed?
if (notifyevent.NotifySubscription.AgeValue != TimeSpan.Zero)
{
var deliverAfter = notifyevent.EventDate + notifyevent.NotifySubscription.AgeValue - notifyevent.NotifySubscription.AdvanceNotice;
if (deliverAfter > DateTime.UtcNow)
{
if (notifyevent.NotifySubscription.DeliveryMethod == NotifyDeliveryMethod.App)
{
await DeliverInApp(notifyevent, ct);
}
if (notifyevent.NotifySubscription.DeliveryMethod == NotifyDeliveryMethod.SMTP)
{
await DeliverSMTP(notifyevent, ct);
}
}
}
else
{
//NORMAL IMMEDIATE DELIVERY EVENT
if (notifyevent.NotifySubscription.DeliveryMethod == NotifyDeliveryMethod.App)
{
await DeliverInApp(notifyevent, ct);
}
if (notifyevent.NotifySubscription.DeliveryMethod == NotifyDeliveryMethod.SMTP)
{
await DeliverSMTP(notifyevent, ct);
}
}
}
//turn notifyEvent records into notifications for in app and deliver smtp
}
}
catch (Exception ex)
{
log.LogError(ex, $"Error processing notification event");
}
finally
{
@@ -129,6 +150,20 @@ namespace AyaNova.Biz
}
private static async Task DeliverInApp(NotifyEvent ne, AyContext ct)
{
log.LogTrace($"DeliverInApp deliving notify event: {ne}");
await ct.Notification.AddAsync(new Notification() { UserId = ne.UserId, AyaType = ne.AyaType, ObjectId = ne.ObjectId, EventType = ne.EventType, NotifySubscriptionId = ne.NotifySubscriptionId, Message = ne.Message });
ct.NotifyEvent.Remove(ne);
await ct.SaveChangesAsync();
}
private static async Task DeliverSMTP(NotifyEvent ne, AyContext ct)
{
log.LogTrace($"DeliverSMTP deliving notify event: {ne}");
throw new System.NotImplementedException("DeliverSMTP: NOT IMPLEMENTED YET");
}
/////////////////////////////////////////////////////////////////////

View File

@@ -28,7 +28,7 @@ namespace AyaNova.Models
public long IdValue { get; set; }
[Required]
public decimal DecValue { 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
@@ -43,7 +43,7 @@ namespace AyaNova.Models
Created = DateTime.UtcNow;
IdValue = 0;
DecValue = 0;
// AgeValue = new TimeSpan(0, 0, 0);
// AgeValue = TimeSpan.Zero;
AyaType = AyaType.NoType;
ObjectId = 0;
}

View File

@@ -42,8 +42,8 @@ namespace AyaNova.Models
AyaType = AyaType.NoType;
IdValue = 0;
DecValue = 0;
AgeValue = new TimeSpan(0, 0, 0);
AdvanceNotice = new TimeSpan(0, 0, 0);
AgeValue = TimeSpan.Zero;
AdvanceNotice = TimeSpan.Zero;
AttachReportId = 0;
}