示例#1
0
        public static string GetDefaultSignalRLocation(ResourceManagementClient client)
        {
            Provider             provider     = client.Providers.Get(SignalRNamespace);
            ProviderResourceType resourceType = provider.ResourceTypes.First(
                t => StringComparer.OrdinalIgnoreCase.Equals(t.ResourceType, SignalRResourceTypeName));

            return(resourceType.Locations.First());
        }
示例#2
0
        public static string GetNonDefaultRegistryLocation(ResourceManagementClient client, string defaultLocation)
        {
            Provider             provider     = client.Providers.Get(ContainerRegistryNamespace);
            ProviderResourceType resourceType = provider.ResourceTypes.First(
                t => StringComparer.OrdinalIgnoreCase.Equals(t.ResourceType, ContainerRegistryResourceType));

            return(resourceType.Locations.First(l => !NormalizeLocation(l).Equals(defaultLocation)));
        }
示例#3
0
        /// <summary>
        /// Gets all locations of deleted sites resource
        /// </summary>
        public IEnumerable <string> GetDeletedSitesLocations()
        {
            Provider             webProvider = ResourceManagementClient.Providers.Get("Microsoft.Web");
            ProviderResourceType resType     = webProvider.ResourceTypes.First((rt) =>
            {
                return(string.Equals(rt.ResourceType, "deletedSites", StringComparison.InvariantCultureIgnoreCase));
            });

            return(resType.Locations);
        }
        /// <summary>
        /// Initializes new instance of the <see cref="SchedulerClient"/> class.
        /// </summary>
        /// <param name="context">The Azure context reference.</param>
        public SchedulerClient(IAzureContext context)
        {
            this.SchedulerManagementClient = AzureSession.Instance.ClientFactory.CreateArmClient <SchedulerManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager);
            this._resourceManagementClient = AzureSession.Instance.ClientFactory.CreateClient <ResourceManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager);

            ProviderResourceType providerResourceType = _resourceManagementClient.Providers.Get(Constants.ProviderNamespace).Provider.ResourceTypes.First((resourceType) => resourceType.Name.Equals(Constants.ResourceType, StringComparison.InvariantCultureIgnoreCase));

            _availableRegions = providerResourceType != null ? providerResourceType.Locations : null;

            this.SchedulerManagementClient.SubscriptionId = context.Subscription.Id.ToString();
        }
示例#5
0
        /// <summary>
        /// Obtains a list of locations via the specified <see cref="Microsoft.Azure.Management.Resources.IResourceManagementClient"/>
        /// and prompts the user to select a location from the list.
        /// </summary>
        /// <param name="resourceManagementClient">The <see cref="Microsoft.Azure.Management.Resources.IResourceManagementClient"/>
        /// to use when obtaining a list of datacenter locations.</param>
        /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns>
        private static async Task <string> PromptUserForLocationAsync(IResourceManagementClient resourceManagementClient)
        {
            // Obtain the list of available datacenter locations for Batch accounts supported by this subscription
            ProviderGetResult batchProvider = await resourceManagementClient.Providers.GetAsync(BatchNameSpace);

            ProviderResourceType batchResource = batchProvider.Provider.ResourceTypes.Where(p => p.Name == BatchAccountResourceType).First();

            string[] locations = batchResource.Locations.ToArray();

            // Ask the user where they would like to create the resource group and account
            return(PromptForSelectionFromCollection(locations, "Enter the number of the location where you'd like to create your Batch account: "));
        }
示例#6
0
        /// <summary>
        /// Returns the API version to use for getting data for resources of the specified provider and type.
        /// This method always returns the latest API version that is not a preview version.
        /// </summary>
        /// <param name="client">The ARM client.</param>
        /// <param name="provider">The provider name.</param>
        /// <param name="type">The resource type.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A <see cref="Task{TResult}"/>, returning the API version.</returns>
        private async Task <string> GetLatestApiVersionAsync(ResourceManagementClient client, string provider, string type, CancellationToken cancellationToken)
        {
            ProviderInner providerInformation = await this.GetProviderInformationAsync(client, provider, cancellationToken);

            ProviderResourceType providerResourceType = providerInformation.ResourceTypes.FirstOrDefault(resourceType => resourceType.ResourceType.Equals(type, StringComparison.CurrentCultureIgnoreCase));

            if (providerResourceType == null)
            {
                throw new ArgumentException($"Provider {provider} does not support type {type}");
            }

            return(providerResourceType.ApiVersions.Where(version => version.Contains("preview") == false).Max());
        }
示例#7
0
        internal static ProviderData DeserializeProvider(JsonElement element)
        {
            Optional <string> id                 = default;
            Optional <string> @namespace         = default;
            Optional <string> registrationState  = default;
            Optional <string> registrationPolicy = default;
            Optional <IReadOnlyList <ProviderResourceType> > resourceTypes = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("id"))
                {
                    id = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("namespace"))
                {
                    @namespace = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("registrationState"))
                {
                    registrationState = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("registrationPolicy"))
                {
                    registrationPolicy = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("resourceTypes"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <ProviderResourceType> array = new List <ProviderResourceType>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(ProviderResourceType.DeserializeProviderResourceType(item));
                    }
                    resourceTypes = array;
                    continue;
                }
            }
            return(new ProviderData(id.Value, @namespace.Value, registrationState.Value, registrationPolicy.Value, Optional.ToList(resourceTypes)));
        }
        public static PSResourceProviderType ToPSResourceProviderType(this ProviderResourceType resourceType, string providerNamespace)
        {
            PSResourceProviderType result = new PSResourceProviderType();

            if (resourceType != null)
            {
                resourceType.Locations = resourceType.Locations ?? new List <string>();
                for (int i = 0; i < ResourcesClient.KnownLocationsNormalized.Count; i++)
                {
                    if (resourceType.Locations.Remove(ResourcesClient.KnownLocationsNormalized[i]))
                    {
                        resourceType.Locations.Add(ResourcesClient.KnownLocations[i]);
                    }
                }

                result.Name            = string.IsNullOrEmpty(providerNamespace) ? resourceType.Name : string.Join("/", providerNamespace, resourceType.Name);
                result.Locations       = resourceType.Locations.Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList();
                result.LocationsString = string.Join(", ", result.Locations);
            }

            return(result);
        }
        /// <summary>
        /// Gets a resource provider.
        /// </summary>
        /// <param name='resourceProviderNamespace'>
        /// Required. Namespace of the resource provider.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// Resource provider information.
        /// </returns>
        public async Task <ProviderGetResult> GetAsync(string resourceProviderNamespace, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceProviderNamespace == null)
            {
                throw new ArgumentNullException("resourceProviderNamespace");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("resourceProviderNamespace", resourceProviderNamespace);
                TracingAdapter.Enter(invocationId, this, "GetAsync", tracingParameters);
            }

            // Construct URL
            string url = "/subscriptions/" + (this.Client.Credentials.SubscriptionId == null ? "" : Uri.EscapeDataString(this.Client.Credentials.SubscriptionId)) + "/providers/" + Uri.EscapeDataString(resourceProviderNamespace) + "?";

            url = url + "api-version=2014-04-01-preview";
            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
                    ProviderGetResult result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new ProviderGetResult();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            Provider providerInstance = new Provider();
                            result.Provider = providerInstance;

                            JToken idValue = responseDoc["id"];
                            if (idValue != null && idValue.Type != JTokenType.Null)
                            {
                                string idInstance = ((string)idValue);
                                providerInstance.Id = idInstance;
                            }

                            JToken namespaceValue = responseDoc["namespace"];
                            if (namespaceValue != null && namespaceValue.Type != JTokenType.Null)
                            {
                                string namespaceInstance = ((string)namespaceValue);
                                providerInstance.Namespace = namespaceInstance;
                            }

                            JToken registrationStateValue = responseDoc["registrationState"];
                            if (registrationStateValue != null && registrationStateValue.Type != JTokenType.Null)
                            {
                                string registrationStateInstance = ((string)registrationStateValue);
                                providerInstance.RegistrationState = registrationStateInstance;
                            }

                            JToken resourceTypesArray = responseDoc["resourceTypes"];
                            if (resourceTypesArray != null && resourceTypesArray.Type != JTokenType.Null)
                            {
                                foreach (JToken resourceTypesValue in ((JArray)resourceTypesArray))
                                {
                                    ProviderResourceType providerResourceTypeInstance = new ProviderResourceType();
                                    providerInstance.ResourceTypes.Add(providerResourceTypeInstance);

                                    JToken resourceTypeValue = resourceTypesValue["resourceType"];
                                    if (resourceTypeValue != null && resourceTypeValue.Type != JTokenType.Null)
                                    {
                                        string resourceTypeInstance = ((string)resourceTypeValue);
                                        providerResourceTypeInstance.Name = resourceTypeInstance;
                                    }

                                    JToken locationsArray = resourceTypesValue["locations"];
                                    if (locationsArray != null && locationsArray.Type != JTokenType.Null)
                                    {
                                        foreach (JToken locationsValue in ((JArray)locationsArray))
                                        {
                                            providerResourceTypeInstance.Locations.Add(((string)locationsValue));
                                        }
                                    }
                                }
                            }
                        }
                    }
                    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>
        /// Get a list of deployments.
        /// </summary>
        /// <param name='nextLink'>
        /// Required. NextLink from the previous successful call to List
        /// operation.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// List of resource providers.
        /// </returns>
        public async Task <ProviderListResult> 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 = nextLink;

            // 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
                    ProviderListResult result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new ProviderListResult();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            JToken valueArray = responseDoc["value"];
                            if (valueArray != null && valueArray.Type != JTokenType.Null)
                            {
                                foreach (JToken valueValue in ((JArray)valueArray))
                                {
                                    Provider providerInstance = new Provider();
                                    result.Providers.Add(providerInstance);

                                    JToken idValue = valueValue["id"];
                                    if (idValue != null && idValue.Type != JTokenType.Null)
                                    {
                                        string idInstance = ((string)idValue);
                                        providerInstance.Id = idInstance;
                                    }

                                    JToken namespaceValue = valueValue["namespace"];
                                    if (namespaceValue != null && namespaceValue.Type != JTokenType.Null)
                                    {
                                        string namespaceInstance = ((string)namespaceValue);
                                        providerInstance.Namespace = namespaceInstance;
                                    }

                                    JToken registrationStateValue = valueValue["registrationState"];
                                    if (registrationStateValue != null && registrationStateValue.Type != JTokenType.Null)
                                    {
                                        string registrationStateInstance = ((string)registrationStateValue);
                                        providerInstance.RegistrationState = registrationStateInstance;
                                    }

                                    JToken resourceTypesArray = valueValue["resourceTypes"];
                                    if (resourceTypesArray != null && resourceTypesArray.Type != JTokenType.Null)
                                    {
                                        foreach (JToken resourceTypesValue in ((JArray)resourceTypesArray))
                                        {
                                            ProviderResourceType providerResourceTypeInstance = new ProviderResourceType();
                                            providerInstance.ResourceTypes.Add(providerResourceTypeInstance);

                                            JToken resourceTypeValue = resourceTypesValue["resourceType"];
                                            if (resourceTypeValue != null && resourceTypeValue.Type != JTokenType.Null)
                                            {
                                                string resourceTypeInstance = ((string)resourceTypeValue);
                                                providerResourceTypeInstance.Name = resourceTypeInstance;
                                            }

                                            JToken locationsArray = resourceTypesValue["locations"];
                                            if (locationsArray != null && locationsArray.Type != JTokenType.Null)
                                            {
                                                foreach (JToken locationsValue in ((JArray)locationsArray))
                                                {
                                                    providerResourceTypeInstance.Locations.Add(((string)locationsValue));
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            JToken odatanextLinkValue = responseDoc["@odata.nextLink"];
                            if (odatanextLinkValue != null && odatanextLinkValue.Type != JTokenType.Null)
                            {
                                string odatanextLinkInstance = ((string)odatanextLinkValue);
                                result.NextLink = odatanextLinkInstance;
                            }
                        }
                    }
                    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();
                }
            }
        }
示例#11
0
        /// <summary>
        /// Gets a list of resource providers.
        /// </summary>
        /// <param name='parameters'>
        /// Optional. Query parameters. If null is passed returns all
        /// deployments.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// List of resource providers.
        /// </returns>
        public async Task <ProviderListResult> ListAsync(ProviderListParameters parameters, CancellationToken cancellationToken)
        {
            // Validate

            // Tracing
            bool   shouldTrace  = CloudContext.Configuration.Tracing.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = Tracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("parameters", parameters);
                Tracing.Enter(invocationId, this, "ListAsync", tracingParameters);
            }

            // Construct URL
            string baseUrl = this.Client.BaseUri.AbsoluteUri;
            string url     = "/subscriptions/" + (this.Client.Credentials.SubscriptionId != null ? this.Client.Credentials.SubscriptionId.Trim() : "") + "/providers?";

            if (parameters != null && parameters.Top != null)
            {
                url = url + "$top=" + Uri.EscapeUriString(parameters.Top.Value.ToString());
            }
            url = url + "&api-version=2014-04-01-preview";
            // 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;

            // 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)
                    {
                        Tracing.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        Tracing.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), CloudExceptionType.Json);
                        if (shouldTrace)
                        {
                            Tracing.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    ProviderListResult result = null;
                    // Deserialize Response
                    cancellationToken.ThrowIfCancellationRequested();
                    string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                    result = new ProviderListResult();
                    JToken responseDoc = null;
                    if (string.IsNullOrEmpty(responseContent) == false)
                    {
                        responseDoc = JToken.Parse(responseContent);
                    }

                    if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                    {
                        JToken valueArray = responseDoc["value"];
                        if (valueArray != null && valueArray.Type != JTokenType.Null)
                        {
                            foreach (JToken valueValue in ((JArray)valueArray))
                            {
                                Provider providerInstance = new Provider();
                                result.Providers.Add(providerInstance);

                                JToken namespaceValue = valueValue["namespace"];
                                if (namespaceValue != null && namespaceValue.Type != JTokenType.Null)
                                {
                                    string namespaceInstance = ((string)namespaceValue);
                                    providerInstance.Namespace = namespaceInstance;
                                }

                                JToken registrationStateValue = valueValue["registrationState"];
                                if (registrationStateValue != null && registrationStateValue.Type != JTokenType.Null)
                                {
                                    string registrationStateInstance = ((string)registrationStateValue);
                                    providerInstance.RegistrationState = registrationStateInstance;
                                }

                                JToken resourceTypesArray = valueValue["resourceTypes"];
                                if (resourceTypesArray != null && resourceTypesArray.Type != JTokenType.Null)
                                {
                                    foreach (JToken resourceTypesValue in ((JArray)resourceTypesArray))
                                    {
                                        ProviderResourceType providerResourceTypeInstance = new ProviderResourceType();
                                        providerInstance.ResourceTypes.Add(providerResourceTypeInstance);

                                        JToken resourceTypeValue = resourceTypesValue["resourceType"];
                                        if (resourceTypeValue != null && resourceTypeValue.Type != JTokenType.Null)
                                        {
                                            string resourceTypeInstance = ((string)resourceTypeValue);
                                            providerResourceTypeInstance.Name = resourceTypeInstance;
                                        }

                                        JToken locationsArray = resourceTypesValue["locations"];
                                        if (locationsArray != null && locationsArray.Type != JTokenType.Null)
                                        {
                                            foreach (JToken locationsValue in ((JArray)locationsArray))
                                            {
                                                providerResourceTypeInstance.Locations.Add(((string)locationsValue));
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        JToken odatanextLinkValue = responseDoc["@odata.nextLink"];
                        if (odatanextLinkValue != null && odatanextLinkValue.Type != JTokenType.Null)
                        {
                            string odatanextLinkInstance = ((string)odatanextLinkValue);
                            result.NextLink = odatanextLinkInstance;
                        }
                    }

                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        Tracing.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
        /// <summary>
        /// Your documentation here.  (see
        /// http://msdn.microsoft.com/en-us/library/windowsazure/XXXXX.aspx
        /// for more information)
        /// </summary>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// Your documentation here.
        /// </returns>
        public async Task <ResourceProviderListResult> ListAsync(CancellationToken cancellationToken)
        {
            // Validate

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                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 + "/providers";
            List <string> queryParameters = new List <string>();

            queryParameters.Add("api-version=" + Uri.EscapeDataString(this.Client.ApiVersion));
            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
                    ResourceProviderListResult result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new ResourceProviderListResult();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            JToken valueArray = responseDoc["value"];
                            if (valueArray != null && valueArray.Type != JTokenType.Null)
                            {
                                foreach (JToken valueValue in ((JArray)valueArray))
                                {
                                    ResourceProviderDefinition resourceProviderDefinitionInstance = new ResourceProviderDefinition();
                                    result.ResourceProviders.Add(resourceProviderDefinitionInstance);

                                    JToken idValue = valueValue["id"];
                                    if (idValue != null && idValue.Type != JTokenType.Null)
                                    {
                                        string idInstance = ((string)idValue);
                                        resourceProviderDefinitionInstance.Id = idInstance;
                                    }

                                    JToken namespaceValue = valueValue["namespace"];
                                    if (namespaceValue != null && namespaceValue.Type != JTokenType.Null)
                                    {
                                        string namespaceInstance = ((string)namespaceValue);
                                        resourceProviderDefinitionInstance.Namespace = namespaceInstance;
                                    }

                                    JToken resourceTypesArray = valueValue["resourceTypes"];
                                    if (resourceTypesArray != null && resourceTypesArray.Type != JTokenType.Null)
                                    {
                                        foreach (JToken resourceTypesValue in ((JArray)resourceTypesArray))
                                        {
                                            ProviderResourceType providerResourceTypeInstance = new ProviderResourceType();
                                            resourceProviderDefinitionInstance.ResourceTypes.Add(providerResourceTypeInstance);

                                            JToken resourceTypeValue = resourceTypesValue["resourceType"];
                                            if (resourceTypeValue != null && resourceTypeValue.Type != JTokenType.Null)
                                            {
                                                string resourceTypeInstance = ((string)resourceTypeValue);
                                                providerResourceTypeInstance.ResourceType = resourceTypeInstance;
                                            }

                                            JToken locationsArray = resourceTypesValue["locations"];
                                            if (locationsArray != null && locationsArray.Type != JTokenType.Null)
                                            {
                                                foreach (JToken locationsValue in ((JArray)locationsArray))
                                                {
                                                    providerResourceTypeInstance.Locations.Add(((string)locationsValue));
                                                }
                                            }

                                            JToken apiVersionsArray = resourceTypesValue["apiVersions"];
                                            if (apiVersionsArray != null && apiVersionsArray.Type != JTokenType.Null)
                                            {
                                                foreach (JToken apiVersionsValue in ((JArray)apiVersionsArray))
                                                {
                                                    providerResourceTypeInstance.ApiVersions.Add(((string)apiVersionsValue));
                                                }
                                            }

                                            JToken propertiesValue = resourceTypesValue["properties"];
                                            if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
                                            {
                                                string propertiesInstance = propertiesValue.ToString(Newtonsoft.Json.Formatting.Indented);
                                                providerResourceTypeInstance.Properties = propertiesInstance;
                                            }
                                        }
                                    }

                                    JToken registrationStateValue = valueValue["registrationState"];
                                    if (registrationStateValue != null && registrationStateValue.Type != JTokenType.Null)
                                    {
                                        SubscriptionRegistrationState registrationStateInstance = ((SubscriptionRegistrationState)Enum.Parse(typeof(SubscriptionRegistrationState), ((string)registrationStateValue), true));
                                        resourceProviderDefinitionInstance.RegistrationState = registrationStateInstance;
                                    }
                                }
                            }

                            JToken odatanextLinkValue = responseDoc["@odata.nextLink"];
                            if (odatanextLinkValue != null && odatanextLinkValue.Type != JTokenType.Null)
                            {
                                string odatanextLinkInstance = ((string)odatanextLinkValue);
                                result.NextLink = odatanextLinkInstance;
                            }
                        }
                    }
                    result.StatusCode = statusCode;

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }