text:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Hyak.Common;
using Microsoft.Azure;
using Microsoft.Azure.Management.Sql;
using Microsoft.Azure.Management.Sql.Models;
using Newtonsoft.Json.Linq;

namespace Microsoft.Azure.Management.Sql
{
    /// <summary>
    /// Represents all the operations for operating on Azure SQL Database
    /// Elastic Pools.  Contains operations to: Create, Retrieve, Update, and
    /// Delete.
    /// </summary>
    internal partial class ElasticPoolOperations : IServiceOperations<SqlManagementClient>, IElasticPoolOperations
    {
        /// <summary>
        /// Initializes a new instance of the ElasticPoolOperations class.
        /// </summary>
        /// <param name='client'>
        /// Reference to the service client.
        /// </param>
        internal ElasticPoolOperations(SqlManagementClient client)
        {
            this._client = client;
        }

        private SqlManagementClient _client;

        /// <summary>
        /// Gets a reference to the
        /// Microsoft.Azure.Management.Sql.SqlManagementClient.
        /// </summary>
        public SqlManagementClient Client
        {
            get { return this._client; }
        }

        /// <summary>
        /// Begins creating a new Azure SQL Database Elastic Pool or updating
        /// an existing Azure SQL Database Elastic Pool. To determine the
        /// status of the operation call GetElasticPoolOperationStatus.
        /// </summary>
        /// <param name='resourceGroupName'>
        /// Required. The name of the Resource Group to which the Azure SQL
        /// Database Server belongs.
        /// </param>
        /// <param name='serverName'>
        /// Required. The name of the Azure SQL Database Server on which the
        /// database is hosted.
        /// </param>
        /// <param name='elasticPoolName'>
        /// Required. The name of the Azure SQL Database Elastic Pool to be
        /// operated on (Updated or created).
        /// </param>
        /// <param name='parameters'>
        /// Required. The required parameters for createing or updating an
        /// Elastic Pool.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// Response for long running Azure Sql Database Elastic Pool operation.
        /// </returns>
        public async Task<ElasticPoolCreateOrUpdateResponse> BeginCreateOrUpdateAsync(string resourceGroupName, string serverName, string elasticPoolName, ElasticPoolCreateOrUpdateParameters parameters, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException("resourceGroupName");
            }
            if (serverName == null)
            {
                throw new ArgumentNullException("serverName");
            }
            if (elasticPoolName == null)
            {
                throw new ArgumentNullException("elasticPoolName");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            if (parameters.Location == null)
            {
                throw new ArgumentNullException("parameters.Location");
            }
            if (parameters.Properties == null)
            {
                throw new ArgumentNullException("parameters.Properties");
            }

            // 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("serverName", serverName);
                tracingParameters.Add("elasticPoolName", elasticPoolName);
                tracingParameters.Add("parameters", parameters);
                TracingAdapter.Enter(invocationId, this, "BeginCreateOrUpdateAsync", 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.Sql";
            url = url + "/servers/";
            url = url + Uri.EscapeDataString(serverName);
            url = url + "/elasticPools/";
            url = url + Uri.EscapeDataString(elasticPoolName);
            List<string> queryParameters = new List<string>();
            queryParameters.Add("api-version=2014-04-01");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;
            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;
            try
            {
                httpRequest = new HttpRequestMessage();
                httpRequest.Method = HttpMethod.Put;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Serialize Request
                string requestContent = null;
                JToken requestDoc = null;

                JObject elasticPoolCreateOrUpdateParametersValue = new JObject();
                requestDoc = elasticPoolCreateOrUpdateParametersValue;

                JObject propertiesValue = new JObject();
                elasticPoolCreateOrUpdateParametersValue["properties"] = propertiesValue;

                if (parameters.Properties.Edition != null)
                {
                    propertiesValue["edition"] = parameters.Properties.Edition;
                }

                if (parameters.Properties.Dtu != null)
                {
                    propertiesValue["dtu"] = parameters.Properties.Dtu.Value.ToString();
                }

                if (parameters.Properties.StorageMB != null)
                {
                    propertiesValue["storageMB"] = parameters.Properties.StorageMB.Value.ToString();
                }

                if (parameters.Properties.DatabaseDtuMin != null)
                {
                    propertiesValue["databaseDtuMin"] = parameters.Properties.DatabaseDtuMin.Value.ToString();
                }

                if (parameters.Properties.DatabaseDtuMax != null)
                {
                    propertiesValue["databaseDtuMax"] = parameters.Properties.DatabaseDtuMax.Value.ToString();
                }

                elasticPoolCreateOrUpdateParametersValue["location"] = parameters.Location;

                if (parameters.Tags != null)
                {
                    JObject tagsDictionary = new JObject();
                    foreach (KeyValuePair<string, string> pair in parameters.Tags)
                    {
                        string tagsKey = pair.Key;
                        string tagsValue = pair.Value;
                        tagsDictionary[tagsKey] = tagsValue;
                    }
                    elasticPoolCreateOrUpdateParametersValue["tags"] = tagsDictionary;
                }

                requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
                httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
                httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        TracingAdapter.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.Created && statusCode != HttpStatusCode.Accepted)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    ElasticPoolCreateOrUpdateResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK || statusCode == HttpStatusCode.Created || statusCode == HttpStatusCode.Accepted)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
                        result = new ElasticPoolCreateOrUpdateResponse();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            ErrorResponse errorInstance = new ErrorResponse();
                            result.Error = errorInstance;

                            JToken codeValue = responseDoc["code"];
                            if (codeValue != null && codeValue.Type != JTokenType.Null)
                            {
                                string codeInstance = ((string)codeValue);
                                errorInstance.Code = codeInstance;
                            }

                            JToken messageValue = responseDoc["message"];
                            if (messageValue != null && messageValue.Type != JTokenType.Null)
                            {
                                string messageInstance = ((string)messageValue);
                                errorInstance.Message = messageInstance;
                            }

                            JToken targetValue = responseDoc["target"];
                            if (targetValue != null && targetValue.Type != JTokenType.Null)
                            {
                                string targetInstance = ((string)targetValue);
                                errorInstance.Target = targetInstance;
                            }

                            ElasticPool elasticPoolInstance = new ElasticPool();
                            result.ElasticPool = elasticPoolInstance;

                            JToken propertiesValue2 = responseDoc["properties"];
                            if (propertiesValue2 != null && propertiesValue2.Type != JTokenType.Null)
                            {
                                ElasticPoolProperties propertiesInstance = new ElasticPoolProperties();
                                elasticPoolInstance.Properties = propertiesInstance;

                                JToken creationDateValue = propertiesValue2["creationDate"];
                                if (creationDateValue != null && creationDateValue.Type != JTokenType.Null)
                                {
                                    DateTime creationDateInstance = ((DateTime)creationDateValue);
                                    propertiesInstance.CreationDate = creationDateInstance;
                                }

                                JToken stateValue = propertiesValue2["state"];
                                if (stateValue != null && stateValue.Type != JTokenType.Null)
                                {
                                    string stateInstance = ((string)stateValue);
                                    propertiesInstance.State = stateInstance;
                                }

                                JToken editionValue = propertiesValue2["edition"];
                                if (editionValue != null && editionValue.Type != JTokenType.Null)
                                {
                                    string editionInstance = ((string)editionValue);
                                    propertiesInstance.Edition = editionInstance;
                                }

                                JToken dtuValue = propertiesValue2["dtu"];
                                if (dtuValue != null && dtuValue.Type != JTokenType.Null)
                                {
                                    int dtuInstance = ((int)dtuValue);
                                    propertiesInstance.Dtu = dtuInstance;
                                }

                                JToken databaseDtuMaxValue = propertiesValue2["databaseDtuMax"];
                                if (databaseDtuMaxValue != null && databaseDtuMaxValue.Type != JTokenType.Null)
                                {
                                    int databaseDtuMaxInstance = ((int)databaseDtuMaxValue);
                                    propertiesInstance.DatabaseDtuMax = databaseDtuMaxInstance;
                                }

                                JToken databaseDtuMinValue = propertiesValue2["databaseDtuMin"];
                                if (databaseDtuMinValue != null && databaseDtuMinValue.Type != JTokenType.Null)
                                {
                                    int databaseDtuMinInstance = ((int)databaseDtuMinValue);
                                    propertiesInstance.DatabaseDtuMin = databaseDtuMinInstance;
                                }

                                JToken storageMBValue = propertiesValue2["storageMB"];
                                if (storageMBValue != null && storageMBValue.Type != JTokenType.Null)
                                {
                                    int storageMBInstance = ((int)storageMBValue);
                                    propertiesInstance.StorageMB = storageMBInstance;
                                }
                            }

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

                            JToken nameValue = responseDoc["name"];
                            if (nameValue != null && nameValue.Type != JTokenType.Null)
                            {
                                string nameInstance = ((string)nameValue);
                                elasticPoolInstance.Name = nameInstance;
                            }

                            JToken typeValue = responseDoc["type"];
                            if (typeValue != null && typeValue.Type != JTokenType.Null)
                            {
                                string typeInstance = ((string)typeValue);
                                elasticPoolInstance.Type = typeInstance;
                            }

                            JToken locationValue = responseDoc["location"];
                            if (locationValue != null && locationValue.Type != JTokenType.Null)
                            {
                                string locationInstance = ((string)locationValue);
                                elasticPoolInstance.Location = locationInstance;
                            }

                            JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
                            if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
                            {
                                foreach (JProperty property in tagsSequenceElement)
                                {
                                    string tagsKey2 = ((string)property.Name);
                                    string tagsValue2 = ((string)property.Value);
                                    elasticPoolInstance.Tags.Add(tagsKey2, tagsValue2);
                                }
                            }
                        }

                    }
                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("Location"))
                    {
                        result.OperationStatusLink = httpResponse.Headers.GetValues("Location").FirstOrDefault();
                    }
                    if (httpResponse.Headers.Contains("Retry-After"))
                    {
                        result.RetryAfter = int.Parse(httpResponse.Headers.GetValues("Retry-After").FirstOrDefault(), CultureInfo.InvariantCulture);
                    }
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }
                    if (statusCode == HttpStatusCode.Created)
                    {
                        result.Status = OperationStatus.Succeeded;
                    }

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

        /// <summary>
        /// Creates a new Azure SQL Database Elastic Pool or updates an
        /// existing Azure SQL Database Elastic Pool.
        /// </summary>
        /// <param name='resourceGroupName'>
        /// Required. The name of the Resource Group to which the Azure SQL
        /// Database Server belongs.
        /// </param>
        /// <param name='serverName'>
        /// Required. The name of the Azure SQL Database Server on which the
        /// Azure SQL Database Elastic Pool is hosted.
        /// </param>
        /// <param name='elasticPoolName'>
        /// Required. The name of the Azure SQL Database Elastic Pool to be
        /// operated on (updated or created).
        /// </param>
        /// <param name='parameters'>
        /// Required. The required parameters for createing or updating an
        /// Azure Sql Databaser Elastic Pool.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// Response for long running Azure Sql Database Elastic Pool operation.
        /// </returns>
        public async Task<ElasticPoolCreateOrUpdateResponse> CreateOrUpdateAsync(string resourceGroupName, string serverName, string elasticPoolName, ElasticPoolCreateOrUpdateParameters parameters, CancellationToken cancellationToken)
        {
            SqlManagementClient client = this.Client;
            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("serverName", serverName);
                tracingParameters.Add("elasticPoolName", elasticPoolName);
                tracingParameters.Add("parameters", parameters);
                TracingAdapter.Enter(invocationId, this, "CreateOrUpdateAsync", tracingParameters);
            }

            cancellationToken.ThrowIfCancellationRequested();
            ElasticPoolCreateOrUpdateResponse response = await client.ElasticPools.BeginCreateOrUpdateAsync(resourceGroupName, serverName, elasticPoolName, parameters, cancellationToken).ConfigureAwait(false);
            if (response.Status == OperationStatus.Succeeded)
            {
                return response;
            }
            cancellationToken.ThrowIfCancellationRequested();
            ElasticPoolCreateOrUpdateResponse result = await client.ElasticPools.GetElasticPoolOperationStatusAsync(response.OperationStatusLink, cancellationToken).ConfigureAwait(false);
            int delayInSeconds = response.RetryAfter;
            if (delayInSeconds == 0)
            {
                delayInSeconds = 30;
            }
            if (client.LongRunningOperationInitialTimeout >= 0)
            {
                delayInSeconds = client.LongRunningOperationInitialTimeout;
            }
            while (result.Status == OperationStatus.InProgress)
            {
                cancellationToken.ThrowIfCancellationRequested();
                await TaskEx.Delay(delayInSeconds * 1000, cancellationToken).ConfigureAwait(false);
                cancellationToken.ThrowIfCancellationRequested();
                result = await client.ElasticPools.GetElasticPoolOperationStatusAsync(response.OperationStatusLink, cancellationToken).ConfigureAwait(false);
                delayInSeconds = result.RetryAfter;
                if (delayInSeconds == 0)
                {
                    delayInSeconds = 15;
                }
                if (client.LongRunningOperationRetryTimeout >= 0)
                {
                    delayInSeconds = client.LongRunningOperationRetryTimeout;
                }
            }

            if (shouldTrace)
            {
                TracingAdapter.Exit(invocationId, result);
            }

            return result;
        }

        /// <summary>
        /// Deletes the Azure SQL Database Elastic Pool with the given name.
        /// </summary>
        /// <param name='resourceGroupName'>
        /// Required. The name of the Resource Group to which the Azure SQL
        /// Database Server belongs.
        /// </param>
        /// <param name='serverName'>
        /// Required. The name of the Azure SQL Database Server on which the
        /// Azure SQL Database Elastic Pool is hosted.
        /// </param>
        /// <param name='elasticPoolName'>
        /// Required. The name of the Azure SQL Database Elastic Pool to be
        /// deleted.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// A standard service response including an HTTP status code and
        /// request ID.
        /// </returns>
        public async Task<AzureOperationResponse> DeleteAsync(string resourceGroupName, string serverName, string elasticPoolName, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException("resourceGroupName");
            }
            if (serverName == null)
            {
                throw new ArgumentNullException("serverName");
            }
            if (elasticPoolName == null)
            {
                throw new ArgumentNullException("elasticPoolName");
            }

            // 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("serverName", serverName);
                tracingParameters.Add("elasticPoolName", elasticPoolName);
                TracingAdapter.Enter(invocationId, this, "DeleteAsync", 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.Sql";
            url = url + "/servers/";
            url = url + Uri.EscapeDataString(serverName);
            url = url + "/elasticPools/";
            url = url + Uri.EscapeDataString(elasticPoolName);
            List<string> queryParameters = new List<string>();
            queryParameters.Add("api-version=2014-04-01");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;
            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;
            try
            {
                httpRequest = new HttpRequestMessage();
                httpRequest.Method = HttpMethod.Delete;
                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 && statusCode != HttpStatusCode.NoContent)
                    {
                        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
                    AzureOperationResponse result = null;
                    // Deserialize Response
                    result = new AzureOperationResponse();
                    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>
        /// Returns information about an Azure SQL Database Elastic Pool.
        /// </summary>
        /// <param name='resourceGroupName'>
        /// Required. The name of the Resource Group to which the Azure SQL
        /// Database Server belongs.
        /// </param>
        /// <param name='serverName'>
        /// Required. The name of the Azure SQL Database Server on which the
        /// Azure SQL Database Elastic Pool is hosted.
        /// </param>
        /// <param name='elasticPoolName'>
        /// Required. The name of the Azure SQL Database Elastic Pool to be
        /// retrieved.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// Represents the response to a Get Azure Sql Elastic Pool request.
        /// </returns>
        public async Task<ElasticPoolGetResponse> GetAsync(string resourceGroupName, string serverName, string elasticPoolName, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException("resourceGroupName");
            }
            if (serverName == null)
            {
                throw new ArgumentNullException("serverName");
            }
            if (elasticPoolName == null)
            {
                throw new ArgumentNullException("elasticPoolName");
            }

            // 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("serverName", serverName);
                tracingParameters.Add("elasticPoolName", elasticPoolName);
                TracingAdapter.Enter(invocationId, this, "GetAsync", 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.Sql";
            url = url + "/servers/";
            url = url + Uri.EscapeDataString(serverName);
            url = url + "/elasticPools/";
            url = url + Uri.EscapeDataString(elasticPoolName);
            List<string> queryParameters = new List<string>();
            queryParameters.Add("api-version=2014-04-01");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;
            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;
            try
            {
                httpRequest = new HttpRequestMessage();
                httpRequest.Method = HttpMethod.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
                    ElasticPoolGetResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
                        result = new ElasticPoolGetResponse();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

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

                            JToken propertiesValue = responseDoc["properties"];
                            if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
                            {
                                ElasticPoolProperties propertiesInstance = new ElasticPoolProperties();
                                elasticPoolInstance.Properties = propertiesInstance;

                                JToken creationDateValue = propertiesValue["creationDate"];
                                if (creationDateValue != null && creationDateValue.Type != JTokenType.Null)
                                {
                                    DateTime creationDateInstance = ((DateTime)creationDateValue);
                                    propertiesInstance.CreationDate = creationDateInstance;
                                }

                                JToken stateValue = propertiesValue["state"];
                                if (stateValue != null && stateValue.Type != JTokenType.Null)
                                {
                                    string stateInstance = ((string)stateValue);
                                    propertiesInstance.State = stateInstance;
                                }

                                JToken editionValue = propertiesValue["edition"];
                                if (editionValue != null && editionValue.Type != JTokenType.Null)
                                {
                                    string editionInstance = ((string)editionValue);
                                    propertiesInstance.Edition = editionInstance;
                                }

                                JToken dtuValue = propertiesValue["dtu"];
                                if (dtuValue != null && dtuValue.Type != JTokenType.Null)
                                {
                                    int dtuInstance = ((int)dtuValue);
                                    propertiesInstance.Dtu = dtuInstance;
                                }

                                JToken databaseDtuMaxValue = propertiesValue["databaseDtuMax"];
                                if (databaseDtuMaxValue != null && databaseDtuMaxValue.Type != JTokenType.Null)
                                {
                                    int databaseDtuMaxInstance = ((int)databaseDtuMaxValue);
                                    propertiesInstance.DatabaseDtuMax = databaseDtuMaxInstance;
                                }

                                JToken databaseDtuMinValue = propertiesValue["databaseDtuMin"];
                                if (databaseDtuMinValue != null && databaseDtuMinValue.Type != JTokenType.Null)
                                {
                                    int databaseDtuMinInstance = ((int)databaseDtuMinValue);
                                    propertiesInstance.DatabaseDtuMin = databaseDtuMinInstance;
                                }

                                JToken storageMBValue = propertiesValue["storageMB"];
                                if (storageMBValue != null && storageMBValue.Type != JTokenType.Null)
                                {
                                    int storageMBInstance = ((int)storageMBValue);
                                    propertiesInstance.StorageMB = storageMBInstance;
                                }
                            }

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

                            JToken nameValue = responseDoc["name"];
                            if (nameValue != null && nameValue.Type != JTokenType.Null)
                            {
                                string nameInstance = ((string)nameValue);
                                elasticPoolInstance.Name = nameInstance;
                            }

                            JToken typeValue = responseDoc["type"];
                            if (typeValue != null && typeValue.Type != JTokenType.Null)
                            {
                                string typeInstance = ((string)typeValue);
                                elasticPoolInstance.Type = typeInstance;
                            }

                            JToken locationValue = responseDoc["location"];
                            if (locationValue != null && locationValue.Type != JTokenType.Null)
                            {
                                string locationInstance = ((string)locationValue);
                                elasticPoolInstance.Location = locationInstance;
                            }

                            JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
                            if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
                            {
                                foreach (JProperty property in tagsSequenceElement)
                                {
                                    string tagsKey = ((string)property.Name);
                                    string tagsValue = ((string)property.Value);
                                    elasticPoolInstance.Tags.Add(tagsKey, tagsValue);
                                }
                            }
                        }

                    }
                    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>
        /// Returns information about an Azure SQL Database inside of an Azure
        /// Sql Database Elastic Pool.
        /// </summary>
        /// <param name='resourceGroupName'>
        /// Required. The name of the Resource Group to which the server
        /// belongs.
        /// </param>
        /// <param name='serverName'>
        /// Required. The name of the Azure SQL Database Server on which the
        /// database is hosted.
        /// </param>
        /// <param name='elasticPoolName'>
        /// Required. The name of the Azure SQL Database Elastic Pool to be
        /// retrieved.
        /// </param>
        /// <param name='databaseName'>
        /// Required. The name of the Azure SQL Database to be retrieved.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// Represents the response to a Get Azure Sql Database request.
        /// </returns>
        public async Task<DatabaseGetResponse> GetDatabasesAsync(string resourceGroupName, string serverName, string elasticPoolName, string databaseName, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException("resourceGroupName");
            }
            if (serverName == null)
            {
                throw new ArgumentNullException("serverName");
            }
            if (elasticPoolName == null)
            {
                throw new ArgumentNullException("elasticPoolName");
            }
            if (databaseName == null)
            {
                throw new ArgumentNullException("databaseName");
            }

            // 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("serverName", serverName);
                tracingParameters.Add("elasticPoolName", elasticPoolName);
                tracingParameters.Add("databaseName", databaseName);
                TracingAdapter.Enter(invocationId, this, "GetDatabasesAsync", 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.Sql";
            url = url + "/servers/";
            url = url + Uri.EscapeDataString(serverName);
            url = url + "/elasticPools/";
            url = url + Uri.EscapeDataString(elasticPoolName);
            url = url + "/databases/";
            url = url + Uri.EscapeDataString(databaseName);
            List<string> queryParameters = new List<string>();
            queryParameters.Add("api-version=2014-04-01");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;
            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;
            try
            {
                httpRequest = new HttpRequestMessage();
                httpRequest.Method = HttpMethod.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
                    DatabaseGetResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
                        result = new DatabaseGetResponse();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

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

                            JToken propertiesValue = responseDoc["properties"];
                            if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
                            {
                                DatabaseProperties propertiesInstance = new DatabaseProperties();
                                databaseInstance.Properties = propertiesInstance;

                                JToken collationValue = propertiesValue["collation"];
                                if (collationValue != null && collationValue.Type != JTokenType.Null)
                                {
                                    string collationInstance = ((string)collationValue);
                                    propertiesInstance.Collation = collationInstance;
                                }

                                JToken creationDateValue = propertiesValue["creationDate"];
                                if (creationDateValue != null && creationDateValue.Type != JTokenType.Null)
                                {
                                    DateTime creationDateInstance = ((DateTime)creationDateValue);
                                    propertiesInstance.CreationDate = creationDateInstance;
                                }

                                JToken currentServiceObjectiveIdValue = propertiesValue["currentServiceObjectiveId"];
                                if (currentServiceObjectiveIdValue != null && currentServiceObjectiveIdValue.Type != JTokenType.Null)
                                {
                                    string currentServiceObjectiveIdInstance = ((string)currentServiceObjectiveIdValue);
                                    propertiesInstance.CurrentServiceObjectiveId = currentServiceObjectiveIdInstance;
                                }

                                JToken databaseIdValue = propertiesValue["databaseId"];
                                if (databaseIdValue != null && databaseIdValue.Type != JTokenType.Null)
                                {
                                    string databaseIdInstance = ((string)databaseIdValue);
                                    propertiesInstance.DatabaseId = databaseIdInstance;
                                }

                                JToken earliestRestoreDateValue = propertiesValue["earliestRestoreDate"];
                                if (earliestRestoreDateValue != null && earliestRestoreDateValue.Type != JTokenType.Null)
                                {
                                    DateTime earliestRestoreDateInstance = ((DateTime)earliestRestoreDateValue);
                                    propertiesInstance.EarliestRestoreDate = earliestRestoreDateInstance;
                                }

                                JToken editionValue = propertiesValue["edition"];
                                if (editionValue != null && editionValue.Type != JTokenType.Null)
                                {
                                    string editionInstance = ((string)editionValue);
                                    propertiesInstance.Edition = editionInstance;
                                }

                                JToken maxSizeBytesValue = propertiesValue["maxSizeBytes"];
                                if (maxSizeBytesValue != null && maxSizeBytesValue.Type != JTokenType.Null)
                                {
                                    long maxSizeBytesInstance = ((long)maxSizeBytesValue);
                                    propertiesInstance.MaxSizeBytes = maxSizeBytesInstance;
                                }

                                JToken requestedServiceObjectiveIdValue = propertiesValue["requestedServiceObjectiveId"];
                                if (requestedServiceObjectiveIdValue != null && requestedServiceObjectiveIdValue.Type != JTokenType.Null)
                                {
                                    string requestedServiceObjectiveIdInstance = ((string)requestedServiceObjectiveIdValue);
                                    propertiesInstance.RequestedServiceObjectiveId = requestedServiceObjectiveIdInstance;
                                }

                                JToken requestedServiceObjectiveNameValue = propertiesValue["requestedServiceObjectiveName"];
                                if (requestedServiceObjectiveNameValue != null && requestedServiceObjectiveNameValue.Type != JTokenType.Null)
                                {
                                    string requestedServiceObjectiveNameInstance = ((string)requestedServiceObjectiveNameValue);
                                    propertiesInstance.RequestedServiceObjectiveName = requestedServiceObjectiveNameInstance;
                                }

                                JToken serviceLevelObjectiveValue = propertiesValue["serviceLevelObjective"];
                                if (serviceLevelObjectiveValue != null && serviceLevelObjectiveValue.Type != JTokenType.Null)
                                {
                                    string serviceLevelObjectiveInstance = ((string)serviceLevelObjectiveValue);
                                    propertiesInstance.ServiceObjective = serviceLevelObjectiveInstance;
                                }

                                JToken statusValue = propertiesValue["status"];
                                if (statusValue != null && statusValue.Type != JTokenType.Null)
                                {
                                    string statusInstance = ((string)statusValue);
                                    propertiesInstance.Status = statusInstance;
                                }

                                JToken elasticPoolNameValue = propertiesValue["elasticPoolName"];
                                if (elasticPoolNameValue != null && elasticPoolNameValue.Type != JTokenType.Null)
                                {
                                    string elasticPoolNameInstance = ((string)elasticPoolNameValue);
                                    propertiesInstance.ElasticPoolName = elasticPoolNameInstance;
                                }

                                JToken serviceTierAdvisorsArray = propertiesValue["serviceTierAdvisors"];
                                if (serviceTierAdvisorsArray != null && serviceTierAdvisorsArray.Type != JTokenType.Null)
                                {
                                    foreach (JToken serviceTierAdvisorsValue in ((JArray)serviceTierAdvisorsArray))
                                    {
                                        ServiceTierAdvisor serviceTierAdvisorInstance = new ServiceTierAdvisor();
                                        propertiesInstance.ServiceTierAdvisors.Add(serviceTierAdvisorInstance);

                                        JToken propertiesValue2 = serviceTierAdvisorsValue["properties"];
                                        if (propertiesValue2 != null && propertiesValue2.Type != JTokenType.Null)
                                        {
                                            ServiceTierAdvisorProperties propertiesInstance2 = new ServiceTierAdvisorProperties();
                                            serviceTierAdvisorInstance.Properties = propertiesInstance2;

                                            JToken observationPeriodStartValue = propertiesValue2["observationPeriodStart"];
                                            if (observationPeriodStartValue != null && observationPeriodStartValue.Type != JTokenType.Null)
                                            {
                                                DateTime observationPeriodStartInstance = ((DateTime)observationPeriodStartValue);
                                                propertiesInstance2.ObservationPeriodStart = observationPeriodStartInstance;
                                            }

                                            JToken observationPeriodEndValue = propertiesValue2["observationPeriodEnd"];
                                            if (observationPeriodEndValue != null && observationPeriodEndValue.Type != JTokenType.Null)
                                            {
                                                DateTime observationPeriodEndInstance = ((DateTime)observationPeriodEndValue);
                                                propertiesInstance2.ObservationPeriodEnd = observationPeriodEndInstance;
                                            }

                                            JToken activeTimeRatioValue = propertiesValue2["activeTimeRatio"];
                                            if (activeTimeRatioValue != null && activeTimeRatioValue.Type != JTokenType.Null)
                                            {
                                                double activeTimeRatioInstance = ((double)activeTimeRatioValue);
                                                propertiesInstance2.ActiveTimeRatio = activeTimeRatioInstance;
                                            }

                                            JToken minDtuValue = propertiesValue2["minDtu"];
                                            if (minDtuValue != null && minDtuValue.Type != JTokenType.Null)
                                            {
                                                double minDtuInstance = ((double)minDtuValue);
                                                propertiesInstance2.MinDtu = minDtuInstance;
                                            }

                                            JToken avgDtuValue = propertiesValue2["avgDtu"];
                                            if (avgDtuValue != null && avgDtuValue.Type != JTokenType.Null)
                                            {
                                                double avgDtuInstance = ((double)avgDtuValue);
                                                propertiesInstance2.AvgDtu = avgDtuInstance;
                                            }

                                            JToken maxDtuValue = propertiesValue2["maxDtu"];
                                            if (maxDtuValue != null && maxDtuValue.Type != JTokenType.Null)
                                            {
                                                double maxDtuInstance = ((double)maxDtuValue);
                                                propertiesInstance2.MaxDtu = maxDtuInstance;
                                            }

                                            JToken maxSizeInGBValue = propertiesValue2["maxSizeInGB"];
                                            if (maxSizeInGBValue != null && maxSizeInGBValue.Type != JTokenType.Null)
                                            {
                                                double maxSizeInGBInstance = ((double)maxSizeInGBValue);
                                                propertiesInstance2.MaxSizeInGB = maxSizeInGBInstance;
                                            }

                                            JToken serviceLevelObjectiveUsageMetricsArray = propertiesValue2["serviceLevelObjectiveUsageMetrics"];
                                            if (serviceLevelObjectiveUsageMetricsArray != null && serviceLevelObjectiveUsageMetricsArray.Type != JTokenType.Null)
                                            {
                                                foreach (JToken serviceLevelObjectiveUsageMetricsValue in ((JArray)serviceLevelObjectiveUsageMetricsArray))
                                                {
                                                    SloUsageMetric sloUsageMetricInstance = new SloUsageMetric();
                                                    propertiesInstance2.ServiceLevelObjectiveUsageMetrics.Add(sloUsageMetricInstance);

                                                    JToken serviceLevelObjectiveValue2 = serviceLevelObjectiveUsageMetricsValue["serviceLevelObjective"];
                                                    if (serviceLevelObjectiveValue2 != null && serviceLevelObjectiveValue2.Type != JTokenType.Null)
                                                    {
                                                        string serviceLevelObjectiveInstance2 = ((string)serviceLevelObjectiveValue2);
                                                        sloUsageMetricInstance.ServiceLevelObjective = serviceLevelObjectiveInstance2;
                                                    }

                                                    JToken serviceLevelObjectiveIdValue = serviceLevelObjectiveUsageMetricsValue["serviceLevelObjectiveId"];
                                                    if (serviceLevelObjectiveIdValue != null && serviceLevelObjectiveIdValue.Type != JTokenType.Null)
                                                    {
                                                        Guid serviceLevelObjectiveIdInstance = Guid.Parse(((string)serviceLevelObjectiveIdValue));
                                                        sloUsageMetricInstance.ServiceLevelObjectiveId = serviceLevelObjectiveIdInstance;
                                                    }

                                                    JToken inRangeTimeRatioValue = serviceLevelObjectiveUsageMetricsValue["inRangeTimeRatio"];
                                                    if (inRangeTimeRatioValue != null && inRangeTimeRatioValue.Type != JTokenType.Null)
                                                    {
                                                        double inRangeTimeRatioInstance = ((double)inRangeTimeRatioValue);
                                                        sloUsageMetricInstance.InRangeTimeRatio = inRangeTimeRatioInstance;
                                                    }

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

                                                    JToken nameValue = serviceLevelObjectiveUsageMetricsValue["name"];
                                                    if (nameValue != null && nameValue.Type != JTokenType.Null)
                                                    {
                                                        string nameInstance = ((string)nameValue);
                                                        sloUsageMetricInstance.Name = nameInstance;
                                                    }

                                                    JToken typeValue = serviceLevelObjectiveUsageMetricsValue["type"];
                                                    if (typeValue != null && typeValue.Type != JTokenType.Null)
                                                    {
                                                        string typeInstance = ((string)typeValue);
                                                        sloUsageMetricInstance.Type = typeInstance;
                                                    }

                                                    JToken locationValue = serviceLevelObjectiveUsageMetricsValue["location"];
                                                    if (locationValue != null && locationValue.Type != JTokenType.Null)
                                                    {
                                                        string locationInstance = ((string)locationValue);
                                                        sloUsageMetricInstance.Location = locationInstance;
                                                    }

                                                    JToken tagsSequenceElement = ((JToken)serviceLevelObjectiveUsageMetricsValue["tags"]);
                                                    if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
                                                    {
                                                        foreach (JProperty property in tagsSequenceElement)
                                                        {
                                                            string tagsKey = ((string)property.Name);
                                                            string tagsValue = ((string)property.Value);
                                                            sloUsageMetricInstance.Tags.Add(tagsKey, tagsValue);
                                                        }
                                                    }
                                                }
                                            }

                                            JToken currentServiceLevelObjectiveValue = propertiesValue2["currentServiceLevelObjective"];
                                            if (currentServiceLevelObjectiveValue != null && currentServiceLevelObjectiveValue.Type != JTokenType.Null)
                                            {
                                                string currentServiceLevelObjectiveInstance = ((string)currentServiceLevelObjectiveValue);
                                                propertiesInstance2.CurrentServiceLevelObjective = currentServiceLevelObjectiveInstance;
                                            }

                                            JToken currentServiceLevelObjectiveIdValue = propertiesValue2["currentServiceLevelObjectiveId"];
                                            if (currentServiceLevelObjectiveIdValue != null && currentServiceLevelObjectiveIdValue.Type != JTokenType.Null)
                                            {
                                                Guid currentServiceLevelObjectiveIdInstance = Guid.Parse(((string)currentServiceLevelObjectiveIdValue));
                                                propertiesInstance2.CurrentServiceLevelObjectiveId = currentServiceLevelObjectiveIdInstance;
                                            }

                                            JToken usageBasedRecommendationServiceLevelObjectiveValue = propertiesValue2["usageBasedRecommendationServiceLevelObjective"];
                                            if (usageBasedRecommendationServiceLevelObjectiveValue != null && usageBasedRecommendationServiceLevelObjectiveValue.Type != JTokenType.Null)
                                            {
                                                string usageBasedRecommendationServiceLevelObjectiveInstance = ((string)usageBasedRecommendationServiceLevelObjectiveValue);
                                                propertiesInstance2.UsageBasedRecommendationServiceLevelObjective = usageBasedRecommendationServiceLevelObjectiveInstance;
                                            }

                                            JToken usageBasedRecommendationServiceLevelObjectiveIdValue = propertiesValue2["usageBasedRecommendationServiceLevelObjectiveId"];
                                            if (usageBasedRecommendationServiceLevelObjectiveIdValue != null && usageBasedRecommendationServiceLevelObjectiveIdValue.Type != JTokenType.Null)
                                            {
                                                Guid usageBasedRecommendationServiceLevelObjectiveIdInstance = Guid.Parse(((string)usageBasedRecommendationServiceLevelObjectiveIdValue));
                                                propertiesInstance2.UsageBasedRecommendationServiceLevelObjectiveId = usageBasedRecommendationServiceLevelObjectiveIdInstance;
                                            }

                                            JToken databaseSizeBasedRecommendationServiceLevelObjectiveValue = propertiesValue2["databaseSizeBasedRecommendationServiceLevelObjective"];
                                            if (databaseSizeBasedRecommendationServiceLevelObjectiveValue != null && databaseSizeBasedRecommendationServiceLevelObjectiveValue.Type != JTokenType.Null)
                                            {
                                                string databaseSizeBasedRecommendationServiceLevelObjectiveInstance = ((string)databaseSizeBasedRecommendationServiceLevelObjectiveValue);
                                                propertiesInstance2.DatabaseSizeBasedRecommendationServiceLevelObjective = databaseSizeBasedRecommendationServiceLevelObjectiveInstance;
                                            }

                                            JToken databaseSizeBasedRecommendationServiceLevelObjectiveIdValue = propertiesValue2["databaseSizeBasedRecommendationServiceLevelObjectiveId"];
                                            if (databaseSizeBasedRecommendationServiceLevelObjectiveIdValue != null && databaseSizeBasedRecommendationServiceLevelObjectiveIdValue.Type != JTokenType.Null)
                                            {
                                                Guid databaseSizeBasedRecommendationServiceLevelObjectiveIdInstance = Guid.Parse(((string)databaseSizeBasedRecommendationServiceLevelObjectiveIdValue));
                                                propertiesInstance2.DatabaseSizeBasedRecommendationServiceLevelObjectiveId = databaseSizeBasedRecommendationServiceLevelObjectiveIdInstance;
                                            }

                                            JToken disasterPlanBasedRecommendationServiceLevelObjectiveValue = propertiesValue2["disasterPlanBasedRecommendationServiceLevelObjective"];
                                            if (disasterPlanBasedRecommendationServiceLevelObjectiveValue != null && disasterPlanBasedRecommendationServiceLevelObjectiveValue.Type != JTokenType.Null)
                                            {
                                                string disasterPlanBasedRecommendationServiceLevelObjectiveInstance = ((string)disasterPlanBasedRecommendationServiceLevelObjectiveValue);
                                                propertiesInstance2.DisasterPlanBasedRecommendationServiceLevelObjective = disasterPlanBasedRecommendationServiceLevelObjectiveInstance;
                                            }

                                            JToken disasterPlanBasedRecommendationServiceLevelObjectiveIdValue = propertiesValue2["disasterPlanBasedRecommendationServiceLevelObjectiveId"];
                                            if (disasterPlanBasedRecommendationServiceLevelObjectiveIdValue != null && disasterPlanBasedRecommendationServiceLevelObjectiveIdValue.Type != JTokenType.Null)
                                            {
                                                Guid disasterPlanBasedRecommendationServiceLevelObjectiveIdInstance = Guid.Parse(((string)disasterPlanBasedRecommendationServiceLevelObjectiveIdValue));
                                                propertiesInstance2.DisasterPlanBasedRecommendationServiceLevelObjectiveId = disasterPlanBasedRecommendationServiceLevelObjectiveIdInstance;
                                            }

                                            JToken overallRecommendationServiceLevelObjectiveValue = propertiesValue2["overallRecommendationServiceLevelObjective"];
                                            if (overallRecommendationServiceLevelObjectiveValue != null && overallRecommendationServiceLevelObjectiveValue.Type != JTokenType.Null)
                                            {
                                                string overallRecommendationServiceLevelObjectiveInstance = ((string)overallRecommendationServiceLevelObjectiveValue);
                                                propertiesInstance2.OverallRecommendationServiceLevelObjective = overallRecommendationServiceLevelObjectiveInstance;
                                            }

                                            JToken overallRecommendationServiceLevelObjectiveIdValue = propertiesValue2["overallRecommendationServiceLevelObjectiveId"];
                                            if (overallRecommendationServiceLevelObjectiveIdValue != null && overallRecommendationServiceLevelObjectiveIdValue.Type != JTokenType.Null)
                                            {
                                                Guid overallRecommendationServiceLevelObjectiveIdInstance = Guid.Parse(((string)overallRecommendationServiceLevelObjectiveIdValue));
                                                propertiesInstance2.OverallRecommendationServiceLevelObjectiveId = overallRecommendationServiceLevelObjectiveIdInstance;
                                            }

                                            JToken confidenceValue = propertiesValue2["confidence"];
                                            if (confidenceValue != null && confidenceValue.Type != JTokenType.Null)
                                            {
                                                double confidenceInstance = ((double)confidenceValue);
                                                propertiesInstance2.Confidence = confidenceInstance;
                                            }
                                        }

                                        JToken idValue2 = serviceTierAdvisorsValue["id"];
                                        if (idValue2 != null && idValue2.Type != JTokenType.Null)
                                        {
                                            string idInstance2 = ((string)idValue2);
                                            serviceTierAdvisorInstance.Id = idInstance2;
                                        }

                                        JToken nameValue2 = serviceTierAdvisorsValue["name"];
                                        if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
                                        {
                                            string nameInstance2 = ((string)nameValue2);
                                            serviceTierAdvisorInstance.Name = nameInstance2;
                                        }

                                        JToken typeValue2 = serviceTierAdvisorsValue["type"];
                                        if (typeValue2 != null && typeValue2.Type != JTokenType.Null)
                                        {
                                            string typeInstance2 = ((string)typeValue2);
                                            serviceTierAdvisorInstance.Type = typeInstance2;
                                        }

                                        JToken locationValue2 = serviceTierAdvisorsValue["location"];
                                        if (locationValue2 != null && locationValue2.Type != JTokenType.Null)
                                        {
                                            string locationInstance2 = ((string)locationValue2);
                                            serviceTierAdvisorInstance.Location = locationInstance2;
                                        }

                                        JToken tagsSequenceElement2 = ((JToken)serviceTierAdvisorsValue["tags"]);
                                        if (tagsSequenceElement2 != null && tagsSequenceElement2.Type != JTokenType.Null)
                                        {
                                            foreach (JProperty property2 in tagsSequenceElement2)
                                            {
                                                string tagsKey2 = ((string)property2.Name);
                                                string tagsValue2 = ((string)property2.Value);
                                                serviceTierAdvisorInstance.Tags.Add(tagsKey2, tagsValue2);
                                            }
                                        }
                                    }
                                }

                                JToken upgradeHintValue = propertiesValue["upgradeHint"];
                                if (upgradeHintValue != null && upgradeHintValue.Type != JTokenType.Null)
                                {
                                    UpgradeHint upgradeHintInstance = new UpgradeHint();
                                    propertiesInstance.UpgradeHint = upgradeHintInstance;

                                    JToken targetServiceLevelObjectiveValue = upgradeHintValue["targetServiceLevelObjective"];
                                    if (targetServiceLevelObjectiveValue != null && targetServiceLevelObjectiveValue.Type != JTokenType.Null)
                                    {
                                        string targetServiceLevelObjectiveInstance = ((string)targetServiceLevelObjectiveValue);
                                        upgradeHintInstance.TargetServiceLevelObjective = targetServiceLevelObjectiveInstance;
                                    }

                                    JToken targetServiceLevelObjectiveIdValue = upgradeHintValue["targetServiceLevelObjectiveId"];
                                    if (targetServiceLevelObjectiveIdValue != null && targetServiceLevelObjectiveIdValue.Type != JTokenType.Null)
                                    {
                                        Guid targetServiceLevelObjectiveIdInstance = Guid.Parse(((string)targetServiceLevelObjectiveIdValue));
                                        upgradeHintInstance.TargetServiceLevelObjectiveId = targetServiceLevelObjectiveIdInstance;
                                    }

                                    JToken idValue3 = upgradeHintValue["id"];
                                    if (idValue3 != null && idValue3.Type != JTokenType.Null)
                                    {
                                        string idInstance3 = ((string)idValue3);
                                        upgradeHintInstance.Id = idInstance3;
                                    }

                                    JToken nameValue3 = upgradeHintValue["name"];
                                    if (nameValue3 != null && nameValue3.Type != JTokenType.Null)
                                    {
                                        string nameInstance3 = ((string)nameValue3);
                                        upgradeHintInstance.Name = nameInstance3;
                                    }

                                    JToken typeValue3 = upgradeHintValue["type"];
                                    if (typeValue3 != null && typeValue3.Type != JTokenType.Null)
                                    {
                                        string typeInstance3 = ((string)typeValue3);
                                        upgradeHintInstance.Type = typeInstance3;
                                    }

                                    JToken locationValue3 = upgradeHintValue["location"];
                                    if (locationValue3 != null && locationValue3.Type != JTokenType.Null)
                                    {
                                        string locationInstance3 = ((string)locationValue3);
                                        upgradeHintInstance.Location = locationInstance3;
                                    }

                                    JToken tagsSequenceElement3 = ((JToken)upgradeHintValue["tags"]);
                                    if (tagsSequenceElement3 != null && tagsSequenceElement3.Type != JTokenType.Null)
                                    {
                                        foreach (JProperty property3 in tagsSequenceElement3)
                                        {
                                            string tagsKey3 = ((string)property3.Name);
                                            string tagsValue3 = ((string)property3.Value);
                                            upgradeHintInstance.Tags.Add(tagsKey3, tagsValue3);
                                        }
                                    }
                                }

                                JToken schemasArray = propertiesValue["schemas"];
                                if (schemasArray != null && schemasArray.Type != JTokenType.Null)
                                {
                                    foreach (JToken schemasValue in ((JArray)schemasArray))
                                    {
                                        Schema schemaInstance = new Schema();
                                        propertiesInstance.Schemas.Add(schemaInstance);

                                        JToken propertiesValue3 = schemasValue["properties"];
                                        if (propertiesValue3 != null && propertiesValue3.Type != JTokenType.Null)
                                        {
                                            SchemaProperties propertiesInstance3 = new SchemaProperties();
                                            schemaInstance.Properties = propertiesInstance3;

                                            JToken tablesArray = propertiesValue3["tables"];
                                            if (tablesArray != null && tablesArray.Type != JTokenType.Null)
                                            {
                                                foreach (JToken tablesValue in ((JArray)tablesArray))
                                                {
                                                    Table tableInstance = new Table();
                                                    propertiesInstance3.Tables.Add(tableInstance);

                                                    JToken propertiesValue4 = tablesValue["properties"];
                                                    if (propertiesValue4 != null && propertiesValue4.Type != JTokenType.Null)
                                                    {
                                                        TableProperties propertiesInstance4 = new TableProperties();
                                                        tableInstance.Properties = propertiesInstance4;

                                                        JToken tableTypeValue = propertiesValue4["tableType"];
                                                        if (tableTypeValue != null && tableTypeValue.Type != JTokenType.Null)
                                                        {
                                                            string tableTypeInstance = ((string)tableTypeValue);
                                                            propertiesInstance4.TableType = tableTypeInstance;
                                                        }

                                                        JToken columnsArray = propertiesValue4["columns"];
                                                        if (columnsArray != null && columnsArray.Type != JTokenType.Null)
                                                        {
                                                            foreach (JToken columnsValue in ((JArray)columnsArray))
                                                            {
                                                                Column columnInstance = new Column();
                                                                propertiesInstance4.Columns.Add(columnInstance);

                                                                JToken propertiesValue5 = columnsValue["properties"];
                                                                if (propertiesValue5 != null && propertiesValue5.Type != JTokenType.Null)
                                                                {
                                                                    ColumnProperties propertiesInstance5 = new ColumnProperties();
                                                                    columnInstance.Properties = propertiesInstance5;

                                                                    JToken columnTypeValue = propertiesValue5["columnType"];
                                                                    if (columnTypeValue != null && columnTypeValue.Type != JTokenType.Null)
                                                                    {
                                                                        string columnTypeInstance = ((string)columnTypeValue);
                                                                        propertiesInstance5.ColumnType = columnTypeInstance;
                                                                    }
                                                                }

                                                                JToken idValue4 = columnsValue["id"];
                                                                if (idValue4 != null && idValue4.Type != JTokenType.Null)
                                                                {
                                                                    string idInstance4 = ((string)idValue4);
                                                                    columnInstance.Id = idInstance4;
                                                                }

                                                                JToken nameValue4 = columnsValue["name"];
                                                                if (nameValue4 != null && nameValue4.Type != JTokenType.Null)
                                                                {
                                                                    string nameInstance4 = ((string)nameValue4);
                                                                    columnInstance.Name = nameInstance4;
                                                                }

                                                                JToken typeValue4 = columnsValue["type"];
                                                                if (typeValue4 != null && typeValue4.Type != JTokenType.Null)
                                                                {
                                                                    string typeInstance4 = ((string)typeValue4);
                                                                    columnInstance.Type = typeInstance4;
                                                                }

                                                                JToken locationValue4 = columnsValue["location"];
                                                                if (locationValue4 != null && locationValue4.Type != JTokenType.Null)
                                                                {
                                                                    string locationInstance4 = ((string)locationValue4);
                                                                    columnInstance.Location = locationInstance4;
                                                                }

                                                                JToken tagsSequenceElement4 = ((JToken)columnsValue["tags"]);
                                                                if (tagsSequenceElement4 != null && tagsSequenceElement4.Type != JTokenType.Null)
                                                                {
                                                                    foreach (JProperty property4 in tagsSequenceElement4)
                                                                    {
                                                                        string tagsKey4 = ((string)property4.Name);
                                                                        string tagsValue4 = ((string)property4.Value);
                                                                        columnInstance.Tags.Add(tagsKey4, tagsValue4);
                                                                    }
                                                                }
                                                            }
                                                        }

                                                        JToken recommendedIndexesArray = propertiesValue4["recommendedIndexes"];
                                                        if (recommendedIndexesArray != null && recommendedIndexesArray.Type != JTokenType.Null)
                                                        {
                                                            foreach (JToken recommendedIndexesValue in ((JArray)recommendedIndexesArray))
                                                            {
                                                                RecommendedIndex recommendedIndexInstance = new RecommendedIndex();
                                                                propertiesInstance4.RecommendedIndexes.Add(recommendedIndexInstance);

                                                                JToken propertiesValue6 = recommendedIndexesValue["properties"];
                                                                if (propertiesValue6 != null && propertiesValue6.Type != JTokenType.Null)
                                                                {
                                                                    RecommendedIndexProperties propertiesInstance6 = new RecommendedIndexProperties();
                                                                    recommendedIndexInstance.Properties = propertiesInstance6;

                                                                    JToken actionValue = propertiesValue6["action"];
                                                                    if (actionValue != null && actionValue.Type != JTokenType.Null)
                                                                    {
                                                                        string actionInstance = ((string)actionValue);
                                                                        propertiesInstance6.Action = actionInstance;
                                                                    }

                                                                    JToken stateValue = propertiesValue6["state"];
                                                                    if (stateValue != null && stateValue.Type != JTokenType.Null)
                                                                    {
                                                                        string stateInstance = ((string)stateValue);
                                                                        propertiesInstance6.State = stateInstance;
                                                                    }

                                                                    JToken createdValue = propertiesValue6["created"];
                                                                    if (createdValue != null && createdValue.Type != JTokenType.Null)
                                                                    {
                                                                        DateTime createdInstance = ((DateTime)createdValue);
                                                                        propertiesInstance6.Created = createdInstance;
                                                                    }

                                                                    JToken lastModifiedValue = propertiesValue6["lastModified"];
                                                                    if (lastModifiedValue != null && lastModifiedValue.Type != JTokenType.Null)
                                                                    {
                                                                        DateTime lastModifiedInstance = ((DateTime)lastModifiedValue);
                                                                        propertiesInstance6.LastModified = lastModifiedInstance;
                                                                    }

                                                                    JToken indexTypeValue = propertiesValue6["indexType"];
                                                                    if (indexTypeValue != null && indexTypeValue.Type != JTokenType.Null)
                                                                    {
                                                                        string indexTypeInstance = ((string)indexTypeValue);
                                                                        propertiesInstance6.IndexType = indexTypeInstance;
                                                                    }

                                                                    JToken schemaValue = propertiesValue6["schema"];
                                                                    if (schemaValue != null && schemaValue.Type != JTokenType.Null)
                                                                    {
                                                                        string schemaInstance2 = ((string)schemaValue);
                                                                        propertiesInstance6.Schema = schemaInstance2;
                                                                    }

                                                                    JToken tableValue = propertiesValue6["table"];
                                                                    if (tableValue != null && tableValue.Type != JTokenType.Null)
                                                                    {
                                                                        string tableInstance2 = ((string)tableValue);
                                                                        propertiesInstance6.Table = tableInstance2;
                                                                    }

                                                                    JToken columnsArray2 = propertiesValue6["columns"];
                                                                    if (columnsArray2 != null && columnsArray2.Type != JTokenType.Null)
                                                                    {
                                                                        foreach (JToken columnsValue2 in ((JArray)columnsArray2))
                                                                        {
                                                                            propertiesInstance6.Columns.Add(((string)columnsValue2));
                                                                        }
                                                                    }

                                                                    JToken includedColumnsArray = propertiesValue6["includedColumns"];
                                                                    if (includedColumnsArray != null && includedColumnsArray.Type != JTokenType.Null)
                                                                    {
                                                                        foreach (JToken includedColumnsValue in ((JArray)includedColumnsArray))
                                                                        {
                                                                            propertiesInstance6.IncludedColumns.Add(((string)includedColumnsValue));
                                                                        }
                                                                    }

                                                                    JToken indexScriptValue = propertiesValue6["indexScript"];
                                                                    if (indexScriptValue != null && indexScriptValue.Type != JTokenType.Null)
                                                                    {
                                                                        string indexScriptInstance = ((string)indexScriptValue);
                                                                        propertiesInstance6.IndexScript = indexScriptInstance;
                                                                    }

                                                                    JToken estimatedImpactArray = propertiesValue6["estimatedImpact"];
                                                                    if (estimatedImpactArray != null && estimatedImpactArray.Type != JTokenType.Null)
                                                                    {
                                                                        foreach (JToken estimatedImpactValue in ((JArray)estimatedImpactArray))
                                                                        {
                                                                            OperationImpact operationImpactInstance = new OperationImpact();
                                                                            propertiesInstance6.EstimatedImpact.Add(operationImpactInstance);

                                                                            JToken nameValue5 = estimatedImpactValue["name"];
                                                                            if (nameValue5 != null && nameValue5.Type != JTokenType.Null)
                                                                            {
                                                                                string nameInstance5 = ((string)nameValue5);
                                                                                operationImpactInstance.Name = nameInstance5;
                                                                            }

                                                                            JToken unitValue = estimatedImpactValue["unit"];
                                                                            if (unitValue != null && unitValue.Type != JTokenType.Null)
                                                                            {
                                                                                string unitInstance = ((string)unitValue);
                                                                                operationImpactInstance.Unit = unitInstance;
                                                                            }

                                                                            JToken changeValueAbsoluteValue = estimatedImpactValue["changeValueAbsolute"];
                                                                            if (changeValueAbsoluteValue != null && changeValueAbsoluteValue.Type != JTokenType.Null)
                                                                            {
                                                                                double changeValueAbsoluteInstance = ((double)changeValueAbsoluteValue);
                                                                                operationImpactInstance.ChangeValueAbsolute = changeValueAbsoluteInstance;
                                                                            }

                                                                            JToken changeValueRelativeValue = estimatedImpactValue["changeValueRelative"];
                                                                            if (changeValueRelativeValue != null && changeValueRelativeValue.Type != JTokenType.Null)
                                                                            {
                                                                                double changeValueRelativeInstance = ((double)changeValueRelativeValue);
                                                                                operationImpactInstance.ChangeValueRelative = changeValueRelativeInstance;
                                                                            }
                                                                        }
                                                                    }

                                                                    JToken reportedImpactArray = propertiesValue6["reportedImpact"];
                                                                    if (reportedImpactArray != null && reportedImpactArray.Type != JTokenType.Null)
                                                                    {
                                                                        foreach (JToken reportedImpactValue in ((JArray)reportedImpactArray))
                                                                        {
                                                                            OperationImpact operationImpactInstance2 = new OperationImpact();
                                                                            propertiesInstance6.ReportedImpact.Add(operationImpactInstance2);

                                                                            JToken nameValue6 = reportedImpactValue["name"];
                                                                            if (nameValue6 != null && nameValue6.Type != JTokenType.Null)
                                                                            {
                                                                                string nameInstance6 = ((string)nameValue6);
                                                                                operationImpactInstance2.Name = nameInstance6;
                                                                            }

                                                                            JToken unitValue2 = reportedImpactValue["unit"];
                                                                            if (unitValue2 != null && unitValue2.Type != JTokenType.Null)
                                                                            {
                                                                                string unitInstance2 = ((string)unitValue2);
                                                                                operationImpactInstance2.Unit = unitInstance2;
                                                                            }

                                                                            JToken changeValueAbsoluteValue2 = reportedImpactValue["changeValueAbsolute"];
                                                                            if (changeValueAbsoluteValue2 != null && changeValueAbsoluteValue2.Type != JTokenType.Null)
                                                                            {
                                                                                double changeValueAbsoluteInstance2 = ((double)changeValueAbsoluteValue2);
                                                                                operationImpactInstance2.ChangeValueAbsolute = changeValueAbsoluteInstance2;
                                                                            }

                                                                            JToken changeValueRelativeValue2 = reportedImpactValue["changeValueRelative"];
                                                                            if (changeValueRelativeValue2 != null && changeValueRelativeValue2.Type != JTokenType.Null)
                                                                            {
                                                                                double changeValueRelativeInstance2 = ((double)changeValueRelativeValue2);
                                                                                operationImpactInstance2.ChangeValueRelative = changeValueRelativeInstance2;
                                                                            }
                                                                        }
                                                                    }
                                                                }

                                                                JToken idValue5 = recommendedIndexesValue["id"];
                                                                if (idValue5 != null && idValue5.Type != JTokenType.Null)
                                                                {
                                                                    string idInstance5 = ((string)idValue5);
                                                                    recommendedIndexInstance.Id = idInstance5;
                                                                }

                                                                JToken nameValue7 = recommendedIndexesValue["name"];
                                                                if (nameValue7 != null && nameValue7.Type != JTokenType.Null)
                                                                {
                                                                    string nameInstance7 = ((string)nameValue7);
                                                                    recommendedIndexInstance.Name = nameInstance7;
                                                                }

                                                                JToken typeValue5 = recommendedIndexesValue["type"];
                                                                if (typeValue5 != null && typeValue5.Type != JTokenType.Null)
                                                                {
                                                                    string typeInstance5 = ((string)typeValue5);
                                                                    recommendedIndexInstance.Type = typeInstance5;
                                                                }

                                                                JToken locationValue5 = recommendedIndexesValue["location"];
                                                                if (locationValue5 != null && locationValue5.Type != JTokenType.Null)
                                                                {
                                                                    string locationInstance5 = ((string)locationValue5);
                                                                    recommendedIndexInstance.Location = locationInstance5;
                                                                }

                                                                JToken tagsSequenceElement5 = ((JToken)recommendedIndexesValue["tags"]);
                                                                if (tagsSequenceElement5 != null && tagsSequenceElement5.Type != JTokenType.Null)
                                                                {
                                                                    foreach (JProperty property5 in tagsSequenceElement5)
                                                                    {
                                                                        string tagsKey5 = ((string)property5.Name);
                                                                        string tagsValue5 = ((string)property5.Value);
                                                                        recommendedIndexInstance.Tags.Add(tagsKey5, tagsValue5);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }

                                                    JToken idValue6 = tablesValue["id"];
                                                    if (idValue6 != null && idValue6.Type != JTokenType.Null)
                                                    {
                                                        string idInstance6 = ((string)idValue6);
                                                        tableInstance.Id = idInstance6;
                                                    }

                                                    JToken nameValue8 = tablesValue["name"];
                                                    if (nameValue8 != null && nameValue8.Type != JTokenType.Null)
                                                    {
                                                        string nameInstance8 = ((string)nameValue8);
                                                        tableInstance.Name = nameInstance8;
                                                    }

                                                    JToken typeValue6 = tablesValue["type"];
                                                    if (typeValue6 != null && typeValue6.Type != JTokenType.Null)
                                                    {
                                                        string typeInstance6 = ((string)typeValue6);
                                                        tableInstance.Type = typeInstance6;
                                                    }

                                                    JToken locationValue6 = tablesValue["location"];
                                                    if (locationValue6 != null && locationValue6.Type != JTokenType.Null)
                                                    {
                                                        string locationInstance6 = ((string)locationValue6);
                                                        tableInstance.Location = locationInstance6;
                                                    }

                                                    JToken tagsSequenceElement6 = ((JToken)tablesValue["tags"]);
                                                    if (tagsSequenceElement6 != null && tagsSequenceElement6.Type != JTokenType.Null)
                                                    {
                                                        foreach (JProperty property6 in tagsSequenceElement6)
                                                        {
                                                            string tagsKey6 = ((string)property6.Name);
                                                            string tagsValue6 = ((string)property6.Value);
                                                            tableInstance.Tags.Add(tagsKey6, tagsValue6);
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        JToken idValue7 = schemasValue["id"];
                                        if (idValue7 != null && idValue7.Type != JTokenType.Null)
                                        {
                                            string idInstance7 = ((string)idValue7);
                                            schemaInstance.Id = idInstance7;
                                        }

                                        JToken nameValue9 = schemasValue["name"];
                                        if (nameValue9 != null && nameValue9.Type != JTokenType.Null)
                                        {
                                            string nameInstance9 = ((string)nameValue9);
                                            schemaInstance.Name = nameInstance9;
                                        }

                                        JToken typeValue7 = schemasValue["type"];
                                        if (typeValue7 != null && typeValue7.Type != JTokenType.Null)
                                        {
                                            string typeInstance7 = ((string)typeValue7);
                                            schemaInstance.Type = typeInstance7;
                                        }

                                        JToken locationValue7 = schemasValue["location"];
                                        if (locationValue7 != null && locationValue7.Type != JTokenType.Null)
                                        {
                                            string locationInstance7 = ((string)locationValue7);
                                            schemaInstance.Location = locationInstance7;
                                        }

                                        JToken tagsSequenceElement7 = ((JToken)schemasValue["tags"]);
                                        if (tagsSequenceElement7 != null && tagsSequenceElement7.Type != JTokenType.Null)
                                        {
                                            foreach (JProperty property7 in tagsSequenceElement7)
                                            {
                                                string tagsKey7 = ((string)property7.Name);
                                                string tagsValue7 = ((string)property7.Value);
                                                schemaInstance.Tags.Add(tagsKey7, tagsValue7);
                                            }
                                        }
                                    }
                                }

                                JToken defaultSecondaryLocationValue = propertiesValue["defaultSecondaryLocation"];
                                if (defaultSecondaryLocationValue != null && defaultSecondaryLocationValue.Type != JTokenType.Null)
                                {
                                    string defaultSecondaryLocationInstance = ((string)defaultSecondaryLocationValue);
                                    propertiesInstance.DefaultSecondaryLocation = defaultSecondaryLocationInstance;
                                }

                                JToken createModeValue = propertiesValue["createMode"];
                                if (createModeValue != null && createModeValue.Type != JTokenType.Null)
                                {
                                    string createModeInstance = ((string)createModeValue);
                                    propertiesInstance.CreateMode = createModeInstance;
                                }
                            }

                            JToken idValue8 = responseDoc["id"];
                            if (idValue8 != null && idValue8.Type != JTokenType.Null)
                            {
                                string idInstance8 = ((string)idValue8);
                                databaseInstance.Id = idInstance8;
                            }

                            JToken nameValue10 = responseDoc["name"];
                            if (nameValue10 != null && nameValue10.Type != JTokenType.Null)
                            {
                                string nameInstance10 = ((string)nameValue10);
                                databaseInstance.Name = nameInstance10;
                            }

                            JToken typeValue8 = responseDoc["type"];
                            if (typeValue8 != null && typeValue8.Type != JTokenType.Null)
                            {
                                string typeInstance8 = ((string)typeValue8);
                                databaseInstance.Type = typeInstance8;
                            }

                            JToken locationValue8 = responseDoc["location"];
                            if (locationValue8 != null && locationValue8.Type != JTokenType.Null)
                            {
                                string locationInstance8 = ((string)locationValue8);
                                databaseInstance.Location = locationInstance8;
                            }

                            JToken tagsSequenceElement8 = ((JToken)responseDoc["tags"]);
                            if (tagsSequenceElement8 != null && tagsSequenceElement8.Type != JTokenType.Null)
                            {
                                foreach (JProperty property8 in tagsSequenceElement8)
                                {
                                    string tagsKey8 = ((string)property8.Name);
                                    string tagsValue8 = ((string)property8.Value);
                                    databaseInstance.Tags.Add(tagsKey8, tagsValue8);
                                }
                            }
                        }

                    }
                    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>
        /// Gets the status of an Azure Sql Database Elastic Pool create or
        /// update operation.
        /// </summary>
        /// <param name='operationStatusLink'>
        /// Required. Location value returned by the Begin operation
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// Response for long running Azure Sql Database Elastic Pool operation.
        /// </returns>
        public async Task<ElasticPoolCreateOrUpdateResponse> GetElasticPoolOperationStatusAsync(string operationStatusLink, CancellationToken cancellationToken)
        {
            // Validate
            if (operationStatusLink == null)
            {
                throw new ArgumentNullException("operationStatusLink");
            }

            // Tracing
            bool shouldTrace = TracingAdapter.IsEnabled;
            string invocationId = null;
            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
                tracingParameters.Add("operationStatusLink", operationStatusLink);
                TracingAdapter.Enter(invocationId, this, "GetElasticPoolOperationStatusAsync", tracingParameters);
            }

            // Construct URL
            string url = "";
            url = url + operationStatusLink;
            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 && statusCode != HttpStatusCode.Created && statusCode != HttpStatusCode.Accepted)
                    {
                        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
                    ElasticPoolCreateOrUpdateResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK || statusCode == HttpStatusCode.Created || statusCode == HttpStatusCode.Accepted)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
                        result = new ElasticPoolCreateOrUpdateResponse();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            ErrorResponse errorInstance = new ErrorResponse();
                            result.Error = errorInstance;

                            JToken codeValue = responseDoc["code"];
                            if (codeValue != null && codeValue.Type != JTokenType.Null)
                            {
                                string codeInstance = ((string)codeValue);
                                errorInstance.Code = codeInstance;
                            }

                            JToken messageValue = responseDoc["message"];
                            if (messageValue != null && messageValue.Type != JTokenType.Null)
                            {
                                string messageInstance = ((string)messageValue);
                                errorInstance.Message = messageInstance;
                            }

                            JToken targetValue = responseDoc["target"];
                            if (targetValue != null && targetValue.Type != JTokenType.Null)
                            {
                                string targetInstance = ((string)targetValue);
                                errorInstance.Target = targetInstance;
                            }

                            ElasticPool elasticPoolInstance = new ElasticPool();
                            result.ElasticPool = elasticPoolInstance;

                            JToken propertiesValue = responseDoc["properties"];
                            if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
                            {
                                ElasticPoolProperties propertiesInstance = new ElasticPoolProperties();
                                elasticPoolInstance.Properties = propertiesInstance;

                                JToken creationDateValue = propertiesValue["creationDate"];
                                if (creationDateValue != null && creationDateValue.Type != JTokenType.Null)
                                {
                                    DateTime creationDateInstance = ((DateTime)creationDateValue);
                                    propertiesInstance.CreationDate = creationDateInstance;
                                }

                                JToken stateValue = propertiesValue["state"];
                                if (stateValue != null && stateValue.Type != JTokenType.Null)
                                {
                                    string stateInstance = ((string)stateValue);
                                    propertiesInstance.State = stateInstance;
                                }

                                JToken editionValue = propertiesValue["edition"];
                                if (editionValue != null && editionValue.Type != JTokenType.Null)
                                {
                                    string editionInstance = ((string)editionValue);
                                    propertiesInstance.Edition = editionInstance;
                                }

                                JToken dtuValue = propertiesValue["dtu"];
                                if (dtuValue != null && dtuValue.Type != JTokenType.Null)
                                {
                                    int dtuInstance = ((int)dtuValue);
                                    propertiesInstance.Dtu = dtuInstance;
                                }

                                JToken databaseDtuMaxValue = propertiesValue["databaseDtuMax"];
                                if (databaseDtuMaxValue != null && databaseDtuMaxValue.Type != JTokenType.Null)
                                {
                                    int databaseDtuMaxInstance = ((int)databaseDtuMaxValue);
                                    propertiesInstance.DatabaseDtuMax = databaseDtuMaxInstance;
                                }

                                JToken databaseDtuMinValue = propertiesValue["databaseDtuMin"];
                                if (databaseDtuMinValue != null && databaseDtuMinValue.Type != JTokenType.Null)
                                {
                                    int databaseDtuMinInstance = ((int)databaseDtuMinValue);
                                    propertiesInstance.DatabaseDtuMin = databaseDtuMinInstance;
                                }

                                JToken storageMBValue = propertiesValue["storageMB"];
                                if (storageMBValue != null && storageMBValue.Type != JTokenType.Null)
                                {
                                    int storageMBInstance = ((int)storageMBValue);
                                    propertiesInstance.StorageMB = storageMBInstance;
                                }
                            }

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

                            JToken nameValue = responseDoc["name"];
                            if (nameValue != null && nameValue.Type != JTokenType.Null)
                            {
                                string nameInstance = ((string)nameValue);
                                elasticPoolInstance.Name = nameInstance;
                            }

                            JToken typeValue = responseDoc["type"];
                            if (typeValue != null && typeValue.Type != JTokenType.Null)
                            {
                                string typeInstance = ((string)typeValue);
                                elasticPoolInstance.Type = typeInstance;
                            }

                            JToken locationValue = responseDoc["location"];
                            if (locationValue != null && locationValue.Type != JTokenType.Null)
                            {
                                string locationInstance = ((string)locationValue);
                                elasticPoolInstance.Location = locationInstance;
                            }

                            JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
                            if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
                            {
                                foreach (JProperty property in tagsSequenceElement)
                                {
                                    string tagsKey = ((string)property.Name);
                                    string tagsValue = ((string)property.Value);
                                    elasticPoolInstance.Tags.Add(tagsKey, tagsValue);
                                }
                            }
                        }

                    }
                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }
                    if (statusCode == HttpStatusCode.OK)
                    {
                        result.Status = OperationStatus.Succeeded;
                    }
                    if (statusCode == HttpStatusCode.Created)
                    {
                        result.Status = OperationStatus.Succeeded;
                    }

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

        /// <summary>
        /// Returns information about Azure SQL Database Elastic Pools.
        /// </summary>
        /// <param name='resourceGroupName'>
        /// Required. The name of the Resource Group to which the Azure SQL
        /// Database Serve belongs.
        /// </param>
        /// <param name='serverName'>
        /// Required. The name of the Azure SQL Database Server in which Azure
        /// SQL Database Elastic Pools are hosted.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// Represents the response to a List Azure Sql Elastic Pool request.
        /// </returns>
        public async Task<ElasticPoolListResponse> ListAsync(string resourceGroupName, string serverName, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException("resourceGroupName");
            }
            if (serverName == null)
            {
                throw new ArgumentNullException("serverName");
            }

            // 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("serverName", serverName);
                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.Sql";
            url = url + "/servers/";
            url = url + Uri.EscapeDataString(serverName);
            url = url + "/elasticPools";
            List<string> queryParameters = new List<string>();
            queryParameters.Add("api-version=2014-04-01");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;
            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;
            try
            {
                httpRequest = new HttpRequestMessage();
                httpRequest.Method = HttpMethod.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
                    ElasticPoolListResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
                        result = new ElasticPoolListResponse();
                        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))
                                {
                                    ElasticPool elasticPoolInstance = new ElasticPool();
                                    result.ElasticPools.Add(elasticPoolInstance);

                                    JToken propertiesValue = valueValue["properties"];
                                    if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
                                    {
                                        ElasticPoolProperties propertiesInstance = new ElasticPoolProperties();
                                        elasticPoolInstance.Properties = propertiesInstance;

                                        JToken creationDateValue = propertiesValue["creationDate"];
                                        if (creationDateValue != null && creationDateValue.Type != JTokenType.Null)
                                        {
                                            DateTime creationDateInstance = ((DateTime)creationDateValue);
                                            propertiesInstance.CreationDate = creationDateInstance;
                                        }

                                        JToken stateValue = propertiesValue["state"];
                                        if (stateValue != null && stateValue.Type != JTokenType.Null)
                                        {
                                            string stateInstance = ((string)stateValue);
                                            propertiesInstance.State = stateInstance;
                                        }

                                        JToken editionValue = propertiesValue["edition"];
                                        if (editionValue != null && editionValue.Type != JTokenType.Null)
                                        {
                                            string editionInstance = ((string)editionValue);
                                            propertiesInstance.Edition = editionInstance;
                                        }

                                        JToken dtuValue = propertiesValue["dtu"];
                                        if (dtuValue != null && dtuValue.Type != JTokenType.Null)
                                        {
                                            int dtuInstance = ((int)dtuValue);
                                            propertiesInstance.Dtu = dtuInstance;
                                        }

                                        JToken databaseDtuMaxValue = propertiesValue["databaseDtuMax"];
                                        if (databaseDtuMaxValue != null && databaseDtuMaxValue.Type != JTokenType.Null)
                                        {
                                            int databaseDtuMaxInstance = ((int)databaseDtuMaxValue);
                                            propertiesInstance.DatabaseDtuMax = databaseDtuMaxInstance;
                                        }

                                        JToken databaseDtuMinValue = propertiesValue["databaseDtuMin"];
                                        if (databaseDtuMinValue != null && databaseDtuMinValue.Type != JTokenType.Null)
                                        {
                                            int databaseDtuMinInstance = ((int)databaseDtuMinValue);
                                            propertiesInstance.DatabaseDtuMin = databaseDtuMinInstance;
                                        }

                                        JToken storageMBValue = propertiesValue["storageMB"];
                                        if (storageMBValue != null && storageMBValue.Type != JTokenType.Null)
                                        {
                                            int storageMBInstance = ((int)storageMBValue);
                                            propertiesInstance.StorageMB = storageMBInstance;
                                        }
                                    }

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

                                    JToken nameValue = valueValue["name"];
                                    if (nameValue != null && nameValue.Type != JTokenType.Null)
                                    {
                                        string nameInstance = ((string)nameValue);
                                        elasticPoolInstance.Name = nameInstance;
                                    }

                                    JToken typeValue = valueValue["type"];
                                    if (typeValue != null && typeValue.Type != JTokenType.Null)
                                    {
                                        string typeInstance = ((string)typeValue);
                                        elasticPoolInstance.Type = typeInstance;
                                    }

                                    JToken locationValue = valueValue["location"];
                                    if (locationValue != null && locationValue.Type != JTokenType.Null)
                                    {
                                        string locationInstance = ((string)locationValue);
                                        elasticPoolInstance.Location = locationInstance;
                                    }

                                    JToken tagsSequenceElement = ((JToken)valueValue["tags"]);
                                    if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
                                    {
                                        foreach (JProperty property in tagsSequenceElement)
                                        {
                                            string tagsKey = ((string)property.Name);
                                            string tagsValue = ((string)property.Value);
                                            elasticPoolInstance.Tags.Add(tagsKey, tagsValue);
                                        }
                                    }
                                }
                            }
                        }

                    }
                    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>
        /// Returns information about Azure SQL Database Elastic Pool Activity.
        /// </summary>
        /// <param name='resourceGroupName'>
        /// Required. The name of the Resource Group to which the Azure SQL
        /// Database Serve belongs.
        /// </param>
        /// <param name='serverName'>
        /// Required. The name of the Azure SQL Database Server in which Azure
        /// SQL Database Elastic Pools are hosted.
        /// </param>
        /// <param name='elasticPoolName'>
        /// Required. The name of the Azure SQL Database Elastic Pool for which
        /// to get the current activity.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// Represents the response to a List Azure Sql Elastic Pool Activity
        /// request.
        /// </returns>
        public async Task<ElasticPoolActivityListResponse> ListActivityAsync(string resourceGroupName, string serverName, string elasticPoolName, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException("resourceGroupName");
            }
            if (serverName == null)
            {
                throw new ArgumentNullException("serverName");
            }
            if (elasticPoolName == null)
            {
                throw new ArgumentNullException("elasticPoolName");
            }

            // 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("serverName", serverName);
                tracingParameters.Add("elasticPoolName", elasticPoolName);
                TracingAdapter.Enter(invocationId, this, "ListActivityAsync", 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.Sql";
            url = url + "/servers/";
            url = url + Uri.EscapeDataString(serverName);
            url = url + "/elasticPools/";
            url = url + Uri.EscapeDataString(elasticPoolName);
            url = url + "/elasticPoolActivity";
            List<string> queryParameters = new List<string>();
            queryParameters.Add("api-version=2014-04-01");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;
            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;
            try
            {
                httpRequest = new HttpRequestMessage();
                httpRequest.Method = HttpMethod.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
                    ElasticPoolActivityListResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
                        result = new ElasticPoolActivityListResponse();
                        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))
                                {
                                    ElasticPoolActivity elasticPoolActivityInstance = new ElasticPoolActivity();
                                    result.ElasticPoolActivities.Add(elasticPoolActivityInstance);

                                    JToken propertiesValue = valueValue["properties"];
                                    if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
                                    {
                                        ElasticPoolActivityProperties propertiesInstance = new ElasticPoolActivityProperties();
                                        elasticPoolActivityInstance.Properties = propertiesInstance;

                                        JToken endTimeValue = propertiesValue["endTime"];
                                        if (endTimeValue != null && endTimeValue.Type != JTokenType.Null)
                                        {
                                            DateTime endTimeInstance = ((DateTime)endTimeValue);
                                            propertiesInstance.EndTime = endTimeInstance;
                                        }

                                        JToken errorCodeValue = propertiesValue["errorCode"];
                                        if (errorCodeValue != null && errorCodeValue.Type != JTokenType.Null)
                                        {
                                            int errorCodeInstance = ((int)errorCodeValue);
                                            propertiesInstance.ErrorCode = errorCodeInstance;
                                        }

                                        JToken errorMessageValue = propertiesValue["errorMessage"];
                                        if (errorMessageValue != null && errorMessageValue.Type != JTokenType.Null)
                                        {
                                            string errorMessageInstance = ((string)errorMessageValue);
                                            propertiesInstance.ErrorMessage = errorMessageInstance;
                                        }

                                        JToken errorSeverityValue = propertiesValue["errorSeverity"];
                                        if (errorSeverityValue != null && errorSeverityValue.Type != JTokenType.Null)
                                        {
                                            int errorSeverityInstance = ((int)errorSeverityValue);
                                            propertiesInstance.ErrorSeverity = errorSeverityInstance;
                                        }

                                        JToken operationValue = propertiesValue["operation"];
                                        if (operationValue != null && operationValue.Type != JTokenType.Null)
                                        {
                                            string operationInstance = ((string)operationValue);
                                            propertiesInstance.Operation = operationInstance;
                                        }

                                        JToken operationIdValue = propertiesValue["operationId"];
                                        if (operationIdValue != null && operationIdValue.Type != JTokenType.Null)
                                        {
                                            Guid operationIdInstance = Guid.Parse(((string)operationIdValue));
                                            propertiesInstance.OperationId = operationIdInstance;
                                        }

                                        JToken percentCompleteValue = propertiesValue["percentComplete"];
                                        if (percentCompleteValue != null && percentCompleteValue.Type != JTokenType.Null)
                                        {
                                            int percentCompleteInstance = ((int)percentCompleteValue);
                                            propertiesInstance.PercentComplete = percentCompleteInstance;
                                        }

                                        JToken requestedDatabaseDtuMaxValue = propertiesValue["requestedDatabaseDtuMax"];
                                        if (requestedDatabaseDtuMaxValue != null && requestedDatabaseDtuMaxValue.Type != JTokenType.Null)
                                        {
                                            int requestedDatabaseDtuMaxInstance = ((int)requestedDatabaseDtuMaxValue);
                                            propertiesInstance.RequestedDatabaseDtuMax = requestedDatabaseDtuMaxInstance;
                                        }

                                        JToken requestedDatabaseDtuMinValue = propertiesValue["requestedDatabaseDtuMin"];
                                        if (requestedDatabaseDtuMinValue != null && requestedDatabaseDtuMinValue.Type != JTokenType.Null)
                                        {
                                            int requestedDatabaseDtuMinInstance = ((int)requestedDatabaseDtuMinValue);
                                            propertiesInstance.RequestedDatabaseDtuMin = requestedDatabaseDtuMinInstance;
                                        }

                                        JToken requestedDtuValue = propertiesValue["requestedDtu"];
                                        if (requestedDtuValue != null && requestedDtuValue.Type != JTokenType.Null)
                                        {
                                            int requestedDtuInstance = ((int)requestedDtuValue);
                                            propertiesInstance.RequestedDtu = requestedDtuInstance;
                                        }

                                        JToken requestedElasticPoolNameValue = propertiesValue["requestedElasticPoolName"];
                                        if (requestedElasticPoolNameValue != null && requestedElasticPoolNameValue.Type != JTokenType.Null)
                                        {
                                            string requestedElasticPoolNameInstance = ((string)requestedElasticPoolNameValue);
                                            propertiesInstance.RequestedElasticPoolName = requestedElasticPoolNameInstance;
                                        }

                                        JToken requestedStorageLimitInGBValue = propertiesValue["requestedStorageLimitInGB"];
                                        if (requestedStorageLimitInGBValue != null && requestedStorageLimitInGBValue.Type != JTokenType.Null)
                                        {
                                            long requestedStorageLimitInGBInstance = ((long)requestedStorageLimitInGBValue);
                                            propertiesInstance.RequestedStorageLimitInGB = requestedStorageLimitInGBInstance;
                                        }

                                        JToken elasticPoolNameValue = propertiesValue["elasticPoolName"];
                                        if (elasticPoolNameValue != null && elasticPoolNameValue.Type != JTokenType.Null)
                                        {
                                            string elasticPoolNameInstance = ((string)elasticPoolNameValue);
                                            propertiesInstance.ElasticPoolName = elasticPoolNameInstance;
                                        }

                                        JToken serverNameValue = propertiesValue["serverName"];
                                        if (serverNameValue != null && serverNameValue.Type != JTokenType.Null)
                                        {
                                            string serverNameInstance = ((string)serverNameValue);
                                            propertiesInstance.ServerName = serverNameInstance;
                                        }

                                        JToken startTimeValue = propertiesValue["startTime"];
                                        if (startTimeValue != null && startTimeValue.Type != JTokenType.Null)
                                        {
                                            DateTime startTimeInstance = ((DateTime)startTimeValue);
                                            propertiesInstance.StartTime = startTimeInstance;
                                        }

                                        JToken stateValue = propertiesValue["state"];
                                        if (stateValue != null && stateValue.Type != JTokenType.Null)
                                        {
                                            string stateInstance = ((string)stateValue);
                                            propertiesInstance.State = stateInstance;
                                        }
                                    }

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

                                    JToken nameValue = valueValue["name"];
                                    if (nameValue != null && nameValue.Type != JTokenType.Null)
                                    {
                                        string nameInstance = ((string)nameValue);
                                        elasticPoolActivityInstance.Name = nameInstance;
                                    }

                                    JToken typeValue = valueValue["type"];
                                    if (typeValue != null && typeValue.Type != JTokenType.Null)
                                    {
                                        string typeInstance = ((string)typeValue);
                                        elasticPoolActivityInstance.Type = typeInstance;
                                    }

                                    JToken locationValue = valueValue["location"];
                                    if (locationValue != null && locationValue.Type != JTokenType.Null)
                                    {
                                        string locationInstance = ((string)locationValue);
                                        elasticPoolActivityInstance.Location = locationInstance;
                                    }

                                    JToken tagsSequenceElement = ((JToken)valueValue["tags"]);
                                    if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
                                    {
                                        foreach (JProperty property in tagsSequenceElement)
                                        {
                                            string tagsKey = ((string)property.Name);
                                            string tagsValue = ((string)property.Value);
                                            elasticPoolActivityInstance.Tags.Add(tagsKey, tagsValue);
                                        }
                                    }
                                }
                            }
                        }

                    }
                    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>
        /// Returns information about activity on Azure SQL Databases inside of
        /// an Azure Sql Database Elastic Pool.
        /// </summary>
        /// <param name='resourceGroupName'>
        /// Required. The name of the Resource Group to which the server
        /// belongs.
        /// </param>
        /// <param name='serverName'>
        /// Required. The name of the Azure SQL Database Server on which the
        /// Elastic Pool is hosted.
        /// </param>
        /// <param name='elasticPoolName'>
        /// Required. The name of the Azure SQL Database Elastic Pool.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// Represents the response to a List Azure Sql Elastic Pool Database
        /// Activity request.
        /// </returns>
        public async Task<ElasticPoolDatabaseActivityListResponse> ListDatabaseActivityAsync(string resourceGroupName, string serverName, string elasticPoolName, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException("resourceGroupName");
            }
            if (serverName == null)
            {
                throw new ArgumentNullException("serverName");
            }
            if (elasticPoolName == null)
            {
                throw new ArgumentNullException("elasticPoolName");
            }

            // 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("serverName", serverName);
                tracingParameters.Add("elasticPoolName", elasticPoolName);
                TracingAdapter.Enter(invocationId, this, "ListDatabaseActivityAsync", 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.Sql";
            url = url + "/servers/";
            url = url + Uri.EscapeDataString(serverName);
            url = url + "/elasticPools/";
            url = url + Uri.EscapeDataString(elasticPoolName);
            url = url + "/elasticPoolDatabaseActivity";
            List<string> queryParameters = new List<string>();
            queryParameters.Add("api-version=2014-04-01");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;
            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;
            try
            {
                httpRequest = new HttpRequestMessage();
                httpRequest.Method = HttpMethod.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
                    ElasticPoolDatabaseActivityListResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
                        result = new ElasticPoolDatabaseActivityListResponse();
                        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))
                                {
                                    ElasticPoolDatabaseActivity elasticPoolDatabaseActivityInstance = new ElasticPoolDatabaseActivity();
                                    result.ElasticPoolDatabaseActivities.Add(elasticPoolDatabaseActivityInstance);

                                    JToken propertiesValue = valueValue["properties"];
                                    if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
                                    {
                                        ElasticPoolDatabaseActivityProperties propertiesInstance = new ElasticPoolDatabaseActivityProperties();
                                        elasticPoolDatabaseActivityInstance.Properties = propertiesInstance;

                                        JToken databaseNameValue = propertiesValue["databaseName"];
                                        if (databaseNameValue != null && databaseNameValue.Type != JTokenType.Null)
                                        {
                                            string databaseNameInstance = ((string)databaseNameValue);
                                            propertiesInstance.DatabaseName = databaseNameInstance;
                                        }

                                        JToken endTimeValue = propertiesValue["endTime"];
                                        if (endTimeValue != null && endTimeValue.Type != JTokenType.Null)
                                        {
                                            DateTime endTimeInstance = ((DateTime)endTimeValue);
                                            propertiesInstance.EndTime = endTimeInstance;
                                        }

                                        JToken errorCodeValue = propertiesValue["errorCode"];
                                        if (errorCodeValue != null && errorCodeValue.Type != JTokenType.Null)
                                        {
                                            int errorCodeInstance = ((int)errorCodeValue);
                                            propertiesInstance.ErrorCode = errorCodeInstance;
                                        }

                                        JToken errorMessageValue = propertiesValue["errorMessage"];
                                        if (errorMessageValue != null && errorMessageValue.Type != JTokenType.Null)
                                        {
                                            string errorMessageInstance = ((string)errorMessageValue);
                                            propertiesInstance.ErrorMessage = errorMessageInstance;
                                        }

                                        JToken errorSeverityValue = propertiesValue["errorSeverity"];
                                        if (errorSeverityValue != null && errorSeverityValue.Type != JTokenType.Null)
                                        {
                                            int errorSeverityInstance = ((int)errorSeverityValue);
                                            propertiesInstance.ErrorSeverity = errorSeverityInstance;
                                        }

                                        JToken operationValue = propertiesValue["operation"];
                                        if (operationValue != null && operationValue.Type != JTokenType.Null)
                                        {
                                            string operationInstance = ((string)operationValue);
                                            propertiesInstance.Operation = operationInstance;
                                        }

                                        JToken operationIdValue = propertiesValue["operationId"];
                                        if (operationIdValue != null && operationIdValue.Type != JTokenType.Null)
                                        {
                                            Guid operationIdInstance = Guid.Parse(((string)operationIdValue));
                                            propertiesInstance.OperationId = operationIdInstance;
                                        }

                                        JToken percentCompleteValue = propertiesValue["percentComplete"];
                                        if (percentCompleteValue != null && percentCompleteValue.Type != JTokenType.Null)
                                        {
                                            int percentCompleteInstance = ((int)percentCompleteValue);
                                            propertiesInstance.PercentComplete = percentCompleteInstance;
                                        }

                                        JToken requestedElasticPoolNameValue = propertiesValue["requestedElasticPoolName"];
                                        if (requestedElasticPoolNameValue != null && requestedElasticPoolNameValue.Type != JTokenType.Null)
                                        {
                                            string requestedElasticPoolNameInstance = ((string)requestedElasticPoolNameValue);
                                            propertiesInstance.RequestedElasticPoolName = requestedElasticPoolNameInstance;
                                        }

                                        JToken currentElasticPoolNameValue = propertiesValue["currentElasticPoolName"];
                                        if (currentElasticPoolNameValue != null && currentElasticPoolNameValue.Type != JTokenType.Null)
                                        {
                                            string currentElasticPoolNameInstance = ((string)currentElasticPoolNameValue);
                                            propertiesInstance.CurrentElasticPoolName = currentElasticPoolNameInstance;
                                        }

                                        JToken currentServiceObjectiveValue = propertiesValue["currentServiceObjective"];
                                        if (currentServiceObjectiveValue != null && currentServiceObjectiveValue.Type != JTokenType.Null)
                                        {
                                            string currentServiceObjectiveInstance = ((string)currentServiceObjectiveValue);
                                            propertiesInstance.CurrentServiceObjectiveName = currentServiceObjectiveInstance;
                                        }

                                        JToken requestedServiceObjectiveValue = propertiesValue["requestedServiceObjective"];
                                        if (requestedServiceObjectiveValue != null && requestedServiceObjectiveValue.Type != JTokenType.Null)
                                        {
                                            string requestedServiceObjectiveInstance = ((string)requestedServiceObjectiveValue);
                                            propertiesInstance.RequestedServiceObjectiveName = requestedServiceObjectiveInstance;
                                        }

                                        JToken serverNameValue = propertiesValue["serverName"];
                                        if (serverNameValue != null && serverNameValue.Type != JTokenType.Null)
                                        {
                                            string serverNameInstance = ((string)serverNameValue);
                                            propertiesInstance.ServerName = serverNameInstance;
                                        }

                                        JToken startTimeValue = propertiesValue["startTime"];
                                        if (startTimeValue != null && startTimeValue.Type != JTokenType.Null)
                                        {
                                            DateTime startTimeInstance = ((DateTime)startTimeValue);
                                            propertiesInstance.StartTime = startTimeInstance;
                                        }

                                        JToken stateValue = propertiesValue["state"];
                                        if (stateValue != null && stateValue.Type != JTokenType.Null)
                                        {
                                            string stateInstance = ((string)stateValue);
                                            propertiesInstance.State = stateInstance;
                                        }
                                    }

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

                                    JToken nameValue = valueValue["name"];
                                    if (nameValue != null && nameValue.Type != JTokenType.Null)
                                    {
                                        string nameInstance = ((string)nameValue);
                                        elasticPoolDatabaseActivityInstance.Name = nameInstance;
                                    }

                                    JToken typeValue = valueValue["type"];
                                    if (typeValue != null && typeValue.Type != JTokenType.Null)
                                    {
                                        string typeInstance = ((string)typeValue);
                                        elasticPoolDatabaseActivityInstance.Type = typeInstance;
                                    }

                                    JToken locationValue = valueValue["location"];
                                    if (locationValue != null && locationValue.Type != JTokenType.Null)
                                    {
                                        string locationInstance = ((string)locationValue);
                                        elasticPoolDatabaseActivityInstance.Location = locationInstance;
                                    }

                                    JToken tagsSequenceElement = ((JToken)valueValue["tags"]);
                                    if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
                                    {
                                        foreach (JProperty property in tagsSequenceElement)
                                        {
                                            string tagsKey = ((string)property.Name);
                                            string tagsValue = ((string)property.Value);
                                            elasticPoolDatabaseActivityInstance.Tags.Add(tagsKey, tagsValue);
                                        }
                                    }
                                }
                            }
                        }

                    }
                    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>
        /// Returns information about an Azure SQL Database inside of an Azure
        /// Sql Database Elastic Pool.
        /// </summary>
        /// <param name='resourceGroupName'>
        /// Required. The name of the Resource Group to which the server
        /// belongs.
        /// </param>
        /// <param name='serverName'>
        /// Required. The name of the Azure SQL Database Server on which the
        /// database is hosted.
        /// </param>
        /// <param name='elasticPoolName'>
        /// Required. The name of the Azure SQL Database Elastic Pool to be
        /// retrieved.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// Represents the response to a List Azure Sql Database request.
        /// </returns>
        public async Task<DatabaseListResponse> ListDatabasesAsync(string resourceGroupName, string serverName, string elasticPoolName, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException("resourceGroupName");
            }
            if (serverName == null)
            {
                throw new ArgumentNullException("serverName");
            }
            if (elasticPoolName == null)
            {
                throw new ArgumentNullException("elasticPoolName");
            }

            // 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("serverName", serverName);
                tracingParameters.Add("elasticPoolName", elasticPoolName);
                TracingAdapter.Enter(invocationId, this, "ListDatabasesAsync", 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.Sql";
            url = url + "/servers/";
            url = url + Uri.EscapeDataString(serverName);
            url = url + "/elasticPools/";
            url = url + Uri.EscapeDataString(elasticPoolName);
            url = url + "/databases";
            List<string> queryParameters = new List<string>();
            queryParameters.Add("api-version=2014-04-01");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;
            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;
            try
            {
                httpRequest = new HttpRequestMessage();
                httpRequest.Method = HttpMethod.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
                    DatabaseListResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
                        result = new DatabaseListResponse();
                        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))
                                {
                                    Database databaseInstance = new Database();
                                    result.Databases.Add(databaseInstance);

                                    JToken propertiesValue = valueValue["properties"];
                                    if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
                                    {
                                        DatabaseProperties propertiesInstance = new DatabaseProperties();
                                        databaseInstance.Properties = propertiesInstance;

                                        JToken collationValue = propertiesValue["collation"];
                                        if (collationValue != null && collationValue.Type != JTokenType.Null)
                                        {
                                            string collationInstance = ((string)collationValue);
                                            propertiesInstance.Collation = collationInstance;
                                        }

                                        JToken creationDateValue = propertiesValue["creationDate"];
                                        if (creationDateValue != null && creationDateValue.Type != JTokenType.Null)
                                        {
                                            DateTime creationDateInstance = ((DateTime)creationDateValue);
                                            propertiesInstance.CreationDate = creationDateInstance;
                                        }

                                        JToken currentServiceObjectiveIdValue = propertiesValue["currentServiceObjectiveId"];
                                        if (currentServiceObjectiveIdValue != null && currentServiceObjectiveIdValue.Type != JTokenType.Null)
                                        {
                                            string currentServiceObjectiveIdInstance = ((string)currentServiceObjectiveIdValue);
                                            propertiesInstance.CurrentServiceObjectiveId = currentServiceObjectiveIdInstance;
                                        }

                                        JToken databaseIdValue = propertiesValue["databaseId"];
                                        if (databaseIdValue != null && databaseIdValue.Type != JTokenType.Null)
                                        {
                                            string databaseIdInstance = ((string)databaseIdValue);
                                            propertiesInstance.DatabaseId = databaseIdInstance;
                                        }

                                        JToken earliestRestoreDateValue = propertiesValue["earliestRestoreDate"];
                                        if (earliestRestoreDateValue != null && earliestRestoreDateValue.Type != JTokenType.Null)
                                        {
                                            DateTime earliestRestoreDateInstance = ((DateTime)earliestRestoreDateValue);
                                            propertiesInstance.EarliestRestoreDate = earliestRestoreDateInstance;
                                        }

                                        JToken editionValue = propertiesValue["edition"];
                                        if (editionValue != null && editionValue.Type != JTokenType.Null)
                                        {
                                            string editionInstance = ((string)editionValue);
                                            propertiesInstance.Edition = editionInstance;
                                        }

                                        JToken maxSizeBytesValue = propertiesValue["maxSizeBytes"];
                                        if (maxSizeBytesValue != null && maxSizeBytesValue.Type != JTokenType.Null)
                                        {
                                            long maxSizeBytesInstance = ((long)maxSizeBytesValue);
                                            propertiesInstance.MaxSizeBytes = maxSizeBytesInstance;
                                        }

                                        JToken requestedServiceObjectiveIdValue = propertiesValue["requestedServiceObjectiveId"];
                                        if (requestedServiceObjectiveIdValue != null && requestedServiceObjectiveIdValue.Type != JTokenType.Null)
                                        {
                                            string requestedServiceObjectiveIdInstance = ((string)requestedServiceObjectiveIdValue);
                                            propertiesInstance.RequestedServiceObjectiveId = requestedServiceObjectiveIdInstance;
                                        }

                                        JToken requestedServiceObjectiveNameValue = propertiesValue["requestedServiceObjectiveName"];
                                        if (requestedServiceObjectiveNameValue != null && requestedServiceObjectiveNameValue.Type != JTokenType.Null)
                                        {
                                            string requestedServiceObjectiveNameInstance = ((string)requestedServiceObjectiveNameValue);
                                            propertiesInstance.RequestedServiceObjectiveName = requestedServiceObjectiveNameInstance;
                                        }

                                        JToken serviceLevelObjectiveValue = propertiesValue["serviceLevelObjective"];
                                        if (serviceLevelObjectiveValue != null && serviceLevelObjectiveValue.Type != JTokenType.Null)
                                        {
                                            string serviceLevelObjectiveInstance = ((string)serviceLevelObjectiveValue);
                                            propertiesInstance.ServiceObjective = serviceLevelObjectiveInstance;
                                        }

                                        JToken statusValue = propertiesValue["status"];
                                        if (statusValue != null && statusValue.Type != JTokenType.Null)
                                        {
                                            string statusInstance = ((string)statusValue);
                                            propertiesInstance.Status = statusInstance;
                                        }

                                        JToken elasticPoolNameValue = propertiesValue["elasticPoolName"];
                                        if (elasticPoolNameValue != null && elasticPoolNameValue.Type != JTokenType.Null)
                                        {
                                            string elasticPoolNameInstance = ((string)elasticPoolNameValue);
                                            propertiesInstance.ElasticPoolName = elasticPoolNameInstance;
                                        }

                                        JToken serviceTierAdvisorsArray = propertiesValue["serviceTierAdvisors"];
                                        if (serviceTierAdvisorsArray != null && serviceTierAdvisorsArray.Type != JTokenType.Null)
                                        {
                                            foreach (JToken serviceTierAdvisorsValue in ((JArray)serviceTierAdvisorsArray))
                                            {
                                                ServiceTierAdvisor serviceTierAdvisorInstance = new ServiceTierAdvisor();
                                                propertiesInstance.ServiceTierAdvisors.Add(serviceTierAdvisorInstance);

                                                JToken propertiesValue2 = serviceTierAdvisorsValue["properties"];
                                                if (propertiesValue2 != null && propertiesValue2.Type != JTokenType.Null)
                                                {
                                                    ServiceTierAdvisorProperties propertiesInstance2 = new ServiceTierAdvisorProperties();
                                                    serviceTierAdvisorInstance.Properties = propertiesInstance2;

                                                    JToken observationPeriodStartValue = propertiesValue2["observationPeriodStart"];
                                                    if (observationPeriodStartValue != null && observationPeriodStartValue.Type != JTokenType.Null)
                                                    {
                                                        DateTime observationPeriodStartInstance = ((DateTime)observationPeriodStartValue);
                                                        propertiesInstance2.ObservationPeriodStart = observationPeriodStartInstance;
                                                    }

                                                    JToken observationPeriodEndValue = propertiesValue2["observationPeriodEnd"];
                                                    if (observationPeriodEndValue != null && observationPeriodEndValue.Type != JTokenType.Null)
                                                    {
                                                        DateTime observationPeriodEndInstance = ((DateTime)observationPeriodEndValue);
                                                        propertiesInstance2.ObservationPeriodEnd = observationPeriodEndInstance;
                                                    }

                                                    JToken activeTimeRatioValue = propertiesValue2["activeTimeRatio"];
                                                    if (activeTimeRatioValue != null && activeTimeRatioValue.Type != JTokenType.Null)
                                                    {
                                                        double activeTimeRatioInstance = ((double)activeTimeRatioValue);
                                                        propertiesInstance2.ActiveTimeRatio = activeTimeRatioInstance;
                                                    }

                                                    JToken minDtuValue = propertiesValue2["minDtu"];
                                                    if (minDtuValue != null && minDtuValue.Type != JTokenType.Null)
                                                    {
                                                        double minDtuInstance = ((double)minDtuValue);
                                                        propertiesInstance2.MinDtu = minDtuInstance;
                                                    }

                                                    JToken avgDtuValue = propertiesValue2["avgDtu"];
                                                    if (avgDtuValue != null && avgDtuValue.Type != JTokenType.Null)
                                                    {
                                                        double avgDtuInstance = ((double)avgDtuValue);
                                                        propertiesInstance2.AvgDtu = avgDtuInstance;
                                                    }

                                                    JToken maxDtuValue = propertiesValue2["maxDtu"];
                                                    if (maxDtuValue != null && maxDtuValue.Type != JTokenType.Null)
                                                    {
                                                        double maxDtuInstance = ((double)maxDtuValue);
                                                        propertiesInstance2.MaxDtu = maxDtuInstance;
                                                    }

                                                    JToken maxSizeInGBValue = propertiesValue2["maxSizeInGB"];
                                                    if (maxSizeInGBValue != null && maxSizeInGBValue.Type != JTokenType.Null)
                                                    {
                                                        double maxSizeInGBInstance = ((double)maxSizeInGBValue);
                                                        propertiesInstance2.MaxSizeInGB = maxSizeInGBInstance;
                                                    }

                                                    JToken serviceLevelObjectiveUsageMetricsArray = propertiesValue2["serviceLevelObjectiveUsageMetrics"];
                                                    if (serviceLevelObjectiveUsageMetricsArray != null && serviceLevelObjectiveUsageMetricsArray.Type != JTokenType.Null)
                                                    {
                                                        foreach (JToken serviceLevelObjectiveUsageMetricsValue in ((JArray)serviceLevelObjectiveUsageMetricsArray))
                                                        {
                                                            SloUsageMetric sloUsageMetricInstance = new SloUsageMetric();
                                                            propertiesInstance2.ServiceLevelObjectiveUsageMetrics.Add(sloUsageMetricInstance);

                                                            JToken serviceLevelObjectiveValue2 = serviceLevelObjectiveUsageMetricsValue["serviceLevelObjective"];
                                                            if (serviceLevelObjectiveValue2 != null && serviceLevelObjectiveValue2.Type != JTokenType.Null)
                                                            {
                                                                string serviceLevelObjectiveInstance2 = ((string)serviceLevelObjectiveValue2);
                                                                sloUsageMetricInstance.ServiceLevelObjective = serviceLevelObjectiveInstance2;
                                                            }

                                                            JToken serviceLevelObjectiveIdValue = serviceLevelObjectiveUsageMetricsValue["serviceLevelObjectiveId"];
                                                            if (serviceLevelObjectiveIdValue != null && serviceLevelObjectiveIdValue.Type != JTokenType.Null)
                                                            {
                                                                Guid serviceLevelObjectiveIdInstance = Guid.Parse(((string)serviceLevelObjectiveIdValue));
                                                                sloUsageMetricInstance.ServiceLevelObjectiveId = serviceLevelObjectiveIdInstance;
                                                            }

                                                            JToken inRangeTimeRatioValue = serviceLevelObjectiveUsageMetricsValue["inRangeTimeRatio"];
                                                            if (inRangeTimeRatioValue != null && inRangeTimeRatioValue.Type != JTokenType.Null)
                                                            {
                                                                double inRangeTimeRatioInstance = ((double)inRangeTimeRatioValue);
                                                                sloUsageMetricInstance.InRangeTimeRatio = inRangeTimeRatioInstance;
                                                            }

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

                                                            JToken nameValue = serviceLevelObjectiveUsageMetricsValue["name"];
                                                            if (nameValue != null && nameValue.Type != JTokenType.Null)
                                                            {
                                                                string nameInstance = ((string)nameValue);
                                                                sloUsageMetricInstance.Name = nameInstance;
                                                            }

                                                            JToken typeValue = serviceLevelObjectiveUsageMetricsValue["type"];
                                                            if (typeValue != null && typeValue.Type != JTokenType.Null)
                                                            {
                                                                string typeInstance = ((string)typeValue);
                                                                sloUsageMetricInstance.Type = typeInstance;
                                                            }

                                                            JToken locationValue = serviceLevelObjectiveUsageMetricsValue["location"];
                                                            if (locationValue != null && locationValue.Type != JTokenType.Null)
                                                            {
                                                                string locationInstance = ((string)locationValue);
                                                                sloUsageMetricInstance.Location = locationInstance;
                                                            }

                                                            JToken tagsSequenceElement = ((JToken)serviceLevelObjectiveUsageMetricsValue["tags"]);
                                                            if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
                                                            {
                                                                foreach (JProperty property in tagsSequenceElement)
                                                                {
                                                                    string tagsKey = ((string)property.Name);
                                                                    string tagsValue = ((string)property.Value);
                                                                    sloUsageMetricInstance.Tags.Add(tagsKey, tagsValue);
                                                                }
                                                            }
                                                        }
                                                    }

                                                    JToken currentServiceLevelObjectiveValue = propertiesValue2["currentServiceLevelObjective"];
                                                    if (currentServiceLevelObjectiveValue != null && currentServiceLevelObjectiveValue.Type != JTokenType.Null)
                                                    {
                                                        string currentServiceLevelObjectiveInstance = ((string)currentServiceLevelObjectiveValue);
                                                        propertiesInstance2.CurrentServiceLevelObjective = currentServiceLevelObjectiveInstance;
                                                    }

                                                    JToken currentServiceLevelObjectiveIdValue = propertiesValue2["currentServiceLevelObjectiveId"];
                                                    if (currentServiceLevelObjectiveIdValue != null && currentServiceLevelObjectiveIdValue.Type != JTokenType.Null)
                                                    {
                                                        Guid currentServiceLevelObjectiveIdInstance = Guid.Parse(((string)currentServiceLevelObjectiveIdValue));
                                                        propertiesInstance2.CurrentServiceLevelObjectiveId = currentServiceLevelObjectiveIdInstance;
                                                    }

                                                    JToken usageBasedRecommendationServiceLevelObjectiveValue = propertiesValue2["usageBasedRecommendationServiceLevelObjective"];
                                                    if (usageBasedRecommendationServiceLevelObjectiveValue != null && usageBasedRecommendationServiceLevelObjectiveValue.Type != JTokenType.Null)
                                                    {
                                                        string usageBasedRecommendationServiceLevelObjectiveInstance = ((string)usageBasedRecommendationServiceLevelObjectiveValue);
                                                        propertiesInstance2.UsageBasedRecommendationServiceLevelObjective = usageBasedRecommendationServiceLevelObjectiveInstance;
                                                    }

                                                    JToken usageBasedRecommendationServiceLevelObjectiveIdValue = propertiesValue2["usageBasedRecommendationServiceLevelObjectiveId"];
                                                    if (usageBasedRecommendationServiceLevelObjectiveIdValue != null && usageBasedRecommendationServiceLevelObjectiveIdValue.Type != JTokenType.Null)
                                                    {
                                                        Guid usageBasedRecommendationServiceLevelObjectiveIdInstance = Guid.Parse(((string)usageBasedRecommendationServiceLevelObjectiveIdValue));
                                                        propertiesInstance2.UsageBasedRecommendationServiceLevelObjectiveId = usageBasedRecommendationServiceLevelObjectiveIdInstance;
                                                    }

                                                    JToken databaseSizeBasedRecommendationServiceLevelObjectiveValue = propertiesValue2["databaseSizeBasedRecommendationServiceLevelObjective"];
                                                    if (databaseSizeBasedRecommendationServiceLevelObjectiveValue != null && databaseSizeBasedRecommendationServiceLevelObjectiveValue.Type != JTokenType.Null)
                                                    {
                                                        string databaseSizeBasedRecommendationServiceLevelObjectiveInstance = ((string)databaseSizeBasedRecommendationServiceLevelObjectiveValue);
                                                        propertiesInstance2.DatabaseSizeBasedRecommendationServiceLevelObjective = databaseSizeBasedRecommendationServiceLevelObjectiveInstance;
                                                    }

                                                    JToken databaseSizeBasedRecommendationServiceLevelObjectiveIdValue = propertiesValue2["databaseSizeBasedRecommendationServiceLevelObjectiveId"];
                                                    if (databaseSizeBasedRecommendationServiceLevelObjectiveIdValue != null && databaseSizeBasedRecommendationServiceLevelObjectiveIdValue.Type != JTokenType.Null)
                                                    {
                                                        Guid databaseSizeBasedRecommendationServiceLevelObjectiveIdInstance = Guid.Parse(((string)databaseSizeBasedRecommendationServiceLevelObjectiveIdValue));
                                                        propertiesInstance2.DatabaseSizeBasedRecommendationServiceLevelObjectiveId = databaseSizeBasedRecommendationServiceLevelObjectiveIdInstance;
                                                    }

                                                    JToken disasterPlanBasedRecommendationServiceLevelObjectiveValue = propertiesValue2["disasterPlanBasedRecommendationServiceLevelObjective"];
                                                    if (disasterPlanBasedRecommendationServiceLevelObjectiveValue != null && disasterPlanBasedRecommendationServiceLevelObjectiveValue.Type != JTokenType.Null)
                                                    {
                                                        string disasterPlanBasedRecommendationServiceLevelObjectiveInstance = ((string)disasterPlanBasedRecommendationServiceLevelObjectiveValue);
                                                        propertiesInstance2.DisasterPlanBasedRecommendationServiceLevelObjective = disasterPlanBasedRecommendationServiceLevelObjectiveInstance;
                                                    }

                                                    JToken disasterPlanBasedRecommendationServiceLevelObjectiveIdValue = propertiesValue2["disasterPlanBasedRecommendationServiceLevelObjectiveId"];
                                                    if (disasterPlanBasedRecommendationServiceLevelObjectiveIdValue != null && disasterPlanBasedRecommendationServiceLevelObjectiveIdValue.Type != JTokenType.Null)
                                                    {
                                                        Guid disasterPlanBasedRecommendationServiceLevelObjectiveIdInstance = Guid.Parse(((string)disasterPlanBasedRecommendationServiceLevelObjectiveIdValue));
                                                        propertiesInstance2.DisasterPlanBasedRecommendationServiceLevelObjectiveId = disasterPlanBasedRecommendationServiceLevelObjectiveIdInstance;
                                                    }

                                                    JToken overallRecommendationServiceLevelObjectiveValue = propertiesValue2["overallRecommendationServiceLevelObjective"];
                                                    if (overallRecommendationServiceLevelObjectiveValue != null && overallRecommendationServiceLevelObjectiveValue.Type != JTokenType.Null)
                                                    {
                                                        string overallRecommendationServiceLevelObjectiveInstance = ((string)overallRecommendationServiceLevelObjectiveValue);
                                                        propertiesInstance2.OverallRecommendationServiceLevelObjective = overallRecommendationServiceLevelObjectiveInstance;
                                                    }

                                                    JToken overallRecommendationServiceLevelObjectiveIdValue = propertiesValue2["overallRecommendationServiceLevelObjectiveId"];
                                                    if (overallRecommendationServiceLevelObjectiveIdValue != null && overallRecommendationServiceLevelObjectiveIdValue.Type != JTokenType.Null)
                                                    {
                                                        Guid overallRecommendationServiceLevelObjectiveIdInstance = Guid.Parse(((string)overallRecommendationServiceLevelObjectiveIdValue));
                                                        propertiesInstance2.OverallRecommendationServiceLevelObjectiveId = overallRecommendationServiceLevelObjectiveIdInstance;
                                                    }

                                                    JToken confidenceValue = propertiesValue2["confidence"];
                                                    if (confidenceValue != null && confidenceValue.Type != JTokenType.Null)
                                                    {
                                                        double confidenceInstance = ((double)confidenceValue);
                                                        propertiesInstance2.Confidence = confidenceInstance;
                                                    }
                                                }

                                                JToken idValue2 = serviceTierAdvisorsValue["id"];
                                                if (idValue2 != null && idValue2.Type != JTokenType.Null)
                                                {
                                                    string idInstance2 = ((string)idValue2);
                                                    serviceTierAdvisorInstance.Id = idInstance2;
                                                }

                                                JToken nameValue2 = serviceTierAdvisorsValue["name"];
                                                if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
                                                {
                                                    string nameInstance2 = ((string)nameValue2);
                                                    serviceTierAdvisorInstance.Name = nameInstance2;
                                                }

                                                JToken typeValue2 = serviceTierAdvisorsValue["type"];
                                                if (typeValue2 != null && typeValue2.Type != JTokenType.Null)
                                                {
                                                    string typeInstance2 = ((string)typeValue2);
                                                    serviceTierAdvisorInstance.Type = typeInstance2;
                                                }

                                                JToken locationValue2 = serviceTierAdvisorsValue["location"];
                                                if (locationValue2 != null && locationValue2.Type != JTokenType.Null)
                                                {
                                                    string locationInstance2 = ((string)locationValue2);
                                                    serviceTierAdvisorInstance.Location = locationInstance2;
                                                }

                                                JToken tagsSequenceElement2 = ((JToken)serviceTierAdvisorsValue["tags"]);
                                                if (tagsSequenceElement2 != null && tagsSequenceElement2.Type != JTokenType.Null)
                                                {
                                                    foreach (JProperty property2 in tagsSequenceElement2)
                                                    {
                                                        string tagsKey2 = ((string)property2.Name);
                                                        string tagsValue2 = ((string)property2.Value);
                                                        serviceTierAdvisorInstance.Tags.Add(tagsKey2, tagsValue2);
                                                    }
                                                }
                                            }
                                        }

                                        JToken upgradeHintValue = propertiesValue["upgradeHint"];
                                        if (upgradeHintValue != null && upgradeHintValue.Type != JTokenType.Null)
                                        {
                                            UpgradeHint upgradeHintInstance = new UpgradeHint();
                                            propertiesInstance.UpgradeHint = upgradeHintInstance;

                                            JToken targetServiceLevelObjectiveValue = upgradeHintValue["targetServiceLevelObjective"];
                                            if (targetServiceLevelObjectiveValue != null && targetServiceLevelObjectiveValue.Type != JTokenType.Null)
                                            {
                                                string targetServiceLevelObjectiveInstance = ((string)targetServiceLevelObjectiveValue);
                                                upgradeHintInstance.TargetServiceLevelObjective = targetServiceLevelObjectiveInstance;
                                            }

                                            JToken targetServiceLevelObjectiveIdValue = upgradeHintValue["targetServiceLevelObjectiveId"];
                                            if (targetServiceLevelObjectiveIdValue != null && targetServiceLevelObjectiveIdValue.Type != JTokenType.Null)
                                            {
                                                Guid targetServiceLevelObjectiveIdInstance = Guid.Parse(((string)targetServiceLevelObjectiveIdValue));
                                                upgradeHintInstance.TargetServiceLevelObjectiveId = targetServiceLevelObjectiveIdInstance;
                                            }

                                            JToken idValue3 = upgradeHintValue["id"];
                                            if (idValue3 != null && idValue3.Type != JTokenType.Null)
                                            {
                                                string idInstance3 = ((string)idValue3);
                                                upgradeHintInstance.Id = idInstance3;
                                            }

                                            JToken nameValue3 = upgradeHintValue["name"];
                                            if (nameValue3 != null && nameValue3.Type != JTokenType.Null)
                                            {
                                                string nameInstance3 = ((string)nameValue3);
                                                upgradeHintInstance.Name = nameInstance3;
                                            }

                                            JToken typeValue3 = upgradeHintValue["type"];
                                            if (typeValue3 != null && typeValue3.Type != JTokenType.Null)
                                            {
                                                string typeInstance3 = ((string)typeValue3);
                                                upgradeHintInstance.Type = typeInstance3;
                                            }

                                            JToken locationValue3 = upgradeHintValue["location"];
                                            if (locationValue3 != null && locationValue3.Type != JTokenType.Null)
                                            {
                                                string locationInstance3 = ((string)locationValue3);
                                                upgradeHintInstance.Location = locationInstance3;
                                            }

                                            JToken tagsSequenceElement3 = ((JToken)upgradeHintValue["tags"]);
                                            if (tagsSequenceElement3 != null && tagsSequenceElement3.Type != JTokenType.Null)
                                            {
                                                foreach (JProperty property3 in tagsSequenceElement3)
                                                {
                                                    string tagsKey3 = ((string)property3.Name);
                                                    string tagsValue3 = ((string)property3.Value);
                                                    upgradeHintInstance.Tags.Add(tagsKey3, tagsValue3);
                                                }
                                            }
                                        }

                                        JToken schemasArray = propertiesValue["schemas"];
                                        if (schemasArray != null && schemasArray.Type != JTokenType.Null)
                                        {
                                            foreach (JToken schemasValue in ((JArray)schemasArray))
                                            {
                                                Schema schemaInstance = new Schema();
                                                propertiesInstance.Schemas.Add(schemaInstance);

                                                JToken propertiesValue3 = schemasValue["properties"];
                                                if (propertiesValue3 != null && propertiesValue3.Type != JTokenType.Null)
                                                {
                                                    SchemaProperties propertiesInstance3 = new SchemaProperties();
                                                    schemaInstance.Properties = propertiesInstance3;

                                                    JToken tablesArray = propertiesValue3["tables"];
                                                    if (tablesArray != null && tablesArray.Type != JTokenType.Null)
                                                    {
                                                        foreach (JToken tablesValue in ((JArray)tablesArray))
                                                        {
                                                            Table tableInstance = new Table();
                                                            propertiesInstance3.Tables.Add(tableInstance);

                                                            JToken propertiesValue4 = tablesValue["properties"];
                                                            if (propertiesValue4 != null && propertiesValue4.Type != JTokenType.Null)
                                                            {
                                                                TableProperties propertiesInstance4 = new TableProperties();
                                                                tableInstance.Properties = propertiesInstance4;

                                                                JToken tableTypeValue = propertiesValue4["tableType"];
                                                                if (tableTypeValue != null && tableTypeValue.Type != JTokenType.Null)
                                                                {
                                                                    string tableTypeInstance = ((string)tableTypeValue);
                                                                    propertiesInstance4.TableType = tableTypeInstance;
                                                                }

                                                                JToken columnsArray = propertiesValue4["columns"];
                                                                if (columnsArray != null && columnsArray.Type != JTokenType.Null)
                                                                {
                                                                    foreach (JToken columnsValue in ((JArray)columnsArray))
                                                                    {
                                                                        Column columnInstance = new Column();
                                                                        propertiesInstance4.Columns.Add(columnInstance);

                                                                        JToken propertiesValue5 = columnsValue["properties"];
                                                                        if (propertiesValue5 != null && propertiesValue5.Type != JTokenType.Null)
                                                                        {
                                                                            ColumnProperties propertiesInstance5 = new ColumnProperties();
                                                                            columnInstance.Properties = propertiesInstance5;

                                                                            JToken columnTypeValue = propertiesValue5["columnType"];
                                                                            if (columnTypeValue != null && columnTypeValue.Type != JTokenType.Null)
                                                                            {
                                                                                string columnTypeInstance = ((string)columnTypeValue);
                                                                                propertiesInstance5.ColumnType = columnTypeInstance;
                                                                            }
                                                                        }

                                                                        JToken idValue4 = columnsValue["id"];
                                                                        if (idValue4 != null && idValue4.Type != JTokenType.Null)
                                                                        {
                                                                            string idInstance4 = ((string)idValue4);
                                                                            columnInstance.Id = idInstance4;
                                                                        }

                                                                        JToken nameValue4 = columnsValue["name"];
                                                                        if (nameValue4 != null && nameValue4.Type != JTokenType.Null)
                                                                        {
                                                                            string nameInstance4 = ((string)nameValue4);
                                                                            columnInstance.Name = nameInstance4;
                                                                        }

                                                                        JToken typeValue4 = columnsValue["type"];
                                                                        if (typeValue4 != null && typeValue4.Type != JTokenType.Null)
                                                                        {
                                                                            string typeInstance4 = ((string)typeValue4);
                                                                            columnInstance.Type = typeInstance4;
                                                                        }

                                                                        JToken locationValue4 = columnsValue["location"];
                                                                        if (locationValue4 != null && locationValue4.Type != JTokenType.Null)
                                                                        {
                                                                            string locationInstance4 = ((string)locationValue4);
                                                                            columnInstance.Location = locationInstance4;
                                                                        }

                                                                        JToken tagsSequenceElement4 = ((JToken)columnsValue["tags"]);
                                                                        if (tagsSequenceElement4 != null && tagsSequenceElement4.Type != JTokenType.Null)
                                                                        {
                                                                            foreach (JProperty property4 in tagsSequenceElement4)
                                                                            {
                                                                                string tagsKey4 = ((string)property4.Name);
                                                                                string tagsValue4 = ((string)property4.Value);
                                                                                columnInstance.Tags.Add(tagsKey4, tagsValue4);
                                                                            }
                                                                        }
                                                                    }
                                                                }

                                                                JToken recommendedIndexesArray = propertiesValue4["recommendedIndexes"];
                                                                if (recommendedIndexesArray != null && recommendedIndexesArray.Type != JTokenType.Null)
                                                                {
                                                                    foreach (JToken recommendedIndexesValue in ((JArray)recommendedIndexesArray))
                                                                    {
                                                                        RecommendedIndex recommendedIndexInstance = new RecommendedIndex();
                                                                        propertiesInstance4.RecommendedIndexes.Add(recommendedIndexInstance);

                                                                        JToken propertiesValue6 = recommendedIndexesValue["properties"];
                                                                        if (propertiesValue6 != null && propertiesValue6.Type != JTokenType.Null)
                                                                        {
                                                                            RecommendedIndexProperties propertiesInstance6 = new RecommendedIndexProperties();
                                                                            recommendedIndexInstance.Properties = propertiesInstance6;

                                                                            JToken actionValue = propertiesValue6["action"];
                                                                            if (actionValue != null && actionValue.Type != JTokenType.Null)
                                                                            {
                                                                                string actionInstance = ((string)actionValue);
                                                                                propertiesInstance6.Action = actionInstance;
                                                                            }

                                                                            JToken stateValue = propertiesValue6["state"];
                                                                            if (stateValue != null && stateValue.Type != JTokenType.Null)
                                                                            {
                                                                                string stateInstance = ((string)stateValue);
                                                                                propertiesInstance6.State = stateInstance;
                                                                            }

                                                                            JToken createdValue = propertiesValue6["created"];
                                                                            if (createdValue != null && createdValue.Type != JTokenType.Null)
                                                                            {
                                                                                DateTime createdInstance = ((DateTime)createdValue);
                                                                                propertiesInstance6.Created = createdInstance;
                                                                            }

                                                                            JToken lastModifiedValue = propertiesValue6["lastModified"];
                                                                            if (lastModifiedValue != null && lastModifiedValue.Type != JTokenType.Null)
                                                                            {
                                                                                DateTime lastModifiedInstance = ((DateTime)lastModifiedValue);
                                                                                propertiesInstance6.LastModified = lastModifiedInstance;
                                                                            }

                                                                            JToken indexTypeValue = propertiesValue6["indexType"];
                                                                            if (indexTypeValue != null && indexTypeValue.Type != JTokenType.Null)
                                                                            {
                                                                                string indexTypeInstance = ((string)indexTypeValue);
                                                                                propertiesInstance6.IndexType = indexTypeInstance;
                                                                            }

                                                                            JToken schemaValue = propertiesValue6["schema"];
                                                                            if (schemaValue != null && schemaValue.Type != JTokenType.Null)
                                                                            {
                                                                                string schemaInstance2 = ((string)schemaValue);
                                                                                propertiesInstance6.Schema = schemaInstance2;
                                                                            }

                                                                            JToken tableValue = propertiesValue6["table"];
                                                                            if (tableValue != null && tableValue.Type != JTokenType.Null)
                                                                            {
                                                                                string tableInstance2 = ((string)tableValue);
                                                                                propertiesInstance6.Table = tableInstance2;
                                                                            }

                                                                            JToken columnsArray2 = propertiesValue6["columns"];
                                                                            if (columnsArray2 != null && columnsArray2.Type != JTokenType.Null)
                                                                            {
                                                                                foreach (JToken columnsValue2 in ((JArray)columnsArray2))
                                                                                {
                                                                                propertiesInstance6.Columns.Add(((string)columnsValue2));
                                                                                }
                                                                            }

                                                                            JToken includedColumnsArray = propertiesValue6["includedColumns"];
                                                                            if (includedColumnsArray != null && includedColumnsArray.Type != JTokenType.Null)
                                                                            {
                                                                                foreach (JToken includedColumnsValue in ((JArray)includedColumnsArray))
                                                                                {
                                                                                propertiesInstance6.IncludedColumns.Add(((string)includedColumnsValue));
                                                                                }
                                                                            }

                                                                            JToken indexScriptValue = propertiesValue6["indexScript"];
                                                                            if (indexScriptValue != null && indexScriptValue.Type != JTokenType.Null)
                                                                            {
                                                                                string indexScriptInstance = ((string)indexScriptValue);
                                                                                propertiesInstance6.IndexScript = indexScriptInstance;
                                                                            }

                                                                            JToken estimatedImpactArray = propertiesValue6["estimatedImpact"];
                                                                            if (estimatedImpactArray != null && estimatedImpactArray.Type != JTokenType.Null)
                                                                            {
                                                                                foreach (JToken estimatedImpactValue in ((JArray)estimatedImpactArray))
                                                                                {
                                                                                OperationImpact operationImpactInstance = new OperationImpact();
                                                                                propertiesInstance6.EstimatedImpact.Add(operationImpactInstance);

                                                                                JToken nameValue5 = estimatedImpactValue["name"];
                                                                                if (nameValue5 != null && nameValue5.Type != JTokenType.Null)
                                                                                {
                                                                                string nameInstance5 = ((string)nameValue5);
                                                                                operationImpactInstance.Name = nameInstance5;
                                                                                }

                                                                                JToken unitValue = estimatedImpactValue["unit"];
                                                                                if (unitValue != null && unitValue.Type != JTokenType.Null)
                                                                                {
                                                                                string unitInstance = ((string)unitValue);
                                                                                operationImpactInstance.Unit = unitInstance;
                                                                                }

                                                                                JToken changeValueAbsoluteValue = estimatedImpactValue["changeValueAbsolute"];
                                                                                if (changeValueAbsoluteValue != null && changeValueAbsoluteValue.Type != JTokenType.Null)
                                                                                {
                                                                                double changeValueAbsoluteInstance = ((double)changeValueAbsoluteValue);
                                                                                operationImpactInstance.ChangeValueAbsolute = changeValueAbsoluteInstance;
                                                                                }

                                                                                JToken changeValueRelativeValue = estimatedImpactValue["changeValueRelative"];
                                                                                if (changeValueRelativeValue != null && changeValueRelativeValue.Type != JTokenType.Null)
                                                                                {
                                                                                double changeValueRelativeInstance = ((double)changeValueRelativeValue);
                                                                                operationImpactInstance.ChangeValueRelative = changeValueRelativeInstance;
                                                                                }
                                                                                }
                                                                            }

                                                                            JToken reportedImpactArray = propertiesValue6["reportedImpact"];
                                                                            if (reportedImpactArray != null && reportedImpactArray.Type != JTokenType.Null)
                                                                            {
                                                                                foreach (JToken reportedImpactValue in ((JArray)reportedImpactArray))
                                                                                {
                                                                                OperationImpact operationImpactInstance2 = new OperationImpact();
                                                                                propertiesInstance6.ReportedImpact.Add(operationImpactInstance2);

                                                                                JToken nameValue6 = reportedImpactValue["name"];
                                                                                if (nameValue6 != null && nameValue6.Type != JTokenType.Null)
                                                                                {
                                                                                string nameInstance6 = ((string)nameValue6);
                                                                                operationImpactInstance2.Name = nameInstance6;
                                                                                }

                                                                                JToken unitValue2 = reportedImpactValue["unit"];
                                                                                if (unitValue2 != null && unitValue2.Type != JTokenType.Null)
                                                                                {
                                                                                string unitInstance2 = ((string)unitValue2);
                                                                                operationImpactInstance2.Unit = unitInstance2;
                                                                                }

                                                                                JToken changeValueAbsoluteValue2 = reportedImpactValue["changeValueAbsolute"];
                                                                                if (changeValueAbsoluteValue2 != null && changeValueAbsoluteValue2.Type != JTokenType.Null)
                                                                                {
                                                                                double changeValueAbsoluteInstance2 = ((double)changeValueAbsoluteValue2);
                                                                                operationImpactInstance2.ChangeValueAbsolute = changeValueAbsoluteInstance2;
                                                                                }

                                                                                JToken changeValueRelativeValue2 = reportedImpactValue["changeValueRelative"];
                                                                                if (changeValueRelativeValue2 != null && changeValueRelativeValue2.Type != JTokenType.Null)
                                                                                {
                                                                                double changeValueRelativeInstance2 = ((double)changeValueRelativeValue2);
                                                                                operationImpactInstance2.ChangeValueRelative = changeValueRelativeInstance2;
                                                                                }
                                                                                }
                                                                            }
                                                                        }

                                                                        JToken idValue5 = recommendedIndexesValue["id"];
                                                                        if (idValue5 != null && idValue5.Type != JTokenType.Null)
                                                                        {
                                                                            string idInstance5 = ((string)idValue5);
                                                                            recommendedIndexInstance.Id = idInstance5;
                                                                        }

                                                                        JToken nameValue7 = recommendedIndexesValue["name"];
                                                                        if (nameValue7 != null && nameValue7.Type != JTokenType.Null)
                                                                        {
                                                                            string nameInstance7 = ((string)nameValue7);
                                                                            recommendedIndexInstance.Name = nameInstance7;
                                                                        }

                                                                        JToken typeValue5 = recommendedIndexesValue["type"];
                                                                        if (typeValue5 != null && typeValue5.Type != JTokenType.Null)
                                                                        {
                                                                            string typeInstance5 = ((string)typeValue5);
                                                                            recommendedIndexInstance.Type = typeInstance5;
                                                                        }

                                                                        JToken locationValue5 = recommendedIndexesValue["location"];
                                                                        if (locationValue5 != null && locationValue5.Type != JTokenType.Null)
                                                                        {
                                                                            string locationInstance5 = ((string)locationValue5);
                                                                            recommendedIndexInstance.Location = locationInstance5;
                                                                        }

                                                                        JToken tagsSequenceElement5 = ((JToken)recommendedIndexesValue["tags"]);
                                                                        if (tagsSequenceElement5 != null && tagsSequenceElement5.Type != JTokenType.Null)
                                                                        {
                                                                            foreach (JProperty property5 in tagsSequenceElement5)
                                                                            {
                                                                                string tagsKey5 = ((string)property5.Name);
                                                                                string tagsValue5 = ((string)property5.Value);
                                                                                recommendedIndexInstance.Tags.Add(tagsKey5, tagsValue5);
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }

                                                            JToken idValue6 = tablesValue["id"];
                                                            if (idValue6 != null && idValue6.Type != JTokenType.Null)
                                                            {
                                                                string idInstance6 = ((string)idValue6);
                                                                tableInstance.Id = idInstance6;
                                                            }

                                                            JToken nameValue8 = tablesValue["name"];
                                                            if (nameValue8 != null && nameValue8.Type != JTokenType.Null)
                                                            {
                                                                string nameInstance8 = ((string)nameValue8);
                                                                tableInstance.Name = nameInstance8;
                                                            }

                                                            JToken typeValue6 = tablesValue["type"];
                                                            if (typeValue6 != null && typeValue6.Type != JTokenType.Null)
                                                            {
                                                                string typeInstance6 = ((string)typeValue6);
                                                                tableInstance.Type = typeInstance6;
                                                            }

                                                            JToken locationValue6 = tablesValue["location"];
                                                            if (locationValue6 != null && locationValue6.Type != JTokenType.Null)
                                                            {
                                                                string locationInstance6 = ((string)locationValue6);
                                                                tableInstance.Location = locationInstance6;
                                                            }

                                                            JToken tagsSequenceElement6 = ((JToken)tablesValue["tags"]);
                                                            if (tagsSequenceElement6 != null && tagsSequenceElement6.Type != JTokenType.Null)
                                                            {
                                                                foreach (JProperty property6 in tagsSequenceElement6)
                                                                {
                                                                    string tagsKey6 = ((string)property6.Name);
                                                                    string tagsValue6 = ((string)property6.Value);
                                                                    tableInstance.Tags.Add(tagsKey6, tagsValue6);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }

                                                JToken idValue7 = schemasValue["id"];
                                                if (idValue7 != null && idValue7.Type != JTokenType.Null)
                                                {
                                                    string idInstance7 = ((string)idValue7);
                                                    schemaInstance.Id = idInstance7;
                                                }

                                                JToken nameValue9 = schemasValue["name"];
                                                if (nameValue9 != null && nameValue9.Type != JTokenType.Null)
                                                {
                                                    string nameInstance9 = ((string)nameValue9);
                                                    schemaInstance.Name = nameInstance9;
                                                }

                                                JToken typeValue7 = schemasValue["type"];
                                                if (typeValue7 != null && typeValue7.Type != JTokenType.Null)
                                                {
                                                    string typeInstance7 = ((string)typeValue7);
                                                    schemaInstance.Type = typeInstance7;
                                                }

                                                JToken locationValue7 = schemasValue["location"];
                                                if (locationValue7 != null && locationValue7.Type != JTokenType.Null)
                                                {
                                                    string locationInstance7 = ((string)locationValue7);
                                                    schemaInstance.Location = locationInstance7;
                                                }

                                                JToken tagsSequenceElement7 = ((JToken)schemasValue["tags"]);
                                                if (tagsSequenceElement7 != null && tagsSequenceElement7.Type != JTokenType.Null)
                                                {
                                                    foreach (JProperty property7 in tagsSequenceElement7)
                                                    {
                                                        string tagsKey7 = ((string)property7.Name);
                                                        string tagsValue7 = ((string)property7.Value);
                                                        schemaInstance.Tags.Add(tagsKey7, tagsValue7);
                                                    }
                                                }
                                            }
                                        }

                                        JToken defaultSecondaryLocationValue = propertiesValue["defaultSecondaryLocation"];
                                        if (defaultSecondaryLocationValue != null && defaultSecondaryLocationValue.Type != JTokenType.Null)
                                        {
                                            string defaultSecondaryLocationInstance = ((string)defaultSecondaryLocationValue);
                                            propertiesInstance.DefaultSecondaryLocation = defaultSecondaryLocationInstance;
                                        }

                                        JToken createModeValue = propertiesValue["createMode"];
                                        if (createModeValue != null && createModeValue.Type != JTokenType.Null)
                                        {
                                            string createModeInstance = ((string)createModeValue);
                                            propertiesInstance.CreateMode = createModeInstance;
                                        }
                                    }

                                    JToken idValue8 = valueValue["id"];
                                    if (idValue8 != null && idValue8.Type != JTokenType.Null)
                                    {
                                        string idInstance8 = ((string)idValue8);
                                        databaseInstance.Id = idInstance8;
                                    }

                                    JToken nameValue10 = valueValue["name"];
                                    if (nameValue10 != null && nameValue10.Type != JTokenType.Null)
                                    {
                                        string nameInstance10 = ((string)nameValue10);
                                        databaseInstance.Name = nameInstance10;
                                    }

                                    JToken typeValue8 = valueValue["type"];
                                    if (typeValue8 != null && typeValue8.Type != JTokenType.Null)
                                    {
                                        string typeInstance8 = ((string)typeValue8);
                                        databaseInstance.Type = typeInstance8;
                                    }

                                    JToken locationValue8 = valueValue["location"];
                                    if (locationValue8 != null && locationValue8.Type != JTokenType.Null)
                                    {
                                        string locationInstance8 = ((string)locationValue8);
                                        databaseInstance.Location = locationInstance8;
                                    }

                                    JToken tagsSequenceElement8 = ((JToken)valueValue["tags"]);
                                    if (tagsSequenceElement8 != null && tagsSequenceElement8.Type != JTokenType.Null)
                                    {
                                        foreach (JProperty property8 in tagsSequenceElement8)
                                        {
                                            string tagsKey8 = ((string)property8.Name);
                                            string tagsValue8 = ((string)property8.Value);
                                            databaseInstance.Tags.Add(tagsKey8, tagsValue8);
                                        }
                                    }
                                }
                            }
                        }

                    }
                    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();
                }
            }
        }
    }
}