protected override void SendNotification(Notification notification)
        {
            var bbn = notification as BlackberryNotification;

            if (bbn != null)
                push(bbn);
        }
        public void Distribute(Notification notification)
        {
            var selectedChannel = this.TheLeastBusyChannel();

            if (selectedChannel != null)
            {
                notification.EnqueuedTimestamp = DateTime.UtcNow;
                selectedChannel.QueueNotification(notification);
            }
        }
Beispiel #3
0
        public void QueueNotification(Notification notification, bool countsAsRequeue = true)
        {
            //If the count is -1, it can be queued infinitely, otherwise check that it's less than the max
            if (this.ServiceSettings.MaxNotificationRequeues < 0 || notification.QueuedCount <= this.ServiceSettings.MaxNotificationRequeues)
            {
                //Increase the queue counter
                if (countsAsRequeue)
                    notification.QueuedCount++;

                queuedNotifications.Enqueue(notification);
            }
            else
                Events.RaiseNotificationSendFailure(notification, new MaxSendAttemptsReachedException());
        }
Beispiel #4
0
        public void QueueNotification(Notification notification, bool countsAsRequeue = true)
        {
            if (this.CancelToken.IsCancellationRequested)
                throw new ObjectDisposedException("Channel", "Channel has already been signaled to stop");

            //If the count is -1, it can be queued infinitely, otherwise check that it's less than the max
            if (this.ServiceSettings.MaxNotificationRequeues < 0 || notification.QueuedCount <= this.ServiceSettings.MaxNotificationRequeues)
            {
                //Increase the queue counter
                if (countsAsRequeue)
                    notification.QueuedCount++;

                queuedNotifications.Enqueue(notification);
            }
            else
                Events.RaiseNotificationSendFailure(notification, new MaxSendAttemptsReachedException());
        }
Beispiel #5
0
 public void QueueNotification(Notification notification)
 {
     switch (notification.Platform)
     {
         case PlatformType.Apple:
             appleService.QueueNotification(notification);
             break;
         case PlatformType.Android:
             androidService.QueueNotification(notification);
             break;
         case PlatformType.WindowsPhone:
             wpService.QueueNotification(notification);
             break;
         case PlatformType.Blackberry:
             bbService.QueueNotification(notification);
             break;
     }
 }
        private void SetResult(int errorCode, PushSharp.Common.Notification notification, Exception ex)
        {
            RemoteNotificationResult result = RemoteNotificationResult.FromNotification(notification);

            result.ErrorCode        = errorCode;
            result.ErrorDescription = GetErrorDescription(errorCode);
            if (ex != null && String.IsNullOrEmpty(result.ErrorDescription))
            {
                if (ex is NotificationFailureException)
                {
                    result.ErrorDescription = ((NotificationFailureException)ex).ErrorStatusDescription;
                }
                else
                {
                    result.ErrorDescription = ex.Message;
                }
                log.Error(String.Format("SetResult - ErrCode {0} - {1}", errorCode, result.ErrorDescription), ex);
            }
            SetResult(result);
        }
        protected override void SendNotification(Notification notification)
        {
            var wpNotification = notification as WindowsPhoneNotification;

            var wr = HttpWebRequest.Create(wpNotification.EndPointUrl) as HttpWebRequest;
            wr.ContentType = "text/xml";
            wr.Method = "POST";

            if (wpNotification.MessageID != null)
                wr.Headers.Add("X-MessageID", wpNotification.MessageID.ToString());

            if (wpNotification.NotificationClass.HasValue)
            {
                var immediateValue = 3;
                var mediumValue = 13;
                var slowValue = 23;

                if (wpNotification is WindowsPhoneToastNotification)
                {
                    immediateValue = 2;
                    mediumValue = 12;
                    slowValue = 22;
                }
                else if (wpNotification is WindowsPhoneTileNotification)
                {
                    immediateValue = 1;
                    mediumValue = 11;
                    slowValue = 21;
                }

                var val = immediateValue;
                if (wpNotification.NotificationClass.Value == BatchingInterval.Medium)
                    val = mediumValue;
                else if (wpNotification.NotificationClass.Value == BatchingInterval.Slow)
                    val = slowValue;

                wr.Headers.Add("X-NotificationClass", val.ToString());
            }

            if (wpNotification is WindowsPhoneToastNotification)
                wr.Headers.Add("X-WindowsPhone-Target", "toast");
            else if (wpNotification is WindowsPhoneTileNotification)
                wr.Headers.Add("X-WindowsPhone-Target", "Tile");

            var payload = wpNotification.PayloadToString();

            var data = Encoding.Default.GetBytes(payload);

            wr.ContentLength = data.Length;

            using (var rs = wr.GetRequestStream())
            {
                rs.Write(data, 0, data.Length);
            }

            try
            {
                wr.BeginGetResponse(new AsyncCallback(getResponseCallback), new object[] { wr, wpNotification });
            }
            catch (WebException wex)
            {
                //Handle different httpstatuses
                var status = ParseStatus(wex.Response as HttpWebResponse, wpNotification);

                HandleStatus(status);
            }
        }
