/// <summary> /// Puts the new diagnostic settings. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.Insights.IAgentDiagnosticSettingsOperations. /// </param> /// <param name='resourceUri'> /// Required. The resource uri. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the operation. /// </param> /// <returns> /// Generic empty response. We only pass it to ensure json error /// handling /// </returns> public static Task <EmptyResponse> PutAsync(this IAgentDiagnosticSettingsOperations operations, string resourceUri, AgentDiagnosticSettgingsPutParameters parameters) { return(operations.PutAsync(resourceUri, parameters, CancellationToken.None)); }
/// <summary> /// Puts the new diagnostic settings. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.Insights.IAgentDiagnosticSettingsOperations. /// </param> /// <param name='resourceUri'> /// Required. The resource uri. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the operation. /// </param> /// <returns> /// Generic empty response. We only pass it to ensure json error /// handling /// </returns> public static EmptyResponse Put(this IAgentDiagnosticSettingsOperations operations, string resourceUri, AgentDiagnosticSettgingsPutParameters parameters) { return(Task.Factory.StartNew((object s) => { return ((IAgentDiagnosticSettingsOperations)s).PutAsync(resourceUri, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Puts the new diagnostic settings. /// </summary> /// <param name='resourceUri'> /// Required. The resource uri. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the operation. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// Generic empty response. We only pass it to ensure json error /// handling /// </returns> public async Task <EmptyResponse> PutAsync(string resourceUri, AgentDiagnosticSettgingsPutParameters parameters, CancellationToken cancellationToken) { // Validate if (resourceUri == null) { throw new ArgumentNullException("resourceUri"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("resourceUri", resourceUri); tracingParameters.Add("parameters", parameters); TracingAdapter.Enter(invocationId, this, "PutAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/"; url = url + Uri.EscapeDataString(resourceUri); url = url + "/diagnosticSettings/agent"; List <string> queryParameters = new List <string>(); queryParameters.Add("api-version=2014-04-01"); if (queryParameters.Count > 0) { url = url + "?" + string.Join("&", queryParameters); } string baseUrl = this.Client.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Put; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("Accept", "application/json"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Serialize Request string requestContent = null; JToken requestDoc = null; JObject agentDiagnosticSettgingsPutParametersValue = new JObject(); requestDoc = agentDiagnosticSettgingsPutParametersValue; if (parameters.Properties != null) { JObject propertiesValue = new JObject(); agentDiagnosticSettgingsPutParametersValue["properties"] = propertiesValue; if (parameters.Properties.Name != null) { propertiesValue["name"] = parameters.Properties.Name; } if (parameters.Properties.Description != null) { propertiesValue["description"] = parameters.Properties.Description; } if (parameters.Properties.PublicConfiguration != null) { JObject publicConfigurationValue = new JObject(); propertiesValue["publicConfiguration"] = publicConfigurationValue; } } requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented); httpRequest.Content = new StringContent(requestContent, Encoding.UTF8); httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { TracingAdapter.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { TracingAdapter.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.Created && statusCode != HttpStatusCode.Accepted) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { TracingAdapter.Error(invocationId, ex); } throw ex; } // Create Result EmptyResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK || statusCode == HttpStatusCode.Created || statusCode == HttpStatusCode.Accepted) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new EmptyResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { TracingAdapter.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }