Exemple #1
0
        private async Task <NotificationHubDescription> CreateOrUpdateNotificationHubAsync(NotificationHubDescription description, bool update, CancellationToken cancellationToken)
        {
            if (description == null)
            {
                throw new ArgumentNullException(nameof(description));
            }

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

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

                    if (update)
                    {
                        httpRequestMessage.Headers.Add("If-Match", "*");
                    }

                    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);
                    var model = GetModelFromResponse <NotificationHubDescription>(xmlResponse, trackingId);
                    model.Path = description.Path;
                    return model;
                };
            }, cancellationToken));
        }
Exemple #2
0
 /// <summary>
 /// Updates the notification hub asynchronously.
 /// </summary>
 /// <param name="description">The description.</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 hub update operation</returns>
 public Task <NotificationHubDescription> UpdateNotificationHubAsync(NotificationHubDescription description, CancellationToken cancellationToken)
 {
     return(CreateOrUpdateNotificationHubAsync(description, true, cancellationToken));
 }
Exemple #3
0
 /// <summary>
 /// Updates the notification hub.
 /// </summary>
 /// <param name="description">The notification hub description.</param>
 /// <returns>The updated hub object</returns>
 public NotificationHubDescription UpdateNotificationHub(NotificationHubDescription description) =>
 UpdateNotificationHubAsync(description).GetAwaiter().GetResult();
Exemple #4
0
 /// <summary>
 /// Updates the notification hub asynchronously.
 /// </summary>
 /// <param name="description">The description.</param>
 /// <returns>A task that represents the asynchronous hub update operation</returns>
 public Task <NotificationHubDescription> UpdateNotificationHubAsync(NotificationHubDescription description)
 {
     return(UpdateNotificationHubAsync(description, CancellationToken.None));
 }
Exemple #5
0
 /// <summary>
 /// Creates the notification hub asynchronously.
 /// </summary>
 /// <param name="description">The notification hub description.</param>
 /// <returns>A task that represents the asynchronous create hub operation</returns>
 public Task <NotificationHubDescription> CreateNotificationHubAsync(NotificationHubDescription description)
 {
     return(CreateOrUpdateNotificationHubAsync(description, false, CancellationToken.None));
 }