in src/Microsoft.Azure.NotificationHubs/NotificationHubClient.cs [3012:3077]
private async Task<NotificationOutcome> SendNotificationImplAsync(Notification notification, string tagExpression, string deviceHandle, CancellationToken cancellationToken)
{
var requestUri = GetGenericRequestUriBuilder();
requestUri.Path += "messages";
if (!string.IsNullOrWhiteSpace(deviceHandle))
{
AddToQuery(requestUri, "&direct");
}
// Convert FcmNotification into GcmNotification
notification = FcmToGcmNotificationTypeCast(notification);
notification.ValidateAndPopulateHeaders();
return await _retryPolicy.RunOperation(async (ct) =>
{
using (var request = CreateHttpRequest(HttpMethod.Post, requestUri.Uri, out var trackingId))
{
if (!string.IsNullOrWhiteSpace(deviceHandle))
{
request.Headers.Add("ServiceBusNotification-DeviceHandle", deviceHandle);
}
if (!string.IsNullOrWhiteSpace(tagExpression))
{
request.Headers.Add("ServiceBusNotification-Tags", tagExpression);
}
foreach (var item in notification.Headers)
{
request.Headers.Add(item.Key, item.Value);
}
ParseContentType(notification.ContentType, out var mediaType, out var encoding);
request.Content = new StringContent(notification.Body, encoding, mediaType);
request.Content.Headers.ContentType = new MediaTypeHeaderValue(mediaType);
using (var response = await SendRequestAsync(request, trackingId, new[] { HttpStatusCode.OK, HttpStatusCode.Created }, ct).ConfigureAwait(false))
{
if (EnableTestSend)
{
using (var responseContent = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
using (var reader = XmlReader.Create(responseContent, new XmlReaderSettings { CloseInput = true }))
{
var result = (NotificationOutcome)_debugResponseSerializer.ReadObject(reader);
result.State = NotificationOutcomeState.DetailedStateAvailable;
result.TrackingId = trackingId;
return result;
}
}
else
{
var result = new NotificationOutcome
{
State = NotificationOutcomeState.Enqueued,
TrackingId = trackingId,
NotificationId = GetNotificationIdFromResponse(response)
};
return result;
}
}
}
}, cancellationToken);
}