Ejemplo n.º 1
0
        /// <summary>Submits the notification hub job asynchronously.</summary>
        /// <param name="job">The job to submit.</param>
        /// <param name="notificationHubPath">The notification hub path.</param>\
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for a task to complete.</param>
        /// <returns>A task that represents the asynchronous get job operation</returns>
        public async Task <NotificationHubJob> SubmitNotificationHubJobAsync(NotificationHubJob job, string notificationHubPath, CancellationToken cancellationToken)
        {
            if (job == null)
            {
                throw new ArgumentNullException(nameof(job));
            }

            if (job.OutputContainerUri == null)
            {
                throw new ArgumentNullException(nameof(job.OutputContainerUri));
            }

            var requestUri = new UriBuilder(_baseUri)
            {
                Scheme = Uri.UriSchemeHttps,
                Path   = $"{notificationHubPath}/jobs",
                Query  = $"api-version={ManagementStrings.ApiVersion}"
            };
            var xmlBody = CreateRequestBody(job);

            return(await _retryPolicy.RunOperation(async (ct) =>
            {
                using (var response = await SendAsync(() =>
                {
                    var httpRequestMessage = CreateHttpRequest(HttpMethod.Post, requestUri.Uri);
                    httpRequestMessage.Content = new StreamContent(new MemoryStream(Encoding.UTF8.GetBytes(xmlBody)));

                    return httpRequestMessage;
                }, ct).ConfigureAwait(false))
                {
                    var trackingId = string.Empty;
                    if (response.Headers.TryGetValues(TrackingIdHeaderKey, out var values))
                    {
                        trackingId = values.FirstOrDefault();
                    }
                    var xmlResponse = await GetXmlContent(response, trackingId).ConfigureAwait(false);
                    return GetModelFromResponse <NotificationHubJob>(xmlResponse, trackingId);
                };
            }, cancellationToken));
        }
Ejemplo n.º 2
0
 /// <summary>Submits the notification hub job asynchronously.</summary>
 /// <param name="job">The job to submit.</param>
 /// <param name="notificationHubPath">The notification hub path.</param>
 /// <returns>A task that represents the asynchronous get job operation</returns>
 public Task <NotificationHubJob> SubmitNotificationHubJobAsync(NotificationHubJob job, string notificationHubPath)
 {
     return(SubmitNotificationHubJobAsync(job, notificationHubPath, CancellationToken.None));
 }