コード例 #1
0
    public async static void DequeueTask(object state)
    {
        CancellationToken token = (CancellationToken)state;

        while (!token.IsCancellationRequested)
        {
            if (dequeueSignal.WaitOne())             // block untill we have items in the queue
            {
                NotificationDelivery delivery = null;

                if (deliveryQueue.TryDequeue(out delivery))
                {
                    NotificationDeliveryStatus ns = NotificationDeliveryStatus.Pending;
                    if (delivery.Subscription.Status == SubscriptionStatus.Subscribed)
                    {
                        PushResult result = await PushService.DoPushAsync(delivery);

                        switch (result)
                        {
                        case PushResult.Pushed:
                            ns = NotificationDeliveryStatus.Delivered;
                            break;

                        case PushResult.Error:
                            ns = NotificationDeliveryStatus.FailureError;
                            break;

                        case PushResult.NotSupported:
                            ns = NotificationDeliveryStatus.FailureNotSupported;
                            break;

                        case PushResult.UnSubscribed:
                            ns = NotificationDeliveryStatus.FailureUnSubscribed;
                            delivery.Subscription.Status = SubscriptionStatus.UnSubscribed;
                            break;
                        }
                    }
                    else
                    {
                        ns = NotificationDeliveryStatus.FailureUnSubscribed;
                    }

                    delivery.Status      = ns;
                    delivery.DeliveredAt = DateTime.Now;
                }
                else
                {
                    // empty queue, no more items
                    // stop dequeueing untill new items added by EnqueueTask
                    dequeueSignal.Reset();
                }
            }
        }
    }
コード例 #2
0
        private async Task SetDeliveryStatus(int deliveryId, NotificationDeliveryStatus status)
        {
            var delivery = db.NotificationDeliveries.Find(deliveryId);

            if (delivery == null)
            {
                return;
            }

            delivery.Status = status;
            await db.SaveChangesAsync();
        }
コード例 #3
0
        private async Task SetDeliveryStatusAsync(int deliveryId, NotificationDeliveryStatus status)
        {
            var delivery = await db.NotificationDeliveries.FindAsync(deliveryId).ConfigureAwait(false);

            if (delivery == null)
            {
                return;
            }

            delivery.Status = status;
            await db.SaveChangesAsync().ConfigureAwait(false);
        }