示例#1
0
        private void HandleFailedNotification(int identifier, byte status)
        {
            int index = this.sentNotifications.FindIndex((Predicate <SentNotification>)(n => n.Identifier == identifier));

            if (index < 0)
            {
                return;
            }
            Log.Info("Failed Notification: {0}", (object)identifier);
            if (index > 0)
            {
                this.sentNotifications.GetRange(0, index).ForEach((Action <SentNotification>)(n =>
                {
                    Interlocked.Decrement(ref this.trackedNotificationCount);
                    if (n.Callback == null)
                    {
                        return;
                    }
                    n.Callback((object)this, new SendNotificationResult((INotification)n.Notification, false, (Exception)null));
                }));
                this.sentNotifications.RemoveRange(0, index);
            }
            SentNotification failedNotification = this.sentNotifications[0];

            Interlocked.Decrement(ref this.trackedNotificationCount);
            if (failedNotification.Callback != null)
            {
                failedNotification.Callback((object)this, new SendNotificationResult((INotification)failedNotification.Notification, false, (Exception) new NotificationFailureException((int)status, failedNotification.Notification)));
            }
            this.sentNotifications.RemoveAt(0);
            this.sentNotifications.Reverse();
            this.sentNotifications.ForEach((Action <SentNotification>)(n =>
            {
                Interlocked.Decrement(ref this.trackedNotificationCount);
                if (failedNotification.Callback == null)
                {
                    return;
                }
                failedNotification.Callback((object)this, new SendNotificationResult((INotification)n.Notification, true, new Exception("Sent after previously failed Notification."))
                {
                    CountsAsRequeue = false
                });
            }));
            this.sentNotifications.Clear();
        }
示例#2
0
        private void Cleanup()
        {
            int num = -1;

            try
            {
                num = Interlocked.CompareExchange(ref this.cleanupSync, 1, 0);
                if (num != 0)
                {
                    return;
                }
                bool flag;
                do
                {
                    lock (this.connectLock)
                    {
                        try
                        {
                            this.Connect();
                        }
                        catch (Exception ex)
                        {
                            PushChannelExceptionDelegate onException = this.OnException;
                            if (onException != null)
                            {
                                onException((object)this, ex);
                            }
                        }
                    }
                    flag = false;
                    lock (this.sentLock)
                    {
                        if (this.sentNotifications.Count > 0)
                        {
                            if (this.connected)
                            {
                                SentNotification sentNotification = this.sentNotifications[0];
                                if (sentNotification.SentAt < DateTime.UtcNow.AddMilliseconds((double)(-1 * this.appleSettings.MillisecondsToWaitBeforeMessageDeclaredSuccess)))
                                {
                                    flag = true;
                                    Interlocked.Decrement(ref this.trackedNotificationCount);
                                    if (sentNotification.Callback != null)
                                    {
                                        sentNotification.Callback((object)this, new SendNotificationResult((INotification)sentNotification.Notification, false, (Exception)null));
                                    }
                                    this.sentNotifications.RemoveAt(0);
                                    Interlocked.Increment(ref this.cleanedUp);
                                }
                                else
                                {
                                    flag = false;
                                }
                            }
                            else
                            {
                                try
                                {
                                    this.sentNotifications[0].SentAt = DateTime.UtcNow;
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                }while (flag);
            }
            finally
            {
                if (num == 0)
                {
                    this.cleanupSync = 0;
                }
            }
        }