Exemplo n.º 1
0
        public void GcmNotification_Priority_Should_Serialize_As_String_Normal ()
        {
            var n = new GcmNotification ();
            n.Priority = GcmNotificationPriority.Normal;

            var str = n.ToString ();

            Assert.IsTrue (str.Contains ("normal"));
        }
Exemplo n.º 2
0
        public void GcmNotification_Priority_Should_Serialize_As_String_High ()
        {
            var n = new GcmNotification ();
            n.Priority = GcmNotificationPriority.High;

            var str = n.ToString ();

            Assert.IsTrue (str.Contains ("high"));
        }
Exemplo n.º 3
0
        public static GcmNotification ForSingleRegistrationId (GcmNotification msg, string registrationId)
        {
            var result = new GcmNotification ();
            result.Tag = msg.Tag;
            result.MessageId = msg.MessageId;
            result.RegistrationIds.Add (registrationId);
            result.To = null;
            result.CollapseKey = msg.CollapseKey;
            result.Data = msg.Data;
            result.DelayWhileIdle = msg.DelayWhileIdle;
            result.ContentAvailable = msg.ContentAvailable;
            result.DryRun = msg.DryRun;
            result.Priority = msg.Priority;
            result.NotificationKey = msg.NotificationKey;

            return result;
        }
Exemplo n.º 4
0
        public static GcmNotification ForSingleRegistrationId(GcmNotification msg, string registrationId)
        {
            var result = new GcmNotification();

            result.Tag       = msg.Tag;
            result.MessageId = msg.MessageId;
            result.RegistrationIds.Add(registrationId);
            result.To               = null;
            result.CollapseKey      = msg.CollapseKey;
            result.Data             = msg.Data;
            result.DelayWhileIdle   = msg.DelayWhileIdle;
            result.ContentAvailable = msg.ContentAvailable;
            result.DryRun           = msg.DryRun;
            result.Priority         = msg.Priority;

            return(result);
        }
Exemplo n.º 5
0
        public static GcmNotification ForSingleResult(GcmResponse response, int resultIndex)
        {
            var result = new GcmNotification();

            result.Tag       = response.OriginalNotification.Tag;
            result.MessageId = response.OriginalNotification.MessageId;
            result.RegistrationIds.Add(response.OriginalNotification.RegistrationIds [resultIndex]);
            result.CollapseKey      = response.OriginalNotification.CollapseKey;
            result.Data             = response.OriginalNotification.Data;
            result.DelayWhileIdle   = response.OriginalNotification.DelayWhileIdle;
            result.ContentAvailable = response.OriginalNotification.ContentAvailable;
            result.DryRun           = response.OriginalNotification.DryRun;
            result.Priority         = response.OriginalNotification.Priority;
            result.To = response.OriginalNotification.To;
            result.NotificationKey = response.OriginalNotification.NotificationKey;

            return(result);
        }
Exemplo n.º 6
0
        public static GcmNotification ForSingleResult (GcmResponse response, int resultIndex)
        {
            var result = new GcmNotification ();
            result.Tag = response.OriginalNotification.Tag;
            result.MessageId = response.OriginalNotification.MessageId;

            if (response.OriginalNotification.RegistrationIds != null && response.OriginalNotification.RegistrationIds.Count >= (resultIndex + 1))
                result.RegistrationIds.Add (response.OriginalNotification.RegistrationIds [resultIndex]);

            result.CollapseKey = response.OriginalNotification.CollapseKey;
            result.Data = response.OriginalNotification.Data;
            result.DelayWhileIdle = response.OriginalNotification.DelayWhileIdle;
            result.ContentAvailable = response.OriginalNotification.ContentAvailable;
            result.DryRun = response.OriginalNotification.DryRun;
            result.Priority = response.OriginalNotification.Priority;
            result.To = response.OriginalNotification.To;
            result.NotificationKey = response.OriginalNotification.NotificationKey;

            return result;
        }
Exemplo n.º 7
0
 public GcmNotificationException(GcmNotification notification, string msg) : base(msg, notification)
 {
     Notification = notification;
 }
Exemplo n.º 8
0
 public GcmNotificationException(GcmNotification notification, string msg, string description) : base(msg, notification)
 {
     Notification = notification;
     Description  = description;
 }
Exemplo n.º 9
0
        private void GcmBroker_OnNotificationFailed(GcmNotification notification, AggregateException exception)
        {
            exception.Handle(ex =>
            {
                // See what kind of exception it was to further diagnose
                if(ex is GcmNotificationException)
                {
                    var notificationException = ex as GcmNotificationException;

                    // Deal with the failed notification
                    var gcmNotification = notificationException.Notification;
                    var description = notificationException.Description;

                    Debug.WriteLine($"GCM Notification Failed: ID={gcmNotification.MessageId}, Desc={description}");
                }
                else if(ex is GcmMulticastResultException)
                {
                    var multicastException = ex as GcmMulticastResultException;

                    foreach(var succeededNotification in multicastException.Succeeded)
                    {
                        Debug.WriteLine($"GCM Notification Failed: ID={succeededNotification.MessageId}");
                    }

                    foreach(var failedKvp in multicastException.Failed)
                    {
                        var n = failedKvp.Key;
                        var e = failedKvp.Value;

                        Debug.WriteLine($"GCM Notification Failed: ID={n.MessageId}, Desc={e.Message}");
                    }

                }
                else if(ex is DeviceSubscriptionExpiredException)
                {
                    var expiredException = ex as DeviceSubscriptionExpiredException;

                    var oldId = expiredException.OldSubscriptionId;
                    var newId = expiredException.NewSubscriptionId;

                    Debug.WriteLine($"Device RegistrationId Expired: {oldId}");

                    if(!string.IsNullOrWhiteSpace(newId))
                    {
                        // If this value isn't null, our subscription changed and we should update our database
                        Debug.WriteLine($"Device RegistrationId Changed To: {newId}");
                    }
                }
                else if(ex is RetryAfterException)
                {
                    var retryException = (RetryAfterException)ex;
                    // If you get rate limited, you should stop sending messages until after the RetryAfterUtc date
                    Debug.WriteLine($"GCM Rate Limited, don't send more until after {retryException.RetryAfterUtc}");
                }
                else
                {
                    Debug.WriteLine("GCM Notification Failed for some unknown reason");
                }

                // Mark it as handled
                return true;
            });
        }
Exemplo n.º 10
0
 public GcmNotificationException (GcmNotification notification, string msg) : base (msg, notification)
 {
     Notification = notification;
 }
Exemplo n.º 11
0
 public GcmNotificationException (GcmNotification notification, string msg, string description) : base (msg, notification)
 {
     Notification = notification;
     Description = description;
 }