示例#1
0
        private static async Task <NotificationDetails> WaitForThePushStatusAsync(string pnsType, NotificationHubClient nhClient, NotificationOutcome notificationOutcome)
        {
            var notificationId = notificationOutcome.NotificationId;
            var state          = NotificationOutcomeState.Enqueued;
            var count          = 0;
            NotificationDetails outcomeDetails = null;

            while ((state == NotificationOutcomeState.Enqueued || state == NotificationOutcomeState.Processing) && ++count < 10)
            {
                try
                {
                    Console.WriteLine($"{pnsType} status: {state}");
                    outcomeDetails = await nhClient.GetNotificationOutcomeDetailsAsync(notificationId);

                    state = outcomeDetails.State;
                }
                catch (MessagingEntityNotFoundException)
                {
                    // It's possible for the notification to not yet be enqueued, so we may have to swallow an exception
                    // until it's ready to give us a new state.
                }
                Thread.Sleep(1000);
            }
            return(outcomeDetails);
        }
        public async Task <NotificationDetails> GetNotificationOutcomeAsync(string notificationId)
        {
            NotificationHubClient client = NotificationHubClient.CreateClientFromConnectionString(_connectionstring, _hubName);
            var outcome = await client.GetNotificationOutcomeDetailsAsync(notificationId);

            return(outcome);
        }
示例#3
0
        private static async Task LogFeedback(NotificationHubClient _hub, string notificationId)
        {
            if (notificationId == null)
            {
                return;
            }

            var retryCount = 0;

            while (retryCount++ < 6)
            {
                try
                {
                    var result = await _hub.GetNotificationOutcomeDetailsAsync(notificationId);

                    if (result.State != NotificationOutcomeState.Completed)
                    {
                        await Task.Delay(TimeSpan.FromSeconds(10));
                    }
                    else
                    {
                        var feedbackUri = result.PnsErrorDetailsUri;
                        if (!string.IsNullOrEmpty(feedbackUri))
                        {
                            Console.WriteLine("feedbackBlobUri: {0}", feedbackUri);
                            var feedbackFromBlob = ReadFeedbackFromBlob(new Uri(feedbackUri));
                            Console.WriteLine("Feedback from blob: {0}", feedbackFromBlob);
                        }
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error StackTrace: {0}", ex.StackTrace);
                }
            }
        }