/* 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 azureCommon = require('azure-common');
var xml = azureCommon.xml2js;
var js2xml = azureCommon.js2xml;
var Service = azureCommon.Service;
var WebResource = azureCommon.WebResource;

var TrafficManagerManagementClient = ( /** @lends TrafficManagerManagementClient */ function() {
  /**
   * @class
   * The Windows Azure Traffic Manager management API provides a RESTful set of
   * web services that interact with Windows Azure Traffic Manager service for
   * creating, updating, listing, and deleting Traffic Manager profiles and
   * definitions.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/dn166981.aspx for
   * more information)
   * Initializes a new instance of the TrafficManagerManagementClient 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 TrafficManagerManagementClient(credentials, baseUri, filters) {
    if (credentials === null || credentials === undefined) {
      throw new Error('credentials cannot be null.');
    }
    
    TrafficManagerManagementClient['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 = '2011-10-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
     * [DefinitionOperations](-DefinitionOperations.html) object.
     * @type {object}
     */
    this.definitions = new DefinitionOperations(this);
    /**
     * Provides an instance of the [ProfileOperations](-ProfileOperations.html)
     * object.
     * @type {object}
     */
    this.profiles = new ProfileOperations(this);
  }
  
  util.inherits(TrafficManagerManagementClient, Service);
  
  
  return TrafficManagerManagementClient;
})();
exports.TrafficManagerManagementClient = TrafficManagerManagementClient;

