/// <summary>
        /// Performs the call to export database using the server data service context channel.
        /// </summary>
        /// <param name="serverName">The name of the server to connect to.</param>
        /// <param name="fullyQualifiedServerName">The fully qualfied name of the server to connect to.</param>
        /// <param name="userName">The username for authentication</param>
        /// <param name="password">The password for authentication</param>
        /// <param name="requestId">The request Id of the operation to query</param>
        /// <returns>The status of the import/export operation</returns>
        internal IEnumerable <Services.ImportExport.StatusInfo> GetAzureSqlDatabaseImportExportStatusProcess(
            string serverName,
            string fullyQualifiedServerName,
            string userName,
            string password,
            string requestId)
        {
            // Get the SQL management client for the current subscription
            SqlManagementClient sqlManagementClient = GetCurrentSqlClient();

            // Start the database export operation
            DacGetStatusResponse response = sqlManagementClient.Dac.GetStatus(
                serverName,
                fullyQualifiedServerName,
                userName,
                password,
                requestId);

            // Construct the result
            IEnumerable <Services.ImportExport.StatusInfo> result = response.StatusInfoList.Select(status => new Services.ImportExport.StatusInfo
            {
                BlobUri          = status.BlobUri.ToString(),
                ServerName       = status.ServerName,
                DatabaseName     = status.DatabaseName,
                Status           = status.Status,
                RequestId        = status.RequestId,
                LastModifiedTime = status.LastModifiedTime,
                QueuedTime       = status.QueuedTime,
                RequestType      = status.RequestType,
                ErrorMessage     = status.ErrorMessage,
            });

            return(result);
        }
        /// <summary>
        /// Gets the status of the DAC.
        /// </summary>
        /// <param name='serverName'>
        /// The name of the server.
        /// </param>
        /// <param name='fullyQualifiedServerName'>
        /// The fully qualified name of the server.
        /// </param>
        /// <param name='username'>
        /// The server's username.
        /// </param>
        /// <param name='password'>
        /// The server's password.
        /// </param>
        /// <param name='requestId'>
        /// The request ID of the operation being queried.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The response structure for the DAC GetStatus operation.
        /// </returns>
        public async Task <DacGetStatusResponse> GetStatusAsync(string serverName, string fullyQualifiedServerName, string username, string password, string requestId, CancellationToken cancellationToken)
        {
            // Validate
            if (serverName == null)
            {
                throw new ArgumentNullException("serverName");
            }
            if (fullyQualifiedServerName == null)
            {
                throw new ArgumentNullException("fullyQualifiedServerName");
            }
            if (username == null)
            {
                throw new ArgumentNullException("username");
            }
            if (password == null)
            {
                throw new ArgumentNullException("password");
            }
            if (requestId == null)
            {
                throw new ArgumentNullException("requestId");
            }

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

            if (shouldTrace)
            {
                invocationId = Tracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("serverName", serverName);
                tracingParameters.Add("fullyQualifiedServerName", fullyQualifiedServerName);
                tracingParameters.Add("username", username);
                tracingParameters.Add("password", password);
                tracingParameters.Add("requestId", requestId);
                Tracing.Enter(invocationId, this, "GetStatusAsync", tracingParameters);
            }

            // Construct URL
            string url = new Uri(this.Client.BaseUri, "/").ToString() + this.Client.Credentials.SubscriptionId + "/services/sqlservers/servers/" + serverName + "/DacOperations/Status?";

            url = url + "servername=" + Uri.EscapeUriString(fullyQualifiedServerName);
            url = url + "&username="******"&password="******"&reqId=" + Uri.EscapeUriString(requestId);

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Get;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("x-ms-version", "2012-03-01");

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

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        Tracing.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        Tracing.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false), CloudExceptionType.Xml);
                        if (shouldTrace)
                        {
                            Tracing.Error(invocationId, ex);
                        }
                        throw ex;
                    }

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

                    result = new DacGetStatusResponse();
                    XDocument responseDoc = XDocument.Parse(responseContent);

                    XElement arrayOfStatusInfoElement = responseDoc.Element(XName.Get("ArrayOfStatusInfo", "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes"));
                    if (arrayOfStatusInfoElement != null)
                    {
                        if (arrayOfStatusInfoElement != null)
                        {
                            foreach (XElement statusInfoElement in arrayOfStatusInfoElement.Elements(XName.Get("StatusInfo", "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes")))
                            {
                                DacGetStatusResponse.StatusInfo statusInfoInstance = new DacGetStatusResponse.StatusInfo();
                                result.StatusInfoList.Add(statusInfoInstance);

                                XElement blobUriElement = statusInfoElement.Element(XName.Get("BlobUri", "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes"));
                                if (blobUriElement != null)
                                {
                                    Uri blobUriInstance = TypeConversion.TryParseUri(blobUriElement.Value);
                                    statusInfoInstance.BlobUri = blobUriInstance;
                                }

                                XElement databaseNameElement = statusInfoElement.Element(XName.Get("DatabaseName", "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes"));
                                if (databaseNameElement != null)
                                {
                                    string databaseNameInstance = databaseNameElement.Value;
                                    statusInfoInstance.DatabaseName = databaseNameInstance;
                                }

                                XElement errorMessageElement = statusInfoElement.Element(XName.Get("ErrorMessage", "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes"));
                                if (errorMessageElement != null)
                                {
                                    bool       isNil        = false;
                                    XAttribute nilAttribute = errorMessageElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
                                    if (nilAttribute != null)
                                    {
                                        isNil = nilAttribute.Value == "true";
                                    }
                                    if (isNil == false)
                                    {
                                        string errorMessageInstance = errorMessageElement.Value;
                                        statusInfoInstance.ErrorMessage = errorMessageInstance;
                                    }
                                }

                                XElement lastModifiedTimeElement = statusInfoElement.Element(XName.Get("LastModifiedTime", "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes"));
                                if (lastModifiedTimeElement != null)
                                {
                                    DateTime lastModifiedTimeInstance = DateTime.Parse(lastModifiedTimeElement.Value, CultureInfo.InvariantCulture);
                                    statusInfoInstance.LastModifiedTime = lastModifiedTimeInstance;
                                }

                                XElement queuedTimeElement = statusInfoElement.Element(XName.Get("QueuedTime", "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes"));
                                if (queuedTimeElement != null)
                                {
                                    DateTime queuedTimeInstance = DateTime.Parse(queuedTimeElement.Value, CultureInfo.InvariantCulture);
                                    statusInfoInstance.QueuedTime = queuedTimeInstance;
                                }

                                XElement requestIdElement = statusInfoElement.Element(XName.Get("RequestId", "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes"));
                                if (requestIdElement != null)
                                {
                                    string requestIdInstance = requestIdElement.Value;
                                    statusInfoInstance.RequestId = requestIdInstance;
                                }

                                XElement requestTypeElement = statusInfoElement.Element(XName.Get("RequestType", "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes"));
                                if (requestTypeElement != null)
                                {
                                    string requestTypeInstance = requestTypeElement.Value;
                                    statusInfoInstance.RequestType = requestTypeInstance;
                                }

                                XElement serverNameElement = statusInfoElement.Element(XName.Get("ServerName", "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes"));
                                if (serverNameElement != null)
                                {
                                    string serverNameInstance = serverNameElement.Value;
                                    statusInfoInstance.ServerName = serverNameInstance;
                                }

                                XElement statusElement = statusInfoElement.Element(XName.Get("Status", "http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes"));
                                if (statusElement != null)
                                {
                                    string statusInstance = statusElement.Value;
                                    statusInfoInstance.Status = statusInstance;
                                }
                            }
                        }
                    }

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

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