Beispiel #8
0
        protected override void SendNotification(Notification notification)
        {
            var appleNotification = notification as AppleNotification;

            bool isOkToSend = true;
            byte[] notificationData = new byte[] {};

            try
            {
                notificationData = appleNotification.ToBytes();
            }
            catch (NotificationFailureException nfex)
            {
                //Bad notification format already
                isOkToSend = false;

                this.Events.RaiseNotificationSendFailure(notification, nfex);
            }

            if (isOkToSend)
            {
                Connect();

                try
                {
                    lock (streamWriteLock)
                    {
                        lock (sentLock)
                        {
                            networkStream.Write(notificationData, 0, notificationData.Length);

                            sentNotifications.Add(new SentNotification(appleNotification));
                        }
                    }
                }
                catch (Exception)
                {
                    SendFailed(notification);
                } //If this failed, we probably had a networking error, so let's requeue the notification
            }
        }
Beispiel #9
0
 protected abstract void SendNotification(Notification notification);
Beispiel #10
0
 public void RaiseNotificationSent(Notification notification)
 {
     var evt = this.OnNotificationSent;
     if (evt != null)
         evt(notification);
 }
Beispiel #11
0
 public void RaiseDeviceSubscriptionIdChanged(PlatformType platform, string oldDeviceInfo, string newDeviceInfo, Notification notification = null)
 {
     var evt = this.OnDeviceSubscriptionIdChanged;
     if (evt != null)
         evt(platform, oldDeviceInfo, newDeviceInfo, notification);
 }
Beispiel #12
0
 public void RaiseChannelException(Exception exception, PlatformType platformType, Notification notification = null)
 {
     var evt = this.OnChannelException;
     if (evt != null)
         evt(exception, platformType, notification);
 }
Beispiel #13
0
 void Events_OnChannelException(Exception notificationFailureException, PushSharp.Common.Notification notification)
 {
     SetResult(CUSTOM_ERROR, notification, notificationFailureException);
 }
Beispiel #14
0
 void Events_OnDeviceSubscriptionExpired(PushSharp.Common.PlatformType platform, string deviceInfo, PushSharp.Common.Notification notification)
 {
     SetResult(CUSTOM_ERROR, notification, new Exception("DeviceSubscriptionExpired - " + deviceInfo));
 }
Beispiel #15
0
 void Events_OnDeviceSubscriptionIdChanged(PushSharp.Common.PlatformType platform, string oldDeviceInfo, string newDeviceInfo, PushSharp.Common.Notification notification)
 {
     SetResult(CUSTOM_ERROR, notification, new Exception("DeviceSubscriptionIdChanged - old:" + oldDeviceInfo + " new: " + newDeviceInfo));
 }
Beispiel #16
0
 void Events_OnNotificationSendFailure(PushSharp.Common.Notification notification, Exception notificationFailureException)
 {
     SetResult(CUSTOM_ERROR, notification, notificationFailureException);
 }
Beispiel #17
0
 void Events_OnNotificationSent(PushSharp.Common.Notification notification)
 {
     SetResult(NO_ERROR, notification, null);
 }
 public void QueueNotification(Notification notification)
 {
     queuedNotifications.Enqueue(notification);
 }
Beispiel #19
0
 protected override void SendNotification(Notification notification)
 {
     Interlocked.Increment(ref waitCounter);
     transport.Send(notification as C2dmNotification, this.googleAuthToken, androidSettings.SenderID, androidSettings.ApplicationID);
 }
Beispiel #20
0
        public override bool QueueNotification(Notification notification, bool countsAsRequeue = true, bool ignoreStoppingChannel = false)
        {
            if (base.QueueNotification(notification, countsAsRequeue, ignoreStoppingChannel))
            {
                if (!ignoreStoppingChannel)
                    Interlocked.Increment(ref trackedNotificationCount);

                return true;
            }

            return false;
        }
 protected override void SendNotification(Notification notification)
 {
     transport.Send(notification as AndroidNotification, this.googleAuthToken, androidSettings.SenderID, androidSettings.ApplicationID);
 }
 public bool QueueNotification(Notification notification)
 {
     return QueueNotification(notification, true, false);
 }
Beispiel #23
0
 public void RaiseDeviceSubscriptionExpired(PlatformType platform, string deviceInfo, Notification notification = null)
 {
     var evt = this.OnDeviceSubscriptionExpired;
     if (evt != null)
         evt(platform, deviceInfo, notification);
 }
Beispiel #24
0
        public void QueueNotification(Notification notification)
        {
            notification.EnqueuedTimestamp = DateTime.UtcNow;

            queuedNotifications.Enqueue(notification);
        }
Beispiel #25
0
 public void RaiseNotificationSendFailure(Notification notification, Exception notificationFailureException)
 {
     var evt = this.OnNotificationSendFailure;
     if (evt != null)
         evt(notification, notificationFailureException);
 }
Beispiel #26
0
        protected override void SendNotification(Notification notification)
        {
            Interlocked.Increment(ref waitCounter);

            transport.Send(notification as GcmNotification, gcmSettings.SenderAuthToken, gcmSettings.SenderID, gcmSettings.ApplicationIdPackageName);
        }
Beispiel #27
0
 protected override void SendNotification(Notification notification)
 {
     transport.Send(notification as GcmNotification, gcmSettings.SenderAuthToken, gcmSettings.SenderID, gcmSettings.ApplicationIdPackageName);
 }
Beispiel #28
0
        public void QueueNotification(Notification notification, bool countsAsRequeue = true)
        {
            if (this.CancelToken.IsCancellationRequested)
            {
                Events.RaiseChannelException(new ObjectDisposedException("Channel", "Channel has already been signaled to stop"), this.PlatformType, notification);
                return;
            }

            //If the count is -1, it can be queued infinitely, otherwise check that it's less than the max
            if (this.ServiceSettings.MaxNotificationRequeues < 0 || notification.QueuedCount <= this.ServiceSettings.MaxNotificationRequeues)
            {
                //Reset the Enqueued time in case this is a requeue
                notification.EnqueuedTimestamp = DateTime.UtcNow;

                //Increase the queue counter
                if (countsAsRequeue)
                    notification.QueuedCount++;

                queuedNotifications.Enqueue(notification);

                //Signal a possibly wait-stated Sender loop that there's work to do
                waitQueuedNotification.Set();
            }
            else
                Events.RaiseNotificationSendFailure(notification, new MaxSendAttemptsReachedException());
        }