Bit.Core.Services.PushSharpPushService.GcmBroker_OnNotificationFailed C# (CSharp) Method

GcmBroker_OnNotificationFailed() private method

private GcmBroker_OnNotificationFailed ( PushSharp.Google.GcmNotification notification, AggregateException exception ) : void
notification PushSharp.Google.GcmNotification
exception System.AggregateException
return void
        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;
            });
        }