/* jshint latedef:false */
/* jshint forin:false */
/* jshint noempty:false */

// 
// Copyright (c) Microsoft and contributors.  All rights reserved.
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//   http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// 
// See the License for the specific language governing permissions and
// limitations under the License.
// 

// Warning: This code was generated by a tool.
// 
// Changes to this file may cause incorrect behavior and will be lost if the
// code is regenerated.

'use strict';

var util = require('util');
var _ = require('underscore');
var azureCommon = require('azure-common');
var xml = azureCommon.xml2js;
var js2xml = azureCommon.js2xml;
var Service = azureCommon.Service;
var WebResource = azureCommon.WebResource;

var SqlManagementClient = ( /** @lends SqlManagementClient */ function() {
  /**
   * @class
   * This is the main client class for interacting with the Azure SQL Database
   * REST APIs.
   * Initializes a new instance of the SqlManagementClient class.
   * @constructor
   * 
   * @param {SubscriptionCloudCredentials} credentials Gets subscription
   * credentials which uniquely identify Microsoft Azure subscription. The
   * subscription ID forms part of the URI for every service call.
   * 
   * @param {string} [credentials.subscriptionId]
   * 
   * @param {string} [baseUri] Gets the URI used as the base for all cloud
   * service requests.
   * 
   * @param {Array} filters
   */
  function SqlManagementClient(credentials, baseUri, filters) {
    if (credentials === null || credentials === undefined) {
      throw new Error('credentials cannot be null.');
    }
    
    SqlManagementClient['super_'].call(this, credentials, filters);
    
    this.credentials = credentials;
    this.baseUri = baseUri;
    if (this.baseUri === null || this.baseUri === undefined) {
      this.baseUri = 'https://management.core.windows.net';
    }
    if (this.apiVersion === null || this.apiVersion === undefined) {
      this.apiVersion = '2012-03-01';
    }
    if (this.longRunningOperationInitialTimeout === null || this.longRunningOperationInitialTimeout === undefined) {
      this.longRunningOperationInitialTimeout = -1;
    }
    if (this.longRunningOperationRetryTimeout === null || this.longRunningOperationRetryTimeout === undefined) {
      this.longRunningOperationRetryTimeout = -1;
    }
    /**
     * Provides an instance of the [DacOperations](-DacOperations.html) object.
     * @type {object}
     */
    this.dac = new DacOperations(this);
    /**
     * Provides an instance of the
     * [DatabaseCopyOperations](-DatabaseCopyOperations.html) object.
     * @type {object}
     */
    this.databaseCopies = new DatabaseCopyOperations(this);
    /**
     * Provides an instance of the
     * [DatabaseOperationOperations](-DatabaseOperationOperations.html) object.
     * @type {object}
     */
    this.databaseOperations = new DatabaseOperationOperations(this);
    /**
     * Provides an instance of the
     * [DatabaseOperations](-DatabaseOperations.html) object.
     * @type {object}
     */
    this.databases = new DatabaseOperations(this);
    /**
     * Provides an instance of the
     * [FirewallRuleOperations](-FirewallRuleOperations.html) object.
     * @type {object}
     */
    this.firewallRules = new FirewallRuleOperations(this);
    /**
     * Provides an instance of the [QuotaOperations](-QuotaOperations.html)
     * object.
     * @type {object}
     */
    this.quotas = new QuotaOperations(this);
    /**
     * Provides an instance of the
     * [RecoverableDatabaseOperations](-RecoverableDatabaseOperations.html)
     * object.
     * @type {object}
     */
    this.recoverableDatabases = new RecoverableDatabaseOperations(this);
    /**
     * Provides an instance of the
     * [RecoverDatabaseOperations](-RecoverDatabaseOperations.html) object.
     * @type {object}
     */
    this.recoverDatabaseOperations = new RecoverDatabaseOperations(this);
    /**
     * Provides an instance of the
     * [RestorableDroppedDatabaseOperations](-RestorableDroppedDatabaseOperations.html)
     * object.
     * @type {object}
     */
    this.restorableDroppedDatabases = new RestorableDroppedDatabaseOperations(this);
    /**
     * Provides an instance of the
     * [RestoreDatabaseOperations](-RestoreDatabaseOperations.html) object.
     * @type {object}
     */
    this.restoreDatabaseOperations = new RestoreDatabaseOperations(this);
    /**
     * Provides an instance of the [ServerOperations](-ServerOperations.html)
     * object.
     * @type {object}
     */
    this.servers = new ServerOperations(this);
    /**
     * Provides an instance of the
     * [ServiceObjectiveOperations](-ServiceObjectiveOperations.html) object.
     * @type {object}
     */
    this.serviceObjectives = new ServiceObjectiveOperations(this);
  }
  
  util.inherits(SqlManagementClient, Service);
  
  
  return SqlManagementClient;
})();
exports.SqlManagementClient = SqlManagementClient;

