This commit is contained in:
@@ -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
|
//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
|
//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
|
//iterate and deliver
|
||||||
foreach(var item in items){
|
foreach (var notifyevent in events)
|
||||||
//Time delayed ones:
|
{
|
||||||
//when to deliver formula: NotifyEvent "EventDate"+NotifySubscription.AgeValue timespan - NotifySubscription AdvanceNotice timespan > utcNow
|
//TIME DELAYED AGED EVENT?
|
||||||
if(item.)
|
//when to time delay deliver formula:If sub.agevalue!= timespan.zero then deliver on =
|
||||||
|
//NotifyEvent "EventDate"+NotifySubscription.AgeValue timespan - NotifySubscription AdvanceNotice timespan > utcNow
|
||||||
//Immediate delivery items
|
//Is it time delayed?
|
||||||
//
|
if (notifyevent.NotifySubscription.AgeValue != TimeSpan.Zero)
|
||||||
if(item.EventDate)
|
{
|
||||||
|
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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
log.LogError(ex, $"Error processing notification event");
|
||||||
}
|
}
|
||||||
finally
|
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");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace AyaNova.Models
|
|||||||
public long IdValue { get; set; }
|
public long IdValue { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public decimal DecValue { get; set; }
|
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
|
//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;
|
Created = DateTime.UtcNow;
|
||||||
IdValue = 0;
|
IdValue = 0;
|
||||||
DecValue = 0;
|
DecValue = 0;
|
||||||
// AgeValue = new TimeSpan(0, 0, 0);
|
// AgeValue = TimeSpan.Zero;
|
||||||
AyaType = AyaType.NoType;
|
AyaType = AyaType.NoType;
|
||||||
ObjectId = 0;
|
ObjectId = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ namespace AyaNova.Models
|
|||||||
AyaType = AyaType.NoType;
|
AyaType = AyaType.NoType;
|
||||||
IdValue = 0;
|
IdValue = 0;
|
||||||
DecValue = 0;
|
DecValue = 0;
|
||||||
AgeValue = new TimeSpan(0, 0, 0);
|
AgeValue = TimeSpan.Zero;
|
||||||
AdvanceNotice = new TimeSpan(0, 0, 0);
|
AdvanceNotice = TimeSpan.Zero;
|
||||||
AttachReportId = 0;
|
AttachReportId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user