/// <summary> /// List all policy snippets. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.ApiManagement.IPolicySnippetsOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group. /// </param> /// <param name='serviceName'> /// Required. The name of the Api Management service. /// </param> /// <param name='scope'> /// Required. Polisy scope. /// </param> /// <returns> /// List policy snippets operation response details. /// </returns> public static PolicySnippetListResponse List(this IPolicySnippetsOperations operations, string resourceGroupName, string serviceName, PolicyScopeContract scope) { return Task.Factory.StartNew((object s) => { return ((IPolicySnippetsOperations)s).ListAsync(resourceGroupName, serviceName, scope); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }
internal static string ToSerializedValue(this PolicyScopeContract value) { switch (value) { case PolicyScopeContract.Tenant: return("Tenant"); case PolicyScopeContract.Product: return("Product"); case PolicyScopeContract.Api: return("Api"); case PolicyScopeContract.Operation: return("Operation"); case PolicyScopeContract.All: return("All"); } return(null); }
/// <summary> /// List all policy snippets. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.ApiManagement.IPolicySnippetsOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group. /// </param> /// <param name='serviceName'> /// Required. The name of the Api Management service. /// </param> /// <param name='scope'> /// Required. Polisy scope. /// </param> /// <returns> /// List policy snippets operation response details. /// </returns> public static Task <PolicySnippetListResponse> ListAsync(this IPolicySnippetsOperations operations, string resourceGroupName, string serviceName, PolicyScopeContract scope) { return(operations.ListAsync(resourceGroupName, serviceName, scope, CancellationToken.None)); }
/// <summary> /// List all policy snippets. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.ApiManagement.IPolicySnippetsOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group. /// </param> /// <param name='serviceName'> /// Required. The name of the Api Management service. /// </param> /// <param name='scope'> /// Required. Polisy scope. /// </param> /// <returns> /// List policy snippets operation response details. /// </returns> public static PolicySnippetListResponse List(this IPolicySnippetsOperations operations, string resourceGroupName, string serviceName, PolicyScopeContract scope) { return(Task.Factory.StartNew((object s) => { return ((IPolicySnippetsOperations)s).ListAsync(resourceGroupName, serviceName, scope); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// List all policy snippets. /// </summary> /// <param name='resourceGroupName'> /// Required. The name of the resource group. /// </param> /// <param name='serviceName'> /// Required. The name of the Api Management service. /// </param> /// <param name='scope'> /// Required. Polisy scope. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// List policy snippets operation response details. /// </returns> public async Task <PolicySnippetListResponse> ListAsync(string resourceGroupName, string serviceName, PolicyScopeContract scope, CancellationToken cancellationToken) { // Validate if (resourceGroupName == null) { throw new ArgumentNullException("resourceGroupName"); } if (serviceName == null) { throw new ArgumentNullException("serviceName"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("resourceGroupName", resourceGroupName); tracingParameters.Add("serviceName", serviceName); tracingParameters.Add("scope", scope); TracingAdapter.Enter(invocationId, this, "ListAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/subscriptions/"; if (this.Client.Credentials.SubscriptionId != null) { url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId); } url = url + "/resourceGroups/"; url = url + Uri.EscapeDataString(resourceGroupName); url = url + "/providers/"; url = url + "Microsoft.ApiManagement"; url = url + "/service/"; url = url + Uri.EscapeDataString(serviceName); url = url + "/policy-snippets"; List <string> queryParameters = new List <string>(); queryParameters.Add("api-version=2014-02-14"); queryParameters.Add("scope=" + Uri.EscapeDataString(scope.ToString())); 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.Get; httpRequest.RequestUri = new Uri(url); // Set Headers // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // 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) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { TracingAdapter.Error(invocationId, ex); } throw ex; } // Create Result PolicySnippetListResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new PolicySnippetListResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { JToken valuesArray = responseDoc; if (valuesArray != null && valuesArray.Type != JTokenType.Null) { foreach (JToken valuesValue in ((JArray)valuesArray)) { PolicySnippetContract policySnippetContractInstance = new PolicySnippetContract(); result.Values.Add(policySnippetContractInstance); JToken nameValue = valuesValue["name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); policySnippetContractInstance.Name = nameInstance; } JToken contentValue = valuesValue["content"]; if (contentValue != null && contentValue.Type != JTokenType.Null) { string contentInstance = ((string)contentValue); policySnippetContractInstance.Content = contentInstance; } JToken toolTipValue = valuesValue["toolTip"]; if (toolTipValue != null && toolTipValue.Type != JTokenType.Null) { string toolTipInstance = ((string)toolTipValue); policySnippetContractInstance.ToolTip = toolTipInstance; } JToken scopeValue = valuesValue["scope"]; if (scopeValue != null && scopeValue.Type != JTokenType.Null) { PolicyScopeContract scopeInstance = ((PolicyScopeContract)Enum.Parse(typeof(PolicyScopeContract), ((string)scopeValue), true)); policySnippetContractInstance.Scope = scopeInstance; } } } } } 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(); } } }
/// <summary> /// List all policy snippets. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.ApiManagement.IPolicySnippetsOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group. /// </param> /// <param name='serviceName'> /// Required. The name of the Api Management service. /// </param> /// <param name='scope'> /// Required. Polisy scope. /// </param> /// <returns> /// List policy snippets operation response details. /// </returns> public static Task<PolicySnippetListResponse> ListAsync(this IPolicySnippetsOperations operations, string resourceGroupName, string serviceName, PolicyScopeContract scope) { return operations.ListAsync(resourceGroupName, serviceName, scope, CancellationToken.None); }