var DacOperations = ( /** @lends DacOperations */ function() {
  /**
   * @class
   * Includes operations for importing and exporting Azure SQL Databases into
   * and out of Azure blob storage.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [SqlManagementClient] {@link
   * SqlManagementClient~SqlManagementClient}.
   * See [dac] {@link SqlManagementClient~SqlManagementClient#dac}.
   * Initializes a new instance of the DacOperations class.
   * @constructor
   * 
   * @param {SqlManagementClient} client Reference to the service client.
   */
  function DacOperations(client) {
    this.client = client;
  }
  
  /**
   * Exports an Azure SQL Database into a DACPAC file in Azure Blob Storage.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server in
   * which the database to export resides.
   * 
   * @param {DacExportParameters} [parametersOrCallback] The parameters needed
   * to initiate the export request.
   * 
   * @param {BlobCredentialsParameter} [parametersOrCallback.blobCredentials]
   * Gets or sets the credentials information needed for setting where the
   * DACPAC file will be exported to in Azure Blob Storage.
   * 
   * @param {string} [parametersOrCallback.blobCredentials.uri] Gets or sets
   * the URI of where the DACPAC file should be stored in Azure Blob Storage.
   * 
   * @param {string} [parametersOrCallback.blobCredentials.storageAccessKey]
   * Gets or sets the access key for the Azure Storage account.
   * 
   * @param {ConnectionInfoParameter} [parametersOrCallback.connectionInfo]
   * Gets or sets the connection information needed for the Azure SQL Database.
   * 
   * @param {string} [parametersOrCallback.connectionInfo.databaseName] Gets or
   * sets the name of the database to be exported.
   * 
   * @param {string} [parametersOrCallback.connectionInfo.password] Gets or
   * sets the password for the database administrator user.
   * 
   * @param {string} [parametersOrCallback.connectionInfo.serverName] Gets or
   * sets the Azure SQL Database Server name where the database resides.
   * 
   * @param {string} [parametersOrCallback.connectionInfo.userName] Gets or
   * sets the username of the database administrator user.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DacOperations.prototype.exportMethod = function(serverName, parametersOrCallback, callback) {
    var parameters = parametersOrCallback;
    if (_.isFunction(parameters)) {
      callback = parameters;
      parameters = null;
    }
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (parameters !== null && parameters !== undefined) {
      if (parameters.blobCredentials !== null && parameters.blobCredentials !== undefined) {
        if (parameters.blobCredentials.storageAccessKey === null || parameters.blobCredentials.storageAccessKey === undefined) {
          return callback(new Error('parameters.blobCredentials. cannot be null.'));
        }
        if (parameters.blobCredentials.uri === null || parameters.blobCredentials.uri === undefined) {
          return callback(new Error('parameters.blobCredentials. cannot be null.'));
        }
      }
      if (parameters.connectionInfo !== null && parameters.connectionInfo !== undefined) {
        if (parameters.connectionInfo.databaseName === null || parameters.connectionInfo.databaseName === undefined) {
          return callback(new Error('parameters.connectionInfo. cannot be null.'));
        }
        if (parameters.connectionInfo.password === null || parameters.connectionInfo.password === undefined) {
          return callback(new Error('parameters.connectionInfo. cannot be null.'));
        }
        if (parameters.connectionInfo.serverName === null || parameters.connectionInfo.serverName === undefined) {
          return callback(new Error('parameters.connectionInfo. cannot be null.'));
        }
        if (parameters.connectionInfo.userName === null || parameters.connectionInfo.userName === undefined) {
          return callback(new Error('parameters.connectionInfo. cannot be null.'));
        }
      }
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/DacOperations/Export';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    if (parameters !== null && parameters !== undefined) {
      var exportInputElement = js2xml.createElement('ExportInput', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
      js2xml.addChildElement(requestDoc, exportInputElement);
      
      if (parameters.blobCredentials !== null && parameters.blobCredentials !== undefined) {
        var blobCredentialsElement = js2xml.createElement('BlobCredentials', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
        js2xml.addChildElement(exportInputElement, blobCredentialsElement);
        
        var typeAttribute = js2xml.createAttribute('p2:type', 'http://www.w3.org/2001/XMLSchema-instance');
        js2xml.setAttributeValue(typeAttribute, 'BlobStorageAccessKeyCredentials');
        js2xml.addAttribute(blobCredentialsElement, typeAttribute);

        var xmlnsAttribute = js2xml.createAttribute('xmlns:p2', 'http://www.w3.org/2001/XMLSchema-instance');
        js2xml.setAttributeValue(xmlnsAttribute, 'http://www.w3.org/2001/XMLSchema-instance');
        js2xml.addAttribute(blobCredentialsElement, xmlnsAttribute);
        
        var uriElement = js2xml.createElement('Uri', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
        js2xml.setElementValue(uriElement, parameters.blobCredentials.uri);
        js2xml.addChildElement(blobCredentialsElement, uriElement);
        
        var storageAccessKeyElement = js2xml.createElement('StorageAccessKey', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
        js2xml.setElementValue(storageAccessKeyElement, parameters.blobCredentials.storageAccessKey);
        js2xml.addChildElement(blobCredentialsElement, storageAccessKeyElement);
      }
      
      if (parameters.connectionInfo !== null && parameters.connectionInfo !== undefined) {
        var connectionInfoElement = js2xml.createElement('ConnectionInfo', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
        js2xml.addChildElement(exportInputElement, connectionInfoElement);
        
        var databaseNameElement = js2xml.createElement('DatabaseName', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
        js2xml.setElementValue(databaseNameElement, parameters.connectionInfo.databaseName);
        js2xml.addChildElement(connectionInfoElement, databaseNameElement);
        
        var passwordElement = js2xml.createElement('Password', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
        js2xml.setElementValue(passwordElement, parameters.connectionInfo.password);
        js2xml.addChildElement(connectionInfoElement, passwordElement);
        
        var serverNameElement = js2xml.createElement('ServerName', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
        js2xml.setElementValue(serverNameElement, parameters.connectionInfo.serverName);
        js2xml.addChildElement(connectionInfoElement, serverNameElement);
        
        var userNameElement = js2xml.createElement('UserName', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
        js2xml.setElementValue(userNameElement, parameters.connectionInfo.userName);
        js2xml.addChildElement(connectionInfoElement, userNameElement);
      }
    }
    
    requestContent = js2xml.serializeDocument(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var guidElement = js2xml.getElement(responseDoc, responseDoc, 'GUID', 'HTTP://SCHEMAS.MICROSOFT.COM/2003/10/SERIALIZATION/');
          if (guidElement !== null && guidElement !== undefined) {
            result.guid = guidElement;
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets the status of the import or export operation in the specified server
   * with the corresponding request ID.  The request ID is provided in the
   * responses of the import or export operation.
   * 
   * @param {string} serverName The name of the server in which the import or
   * export operation is taking place.
   * 
   * @param {string} fullyQualifiedServerName The fully qualified domain name
   * of the Azure SQL Database Server where the operation is taking place.
   * Example: a9s7f7s9d3.database.windows.net
   * 
   * @param {string} username The administrator username for the Azure SQL
   * Database Server.
   * 
   * @param {string} password The administrator password for the Azure SQL
   * Database Server.
   * 
   * @param {string} requestId The request ID of the operation being queried.
   * The request ID is obtained from the responses of the import and export
   * operations.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DacOperations.prototype.getStatus = function(serverName, fullyQualifiedServerName, username, password, requestId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (fullyQualifiedServerName === null || fullyQualifiedServerName === undefined) {
      return callback(new Error('fullyQualifiedServerName cannot be null.'));
    }
    if (username === null || username === undefined) {
      return callback(new Error('username cannot be null.'));
    }
    if (password === null || password === undefined) {
      return callback(new Error('password cannot be null.'));
    }
    if (requestId === null || requestId === undefined) {
      return callback(new Error('requestId cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/DacOperations/Status';
    var queryParameters = [];
    queryParameters.push('servername=' + encodeURIComponent(fullyQualifiedServerName));
    queryParameters.push('username=' + encodeURIComponent(username));
    queryParameters.push('password=' + encodeURIComponent(password));
    queryParameters.push('reqId=' + encodeURIComponent(requestId));
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { statusInfoList: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var arrayOfStatusInfoElement = js2xml.getElement(responseDoc, responseDoc, 'ARRAYOFSTATUSINFO', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
          if (arrayOfStatusInfoElement !== null && arrayOfStatusInfoElement !== undefined) {
            if (arrayOfStatusInfoElement !== null && arrayOfStatusInfoElement !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, arrayOfStatusInfoElement, 'STATUSINFO', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES').length; loweredIndex1 = loweredIndex1 + 1) {
                var statusInfoElement = js2xml.getElements(responseDoc, arrayOfStatusInfoElement, 'STATUSINFO', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES')[loweredIndex1];
                var statusInfoInstance = {};
                result.statusInfoList.push(statusInfoInstance);
                
                var blobUriElement = js2xml.getElement(responseDoc, statusInfoElement, 'BLOBURI', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
                if (blobUriElement !== null && blobUriElement !== undefined) {
                  var blobUriInstance = blobUriElement;
                  statusInfoInstance.blobUri = blobUriInstance;
                }
                
                var databaseNameElement = js2xml.getElement(responseDoc, statusInfoElement, 'DATABASENAME', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
                if (databaseNameElement !== null && databaseNameElement !== undefined) {
                  var databaseNameInstance = databaseNameElement;
                  statusInfoInstance.databaseName = databaseNameInstance;
                }
                
                var errorMessageElement = js2xml.getElement(responseDoc, statusInfoElement, 'ERRORMESSAGE', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
                if (errorMessageElement !== null && errorMessageElement !== undefined) {
                  var isNil = false;
                  var nilAttribute = js2xml.getAttribute(responseDoc, errorMessageElement, 'NIL', 'HTTP://WWW.W3.ORG/2001/XMLSCHEMA-INSTANCE');
                  if (nilAttribute !== null && nilAttribute !== undefined) {
                    isNil = nilAttribute === 'true';
                  }
                  if (isNil === false) {
                    var errorMessageInstance = errorMessageElement;
                    statusInfoInstance.errorMessage = errorMessageInstance;
                  }
                }
                
                var lastModifiedTimeElement = js2xml.getElement(responseDoc, statusInfoElement, 'LASTMODIFIEDTIME', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
                if (lastModifiedTimeElement !== null && lastModifiedTimeElement !== undefined && lastModifiedTimeElement.length !== 0) {
                  var lastModifiedTimeInstance = new Date(lastModifiedTimeElement);
                  statusInfoInstance.lastModifiedTime = lastModifiedTimeInstance;
                }
                
                var queuedTimeElement = js2xml.getElement(responseDoc, statusInfoElement, 'QUEUEDTIME', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
                if (queuedTimeElement !== null && queuedTimeElement !== undefined && queuedTimeElement.length !== 0) {
                  var queuedTimeInstance = new Date(queuedTimeElement);
                  statusInfoInstance.queuedTime = queuedTimeInstance;
                }
                
                var requestIdElement = js2xml.getElement(responseDoc, statusInfoElement, 'REQUESTID', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
                if (requestIdElement !== null && requestIdElement !== undefined) {
                  var requestIdInstance = requestIdElement;
                  statusInfoInstance.requestId = requestIdInstance;
                }
                
                var requestTypeElement = js2xml.getElement(responseDoc, statusInfoElement, 'REQUESTTYPE', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
                if (requestTypeElement !== null && requestTypeElement !== undefined) {
                  var requestTypeInstance = requestTypeElement;
                  statusInfoInstance.requestType = requestTypeInstance;
                }
                
                var serverNameElement = js2xml.getElement(responseDoc, statusInfoElement, 'SERVERNAME', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
                if (serverNameElement !== null && serverNameElement !== undefined) {
                  var serverNameInstance = serverNameElement;
                  statusInfoInstance.serverName = serverNameInstance;
                }
                
                var statusElement = js2xml.getElement(responseDoc, statusInfoElement, 'STATUS', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
                if (statusElement !== null && statusElement !== undefined) {
                  var statusInstance = statusElement;
                  statusInfoInstance.status = statusInstance;
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets the status of the import or export operation in the specified server
   * with the corresponding request ID.  The request ID is provided in the
   * responses of the import or export operation.
   * 
   * @param {string} serverName The name of the server in which the import or
   * export operation is taking place.
   * 
   * @param {DacGetStatusParameters} parameters The parameters needed to get
   * the status of an import or export operation.
   * 
   * @param {string} parameters.serverName Gets or sets the fully qualified
   * name of the Azure SQL Database server where the import or export
   * operation is occurring.
   * 
   * @param {string} parameters.userName Gets or sets the username for the
   * Azure SQL Database server where the import or export operation is
   * occurring.
   * 
   * @param {string} parameters.password Gets or sets the password for the
   * Azure SQL Database server where the import or export operation is
   * occurring.
   * 
   * @param {string} parameters.requestId Gets or sets the Id for the import or
   * export operation of which to query the status.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DacOperations.prototype.getStatusPost = function(serverName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.password === null || parameters.password === undefined) {
      return callback(new Error('parameters.password cannot be null.'));
    }
    if (parameters.requestId === null || parameters.requestId === undefined) {
      return callback(new Error('parameters.requestId cannot be null.'));
    }
    if (parameters.serverName === null || parameters.serverName === undefined) {
      return callback(new Error('parameters.serverName cannot be null.'));
    }
    if (parameters.userName === null || parameters.userName === undefined) {
      return callback(new Error('parameters.userName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/DacOperations/Status';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var statusInputElement = js2xml.createElement('StatusInput', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
    js2xml.addChildElement(requestDoc, statusInputElement);
    
    var passwordElement = js2xml.createElement('Password', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
    js2xml.setElementValue(passwordElement, parameters.password);
    js2xml.addChildElement(statusInputElement, passwordElement);
    
    var requestIdElement = js2xml.createElement('RequestId', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
    js2xml.setElementValue(requestIdElement, parameters.requestId);
    js2xml.addChildElement(statusInputElement, requestIdElement);
    
    var serverNameElement = js2xml.createElement('ServerName', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
    js2xml.setElementValue(serverNameElement, parameters.serverName);
    js2xml.addChildElement(statusInputElement, serverNameElement);
    
    var userNameElement = js2xml.createElement('UserName', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
    js2xml.setElementValue(userNameElement, parameters.userName);
    js2xml.addChildElement(statusInputElement, userNameElement);
    
    requestContent = js2xml.serializeDocument(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { statusInfoList: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var arrayOfStatusInfoElement = js2xml.getElement(responseDoc, responseDoc, 'ARRAYOFSTATUSINFO', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
          if (arrayOfStatusInfoElement !== null && arrayOfStatusInfoElement !== undefined) {
            if (arrayOfStatusInfoElement !== null && arrayOfStatusInfoElement !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, arrayOfStatusInfoElement, 'STATUSINFO', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES').length; loweredIndex1 = loweredIndex1 + 1) {
                var statusInfoElement = js2xml.getElements(responseDoc, arrayOfStatusInfoElement, 'STATUSINFO', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES')[loweredIndex1];
                var statusInfoInstance = {};
                result.statusInfoList.push(statusInfoInstance);
                
                var blobUriElement = js2xml.getElement(responseDoc, statusInfoElement, 'BLOBURI', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
                if (blobUriElement !== null && blobUriElement !== undefined) {
                  var blobUriInstance = blobUriElement;
                  statusInfoInstance.blobUri = blobUriInstance;
                }
                
                var databaseNameElement = js2xml.getElement(responseDoc, statusInfoElement, 'DATABASENAME', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
                if (databaseNameElement !== null && databaseNameElement !== undefined) {
                  var databaseNameInstance = databaseNameElement;
                  statusInfoInstance.databaseName = databaseNameInstance;
                }
                
                var errorMessageElement = js2xml.getElement(responseDoc, statusInfoElement, 'ERRORMESSAGE', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
                if (errorMessageElement !== null && errorMessageElement !== undefined) {
                  var isNil = false;
                  var nilAttribute = js2xml.getAttribute(responseDoc, errorMessageElement, 'NIL', 'HTTP://WWW.W3.ORG/2001/XMLSCHEMA-INSTANCE');
                  if (nilAttribute !== null && nilAttribute !== undefined) {
                    isNil = nilAttribute === 'true';
                  }
                  if (isNil === false) {
                    var errorMessageInstance = errorMessageElement;
                    statusInfoInstance.errorMessage = errorMessageInstance;
                  }
                }
                
                var lastModifiedTimeElement = js2xml.getElement(responseDoc, statusInfoElement, 'LASTMODIFIEDTIME', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
                if (lastModifiedTimeElement !== null && lastModifiedTimeElement !== undefined && lastModifiedTimeElement.length !== 0) {
                  var lastModifiedTimeInstance = new Date(lastModifiedTimeElement);
                  statusInfoInstance.lastModifiedTime = lastModifiedTimeInstance;
                }
                
                var queuedTimeElement = js2xml.getElement(responseDoc, statusInfoElement, 'QUEUEDTIME', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
                if (queuedTimeElement !== null && queuedTimeElement !== undefined && queuedTimeElement.length !== 0) {
                  var queuedTimeInstance = new Date(queuedTimeElement);
                  statusInfoInstance.queuedTime = queuedTimeInstance;
                }
                
                var requestIdElement2 = js2xml.getElement(responseDoc, statusInfoElement, 'REQUESTID', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
                if (requestIdElement2 !== null && requestIdElement2 !== undefined) {
                  var requestIdInstance = requestIdElement2;
                  statusInfoInstance.requestId = requestIdInstance;
                }
                
                var requestTypeElement = js2xml.getElement(responseDoc, statusInfoElement, 'REQUESTTYPE', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
                if (requestTypeElement !== null && requestTypeElement !== undefined) {
                  var requestTypeInstance = requestTypeElement;
                  statusInfoInstance.requestType = requestTypeInstance;
                }
                
                var serverNameElement2 = js2xml.getElement(responseDoc, statusInfoElement, 'SERVERNAME', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
                if (serverNameElement2 !== null && serverNameElement2 !== undefined) {
                  var serverNameInstance = serverNameElement2;
                  statusInfoInstance.serverName = serverNameInstance;
                }
                
                var statusElement = js2xml.getElement(responseDoc, statusInfoElement, 'STATUS', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.SQLSERVER.MANAGEMENT.DAC.SERVICETYPES');
                if (statusElement !== null && statusElement !== undefined) {
                  var statusInstance = statusElement;
                  statusInfoInstance.status = statusInstance;
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Initiates an Import of a DACPAC file from Azure Blob Storage into a Azure
   * SQL Database.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server into
   * which the database is being imported.
   * 
   * @param {DacImportParameters} [parametersOrCallback] The parameters needed
   * to initiated the Import request.
   * 
   * @param {string} [parametersOrCallback.azureEdition] Gets or sets the
   * edition for the database that will be created upon import.
   * 
   * @param {BlobCredentialsParameter} [parametersOrCallback.blobCredentials]
   * Gets or sets the credentials for retrieving the DACPAC from Azure Blob
   * Storage.
   * 
   * @param {string} [parametersOrCallback.blobCredentials.uri] Gets or sets
   * the URI of the DACPAC file stored in Azure Blob Storage to be imported.
   * 
   * @param {string} [parametersOrCallback.blobCredentials.storageAccessKey]
   * Gets or sets the access key for the Azure Blob Storage account where the
   * DACPAC file is stored.
   * 
   * @param {ConnectionInfoParameter} [parametersOrCallback.connectionInfo]
   * Gets or sets the connection information needed for connecting to SQL
   * Azure and creating a database to import into.
   * 
   * @param {string} [parametersOrCallback.connectionInfo.databaseName] Gets or
   * sets the name of the database into which the DACPAC file will be imported.
   * 
   * @param {string} [parametersOrCallback.connectionInfo.password] Gets or
   * sets the password for the server administrator.
   * 
   * @param {string} [parametersOrCallback.connectionInfo.serverName] Gets or
   * sets the Azure SQL Database Server name where the imported database will
   * be created.
   * 
   * @param {string} [parametersOrCallback.connectionInfo.userName] Gets or
   * sets the username of the server administration.
   * 
   * @param {number} [parametersOrCallback.databaseSizeInGB] Gets or sets the
   * size for the database that will be created upon import.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DacOperations.prototype.importMethod = function(serverName, parametersOrCallback, callback) {
    var parameters = parametersOrCallback;
    if (_.isFunction(parameters)) {
      callback = parameters;
      parameters = null;
    }
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (parameters !== null && parameters !== undefined) {
      if (parameters.blobCredentials !== null && parameters.blobCredentials !== undefined) {
        if (parameters.blobCredentials.storageAccessKey === null || parameters.blobCredentials.storageAccessKey === undefined) {
          return callback(new Error('parameters.blobCredentials. cannot be null.'));
        }
        if (parameters.blobCredentials.uri === null || parameters.blobCredentials.uri === undefined) {
          return callback(new Error('parameters.blobCredentials. cannot be null.'));
        }
      }
      if (parameters.connectionInfo !== null && parameters.connectionInfo !== undefined) {
        if (parameters.connectionInfo.databaseName === null || parameters.connectionInfo.databaseName === undefined) {
          return callback(new Error('parameters.connectionInfo. cannot be null.'));
        }
        if (parameters.connectionInfo.password === null || parameters.connectionInfo.password === undefined) {
          return callback(new Error('parameters.connectionInfo. cannot be null.'));
        }
        if (parameters.connectionInfo.serverName === null || parameters.connectionInfo.serverName === undefined) {
          return callback(new Error('parameters.connectionInfo. cannot be null.'));
        }
        if (parameters.connectionInfo.userName === null || parameters.connectionInfo.userName === undefined) {
          return callback(new Error('parameters.connectionInfo. cannot be null.'));
        }
      }
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/DacOperations/Import';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    if (parameters !== null && parameters !== undefined) {
      var importInputElement = js2xml.createElement('ImportInput', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
      js2xml.addChildElement(requestDoc, importInputElement);
      
      if (parameters.azureEdition !== null && parameters.azureEdition !== undefined) {
        var azureEditionElement = js2xml.createElement('AzureEdition', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
        js2xml.setElementValue(azureEditionElement, parameters.azureEdition);
        js2xml.addChildElement(importInputElement, azureEditionElement);
      }
      
      if (parameters.blobCredentials !== null && parameters.blobCredentials !== undefined) {
        var blobCredentialsElement = js2xml.createElement('BlobCredentials', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
        js2xml.addChildElement(importInputElement, blobCredentialsElement);
        
        var typeAttribute = js2xml.createAttribute('type', 'http://www.w3.org/2001/XMLSchema-instance');
        js2xml.setAttributeValue(typeAttribute, 'BlobStorageAccessKeyCredentials');
        js2xml.addAttribute(blobCredentialsElement, typeAttribute);
        
        var uriElement = js2xml.createElement('Uri', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
        js2xml.setElementValue(uriElement, parameters.blobCredentials.uri);
        js2xml.addChildElement(blobCredentialsElement, uriElement);
        
        var storageAccessKeyElement = js2xml.createElement('StorageAccessKey', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
        js2xml.setElementValue(storageAccessKeyElement, parameters.blobCredentials.storageAccessKey);
        js2xml.addChildElement(blobCredentialsElement, storageAccessKeyElement);
      }
      
      if (parameters.connectionInfo !== null && parameters.connectionInfo !== undefined) {
        var connectionInfoElement = js2xml.createElement('ConnectionInfo', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
        js2xml.addChildElement(importInputElement, connectionInfoElement);
        
        var databaseNameElement = js2xml.createElement('DatabaseName', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
        js2xml.setElementValue(databaseNameElement, parameters.connectionInfo.databaseName);
        js2xml.addChildElement(connectionInfoElement, databaseNameElement);
        
        var passwordElement = js2xml.createElement('Password', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
        js2xml.setElementValue(passwordElement, parameters.connectionInfo.password);
        js2xml.addChildElement(connectionInfoElement, passwordElement);
        
        var serverNameElement = js2xml.createElement('ServerName', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
        js2xml.setElementValue(serverNameElement, parameters.connectionInfo.serverName);
        js2xml.addChildElement(connectionInfoElement, serverNameElement);
        
        var userNameElement = js2xml.createElement('UserName', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
        js2xml.setElementValue(userNameElement, parameters.connectionInfo.userName);
        js2xml.addChildElement(connectionInfoElement, userNameElement);
      }
      
      if (parameters.databaseSizeInGB !== null && parameters.databaseSizeInGB !== undefined) {
        var databaseSizeInGBElement = js2xml.createElement('DatabaseSizeInGB', 'http://schemas.datacontract.org/2004/07/Microsoft.SqlServer.Management.Dac.ServiceTypes');
        js2xml.setElementValue(databaseSizeInGBElement, parameters.databaseSizeInGB.toString());
        js2xml.addChildElement(importInputElement, databaseSizeInGBElement);
      }
    }
    
    requestContent = js2xml.serializeDocument(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var guidElement = js2xml.getElement(responseDoc, responseDoc, 'GUID', 'HTTP://SCHEMAS.MICROSOFT.COM/2003/10/SERIALIZATION/');
          if (guidElement !== null && guidElement !== undefined) {
            result.guid = guidElement;
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return DacOperations;
})();

var DatabaseCopyOperations = ( /** @lends DatabaseCopyOperations */ function() {
  /**
   * @class
   * Represents the SQL Database Management API includes operations for
   * managing SQL Server database copies for a subscription.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [SqlManagementClient] {@link
   * SqlManagementClient~SqlManagementClient}.
   * See [databaseCopies] {@link
   * SqlManagementClient~SqlManagementClient#databaseCopies}.
   * Initializes a new instance of the DatabaseCopyOperations class.
   * @constructor
   * 
   * @param {SqlManagementClient} client Reference to the service client.
   */
  function DatabaseCopyOperations(client) {
    this.client = client;
  }
  
  /**
   * Starts a SQL Server database copy.
   * 
   * @param {string} serverName The name of the SQL Server where the source
   * database resides.
   * 
   * @param {string} databaseName The name of the source database.
   * 
   * @param {DatabaseCopyCreateParameters} parameters The additional parameters
   * for the create database copy operation.
   * 
   * @param {string} parameters.partnerServer Gets the name of the destination
   * server for the copy.
   * 
   * @param {string} parameters.partnerDatabase Gets the name of the
   * destination database for the copy.
   * 
   * @param {boolean} parameters.isContinuous Gets a value that indicates
   * whether the copy should be continuous.
   * 
   * @param {boolean} [parameters.isOfflineSecondary] Gets a value that
   * indicates whether it is an offline secondary copy.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DatabaseCopyOperations.prototype.create = function(serverName, databaseName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (databaseName === null || databaseName === undefined) {
      return callback(new Error('databaseName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.isContinuous === null || parameters.isContinuous === undefined) {
      return callback(new Error('parameters.isContinuous cannot be null.'));
    }
    if (parameters.partnerDatabase === null || parameters.partnerDatabase === undefined) {
      return callback(new Error('parameters.partnerDatabase cannot be null.'));
    }
    if (parameters.partnerServer === null || parameters.partnerServer === undefined) {
      return callback(new Error('parameters.partnerServer cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/databases/';
    url2 = url2 + encodeURIComponent(databaseName);
    url2 = url2 + '/databasecopies';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var serviceResourceElement = js2xml.createElement('ServiceResource', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, serviceResourceElement);
    
    var partnerServerElement = js2xml.createElement('PartnerServer', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(partnerServerElement, parameters.partnerServer);
    js2xml.addChildElement(serviceResourceElement, partnerServerElement);
    
    var partnerDatabaseElement = js2xml.createElement('PartnerDatabase', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(partnerDatabaseElement, parameters.partnerDatabase);
    js2xml.addChildElement(serviceResourceElement, partnerDatabaseElement);
    
    var isContinuousElement = js2xml.createElement('IsContinuous', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(isContinuousElement, parameters.isContinuous.toString());
    js2xml.addChildElement(serviceResourceElement, isContinuousElement);
    
    if (parameters.isOfflineSecondary !== null && parameters.isOfflineSecondary !== undefined) {
      var isOfflineSecondaryElement = js2xml.createElement('IsOfflineSecondary', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(isOfflineSecondaryElement, parameters.isOfflineSecondary.toString());
      js2xml.addChildElement(serviceResourceElement, isOfflineSecondaryElement);
    }
    
    requestContent = js2xml.serializeDocument(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 201) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 201) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourceElement2 = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourceElement2 !== null && serviceResourceElement2 !== undefined) {
            var serviceResourceInstance = {};
            result.databaseCopy = serviceResourceInstance;
            
            var sourceServerNameElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'SOURCESERVERNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (sourceServerNameElement !== null && sourceServerNameElement !== undefined) {
              var sourceServerNameInstance = sourceServerNameElement;
              serviceResourceInstance.sourceServerName = sourceServerNameInstance;
            }
            
            var sourceDatabaseNameElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'SOURCEDATABASENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (sourceDatabaseNameElement !== null && sourceDatabaseNameElement !== undefined) {
              var sourceDatabaseNameInstance = sourceDatabaseNameElement;
              serviceResourceInstance.sourceDatabaseName = sourceDatabaseNameInstance;
            }
            
            var destinationServerNameElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'DESTINATIONSERVERNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (destinationServerNameElement !== null && destinationServerNameElement !== undefined) {
              var destinationServerNameInstance = destinationServerNameElement;
              serviceResourceInstance.destinationServerName = destinationServerNameInstance;
            }
            
            var destinationDatabaseNameElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'DESTINATIONDATABASENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (destinationDatabaseNameElement !== null && destinationDatabaseNameElement !== undefined) {
              var destinationDatabaseNameInstance = destinationDatabaseNameElement;
              serviceResourceInstance.destinationDatabaseName = destinationDatabaseNameInstance;
            }
            
            var isContinuousElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'ISCONTINUOUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isContinuousElement2 !== null && isContinuousElement2 !== undefined && isContinuousElement2.length !== 0) {
              var isContinuousInstance = isContinuousElement2 === 'true';
              serviceResourceInstance.isContinuous = isContinuousInstance;
            }
            
            var replicationStateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'REPLICATIONSTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (replicationStateElement !== null && replicationStateElement !== undefined && replicationStateElement.length !== 0) {
              var replicationStateInstance = parseInt(replicationStateElement, 10);
              serviceResourceInstance.replicationState = replicationStateInstance;
            }
            
            var replicationStateDescriptionElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'REPLICATIONSTATEDESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (replicationStateDescriptionElement !== null && replicationStateDescriptionElement !== undefined) {
              var replicationStateDescriptionInstance = replicationStateDescriptionElement;
              serviceResourceInstance.replicationStateDescription = replicationStateDescriptionInstance;
            }
            
            var localDatabaseIdElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'LOCALDATABASEID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (localDatabaseIdElement !== null && localDatabaseIdElement !== undefined && localDatabaseIdElement.length !== 0) {
              var localDatabaseIdInstance = parseInt(localDatabaseIdElement, 10);
              serviceResourceInstance.localDatabaseId = localDatabaseIdInstance;
            }
            
            var isLocalDatabaseReplicationTargetElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'ISLOCALDATABASEREPLICATIONTARGET', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isLocalDatabaseReplicationTargetElement !== null && isLocalDatabaseReplicationTargetElement !== undefined && isLocalDatabaseReplicationTargetElement.length !== 0) {
              var isLocalDatabaseReplicationTargetInstance = isLocalDatabaseReplicationTargetElement === 'true';
              serviceResourceInstance.isLocalDatabaseReplicationTarget = isLocalDatabaseReplicationTargetInstance;
            }
            
            var isInterlinkConnectedElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'ISINTERLINKCONNECTED', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isInterlinkConnectedElement !== null && isInterlinkConnectedElement !== undefined && isInterlinkConnectedElement.length !== 0) {
              var isInterlinkConnectedInstance = isInterlinkConnectedElement === 'true';
              serviceResourceInstance.isInterlinkConnected = isInterlinkConnectedInstance;
            }
            
            var startDateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'STARTDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (startDateElement !== null && startDateElement !== undefined) {
              var startDateInstance = startDateElement;
              serviceResourceInstance.startDate = startDateInstance;
            }
            
            var modifyDateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'MODIFYDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (modifyDateElement !== null && modifyDateElement !== undefined) {
              var modifyDateInstance = modifyDateElement;
              serviceResourceInstance.modifyDate = modifyDateInstance;
            }
            
            var percentCompleteElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'PERCENTCOMPLETE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (percentCompleteElement !== null && percentCompleteElement !== undefined && percentCompleteElement.length !== 0) {
              var percentCompleteInstance = parseFloat(percentCompleteElement, 10);
              serviceResourceInstance.percentComplete = percentCompleteInstance;
            }
            
            var isOfflineSecondaryElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'ISOFFLINESECONDARY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isOfflineSecondaryElement2 !== null && isOfflineSecondaryElement2 !== undefined && isOfflineSecondaryElement2.length !== 0) {
              var isOfflineSecondaryInstance = isOfflineSecondaryElement2 === 'true';
              serviceResourceInstance.isOfflineSecondary = isOfflineSecondaryInstance;
            }
            
            var isTerminationAllowedElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'ISTERMINATIONALLOWED', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isTerminationAllowedElement !== null && isTerminationAllowedElement !== undefined && isTerminationAllowedElement.length !== 0) {
              var isTerminationAllowedInstance = isTerminationAllowedElement === 'true';
              serviceResourceInstance.isTerminationAllowed = isTerminationAllowedInstance;
            }
            
            var nameElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              serviceResourceInstance.name = nameInstance;
            }
            
            var typeElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (typeElement !== null && typeElement !== undefined) {
              var typeInstance = typeElement;
              serviceResourceInstance.type = typeInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              serviceResourceInstance.state = stateInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Stops a SQL Server database copy.
   * 
   * @param {string} serverName The name of the source or destination SQL
   * Server instance.
   * 
   * @param {string} databaseName The name of the database.
   * 
   * @param {Guid} databaseCopyName The unique identifier for the database copy
   * to stop.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DatabaseCopyOperations.prototype.deleteMethod = function(serverName, databaseName, databaseCopyName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (databaseName === null || databaseName === undefined) {
      return callback(new Error('databaseName cannot be null.'));
    }
    if (databaseCopyName === null || databaseCopyName === undefined) {
      return callback(new Error('databaseCopyName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/databases/';
    url2 = url2 + encodeURIComponent(databaseName);
    url2 = url2 + '/databasecopies/';
    url2 = url2 + encodeURIComponent(databaseCopyName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Retrieves information about a SQL Server database copy.
   * 
   * @param {string} serverName The name of the source or destination SQL
   * Server instance.
   * 
   * @param {string} databaseName The name of the database.
   * 
   * @param {string} databaseCopyName The unique identifier for the database
   * copy to retrieve.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DatabaseCopyOperations.prototype.get = function(serverName, databaseName, databaseCopyName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (databaseName === null || databaseName === undefined) {
      return callback(new Error('databaseName cannot be null.'));
    }
    if (databaseCopyName === null || databaseCopyName === undefined) {
      return callback(new Error('databaseCopyName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/databases/';
    url2 = url2 + encodeURIComponent(databaseName);
    url2 = url2 + '/databasecopies/';
    url2 = url2 + encodeURIComponent(databaseCopyName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourceElement = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourceElement !== null && serviceResourceElement !== undefined) {
            var serviceResourceInstance = {};
            result.databaseCopy = serviceResourceInstance;
            
            var sourceServerNameElement = js2xml.getElement(responseDoc, serviceResourceElement, 'SOURCESERVERNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (sourceServerNameElement !== null && sourceServerNameElement !== undefined) {
              var sourceServerNameInstance = sourceServerNameElement;
              serviceResourceInstance.sourceServerName = sourceServerNameInstance;
            }
            
            var sourceDatabaseNameElement = js2xml.getElement(responseDoc, serviceResourceElement, 'SOURCEDATABASENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (sourceDatabaseNameElement !== null && sourceDatabaseNameElement !== undefined) {
              var sourceDatabaseNameInstance = sourceDatabaseNameElement;
              serviceResourceInstance.sourceDatabaseName = sourceDatabaseNameInstance;
            }
            
            var destinationServerNameElement = js2xml.getElement(responseDoc, serviceResourceElement, 'DESTINATIONSERVERNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (destinationServerNameElement !== null && destinationServerNameElement !== undefined) {
              var destinationServerNameInstance = destinationServerNameElement;
              serviceResourceInstance.destinationServerName = destinationServerNameInstance;
            }
            
            var destinationDatabaseNameElement = js2xml.getElement(responseDoc, serviceResourceElement, 'DESTINATIONDATABASENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (destinationDatabaseNameElement !== null && destinationDatabaseNameElement !== undefined) {
              var destinationDatabaseNameInstance = destinationDatabaseNameElement;
              serviceResourceInstance.destinationDatabaseName = destinationDatabaseNameInstance;
            }
            
            var isContinuousElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ISCONTINUOUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isContinuousElement !== null && isContinuousElement !== undefined && isContinuousElement.length !== 0) {
              var isContinuousInstance = isContinuousElement === 'true';
              serviceResourceInstance.isContinuous = isContinuousInstance;
            }
            
            var replicationStateElement = js2xml.getElement(responseDoc, serviceResourceElement, 'REPLICATIONSTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (replicationStateElement !== null && replicationStateElement !== undefined && replicationStateElement.length !== 0) {
              var replicationStateInstance = parseInt(replicationStateElement, 10);
              serviceResourceInstance.replicationState = replicationStateInstance;
            }
            
            var replicationStateDescriptionElement = js2xml.getElement(responseDoc, serviceResourceElement, 'REPLICATIONSTATEDESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (replicationStateDescriptionElement !== null && replicationStateDescriptionElement !== undefined) {
              var replicationStateDescriptionInstance = replicationStateDescriptionElement;
              serviceResourceInstance.replicationStateDescription = replicationStateDescriptionInstance;
            }
            
            var localDatabaseIdElement = js2xml.getElement(responseDoc, serviceResourceElement, 'LOCALDATABASEID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (localDatabaseIdElement !== null && localDatabaseIdElement !== undefined && localDatabaseIdElement.length !== 0) {
              var localDatabaseIdInstance = parseInt(localDatabaseIdElement, 10);
              serviceResourceInstance.localDatabaseId = localDatabaseIdInstance;
            }
            
            var isLocalDatabaseReplicationTargetElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ISLOCALDATABASEREPLICATIONTARGET', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isLocalDatabaseReplicationTargetElement !== null && isLocalDatabaseReplicationTargetElement !== undefined && isLocalDatabaseReplicationTargetElement.length !== 0) {
              var isLocalDatabaseReplicationTargetInstance = isLocalDatabaseReplicationTargetElement === 'true';
              serviceResourceInstance.isLocalDatabaseReplicationTarget = isLocalDatabaseReplicationTargetInstance;
            }
            
            var isInterlinkConnectedElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ISINTERLINKCONNECTED', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isInterlinkConnectedElement !== null && isInterlinkConnectedElement !== undefined && isInterlinkConnectedElement.length !== 0) {
              var isInterlinkConnectedInstance = isInterlinkConnectedElement === 'true';
              serviceResourceInstance.isInterlinkConnected = isInterlinkConnectedInstance;
            }
            
            var startDateElement = js2xml.getElement(responseDoc, serviceResourceElement, 'STARTDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (startDateElement !== null && startDateElement !== undefined) {
              var startDateInstance = startDateElement;
              serviceResourceInstance.startDate = startDateInstance;
            }
            
            var modifyDateElement = js2xml.getElement(responseDoc, serviceResourceElement, 'MODIFYDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (modifyDateElement !== null && modifyDateElement !== undefined) {
              var modifyDateInstance = modifyDateElement;
              serviceResourceInstance.modifyDate = modifyDateInstance;
            }
            
            var percentCompleteElement = js2xml.getElement(responseDoc, serviceResourceElement, 'PERCENTCOMPLETE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (percentCompleteElement !== null && percentCompleteElement !== undefined && percentCompleteElement.length !== 0) {
              var percentCompleteInstance = parseFloat(percentCompleteElement, 10);
              serviceResourceInstance.percentComplete = percentCompleteInstance;
            }
            
            var isOfflineSecondaryElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ISOFFLINESECONDARY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isOfflineSecondaryElement !== null && isOfflineSecondaryElement !== undefined && isOfflineSecondaryElement.length !== 0) {
              var isOfflineSecondaryInstance = isOfflineSecondaryElement === 'true';
              serviceResourceInstance.isOfflineSecondary = isOfflineSecondaryInstance;
            }
            
            var isTerminationAllowedElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ISTERMINATIONALLOWED', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isTerminationAllowedElement !== null && isTerminationAllowedElement !== undefined && isTerminationAllowedElement.length !== 0) {
              var isTerminationAllowedInstance = isTerminationAllowedElement === 'true';
              serviceResourceInstance.isTerminationAllowed = isTerminationAllowedInstance;
            }
            
            var nameElement = js2xml.getElement(responseDoc, serviceResourceElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              serviceResourceInstance.name = nameInstance;
            }
            
            var typeElement = js2xml.getElement(responseDoc, serviceResourceElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (typeElement !== null && typeElement !== undefined) {
              var typeInstance = typeElement;
              serviceResourceInstance.type = typeInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, serviceResourceElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              serviceResourceInstance.state = stateInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Retrieves the list of SQL Server database copies for a database.
   * 
   * @param {string} serverName The name of the database server to be queried.
   * 
   * @param {string} databaseName The name of the database to be queried.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DatabaseCopyOperations.prototype.list = function(serverName, databaseName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (databaseName === null || databaseName === undefined) {
      return callback(new Error('databaseName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/databases/';
    url2 = url2 + encodeURIComponent(databaseName);
    url2 = url2 + '/databasecopies';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { databaseCopies: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourcesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourcesSequenceElement !== null && serviceResourcesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var serviceResourcesElement = js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var serviceResourceInstance = {};
              result.databaseCopies.push(serviceResourceInstance);
              
              var sourceServerNameElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'SOURCESERVERNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (sourceServerNameElement !== null && sourceServerNameElement !== undefined) {
                var sourceServerNameInstance = sourceServerNameElement;
                serviceResourceInstance.sourceServerName = sourceServerNameInstance;
              }
              
              var sourceDatabaseNameElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'SOURCEDATABASENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (sourceDatabaseNameElement !== null && sourceDatabaseNameElement !== undefined) {
                var sourceDatabaseNameInstance = sourceDatabaseNameElement;
                serviceResourceInstance.sourceDatabaseName = sourceDatabaseNameInstance;
              }
              
              var destinationServerNameElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'DESTINATIONSERVERNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (destinationServerNameElement !== null && destinationServerNameElement !== undefined) {
                var destinationServerNameInstance = destinationServerNameElement;
                serviceResourceInstance.destinationServerName = destinationServerNameInstance;
              }
              
              var destinationDatabaseNameElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'DESTINATIONDATABASENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (destinationDatabaseNameElement !== null && destinationDatabaseNameElement !== undefined) {
                var destinationDatabaseNameInstance = destinationDatabaseNameElement;
                serviceResourceInstance.destinationDatabaseName = destinationDatabaseNameInstance;
              }
              
              var isContinuousElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ISCONTINUOUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (isContinuousElement !== null && isContinuousElement !== undefined && isContinuousElement.length !== 0) {
                var isContinuousInstance = isContinuousElement === 'true';
                serviceResourceInstance.isContinuous = isContinuousInstance;
              }
              
              var replicationStateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'REPLICATIONSTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (replicationStateElement !== null && replicationStateElement !== undefined && replicationStateElement.length !== 0) {
                var replicationStateInstance = parseInt(replicationStateElement, 10);
                serviceResourceInstance.replicationState = replicationStateInstance;
              }
              
              var replicationStateDescriptionElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'REPLICATIONSTATEDESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (replicationStateDescriptionElement !== null && replicationStateDescriptionElement !== undefined) {
                var replicationStateDescriptionInstance = replicationStateDescriptionElement;
                serviceResourceInstance.replicationStateDescription = replicationStateDescriptionInstance;
              }
              
              var localDatabaseIdElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'LOCALDATABASEID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (localDatabaseIdElement !== null && localDatabaseIdElement !== undefined && localDatabaseIdElement.length !== 0) {
                var localDatabaseIdInstance = parseInt(localDatabaseIdElement, 10);
                serviceResourceInstance.localDatabaseId = localDatabaseIdInstance;
              }
              
              var isLocalDatabaseReplicationTargetElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ISLOCALDATABASEREPLICATIONTARGET', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (isLocalDatabaseReplicationTargetElement !== null && isLocalDatabaseReplicationTargetElement !== undefined && isLocalDatabaseReplicationTargetElement.length !== 0) {
                var isLocalDatabaseReplicationTargetInstance = isLocalDatabaseReplicationTargetElement === 'true';
                serviceResourceInstance.isLocalDatabaseReplicationTarget = isLocalDatabaseReplicationTargetInstance;
              }
              
              var isInterlinkConnectedElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ISINTERLINKCONNECTED', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (isInterlinkConnectedElement !== null && isInterlinkConnectedElement !== undefined && isInterlinkConnectedElement.length !== 0) {
                var isInterlinkConnectedInstance = isInterlinkConnectedElement === 'true';
                serviceResourceInstance.isInterlinkConnected = isInterlinkConnectedInstance;
              }
              
              var startDateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'STARTDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (startDateElement !== null && startDateElement !== undefined) {
                var startDateInstance = startDateElement;
                serviceResourceInstance.startDate = startDateInstance;
              }
              
              var modifyDateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'MODIFYDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (modifyDateElement !== null && modifyDateElement !== undefined) {
                var modifyDateInstance = modifyDateElement;
                serviceResourceInstance.modifyDate = modifyDateInstance;
              }
              
              var percentCompleteElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'PERCENTCOMPLETE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (percentCompleteElement !== null && percentCompleteElement !== undefined && percentCompleteElement.length !== 0) {
                var percentCompleteInstance = parseFloat(percentCompleteElement, 10);
                serviceResourceInstance.percentComplete = percentCompleteInstance;
              }
              
              var isOfflineSecondaryElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ISOFFLINESECONDARY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (isOfflineSecondaryElement !== null && isOfflineSecondaryElement !== undefined && isOfflineSecondaryElement.length !== 0) {
                var isOfflineSecondaryInstance = isOfflineSecondaryElement === 'true';
                serviceResourceInstance.isOfflineSecondary = isOfflineSecondaryInstance;
              }
              
              var isTerminationAllowedElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ISTERMINATIONALLOWED', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (isTerminationAllowedElement !== null && isTerminationAllowedElement !== undefined && isTerminationAllowedElement.length !== 0) {
                var isTerminationAllowedInstance = isTerminationAllowedElement === 'true';
                serviceResourceInstance.isTerminationAllowed = isTerminationAllowedInstance;
              }
              
              var nameElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                serviceResourceInstance.name = nameInstance;
              }
              
              var typeElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (typeElement !== null && typeElement !== undefined) {
                var typeInstance = typeElement;
                serviceResourceInstance.type = typeInstance;
              }
              
              var stateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stateElement !== null && stateElement !== undefined) {
                var stateInstance = stateElement;
                serviceResourceInstance.state = stateInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Updates a SQL Server database copy.
   * 
   * @param {string} serverName The name of the source or destination SQL
   * Server instance.
   * 
   * @param {string} databaseName The name of the database.
   * 
   * @param {Guid} databaseCopyName The unique identifier for the database copy
   * to update.
   * 
   * @param {DatabaseCopyUpdateParameters} parameters The additional parameters
   * for the update database copy operation.
   * 
   * @param {boolean} [parameters.isForcedTerminate] Gets or sets whether a
   * Delete Database Operation will result in forced or friendly termination.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DatabaseCopyOperations.prototype.update = function(serverName, databaseName, databaseCopyName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (databaseName === null || databaseName === undefined) {
      return callback(new Error('databaseName cannot be null.'));
    }
    if (databaseCopyName === null || databaseCopyName === undefined) {
      return callback(new Error('databaseCopyName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/databases/';
    url2 = url2 + encodeURIComponent(databaseName);
    url2 = url2 + '/databasecopies/';
    url2 = url2 + encodeURIComponent(databaseCopyName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var serviceResourceElement = js2xml.createElement('ServiceResource', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, serviceResourceElement);
    
    if (parameters.isForcedTerminate !== null && parameters.isForcedTerminate !== undefined) {
      var isForcedTerminateElement = js2xml.createElement('IsForcedTerminate', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(isForcedTerminateElement, parameters.isForcedTerminate.toString());
      js2xml.addChildElement(serviceResourceElement, isForcedTerminateElement);
    }
    
    requestContent = js2xml.serializeDocument(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourceElement2 = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourceElement2 !== null && serviceResourceElement2 !== undefined) {
            var serviceResourceInstance = {};
            result.databaseCopy = serviceResourceInstance;
            
            var sourceServerNameElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'SOURCESERVERNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (sourceServerNameElement !== null && sourceServerNameElement !== undefined) {
              var sourceServerNameInstance = sourceServerNameElement;
              serviceResourceInstance.sourceServerName = sourceServerNameInstance;
            }
            
            var sourceDatabaseNameElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'SOURCEDATABASENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (sourceDatabaseNameElement !== null && sourceDatabaseNameElement !== undefined) {
              var sourceDatabaseNameInstance = sourceDatabaseNameElement;
              serviceResourceInstance.sourceDatabaseName = sourceDatabaseNameInstance;
            }
            
            var destinationServerNameElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'DESTINATIONSERVERNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (destinationServerNameElement !== null && destinationServerNameElement !== undefined) {
              var destinationServerNameInstance = destinationServerNameElement;
              serviceResourceInstance.destinationServerName = destinationServerNameInstance;
            }
            
            var destinationDatabaseNameElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'DESTINATIONDATABASENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (destinationDatabaseNameElement !== null && destinationDatabaseNameElement !== undefined) {
              var destinationDatabaseNameInstance = destinationDatabaseNameElement;
              serviceResourceInstance.destinationDatabaseName = destinationDatabaseNameInstance;
            }
            
            var isContinuousElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'ISCONTINUOUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isContinuousElement !== null && isContinuousElement !== undefined && isContinuousElement.length !== 0) {
              var isContinuousInstance = isContinuousElement === 'true';
              serviceResourceInstance.isContinuous = isContinuousInstance;
            }
            
            var replicationStateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'REPLICATIONSTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (replicationStateElement !== null && replicationStateElement !== undefined && replicationStateElement.length !== 0) {
              var replicationStateInstance = parseInt(replicationStateElement, 10);
              serviceResourceInstance.replicationState = replicationStateInstance;
            }
            
            var replicationStateDescriptionElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'REPLICATIONSTATEDESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (replicationStateDescriptionElement !== null && replicationStateDescriptionElement !== undefined) {
              var replicationStateDescriptionInstance = replicationStateDescriptionElement;
              serviceResourceInstance.replicationStateDescription = replicationStateDescriptionInstance;
            }
            
            var localDatabaseIdElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'LOCALDATABASEID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (localDatabaseIdElement !== null && localDatabaseIdElement !== undefined && localDatabaseIdElement.length !== 0) {
              var localDatabaseIdInstance = parseInt(localDatabaseIdElement, 10);
              serviceResourceInstance.localDatabaseId = localDatabaseIdInstance;
            }
            
            var isLocalDatabaseReplicationTargetElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'ISLOCALDATABASEREPLICATIONTARGET', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isLocalDatabaseReplicationTargetElement !== null && isLocalDatabaseReplicationTargetElement !== undefined && isLocalDatabaseReplicationTargetElement.length !== 0) {
              var isLocalDatabaseReplicationTargetInstance = isLocalDatabaseReplicationTargetElement === 'true';
              serviceResourceInstance.isLocalDatabaseReplicationTarget = isLocalDatabaseReplicationTargetInstance;
            }
            
            var isInterlinkConnectedElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'ISINTERLINKCONNECTED', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isInterlinkConnectedElement !== null && isInterlinkConnectedElement !== undefined && isInterlinkConnectedElement.length !== 0) {
              var isInterlinkConnectedInstance = isInterlinkConnectedElement === 'true';
              serviceResourceInstance.isInterlinkConnected = isInterlinkConnectedInstance;
            }
            
            var startDateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'STARTDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (startDateElement !== null && startDateElement !== undefined) {
              var startDateInstance = startDateElement;
              serviceResourceInstance.startDate = startDateInstance;
            }
            
            var modifyDateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'MODIFYDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (modifyDateElement !== null && modifyDateElement !== undefined) {
              var modifyDateInstance = modifyDateElement;
              serviceResourceInstance.modifyDate = modifyDateInstance;
            }
            
            var percentCompleteElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'PERCENTCOMPLETE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (percentCompleteElement !== null && percentCompleteElement !== undefined && percentCompleteElement.length !== 0) {
              var percentCompleteInstance = parseFloat(percentCompleteElement, 10);
              serviceResourceInstance.percentComplete = percentCompleteInstance;
            }
            
            var isOfflineSecondaryElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'ISOFFLINESECONDARY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isOfflineSecondaryElement !== null && isOfflineSecondaryElement !== undefined && isOfflineSecondaryElement.length !== 0) {
              var isOfflineSecondaryInstance = isOfflineSecondaryElement === 'true';
              serviceResourceInstance.isOfflineSecondary = isOfflineSecondaryInstance;
            }
            
            var isTerminationAllowedElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'ISTERMINATIONALLOWED', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isTerminationAllowedElement !== null && isTerminationAllowedElement !== undefined && isTerminationAllowedElement.length !== 0) {
              var isTerminationAllowedInstance = isTerminationAllowedElement === 'true';
              serviceResourceInstance.isTerminationAllowed = isTerminationAllowedInstance;
            }
            
            var nameElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              serviceResourceInstance.name = nameInstance;
            }
            
            var typeElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (typeElement !== null && typeElement !== undefined) {
              var typeInstance = typeElement;
              serviceResourceInstance.type = typeInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              serviceResourceInstance.state = stateInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return DatabaseCopyOperations;
})();

var DatabaseOperationOperations = ( /** @lends DatabaseOperationOperations */ function() {
  /**
   * @class
   * The Azure SQL Database Management API includes operations for getting
   * database operations. Specifically, this API allows you to get a specific
   * operation, or to list all the operations that happened on a specific
   * database or on all databases in the Azure SQL Database Server.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [SqlManagementClient] {@link
   * SqlManagementClient~SqlManagementClient}.
   * See [databaseOperations] {@link
   * SqlManagementClient~SqlManagementClient#databaseOperations}.
   * Initializes a new instance of the DatabaseOperationOperations class.
   * @constructor
   * 
   * @param {SqlManagementClient} client Reference to the service client.
   */
  function DatabaseOperationOperations(client) {
    this.client = client;
  }
  
  /**
   * Returns information about a specific operation by using the operation Guid.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server where
   * the database is hosted.
   * 
   * @param {string} operationGuid The Guid of the Azure SQL Database operation
   * to be obtained.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DatabaseOperationOperations.prototype.get = function(serverName, operationGuid, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (operationGuid === null || operationGuid === undefined) {
      return callback(new Error('operationGuid cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/databaseoperations/';
    url2 = url2 + encodeURIComponent(operationGuid);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourceElement = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourceElement !== null && serviceResourceElement !== undefined) {
            var serviceResourceInstance = {};
            result.databaseOperation = serviceResourceInstance;
            
            var idElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              serviceResourceInstance.id = idInstance;
            }
            
            var stateIdElement = js2xml.getElement(responseDoc, serviceResourceElement, 'STATEID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateIdElement !== null && stateIdElement !== undefined && stateIdElement.length !== 0) {
              var stateIdInstance = parseInt(stateIdElement, 10);
              serviceResourceInstance.stateId = stateIdInstance;
            }
            
            var sessionActivityIdElement = js2xml.getElement(responseDoc, serviceResourceElement, 'SESSIONACTIVITYID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (sessionActivityIdElement !== null && sessionActivityIdElement !== undefined) {
              var sessionActivityIdInstance = sessionActivityIdElement;
              serviceResourceInstance.sessionActivityId = sessionActivityIdInstance;
            }
            
            var databaseNameElement = js2xml.getElement(responseDoc, serviceResourceElement, 'DATABASENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (databaseNameElement !== null && databaseNameElement !== undefined) {
              var databaseNameInstance = databaseNameElement;
              serviceResourceInstance.databaseName = databaseNameInstance;
            }
            
            var percentCompleteElement = js2xml.getElement(responseDoc, serviceResourceElement, 'PERCENTCOMPLETE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (percentCompleteElement !== null && percentCompleteElement !== undefined && percentCompleteElement.length !== 0) {
              var percentCompleteInstance = parseInt(percentCompleteElement, 10);
              serviceResourceInstance.percentComplete = percentCompleteInstance;
            }
            
            var errorCodeElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ERRORCODE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (errorCodeElement !== null && errorCodeElement !== undefined && errorCodeElement.length !== 0) {
              var errorCodeInstance = parseInt(errorCodeElement, 10);
              serviceResourceInstance.errorCode = errorCodeInstance;
            }
            
            var errorElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ERROR', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (errorElement !== null && errorElement !== undefined) {
              var errorInstance = errorElement;
              serviceResourceInstance.error = errorInstance;
            }
            
            var errorSeverityElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ERRORSEVERITY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (errorSeverityElement !== null && errorSeverityElement !== undefined && errorSeverityElement.length !== 0) {
              var errorSeverityInstance = parseInt(errorSeverityElement, 10);
              serviceResourceInstance.errorSeverity = errorSeverityInstance;
            }
            
            var errorStateElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ERRORSTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (errorStateElement !== null && errorStateElement !== undefined && errorStateElement.length !== 0) {
              var errorStateInstance = parseInt(errorStateElement, 10);
              serviceResourceInstance.errorState = errorStateInstance;
            }
            
            var startTimeElement = js2xml.getElement(responseDoc, serviceResourceElement, 'STARTTIME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (startTimeElement !== null && startTimeElement !== undefined && startTimeElement.length !== 0) {
              var startTimeInstance = new Date(startTimeElement);
              serviceResourceInstance.startTime = startTimeInstance;
            }
            
            var lastModifyTimeElement = js2xml.getElement(responseDoc, serviceResourceElement, 'LASTMODIFYTIME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (lastModifyTimeElement !== null && lastModifyTimeElement !== undefined && lastModifyTimeElement.length !== 0) {
              var lastModifyTimeInstance = new Date(lastModifyTimeElement);
              serviceResourceInstance.lastModifyTime = lastModifyTimeInstance;
            }
            
            var nameElement = js2xml.getElement(responseDoc, serviceResourceElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              serviceResourceInstance.name = nameInstance;
            }
            
            var typeElement = js2xml.getElement(responseDoc, serviceResourceElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (typeElement !== null && typeElement !== undefined) {
              var typeInstance = typeElement;
              serviceResourceInstance.type = typeInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, serviceResourceElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              serviceResourceInstance.state = stateInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Retrieves all of the operations that took place on a specific database.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server that
   * hosts the database.
   * 
   * @param {string} databaseName The name of the database for which the
   * operations should be retrieved.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DatabaseOperationOperations.prototype.listByDatabase = function(serverName, databaseName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (databaseName === null || databaseName === undefined) {
      return callback(new Error('databaseName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/databaseoperations';
    var queryParameters = [];
    queryParameters.push('databaseName=' + encodeURIComponent(databaseName));
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { databaseOperations: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourcesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourcesSequenceElement !== null && serviceResourcesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var serviceResourcesElement = js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var serviceResourceInstance = {};
              result.databaseOperations.push(serviceResourceInstance);
              
              var idElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (idElement !== null && idElement !== undefined) {
                var idInstance = idElement;
                serviceResourceInstance.id = idInstance;
              }
              
              var stateIdElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'STATEID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stateIdElement !== null && stateIdElement !== undefined && stateIdElement.length !== 0) {
                var stateIdInstance = parseInt(stateIdElement, 10);
                serviceResourceInstance.stateId = stateIdInstance;
              }
              
              var sessionActivityIdElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'SESSIONACTIVITYID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (sessionActivityIdElement !== null && sessionActivityIdElement !== undefined) {
                var sessionActivityIdInstance = sessionActivityIdElement;
                serviceResourceInstance.sessionActivityId = sessionActivityIdInstance;
              }
              
              var databaseNameElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'DATABASENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (databaseNameElement !== null && databaseNameElement !== undefined) {
                var databaseNameInstance = databaseNameElement;
                serviceResourceInstance.databaseName = databaseNameInstance;
              }
              
              var percentCompleteElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'PERCENTCOMPLETE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (percentCompleteElement !== null && percentCompleteElement !== undefined && percentCompleteElement.length !== 0) {
                var percentCompleteInstance = parseInt(percentCompleteElement, 10);
                serviceResourceInstance.percentComplete = percentCompleteInstance;
              }
              
              var errorCodeElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ERRORCODE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (errorCodeElement !== null && errorCodeElement !== undefined && errorCodeElement.length !== 0) {
                var errorCodeInstance = parseInt(errorCodeElement, 10);
                serviceResourceInstance.errorCode = errorCodeInstance;
              }
              
              var errorElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ERROR', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (errorElement !== null && errorElement !== undefined) {
                var errorInstance = errorElement;
                serviceResourceInstance.error = errorInstance;
              }
              
              var errorSeverityElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ERRORSEVERITY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (errorSeverityElement !== null && errorSeverityElement !== undefined && errorSeverityElement.length !== 0) {
                var errorSeverityInstance = parseInt(errorSeverityElement, 10);
                serviceResourceInstance.errorSeverity = errorSeverityInstance;
              }
              
              var errorStateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ERRORSTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (errorStateElement !== null && errorStateElement !== undefined && errorStateElement.length !== 0) {
                var errorStateInstance = parseInt(errorStateElement, 10);
                serviceResourceInstance.errorState = errorStateInstance;
              }
              
              var startTimeElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'STARTTIME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (startTimeElement !== null && startTimeElement !== undefined && startTimeElement.length !== 0) {
                var startTimeInstance = new Date(startTimeElement);
                serviceResourceInstance.startTime = startTimeInstance;
              }
              
              var lastModifyTimeElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'LASTMODIFYTIME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (lastModifyTimeElement !== null && lastModifyTimeElement !== undefined && lastModifyTimeElement.length !== 0) {
                var lastModifyTimeInstance = new Date(lastModifyTimeElement);
                serviceResourceInstance.lastModifyTime = lastModifyTimeInstance;
              }
              
              var nameElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                serviceResourceInstance.name = nameInstance;
              }
              
              var typeElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (typeElement !== null && typeElement !== undefined) {
                var typeInstance = typeElement;
                serviceResourceInstance.type = typeInstance;
              }
              
              var stateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stateElement !== null && stateElement !== undefined) {
                var stateInstance = stateElement;
                serviceResourceInstance.state = stateInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Retrieves all of the operations that occured on the Azure SQL Database
   * Server.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server to be
   * queried.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DatabaseOperationOperations.prototype.listByServer = function(serverName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/databaseoperations';
    var queryParameters = [];
    queryParameters.push('contentview=generic');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { databaseOperations: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourcesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourcesSequenceElement !== null && serviceResourcesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var serviceResourcesElement = js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var serviceResourceInstance = {};
              result.databaseOperations.push(serviceResourceInstance);
              
              var idElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (idElement !== null && idElement !== undefined) {
                var idInstance = idElement;
                serviceResourceInstance.id = idInstance;
              }
              
              var stateIdElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'STATEID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stateIdElement !== null && stateIdElement !== undefined && stateIdElement.length !== 0) {
                var stateIdInstance = parseInt(stateIdElement, 10);
                serviceResourceInstance.stateId = stateIdInstance;
              }
              
              var sessionActivityIdElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'SESSIONACTIVITYID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (sessionActivityIdElement !== null && sessionActivityIdElement !== undefined) {
                var sessionActivityIdInstance = sessionActivityIdElement;
                serviceResourceInstance.sessionActivityId = sessionActivityIdInstance;
              }
              
              var databaseNameElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'DATABASENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (databaseNameElement !== null && databaseNameElement !== undefined) {
                var databaseNameInstance = databaseNameElement;
                serviceResourceInstance.databaseName = databaseNameInstance;
              }
              
              var percentCompleteElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'PERCENTCOMPLETE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (percentCompleteElement !== null && percentCompleteElement !== undefined && percentCompleteElement.length !== 0) {
                var percentCompleteInstance = parseInt(percentCompleteElement, 10);
                serviceResourceInstance.percentComplete = percentCompleteInstance;
              }
              
              var errorCodeElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ERRORCODE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (errorCodeElement !== null && errorCodeElement !== undefined && errorCodeElement.length !== 0) {
                var errorCodeInstance = parseInt(errorCodeElement, 10);
                serviceResourceInstance.errorCode = errorCodeInstance;
              }
              
              var errorElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ERROR', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (errorElement !== null && errorElement !== undefined) {
                var errorInstance = errorElement;
                serviceResourceInstance.error = errorInstance;
              }
              
              var errorSeverityElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ERRORSEVERITY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (errorSeverityElement !== null && errorSeverityElement !== undefined && errorSeverityElement.length !== 0) {
                var errorSeverityInstance = parseInt(errorSeverityElement, 10);
                serviceResourceInstance.errorSeverity = errorSeverityInstance;
              }
              
              var errorStateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ERRORSTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (errorStateElement !== null && errorStateElement !== undefined && errorStateElement.length !== 0) {
                var errorStateInstance = parseInt(errorStateElement, 10);
                serviceResourceInstance.errorState = errorStateInstance;
              }
              
              var startTimeElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'STARTTIME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (startTimeElement !== null && startTimeElement !== undefined && startTimeElement.length !== 0) {
                var startTimeInstance = new Date(startTimeElement);
                serviceResourceInstance.startTime = startTimeInstance;
              }
              
              var lastModifyTimeElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'LASTMODIFYTIME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (lastModifyTimeElement !== null && lastModifyTimeElement !== undefined && lastModifyTimeElement.length !== 0) {
                var lastModifyTimeInstance = new Date(lastModifyTimeElement);
                serviceResourceInstance.lastModifyTime = lastModifyTimeInstance;
              }
              
              var nameElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                serviceResourceInstance.name = nameInstance;
              }
              
              var typeElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (typeElement !== null && typeElement !== undefined) {
                var typeInstance = typeElement;
                serviceResourceInstance.type = typeInstance;
              }
              
              var stateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stateElement !== null && stateElement !== undefined) {
                var stateInstance = stateElement;
                serviceResourceInstance.state = stateInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return DatabaseOperationOperations;
})();

var DatabaseOperations = ( /** @lends DatabaseOperations */ function() {
  /**
   * @class
   * Represents all the operations for operating on Azure SQL Databases.
   * Contains operations to: Create, Retrieve, Update, and Delete databases,
   * and also includes the ability to get the event logs for a database.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [SqlManagementClient] {@link
   * SqlManagementClient~SqlManagementClient}.
   * See [databases] {@link SqlManagementClient~SqlManagementClient#databases}.
   * Initializes a new instance of the DatabaseOperations class.
   * @constructor
   * 
   * @param {SqlManagementClient} client Reference to the service client.
   */
  function DatabaseOperations(client) {
    this.client = client;
  }
  
  /**
   * Creates a database in an Azure SQL Database Server.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server where
   * the database will be created.
   * 
   * @param {DatabaseCreateParameters} parameters The parameters for the create
   * database operation.
   * 
   * @param {string} parameters.name Gets or sets the name for the new database.
   * 
   * @param {string} [parameters.edition] Gets or sets the edition for the new
   * database.  The DatabaseEditions enumeration contains the valid values for
   * this property.
   * 
   * @param {number} [parameters.maximumDatabaseSizeInGB] Gets or sets the
   * maximum size of this database expressed in gigabytes.  If this is used in
   * conjunction with MaximumDatabaseSizeInBytes they must agree.
   * 
   * @param {string} [parameters.collationName] Gets or sets the collation name
   * for the new database.
   * 
   * @param {number} [parameters.maximumDatabaseSizeInBytes] Gets or sets the
   * maximum size of this database expressed in bytes.  If this is used in
   * conjunction with MaximumDatabaseSizeInGB they must agree.
   * 
   * @param {string} [parameters.serviceObjectiveId] Gets or sets the service
   * objective ID to be applied to the database.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DatabaseOperations.prototype.create = function(serverName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.name === null || parameters.name === undefined) {
      return callback(new Error('parameters.name cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/databases';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var serviceResourceElement = js2xml.createElement('ServiceResource', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, serviceResourceElement);
    
    var nameElement = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(nameElement, parameters.name);
    js2xml.addChildElement(serviceResourceElement, nameElement);
    
    if (parameters.edition !== null && parameters.edition !== undefined) {
      var editionElement = js2xml.createElement('Edition', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(editionElement, parameters.edition);
      js2xml.addChildElement(serviceResourceElement, editionElement);
    }
    
    if (parameters.maximumDatabaseSizeInGB !== null && parameters.maximumDatabaseSizeInGB !== undefined) {
      var maxSizeGBElement = js2xml.createElement('MaxSizeGB', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(maxSizeGBElement, parameters.maximumDatabaseSizeInGB.toString());
      js2xml.addChildElement(serviceResourceElement, maxSizeGBElement);
    }
    
    if (parameters.collationName !== null && parameters.collationName !== undefined) {
      var collationNameElement = js2xml.createElement('CollationName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(collationNameElement, parameters.collationName);
      js2xml.addChildElement(serviceResourceElement, collationNameElement);
    }
    
    if (parameters.maximumDatabaseSizeInBytes !== null && parameters.maximumDatabaseSizeInBytes !== undefined) {
      var maxSizeBytesElement = js2xml.createElement('MaxSizeBytes', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(maxSizeBytesElement, parameters.maximumDatabaseSizeInBytes.toString());
      js2xml.addChildElement(serviceResourceElement, maxSizeBytesElement);
    }
    
    if (parameters.serviceObjectiveId !== null && parameters.serviceObjectiveId !== undefined) {
      var serviceObjectiveIdElement = js2xml.createElement('ServiceObjectiveId', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(serviceObjectiveIdElement, parameters.serviceObjectiveId);
      js2xml.addChildElement(serviceResourceElement, serviceObjectiveIdElement);
    }
    
    requestContent = js2xml.serializeDocument(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 201) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 201) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourceElement2 = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourceElement2 !== null && serviceResourceElement2 !== undefined) {
            var serviceResourceInstance = {};
            result.database = serviceResourceInstance;
            
            var idElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined && idElement.length !== 0) {
              var idInstance = parseInt(idElement, 10);
              serviceResourceInstance.id = idInstance;
            }
            
            var editionElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'EDITION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (editionElement2 !== null && editionElement2 !== undefined) {
              var editionInstance = editionElement2;
              serviceResourceInstance.edition = editionInstance;
            }
            
            var maxSizeGBElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'MAXSIZEGB', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (maxSizeGBElement2 !== null && maxSizeGBElement2 !== undefined && maxSizeGBElement2.length !== 0) {
              var maxSizeGBInstance = parseInt(maxSizeGBElement2, 10);
              serviceResourceInstance.maximumDatabaseSizeInGB = maxSizeGBInstance;
            }
            
            var maxSizeBytesElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'MAXSIZEBYTES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (maxSizeBytesElement2 !== null && maxSizeBytesElement2 !== undefined && maxSizeBytesElement2.length !== 0) {
              var maxSizeBytesInstance = parseInt(maxSizeBytesElement2, 10);
              serviceResourceInstance.maximumDatabaseSizeInBytes = maxSizeBytesInstance;
            }
            
            var collationNameElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'COLLATIONNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (collationNameElement2 !== null && collationNameElement2 !== undefined) {
              var collationNameInstance = collationNameElement2;
              serviceResourceInstance.collationName = collationNameInstance;
            }
            
            var creationDateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'CREATIONDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (creationDateElement !== null && creationDateElement !== undefined && creationDateElement.length !== 0) {
              var creationDateInstance = new Date(creationDateElement);
              serviceResourceInstance.creationDate = creationDateInstance;
            }
            
            var isFederationRootElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'ISFEDERATIONROOT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isFederationRootElement !== null && isFederationRootElement !== undefined && isFederationRootElement.length !== 0) {
              var isFederationRootInstance = isFederationRootElement === 'true';
              serviceResourceInstance.isFederationRoot = isFederationRootInstance;
            }
            
            var isSystemObjectElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'ISSYSTEMOBJECT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isSystemObjectElement !== null && isSystemObjectElement !== undefined && isSystemObjectElement.length !== 0) {
              var isSystemObjectInstance = isSystemObjectElement === 'true';
              serviceResourceInstance.isSystemObject = isSystemObjectInstance;
            }
            
            var sizeMBElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'SIZEMB', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (sizeMBElement !== null && sizeMBElement !== undefined) {
              var sizeMBInstance = sizeMBElement;
              serviceResourceInstance.sizeMB = sizeMBInstance;
            }
            
            var serviceObjectiveAssignmentErrorCodeElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'SERVICEOBJECTIVEASSIGNMENTERRORCODE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceObjectiveAssignmentErrorCodeElement !== null && serviceObjectiveAssignmentErrorCodeElement !== undefined) {
              var serviceObjectiveAssignmentErrorCodeInstance = serviceObjectiveAssignmentErrorCodeElement;
              serviceResourceInstance.serviceObjectiveAssignmentErrorCode = serviceObjectiveAssignmentErrorCodeInstance;
            }
            
            var serviceObjectiveAssignmentErrorDescriptionElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'SERVICEOBJECTIVEASSIGNMENTERRORDESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceObjectiveAssignmentErrorDescriptionElement !== null && serviceObjectiveAssignmentErrorDescriptionElement !== undefined) {
              var serviceObjectiveAssignmentErrorDescriptionInstance = serviceObjectiveAssignmentErrorDescriptionElement;
              serviceResourceInstance.serviceObjectiveAssignmentErrorDescription = serviceObjectiveAssignmentErrorDescriptionInstance;
            }
            
            var serviceObjectiveAssignmentStateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'SERVICEOBJECTIVEASSIGNMENTSTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceObjectiveAssignmentStateElement !== null && serviceObjectiveAssignmentStateElement !== undefined) {
              var serviceObjectiveAssignmentStateInstance = serviceObjectiveAssignmentStateElement;
              serviceResourceInstance.serviceObjectiveAssignmentState = serviceObjectiveAssignmentStateInstance;
            }
            
            var serviceObjectiveAssignmentStateDescriptionElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'SERVICEOBJECTIVEASSIGNMENTSTATEDESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceObjectiveAssignmentStateDescriptionElement !== null && serviceObjectiveAssignmentStateDescriptionElement !== undefined) {
              var serviceObjectiveAssignmentStateDescriptionInstance = serviceObjectiveAssignmentStateDescriptionElement;
              serviceResourceInstance.serviceObjectiveAssignmentStateDescription = serviceObjectiveAssignmentStateDescriptionInstance;
            }
            
            var serviceObjectiveAssignmentSuccessDateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'SERVICEOBJECTIVEASSIGNMENTSUCCESSDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceObjectiveAssignmentSuccessDateElement !== null && serviceObjectiveAssignmentSuccessDateElement !== undefined) {
              var serviceObjectiveAssignmentSuccessDateInstance = serviceObjectiveAssignmentSuccessDateElement;
              serviceResourceInstance.serviceObjectiveAssignmentSuccessDate = serviceObjectiveAssignmentSuccessDateInstance;
            }
            
            var serviceObjectiveIdElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'SERVICEOBJECTIVEID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceObjectiveIdElement2 !== null && serviceObjectiveIdElement2 !== undefined) {
              var serviceObjectiveIdInstance = serviceObjectiveIdElement2;
              serviceResourceInstance.serviceObjectiveId = serviceObjectiveIdInstance;
            }
            
            var assignedServiceObjectiveIdElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'ASSIGNEDSERVICEOBJECTIVEID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (assignedServiceObjectiveIdElement !== null && assignedServiceObjectiveIdElement !== undefined) {
              var assignedServiceObjectiveIdInstance = assignedServiceObjectiveIdElement;
              serviceResourceInstance.assignedServiceObjectiveId = assignedServiceObjectiveIdInstance;
            }
            
            var recoveryPeriodStartDateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'RECOVERYPERIODSTARTDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (recoveryPeriodStartDateElement !== null && recoveryPeriodStartDateElement !== undefined && recoveryPeriodStartDateElement.length !== 0) {
              var recoveryPeriodStartDateInstance = new Date(recoveryPeriodStartDateElement);
              serviceResourceInstance.recoveryPeriodStartDate = recoveryPeriodStartDateInstance;
            }
            
            var nameElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement2 !== null && nameElement2 !== undefined) {
              var nameInstance = nameElement2;
              serviceResourceInstance.name = nameInstance;
            }
            
            var typeElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (typeElement !== null && typeElement !== undefined) {
              var typeInstance = typeElement;
              serviceResourceInstance.type = typeInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              serviceResourceInstance.state = stateInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Drops a database from an Azure SQL Database Server.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server on
   * which the database is hosted.
   * 
   * @param {string} databaseName The name of the Azure SQL Database to be
   * deleted.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DatabaseOperations.prototype.deleteMethod = function(serverName, databaseName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (databaseName === null || databaseName === undefined) {
      return callback(new Error('databaseName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/databases/';
    url2 = url2 + encodeURIComponent(databaseName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Returns information about an Azure SQL Database.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server on
   * which the database is hosted.
   * 
   * @param {string} databaseName The name of the Azure SQL Database to be
   * retrieved.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DatabaseOperations.prototype.get = function(serverName, databaseName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (databaseName === null || databaseName === undefined) {
      return callback(new Error('databaseName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/databases/';
    url2 = url2 + encodeURIComponent(databaseName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourceElement = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourceElement !== null && serviceResourceElement !== undefined) {
            var serviceResourceInstance = {};
            result.database = serviceResourceInstance;
            
            var idElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined && idElement.length !== 0) {
              var idInstance = parseInt(idElement, 10);
              serviceResourceInstance.id = idInstance;
            }
            
            var editionElement = js2xml.getElement(responseDoc, serviceResourceElement, 'EDITION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (editionElement !== null && editionElement !== undefined) {
              var editionInstance = editionElement;
              serviceResourceInstance.edition = editionInstance;
            }
            
            var maxSizeGBElement = js2xml.getElement(responseDoc, serviceResourceElement, 'MAXSIZEGB', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (maxSizeGBElement !== null && maxSizeGBElement !== undefined && maxSizeGBElement.length !== 0) {
              var maxSizeGBInstance = parseInt(maxSizeGBElement, 10);
              serviceResourceInstance.maximumDatabaseSizeInGB = maxSizeGBInstance;
            }
            
            var maxSizeBytesElement = js2xml.getElement(responseDoc, serviceResourceElement, 'MAXSIZEBYTES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (maxSizeBytesElement !== null && maxSizeBytesElement !== undefined && maxSizeBytesElement.length !== 0) {
              var maxSizeBytesInstance = parseInt(maxSizeBytesElement, 10);
              serviceResourceInstance.maximumDatabaseSizeInBytes = maxSizeBytesInstance;
            }
            
            var collationNameElement = js2xml.getElement(responseDoc, serviceResourceElement, 'COLLATIONNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (collationNameElement !== null && collationNameElement !== undefined) {
              var collationNameInstance = collationNameElement;
              serviceResourceInstance.collationName = collationNameInstance;
            }
            
            var creationDateElement = js2xml.getElement(responseDoc, serviceResourceElement, 'CREATIONDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (creationDateElement !== null && creationDateElement !== undefined && creationDateElement.length !== 0) {
              var creationDateInstance = new Date(creationDateElement);
              serviceResourceInstance.creationDate = creationDateInstance;
            }
            
            var isFederationRootElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ISFEDERATIONROOT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isFederationRootElement !== null && isFederationRootElement !== undefined && isFederationRootElement.length !== 0) {
              var isFederationRootInstance = isFederationRootElement === 'true';
              serviceResourceInstance.isFederationRoot = isFederationRootInstance;
            }
            
            var isSystemObjectElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ISSYSTEMOBJECT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isSystemObjectElement !== null && isSystemObjectElement !== undefined && isSystemObjectElement.length !== 0) {
              var isSystemObjectInstance = isSystemObjectElement === 'true';
              serviceResourceInstance.isSystemObject = isSystemObjectInstance;
            }
            
            var sizeMBElement = js2xml.getElement(responseDoc, serviceResourceElement, 'SIZEMB', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (sizeMBElement !== null && sizeMBElement !== undefined) {
              var sizeMBInstance = sizeMBElement;
              serviceResourceInstance.sizeMB = sizeMBInstance;
            }
            
            var serviceObjectiveAssignmentErrorCodeElement = js2xml.getElement(responseDoc, serviceResourceElement, 'SERVICEOBJECTIVEASSIGNMENTERRORCODE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceObjectiveAssignmentErrorCodeElement !== null && serviceObjectiveAssignmentErrorCodeElement !== undefined) {
              var serviceObjectiveAssignmentErrorCodeInstance = serviceObjectiveAssignmentErrorCodeElement;
              serviceResourceInstance.serviceObjectiveAssignmentErrorCode = serviceObjectiveAssignmentErrorCodeInstance;
            }
            
            var serviceObjectiveAssignmentErrorDescriptionElement = js2xml.getElement(responseDoc, serviceResourceElement, 'SERVICEOBJECTIVEASSIGNMENTERRORDESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceObjectiveAssignmentErrorDescriptionElement !== null && serviceObjectiveAssignmentErrorDescriptionElement !== undefined) {
              var serviceObjectiveAssignmentErrorDescriptionInstance = serviceObjectiveAssignmentErrorDescriptionElement;
              serviceResourceInstance.serviceObjectiveAssignmentErrorDescription = serviceObjectiveAssignmentErrorDescriptionInstance;
            }
            
            var serviceObjectiveAssignmentStateElement = js2xml.getElement(responseDoc, serviceResourceElement, 'SERVICEOBJECTIVEASSIGNMENTSTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceObjectiveAssignmentStateElement !== null && serviceObjectiveAssignmentStateElement !== undefined) {
              var serviceObjectiveAssignmentStateInstance = serviceObjectiveAssignmentStateElement;
              serviceResourceInstance.serviceObjectiveAssignmentState = serviceObjectiveAssignmentStateInstance;
            }
            
            var serviceObjectiveAssignmentStateDescriptionElement = js2xml.getElement(responseDoc, serviceResourceElement, 'SERVICEOBJECTIVEASSIGNMENTSTATEDESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceObjectiveAssignmentStateDescriptionElement !== null && serviceObjectiveAssignmentStateDescriptionElement !== undefined) {
              var serviceObjectiveAssignmentStateDescriptionInstance = serviceObjectiveAssignmentStateDescriptionElement;
              serviceResourceInstance.serviceObjectiveAssignmentStateDescription = serviceObjectiveAssignmentStateDescriptionInstance;
            }
            
            var serviceObjectiveAssignmentSuccessDateElement = js2xml.getElement(responseDoc, serviceResourceElement, 'SERVICEOBJECTIVEASSIGNMENTSUCCESSDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceObjectiveAssignmentSuccessDateElement !== null && serviceObjectiveAssignmentSuccessDateElement !== undefined) {
              var serviceObjectiveAssignmentSuccessDateInstance = serviceObjectiveAssignmentSuccessDateElement;
              serviceResourceInstance.serviceObjectiveAssignmentSuccessDate = serviceObjectiveAssignmentSuccessDateInstance;
            }
            
            var serviceObjectiveIdElement = js2xml.getElement(responseDoc, serviceResourceElement, 'SERVICEOBJECTIVEID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceObjectiveIdElement !== null && serviceObjectiveIdElement !== undefined) {
              var serviceObjectiveIdInstance = serviceObjectiveIdElement;
              serviceResourceInstance.serviceObjectiveId = serviceObjectiveIdInstance;
            }
            
            var assignedServiceObjectiveIdElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ASSIGNEDSERVICEOBJECTIVEID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (assignedServiceObjectiveIdElement !== null && assignedServiceObjectiveIdElement !== undefined) {
              var assignedServiceObjectiveIdInstance = assignedServiceObjectiveIdElement;
              serviceResourceInstance.assignedServiceObjectiveId = assignedServiceObjectiveIdInstance;
            }
            
            var recoveryPeriodStartDateElement = js2xml.getElement(responseDoc, serviceResourceElement, 'RECOVERYPERIODSTARTDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (recoveryPeriodStartDateElement !== null && recoveryPeriodStartDateElement !== undefined && recoveryPeriodStartDateElement.length !== 0) {
              var recoveryPeriodStartDateInstance = new Date(recoveryPeriodStartDateElement);
              serviceResourceInstance.recoveryPeriodStartDate = recoveryPeriodStartDateInstance;
            }
            
            var nameElement = js2xml.getElement(responseDoc, serviceResourceElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              serviceResourceInstance.name = nameInstance;
            }
            
            var typeElement = js2xml.getElement(responseDoc, serviceResourceElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (typeElement !== null && typeElement !== undefined) {
              var typeInstance = typeElement;
              serviceResourceInstance.type = typeInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, serviceResourceElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              serviceResourceInstance.state = stateInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Returns information about an Azure SQL Database event logs.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server on
   * which the database is hosted.
   * 
   * @param {string} databaseName The name of the Azure SQL Database to be
   * retrieved.
   * 
   * @param {DatabaseGetEventLogsParameters} parameters The parameters for the
   * Get Database Event Logs operation.
   * 
   * @param {date} parameters.startDate Gets or sets the start date for the
   * event log.
   * 
   * @param {number} parameters.intervalSizeInMinutes Gets or sets the interval
   * size in minutes.
   * 
   * @param {string} parameters.eventTypes Gets or sets the event types to
   * retrieve.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DatabaseOperations.prototype.getEventLogs = function(serverName, databaseName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (databaseName === null || databaseName === undefined) {
      return callback(new Error('databaseName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.eventTypes === null || parameters.eventTypes === undefined) {
      return callback(new Error('parameters.eventTypes cannot be null.'));
    }
    if (parameters.intervalSizeInMinutes === null || parameters.intervalSizeInMinutes === undefined) {
      return callback(new Error('parameters.intervalSizeInMinutes cannot be null.'));
    }
    if (parameters.startDate === null || parameters.startDate === undefined) {
      return callback(new Error('parameters.startDate cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/databases/';
    url2 = url2 + encodeURIComponent(databaseName);
    url2 = url2 + '/events';
    var queryParameters = [];
    queryParameters.push('startDate=' + encodeURIComponent(parameters.startDate.toISOString()));
    queryParameters.push('intervalSizeInMinutes=' + encodeURIComponent(parameters.intervalSizeInMinutes.toString()));
    queryParameters.push('eventTypes=' + encodeURIComponent(parameters.eventTypes));
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { eventLogs: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourcesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourcesSequenceElement !== null && serviceResourcesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var serviceResourcesElement = js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var serviceResourceInstance = {};
              result.eventLogs.push(serviceResourceInstance);
              
              var databaseNameElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'DATABASENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (databaseNameElement !== null && databaseNameElement !== undefined) {
                var databaseNameInstance = databaseNameElement;
                serviceResourceInstance.databaseName = databaseNameInstance;
              }
              
              var startTimeUtcElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'STARTTIMEUTC', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (startTimeUtcElement !== null && startTimeUtcElement !== undefined && startTimeUtcElement.length !== 0) {
                var startTimeUtcInstance = new Date(startTimeUtcElement);
                serviceResourceInstance.startTimeUtc = startTimeUtcInstance;
              }
              
              var intervalSizeInMinutesElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'INTERVALSIZEINMINUTES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (intervalSizeInMinutesElement !== null && intervalSizeInMinutesElement !== undefined && intervalSizeInMinutesElement.length !== 0) {
                var intervalSizeInMinutesInstance = parseInt(intervalSizeInMinutesElement, 10);
                serviceResourceInstance.intervalSizeInMinutes = intervalSizeInMinutesInstance;
              }
              
              var eventCategoryElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'EVENTCATEGORY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (eventCategoryElement !== null && eventCategoryElement !== undefined) {
                var eventCategoryInstance = eventCategoryElement;
                serviceResourceInstance.eventCategory = eventCategoryInstance;
              }
              
              var eventTypeElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'EVENTTYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (eventTypeElement !== null && eventTypeElement !== undefined) {
                var eventTypeInstance = eventTypeElement;
                serviceResourceInstance.eventType = eventTypeInstance;
              }
              
              var eventSubtypeElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'EVENTSUBTYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (eventSubtypeElement !== null && eventSubtypeElement !== undefined) {
                var eventSubtypeInstance = eventSubtypeElement;
                serviceResourceInstance.eventSubtype = eventSubtypeInstance;
              }
              
              var eventSubtypeDescriptionElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'EVENTSUBTYPEDESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (eventSubtypeDescriptionElement !== null && eventSubtypeDescriptionElement !== undefined) {
                var eventSubtypeDescriptionInstance = eventSubtypeDescriptionElement;
                serviceResourceInstance.eventSubtypeDescription = eventSubtypeDescriptionInstance;
              }
              
              var numberOfEventsElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'NUMBEROFEVENTS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (numberOfEventsElement !== null && numberOfEventsElement !== undefined && numberOfEventsElement.length !== 0) {
                var numberOfEventsInstance = parseInt(numberOfEventsElement, 10);
                serviceResourceInstance.numberOfEvents = numberOfEventsInstance;
              }
              
              var severityElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'SEVERITY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (severityElement !== null && severityElement !== undefined && severityElement.length !== 0) {
                var severityInstance = parseInt(severityElement, 10);
                serviceResourceInstance.severity = severityInstance;
              }
              
              var descriptionElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'DESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (descriptionElement !== null && descriptionElement !== undefined) {
                var descriptionInstance = descriptionElement;
                serviceResourceInstance.description = descriptionInstance;
              }
              
              var additionalDataElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ADDITIONALDATA', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (additionalDataElement !== null && additionalDataElement !== undefined) {
                var isNil = false;
                var nilAttribute = js2xml.getAttribute(responseDoc, additionalDataElement, 'NIL', 'HTTP://WWW.W3.ORG/2001/XMLSCHEMA-INSTANCE');
                if (nilAttribute !== null && nilAttribute !== undefined) {
                  isNil = nilAttribute === 'true';
                }
                if (isNil === false) {
                  var additionalDataInstance = additionalDataElement;
                  serviceResourceInstance.additionalData = additionalDataInstance;
                }
              }
              
              var nameElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                serviceResourceInstance.name = nameInstance;
              }
              
              var typeElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (typeElement !== null && typeElement !== undefined) {
                var typeInstance = typeElement;
                serviceResourceInstance.type = typeInstance;
              }
              
              var stateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stateElement !== null && stateElement !== undefined) {
                var stateInstance = stateElement;
                serviceResourceInstance.state = stateInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Returns a collection of Azure SQL Databases.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server from
   * which to retrieve the database.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DatabaseOperations.prototype.list = function(serverName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/databases';
    var queryParameters = [];
    queryParameters.push('contentview=generic');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { databases: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourcesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourcesSequenceElement !== null && serviceResourcesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var serviceResourcesElement = js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var serviceResourceInstance = {};
              result.databases.push(serviceResourceInstance);
              
              var idElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (idElement !== null && idElement !== undefined && idElement.length !== 0) {
                var idInstance = parseInt(idElement, 10);
                serviceResourceInstance.id = idInstance;
              }
              
              var editionElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'EDITION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (editionElement !== null && editionElement !== undefined) {
                var editionInstance = editionElement;
                serviceResourceInstance.edition = editionInstance;
              }
              
              var maxSizeGBElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'MAXSIZEGB', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (maxSizeGBElement !== null && maxSizeGBElement !== undefined && maxSizeGBElement.length !== 0) {
                var maxSizeGBInstance = parseInt(maxSizeGBElement, 10);
                serviceResourceInstance.maximumDatabaseSizeInGB = maxSizeGBInstance;
              }
              
              var maxSizeBytesElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'MAXSIZEBYTES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (maxSizeBytesElement !== null && maxSizeBytesElement !== undefined && maxSizeBytesElement.length !== 0) {
                var maxSizeBytesInstance = parseInt(maxSizeBytesElement, 10);
                serviceResourceInstance.maximumDatabaseSizeInBytes = maxSizeBytesInstance;
              }
              
              var collationNameElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'COLLATIONNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (collationNameElement !== null && collationNameElement !== undefined) {
                var collationNameInstance = collationNameElement;
                serviceResourceInstance.collationName = collationNameInstance;
              }
              
              var creationDateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'CREATIONDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (creationDateElement !== null && creationDateElement !== undefined && creationDateElement.length !== 0) {
                var creationDateInstance = new Date(creationDateElement);
                serviceResourceInstance.creationDate = creationDateInstance;
              }
              
              var isFederationRootElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ISFEDERATIONROOT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (isFederationRootElement !== null && isFederationRootElement !== undefined && isFederationRootElement.length !== 0) {
                var isFederationRootInstance = isFederationRootElement === 'true';
                serviceResourceInstance.isFederationRoot = isFederationRootInstance;
              }
              
              var isSystemObjectElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ISSYSTEMOBJECT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (isSystemObjectElement !== null && isSystemObjectElement !== undefined && isSystemObjectElement.length !== 0) {
                var isSystemObjectInstance = isSystemObjectElement === 'true';
                serviceResourceInstance.isSystemObject = isSystemObjectInstance;
              }
              
              var sizeMBElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'SIZEMB', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (sizeMBElement !== null && sizeMBElement !== undefined) {
                var sizeMBInstance = sizeMBElement;
                serviceResourceInstance.sizeMB = sizeMBInstance;
              }
              
              var serviceObjectiveAssignmentErrorCodeElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'SERVICEOBJECTIVEASSIGNMENTERRORCODE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (serviceObjectiveAssignmentErrorCodeElement !== null && serviceObjectiveAssignmentErrorCodeElement !== undefined) {
                var serviceObjectiveAssignmentErrorCodeInstance = serviceObjectiveAssignmentErrorCodeElement;
                serviceResourceInstance.serviceObjectiveAssignmentErrorCode = serviceObjectiveAssignmentErrorCodeInstance;
              }
              
              var serviceObjectiveAssignmentErrorDescriptionElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'SERVICEOBJECTIVEASSIGNMENTERRORDESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (serviceObjectiveAssignmentErrorDescriptionElement !== null && serviceObjectiveAssignmentErrorDescriptionElement !== undefined) {
                var serviceObjectiveAssignmentErrorDescriptionInstance = serviceObjectiveAssignmentErrorDescriptionElement;
                serviceResourceInstance.serviceObjectiveAssignmentErrorDescription = serviceObjectiveAssignmentErrorDescriptionInstance;
              }
              
              var serviceObjectiveAssignmentStateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'SERVICEOBJECTIVEASSIGNMENTSTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (serviceObjectiveAssignmentStateElement !== null && serviceObjectiveAssignmentStateElement !== undefined) {
                var serviceObjectiveAssignmentStateInstance = serviceObjectiveAssignmentStateElement;
                serviceResourceInstance.serviceObjectiveAssignmentState = serviceObjectiveAssignmentStateInstance;
              }
              
              var serviceObjectiveAssignmentStateDescriptionElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'SERVICEOBJECTIVEASSIGNMENTSTATEDESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (serviceObjectiveAssignmentStateDescriptionElement !== null && serviceObjectiveAssignmentStateDescriptionElement !== undefined) {
                var serviceObjectiveAssignmentStateDescriptionInstance = serviceObjectiveAssignmentStateDescriptionElement;
                serviceResourceInstance.serviceObjectiveAssignmentStateDescription = serviceObjectiveAssignmentStateDescriptionInstance;
              }
              
              var serviceObjectiveAssignmentSuccessDateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'SERVICEOBJECTIVEASSIGNMENTSUCCESSDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (serviceObjectiveAssignmentSuccessDateElement !== null && serviceObjectiveAssignmentSuccessDateElement !== undefined) {
                var serviceObjectiveAssignmentSuccessDateInstance = serviceObjectiveAssignmentSuccessDateElement;
                serviceResourceInstance.serviceObjectiveAssignmentSuccessDate = serviceObjectiveAssignmentSuccessDateInstance;
              }
              
              var serviceObjectiveIdElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'SERVICEOBJECTIVEID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (serviceObjectiveIdElement !== null && serviceObjectiveIdElement !== undefined) {
                var serviceObjectiveIdInstance = serviceObjectiveIdElement;
                serviceResourceInstance.serviceObjectiveId = serviceObjectiveIdInstance;
              }
              
              var assignedServiceObjectiveIdElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ASSIGNEDSERVICEOBJECTIVEID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (assignedServiceObjectiveIdElement !== null && assignedServiceObjectiveIdElement !== undefined) {
                var assignedServiceObjectiveIdInstance = assignedServiceObjectiveIdElement;
                serviceResourceInstance.assignedServiceObjectiveId = assignedServiceObjectiveIdInstance;
              }
              
              var recoveryPeriodStartDateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'RECOVERYPERIODSTARTDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (recoveryPeriodStartDateElement !== null && recoveryPeriodStartDateElement !== undefined && recoveryPeriodStartDateElement.length !== 0) {
                var recoveryPeriodStartDateInstance = new Date(recoveryPeriodStartDateElement);
                serviceResourceInstance.recoveryPeriodStartDate = recoveryPeriodStartDateInstance;
              }
              
              var nameElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                serviceResourceInstance.name = nameInstance;
              }
              
              var typeElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (typeElement !== null && typeElement !== undefined) {
                var typeInstance = typeElement;
                serviceResourceInstance.type = typeInstance;
              }
              
              var stateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stateElement !== null && stateElement !== undefined) {
                var stateInstance = stateElement;
                serviceResourceInstance.state = stateInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Updates the properties of an Azure SQL Database.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server where
   * the database is hosted.
   * 
   * @param {string} databaseName The name of the Azure SQL Database to be
   * updated.
   * 
   * @param {DatabaseUpdateParameters} parameters The parameters for the Update
   * Database operation.
   * 
   * @param {string} [parameters.name] Gets or sets the new name of the
   * database.
   * 
   * @param {string} parameters.edition Gets or sets the new edition for the
   * database.
   * 
   * @param {number} [parameters.maximumDatabaseSizeInGB] Gets or sets the
   * maximum size of this database expressed in gigabytes.  If this is used
   * with MaximumDatabaseSizeInBytes they must agree.
   * 
   * @param {number} [parameters.maximumDatabaseSizeInBytes] Gets or sets the
   * maximum size of this database expressed in bytes.  If this is used with
   * MaximumDatabaseSizeInGB they must agree.
   * 
   * @param {string} [parameters.serviceObjectiveId] Gets or sets the unique
   * identifier for the service objective to apply to the database.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DatabaseOperations.prototype.update = function(serverName, databaseName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (databaseName === null || databaseName === undefined) {
      return callback(new Error('databaseName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.edition === null || parameters.edition === undefined) {
      return callback(new Error('parameters.edition cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/databases/';
    url2 = url2 + encodeURIComponent(databaseName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var serviceResourceElement = js2xml.createElement('ServiceResource', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, serviceResourceElement);
    
    if (parameters.name !== null && parameters.name !== undefined) {
      var nameElement = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(nameElement, parameters.name);
      js2xml.addChildElement(serviceResourceElement, nameElement);
    }
    
    var editionElement = js2xml.createElement('Edition', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(editionElement, parameters.edition);
    js2xml.addChildElement(serviceResourceElement, editionElement);
    
    if (parameters.maximumDatabaseSizeInGB !== null && parameters.maximumDatabaseSizeInGB !== undefined) {
      var maxSizeGBElement = js2xml.createElement('MaxSizeGB', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(maxSizeGBElement, parameters.maximumDatabaseSizeInGB.toString());
      js2xml.addChildElement(serviceResourceElement, maxSizeGBElement);
    }
    
    if (parameters.maximumDatabaseSizeInBytes !== null && parameters.maximumDatabaseSizeInBytes !== undefined) {
      var maxSizeBytesElement = js2xml.createElement('MaxSizeBytes', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(maxSizeBytesElement, parameters.maximumDatabaseSizeInBytes.toString());
      js2xml.addChildElement(serviceResourceElement, maxSizeBytesElement);
    }
    
    if (parameters.serviceObjectiveId !== null && parameters.serviceObjectiveId !== undefined) {
      var serviceObjectiveIdElement = js2xml.createElement('ServiceObjectiveId', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(serviceObjectiveIdElement, parameters.serviceObjectiveId);
      js2xml.addChildElement(serviceResourceElement, serviceObjectiveIdElement);
    }
    
    requestContent = js2xml.serializeDocument(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourceElement2 = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourceElement2 !== null && serviceResourceElement2 !== undefined) {
            var serviceResourceInstance = {};
            result.database = serviceResourceInstance;
            
            var idElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined && idElement.length !== 0) {
              var idInstance = parseInt(idElement, 10);
              serviceResourceInstance.id = idInstance;
            }
            
            var editionElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'EDITION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (editionElement2 !== null && editionElement2 !== undefined) {
              var editionInstance = editionElement2;
              serviceResourceInstance.edition = editionInstance;
            }
            
            var maxSizeGBElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'MAXSIZEGB', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (maxSizeGBElement2 !== null && maxSizeGBElement2 !== undefined && maxSizeGBElement2.length !== 0) {
              var maxSizeGBInstance = parseInt(maxSizeGBElement2, 10);
              serviceResourceInstance.maximumDatabaseSizeInGB = maxSizeGBInstance;
            }
            
            var maxSizeBytesElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'MAXSIZEBYTES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (maxSizeBytesElement2 !== null && maxSizeBytesElement2 !== undefined && maxSizeBytesElement2.length !== 0) {
              var maxSizeBytesInstance = parseInt(maxSizeBytesElement2, 10);
              serviceResourceInstance.maximumDatabaseSizeInBytes = maxSizeBytesInstance;
            }
            
            var collationNameElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'COLLATIONNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (collationNameElement !== null && collationNameElement !== undefined) {
              var collationNameInstance = collationNameElement;
              serviceResourceInstance.collationName = collationNameInstance;
            }
            
            var creationDateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'CREATIONDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (creationDateElement !== null && creationDateElement !== undefined && creationDateElement.length !== 0) {
              var creationDateInstance = new Date(creationDateElement);
              serviceResourceInstance.creationDate = creationDateInstance;
            }
            
            var isFederationRootElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'ISFEDERATIONROOT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isFederationRootElement !== null && isFederationRootElement !== undefined && isFederationRootElement.length !== 0) {
              var isFederationRootInstance = isFederationRootElement === 'true';
              serviceResourceInstance.isFederationRoot = isFederationRootInstance;
            }
            
            var isSystemObjectElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'ISSYSTEMOBJECT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isSystemObjectElement !== null && isSystemObjectElement !== undefined && isSystemObjectElement.length !== 0) {
              var isSystemObjectInstance = isSystemObjectElement === 'true';
              serviceResourceInstance.isSystemObject = isSystemObjectInstance;
            }
            
            var sizeMBElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'SIZEMB', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (sizeMBElement !== null && sizeMBElement !== undefined) {
              var sizeMBInstance = sizeMBElement;
              serviceResourceInstance.sizeMB = sizeMBInstance;
            }
            
            var serviceObjectiveAssignmentErrorCodeElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'SERVICEOBJECTIVEASSIGNMENTERRORCODE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceObjectiveAssignmentErrorCodeElement !== null && serviceObjectiveAssignmentErrorCodeElement !== undefined) {
              var serviceObjectiveAssignmentErrorCodeInstance = serviceObjectiveAssignmentErrorCodeElement;
              serviceResourceInstance.serviceObjectiveAssignmentErrorCode = serviceObjectiveAssignmentErrorCodeInstance;
            }
            
            var serviceObjectiveAssignmentErrorDescriptionElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'SERVICEOBJECTIVEASSIGNMENTERRORDESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceObjectiveAssignmentErrorDescriptionElement !== null && serviceObjectiveAssignmentErrorDescriptionElement !== undefined) {
              var serviceObjectiveAssignmentErrorDescriptionInstance = serviceObjectiveAssignmentErrorDescriptionElement;
              serviceResourceInstance.serviceObjectiveAssignmentErrorDescription = serviceObjectiveAssignmentErrorDescriptionInstance;
            }
            
            var serviceObjectiveAssignmentStateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'SERVICEOBJECTIVEASSIGNMENTSTATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceObjectiveAssignmentStateElement !== null && serviceObjectiveAssignmentStateElement !== undefined) {
              var serviceObjectiveAssignmentStateInstance = serviceObjectiveAssignmentStateElement;
              serviceResourceInstance.serviceObjectiveAssignmentState = serviceObjectiveAssignmentStateInstance;
            }
            
            var serviceObjectiveAssignmentStateDescriptionElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'SERVICEOBJECTIVEASSIGNMENTSTATEDESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceObjectiveAssignmentStateDescriptionElement !== null && serviceObjectiveAssignmentStateDescriptionElement !== undefined) {
              var serviceObjectiveAssignmentStateDescriptionInstance = serviceObjectiveAssignmentStateDescriptionElement;
              serviceResourceInstance.serviceObjectiveAssignmentStateDescription = serviceObjectiveAssignmentStateDescriptionInstance;
            }
            
            var serviceObjectiveAssignmentSuccessDateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'SERVICEOBJECTIVEASSIGNMENTSUCCESSDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceObjectiveAssignmentSuccessDateElement !== null && serviceObjectiveAssignmentSuccessDateElement !== undefined) {
              var serviceObjectiveAssignmentSuccessDateInstance = serviceObjectiveAssignmentSuccessDateElement;
              serviceResourceInstance.serviceObjectiveAssignmentSuccessDate = serviceObjectiveAssignmentSuccessDateInstance;
            }
            
            var serviceObjectiveIdElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'SERVICEOBJECTIVEID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceObjectiveIdElement2 !== null && serviceObjectiveIdElement2 !== undefined) {
              var serviceObjectiveIdInstance = serviceObjectiveIdElement2;
              serviceResourceInstance.serviceObjectiveId = serviceObjectiveIdInstance;
            }
            
            var assignedServiceObjectiveIdElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'ASSIGNEDSERVICEOBJECTIVEID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (assignedServiceObjectiveIdElement !== null && assignedServiceObjectiveIdElement !== undefined) {
              var assignedServiceObjectiveIdInstance = assignedServiceObjectiveIdElement;
              serviceResourceInstance.assignedServiceObjectiveId = assignedServiceObjectiveIdInstance;
            }
            
            var recoveryPeriodStartDateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'RECOVERYPERIODSTARTDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (recoveryPeriodStartDateElement !== null && recoveryPeriodStartDateElement !== undefined && recoveryPeriodStartDateElement.length !== 0) {
              var recoveryPeriodStartDateInstance = new Date(recoveryPeriodStartDateElement);
              serviceResourceInstance.recoveryPeriodStartDate = recoveryPeriodStartDateInstance;
            }
            
            var nameElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement2 !== null && nameElement2 !== undefined) {
              var nameInstance = nameElement2;
              serviceResourceInstance.name = nameInstance;
            }
            
            var typeElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (typeElement !== null && typeElement !== undefined) {
              var typeInstance = typeElement;
              serviceResourceInstance.type = typeInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              serviceResourceInstance.state = stateInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return DatabaseOperations;
})();

var FirewallRuleOperations = ( /** @lends FirewallRuleOperations */ function() {
  /**
   * @class
   * The Azure SQL Database Management API includes operations for managing the
   * server-level Firewall Rules for Azure SQL Database Servers. You cannot
   * manage the database-level firewall rules using the Azure SQL Database
   * Management API; they can only be managed by running the Transact-SQL
   * statements against the master or individual user databases.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [SqlManagementClient] {@link
   * SqlManagementClient~SqlManagementClient}.
   * See [firewallRules] {@link
   * SqlManagementClient~SqlManagementClient#firewallRules}.
   * Initializes a new instance of the FirewallRuleOperations class.
   * @constructor
   * 
   * @param {SqlManagementClient} client Reference to the service client.
   */
  function FirewallRuleOperations(client) {
    this.client = client;
  }
  
  /**
   * Adds a new server-level Firewall Rule for an Azure SQL Database Server.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server to
   * which this rule will be applied.
   * 
   * @param {FirewallRuleCreateParameters} parameters The parameters for the
   * Create Firewall Rule operation.
   * 
   * @param {string} parameters.name Gets or sets the name for the new Firewall
   * Rule.
   * 
   * @param {string} parameters.startIPAddress Gets or sets the beginning IP
   * address for the new Firewall Rule.
   * 
   * @param {string} parameters.endIPAddress Gets or sets the ending IP address
   * for the new Firewall Rule.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  FirewallRuleOperations.prototype.create = function(serverName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.endIPAddress === null || parameters.endIPAddress === undefined) {
      return callback(new Error('parameters.endIPAddress cannot be null.'));
    }
    if (parameters.name === null || parameters.name === undefined) {
      return callback(new Error('parameters.name cannot be null.'));
    }
    if (parameters.startIPAddress === null || parameters.startIPAddress === undefined) {
      return callback(new Error('parameters.startIPAddress cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/firewallrules';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var serviceResourceElement = js2xml.createElement('ServiceResource', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, serviceResourceElement);
    
    var nameElement = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(nameElement, parameters.name);
    js2xml.addChildElement(serviceResourceElement, nameElement);
    
    var startIPAddressElement = js2xml.createElement('StartIPAddress', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(startIPAddressElement, parameters.startIPAddress);
    js2xml.addChildElement(serviceResourceElement, startIPAddressElement);
    
    var endIPAddressElement = js2xml.createElement('EndIPAddress', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(endIPAddressElement, parameters.endIPAddress);
    js2xml.addChildElement(serviceResourceElement, endIPAddressElement);
    
    requestContent = js2xml.serializeDocument(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 201) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 201) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourceElement2 = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourceElement2 !== null && serviceResourceElement2 !== undefined) {
            var serviceResourceInstance = {};
            result.firewallRule = serviceResourceInstance;
            
            var startIPAddressElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'STARTIPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (startIPAddressElement2 !== null && startIPAddressElement2 !== undefined) {
              var startIPAddressInstance = startIPAddressElement2;
              serviceResourceInstance.startIPAddress = startIPAddressInstance;
            }
            
            var endIPAddressElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'ENDIPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (endIPAddressElement2 !== null && endIPAddressElement2 !== undefined) {
              var endIPAddressInstance = endIPAddressElement2;
              serviceResourceInstance.endIPAddress = endIPAddressInstance;
            }
            
            var nameElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement2 !== null && nameElement2 !== undefined) {
              var nameInstance = nameElement2;
              serviceResourceInstance.name = nameInstance;
            }
            
            var typeElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (typeElement !== null && typeElement !== undefined) {
              var typeInstance = typeElement;
              serviceResourceInstance.type = typeInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              serviceResourceInstance.state = stateInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Deletes a server-level Firewall Rule from an Azure SQL Database Server.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server that
   * will have the Firewall Fule removed from it.
   * 
   * @param {string} ruleName The name of the Firewall Fule to delete.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  FirewallRuleOperations.prototype.deleteMethod = function(serverName, ruleName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (ruleName === null || ruleName === undefined) {
      return callback(new Error('ruleName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/firewallrules/';
    url2 = url2 + encodeURIComponent(ruleName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Returns the Firewall rule for an Azure SQL Database Server with a matching
   * name.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server to
   * query for the Firewall Rule.
   * 
   * @param {string} ruleName The name of the rule to retrieve.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  FirewallRuleOperations.prototype.get = function(serverName, ruleName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (ruleName === null || ruleName === undefined) {
      return callback(new Error('ruleName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/firewallrules/';
    url2 = url2 + encodeURIComponent(ruleName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourceElement = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourceElement !== null && serviceResourceElement !== undefined) {
            var serviceResourceInstance = {};
            result.firewallRule = serviceResourceInstance;
            
            var startIPAddressElement = js2xml.getElement(responseDoc, serviceResourceElement, 'STARTIPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (startIPAddressElement !== null && startIPAddressElement !== undefined) {
              var startIPAddressInstance = startIPAddressElement;
              serviceResourceInstance.startIPAddress = startIPAddressInstance;
            }
            
            var endIPAddressElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ENDIPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (endIPAddressElement !== null && endIPAddressElement !== undefined) {
              var endIPAddressInstance = endIPAddressElement;
              serviceResourceInstance.endIPAddress = endIPAddressInstance;
            }
            
            var nameElement = js2xml.getElement(responseDoc, serviceResourceElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              serviceResourceInstance.name = nameInstance;
            }
            
            var typeElement = js2xml.getElement(responseDoc, serviceResourceElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (typeElement !== null && typeElement !== undefined) {
              var typeInstance = typeElement;
              serviceResourceInstance.type = typeInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, serviceResourceElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              serviceResourceInstance.state = stateInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Returns a list of server-level Firewall Rules for an Azure SQL Database
   * Server.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server from
   * which to list the Firewall Rules.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  FirewallRuleOperations.prototype.list = function(serverName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/firewallrules';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { firewallRules: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourcesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourcesSequenceElement !== null && serviceResourcesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var serviceResourcesElement = js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var serviceResourceInstance = {};
              result.firewallRules.push(serviceResourceInstance);
              
              var startIPAddressElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'STARTIPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (startIPAddressElement !== null && startIPAddressElement !== undefined) {
                var startIPAddressInstance = startIPAddressElement;
                serviceResourceInstance.startIPAddress = startIPAddressInstance;
              }
              
              var endIPAddressElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ENDIPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (endIPAddressElement !== null && endIPAddressElement !== undefined) {
                var endIPAddressInstance = endIPAddressElement;
                serviceResourceInstance.endIPAddress = endIPAddressInstance;
              }
              
              var nameElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                serviceResourceInstance.name = nameInstance;
              }
              
              var typeElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (typeElement !== null && typeElement !== undefined) {
                var typeInstance = typeElement;
                serviceResourceInstance.type = typeInstance;
              }
              
              var stateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stateElement !== null && stateElement !== undefined) {
                var stateInstance = stateElement;
                serviceResourceInstance.state = stateInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Updates an existing server-level Firewall Rule for an Azure SQL Database
   * Server.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server that
   * has the Firewall Rule to be updated.
   * 
   * @param {string} ruleName The name of the Firewall Rule to be updated.
   * 
   * @param {FirewallRuleUpdateParameters} parameters The parameters for the
   * Update Firewall Rule operation.
   * 
   * @param {string} parameters.name Gets or sets the new name of the Firewall
   * Rule.
   * 
   * @param {string} parameters.startIPAddress Gets or sets the new beginning
   * IP address for this Firewall Rule.
   * 
   * @param {string} parameters.endIPAddress Gets or sets the new ending IP
   * address for this Firewall Rule.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  FirewallRuleOperations.prototype.update = function(serverName, ruleName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (ruleName === null || ruleName === undefined) {
      return callback(new Error('ruleName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.endIPAddress === null || parameters.endIPAddress === undefined) {
      return callback(new Error('parameters.endIPAddress cannot be null.'));
    }
    if (parameters.name === null || parameters.name === undefined) {
      return callback(new Error('parameters.name cannot be null.'));
    }
    if (parameters.startIPAddress === null || parameters.startIPAddress === undefined) {
      return callback(new Error('parameters.startIPAddress cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/firewallrules/';
    url2 = url2 + encodeURIComponent(ruleName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var serviceResourceElement = js2xml.createElement('ServiceResource', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, serviceResourceElement);
    
    var nameElement = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(nameElement, parameters.name);
    js2xml.addChildElement(serviceResourceElement, nameElement);
    
    var startIPAddressElement = js2xml.createElement('StartIPAddress', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(startIPAddressElement, parameters.startIPAddress);
    js2xml.addChildElement(serviceResourceElement, startIPAddressElement);
    
    var endIPAddressElement = js2xml.createElement('EndIPAddress', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(endIPAddressElement, parameters.endIPAddress);
    js2xml.addChildElement(serviceResourceElement, endIPAddressElement);
    
    requestContent = js2xml.serializeDocument(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourceElement2 = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourceElement2 !== null && serviceResourceElement2 !== undefined) {
            var serviceResourceInstance = {};
            result.firewallRule = serviceResourceInstance;
            
            var startIPAddressElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'STARTIPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (startIPAddressElement2 !== null && startIPAddressElement2 !== undefined) {
              var startIPAddressInstance = startIPAddressElement2;
              serviceResourceInstance.startIPAddress = startIPAddressInstance;
            }
            
            var endIPAddressElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'ENDIPADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (endIPAddressElement2 !== null && endIPAddressElement2 !== undefined) {
              var endIPAddressInstance = endIPAddressElement2;
              serviceResourceInstance.endIPAddress = endIPAddressInstance;
            }
            
            var nameElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement2 !== null && nameElement2 !== undefined) {
              var nameInstance = nameElement2;
              serviceResourceInstance.name = nameInstance;
            }
            
            var typeElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (typeElement !== null && typeElement !== undefined) {
              var typeInstance = typeElement;
              serviceResourceInstance.type = typeInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              serviceResourceInstance.state = stateInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return FirewallRuleOperations;
})();

var QuotaOperations = ( /** @lends QuotaOperations */ function() {
  /**
   * @class
   * The Azure SQL Database Management API includes operations for getting
   * Azure SQL Database Server quotas. Specifically, using the APIs you can
   * get a specific quota or list all of the quotas for the Azure SQL Database
   * Server.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [SqlManagementClient] {@link
   * SqlManagementClient~SqlManagementClient}.
   * See [quotas] {@link SqlManagementClient~SqlManagementClient#quotas}.
   * Initializes a new instance of the QuotaOperations class.
   * @constructor
   * 
   * @param {SqlManagementClient} client Reference to the service client.
   */
  function QuotaOperations(client) {
    this.client = client;
  }
  
  /**
   * Retrieves the specified quota from the server.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server from
   * which to retrieve the quota.
   * 
   * @param {string} quotaName The name of the quota to retrieve.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  QuotaOperations.prototype.get = function(serverName, quotaName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (quotaName === null || quotaName === undefined) {
      return callback(new Error('quotaName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/serverquotas/';
    url2 = url2 + encodeURIComponent(quotaName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourceElement = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourceElement !== null && serviceResourceElement !== undefined) {
            var serviceResourceElement2 = js2xml.getElement(responseDoc, serviceResourceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceResourceElement2 !== null && serviceResourceElement2 !== undefined) {
              var serviceResourceInstance = {};
              result.quota = serviceResourceInstance;
              
              var valueElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'VALUE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (valueElement !== null && valueElement !== undefined) {
                var valueInstance = valueElement;
                serviceResourceInstance.value = valueInstance;
              }
              
              var nameElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                serviceResourceInstance.name = nameInstance;
              }
              
              var typeElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (typeElement !== null && typeElement !== undefined) {
                var typeInstance = typeElement;
                serviceResourceInstance.type = typeInstance;
              }
              
              var stateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stateElement !== null && stateElement !== undefined) {
                var stateInstance = stateElement;
                serviceResourceInstance.state = stateInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Returns a list of quotas from the server.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server from
   * which to get the quotas.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  QuotaOperations.prototype.list = function(serverName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/serverquotas';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { quotas: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourcesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourcesSequenceElement !== null && serviceResourcesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var serviceResourcesElement = js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var serviceResourceInstance = {};
              result.quotas.push(serviceResourceInstance);
              
              var valueElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'VALUE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (valueElement !== null && valueElement !== undefined) {
                var valueInstance = valueElement;
                serviceResourceInstance.value = valueInstance;
              }
              
              var nameElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                serviceResourceInstance.name = nameInstance;
              }
              
              var typeElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (typeElement !== null && typeElement !== undefined) {
                var typeInstance = typeElement;
                serviceResourceInstance.type = typeInstance;
              }
              
              var stateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stateElement !== null && stateElement !== undefined) {
                var stateInstance = stateElement;
                serviceResourceInstance.state = stateInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return QuotaOperations;
})();

var RecoverableDatabaseOperations = ( /** @lends RecoverableDatabaseOperations */ function() {
  /**
   * @class
   * Contains operations for getting Azure SQL Databases that can be recovered.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [SqlManagementClient] {@link
   * SqlManagementClient~SqlManagementClient}.
   * See [recoverableDatabases] {@link
   * SqlManagementClient~SqlManagementClient#recoverableDatabases}.
   * Initializes a new instance of the RecoverableDatabaseOperations class.
   * @constructor
   * 
   * @param {SqlManagementClient} client Reference to the service client.
   */
  function RecoverableDatabaseOperations(client) {
    this.client = client;
  }
  
  /**
   * Returns information about a recoverable Azure SQL Database.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server on
   * which the database was hosted.
   * 
   * @param {string} databaseName The name of the recoverable Azure SQL
   * Database to be obtained.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RecoverableDatabaseOperations.prototype.get = function(serverName, databaseName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (databaseName === null || databaseName === undefined) {
      return callback(new Error('databaseName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/recoverabledatabases/';
    url2 = url2 + encodeURIComponent(databaseName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourceElement = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourceElement !== null && serviceResourceElement !== undefined) {
            var serviceResourceInstance = {};
            result.database = serviceResourceInstance;
            
            var entityIdElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ENTITYID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (entityIdElement !== null && entityIdElement !== undefined) {
              var entityIdInstance = entityIdElement;
              serviceResourceInstance.entityId = entityIdInstance;
            }
            
            var serverNameElement = js2xml.getElement(responseDoc, serviceResourceElement, 'SERVERNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serverNameElement !== null && serverNameElement !== undefined) {
              var serverNameInstance = serverNameElement;
              serviceResourceInstance.serverName = serverNameInstance;
            }
            
            var editionElement = js2xml.getElement(responseDoc, serviceResourceElement, 'EDITION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (editionElement !== null && editionElement !== undefined) {
              var editionInstance = editionElement;
              serviceResourceInstance.edition = editionInstance;
            }
            
            var lastAvailableBackupDateElement = js2xml.getElement(responseDoc, serviceResourceElement, 'LASTAVAILABLEBACKUPDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (lastAvailableBackupDateElement !== null && lastAvailableBackupDateElement !== undefined && lastAvailableBackupDateElement.length !== 0) {
              var lastAvailableBackupDateInstance = new Date(lastAvailableBackupDateElement);
              serviceResourceInstance.lastAvailableBackupDate = lastAvailableBackupDateInstance;
            }
            
            var nameElement = js2xml.getElement(responseDoc, serviceResourceElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              serviceResourceInstance.name = nameInstance;
            }
            
            var typeElement = js2xml.getElement(responseDoc, serviceResourceElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (typeElement !== null && typeElement !== undefined) {
              var typeInstance = typeElement;
              serviceResourceInstance.type = typeInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, serviceResourceElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              serviceResourceInstance.state = stateInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Returns a collection of databases that can be recovered from a specified
   * server.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server on
   * which the databases were hosted.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RecoverableDatabaseOperations.prototype.list = function(serverName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/recoverabledatabases';
    var queryParameters = [];
    queryParameters.push('contentview=generic');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { databases: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourcesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourcesSequenceElement !== null && serviceResourcesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var serviceResourcesElement = js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var serviceResourceInstance = {};
              result.databases.push(serviceResourceInstance);
              
              var entityIdElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ENTITYID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (entityIdElement !== null && entityIdElement !== undefined) {
                var entityIdInstance = entityIdElement;
                serviceResourceInstance.entityId = entityIdInstance;
              }
              
              var serverNameElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'SERVERNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (serverNameElement !== null && serverNameElement !== undefined) {
                var serverNameInstance = serverNameElement;
                serviceResourceInstance.serverName = serverNameInstance;
              }
              
              var editionElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'EDITION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (editionElement !== null && editionElement !== undefined) {
                var editionInstance = editionElement;
                serviceResourceInstance.edition = editionInstance;
              }
              
              var lastAvailableBackupDateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'LASTAVAILABLEBACKUPDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (lastAvailableBackupDateElement !== null && lastAvailableBackupDateElement !== undefined && lastAvailableBackupDateElement.length !== 0) {
                var lastAvailableBackupDateInstance = new Date(lastAvailableBackupDateElement);
                serviceResourceInstance.lastAvailableBackupDate = lastAvailableBackupDateInstance;
              }
              
              var nameElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                serviceResourceInstance.name = nameInstance;
              }
              
              var typeElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (typeElement !== null && typeElement !== undefined) {
                var typeInstance = typeElement;
                serviceResourceInstance.type = typeInstance;
              }
              
              var stateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stateElement !== null && stateElement !== undefined) {
                var stateInstance = stateElement;
                serviceResourceInstance.state = stateInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return RecoverableDatabaseOperations;
})();

var RecoverDatabaseOperations = ( /** @lends RecoverDatabaseOperations */ function() {
  /**
   * @class
   * Contains the operation to create recovery requests for Azure SQL Databases.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [SqlManagementClient] {@link
   * SqlManagementClient~SqlManagementClient}.
   * See [recoverDatabaseOperations] {@link
   * SqlManagementClient~SqlManagementClient#recoverDatabaseOperations}.
   * Initializes a new instance of the RecoverDatabaseOperations class.
   * @constructor
   * 
   * @param {SqlManagementClient} client Reference to the service client.
   */
  function RecoverDatabaseOperations(client) {
    this.client = client;
  }
  
  /**
   * Issues a recovery request for an Azure SQL Database.
   * 
   * @param {string} sourceServerName The name of the Azure SQL Database Server
   * on which the database was hosted.
   * 
   * @param {RecoverDatabaseOperationCreateParameters} parameters Additional
   * parameters for the Create Recover Database Operation request.
   * 
   * @param {string} parameters.sourceDatabaseName Gets or sets the name of the
   * source Azure SQL Database.
   * 
   * @param {string} [parameters.targetServerName] Gets or sets the name of the
   * target Azure SQL Database Server.
   * 
   * @param {string} [parameters.targetDatabaseName] Gets or sets the name of
   * the target Azure SQL Database.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RecoverDatabaseOperations.prototype.create = function(sourceServerName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (sourceServerName === null || sourceServerName === undefined) {
      return callback(new Error('sourceServerName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.sourceDatabaseName === null || parameters.sourceDatabaseName === undefined) {
      return callback(new Error('parameters.sourceDatabaseName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(sourceServerName);
    url2 = url2 + '/recoverdatabaseoperations';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var serviceResourceElement = js2xml.createElement('ServiceResource', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, serviceResourceElement);
    
    var sourceDatabaseNameElement = js2xml.createElement('SourceDatabaseName', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(sourceDatabaseNameElement, parameters.sourceDatabaseName);
    js2xml.addChildElement(serviceResourceElement, sourceDatabaseNameElement);
    
    if (parameters.targetServerName !== null && parameters.targetServerName !== undefined) {
      var targetServerNameElement = js2xml.createElement('TargetServerName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(targetServerNameElement, parameters.targetServerName);
      js2xml.addChildElement(serviceResourceElement, targetServerNameElement);
    }
    
    if (parameters.targetDatabaseName !== null && parameters.targetDatabaseName !== undefined) {
      var targetDatabaseNameElement = js2xml.createElement('TargetDatabaseName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(targetDatabaseNameElement, parameters.targetDatabaseName);
      js2xml.addChildElement(serviceResourceElement, targetDatabaseNameElement);
    }
    
    requestContent = js2xml.serializeDocument(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 201) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 201) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourceElement2 = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourceElement2 !== null && serviceResourceElement2 !== undefined) {
            var serviceResourceInstance = {};
            result.operation = serviceResourceInstance;
            
            var requestIDElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'REQUESTID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (requestIDElement !== null && requestIDElement !== undefined) {
              var requestIDInstance = requestIDElement;
              serviceResourceInstance.id = requestIDInstance;
            }
            
            var sourceDatabaseNameElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'SOURCEDATABASENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (sourceDatabaseNameElement2 !== null && sourceDatabaseNameElement2 !== undefined) {
              var sourceDatabaseNameInstance = sourceDatabaseNameElement2;
              serviceResourceInstance.sourceDatabaseName = sourceDatabaseNameInstance;
            }
            
            var targetServerNameElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'TARGETSERVERNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (targetServerNameElement2 !== null && targetServerNameElement2 !== undefined) {
              var targetServerNameInstance = targetServerNameElement2;
              serviceResourceInstance.targetServerName = targetServerNameInstance;
            }
            
            var targetDatabaseNameElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'TARGETDATABASENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (targetDatabaseNameElement2 !== null && targetDatabaseNameElement2 !== undefined) {
              var targetDatabaseNameInstance = targetDatabaseNameElement2;
              serviceResourceInstance.targetDatabaseName = targetDatabaseNameInstance;
            }
            
            var nameElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              serviceResourceInstance.name = nameInstance;
            }
            
            var typeElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (typeElement !== null && typeElement !== undefined) {
              var typeInstance = typeElement;
              serviceResourceInstance.type = typeInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              serviceResourceInstance.state = stateInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return RecoverDatabaseOperations;
})();

var RestorableDroppedDatabaseOperations = ( /** @lends RestorableDroppedDatabaseOperations */ function() {
  /**
   * @class
   * Contains operations for getting dropped Azure SQL Databases that can be
   * restored.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [SqlManagementClient] {@link
   * SqlManagementClient~SqlManagementClient}.
   * See [restorableDroppedDatabases] {@link
   * SqlManagementClient~SqlManagementClient#restorableDroppedDatabases}.
   * Initializes a new instance of the RestorableDroppedDatabaseOperations
   * class.
   * @constructor
   * 
   * @param {SqlManagementClient} client Reference to the service client.
   */
  function RestorableDroppedDatabaseOperations(client) {
    this.client = client;
  }
  
  /**
   * Returns information about a dropped Azure SQL Database that can be
   * restored.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server on
   * which the database was hosted.
   * 
   * @param {string} entityId The entity ID of the restorable dropped Azure SQL
   * Database to be obtained.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RestorableDroppedDatabaseOperations.prototype.get = function(serverName, entityId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (entityId === null || entityId === undefined) {
      return callback(new Error('entityId cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/restorabledroppeddatabases/';
    url2 = url2 + encodeURIComponent(entityId);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourceElement = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourceElement !== null && serviceResourceElement !== undefined) {
            var serviceResourceInstance = {};
            result.database = serviceResourceInstance;
            
            var entityIdElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ENTITYID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (entityIdElement !== null && entityIdElement !== undefined) {
              var entityIdInstance = entityIdElement;
              serviceResourceInstance.entityId = entityIdInstance;
            }
            
            var serverNameElement = js2xml.getElement(responseDoc, serviceResourceElement, 'SERVERNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serverNameElement !== null && serverNameElement !== undefined) {
              var serverNameInstance = serverNameElement;
              serviceResourceInstance.serverName = serverNameInstance;
            }
            
            var editionElement = js2xml.getElement(responseDoc, serviceResourceElement, 'EDITION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (editionElement !== null && editionElement !== undefined) {
              var editionInstance = editionElement;
              serviceResourceInstance.edition = editionInstance;
            }
            
            var maxSizeBytesElement = js2xml.getElement(responseDoc, serviceResourceElement, 'MAXSIZEBYTES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (maxSizeBytesElement !== null && maxSizeBytesElement !== undefined && maxSizeBytesElement.length !== 0) {
              var maxSizeBytesInstance = parseInt(maxSizeBytesElement, 10);
              serviceResourceInstance.maximumDatabaseSizeInBytes = maxSizeBytesInstance;
            }
            
            var creationDateElement = js2xml.getElement(responseDoc, serviceResourceElement, 'CREATIONDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (creationDateElement !== null && creationDateElement !== undefined && creationDateElement.length !== 0) {
              var creationDateInstance = new Date(creationDateElement);
              serviceResourceInstance.creationDate = creationDateInstance;
            }
            
            var deletionDateElement = js2xml.getElement(responseDoc, serviceResourceElement, 'DELETIONDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (deletionDateElement !== null && deletionDateElement !== undefined && deletionDateElement.length !== 0) {
              var deletionDateInstance = new Date(deletionDateElement);
              serviceResourceInstance.deletionDate = deletionDateInstance;
            }
            
            var recoveryPeriodStartDateElement = js2xml.getElement(responseDoc, serviceResourceElement, 'RECOVERYPERIODSTARTDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (recoveryPeriodStartDateElement !== null && recoveryPeriodStartDateElement !== undefined && recoveryPeriodStartDateElement.length !== 0) {
              var recoveryPeriodStartDateInstance = new Date(recoveryPeriodStartDateElement);
              serviceResourceInstance.recoveryPeriodStartDate = recoveryPeriodStartDateInstance;
            }
            
            var nameElement = js2xml.getElement(responseDoc, serviceResourceElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              serviceResourceInstance.name = nameInstance;
            }
            
            var typeElement = js2xml.getElement(responseDoc, serviceResourceElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (typeElement !== null && typeElement !== undefined) {
              var typeInstance = typeElement;
              serviceResourceInstance.type = typeInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, serviceResourceElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              serviceResourceInstance.state = stateInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Returns a collection of databases that has been dropped but can still be
   * restored from a specified server.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server to
   * query for dropped databases that can still be restored.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RestorableDroppedDatabaseOperations.prototype.list = function(serverName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/restorabledroppeddatabases';
    var queryParameters = [];
    queryParameters.push('contentview=generic');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { databases: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourcesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourcesSequenceElement !== null && serviceResourcesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var serviceResourcesElement = js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var serviceResourceInstance = {};
              result.databases.push(serviceResourceInstance);
              
              var entityIdElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ENTITYID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (entityIdElement !== null && entityIdElement !== undefined) {
                var entityIdInstance = entityIdElement;
                serviceResourceInstance.entityId = entityIdInstance;
              }
              
              var serverNameElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'SERVERNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (serverNameElement !== null && serverNameElement !== undefined) {
                var serverNameInstance = serverNameElement;
                serviceResourceInstance.serverName = serverNameInstance;
              }
              
              var editionElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'EDITION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (editionElement !== null && editionElement !== undefined) {
                var editionInstance = editionElement;
                serviceResourceInstance.edition = editionInstance;
              }
              
              var maxSizeBytesElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'MAXSIZEBYTES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (maxSizeBytesElement !== null && maxSizeBytesElement !== undefined && maxSizeBytesElement.length !== 0) {
                var maxSizeBytesInstance = parseInt(maxSizeBytesElement, 10);
                serviceResourceInstance.maximumDatabaseSizeInBytes = maxSizeBytesInstance;
              }
              
              var creationDateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'CREATIONDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (creationDateElement !== null && creationDateElement !== undefined && creationDateElement.length !== 0) {
                var creationDateInstance = new Date(creationDateElement);
                serviceResourceInstance.creationDate = creationDateInstance;
              }
              
              var deletionDateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'DELETIONDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (deletionDateElement !== null && deletionDateElement !== undefined && deletionDateElement.length !== 0) {
                var deletionDateInstance = new Date(deletionDateElement);
                serviceResourceInstance.deletionDate = deletionDateInstance;
              }
              
              var recoveryPeriodStartDateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'RECOVERYPERIODSTARTDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (recoveryPeriodStartDateElement !== null && recoveryPeriodStartDateElement !== undefined && recoveryPeriodStartDateElement.length !== 0) {
                var recoveryPeriodStartDateInstance = new Date(recoveryPeriodStartDateElement);
                serviceResourceInstance.recoveryPeriodStartDate = recoveryPeriodStartDateInstance;
              }
              
              var nameElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                serviceResourceInstance.name = nameInstance;
              }
              
              var typeElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (typeElement !== null && typeElement !== undefined) {
                var typeInstance = typeElement;
                serviceResourceInstance.type = typeInstance;
              }
              
              var stateElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stateElement !== null && stateElement !== undefined) {
                var stateInstance = stateElement;
                serviceResourceInstance.state = stateInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return RestorableDroppedDatabaseOperations;
})();

var RestoreDatabaseOperations = ( /** @lends RestoreDatabaseOperations */ function() {
  /**
   * @class
   * Contains the operation to create restore requests for Azure SQL Databases.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [SqlManagementClient] {@link
   * SqlManagementClient~SqlManagementClient}.
   * See [restoreDatabaseOperations] {@link
   * SqlManagementClient~SqlManagementClient#restoreDatabaseOperations}.
   * Initializes a new instance of the RestoreDatabaseOperations class.
   * @constructor
   * 
   * @param {SqlManagementClient} client Reference to the service client.
   */
  function RestoreDatabaseOperations(client) {
    this.client = client;
  }
  
  /**
   * Issues a restore request for an Azure SQL Database.
   * 
   * @param {string} sourceServerName The name of the Azure SQL Database Server
   * where the source database is, or was, hosted.
   * 
   * @param {RestoreDatabaseOperationCreateParameters} parameters Additional
   * parameters for the Create Restore Database Operation request.
   * 
   * @param {string} parameters.sourceDatabaseName Gets or sets the name of the
   * source Azure SQL Database.
   * 
   * @param {date} [parameters.sourceDatabaseDeletionDate] Gets or sets the
   * deletion date of the source Azure SQL Database.
   * 
   * @param {string} [parameters.targetServerName] Gets or sets the name of the
   * target Azure SQL Database Server.
   * 
   * @param {string} parameters.targetDatabaseName Gets or sets the name of the
   * target Azure SQL Database.
   * 
   * @param {date} [parameters.pointInTime] Gets or sets the point in time to
   * restore to.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RestoreDatabaseOperations.prototype.create = function(sourceServerName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (sourceServerName === null || sourceServerName === undefined) {
      return callback(new Error('sourceServerName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.sourceDatabaseName === null || parameters.sourceDatabaseName === undefined) {
      return callback(new Error('parameters.sourceDatabaseName cannot be null.'));
    }
    if (parameters.targetDatabaseName === null || parameters.targetDatabaseName === undefined) {
      return callback(new Error('parameters.targetDatabaseName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(sourceServerName);
    url2 = url2 + '/restoredatabaseoperations';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var serviceResourceElement = js2xml.createElement('ServiceResource', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, serviceResourceElement);
    
    var sourceDatabaseNameElement = js2xml.createElement('SourceDatabaseName', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(sourceDatabaseNameElement, parameters.sourceDatabaseName);
    js2xml.addChildElement(serviceResourceElement, sourceDatabaseNameElement);
    
    if (parameters.sourceDatabaseDeletionDate !== null && parameters.sourceDatabaseDeletionDate !== undefined) {
      var sourceDatabaseDeletionDateElement = js2xml.createElement('SourceDatabaseDeletionDate', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(sourceDatabaseDeletionDateElement, parameters.sourceDatabaseDeletionDate.toISOString());
      js2xml.addChildElement(serviceResourceElement, sourceDatabaseDeletionDateElement);
    }
    
    if (parameters.targetServerName !== null && parameters.targetServerName !== undefined) {
      var targetServerNameElement = js2xml.createElement('TargetServerName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(targetServerNameElement, parameters.targetServerName);
      js2xml.addChildElement(serviceResourceElement, targetServerNameElement);
    }
    
    var targetDatabaseNameElement = js2xml.createElement('TargetDatabaseName', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(targetDatabaseNameElement, parameters.targetDatabaseName);
    js2xml.addChildElement(serviceResourceElement, targetDatabaseNameElement);
    
    if (parameters.pointInTime !== null && parameters.pointInTime !== undefined) {
      var targetUtcPointInTimeElement = js2xml.createElement('TargetUtcPointInTime', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(targetUtcPointInTimeElement, parameters.pointInTime.toISOString());
      js2xml.addChildElement(serviceResourceElement, targetUtcPointInTimeElement);
    }
    
    requestContent = js2xml.serializeDocument(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 201) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 201) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourceElement2 = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourceElement2 !== null && serviceResourceElement2 !== undefined) {
            var serviceResourceInstance = {};
            result.operation = serviceResourceInstance;
            
            var requestIDElement = js2xml.getElement(responseDoc, serviceResourceElement2, 'REQUESTID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (requestIDElement !== null && requestIDElement !== undefined) {
              var requestIDInstance = requestIDElement;
              serviceResourceInstance.id = requestIDInstance;
            }
            
            var sourceDatabaseNameElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'SOURCEDATABASENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (sourceDatabaseNameElement2 !== null && sourceDatabaseNameElement2 !== undefined) {
              var sourceDatabaseNameInstance = sourceDatabaseNameElement2;
              serviceResourceInstance.sourceDatabaseName = sourceDatabaseNameInstance;
            }
            
            var sourceDatabaseDeletionDateElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'SOURCEDATABASEDELETIONDATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (sourceDatabaseDeletionDateElement2 !== null && sourceDatabaseDeletionDateElement2 !== undefined && sourceDatabaseDeletionDateElement2.length !== 0) {
              var sourceDatabaseDeletionDateInstance = new Date(sourceDatabaseDeletionDateElement2);
              serviceResourceInstance.sourceDatabaseDeletionDate = sourceDatabaseDeletionDateInstance;
            }
            
            var targetServerNameElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'TARGETSERVERNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (targetServerNameElement2 !== null && targetServerNameElement2 !== undefined) {
              var targetServerNameInstance = targetServerNameElement2;
              serviceResourceInstance.targetServerName = targetServerNameInstance;
            }
            
            var targetDatabaseNameElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'TARGETDATABASENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (targetDatabaseNameElement2 !== null && targetDatabaseNameElement2 !== undefined) {
              var targetDatabaseNameInstance = targetDatabaseNameElement2;
              serviceResourceInstance.targetDatabaseName = targetDatabaseNameInstance;
            }
            
            var targetUtcPointInTimeElement2 = js2xml.getElement(responseDoc, serviceResourceElement2, 'TARGETUTCPOINTINTIME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (targetUtcPointInTimeElement2 !== null && targetUtcPointInTimeElement2 !== undefined && targetUtcPointInTimeElement2.length !== 0) {
              var targetUtcPointInTimeInstance = new Date(targetUtcPointInTimeElement2);
              serviceResourceInstance.pointInTime = targetUtcPointInTimeInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return RestoreDatabaseOperations;
})();

var ServerOperations = ( /** @lends ServerOperations */ function() {
  /**
   * @class
   * Contains methods to allow various operations on Azure SQL Database Servers.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [SqlManagementClient] {@link
   * SqlManagementClient~SqlManagementClient}.
   * See [servers] {@link SqlManagementClient~SqlManagementClient#servers}.
   * Initializes a new instance of the ServerOperations class.
   * @constructor
   * 
   * @param {SqlManagementClient} client Reference to the service client.
   */
  function ServerOperations(client) {
    this.client = client;
  }
  
  /**
   * Changes the administrative password of an existing Azure SQL Database
   * Server for a given subscription.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server that
   * will have the administrator password changed.
   * 
   * @param {ServerChangeAdministratorPasswordParameters} parameters The
   * necessary parameters for modifying the adminstrator password for a server.
   * 
   * @param {string} parameters.newPassword Gets or sets the new password for
   * the administrator.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ServerOperations.prototype.changeAdministratorPassword = function(serverName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.newPassword === null || parameters.newPassword === undefined) {
      return callback(new Error('parameters.newPassword cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    var queryParameters = [];
    queryParameters.push('op=ResetPassword');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var administratorLoginPasswordElement = js2xml.createElement('AdministratorLoginPassword', 'http://schemas.microsoft.com/sqlazure/2010/12/');
    js2xml.addChildElement(requestDoc, administratorLoginPasswordElement);
    
    js2xml.setElementValue(administratorLoginPasswordElement, parameters.newPassword);
    
    requestContent = js2xml.serializeDocument(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Provisions a new SQL Database server in a subscription.
   * 
   * @param {ServerCreateParameters} parameters The parameters needed to
   * provision a server.
   * 
   * @param {string} parameters.administratorUserName Gets or sets the
   * administrator username that will be used for the new server.
   * 
   * @param {string} parameters.administratorPassword Gets or sets the
   * administrator password for the new server.
   * 
   * @param {string} parameters.location Gets or sets the region in which this
   * server will be created.  See
   * http://azure.microsoft.com/en-us/regions/#services for a list of all the
   * available regions.
   * 
   * @param {string} [parameters.version] Gets or sets the version of server to
   * create.  Valid values are: 1.0, 2.0.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ServerOperations.prototype.create = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.administratorPassword === null || parameters.administratorPassword === undefined) {
      return callback(new Error('parameters.administratorPassword cannot be null.'));
    }
    if (parameters.administratorUserName === null || parameters.administratorUserName === undefined) {
      return callback(new Error('parameters.administratorUserName cannot be null.'));
    }
    if (parameters.location === null || parameters.location === undefined) {
      return callback(new Error('parameters.location cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var serverElement = js2xml.createElement('Server', 'http://schemas.microsoft.com/sqlazure/2010/12/');
    js2xml.addChildElement(requestDoc, serverElement);
    
    var administratorLoginElement = js2xml.createElement('AdministratorLogin', 'http://schemas.microsoft.com/sqlazure/2010/12/');
    js2xml.setElementValue(administratorLoginElement, parameters.administratorUserName);
    js2xml.addChildElement(serverElement, administratorLoginElement);
    
    var administratorLoginPasswordElement = js2xml.createElement('AdministratorLoginPassword', 'http://schemas.microsoft.com/sqlazure/2010/12/');
    js2xml.setElementValue(administratorLoginPasswordElement, parameters.administratorPassword);
    js2xml.addChildElement(serverElement, administratorLoginPasswordElement);
    
    var locationElement = js2xml.createElement('Location', 'http://schemas.microsoft.com/sqlazure/2010/12/');
    js2xml.setElementValue(locationElement, parameters.location);
    js2xml.addChildElement(serverElement, locationElement);
    
    if (parameters.version !== null && parameters.version !== undefined) {
      var versionElement = js2xml.createElement('Version', 'http://schemas.microsoft.com/sqlazure/2010/12/');
      js2xml.setElementValue(versionElement, parameters.version);
      js2xml.addChildElement(serverElement, versionElement);
    }
    
    requestContent = js2xml.serializeDocument(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 201) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 201) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serverNameElement = js2xml.getElement(responseDoc, responseDoc, 'SERVERNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/SQLAZURE/2010/12/');
          if (serverNameElement !== null && serverNameElement !== undefined) {
            var fullyQualifiedDomainNameAttribute = js2xml.getAttribute(responseDoc, serverNameElement, 'FULLYQUALIFIEDDOMAINNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/SQLAZURE/2010/12/');
            if (fullyQualifiedDomainNameAttribute !== null && fullyQualifiedDomainNameAttribute !== undefined) {
              result.fullyQualifiedDomainName = fullyQualifiedDomainNameAttribute;
            }
            
            result.serverName = serverNameElement;
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Deletes the specified Azure SQL Database Server from a subscription.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server to be
   * deleted.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ServerOperations.prototype.deleteMethod = function(serverName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Returns all SQL Database Servers that are provisioned for a subscription.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ServerOperations.prototype.list = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { servers: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serversSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'SERVERS', 'HTTP://SCHEMAS.MICROSOFT.COM/SQLAZURE/2010/12/');
          if (serversSequenceElement !== null && serversSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, serversSequenceElement, 'SERVER', 'HTTP://SCHEMAS.MICROSOFT.COM/SQLAZURE/2010/12/').length; loweredIndex1 = loweredIndex1 + 1) {
              var serversElement = js2xml.getElements(responseDoc, serversSequenceElement, 'SERVER', 'HTTP://SCHEMAS.MICROSOFT.COM/SQLAZURE/2010/12/')[loweredIndex1];
              var serverInstance = {};
              result.servers.push(serverInstance);
              
              var nameElement = js2xml.getElement(responseDoc, serversElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/SQLAZURE/2010/12/');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                serverInstance.name = nameInstance;
              }
              
              var administratorLoginElement = js2xml.getElement(responseDoc, serversElement, 'ADMINISTRATORLOGIN', 'HTTP://SCHEMAS.MICROSOFT.COM/SQLAZURE/2010/12/');
              if (administratorLoginElement !== null && administratorLoginElement !== undefined) {
                var administratorLoginInstance = administratorLoginElement;
                serverInstance.administratorUserName = administratorLoginInstance;
              }
              
              var locationElement = js2xml.getElement(responseDoc, serversElement, 'LOCATION', 'HTTP://SCHEMAS.MICROSOFT.COM/SQLAZURE/2010/12/');
              if (locationElement !== null && locationElement !== undefined) {
                var locationInstance = locationElement;
                serverInstance.location = locationInstance;
              }
              
              var fullyQualifiedDomainNameElement = js2xml.getElement(responseDoc, serversElement, 'FULLYQUALIFIEDDOMAINNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/SQLAZURE/2010/12/');
              if (fullyQualifiedDomainNameElement !== null && fullyQualifiedDomainNameElement !== undefined) {
                var fullyQualifiedDomainNameInstance = fullyQualifiedDomainNameElement;
                serverInstance.fullyQualifiedDomainName = fullyQualifiedDomainNameInstance;
              }
              
              var stateElement = js2xml.getElement(responseDoc, serversElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/SQLAZURE/2010/12/');
              if (stateElement !== null && stateElement !== undefined) {
                var stateInstance = stateElement;
                serverInstance.state = stateInstance;
              }
              
              var versionElement = js2xml.getElement(responseDoc, serversElement, 'VERSION', 'HTTP://SCHEMAS.MICROSOFT.COM/SQLAZURE/2010/12/');
              if (versionElement !== null && versionElement !== undefined) {
                var versionInstance = versionElement;
                serverInstance.version = versionInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return ServerOperations;
})();

var ServiceObjectiveOperations = ( /** @lends ServiceObjectiveOperations */ function() {
  /**
   * @class
   * This class provides methods to get a specific service objective by using
   * its ID or to List all of the service objectives on a server.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [SqlManagementClient] {@link
   * SqlManagementClient~SqlManagementClient}.
   * See [serviceObjectives] {@link
   * SqlManagementClient~SqlManagementClient#serviceObjectives}.
   * Initializes a new instance of the ServiceObjectiveOperations class.
   * @constructor
   * 
   * @param {SqlManagementClient} client Reference to the service client.
   */
  function ServiceObjectiveOperations(client) {
    this.client = client;
  }
  
  /**
   * Returns information about a certain Service Objective with a specific Id.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server to be
   * queried.
   * 
   * @param {string} serviceObjectiveId The Id of the Service Objective to be
   * obtained.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ServiceObjectiveOperations.prototype.get = function(serverName, serviceObjectiveId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    if (serviceObjectiveId === null || serviceObjectiveId === undefined) {
      return callback(new Error('serviceObjectiveId cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/serviceobjectives/';
    url2 = url2 + encodeURIComponent(serviceObjectiveId);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourceElement = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourceElement !== null && serviceResourceElement !== undefined) {
            var serviceResourceInstance = { dimensionSettings: [] };
            result.serviceObjective = serviceResourceInstance;
            
            var idElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              serviceResourceInstance.id = idInstance;
            }
            
            var isDefaultElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ISDEFAULT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isDefaultElement !== null && isDefaultElement !== undefined && isDefaultElement.length !== 0) {
              var isDefaultInstance = isDefaultElement === 'true';
              serviceResourceInstance.isDefault = isDefaultInstance;
            }
            
            var isSystemElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ISSYSTEM', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isSystemElement !== null && isSystemElement !== undefined && isSystemElement.length !== 0) {
              var isSystemInstance = isSystemElement === 'true';
              serviceResourceInstance.isSystem = isSystemInstance;
            }
            
            var descriptionElement = js2xml.getElement(responseDoc, serviceResourceElement, 'DESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (descriptionElement !== null && descriptionElement !== undefined) {
              var descriptionInstance = descriptionElement;
              serviceResourceInstance.description = descriptionInstance;
            }
            
            var enabledElement = js2xml.getElement(responseDoc, serviceResourceElement, 'ENABLED', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (enabledElement !== null && enabledElement !== undefined && enabledElement.length !== 0) {
              var enabledInstance = enabledElement === 'true';
              serviceResourceInstance.enabled = enabledInstance;
            }
            
            var dimensionSettingsSequenceElement = js2xml.getElement(responseDoc, serviceResourceElement, 'DIMENSIONSETTINGS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (dimensionSettingsSequenceElement !== null && dimensionSettingsSequenceElement !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, dimensionSettingsSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
                var dimensionSettingsElement = js2xml.getElements(responseDoc, dimensionSettingsSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
                var serviceResourceInstance2 = {};
                serviceResourceInstance.dimensionSettings.push(serviceResourceInstance2);
                
                var idElement2 = js2xml.getElement(responseDoc, dimensionSettingsElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (idElement2 !== null && idElement2 !== undefined) {
                  var idInstance2 = idElement2;
                  serviceResourceInstance2.id = idInstance2;
                }
                
                var descriptionElement2 = js2xml.getElement(responseDoc, dimensionSettingsElement, 'DESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (descriptionElement2 !== null && descriptionElement2 !== undefined) {
                  var descriptionInstance2 = descriptionElement2;
                  serviceResourceInstance2.description = descriptionInstance2;
                }
                
                var ordinalElement = js2xml.getElement(responseDoc, dimensionSettingsElement, 'ORDINAL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (ordinalElement !== null && ordinalElement !== undefined && ordinalElement.length !== 0) {
                  var ordinalInstance = parseInt(ordinalElement, 10);
                  serviceResourceInstance2.ordinal = ordinalInstance;
                }
                
                var isDefaultElement2 = js2xml.getElement(responseDoc, dimensionSettingsElement, 'ISDEFAULT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (isDefaultElement2 !== null && isDefaultElement2 !== undefined && isDefaultElement2.length !== 0) {
                  var isDefaultInstance2 = isDefaultElement2 === 'true';
                  serviceResourceInstance2.isDefault = isDefaultInstance2;
                }
                
                var nameElement = js2xml.getElement(responseDoc, dimensionSettingsElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (nameElement !== null && nameElement !== undefined) {
                  var nameInstance = nameElement;
                  serviceResourceInstance2.name = nameInstance;
                }
                
                var typeElement = js2xml.getElement(responseDoc, dimensionSettingsElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (typeElement !== null && typeElement !== undefined) {
                  var typeInstance = typeElement;
                  serviceResourceInstance2.type = typeInstance;
                }
                
                var stateElement = js2xml.getElement(responseDoc, dimensionSettingsElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (stateElement !== null && stateElement !== undefined) {
                  var stateInstance = stateElement;
                  serviceResourceInstance2.state = stateInstance;
                }
              }
            }
            
            var nameElement2 = js2xml.getElement(responseDoc, serviceResourceElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement2 !== null && nameElement2 !== undefined) {
              var nameInstance2 = nameElement2;
              serviceResourceInstance.name = nameInstance2;
            }
            
            var typeElement2 = js2xml.getElement(responseDoc, serviceResourceElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (typeElement2 !== null && typeElement2 !== undefined) {
              var typeInstance2 = typeElement2;
              serviceResourceInstance.type = typeInstance2;
            }
            
            var stateElement2 = js2xml.getElement(responseDoc, serviceResourceElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement2 !== null && stateElement2 !== undefined) {
              var stateInstance2 = stateElement2;
              serviceResourceInstance.state = stateInstance2;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Returns information about all Service Objectives on an Azure SQL Database
   * Server.
   * 
   * @param {string} serverName The name of the Azure SQL Database Server to be
   * queried.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ServiceObjectiveOperations.prototype.list = function(serverName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (serverName === null || serverName === undefined) {
      return callback(new Error('serverName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/services/sqlservers/servers/';
    url2 = url2 + encodeURIComponent(serverName);
    url2 = url2 + '/serviceobjectives';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2012-03-01';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { serviceObjectives: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var serviceResourcesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'SERVICERESOURCES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (serviceResourcesSequenceElement !== null && serviceResourcesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var serviceResourcesElement = js2xml.getElements(responseDoc, serviceResourcesSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var serviceResourceInstance = { dimensionSettings: [] };
              result.serviceObjectives.push(serviceResourceInstance);
              
              var idElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (idElement !== null && idElement !== undefined) {
                var idInstance = idElement;
                serviceResourceInstance.id = idInstance;
              }
              
              var isDefaultElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ISDEFAULT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (isDefaultElement !== null && isDefaultElement !== undefined && isDefaultElement.length !== 0) {
                var isDefaultInstance = isDefaultElement === 'true';
                serviceResourceInstance.isDefault = isDefaultInstance;
              }
              
              var isSystemElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ISSYSTEM', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (isSystemElement !== null && isSystemElement !== undefined && isSystemElement.length !== 0) {
                var isSystemInstance = isSystemElement === 'true';
                serviceResourceInstance.isSystem = isSystemInstance;
              }
              
              var descriptionElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'DESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (descriptionElement !== null && descriptionElement !== undefined) {
                var descriptionInstance = descriptionElement;
                serviceResourceInstance.description = descriptionInstance;
              }
              
              var enabledElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'ENABLED', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (enabledElement !== null && enabledElement !== undefined && enabledElement.length !== 0) {
                var enabledInstance = enabledElement === 'true';
                serviceResourceInstance.enabled = enabledInstance;
              }
              
              var dimensionSettingsSequenceElement = js2xml.getElement(responseDoc, serviceResourcesElement, 'DIMENSIONSETTINGS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (dimensionSettingsSequenceElement !== null && dimensionSettingsSequenceElement !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < js2xml.getElements(responseDoc, dimensionSettingsSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex2 = loweredIndex2 + 1) {
                  var dimensionSettingsElement = js2xml.getElements(responseDoc, dimensionSettingsSequenceElement, 'SERVICERESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex2];
                  var serviceResourceInstance2 = {};
                  serviceResourceInstance.dimensionSettings.push(serviceResourceInstance2);
                  
                  var idElement2 = js2xml.getElement(responseDoc, dimensionSettingsElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (idElement2 !== null && idElement2 !== undefined) {
                    var idInstance2 = idElement2;
                    serviceResourceInstance2.id = idInstance2;
                  }
                  
                  var descriptionElement2 = js2xml.getElement(responseDoc, dimensionSettingsElement, 'DESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (descriptionElement2 !== null && descriptionElement2 !== undefined) {
                    var descriptionInstance2 = descriptionElement2;
                    serviceResourceInstance2.description = descriptionInstance2;
                  }
                  
                  var ordinalElement = js2xml.getElement(responseDoc, dimensionSettingsElement, 'ORDINAL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (ordinalElement !== null && ordinalElement !== undefined && ordinalElement.length !== 0) {
                    var ordinalInstance = parseInt(ordinalElement, 10);
                    serviceResourceInstance2.ordinal = ordinalInstance;
                  }
                  
                  var isDefaultElement2 = js2xml.getElement(responseDoc, dimensionSettingsElement, 'ISDEFAULT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (isDefaultElement2 !== null && isDefaultElement2 !== undefined && isDefaultElement2.length !== 0) {
                    var isDefaultInstance2 = isDefaultElement2 === 'true';
                    serviceResourceInstance2.isDefault = isDefaultInstance2;
                  }
                  
                  var nameElement = js2xml.getElement(responseDoc, dimensionSettingsElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (nameElement !== null && nameElement !== undefined) {
                    var nameInstance = nameElement;
                    serviceResourceInstance2.name = nameInstance;
                  }
                  
                  var typeElement = js2xml.getElement(responseDoc, dimensionSettingsElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (typeElement !== null && typeElement !== undefined) {
                    var typeInstance = typeElement;
                    serviceResourceInstance2.type = typeInstance;
                  }
                  
                  var stateElement = js2xml.getElement(responseDoc, dimensionSettingsElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (stateElement !== null && stateElement !== undefined) {
                    var stateInstance = stateElement;
                    serviceResourceInstance2.state = stateInstance;
                  }
                }
              }
              
              var nameElement2 = js2xml.getElement(responseDoc, serviceResourcesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement2 !== null && nameElement2 !== undefined) {
                var nameInstance2 = nameElement2;
                serviceResourceInstance.name = nameInstance2;
              }
              
              var typeElement2 = js2xml.getElement(responseDoc, serviceResourcesElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (typeElement2 !== null && typeElement2 !== undefined) {
                var typeInstance2 = typeElement2;
                serviceResourceInstance.type = typeInstance2;
              }
              
              var stateElement2 = js2xml.getElement(responseDoc, serviceResourcesElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (stateElement2 !== null && stateElement2 !== undefined) {
                var stateInstance2 = stateElement2;
                serviceResourceInstance.state = stateInstance2;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return ServiceObjectiveOperations;
})();
