in src/Microsoft.Azure.NotificationHubs/NotificationHubClient.cs [3121:3172]
private async Task<ScheduledNotification> SendScheduledNotificationImplAsync(Notification notification, DateTimeOffset scheduledTime, string tagExpression, CancellationToken cancellationToken)
{
var requestUri = GetGenericRequestUriBuilder();
requestUri.Path += "schedulednotifications";
// 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))
{
request.Headers.Add("ServiceBusNotification-ScheduleTime", scheduledTime.UtcDateTime.ToString("s", CultureInfo.InvariantCulture));
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))
{
string notificationId = null;
if (response.Headers.Location != null)
{
notificationId = response.Headers.Location.Segments.Last().Trim('/');
}
var result = new ScheduledNotification()
{
ScheduledNotificationId = notificationId,
Tags = tagExpression,
ScheduledTime = scheduledTime,
Payload = notification,
TrackingId = trackingId
};
return result;
}
}
}, cancellationToken);
}