예제 #1
0
        private async Task <BatchResponse> SendBatchRequestAsync(
            IEnumerable <Message> messages,
            bool dryRun,
            CancellationToken cancellationToken)
        {
            var responses = new List <SendResponse>();

            var batch = this.CreateBatchRequest(
                messages,
                dryRun,
                (content, error, index, message) =>
            {
                if (error != null)
                {
                    responses.Add(SendResponse.FromException(CreateExceptionFor(error)));
                }
                else if (content != null)
                {
                    responses.Add(SendResponse.FromMessageId(content.Name));
                }
                else
                {
                    responses.Add(SendResponse.FromException(new FirebaseException(
                                                                 $"Unexpected batch response. Response status code was {message.StatusCode}.")));
                }
            });

            await batch.ExecuteAsync(cancellationToken).ConfigureAwait(false);

            return(new BatchResponse(responses));
        }
예제 #2
0
        private async Task <BatchResponse> SendBatchRequestAsync(
            IEnumerable <Message> messages,
            bool dryRun,
            CancellationToken cancellationToken)
        {
            var responses = new List <SendResponse>();

            var batch = this.CreateBatchRequest(
                messages,
                dryRun,
                (content, error, index, message) =>
            {
                SendResponse sendResponse;
                if (error != null)
                {
                    var json      = (error as ContentRetainingRequestError).Content;
                    var exception = MessagingErrorHandler.Instance.HandleHttpErrorResponse(
                        message, json);
                    sendResponse = SendResponse.FromException(exception);
                }
                else if (content != null)
                {
                    sendResponse = SendResponse.FromMessageId(content.Name);
                }
                else
                {
                    var exception = new FirebaseMessagingException(
                        ErrorCode.Unknown,
                        $"Unexpected batch response. Response status code: {message.StatusCode}.");
                    sendResponse = SendResponse.FromException(exception);
                }

                responses.Add(sendResponse);
            });

            await batch.ExecuteAsync(cancellationToken).ConfigureAwait(false);

            return(new BatchResponse(responses));
        }