This commit is contained in:
@@ -427,16 +427,142 @@ namespace Sockeye.Biz
|
|||||||
//just blanket remove any event for this object of eventtype that would be added below here
|
//just blanket remove any event for this object of eventtype that would be added below here
|
||||||
//do it regardless any time there's an update and then
|
//do it regardless any time there's an update and then
|
||||||
//let this code below handle the refreshing addition that could have changes
|
//let this code below handle the refreshing addition that could have changes
|
||||||
//await NotifyEventHelper.ClearPriorEventsForObject(ct, SockType.SubscriptionServer, o.Id, NotifyEventType.ContractExpiring);
|
await NotifyEventHelper.ClearPriorEventsForObject(ct, BizType, o.Id, NotifyEventType.SubscriptionServerExpiring);
|
||||||
|
await NotifyEventHelper.ClearPriorEventsForObject(ct, BizType, o.Id, NotifyEventType.SubscriptionServerLastUpdateAge);
|
||||||
|
|
||||||
|
|
||||||
//## CREATED / MODIFIED EVENTS
|
//## CREATED / MODIFIED EVENTS
|
||||||
if (ayaEvent == SockEvent.Created || ayaEvent == SockEvent.Modified)
|
if (ayaEvent == SockEvent.Created || ayaEvent == SockEvent.Modified)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//# SUBSCRIPTION SERVER EXPIRY
|
||||||
|
{
|
||||||
|
//notify users about warranty expiry (time delayed)
|
||||||
|
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.SubscriptionServerExpiring).ToListAsync();
|
||||||
|
foreach (var sub in subs)
|
||||||
|
{
|
||||||
|
//not for inactive users
|
||||||
|
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
||||||
|
|
||||||
|
//Tag match? (will be true if no sub tags so always safe to call this)
|
||||||
|
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(o.Tags, sub.Tags))
|
||||||
|
{
|
||||||
|
|
||||||
|
NotifyEvent n = new NotifyEvent()
|
||||||
|
{
|
||||||
|
EventType = NotifyEventType.SubscriptionServerExpiring,
|
||||||
|
UserId = sub.UserId,
|
||||||
|
SockType = BizType,
|
||||||
|
ObjectId = o.Id,
|
||||||
|
NotifySubscriptionId = sub.Id,
|
||||||
|
Name = o.Name,
|
||||||
|
EventDate = o.SubscriptionExpire
|
||||||
|
};
|
||||||
|
await ct.NotifyEvent.AddAsync(n);
|
||||||
|
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||||
|
await ct.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}//subscription server expiry event
|
||||||
|
|
||||||
|
|
||||||
}
|
//# SUBSCRIPTION SERVER LAST UPDATE AGE
|
||||||
|
{
|
||||||
|
if (o.LastUpdated != null)
|
||||||
|
{
|
||||||
|
//notify users about warranty expiry (time delayed)
|
||||||
|
var subs = await ct.NotifySubscription.Where(z => z.EventType == NotifyEventType.SubscriptionServerLastUpdateAge).ToListAsync();
|
||||||
|
foreach (var sub in subs)
|
||||||
|
{
|
||||||
|
//not for inactive users
|
||||||
|
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
||||||
|
|
||||||
|
//Tag match? (will be true if no sub tags so always safe to call this)
|
||||||
|
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(o.Tags, sub.Tags))
|
||||||
|
{
|
||||||
|
NotifyEvent n = new NotifyEvent()
|
||||||
|
{
|
||||||
|
EventType = NotifyEventType.SubscriptionServerLastUpdateAge,
|
||||||
|
UserId = sub.UserId,
|
||||||
|
SockType = BizType,
|
||||||
|
ObjectId = o.Id,
|
||||||
|
NotifySubscriptionId = sub.Id,
|
||||||
|
Name = o.Name,
|
||||||
|
EventDate = (DateTime)o.LastUpdated
|
||||||
|
};
|
||||||
|
await ct.NotifyEvent.AddAsync(n);
|
||||||
|
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||||
|
await ct.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}//subscription server expiry event
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//# STATUS CHANGE (create new status)
|
||||||
|
{
|
||||||
|
//Conditions: must match specific status id value and also tags below
|
||||||
|
//delivery is immediate so no need to remove old ones of this kind
|
||||||
|
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.ServerStateStatusChange && z.IdValue == (long)o.ServerState).ToListAsync();
|
||||||
|
foreach (var sub in subs)
|
||||||
|
{
|
||||||
|
//not for inactive users
|
||||||
|
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
||||||
|
|
||||||
|
//Tag match? (will be true if no sub tags so always safe to call this)
|
||||||
|
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(o.Tags, sub.Tags))
|
||||||
|
{
|
||||||
|
NotifyEvent n = new NotifyEvent()
|
||||||
|
{
|
||||||
|
EventType = NotifyEventType.ServerStateStatusChange,
|
||||||
|
UserId = sub.UserId,
|
||||||
|
SockType = BizType,
|
||||||
|
ObjectId = o.Id,
|
||||||
|
NotifySubscriptionId = sub.Id,
|
||||||
|
Name = $"{o.Name} - {o.ServerState.ToString()}"
|
||||||
|
};
|
||||||
|
await ct.NotifyEvent.AddAsync(n);
|
||||||
|
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||||
|
await ct.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}// status change event
|
||||||
|
|
||||||
|
//# STATUS AGE
|
||||||
|
{
|
||||||
|
//ServerStateStatusAge unchanged for set time (stuck in state), conditional on: Duration (how long stuck), exact status selected IdValue, Tags. Advance notice can NOT be set
|
||||||
|
//Always clear any old ones for this object as they are all irrelevant the moment the state has changed:
|
||||||
|
await NotifyEventHelper.ClearPriorEventsForObject(ct, SockType.SubscriptionServer, proposedObj.Id, NotifyEventType.ServerStateStatusAge);
|
||||||
|
var subs = await ct.NotifySubscription.AsNoTracking().Where(z => z.EventType == NotifyEventType.ServerStateStatusAge && z.IdValue == (long)o.ServerState).ToListAsync();
|
||||||
|
foreach (var sub in subs)
|
||||||
|
{
|
||||||
|
//not for inactive users
|
||||||
|
if (!await UserBiz.UserIsActive(sub.UserId)) continue;
|
||||||
|
|
||||||
|
//WorkOrder Tag match? (Not State, state has no tags, will be true if no sub tags so always safe to call this)
|
||||||
|
if (NotifyEventHelper.ObjectHasAllSubscriptionTags(o.Tags, sub.Tags))
|
||||||
|
{
|
||||||
|
NotifyEvent n = new NotifyEvent()
|
||||||
|
{
|
||||||
|
EventType = NotifyEventType.ServerStateStatusAge,
|
||||||
|
UserId = sub.UserId,
|
||||||
|
SockType = SockType.SubscriptionServer,
|
||||||
|
ObjectId = o.Id,
|
||||||
|
NotifySubscriptionId = sub.Id,
|
||||||
|
Name = $"{o.Name} - {o.ServerState.ToString()}"
|
||||||
|
};
|
||||||
|
await ct.NotifyEvent.AddAsync(n);
|
||||||
|
log.LogDebug($"Adding NotifyEvent: [{n.ToString()}]");
|
||||||
|
await ct.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}// status age event
|
||||||
|
|
||||||
|
|
||||||
|
}//object created or modified
|
||||||
|
|
||||||
}//end of process notifications
|
}//end of process notifications
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user