Пример #1
0
 /// <summary>
 /// Send a notification to a connected channel immediately.  Must call EnsureConnection() before starting to send.
 /// </summary>
 /// <param name="notification">The Notification to send.</param>
 public void Send(Notification notification)
 {
     apnsStream.Write(notification.ToBytes());
 }
Пример #2
0
 /// <summary>
 /// Send a notification to a connected channel immediately.  Must call EnsureConnection() before starting to send.
 /// </summary>
 /// <param name="notification">The Notification to send.</param>
 public void Send(Notification notification)
 {
     apnsStream.Write(notification.ToBytes());
 }
Пример #3
0
        private void workerMethod()
        {
            while (!disposing && !closing)
            {
                try
                {
                    while (this.notifications.Count > 0 && !disposing)
                    {
                        Notification notification = this.notifications.Dequeue();

                        int  tries = 0;
                        bool sent  = false;

                        while (!sent && tries < this.SendRetries)
                        {
                            try
                            {
                                if (!disposing)
                                {
                                    while (!connected)
                                    {
                                        Reconnect();
                                    }

                                    try
                                    {
                                        apnsStream.Write(notification.ToBytes());
                                    }
                                    catch (BadDeviceTokenException btex)
                                    {
                                        if (this.BadDeviceToken != null)
                                        {
                                            this.BadDeviceToken(this, btex);
                                        }
                                    }
                                    catch (NotificationLengthException nlex)
                                    {
                                        if (this.NotificationTooLong != null)
                                        {
                                            this.NotificationTooLong(this, nlex);
                                        }
                                    }

                                    string txtAlert = string.Empty;

                                    if (this.NotificationSuccess != null)
                                    {
                                        this.NotificationSuccess(this, notification);
                                    }

                                    sent = true;
                                }
                                else
                                {
                                    this.connected = false;
                                }
                            }
                            catch (Exception ex)
                            {
                                if (this.Error != null)
                                {
                                    this.Error(this, ex);
                                }

                                this.connected = false;
                            }

                            tries++;
                        }

                        //Didn't send in 3 tries
                        if (!sent && this.NotificationFailed != null)
                        {
                            this.NotificationFailed(this, notification);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (this.Error != null)
                    {
                        this.Error(this, ex);
                    }

                    this.connected = false;
                }

                if (!disposing)
                {
                    Thread.Sleep(500);
                }
            }
        }