public static async Task SendNotificationAsync ( int contentSourceId, string contentSourceType, string subscriberId, int destinationId ) { using (var context = new TdPushNotificationContext()) { var readyNote = await context.PushNotificationItems .FirstOrDefaultAsync(n => ( n.ContentSourceId == contentSourceId && n.ContentSourceType == contentSourceType && n.SubscriberId == subscriberId && n.DestinationId == destinationId ) && ( n.DeliveryStatus == PushNotificationItemStatus.Scheduled || n.DeliveryStatus == PushNotificationItemStatus.Retrying) ); if (readyNote == null) { return; } await SendNotificationMessageAsync(context, readyNote, CancellationToken.None); await context.SaveChangesAsync(); } }
public static async Task <int> SendNextReadyNotificationAsync(CancellationToken ct) { using (var context = new TdPushNotificationContext()) { //get the next notification that is ready to send var readyNote = await context.PushNotificationItems.Include(n => n.Destination).OrderBy(n => n.ScheduledSendDate).FirstOrDefaultAsync( n => (n.DeliveryStatus == PushNotificationItemStatus.Scheduled || n.DeliveryStatus == PushNotificationItemStatus.Retrying) && n.ScheduledSendDate <= DateTimeOffset.Now, ct); if (readyNote == null) { return(0); } await SendNotificationMessageAsync(context, readyNote, ct); return(await context.SaveChangesAsync(ct)); } }
public static async Task SendNotification ( int contentSourceId, string contentSourceType, string subscriberId, int destinationId ) { using (var context = new TdPushNotificationContext()) { var readyNote = await context.PushNotificationItems .FirstOrDefaultAsync(n => ( n.ContentSourceId == contentSourceId && n.ContentSourceType == contentSourceType && n.SubscriberId == subscriberId && n.DestinationId == destinationId ) && ( n.DeliveryStatus == PushNotificationItemStatus.Scheduled || n.DeliveryStatus == PushNotificationItemStatus.Retrying) ); if (readyNote == null) { return; } await SendNotificationMessageAsync(context, readyNote, CancellationToken.None); await context.SaveChangesAsync(); } }
public static async Task<int> SendNextReadyNotification(CancellationToken ct) { using (var context = new TdPushNotificationContext()) { //get the next notification that is ready to send var readyNote = await context.PushNotificationItems.Include(n => n.Destination).OrderBy(n => n.ScheduledSendDate).FirstOrDefaultAsync( n => (n.DeliveryStatus == PushNotificationItemStatus.Scheduled || n.DeliveryStatus == PushNotificationItemStatus.Retrying) && n.ScheduledSendDate <= DateTimeOffset.Now, ct); if (readyNote == null) { return 0; } await SendNotificationMessageAsync(context, readyNote, ct); return await context.SaveChangesAsync(ct); } }