/// <summary> /// List all API associated products. /// </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='aid'> /// Required. Identifier of the API. /// </param> /// <param name='query'> /// Optional. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// List Products operation response details. /// </returns> public async Task <ProductListResponse> ListAsync(string resourceGroupName, string serviceName, string aid, QueryParameters query, CancellationToken cancellationToken) { // Validate if (resourceGroupName == null) { throw new ArgumentNullException("resourceGroupName"); } if (serviceName == null) { throw new ArgumentNullException("serviceName"); } if (aid == null) { throw new ArgumentNullException("aid"); } // 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("aid", aid); tracingParameters.Add("query", query); 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 + "/apis/"; url = url + Uri.EscapeDataString(aid); url = url + "/products"; List <string> queryParameters = new List <string>(); queryParameters.Add("api-version=2014-02-14"); List <string> odataFilter = new List <string>(); if (query != null && query.Filter != null) { odataFilter.Add(Uri.EscapeDataString(query.Filter)); } if (odataFilter.Count > 0) { queryParameters.Add("$filter=" + string.Join(null, odataFilter)); } if (query != null && query.Top != null) { queryParameters.Add("$top=" + Uri.EscapeDataString(query.Top.Value.ToString())); } if (query != null && query.Skip != null) { queryParameters.Add("$skip=" + Uri.EscapeDataString(query.Skip.Value.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 ProductListResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new ProductListResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { ProductPaged resultInstance = new ProductPaged(); result.Result = resultInstance; JToken valueArray = responseDoc["value"]; if (valueArray != null && valueArray.Type != JTokenType.Null) { foreach (JToken valueValue in ((JArray)valueArray)) { ProductContract productContractInstance = new ProductContract(); resultInstance.Values.Add(productContractInstance); JToken idValue = valueValue["id"]; if (idValue != null && idValue.Type != JTokenType.Null) { string idInstance = ((string)idValue); productContractInstance.IdPath = idInstance; } JToken nameValue = valueValue["name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); productContractInstance.Name = nameInstance; } JToken descriptionValue = valueValue["description"]; if (descriptionValue != null && descriptionValue.Type != JTokenType.Null) { string descriptionInstance = ((string)descriptionValue); productContractInstance.Description = descriptionInstance; } JToken termsValue = valueValue["terms"]; if (termsValue != null && termsValue.Type != JTokenType.Null) { string termsInstance = ((string)termsValue); productContractInstance.Terms = termsInstance; } JToken subscriptionRequiredValue = valueValue["subscriptionRequired"]; if (subscriptionRequiredValue != null && subscriptionRequiredValue.Type != JTokenType.Null) { bool subscriptionRequiredInstance = ((bool)subscriptionRequiredValue); productContractInstance.SubscriptionRequired = subscriptionRequiredInstance; } JToken approvalRequiredValue = valueValue["approvalRequired"]; if (approvalRequiredValue != null && approvalRequiredValue.Type != JTokenType.Null) { bool approvalRequiredInstance = ((bool)approvalRequiredValue); productContractInstance.ApprovalRequired = approvalRequiredInstance; } JToken subscriptionsLimitValue = valueValue["subscriptionsLimit"]; if (subscriptionsLimitValue != null && subscriptionsLimitValue.Type != JTokenType.Null) { int subscriptionsLimitInstance = ((int)subscriptionsLimitValue); productContractInstance.SubscriptionsLimit = subscriptionsLimitInstance; } JToken subscriptionPeriodValue = valueValue["subscriptionPeriod"]; if (subscriptionPeriodValue != null && subscriptionPeriodValue.Type != JTokenType.Null) { PeriodContract subscriptionPeriodInstance = new PeriodContract(); productContractInstance.SubscriptionPeriod = subscriptionPeriodInstance; JToken valueValue2 = subscriptionPeriodValue["value"]; if (valueValue2 != null && valueValue2.Type != JTokenType.Null) { int valueInstance = ((int)valueValue2); subscriptionPeriodInstance.Value = valueInstance; } JToken intervalValue = subscriptionPeriodValue["interval"]; if (intervalValue != null && intervalValue.Type != JTokenType.Null) { PeriodIntervalContract intervalInstance = ((PeriodIntervalContract)Enum.Parse(typeof(PeriodIntervalContract), ((string)intervalValue), true)); subscriptionPeriodInstance.Interval = intervalInstance; } } JToken notificationPeriodValue = valueValue["notificationPeriod"]; if (notificationPeriodValue != null && notificationPeriodValue.Type != JTokenType.Null) { PeriodContract notificationPeriodInstance = new PeriodContract(); productContractInstance.NotificationPeriod = notificationPeriodInstance; JToken valueValue3 = notificationPeriodValue["value"]; if (valueValue3 != null && valueValue3.Type != JTokenType.Null) { int valueInstance2 = ((int)valueValue3); notificationPeriodInstance.Value = valueInstance2; } JToken intervalValue2 = notificationPeriodValue["interval"]; if (intervalValue2 != null && intervalValue2.Type != JTokenType.Null) { PeriodIntervalContract intervalInstance2 = ((PeriodIntervalContract)Enum.Parse(typeof(PeriodIntervalContract), ((string)intervalValue2), true)); notificationPeriodInstance.Interval = intervalInstance2; } } JToken stateValue = valueValue["state"]; if (stateValue != null && stateValue.Type != JTokenType.Null) { ProductStateContract stateInstance = ((ProductStateContract)Enum.Parse(typeof(ProductStateContract), ((string)stateValue), true)); productContractInstance.State = stateInstance; } } } JToken countValue = responseDoc["count"]; if (countValue != null && countValue.Type != JTokenType.Null) { long countInstance = ((long)countValue); resultInstance.TotalCount = countInstance; } JToken nextLinkValue = responseDoc["nextLink"]; if (nextLinkValue != null && nextLinkValue.Type != JTokenType.Null) { string nextLinkInstance = ((string)nextLinkValue); resultInstance.NextLink = nextLinkInstance; } } } 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 API associated products. /// </summary> /// <param name='nextLink'> /// Required. NextLink from the previous successful call to List /// operation. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// List Products operation response details. /// </returns> public async Task <ProductListResponse> ListNextAsync(string nextLink, CancellationToken cancellationToken) { // Validate if (nextLink == null) { throw new ArgumentNullException("nextLink"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("nextLink", nextLink); TracingAdapter.Enter(invocationId, this, "ListNextAsync", tracingParameters); } // Construct URL string url = ""; url = url + nextLink; 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 ProductListResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new ProductListResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { ProductPaged resultInstance = new ProductPaged(); result.Result = resultInstance; JToken valueArray = responseDoc["value"]; if (valueArray != null && valueArray.Type != JTokenType.Null) { foreach (JToken valueValue in ((JArray)valueArray)) { ProductContract productContractInstance = new ProductContract(); resultInstance.Values.Add(productContractInstance); JToken idValue = valueValue["id"]; if (idValue != null && idValue.Type != JTokenType.Null) { string idInstance = ((string)idValue); productContractInstance.IdPath = idInstance; } JToken nameValue = valueValue["name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); productContractInstance.Name = nameInstance; } JToken descriptionValue = valueValue["description"]; if (descriptionValue != null && descriptionValue.Type != JTokenType.Null) { string descriptionInstance = ((string)descriptionValue); productContractInstance.Description = descriptionInstance; } JToken termsValue = valueValue["terms"]; if (termsValue != null && termsValue.Type != JTokenType.Null) { string termsInstance = ((string)termsValue); productContractInstance.Terms = termsInstance; } JToken subscriptionRequiredValue = valueValue["subscriptionRequired"]; if (subscriptionRequiredValue != null && subscriptionRequiredValue.Type != JTokenType.Null) { bool subscriptionRequiredInstance = ((bool)subscriptionRequiredValue); productContractInstance.SubscriptionRequired = subscriptionRequiredInstance; } JToken approvalRequiredValue = valueValue["approvalRequired"]; if (approvalRequiredValue != null && approvalRequiredValue.Type != JTokenType.Null) { bool approvalRequiredInstance = ((bool)approvalRequiredValue); productContractInstance.ApprovalRequired = approvalRequiredInstance; } JToken subscriptionsLimitValue = valueValue["subscriptionsLimit"]; if (subscriptionsLimitValue != null && subscriptionsLimitValue.Type != JTokenType.Null) { int subscriptionsLimitInstance = ((int)subscriptionsLimitValue); productContractInstance.SubscriptionsLimit = subscriptionsLimitInstance; } JToken subscriptionPeriodValue = valueValue["subscriptionPeriod"]; if (subscriptionPeriodValue != null && subscriptionPeriodValue.Type != JTokenType.Null) { PeriodContract subscriptionPeriodInstance = new PeriodContract(); productContractInstance.SubscriptionPeriod = subscriptionPeriodInstance; JToken valueValue2 = subscriptionPeriodValue["value"]; if (valueValue2 != null && valueValue2.Type != JTokenType.Null) { int valueInstance = ((int)valueValue2); subscriptionPeriodInstance.Value = valueInstance; } JToken intervalValue = subscriptionPeriodValue["interval"]; if (intervalValue != null && intervalValue.Type != JTokenType.Null) { PeriodIntervalContract intervalInstance = ((PeriodIntervalContract)Enum.Parse(typeof(PeriodIntervalContract), ((string)intervalValue), true)); subscriptionPeriodInstance.Interval = intervalInstance; } } JToken notificationPeriodValue = valueValue["notificationPeriod"]; if (notificationPeriodValue != null && notificationPeriodValue.Type != JTokenType.Null) { PeriodContract notificationPeriodInstance = new PeriodContract(); productContractInstance.NotificationPeriod = notificationPeriodInstance; JToken valueValue3 = notificationPeriodValue["value"]; if (valueValue3 != null && valueValue3.Type != JTokenType.Null) { int valueInstance2 = ((int)valueValue3); notificationPeriodInstance.Value = valueInstance2; } JToken intervalValue2 = notificationPeriodValue["interval"]; if (intervalValue2 != null && intervalValue2.Type != JTokenType.Null) { PeriodIntervalContract intervalInstance2 = ((PeriodIntervalContract)Enum.Parse(typeof(PeriodIntervalContract), ((string)intervalValue2), true)); notificationPeriodInstance.Interval = intervalInstance2; } } JToken stateValue = valueValue["state"]; if (stateValue != null && stateValue.Type != JTokenType.Null) { ProductStateContract stateInstance = ((ProductStateContract)Enum.Parse(typeof(ProductStateContract), ((string)stateValue), true)); productContractInstance.State = stateInstance; } } } JToken countValue = responseDoc["count"]; if (countValue != null && countValue.Type != JTokenType.Null) { long countInstance = ((long)countValue); resultInstance.TotalCount = countInstance; } JToken nextLinkValue = responseDoc["nextLink"]; if (nextLinkValue != null && nextLinkValue.Type != JTokenType.Null) { string nextLinkInstance = ((string)nextLinkValue); resultInstance.NextLink = nextLinkInstance; } } } 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(); } } }