var DefinitionOperations = ( /** @lends DefinitionOperations */ function() {
  /**
   * @class
   * The Traffic Manager API includes operations for managing definitions for a
   * specified profile.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [TrafficManagerManagementClient] {@link
   * TrafficManagerManagementClient~TrafficManagerManagementClient}.
   * See [definitions] {@link
   * TrafficManagerManagementClient~TrafficManagerManagementClient#definitions}.
   * Initializes a new instance of the DefinitionOperations class.
   * @constructor
   * 
   * @param {TrafficManagerManagementClient} client Reference to the service
   * client.
   */
  function DefinitionOperations(client) {
    this.client = client;
  }
  
  /**
   * Creates a new definition for a specified profile.  (see
   * http://msdn.microsoft.com/en-us/library/hh758257.aspx for more
   * information)
   * 
   * @param {string} profileName The name of the profile to create a new
   * definition for.
   * 
   * @param {DefinitionCreateParameters} parameters Parameters supplied to the
   * Create Definition operation.
   * 
   * @param {DefinitionDnsOptions} parameters.dnsOptions
   * 
   * @param {number} parameters.dnsOptions.timeToLiveInSeconds Specifies the
   * DNS Time-to-Live (TTL) that informs the Local DNS resolvers how long to
   * cache DNS entries. The value is an integer from 30 through 999,999.
   * 
   * @param {array} parameters.monitors
   * 
   * @param {DefinitionPolicyCreateParameters} parameters.policy
   * 
   * @param {LoadBalancingMethod} parameters.policy.loadBalancingMethod
   * Specifies the load balancing method to use to distribute connections.
   * 
   * @param {array} parameters.policy.endpoints Encapsulates the list of
   * Windows Azure Traffic Manager endpoints. You can define up to 100
   * endpoints in the list. If the load balancing method is set to Failover,
   * traffic to the endpoints is load balanced in the sequential order in
   * which the endpoints are defined.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DefinitionOperations.prototype.create = function(profileName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (profileName === null || profileName === undefined) {
      return callback(new Error('profileName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.dnsOptions === null || parameters.dnsOptions === undefined) {
      return callback(new Error('parameters.dnsOptions cannot be null.'));
    }
    if (parameters.dnsOptions.timeToLiveInSeconds === null || parameters.dnsOptions.timeToLiveInSeconds === undefined) {
      return callback(new Error('parameters.dnsOptions.timeToLiveInSeconds cannot be null.'));
    }
    if (parameters.monitors === null || parameters.monitors === undefined) {
      return callback(new Error('parameters.monitors cannot be null.'));
    }
    if (parameters.monitors !== null && parameters.monitors !== undefined) {
      for (var loweredIndex1 = 0; loweredIndex1 < parameters.monitors.length; loweredIndex1 = loweredIndex1 + 1) {
        var monitorsParameterItem = parameters.monitors[loweredIndex1];
        if (monitorsParameterItem.httpOptions === null || monitorsParameterItem.httpOptions === undefined) {
          return callback(new Error('parameters.monitors.httpOptions cannot be null.'));
        }
        if (monitorsParameterItem.intervalInSeconds === null || monitorsParameterItem.intervalInSeconds === undefined) {
          return callback(new Error('parameters.monitors.intervalInSeconds cannot be null.'));
        }
        if (monitorsParameterItem.port === null || monitorsParameterItem.port === undefined) {
          return callback(new Error('parameters.monitors.port cannot be null.'));
        }
        if (monitorsParameterItem.protocol === null || monitorsParameterItem.protocol === undefined) {
          return callback(new Error('parameters.monitors.protocol cannot be null.'));
        }
        if (monitorsParameterItem.timeoutInSeconds === null || monitorsParameterItem.timeoutInSeconds === undefined) {
          return callback(new Error('parameters.monitors.timeoutInSeconds cannot be null.'));
        }
        if (monitorsParameterItem.toleratedNumberOfFailures === null || monitorsParameterItem.toleratedNumberOfFailures === undefined) {
          return callback(new Error('parameters.monitors.toleratedNumberOfFailures cannot be null.'));
        }
      }
    }
    if (parameters.policy === null || parameters.policy === undefined) {
      return callback(new Error('parameters.policy cannot be null.'));
    }
    if (parameters.policy.endpoints === null || parameters.policy.endpoints === undefined) {
      return callback(new Error('parameters.policy.endpoints cannot be null.'));
    }
    if (parameters.policy.endpoints !== null && parameters.policy.endpoints !== undefined) {
      for (var loweredIndex2 = 0; loweredIndex2 < parameters.policy.endpoints.length; loweredIndex2 = loweredIndex2 + 1) {
        var endpointsParameterItem = parameters.policy.endpoints[loweredIndex2];
        if (endpointsParameterItem.domainName === null || endpointsParameterItem.domainName === undefined) {
          return callback(new Error('parameters.policy.endpoints.domainName cannot be null.'));
        }
        if (endpointsParameterItem.status === null || endpointsParameterItem.status === undefined) {
          return callback(new Error('parameters.policy.endpoints.status cannot be null.'));
        }
      }
    }
    if (parameters.policy.loadBalancingMethod === null || parameters.policy.loadBalancingMethod === undefined) {
      return callback(new Error('parameters.policy.loadBalancingMethod 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/WATM/profiles/';
    url2 = url2 + encodeURIComponent(profileName);
    url2 = url2 + '/definitions';
    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'] = '2011-10-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var definitionElement = js2xml.createElement('Definition', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, definitionElement);
    
    var dnsOptionsElement = js2xml.createElement('DnsOptions', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(definitionElement, dnsOptionsElement);
    
    var timeToLiveInSecondsElement = js2xml.createElement('TimeToLiveInSeconds', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(timeToLiveInSecondsElement, parameters.dnsOptions.timeToLiveInSeconds.toString());
    js2xml.addChildElement(dnsOptionsElement, timeToLiveInSecondsElement);
    
    var monitorsSequenceElement = js2xml.createElement('Monitors', 'http://schemas.microsoft.com/windowsazure');
    for (var loweredIndex3 = 0; loweredIndex3 < parameters.monitors.length; loweredIndex3 = loweredIndex3 + 1) {
      var monitorsItem = parameters.monitors[loweredIndex3];
      var monitorElement = js2xml.createElement('Monitor', 'http://schemas.microsoft.com/windowsazure');
      js2xml.addChildElement(monitorsSequenceElement, monitorElement);
      
      var intervalInSecondsElement = js2xml.createElement('IntervalInSeconds', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(intervalInSecondsElement, monitorsItem.intervalInSeconds.toString());
      js2xml.addChildElement(monitorElement, intervalInSecondsElement);
      
      var timeoutInSecondsElement = js2xml.createElement('TimeoutInSeconds', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(timeoutInSecondsElement, monitorsItem.timeoutInSeconds.toString());
      js2xml.addChildElement(monitorElement, timeoutInSecondsElement);
      
      var toleratedNumberOfFailuresElement = js2xml.createElement('ToleratedNumberOfFailures', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(toleratedNumberOfFailuresElement, monitorsItem.toleratedNumberOfFailures.toString());
      js2xml.addChildElement(monitorElement, toleratedNumberOfFailuresElement);
      
      var protocolElement = js2xml.createElement('Protocol', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(protocolElement, monitorsItem.protocol !== null && monitorsItem.protocol !== undefined ? monitorsItem.protocol.toString() : 'Http');
      js2xml.addChildElement(monitorElement, protocolElement);
      
      var portElement = js2xml.createElement('Port', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(portElement, monitorsItem.port.toString());
      js2xml.addChildElement(monitorElement, portElement);
      
      var httpOptionsElement = js2xml.createElement('HttpOptions', 'http://schemas.microsoft.com/windowsazure');
      js2xml.addChildElement(monitorElement, httpOptionsElement);
      
      if (monitorsItem.httpOptions.verb !== null && monitorsItem.httpOptions.verb !== undefined) {
        var verbElement = js2xml.createElement('Verb', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(verbElement, 'GET');
        js2xml.addChildElement(httpOptionsElement, verbElement);
      }
      
      if (monitorsItem.httpOptions.relativePath !== null && monitorsItem.httpOptions.relativePath !== undefined) {
        var relativePathElement = js2xml.createElement('RelativePath', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(relativePathElement, monitorsItem.httpOptions.relativePath);
        js2xml.addChildElement(httpOptionsElement, relativePathElement);
      }
      
      if (monitorsItem.httpOptions.expectedStatusCode !== null && monitorsItem.httpOptions.expectedStatusCode !== undefined) {
        var expectedStatusCodeElement = js2xml.createElement('ExpectedStatusCode', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(expectedStatusCodeElement, '200');
        js2xml.addChildElement(httpOptionsElement, expectedStatusCodeElement);
      }
    }
    js2xml.addChildElement(definitionElement, monitorsSequenceElement);
    
    var policyElement = js2xml.createElement('Policy', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(definitionElement, policyElement);
    
    var loadBalancingMethodElement = js2xml.createElement('LoadBalancingMethod', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(loadBalancingMethodElement, parameters.policy.loadBalancingMethod !== null && parameters.policy.loadBalancingMethod !== undefined ? parameters.policy.loadBalancingMethod.toString() : 'Performance');
    js2xml.addChildElement(policyElement, loadBalancingMethodElement);
    
    var endpointsSequenceElement = js2xml.createElement('Endpoints', 'http://schemas.microsoft.com/windowsazure');
    for (var loweredIndex4 = 0; loweredIndex4 < parameters.policy.endpoints.length; loweredIndex4 = loweredIndex4 + 1) {
      var endpointsItem = parameters.policy.endpoints[loweredIndex4];
      var endpointElement = js2xml.createElement('Endpoint', 'http://schemas.microsoft.com/windowsazure');
      js2xml.addChildElement(endpointsSequenceElement, endpointElement);
      
      var domainNameElement = js2xml.createElement('DomainName', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(domainNameElement, endpointsItem.domainName);
      js2xml.addChildElement(endpointElement, domainNameElement);
      
      var statusElement = js2xml.createElement('Status', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(statusElement, endpointsItem.status !== null && endpointsItem.status !== undefined ? endpointsItem.status.toString() : 'Enabled');
      js2xml.addChildElement(endpointElement, statusElement);
      
      if (endpointsItem.type !== null && endpointsItem.type !== undefined) {
        var typeElement = js2xml.createElement('Type', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(typeElement, endpointsItem.type !== null && endpointsItem.type !== undefined ? endpointsItem.type.toString() : 'CloudService');
        js2xml.addChildElement(endpointElement, typeElement);
      }
      
      if (endpointsItem.location !== null && endpointsItem.location !== undefined) {
        var locationElement = js2xml.createElement('Location', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(locationElement, endpointsItem.location);
        js2xml.addChildElement(endpointElement, locationElement);
      }
      
      if (endpointsItem.weight !== null && endpointsItem.weight !== undefined) {
        var weightElement = js2xml.createElement('Weight', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(weightElement, endpointsItem.weight.toString());
        js2xml.addChildElement(endpointElement, weightElement);
      }
      
      if (endpointsItem.minChildEndpoints !== null && endpointsItem.minChildEndpoints !== undefined) {
        var minChildEndpointsElement = js2xml.createElement('MinChildEndpoints', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(minChildEndpointsElement, endpointsItem.minChildEndpoints.toString());
        js2xml.addChildElement(endpointElement, minChildEndpointsElement);
      }
    }
    js2xml.addChildElement(policyElement, endpointsSequenceElement);
    
    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);
    });
  };
  
  /**
   * Returns an existing profile definition.  (see
   * http://msdn.microsoft.com/en-us/library/hh758248.aspx for more
   * information)
   * 
   * @param {string} profileName The name of the profile to get definition from.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DefinitionOperations.prototype.get = function(profileName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (profileName === null || profileName === undefined) {
      return callback(new Error('profileName 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/WATM/profiles/';
    url2 = url2 + encodeURIComponent(profileName);
    url2 = url2 + '/definitions/1';
    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['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2011-10-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 definitionElement = js2xml.getElement(responseDoc, responseDoc, 'DEFINITION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (definitionElement !== null && definitionElement !== undefined) {
            var definitionInstance = { monitors: [] };
            result.definition = definitionInstance;
            
            var dnsOptionsElement = js2xml.getElement(responseDoc, definitionElement, 'DNSOPTIONS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (dnsOptionsElement !== null && dnsOptionsElement !== undefined) {
              var dnsOptionsInstance = {};
              definitionInstance.dnsOptions = dnsOptionsInstance;
              
              var timeToLiveInSecondsElement = js2xml.getElement(responseDoc, dnsOptionsElement, 'TIMETOLIVEINSECONDS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (timeToLiveInSecondsElement !== null && timeToLiveInSecondsElement !== undefined && timeToLiveInSecondsElement.length !== 0) {
                var timeToLiveInSecondsInstance = parseInt(timeToLiveInSecondsElement, 10);
                dnsOptionsInstance.timeToLiveInSeconds = timeToLiveInSecondsInstance;
              }
            }
            
            var statusElement = js2xml.getElement(responseDoc, definitionElement, 'STATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (statusElement !== null && statusElement !== undefined && statusElement.length !== 0) {
              var statusInstance = statusElement;
              definitionInstance.status = statusInstance;
            }
            
            var versionElement = js2xml.getElement(responseDoc, definitionElement, 'VERSION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (versionElement !== null && versionElement !== undefined && versionElement.length !== 0) {
              var versionInstance = parseInt(versionElement, 10);
              definitionInstance.version = versionInstance;
            }
            
            var monitorsSequenceElement = js2xml.getElement(responseDoc, definitionElement, 'MONITORS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (monitorsSequenceElement !== null && monitorsSequenceElement !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, monitorsSequenceElement, 'MONITOR', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
                var monitorsElement = js2xml.getElements(responseDoc, monitorsSequenceElement, 'MONITOR', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
                var monitorInstance = {};
                definitionInstance.monitors.push(monitorInstance);
                
                var intervalInSecondsElement = js2xml.getElement(responseDoc, monitorsElement, 'INTERVALINSECONDS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (intervalInSecondsElement !== null && intervalInSecondsElement !== undefined && intervalInSecondsElement.length !== 0) {
                  var intervalInSecondsInstance = parseInt(intervalInSecondsElement, 10);
                  monitorInstance.intervalInSeconds = intervalInSecondsInstance;
                }
                
                var timeoutInSecondsElement = js2xml.getElement(responseDoc, monitorsElement, 'TIMEOUTINSECONDS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (timeoutInSecondsElement !== null && timeoutInSecondsElement !== undefined && timeoutInSecondsElement.length !== 0) {
                  var timeoutInSecondsInstance = parseInt(timeoutInSecondsElement, 10);
                  monitorInstance.timeoutInSeconds = timeoutInSecondsInstance;
                }
                
                var toleratedNumberOfFailuresElement = js2xml.getElement(responseDoc, monitorsElement, 'TOLERATEDNUMBEROFFAILURES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (toleratedNumberOfFailuresElement !== null && toleratedNumberOfFailuresElement !== undefined && toleratedNumberOfFailuresElement.length !== 0) {
                  var toleratedNumberOfFailuresInstance = parseInt(toleratedNumberOfFailuresElement, 10);
                  monitorInstance.toleratedNumberOfFailures = toleratedNumberOfFailuresInstance;
                }
                
                var protocolElement = js2xml.getElement(responseDoc, monitorsElement, 'PROTOCOL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (protocolElement !== null && protocolElement !== undefined && protocolElement.length !== 0) {
                  var protocolInstance = protocolElement;
                  monitorInstance.protocol = protocolInstance;
                }
                
                var portElement = js2xml.getElement(responseDoc, monitorsElement, 'PORT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (portElement !== null && portElement !== undefined && portElement.length !== 0) {
                  var portInstance = parseInt(portElement, 10);
                  monitorInstance.port = portInstance;
                }
                
                var httpOptionsElement = js2xml.getElement(responseDoc, monitorsElement, 'HTTPOPTIONS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (httpOptionsElement !== null && httpOptionsElement !== undefined) {
                  var httpOptionsInstance = {};
                  monitorInstance.httpOptions = httpOptionsInstance;
                  
                  var verbElement = js2xml.getElement(responseDoc, httpOptionsElement, 'VERB', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (verbElement !== null && verbElement !== undefined) {
                    var verbInstance = verbElement;
                    httpOptionsInstance.verb = verbInstance;
                  }
                  
                  var relativePathElement = js2xml.getElement(responseDoc, httpOptionsElement, 'RELATIVEPATH', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (relativePathElement !== null && relativePathElement !== undefined) {
                    var relativePathInstance = relativePathElement;
                    httpOptionsInstance.relativePath = relativePathInstance;
                  }
                  
                  var expectedStatusCodeElement = js2xml.getElement(responseDoc, httpOptionsElement, 'EXPECTEDSTATUSCODE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (expectedStatusCodeElement !== null && expectedStatusCodeElement !== undefined && expectedStatusCodeElement.length !== 0) {
                    var expectedStatusCodeInstance = parseInt(expectedStatusCodeElement, 10);
                    httpOptionsInstance.expectedStatusCode = expectedStatusCodeInstance;
                  }
                }
              }
            }
            
            var policyElement = js2xml.getElement(responseDoc, definitionElement, 'POLICY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (policyElement !== null && policyElement !== undefined) {
              var policyInstance = { endpoints: [] };
              definitionInstance.policy = policyInstance;
              
              var loadBalancingMethodElement = js2xml.getElement(responseDoc, policyElement, 'LOADBALANCINGMETHOD', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (loadBalancingMethodElement !== null && loadBalancingMethodElement !== undefined && loadBalancingMethodElement.length !== 0) {
                var loadBalancingMethodInstance = loadBalancingMethodElement;
                policyInstance.loadBalancingMethod = loadBalancingMethodInstance;
              }
              
              var endpointsSequenceElement = js2xml.getElement(responseDoc, policyElement, 'ENDPOINTS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (endpointsSequenceElement !== null && endpointsSequenceElement !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < js2xml.getElements(responseDoc, endpointsSequenceElement, 'ENDPOINT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex2 = loweredIndex2 + 1) {
                  var endpointsElement = js2xml.getElements(responseDoc, endpointsSequenceElement, 'ENDPOINT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex2];
                  var endpointInstance = {};
                  policyInstance.endpoints.push(endpointInstance);
                  
                  var domainNameElement = js2xml.getElement(responseDoc, endpointsElement, 'DOMAINNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (domainNameElement !== null && domainNameElement !== undefined) {
                    var domainNameInstance = domainNameElement;
                    endpointInstance.domainName = domainNameInstance;
                  }
                  
                  var statusElement2 = js2xml.getElement(responseDoc, endpointsElement, 'STATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (statusElement2 !== null && statusElement2 !== undefined && statusElement2.length !== 0) {
                    var statusInstance2 = statusElement2;
                    endpointInstance.status = statusInstance2;
                  }
                  
                  var typeElement = js2xml.getElement(responseDoc, endpointsElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (typeElement !== null && typeElement !== undefined && typeElement.length !== 0) {
                    var typeInstance = typeElement;
                    endpointInstance.type = typeInstance;
                  }
                  
                  var locationElement = js2xml.getElement(responseDoc, endpointsElement, 'LOCATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (locationElement !== null && locationElement !== undefined) {
                    var locationInstance = locationElement;
                    endpointInstance.location = locationInstance;
                  }
                  
                  var monitorStatusElement = js2xml.getElement(responseDoc, endpointsElement, 'MONITORSTATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (monitorStatusElement !== null && monitorStatusElement !== undefined && monitorStatusElement.length !== 0) {
                    var monitorStatusInstance = monitorStatusElement;
                    endpointInstance.monitorStatus = monitorStatusInstance;
                  }
                  
                  var weightElement = js2xml.getElement(responseDoc, endpointsElement, 'WEIGHT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (weightElement !== null && weightElement !== undefined && weightElement.length !== 0) {
                    var weightInstance = parseInt(weightElement, 10);
                    endpointInstance.weight = weightInstance;
                  }
                  
                  var minChildEndpointsElement = js2xml.getElement(responseDoc, endpointsElement, 'MINCHILDENDPOINTS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (minChildEndpointsElement !== null && minChildEndpointsElement !== undefined && minChildEndpointsElement.length !== 0) {
                    var minChildEndpointsInstance = parseInt(minChildEndpointsElement, 10);
                    endpointInstance.minChildEndpoints = minChildEndpointsInstance;
                  }
                }
              }
              
              var monitorStatusElement2 = js2xml.getElement(responseDoc, policyElement, 'MONITORSTATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (monitorStatusElement2 !== null && monitorStatusElement2 !== undefined && monitorStatusElement2.length !== 0) {
                var monitorStatusInstance2 = monitorStatusElement2;
                policyInstance.monitorStatus = monitorStatusInstance2;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Returns all definitions of a profile  (see
   * http://msdn.microsoft.com/en-us/library/hh758252.aspx for more
   * information)
   * 
   * @param {string} profileName The name of the profile to return all
   * definitions
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DefinitionOperations.prototype.list = function(profileName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (profileName === null || profileName === undefined) {
      return callback(new Error('profileName 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/WATM/profiles/';
    url2 = url2 + encodeURIComponent(profileName);
    url2 = url2 + '/definitions';
    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['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2011-10-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 = { definitions: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var definitionsSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'DEFINITIONS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (definitionsSequenceElement !== null && definitionsSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, definitionsSequenceElement, 'DEFINITION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var definitionsElement = js2xml.getElements(responseDoc, definitionsSequenceElement, 'DEFINITION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var definitionInstance = { monitors: [] };
              result.definitions.push(definitionInstance);
              
              var dnsOptionsElement = js2xml.getElement(responseDoc, definitionsElement, 'DNSOPTIONS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (dnsOptionsElement !== null && dnsOptionsElement !== undefined) {
                var dnsOptionsInstance = {};
                definitionInstance.dnsOptions = dnsOptionsInstance;
                
                var timeToLiveInSecondsElement = js2xml.getElement(responseDoc, dnsOptionsElement, 'TIMETOLIVEINSECONDS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (timeToLiveInSecondsElement !== null && timeToLiveInSecondsElement !== undefined && timeToLiveInSecondsElement.length !== 0) {
                  var timeToLiveInSecondsInstance = parseInt(timeToLiveInSecondsElement, 10);
                  dnsOptionsInstance.timeToLiveInSeconds = timeToLiveInSecondsInstance;
                }
              }
              
              var statusElement = js2xml.getElement(responseDoc, definitionsElement, 'STATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (statusElement !== null && statusElement !== undefined && statusElement.length !== 0) {
                var statusInstance = statusElement;
                definitionInstance.status = statusInstance;
              }
              
              var versionElement = js2xml.getElement(responseDoc, definitionsElement, 'VERSION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (versionElement !== null && versionElement !== undefined && versionElement.length !== 0) {
                var versionInstance = parseInt(versionElement, 10);
                definitionInstance.version = versionInstance;
              }
              
              var monitorsSequenceElement = js2xml.getElement(responseDoc, definitionsElement, 'MONITORS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (monitorsSequenceElement !== null && monitorsSequenceElement !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < js2xml.getElements(responseDoc, monitorsSequenceElement, 'MONITOR', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex2 = loweredIndex2 + 1) {
                  var monitorsElement = js2xml.getElements(responseDoc, monitorsSequenceElement, 'MONITOR', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex2];
                  var monitorInstance = {};
                  definitionInstance.monitors.push(monitorInstance);
                  
                  var intervalInSecondsElement = js2xml.getElement(responseDoc, monitorsElement, 'INTERVALINSECONDS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (intervalInSecondsElement !== null && intervalInSecondsElement !== undefined && intervalInSecondsElement.length !== 0) {
                    var intervalInSecondsInstance = parseInt(intervalInSecondsElement, 10);
                    monitorInstance.intervalInSeconds = intervalInSecondsInstance;
                  }
                  
                  var timeoutInSecondsElement = js2xml.getElement(responseDoc, monitorsElement, 'TIMEOUTINSECONDS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (timeoutInSecondsElement !== null && timeoutInSecondsElement !== undefined && timeoutInSecondsElement.length !== 0) {
                    var timeoutInSecondsInstance = parseInt(timeoutInSecondsElement, 10);
                    monitorInstance.timeoutInSeconds = timeoutInSecondsInstance;
                  }
                  
                  var toleratedNumberOfFailuresElement = js2xml.getElement(responseDoc, monitorsElement, 'TOLERATEDNUMBEROFFAILURES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (toleratedNumberOfFailuresElement !== null && toleratedNumberOfFailuresElement !== undefined && toleratedNumberOfFailuresElement.length !== 0) {
                    var toleratedNumberOfFailuresInstance = parseInt(toleratedNumberOfFailuresElement, 10);
                    monitorInstance.toleratedNumberOfFailures = toleratedNumberOfFailuresInstance;
                  }
                  
                  var protocolElement = js2xml.getElement(responseDoc, monitorsElement, 'PROTOCOL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (protocolElement !== null && protocolElement !== undefined && protocolElement.length !== 0) {
                    var protocolInstance = protocolElement;
                    monitorInstance.protocol = protocolInstance;
                  }
                  
                  var portElement = js2xml.getElement(responseDoc, monitorsElement, 'PORT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (portElement !== null && portElement !== undefined && portElement.length !== 0) {
                    var portInstance = parseInt(portElement, 10);
                    monitorInstance.port = portInstance;
                  }
                  
                  var httpOptionsElement = js2xml.getElement(responseDoc, monitorsElement, 'HTTPOPTIONS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (httpOptionsElement !== null && httpOptionsElement !== undefined) {
                    var httpOptionsInstance = {};
                    monitorInstance.httpOptions = httpOptionsInstance;
                    
                    var verbElement = js2xml.getElement(responseDoc, httpOptionsElement, 'VERB', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (verbElement !== null && verbElement !== undefined) {
                      var verbInstance = verbElement;
                      httpOptionsInstance.verb = verbInstance;
                    }
                    
                    var relativePathElement = js2xml.getElement(responseDoc, httpOptionsElement, 'RELATIVEPATH', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (relativePathElement !== null && relativePathElement !== undefined) {
                      var relativePathInstance = relativePathElement;
                      httpOptionsInstance.relativePath = relativePathInstance;
                    }
                    
                    var expectedStatusCodeElement = js2xml.getElement(responseDoc, httpOptionsElement, 'EXPECTEDSTATUSCODE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (expectedStatusCodeElement !== null && expectedStatusCodeElement !== undefined && expectedStatusCodeElement.length !== 0) {
                      var expectedStatusCodeInstance = parseInt(expectedStatusCodeElement, 10);
                      httpOptionsInstance.expectedStatusCode = expectedStatusCodeInstance;
                    }
                  }
                }
              }
              
              var policyElement = js2xml.getElement(responseDoc, definitionsElement, 'POLICY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (policyElement !== null && policyElement !== undefined) {
                var policyInstance = { endpoints: [] };
                definitionInstance.policy = policyInstance;
                
                var loadBalancingMethodElement = js2xml.getElement(responseDoc, policyElement, 'LOADBALANCINGMETHOD', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (loadBalancingMethodElement !== null && loadBalancingMethodElement !== undefined && loadBalancingMethodElement.length !== 0) {
                  var loadBalancingMethodInstance = loadBalancingMethodElement;
                  policyInstance.loadBalancingMethod = loadBalancingMethodInstance;
                }
                
                var endpointsSequenceElement = js2xml.getElement(responseDoc, policyElement, 'ENDPOINTS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (endpointsSequenceElement !== null && endpointsSequenceElement !== undefined) {
                  for (var loweredIndex3 = 0; loweredIndex3 < js2xml.getElements(responseDoc, endpointsSequenceElement, 'ENDPOINT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex3 = loweredIndex3 + 1) {
                    var endpointsElement = js2xml.getElements(responseDoc, endpointsSequenceElement, 'ENDPOINT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex3];
                    var endpointInstance = {};
                    policyInstance.endpoints.push(endpointInstance);
                    
                    var domainNameElement = js2xml.getElement(responseDoc, endpointsElement, 'DOMAINNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (domainNameElement !== null && domainNameElement !== undefined) {
                      var domainNameInstance = domainNameElement;
                      endpointInstance.domainName = domainNameInstance;
                    }
                    
                    var statusElement2 = js2xml.getElement(responseDoc, endpointsElement, 'STATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (statusElement2 !== null && statusElement2 !== undefined && statusElement2.length !== 0) {
                      var statusInstance2 = statusElement2;
                      endpointInstance.status = statusInstance2;
                    }
                    
                    var typeElement = js2xml.getElement(responseDoc, endpointsElement, 'TYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (typeElement !== null && typeElement !== undefined && typeElement.length !== 0) {
                      var typeInstance = typeElement;
                      endpointInstance.type = typeInstance;
                    }
                    
                    var locationElement = js2xml.getElement(responseDoc, endpointsElement, 'LOCATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (locationElement !== null && locationElement !== undefined) {
                      var locationInstance = locationElement;
                      endpointInstance.location = locationInstance;
                    }
                    
                    var monitorStatusElement = js2xml.getElement(responseDoc, endpointsElement, 'MONITORSTATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (monitorStatusElement !== null && monitorStatusElement !== undefined && monitorStatusElement.length !== 0) {
                      var monitorStatusInstance = monitorStatusElement;
                      endpointInstance.monitorStatus = monitorStatusInstance;
                    }
                    
                    var weightElement = js2xml.getElement(responseDoc, endpointsElement, 'WEIGHT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (weightElement !== null && weightElement !== undefined && weightElement.length !== 0) {
                      var weightInstance = parseInt(weightElement, 10);
                      endpointInstance.weight = weightInstance;
                    }
                    
                    var minChildEndpointsElement = js2xml.getElement(responseDoc, endpointsElement, 'MINCHILDENDPOINTS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                    if (minChildEndpointsElement !== null && minChildEndpointsElement !== undefined && minChildEndpointsElement.length !== 0) {
                      var minChildEndpointsInstance = parseInt(minChildEndpointsElement, 10);
                      endpointInstance.minChildEndpoints = minChildEndpointsInstance;
                    }
                  }
                }
                
                var monitorStatusElement2 = js2xml.getElement(responseDoc, policyElement, 'MONITORSTATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (monitorStatusElement2 !== null && monitorStatusElement2 !== undefined && monitorStatusElement2.length !== 0) {
                  var monitorStatusInstance2 = monitorStatusElement2;
                  policyInstance.monitorStatus = monitorStatusInstance2;
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return DefinitionOperations;
})();

var ProfileOperations = ( /** @lends ProfileOperations */ function() {
  /**
   * @class
   * The Traffic Manager API includes operations for managing Traffic Manager
   * profiles.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [TrafficManagerManagementClient] {@link
   * TrafficManagerManagementClient~TrafficManagerManagementClient}.
   * See [profiles] {@link
   * TrafficManagerManagementClient~TrafficManagerManagementClient#profiles}.
   * Initializes a new instance of the ProfileOperations class.
   * @constructor
   * 
   * @param {TrafficManagerManagementClient} client Reference to the service
   * client.
   */
  function ProfileOperations(client) {
    this.client = client;
  }
  
  /**
   * The DNS name that you want to use. You must include .trafficmanager.net in
   * the name.  (see http://msdn.microsoft.com/en-us/library/dn510368.aspx for
   * more information)
   * 
   * @param {string} dnsName DNS name that you want to use
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProfileOperations.prototype.checkDnsPrefixAvailability = function(dnsName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (dnsName === null || dnsName === undefined) {
      return callback(new Error('dnsName 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/WATM/operations/isavailable/';
    url2 = url2 + encodeURIComponent(dnsName);
    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'] = '2011-10-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 availabilityResponseElement = js2xml.getElement(responseDoc, responseDoc, 'AVAILABILITYRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (availabilityResponseElement !== null && availabilityResponseElement !== undefined) {
            var resultElement = js2xml.getElement(responseDoc, availabilityResponseElement, 'RESULT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (resultElement !== null && resultElement !== undefined && resultElement.length !== 0) {
              var resultInstance = resultElement === 'true';
              result.result = resultInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Creates a new profile for a domain name, owned by the specified
   * subscription.  (see http://msdn.microsoft.com/en-us/library/hh758254.aspx
   * for more information)
   * 
   * @param {string} name The name of the profile.
   * 
   * @param {string} domainName The name of the domain that the profile is
   * being created for.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProfileOperations.prototype.create = function(name, domainName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (name === null || name === undefined) {
      return callback(new Error('name cannot be null.'));
    }
    if (name.length > 256) {
      return callback(new Error('name is outside the valid range.'));
    }
    if (domainName === null || domainName === undefined) {
      return callback(new Error('domainName cannot be null.'));
    }
    if (domainName.length > 253) {
      return callback(new Error('domainName is outside the valid range.'));
    }
    
    // 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/WATM/profiles';
    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'] = '2011-10-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var profileElement = js2xml.createElement('Profile', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, profileElement);
    
    var domainNameElement = js2xml.createElement('DomainName', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(domainNameElement, domainName);
    js2xml.addChildElement(profileElement, domainNameElement);
    
    var nameElement = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(nameElement, name);
    js2xml.addChildElement(profileElement, nameElement);
    
    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);
    });
  };
  
  /**
   * Deletes a profile and all of its definitions. This operation cannot be
   * reverted.  (see http://msdn.microsoft.com/en-us/library/hh758256.aspx for
   * more information)
   * 
   * @param {string} profileName The name of the profile.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProfileOperations.prototype.deleteMethod = function(profileName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (profileName === null || profileName === undefined) {
      return callback(new Error('profileName 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/WATM/profiles/';
    url2 = url2 + encodeURIComponent(profileName);
    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'] = '2011-10-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 profile details, including all definition versions and their
   * statuses.  (see http://msdn.microsoft.com/en-us/library/hh758248.aspx for
   * more information)
   * 
   * @param {string} profileName The name of the profile.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProfileOperations.prototype.get = function(profileName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (profileName === null || profileName === undefined) {
      return callback(new Error('profileName 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/WATM/profiles/';
    url2 = url2 + encodeURIComponent(profileName);
    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['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2011-10-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 profileElement = js2xml.getElement(responseDoc, responseDoc, 'PROFILE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (profileElement !== null && profileElement !== undefined) {
            var profileInstance = { definitions: [] };
            result.profile = profileInstance;
            
            var domainNameElement = js2xml.getElement(responseDoc, profileElement, 'DOMAINNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (domainNameElement !== null && domainNameElement !== undefined) {
              var domainNameInstance = domainNameElement;
              profileInstance.domainName = domainNameInstance;
            }
            
            var nameElement = js2xml.getElement(responseDoc, profileElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              profileInstance.name = nameInstance;
            }
            
            var statusElement = js2xml.getElement(responseDoc, profileElement, 'STATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (statusElement !== null && statusElement !== undefined && statusElement.length !== 0) {
              var statusInstance = statusElement;
              profileInstance.status = statusInstance;
            }
            
            var statusDetailsElement = js2xml.getElement(responseDoc, profileElement, 'STATUSDETAILS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (statusDetailsElement !== null && statusDetailsElement !== undefined) {
              var statusDetailsInstance = {};
              profileInstance.statusDetails = statusDetailsInstance;
              
              var enabledVersionElement = js2xml.getElement(responseDoc, statusDetailsElement, 'ENABLEDVERSION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (enabledVersionElement !== null && enabledVersionElement !== undefined && enabledVersionElement.length !== 0) {
                var enabledVersionInstance = parseInt(enabledVersionElement, 10);
                statusDetailsInstance.enabledDefinitionVersion = enabledVersionInstance;
              }
            }
            
            var definitionsSequenceElement = js2xml.getElement(responseDoc, profileElement, 'DEFINITIONS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (definitionsSequenceElement !== null && definitionsSequenceElement !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, definitionsSequenceElement, 'DEFINITION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
                var definitionsElement = js2xml.getElements(responseDoc, definitionsSequenceElement, 'DEFINITION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
                var definitionInstance = {};
                profileInstance.definitions.push(definitionInstance);
                
                var statusElement2 = js2xml.getElement(responseDoc, definitionsElement, 'STATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (statusElement2 !== null && statusElement2 !== undefined && statusElement2.length !== 0) {
                  var statusInstance2 = statusElement2;
                  definitionInstance.status = statusInstance2;
                }
                
                var versionElement = js2xml.getElement(responseDoc, definitionsElement, 'VERSION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (versionElement !== null && versionElement !== undefined && versionElement.length !== 0) {
                  var versionInstance = parseInt(versionElement, 10);
                  definitionInstance.version = versionInstance;
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Returns all profiles owned by a subscription.  (see
   * http://msdn.microsoft.com/en-us/library/hh758249.aspx for more
   * information)
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProfileOperations.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/WATM/profiles';
    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['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2011-10-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 = { profiles: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var profilesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'PROFILES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (profilesSequenceElement !== null && profilesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, profilesSequenceElement, 'PROFILE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var profilesElement = js2xml.getElements(responseDoc, profilesSequenceElement, 'PROFILE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var profileInstance = { definitions: [] };
              result.profiles.push(profileInstance);
              
              var domainNameElement = js2xml.getElement(responseDoc, profilesElement, 'DOMAINNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (domainNameElement !== null && domainNameElement !== undefined) {
                var domainNameInstance = domainNameElement;
                profileInstance.domainName = domainNameInstance;
              }
              
              var nameElement = js2xml.getElement(responseDoc, profilesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                profileInstance.name = nameInstance;
              }
              
              var statusElement = js2xml.getElement(responseDoc, profilesElement, 'STATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (statusElement !== null && statusElement !== undefined && statusElement.length !== 0) {
                var statusInstance = statusElement;
                profileInstance.status = statusInstance;
              }
              
              var statusDetailsElement = js2xml.getElement(responseDoc, profilesElement, 'STATUSDETAILS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (statusDetailsElement !== null && statusDetailsElement !== undefined) {
                var statusDetailsInstance = {};
                profileInstance.statusDetails = statusDetailsInstance;
                
                var enabledVersionElement = js2xml.getElement(responseDoc, statusDetailsElement, 'ENABLEDVERSION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (enabledVersionElement !== null && enabledVersionElement !== undefined && enabledVersionElement.length !== 0) {
                  var enabledVersionInstance = parseInt(enabledVersionElement, 10);
                  statusDetailsInstance.enabledDefinitionVersion = enabledVersionInstance;
                }
              }
              
              var definitionsSequenceElement = js2xml.getElement(responseDoc, profilesElement, 'DEFINITIONS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (definitionsSequenceElement !== null && definitionsSequenceElement !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < js2xml.getElements(responseDoc, definitionsSequenceElement, 'DEFINITION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex2 = loweredIndex2 + 1) {
                  var definitionsElement = js2xml.getElements(responseDoc, definitionsSequenceElement, 'DEFINITION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex2];
                  var definitionInstance = {};
                  profileInstance.definitions.push(definitionInstance);
                  
                  var statusElement2 = js2xml.getElement(responseDoc, definitionsElement, 'STATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (statusElement2 !== null && statusElement2 !== undefined && statusElement2.length !== 0) {
                    var statusInstance2 = statusElement2;
                    definitionInstance.status = statusInstance2;
                  }
                  
                  var versionElement = js2xml.getElement(responseDoc, definitionsElement, 'VERSION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (versionElement !== null && versionElement !== undefined && versionElement.length !== 0) {
                    var versionInstance = parseInt(versionElement, 10);
                    definitionInstance.version = versionInstance;
                  }
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Enables or disables a profile.  (see
   * http://msdn.microsoft.com/en-us/library/hh758250.aspx for more
   * information)
   * 
   * @param {string} profileName The name of the profile.
   * 
   * @param {ProfileDefinitionStatus} profileStatus Specifies whether the
   * profile should be enabled or disabled.
   * 
   * @param {Number} definitionVersionNumber Version of the definition
   * associated with the profile
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProfileOperations.prototype.update = function(profileName, profileStatus, definitionVersionNumber, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (profileName === null || profileName === undefined) {
      return callback(new Error('profileName cannot be null.'));
    }
    if (profileStatus === null || profileStatus === undefined) {
      return callback(new Error('profileStatus cannot be null.'));
    }
    if (definitionVersionNumber === null || definitionVersionNumber === undefined) {
      return callback(new Error('definitionVersionNumber 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/WATM/profiles/';
    url2 = url2 + encodeURIComponent(profileName);
    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'] = '2011-10-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var profileElement = js2xml.createElement('Profile', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, profileElement);
    
    var statusElement = js2xml.createElement('Status', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(statusElement, profileStatus !== null && profileStatus !== undefined ? profileStatus.toString() : 'Enabled');
    js2xml.addChildElement(profileElement, statusElement);
    
    var statusDetailsElement = js2xml.createElement('StatusDetails', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(profileElement, statusDetailsElement);
    
    var enabledVersionElement = js2xml.createElement('EnabledVersion', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(enabledVersionElement, definitionVersionNumber.toString());
    js2xml.addChildElement(statusDetailsElement, enabledVersionElement);
    
    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);
    });
  };
  
  return ProfileOperations;
})();
