/// <summary> /// Lists report records. /// </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='aggregation'> /// Required. Report aggregation. /// </param> /// <param name='query'> /// Optional. /// </param> /// <param name='interval'> /// Optional. By time interval. This value is only applicable to ByTime /// aggregation. Interval must be multiple of 15 minutes and may not /// be zero. The value should be in ISO 8601 format /// (http://en.wikipedia.org/wiki/ISO_8601#Durations).This code can be /// used to convert TimSpan to a valid interval string: /// XmlConvert.ToString(new TimeSpan(hours, minutes, secconds)) /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// List Report records operation response details. /// </returns> public async Task <ReportListResponse> ListAsync(string resourceGroupName, string serviceName, ReportsAggregation aggregation, QueryParameters query, string interval, 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("aggregation", aggregation); tracingParameters.Add("query", query); tracingParameters.Add("interval", interval); 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 + "/reports/"; url = url + Uri.EscapeDataString(ApiManagementClient.ReportsAggregationToString(aggregation)); List <string> queryParameters = new List <string>(); queryParameters.Add("api-version=2016-10-10"); 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 (interval != null) { queryParameters.Add("interval=" + Uri.EscapeDataString(interval)); } 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 ReportListResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new ReportListResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { ReportPaged resultInstance = new ReportPaged(); result.Result = resultInstance; JToken valueArray = responseDoc["value"]; if (valueArray != null && valueArray.Type != JTokenType.Null) { foreach (JToken valueValue in ((JArray)valueArray)) { ReportRecordContract reportRecordContractInstance = new ReportRecordContract(); resultInstance.Values.Add(reportRecordContractInstance); JToken nameValue = valueValue["name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); reportRecordContractInstance.Name = nameInstance; } JToken timestampValue = valueValue["timestamp"]; if (timestampValue != null && timestampValue.Type != JTokenType.Null) { DateTime timestampInstance = ((DateTime)timestampValue); reportRecordContractInstance.Timestamp = timestampInstance; } JToken intervalValue = valueValue["interval"]; if (intervalValue != null && intervalValue.Type != JTokenType.Null) { TimeSpan intervalInstance = TimeSpan.Parse(((string)intervalValue), CultureInfo.InvariantCulture); reportRecordContractInstance.Interval = intervalInstance; } JToken countryValue = valueValue["country"]; if (countryValue != null && countryValue.Type != JTokenType.Null) { string countryInstance = ((string)countryValue); reportRecordContractInstance.Country = countryInstance; } JToken regionValue = valueValue["region"]; if (regionValue != null && regionValue.Type != JTokenType.Null) { string regionInstance = ((string)regionValue); reportRecordContractInstance.Region = regionInstance; } JToken zipValue = valueValue["zip"]; if (zipValue != null && zipValue.Type != JTokenType.Null) { string zipInstance = ((string)zipValue); reportRecordContractInstance.Zip = zipInstance; } JToken userIdValue = valueValue["userId"]; if (userIdValue != null && userIdValue.Type != JTokenType.Null) { string userIdInstance = ((string)userIdValue); reportRecordContractInstance.UserIdPath = userIdInstance; } JToken productIdValue = valueValue["productId"]; if (productIdValue != null && productIdValue.Type != JTokenType.Null) { string productIdInstance = ((string)productIdValue); reportRecordContractInstance.ProductIdPath = productIdInstance; } JToken apiIdValue = valueValue["apiId"]; if (apiIdValue != null && apiIdValue.Type != JTokenType.Null) { string apiIdInstance = ((string)apiIdValue); reportRecordContractInstance.ApiIdPath = apiIdInstance; } JToken operationIdValue = valueValue["operationId"]; if (operationIdValue != null && operationIdValue.Type != JTokenType.Null) { string operationIdInstance = ((string)operationIdValue); reportRecordContractInstance.OperationIdPath = operationIdInstance; } JToken apiRegionValue = valueValue["apiRegion"]; if (apiRegionValue != null && apiRegionValue.Type != JTokenType.Null) { string apiRegionInstance = ((string)apiRegionValue); reportRecordContractInstance.ApiRegion = apiRegionInstance; } JToken subscriptionIdValue = valueValue["subscriptionId"]; if (subscriptionIdValue != null && subscriptionIdValue.Type != JTokenType.Null) { string subscriptionIdInstance = ((string)subscriptionIdValue); reportRecordContractInstance.SubscriptionIdPath = subscriptionIdInstance; } JToken callCountSuccessValue = valueValue["callCountSuccess"]; if (callCountSuccessValue != null && callCountSuccessValue.Type != JTokenType.Null) { int callCountSuccessInstance = ((int)callCountSuccessValue); reportRecordContractInstance.CallCountSuccess = callCountSuccessInstance; } JToken callCountBlockedValue = valueValue["callCountBlocked"]; if (callCountBlockedValue != null && callCountBlockedValue.Type != JTokenType.Null) { int callCountBlockedInstance = ((int)callCountBlockedValue); reportRecordContractInstance.CallCountBlocked = callCountBlockedInstance; } JToken callCountFailedValue = valueValue["callCountFailed"]; if (callCountFailedValue != null && callCountFailedValue.Type != JTokenType.Null) { int callCountFailedInstance = ((int)callCountFailedValue); reportRecordContractInstance.CallCountFailed = callCountFailedInstance; } JToken callCountOtherValue = valueValue["callCountOther"]; if (callCountOtherValue != null && callCountOtherValue.Type != JTokenType.Null) { int callCountOtherInstance = ((int)callCountOtherValue); reportRecordContractInstance.CallCountOther = callCountOtherInstance; } JToken callCountTotalValue = valueValue["callCountTotal"]; if (callCountTotalValue != null && callCountTotalValue.Type != JTokenType.Null) { int callCountTotalInstance = ((int)callCountTotalValue); reportRecordContractInstance.CallCountTotal = callCountTotalInstance; } JToken bandwidthValue = valueValue["bandwidth"]; if (bandwidthValue != null && bandwidthValue.Type != JTokenType.Null) { long bandwidthInstance = ((long)bandwidthValue); reportRecordContractInstance.Bandwidth = bandwidthInstance; } JToken cacheHitCountValue = valueValue["cacheHitCount"]; if (cacheHitCountValue != null && cacheHitCountValue.Type != JTokenType.Null) { int cacheHitCountInstance = ((int)cacheHitCountValue); reportRecordContractInstance.CacheHitCount = cacheHitCountInstance; } JToken cacheMissCountValue = valueValue["cacheMissCount"]; if (cacheMissCountValue != null && cacheMissCountValue.Type != JTokenType.Null) { int cacheMissCountInstance = ((int)cacheMissCountValue); reportRecordContractInstance.CacheMissCount = cacheMissCountInstance; } JToken apiTimeAvgValue = valueValue["apiTimeAvg"]; if (apiTimeAvgValue != null && apiTimeAvgValue.Type != JTokenType.Null) { double apiTimeAvgInstance = ((double)apiTimeAvgValue); reportRecordContractInstance.ApiTimeAvg = apiTimeAvgInstance; } JToken apiTimeMinValue = valueValue["apiTimeMin"]; if (apiTimeMinValue != null && apiTimeMinValue.Type != JTokenType.Null) { double apiTimeMinInstance = ((double)apiTimeMinValue); reportRecordContractInstance.ApiTimeMin = apiTimeMinInstance; } JToken apiTimeMaxValue = valueValue["apiTimeMax"]; if (apiTimeMaxValue != null && apiTimeMaxValue.Type != JTokenType.Null) { double apiTimeMaxInstance = ((double)apiTimeMaxValue); reportRecordContractInstance.ApiTimeMax = apiTimeMaxInstance; } JToken serviceTimeAvgValue = valueValue["serviceTimeAvg"]; if (serviceTimeAvgValue != null && serviceTimeAvgValue.Type != JTokenType.Null) { double serviceTimeAvgInstance = ((double)serviceTimeAvgValue); reportRecordContractInstance.ServiceTimeAvg = serviceTimeAvgInstance; } JToken serviceTimeMinValue = valueValue["serviceTimeMin"]; if (serviceTimeMinValue != null && serviceTimeMinValue.Type != JTokenType.Null) { double serviceTimeMinInstance = ((double)serviceTimeMinValue); reportRecordContractInstance.ServiceTimeMin = serviceTimeMinInstance; } JToken serviceTimeMaxValue = valueValue["serviceTimeMax"]; if (serviceTimeMaxValue != null && serviceTimeMaxValue.Type != JTokenType.Null) { double serviceTimeMaxInstance = ((double)serviceTimeMaxValue); reportRecordContractInstance.ServiceTimeMax = serviceTimeMaxInstance; } } } 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 report records. /// </summary> /// <param name='nextLink'> /// Required. NextLink from the previous successful call to List /// operation. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// List Report records operation response details. /// </returns> public async Task <ReportListResponse> 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 ReportListResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new ReportListResponse(); JToken responseDoc = null; if (string.IsNullOrEmpty(responseContent) == false) { responseDoc = JToken.Parse(responseContent); } if (responseDoc != null && responseDoc.Type != JTokenType.Null) { ReportPaged resultInstance = new ReportPaged(); result.Result = resultInstance; JToken valueArray = responseDoc["value"]; if (valueArray != null && valueArray.Type != JTokenType.Null) { foreach (JToken valueValue in ((JArray)valueArray)) { ReportRecordContract reportRecordContractInstance = new ReportRecordContract(); resultInstance.Values.Add(reportRecordContractInstance); JToken nameValue = valueValue["name"]; if (nameValue != null && nameValue.Type != JTokenType.Null) { string nameInstance = ((string)nameValue); reportRecordContractInstance.Name = nameInstance; } JToken timestampValue = valueValue["timestamp"]; if (timestampValue != null && timestampValue.Type != JTokenType.Null) { DateTime timestampInstance = ((DateTime)timestampValue); reportRecordContractInstance.Timestamp = timestampInstance; } JToken intervalValue = valueValue["interval"]; if (intervalValue != null && intervalValue.Type != JTokenType.Null) { TimeSpan intervalInstance = TimeSpan.Parse(((string)intervalValue), CultureInfo.InvariantCulture); reportRecordContractInstance.Interval = intervalInstance; } JToken countryValue = valueValue["country"]; if (countryValue != null && countryValue.Type != JTokenType.Null) { string countryInstance = ((string)countryValue); reportRecordContractInstance.Country = countryInstance; } JToken regionValue = valueValue["region"]; if (regionValue != null && regionValue.Type != JTokenType.Null) { string regionInstance = ((string)regionValue); reportRecordContractInstance.Region = regionInstance; } JToken zipValue = valueValue["zip"]; if (zipValue != null && zipValue.Type != JTokenType.Null) { string zipInstance = ((string)zipValue); reportRecordContractInstance.Zip = zipInstance; } JToken userIdValue = valueValue["userId"]; if (userIdValue != null && userIdValue.Type != JTokenType.Null) { string userIdInstance = ((string)userIdValue); reportRecordContractInstance.UserIdPath = userIdInstance; } JToken productIdValue = valueValue["productId"]; if (productIdValue != null && productIdValue.Type != JTokenType.Null) { string productIdInstance = ((string)productIdValue); reportRecordContractInstance.ProductIdPath = productIdInstance; } JToken apiIdValue = valueValue["apiId"]; if (apiIdValue != null && apiIdValue.Type != JTokenType.Null) { string apiIdInstance = ((string)apiIdValue); reportRecordContractInstance.ApiIdPath = apiIdInstance; } JToken operationIdValue = valueValue["operationId"]; if (operationIdValue != null && operationIdValue.Type != JTokenType.Null) { string operationIdInstance = ((string)operationIdValue); reportRecordContractInstance.OperationIdPath = operationIdInstance; } JToken apiRegionValue = valueValue["apiRegion"]; if (apiRegionValue != null && apiRegionValue.Type != JTokenType.Null) { string apiRegionInstance = ((string)apiRegionValue); reportRecordContractInstance.ApiRegion = apiRegionInstance; } JToken subscriptionIdValue = valueValue["subscriptionId"]; if (subscriptionIdValue != null && subscriptionIdValue.Type != JTokenType.Null) { string subscriptionIdInstance = ((string)subscriptionIdValue); reportRecordContractInstance.SubscriptionIdPath = subscriptionIdInstance; } JToken callCountSuccessValue = valueValue["callCountSuccess"]; if (callCountSuccessValue != null && callCountSuccessValue.Type != JTokenType.Null) { int callCountSuccessInstance = ((int)callCountSuccessValue); reportRecordContractInstance.CallCountSuccess = callCountSuccessInstance; } JToken callCountBlockedValue = valueValue["callCountBlocked"]; if (callCountBlockedValue != null && callCountBlockedValue.Type != JTokenType.Null) { int callCountBlockedInstance = ((int)callCountBlockedValue); reportRecordContractInstance.CallCountBlocked = callCountBlockedInstance; } JToken callCountFailedValue = valueValue["callCountFailed"]; if (callCountFailedValue != null && callCountFailedValue.Type != JTokenType.Null) { int callCountFailedInstance = ((int)callCountFailedValue); reportRecordContractInstance.CallCountFailed = callCountFailedInstance; } JToken callCountOtherValue = valueValue["callCountOther"]; if (callCountOtherValue != null && callCountOtherValue.Type != JTokenType.Null) { int callCountOtherInstance = ((int)callCountOtherValue); reportRecordContractInstance.CallCountOther = callCountOtherInstance; } JToken callCountTotalValue = valueValue["callCountTotal"]; if (callCountTotalValue != null && callCountTotalValue.Type != JTokenType.Null) { int callCountTotalInstance = ((int)callCountTotalValue); reportRecordContractInstance.CallCountTotal = callCountTotalInstance; } JToken bandwidthValue = valueValue["bandwidth"]; if (bandwidthValue != null && bandwidthValue.Type != JTokenType.Null) { long bandwidthInstance = ((long)bandwidthValue); reportRecordContractInstance.Bandwidth = bandwidthInstance; } JToken cacheHitCountValue = valueValue["cacheHitCount"]; if (cacheHitCountValue != null && cacheHitCountValue.Type != JTokenType.Null) { int cacheHitCountInstance = ((int)cacheHitCountValue); reportRecordContractInstance.CacheHitCount = cacheHitCountInstance; } JToken cacheMissCountValue = valueValue["cacheMissCount"]; if (cacheMissCountValue != null && cacheMissCountValue.Type != JTokenType.Null) { int cacheMissCountInstance = ((int)cacheMissCountValue); reportRecordContractInstance.CacheMissCount = cacheMissCountInstance; } JToken apiTimeAvgValue = valueValue["apiTimeAvg"]; if (apiTimeAvgValue != null && apiTimeAvgValue.Type != JTokenType.Null) { double apiTimeAvgInstance = ((double)apiTimeAvgValue); reportRecordContractInstance.ApiTimeAvg = apiTimeAvgInstance; } JToken apiTimeMinValue = valueValue["apiTimeMin"]; if (apiTimeMinValue != null && apiTimeMinValue.Type != JTokenType.Null) { double apiTimeMinInstance = ((double)apiTimeMinValue); reportRecordContractInstance.ApiTimeMin = apiTimeMinInstance; } JToken apiTimeMaxValue = valueValue["apiTimeMax"]; if (apiTimeMaxValue != null && apiTimeMaxValue.Type != JTokenType.Null) { double apiTimeMaxInstance = ((double)apiTimeMaxValue); reportRecordContractInstance.ApiTimeMax = apiTimeMaxInstance; } JToken serviceTimeAvgValue = valueValue["serviceTimeAvg"]; if (serviceTimeAvgValue != null && serviceTimeAvgValue.Type != JTokenType.Null) { double serviceTimeAvgInstance = ((double)serviceTimeAvgValue); reportRecordContractInstance.ServiceTimeAvg = serviceTimeAvgInstance; } JToken serviceTimeMinValue = valueValue["serviceTimeMin"]; if (serviceTimeMinValue != null && serviceTimeMinValue.Type != JTokenType.Null) { double serviceTimeMinInstance = ((double)serviceTimeMinValue); reportRecordContractInstance.ServiceTimeMin = serviceTimeMinInstance; } JToken serviceTimeMaxValue = valueValue["serviceTimeMax"]; if (serviceTimeMaxValue != null && serviceTimeMaxValue.Type != JTokenType.Null) { double serviceTimeMaxInstance = ((double)serviceTimeMaxValue); reportRecordContractInstance.ServiceTimeMax = serviceTimeMaxInstance; } } } 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(); } } }