public virtual Response <ValidateProbeOutput> ValidateProbe(ValidateProbeInput validateProbeInput, CancellationToken cancellationToken = default) { using var scope = DefaultClientDiagnostics.CreateScope("SubscriptionResourceExtensionClient.ValidateProbe"); scope.Start(); try { var response = DefaultRestClient.ValidateProbe(Id.SubscriptionId, validateProbeInput, cancellationToken); return(response); } catch (Exception e) { scope.Failed(e); throw; } }
public async Task Validate() { SubscriptionResource subscription = await Client.GetDefaultSubscriptionAsync(); Uri probeURL = new Uri("https://azurecdn-files.azureedge.net/dsa-test/probe-v.txt"); ValidateProbeInput validateProbeInput2 = new ValidateProbeInput(probeURL); ValidateProbeOutput ValidateProbeOutput = await subscription.ValidateProbeAsync(validateProbeInput2); Assert.True(ValidateProbeOutput.IsValid); probeURL = new Uri("https://www.notexist.com/notexist/notexist.txt"); ValidateProbeInput validateProbeInput3 = new ValidateProbeInput(probeURL); ValidateProbeOutput = await subscription.ValidateProbeAsync(validateProbeInput3); Assert.False(ValidateProbeOutput.IsValid); }
public async Task Validate() { string probeURL = "www.withoutHttp.com"; ValidateProbeInput validateProbeInput1 = new ValidateProbeInput(probeURL); Subscription subscription = await Client.GetDefaultSubscriptionAsync(); Assert.ThrowsAsync <RequestFailedException>(async() => await subscription.ValidateProbeAsync(validateProbeInput1)); probeURL = "https://azurecdn-files.azureedge.net/dsa-test/probe-v.txt"; ValidateProbeInput validateProbeInput2 = new ValidateProbeInput(probeURL); ValidateProbeOutput ValidateProbeOutput = await subscription.ValidateProbeAsync(validateProbeInput2); Assert.True(ValidateProbeOutput.IsValid); probeURL = "https://www.notexist.com/notexist/notexist.txt"; ValidateProbeInput validateProbeInput3 = new ValidateProbeInput(probeURL); ValidateProbeOutput = await subscription.ValidateProbeAsync(validateProbeInput3); Assert.False(ValidateProbeOutput.IsValid); }
/// <summary> /// Check if the probe path is a valid path and the file can be accessed. Probe /// path is the path to a file hosted on the origin server to help accelerate /// the delivery of dynamic content via the CDN endpoint. This path is relative /// to the origin path specified in the endpoint configuration. /// </summary> /// <param name='probeURL'> /// The probe URL to validate. /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="ErrorResponseException"> /// Thrown when the operation returned an invalid status code /// </exception> /// <exception cref="SerializationException"> /// Thrown when unable to deserialize the response /// </exception> /// <exception cref="ValidationException"> /// Thrown when a required parameter is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when a required parameter is null /// </exception> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <AzureOperationResponse <ValidateProbeOutput> > ValidateProbeWithHttpMessagesAsync(string probeURL, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (SubscriptionId == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.SubscriptionId"); } if (ApiVersion == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.ApiVersion"); } if (probeURL == null) { throw new ValidationException(ValidationRules.CannotBeNull, "probeURL"); } ValidateProbeInput validateProbeInput = new ValidateProbeInput(); if (probeURL != null) { validateProbeInput.ProbeURL = probeURL; } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("validateProbeInput", validateProbeInput); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "ValidateProbe", tracingParameters); } // Construct URL var _baseUrl = BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{subscriptionId}/providers/Microsoft.Cdn/validateProbe").ToString(); _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(SubscriptionId)); List <string> _queryParameters = new List <string>(); if (ApiVersion != null) { _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(ApiVersion))); } if (_queryParameters.Count > 0) { _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); } // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("POST"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (GenerateClientRequestId != null && GenerateClientRequestId.Value) { _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()); } if (AcceptLanguage != null) { if (_httpRequest.Headers.Contains("accept-language")) { _httpRequest.Headers.Remove("accept-language"); } _httpRequest.Headers.TryAddWithoutValidation("accept-language", AcceptLanguage); } if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (validateProbeInput != null) { _requestContent = SafeJsonConvert.SerializeObject(validateProbeInput, SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); } // Set Credentials if (Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 200) { var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); try { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); ErrorResponse _errorBody = SafeJsonConvert.DeserializeObject <ErrorResponse>(_responseContent, DeserializationSettings); if (_errorBody != null) { ex.Body = _errorBody; } } catch (JsonException) { // Ignore the exception } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new AzureOperationResponse <ValidateProbeOutput>(); _result.Request = _httpRequest; _result.Response = _httpResponse; if (_httpResponse.Headers.Contains("x-ms-request-id")) { _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } // Deserialize Response if ((int)_statusCode == 200) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = SafeJsonConvert.DeserializeObject <ValidateProbeOutput>(_responseContent, DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }
public static Response <ValidateProbeOutput> ValidateProbe(this Subscription subscription, ValidateProbeInput validateProbeInput, CancellationToken cancellationToken = default) { if (validateProbeInput == null) { throw new ArgumentNullException(nameof(validateProbeInput)); } return(subscription.UseClientContext((baseUri, credential, options, pipeline) => { var clientDiagnostics = new ClientDiagnostics(options); using var scope = clientDiagnostics.CreateScope("SubscriptionExtensions.ValidateProbe"); scope.Start(); try { CdnManagementRestOperations restOperations = GetCdnManagementRestOperations(clientDiagnostics, pipeline, options, baseUri); var response = restOperations.ValidateProbe(subscription.Id.SubscriptionId, validateProbeInput, cancellationToken); return response; } catch (Exception e) { scope.Failed(e); throw; } } )); }
public static async Task <Response <ValidateProbeOutput> > ValidateProbeAsync(this Subscription subscription, ValidateProbeInput validateProbeInput, CancellationToken cancellationToken = default) { Argument.AssertNotNull(validateProbeInput, nameof(validateProbeInput)); return(await GetExtensionClient(subscription).ValidateProbeAsync(validateProbeInput, cancellationToken).ConfigureAwait(false)); }
public static Response <ValidateProbeOutput> ValidateProbe(this Subscription subscription, ValidateProbeInput validateProbeInput, CancellationToken cancellationToken = default) { Argument.AssertNotNull(validateProbeInput, nameof(validateProbeInput)); return(GetExtensionClient(subscription).ValidateProbe(validateProbeInput, cancellationToken)); }
public async virtual Task <Response <ValidateProbeOutput> > ValidateProbeAsync(ValidateProbeInput validateProbeInput, CancellationToken cancellationToken = default) { using var scope = DefaultClientDiagnostics.CreateScope("SubscriptionExtensionClient.ValidateProbe"); scope.Start(); try { var response = await DefaultRestClient.ValidateProbeAsync(Id.SubscriptionId, validateProbeInput, cancellationToken).ConfigureAwait(false); return(response); } catch (Exception e) { scope.Failed(e); throw; } }
public static Response <ValidateProbeOutput> ValidateProbe(this Subscription subscription, ValidateProbeInput validateProbeInput, CancellationToken cancellationToken = default) { if (validateProbeInput == null) { throw new ArgumentNullException(nameof(validateProbeInput)); } return(GetExtensionClient(subscription).ValidateProbe(validateProbeInput, cancellationToken)); }
public async static Task <Response <ValidateProbeOutput> > ValidateProbeAsync(this Subscription subscription, ValidateProbeInput validateProbeInput, CancellationToken cancellationToken = default) { if (validateProbeInput == null) { throw new ArgumentNullException(nameof(validateProbeInput)); } return(await GetExtensionClient(subscription).ValidateProbeAsync(validateProbeInput, cancellationToken).ConfigureAwait(false)); }
public static Response <ValidateProbeOutput> ValidateProbe(this Subscription subscription, ValidateProbeInput validateProbeInput, CancellationToken cancellationToken = default) { return(GetExtensionClient(subscription).ValidateProbe(validateProbeInput, cancellationToken)); }