/* 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 ManagementClient = ( /** @lends ManagementClient */ function() {
  /**
   * @class
   * The Service Management API provides programmatic access to much of the
   * functionality available through the Management Portal. The Service
   * Management API is a REST API. All API operations are performed over SSL
   * and are mutually authenticated using X.509 v3 certificates.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/ee460799.aspx for
   * more information)
   * Initializes a new instance of the ManagementClient 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 ManagementClient(credentials, baseUri, filters) {
    if (credentials === null || credentials === undefined) {
      throw new Error('credentials cannot be null.');
    }
    
    ManagementClient['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 = '2014-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
     * [AffinityGroupOperations](-AffinityGroupOperations.html) object.
     * @type {object}
     */
    this.affinityGroups = new AffinityGroupOperations(this);
    /**
     * Provides an instance of the
     * [LocationOperations](-LocationOperations.html) object.
     * @type {object}
     */
    this.locations = new LocationOperations(this);
    /**
     * Provides an instance of the
     * [ManagementCertificateOperations](-ManagementCertificateOperations.html)
     * object.
     * @type {object}
     */
    this.managementCertificates = new ManagementCertificateOperations(this);
    /**
     * Provides an instance of the
     * [RoleSizeOperations](-RoleSizeOperations.html) object.
     * @type {object}
     */
    this.roleSizes = new RoleSizeOperations(this);
    /**
     * Provides an instance of the
     * [SubscriptionOperations](-SubscriptionOperations.html) object.
     * @type {object}
     */
    this.subscriptions = new SubscriptionOperations(this);
  }
  
  util.inherits(ManagementClient, Service);
  
  /**
   * The Get Operation Status operation returns the status of the specified
   * operation. After calling an asynchronous operation, you can call Get
   * Operation Status to determine whether the operation has succeeded,
   * failed, or is still in progress.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/ee460783.aspx for
   * more information)
   * 
   * @param {string} requestId The request ID for the request you wish to
   * track. The request ID is returned in the x-ms-request-id response header
   * for every request.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ManagementClient.prototype.getOperationStatus = function(requestId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (requestId === null || requestId === undefined) {
      return callback(new Error('requestId cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    if (this.credentials.subscriptionId !== null && this.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.credentials.subscriptionId);
    }
    url2 = url2 + '/operations/';
    url2 = url2 + encodeURIComponent(requestId);
    var baseUrl = this.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'] = '2014-10-01';
    
    // Send Request
    return this.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 operationElement = js2xml.getElement(responseDoc, responseDoc, 'OPERATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (operationElement !== null && operationElement !== undefined) {
            var idElement = js2xml.getElement(responseDoc, operationElement, 'ID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (idElement !== null && idElement !== undefined) {
              var idInstance = idElement;
              result.id = idInstance;
            }
            
            var statusElement = js2xml.getElement(responseDoc, operationElement, 'STATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (statusElement !== null && statusElement !== undefined && statusElement.length !== 0) {
              var statusInstance = statusElement;
              result.status = statusInstance;
            }
            
            var httpStatusCodeElement = js2xml.getElement(responseDoc, operationElement, 'HTTPSTATUSCODE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (httpStatusCodeElement !== null && httpStatusCodeElement !== undefined && httpStatusCodeElement.length !== 0) {
              var httpStatusCodeInstance = httpStatusCodeElement;
              result.httpStatusCode = httpStatusCodeInstance;
            }
            
            var errorElement = js2xml.getElement(responseDoc, operationElement, 'ERROR', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (errorElement !== null && errorElement !== undefined) {
              var errorInstance = {};
              result.error = errorInstance;
              
              var codeElement = js2xml.getElement(responseDoc, errorElement, 'CODE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (codeElement !== null && codeElement !== undefined) {
                var codeInstance = codeElement;
                errorInstance.code = codeInstance;
              }
              
              var messageElement = js2xml.getElement(responseDoc, errorElement, 'MESSAGE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (messageElement !== null && messageElement !== undefined) {
                var messageInstance = messageElement;
                errorInstance.message = messageInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return ManagementClient;
})();
exports.ManagementClient = ManagementClient;

var AffinityGroupOperations = ( /** @lends AffinityGroupOperations */ function() {
  /**
   * @class
   * Operations for managing affinity groups in your subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/ee460798.aspx for
   * more information)
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [ManagementClient] {@link
   * ManagementClient~ManagementClient}.
   * See [affinityGroups] {@link
   * ManagementClient~ManagementClient#affinityGroups}.
   * Initializes a new instance of the AffinityGroupOperations class.
   * @constructor
   * 
   * @param {ManagementClient} client Reference to the service client.
   */
  function AffinityGroupOperations(client) {
    this.client = client;
  }
  
  /**
   * The Create Affinity Group operation creates a new affinity group for the
   * specified subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/gg715317.aspx for
   * more information)
   * 
   * @param {AffinityGroupCreateParameters} parameters Parameters supplied to
   * the Create Affinity Group operation.
   * 
   * @param {string} parameters.name A name for the affinity group that is
   * unique to the subscription.
   * 
   * @param {string} parameters.label A base-64-encoded name for the affinity
   * group. The name can be up to 100 characters in length. Its value defaults
   * to the Name of the affinity group if not provided.
   * 
   * @param {string} [parameters.description] A description for the affinity
   * group. The description can be up to 1024 characters in length.
   * 
   * @param {string} parameters.location The data center location where the
   * affinity group will be created. To list available locations, see the List
   * Locations operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  AffinityGroupOperations.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.description !== null && parameters.description !== undefined && parameters.description.length > 1024) {
      return callback(new Error('parameters.description is outside the valid range.'));
    }
    if (parameters.label === null || parameters.label === undefined) {
      return callback(new Error('parameters.label cannot be null.'));
    }
    if (parameters.label.length > 100) {
      return callback(new Error('parameters.label is outside the valid range.'));
    }
    if (parameters.location === null || parameters.location === undefined) {
      return callback(new Error('parameters.location 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 + '/affinitygroups';
    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'] = '2014-10-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var createAffinityGroupElement = js2xml.createElement('CreateAffinityGroup', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, createAffinityGroupElement);
    
    var nameElement = js2xml.createElement('Name', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(nameElement, parameters.name);
    js2xml.addChildElement(createAffinityGroupElement, nameElement);
    
    var labelElement = js2xml.createElement('Label', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(labelElement, new Buffer(parameters.label).toString('base64'));
    js2xml.addChildElement(createAffinityGroupElement, labelElement);
    
    if (parameters.description !== null && parameters.description !== undefined) {
      var descriptionElement = js2xml.createElement('Description', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(descriptionElement, parameters.description);
      js2xml.addChildElement(createAffinityGroupElement, descriptionElement);
    }
    
    var locationElement = js2xml.createElement('Location', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(locationElement, parameters.location);
    js2xml.addChildElement(createAffinityGroupElement, locationElement);
    
    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
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Delete Affinity Group operation deletes an affinity group in the
   * specified subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/gg715314.aspx for
   * more information)
   * 
   * @param {string} affinityGroupName The name of the affinity group.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  AffinityGroupOperations.prototype.deleteMethod = function(affinityGroupName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (affinityGroupName === null || affinityGroupName === undefined) {
      return callback(new Error('affinityGroupName 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 + '/affinitygroups/';
    url2 = url2 + encodeURIComponent(affinityGroupName);
    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'] = '2014-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);
    });
  };
  
  /**
   * The Get Affinity Group Properties operation returns the system properties
   * associated with the specified affinity group.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/ee460789.aspx for
   * more information)
   * 
   * @param {string} affinityGroupName The name of the desired affinity group
   * as returned by the name element of the List Affinity Groups operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  AffinityGroupOperations.prototype.get = function(affinityGroupName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (affinityGroupName === null || affinityGroupName === undefined) {
      return callback(new Error('affinityGroupName 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 + '/affinitygroups/';
    url2 = url2 + encodeURIComponent(affinityGroupName);
    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'] = '2014-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 = { capabilities: [], hostedServices: [], storageServices: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var affinityGroupElement = js2xml.getElement(responseDoc, responseDoc, 'AFFINITYGROUP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (affinityGroupElement !== null && affinityGroupElement !== undefined) {
            var nameElement = js2xml.getElement(responseDoc, affinityGroupElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              result.name = nameInstance;
            }
            
            var labelElement = js2xml.getElement(responseDoc, affinityGroupElement, 'LABEL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (labelElement !== null && labelElement !== undefined) {
              var labelInstance = new Buffer(labelElement, 'base64').toString('utf8');
              result.label = labelInstance;
            }
            
            var descriptionElement = js2xml.getElement(responseDoc, affinityGroupElement, 'DESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (descriptionElement !== null && descriptionElement !== undefined) {
              var descriptionInstance = descriptionElement;
              result.description = descriptionInstance;
            }
            
            var locationElement = js2xml.getElement(responseDoc, affinityGroupElement, 'LOCATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (locationElement !== null && locationElement !== undefined) {
              var locationInstance = locationElement;
              result.location = locationInstance;
            }
            
            var hostedServicesSequenceElement = js2xml.getElement(responseDoc, affinityGroupElement, 'HOSTEDSERVICES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (hostedServicesSequenceElement !== null && hostedServicesSequenceElement !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, hostedServicesSequenceElement, 'HOSTEDSERVICE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
                var hostedServicesElement = js2xml.getElements(responseDoc, hostedServicesSequenceElement, 'HOSTEDSERVICE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
                var hostedServiceInstance = {};
                result.hostedServices.push(hostedServiceInstance);
                
                var urlElement = js2xml.getElement(responseDoc, hostedServicesElement, 'URL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (urlElement !== null && urlElement !== undefined) {
                  var urlInstance = urlElement;
                  hostedServiceInstance.uri = urlInstance;
                }
                
                var serviceNameElement = js2xml.getElement(responseDoc, hostedServicesElement, 'SERVICENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (serviceNameElement !== null && serviceNameElement !== undefined) {
                  var serviceNameInstance = serviceNameElement;
                  hostedServiceInstance.serviceName = serviceNameInstance;
                }
              }
            }
            
            var storageServicesSequenceElement = js2xml.getElement(responseDoc, affinityGroupElement, 'STORAGESERVICES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (storageServicesSequenceElement !== null && storageServicesSequenceElement !== undefined) {
              for (var loweredIndex2 = 0; loweredIndex2 < js2xml.getElements(responseDoc, storageServicesSequenceElement, 'STORAGESERVICE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex2 = loweredIndex2 + 1) {
                var storageServicesElement = js2xml.getElements(responseDoc, storageServicesSequenceElement, 'STORAGESERVICE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex2];
                var storageServiceInstance = {};
                result.storageServices.push(storageServiceInstance);
                
                var urlElement2 = js2xml.getElement(responseDoc, storageServicesElement, 'URL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (urlElement2 !== null && urlElement2 !== undefined) {
                  var urlInstance2 = urlElement2;
                  storageServiceInstance.uri = urlInstance2;
                }
                
                var serviceNameElement2 = js2xml.getElement(responseDoc, storageServicesElement, 'SERVICENAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (serviceNameElement2 !== null && serviceNameElement2 !== undefined) {
                  var serviceNameInstance2 = serviceNameElement2;
                  storageServiceInstance.serviceName = serviceNameInstance2;
                }
              }
            }
            
            var capabilitiesSequenceElement = js2xml.getElement(responseDoc, affinityGroupElement, 'CAPABILITIES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (capabilitiesSequenceElement !== null && capabilitiesSequenceElement !== undefined) {
              for (var loweredIndex3 = 0; loweredIndex3 < js2xml.getElements(responseDoc, capabilitiesSequenceElement, 'CAPABILITY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex3 = loweredIndex3 + 1) {
                var capabilitiesElement = js2xml.getElements(responseDoc, capabilitiesSequenceElement, 'CAPABILITY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex3];
                result.capabilities.push(capabilitiesElement);
              }
            }
            
            var createdTimeElement = js2xml.getElement(responseDoc, affinityGroupElement, 'CREATEDTIME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (createdTimeElement !== null && createdTimeElement !== undefined && createdTimeElement.length !== 0) {
              var createdTimeInstance = new Date(createdTimeElement);
              result.createdTime = createdTimeInstance;
            }
            
            var computeCapabilitiesElement = js2xml.getElement(responseDoc, affinityGroupElement, 'COMPUTECAPABILITIES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (computeCapabilitiesElement !== null && computeCapabilitiesElement !== undefined) {
              var computeCapabilitiesInstance = { virtualMachinesRoleSizes: [], webWorkerRoleSizes: [] };
              result.computeCapabilities = computeCapabilitiesInstance;
              
              var virtualMachinesRoleSizesSequenceElement = js2xml.getElement(responseDoc, computeCapabilitiesElement, 'VIRTUALMACHINESROLESIZES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (virtualMachinesRoleSizesSequenceElement !== null && virtualMachinesRoleSizesSequenceElement !== undefined) {
                for (var loweredIndex4 = 0; loweredIndex4 < js2xml.getElements(responseDoc, virtualMachinesRoleSizesSequenceElement, 'ROLESIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex4 = loweredIndex4 + 1) {
                  var virtualMachinesRoleSizesElement = js2xml.getElements(responseDoc, virtualMachinesRoleSizesSequenceElement, 'ROLESIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex4];
                  computeCapabilitiesInstance.virtualMachinesRoleSizes.push(virtualMachinesRoleSizesElement);
                }
              }
              
              var webWorkerRoleSizesSequenceElement = js2xml.getElement(responseDoc, computeCapabilitiesElement, 'WEBWORKERROLESIZES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (webWorkerRoleSizesSequenceElement !== null && webWorkerRoleSizesSequenceElement !== undefined) {
                for (var loweredIndex5 = 0; loweredIndex5 < js2xml.getElements(responseDoc, webWorkerRoleSizesSequenceElement, 'ROLESIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex5 = loweredIndex5 + 1) {
                  var webWorkerRoleSizesElement = js2xml.getElements(responseDoc, webWorkerRoleSizesSequenceElement, 'ROLESIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex5];
                  computeCapabilitiesInstance.webWorkerRoleSizes.push(webWorkerRoleSizesElement);
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The List Affinity Groups operation lists the affinity groups associated
   * with the specified subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/ee460797.aspx for
   * more information)
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  AffinityGroupOperations.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 + '/affinitygroups';
    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'] = '2014-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 = { affinityGroups: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var affinityGroupsSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'AFFINITYGROUPS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (affinityGroupsSequenceElement !== null && affinityGroupsSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, affinityGroupsSequenceElement, 'AFFINITYGROUP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var affinityGroupsElement = js2xml.getElements(responseDoc, affinityGroupsSequenceElement, 'AFFINITYGROUP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var affinityGroupInstance = { capabilities: [] };
              result.affinityGroups.push(affinityGroupInstance);
              
              var nameElement = js2xml.getElement(responseDoc, affinityGroupsElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                affinityGroupInstance.name = nameInstance;
              }
              
              var labelElement = js2xml.getElement(responseDoc, affinityGroupsElement, 'LABEL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (labelElement !== null && labelElement !== undefined) {
                var labelInstance = new Buffer(labelElement, 'base64').toString('utf8');
                affinityGroupInstance.label = labelInstance;
              }
              
              var descriptionElement = js2xml.getElement(responseDoc, affinityGroupsElement, 'DESCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (descriptionElement !== null && descriptionElement !== undefined) {
                var descriptionInstance = descriptionElement;
                affinityGroupInstance.description = descriptionInstance;
              }
              
              var locationElement = js2xml.getElement(responseDoc, affinityGroupsElement, 'LOCATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (locationElement !== null && locationElement !== undefined) {
                var locationInstance = locationElement;
                affinityGroupInstance.location = locationInstance;
              }
              
              var capabilitiesSequenceElement = js2xml.getElement(responseDoc, affinityGroupsElement, 'CAPABILITIES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (capabilitiesSequenceElement !== null && capabilitiesSequenceElement !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < js2xml.getElements(responseDoc, capabilitiesSequenceElement, 'CAPABILITY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex2 = loweredIndex2 + 1) {
                  var capabilitiesElement = js2xml.getElements(responseDoc, capabilitiesSequenceElement, 'CAPABILITY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex2];
                  affinityGroupInstance.capabilities.push(capabilitiesElement);
                }
              }
              
              var createdTimeElement = js2xml.getElement(responseDoc, affinityGroupsElement, 'CREATEDTIME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (createdTimeElement !== null && createdTimeElement !== undefined && createdTimeElement.length !== 0) {
                var createdTimeInstance = new Date(createdTimeElement);
                affinityGroupInstance.createdTime = createdTimeInstance;
              }
              
              var computeCapabilitiesElement = js2xml.getElement(responseDoc, affinityGroupsElement, 'COMPUTECAPABILITIES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (computeCapabilitiesElement !== null && computeCapabilitiesElement !== undefined) {
                var computeCapabilitiesInstance = { virtualMachinesRoleSizes: [], webWorkerRoleSizes: [] };
                affinityGroupInstance.computeCapabilities = computeCapabilitiesInstance;
                
                var virtualMachinesRoleSizesSequenceElement = js2xml.getElement(responseDoc, computeCapabilitiesElement, 'VIRTUALMACHINESROLESIZES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (virtualMachinesRoleSizesSequenceElement !== null && virtualMachinesRoleSizesSequenceElement !== undefined) {
                  for (var loweredIndex3 = 0; loweredIndex3 < js2xml.getElements(responseDoc, virtualMachinesRoleSizesSequenceElement, 'ROLESIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex3 = loweredIndex3 + 1) {
                    var virtualMachinesRoleSizesElement = js2xml.getElements(responseDoc, virtualMachinesRoleSizesSequenceElement, 'ROLESIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex3];
                    computeCapabilitiesInstance.virtualMachinesRoleSizes.push(virtualMachinesRoleSizesElement);
                  }
                }
                
                var webWorkerRoleSizesSequenceElement = js2xml.getElement(responseDoc, computeCapabilitiesElement, 'WEBWORKERROLESIZES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (webWorkerRoleSizesSequenceElement !== null && webWorkerRoleSizesSequenceElement !== undefined) {
                  for (var loweredIndex4 = 0; loweredIndex4 < js2xml.getElements(responseDoc, webWorkerRoleSizesSequenceElement, 'ROLESIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex4 = loweredIndex4 + 1) {
                    var webWorkerRoleSizesElement = js2xml.getElements(responseDoc, webWorkerRoleSizesSequenceElement, 'ROLESIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex4];
                    computeCapabilitiesInstance.webWorkerRoleSizes.push(webWorkerRoleSizesElement);
                  }
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The Update Affinity Group operation updates the label and/or the
   * description for an affinity group for the specified subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/gg715316.aspx for
   * more information)
   * 
   * @param {string} affinityGroupName The name of the affinity group.
   * 
   * @param {AffinityGroupUpdateParameters} parameters Parameters supplied to
   * the Update Affinity Group operation.
   * 
   * @param {string} parameters.label A name for the affinity specified as a
   * base-64-encoded string. The label can be up to 100 characters in length.
   * 
   * @param {string} [parameters.description] A description for the affinity
   * group. The description can be up to 1024 characters in length.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  AffinityGroupOperations.prototype.update = function(affinityGroupName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (affinityGroupName === null || affinityGroupName === undefined) {
      return callback(new Error('affinityGroupName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.description !== null && parameters.description !== undefined && parameters.description.length > 1024) {
      return callback(new Error('parameters.description is outside the valid range.'));
    }
    if (parameters.label === null || parameters.label === undefined) {
      return callback(new Error('parameters.label cannot be null.'));
    }
    if (parameters.label.length > 100) {
      return callback(new Error('parameters.label 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 + '/affinitygroups/';
    url2 = url2 + encodeURIComponent(affinityGroupName);
    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'] = '2014-10-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var updateAffinityGroupElement = js2xml.createElement('UpdateAffinityGroup', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, updateAffinityGroupElement);
    
    var labelElement = js2xml.createElement('Label', 'http://schemas.microsoft.com/windowsazure');
    js2xml.setElementValue(labelElement, new Buffer(parameters.label).toString('base64'));
    js2xml.addChildElement(updateAffinityGroupElement, labelElement);
    
    if (parameters.description !== null && parameters.description !== undefined) {
      var descriptionElement = js2xml.createElement('Description', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(descriptionElement, parameters.description);
      js2xml.addChildElement(updateAffinityGroupElement, descriptionElement);
    }
    
    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 AffinityGroupOperations;
})();

var LocationOperations = ( /** @lends LocationOperations */ function() {
  /**
   * @class
   * The Service Management API includes operations for listing the available
   * data center locations for a hosted service in your subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/gg441299.aspx for
   * more information)
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [ManagementClient] {@link
   * ManagementClient~ManagementClient}.
   * See [locations] {@link ManagementClient~ManagementClient#locations}.
   * Initializes a new instance of the LocationOperations class.
   * @constructor
   * 
   * @param {ManagementClient} client Reference to the service client.
   */
  function LocationOperations(client) {
    this.client = client;
  }
  
  /**
   * The List Locations operation lists all of the data center locations that
   * are valid for your subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/gg441293.aspx for
   * more information)
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  LocationOperations.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 + '/locations';
    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'] = '2014-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 = { locations: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var locationsSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'LOCATIONS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (locationsSequenceElement !== null && locationsSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, locationsSequenceElement, 'LOCATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var locationsElement = js2xml.getElements(responseDoc, locationsSequenceElement, 'LOCATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var locationInstance = { availableServices: [] };
              result.locations.push(locationInstance);
              
              var nameElement = js2xml.getElement(responseDoc, locationsElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                locationInstance.name = nameInstance;
              }
              
              var displayNameElement = js2xml.getElement(responseDoc, locationsElement, 'DISPLAYNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (displayNameElement !== null && displayNameElement !== undefined) {
                var displayNameInstance = displayNameElement;
                locationInstance.displayName = displayNameInstance;
              }
              
              var availableServicesSequenceElement = js2xml.getElement(responseDoc, locationsElement, 'AVAILABLESERVICES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (availableServicesSequenceElement !== null && availableServicesSequenceElement !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < js2xml.getElements(responseDoc, availableServicesSequenceElement, 'AVAILABLESERVICE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex2 = loweredIndex2 + 1) {
                  var availableServicesElement = js2xml.getElements(responseDoc, availableServicesSequenceElement, 'AVAILABLESERVICE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex2];
                  locationInstance.availableServices.push(availableServicesElement);
                }
              }
              
              var storageCapabilitiesElement = js2xml.getElement(responseDoc, locationsElement, 'STORAGECAPABILITIES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (storageCapabilitiesElement !== null && storageCapabilitiesElement !== undefined) {
                var storageCapabilitiesInstance = { storageAccountTypes: [] };
                locationInstance.storageCapabilities = storageCapabilitiesInstance;
                
                var storageAccountTypesSequenceElement = js2xml.getElement(responseDoc, storageCapabilitiesElement, 'STORAGEACCOUNTTYPES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (storageAccountTypesSequenceElement !== null && storageAccountTypesSequenceElement !== undefined) {
                  storageCapabilitiesInstance.storageAccountTypes = [];
                  for (var loweredIndex3 = 0; loweredIndex3 < js2xml.getElements(responseDoc, storageAccountTypesSequenceElement, 'STORAGEACCOUNTTYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex3 = loweredIndex3 + 1) {
                    var storageAccountTypesElement = js2xml.getElements(responseDoc, storageAccountTypesSequenceElement, 'STORAGEACCOUNTTYPE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex3];
                    storageCapabilitiesInstance.storageAccountTypes.push(storageAccountTypesElement);
                  }
                }
              }
              
              var computeCapabilitiesElement = js2xml.getElement(responseDoc, locationsElement, 'COMPUTECAPABILITIES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (computeCapabilitiesElement !== null && computeCapabilitiesElement !== undefined) {
                var computeCapabilitiesInstance = { virtualMachinesRoleSizes: [], webWorkerRoleSizes: [] };
                locationInstance.computeCapabilities = computeCapabilitiesInstance;
                
                var virtualMachinesRoleSizesSequenceElement = js2xml.getElement(responseDoc, computeCapabilitiesElement, 'VIRTUALMACHINESROLESIZES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (virtualMachinesRoleSizesSequenceElement !== null && virtualMachinesRoleSizesSequenceElement !== undefined) {
                  for (var loweredIndex4 = 0; loweredIndex4 < js2xml.getElements(responseDoc, virtualMachinesRoleSizesSequenceElement, 'ROLESIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex4 = loweredIndex4 + 1) {
                    var virtualMachinesRoleSizesElement = js2xml.getElements(responseDoc, virtualMachinesRoleSizesSequenceElement, 'ROLESIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex4];
                    computeCapabilitiesInstance.virtualMachinesRoleSizes.push(virtualMachinesRoleSizesElement);
                  }
                }
                
                var webWorkerRoleSizesSequenceElement = js2xml.getElement(responseDoc, computeCapabilitiesElement, 'WEBWORKERROLESIZES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (webWorkerRoleSizesSequenceElement !== null && webWorkerRoleSizesSequenceElement !== undefined) {
                  for (var loweredIndex5 = 0; loweredIndex5 < js2xml.getElements(responseDoc, webWorkerRoleSizesSequenceElement, 'ROLESIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex5 = loweredIndex5 + 1) {
                    var webWorkerRoleSizesElement = js2xml.getElements(responseDoc, webWorkerRoleSizesSequenceElement, 'ROLESIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex5];
                    computeCapabilitiesInstance.webWorkerRoleSizes.push(webWorkerRoleSizesElement);
                  }
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return LocationOperations;
})();

var ManagementCertificateOperations = ( /** @lends ManagementCertificateOperations */ function() {
  /**
   * @class
   * You can use management certificates, which are also known as subscription
   * certificates, to authenticate clients attempting to connect to resources
   * associated with your Azure subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154124.aspx for
   * more information)
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [ManagementClient] {@link
   * ManagementClient~ManagementClient}.
   * See [managementCertificates] {@link
   * ManagementClient~ManagementClient#managementCertificates}.
   * Initializes a new instance of the ManagementCertificateOperations class.
   * @constructor
   * 
   * @param {ManagementClient} client Reference to the service client.
   */
  function ManagementCertificateOperations(client) {
    this.client = client;
  }
  
  /**
   * The Create Management Certificate operation adds a certificate to the list
   * of management certificates. Management certificates, which are also known
   * as subscription certificates, authenticate clients attempting to connect
   * to resources associated with your Azure subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154123.aspx for
   * more information)
   * 
   * @param {ManagementCertificateCreateParameters} parameters Parameters
   * supplied to the Create Management Certificate operation.
   * 
   * @param {buffer} [parameters.publicKey] A base-64-representation of the
   * management certificate public key.
   * 
   * @param {string} [parameters.thumbprint] The thumbprint that uniquely
   * identifies the management certificate.
   * 
   * @param {buffer} [parameters.data] The certificate's raw data in
   * base-64-encoded cer format.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ManagementCertificateOperations.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.'));
    }
    
    // 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 + '/certificates';
    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'] = '2014-10-01';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = {};
    
    var subscriptionCertificateElement = js2xml.createElement('SubscriptionCertificate', 'http://schemas.microsoft.com/windowsazure');
    js2xml.addChildElement(requestDoc, subscriptionCertificateElement);
    
    if (parameters.publicKey !== null && parameters.publicKey !== undefined) {
      var subscriptionCertificatePublicKeyElement = js2xml.createElement('SubscriptionCertificatePublicKey', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(subscriptionCertificatePublicKeyElement, parameters.publicKey.toString('base64'));
      js2xml.addChildElement(subscriptionCertificateElement, subscriptionCertificatePublicKeyElement);
    }
    
    if (parameters.thumbprint !== null && parameters.thumbprint !== undefined) {
      var subscriptionCertificateThumbprintElement = js2xml.createElement('SubscriptionCertificateThumbprint', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(subscriptionCertificateThumbprintElement, parameters.thumbprint);
      js2xml.addChildElement(subscriptionCertificateElement, subscriptionCertificateThumbprintElement);
    }
    
    if (parameters.data !== null && parameters.data !== undefined) {
      var subscriptionCertificateDataElement = js2xml.createElement('SubscriptionCertificateData', 'http://schemas.microsoft.com/windowsazure');
      js2xml.setElementValue(subscriptionCertificateDataElement, parameters.data.toString('base64'));
      js2xml.addChildElement(subscriptionCertificateElement, subscriptionCertificateDataElement);
    }
    
    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);
    });
  };
  
  /**
   * The Delete Management Certificate operation deletes a certificate from the
   * list of management certificates. Management certificates, which are also
   * known as subscription certificates, authenticate clients attempting to
   * connect to resources associated with your Azure subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154127.aspx for
   * more information)
   * 
   * @param {string} thumbprint The thumbprint value of the certificate to
   * delete.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ManagementCertificateOperations.prototype.deleteMethod = function(thumbprint, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (thumbprint === null || thumbprint === undefined) {
      return callback(new Error('thumbprint 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 + '/certificates/';
    url2 = url2 + encodeURIComponent(thumbprint);
    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'] = '2014-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 && statusCode !== 404) {
        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);
    });
  };
  
  /**
   * The Get Management Certificate operation retrieves information about the
   * management certificate with the specified thumbprint. Management
   * certificates, which are also known as subscription certificates,
   * authenticate clients attempting to connect to resources associated with
   * your Azure subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154131.aspx for
   * more information)
   * 
   * @param {string} thumbprint The thumbprint value of the certificate to
   * retrieve information about.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ManagementCertificateOperations.prototype.get = function(thumbprint, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (thumbprint === null || thumbprint === undefined) {
      return callback(new Error('thumbprint 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 + '/certificates/';
    url2 = url2 + encodeURIComponent(thumbprint);
    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'] = '2014-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 subscriptionCertificateElement = js2xml.getElement(responseDoc, responseDoc, 'SUBSCRIPTIONCERTIFICATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (subscriptionCertificateElement !== null && subscriptionCertificateElement !== undefined) {
            var subscriptionCertificatePublicKeyElement = js2xml.getElement(responseDoc, subscriptionCertificateElement, 'SUBSCRIPTIONCERTIFICATEPUBLICKEY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (subscriptionCertificatePublicKeyElement !== null && subscriptionCertificatePublicKeyElement !== undefined) {
              var subscriptionCertificatePublicKeyInstance = new Buffer(subscriptionCertificatePublicKeyElement, 'base64').toString('utf8');
              result.publicKey = subscriptionCertificatePublicKeyInstance;
            }
            
            var subscriptionCertificateThumbprintElement = js2xml.getElement(responseDoc, subscriptionCertificateElement, 'SUBSCRIPTIONCERTIFICATETHUMBPRINT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (subscriptionCertificateThumbprintElement !== null && subscriptionCertificateThumbprintElement !== undefined) {
              var subscriptionCertificateThumbprintInstance = subscriptionCertificateThumbprintElement;
              result.thumbprint = subscriptionCertificateThumbprintInstance;
            }
            
            var subscriptionCertificateDataElement = js2xml.getElement(responseDoc, subscriptionCertificateElement, 'SUBSCRIPTIONCERTIFICATEDATA', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (subscriptionCertificateDataElement !== null && subscriptionCertificateDataElement !== undefined) {
              var subscriptionCertificateDataInstance = new Buffer(subscriptionCertificateDataElement, 'base64').toString('utf8');
              result.data = subscriptionCertificateDataInstance;
            }
            
            var createdElement = js2xml.getElement(responseDoc, subscriptionCertificateElement, 'CREATED', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (createdElement !== null && createdElement !== undefined && createdElement.length !== 0) {
              var createdInstance = new Date(createdElement);
              result.created = createdInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The List Management Certificates operation lists and returns basic
   * information about all of the management certificates associated with the
   * specified subscription. Management certificates, which are also known as
   * subscription certificates, authenticate clients attempting to connect to
   * resources associated with your Azure subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/jj154105.aspx for
   * more information)
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ManagementCertificateOperations.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 + '/certificates';
    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'] = '2014-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 = { subscriptionCertificates: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var subscriptionCertificatesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'SUBSCRIPTIONCERTIFICATES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (subscriptionCertificatesSequenceElement !== null && subscriptionCertificatesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, subscriptionCertificatesSequenceElement, 'SUBSCRIPTIONCERTIFICATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var subscriptionCertificatesElement = js2xml.getElements(responseDoc, subscriptionCertificatesSequenceElement, 'SUBSCRIPTIONCERTIFICATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var subscriptionCertificateInstance = {};
              result.subscriptionCertificates.push(subscriptionCertificateInstance);
              
              var subscriptionCertificatePublicKeyElement = js2xml.getElement(responseDoc, subscriptionCertificatesElement, 'SUBSCRIPTIONCERTIFICATEPUBLICKEY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (subscriptionCertificatePublicKeyElement !== null && subscriptionCertificatePublicKeyElement !== undefined) {
                var subscriptionCertificatePublicKeyInstance = new Buffer(subscriptionCertificatePublicKeyElement, 'base64').toString('utf8');
                subscriptionCertificateInstance.publicKey = subscriptionCertificatePublicKeyInstance;
              }
              
              var subscriptionCertificateThumbprintElement = js2xml.getElement(responseDoc, subscriptionCertificatesElement, 'SUBSCRIPTIONCERTIFICATETHUMBPRINT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (subscriptionCertificateThumbprintElement !== null && subscriptionCertificateThumbprintElement !== undefined) {
                var subscriptionCertificateThumbprintInstance = subscriptionCertificateThumbprintElement;
                subscriptionCertificateInstance.thumbprint = subscriptionCertificateThumbprintInstance;
              }
              
              var subscriptionCertificateDataElement = js2xml.getElement(responseDoc, subscriptionCertificatesElement, 'SUBSCRIPTIONCERTIFICATEDATA', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (subscriptionCertificateDataElement !== null && subscriptionCertificateDataElement !== undefined) {
                var subscriptionCertificateDataInstance = new Buffer(subscriptionCertificateDataElement, 'base64').toString('utf8');
                subscriptionCertificateInstance.data = subscriptionCertificateDataInstance;
              }
              
              var createdElement = js2xml.getElement(responseDoc, subscriptionCertificatesElement, 'CREATED', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (createdElement !== null && createdElement !== undefined && createdElement.length !== 0) {
                var createdInstance = new Date(createdElement);
                subscriptionCertificateInstance.created = createdInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return ManagementCertificateOperations;
})();

var RoleSizeOperations = ( /** @lends RoleSizeOperations */ function() {
  /**
   * @class
   * The Service Management API includes operations for listing the available
   * role sizes for VMs in your subscription.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [ManagementClient] {@link
   * ManagementClient~ManagementClient}.
   * See [roleSizes] {@link ManagementClient~ManagementClient#roleSizes}.
   * Initializes a new instance of the RoleSizeOperations class.
   * @constructor
   * 
   * @param {ManagementClient} client Reference to the service client.
   */
  function RoleSizeOperations(client) {
    this.client = client;
  }
  
  /**
   * The List Role Sizes operation lists all of the role sizes that are valid
   * for your subscription.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RoleSizeOperations.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 + '/rolesizes';
    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'] = '2014-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 = { roleSizes: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var roleSizesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'ROLESIZES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (roleSizesSequenceElement !== null && roleSizesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, roleSizesSequenceElement, 'ROLESIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var roleSizesElement = js2xml.getElements(responseDoc, roleSizesSequenceElement, 'ROLESIZE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var roleSizeInstance = {};
              result.roleSizes.push(roleSizeInstance);
              
              var nameElement = js2xml.getElement(responseDoc, roleSizesElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (nameElement !== null && nameElement !== undefined) {
                var nameInstance = nameElement;
                roleSizeInstance.name = nameInstance;
              }
              
              var labelElement = js2xml.getElement(responseDoc, roleSizesElement, 'LABEL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (labelElement !== null && labelElement !== undefined) {
                var labelInstance = labelElement;
                roleSizeInstance.label = labelInstance;
              }
              
              var coresElement = js2xml.getElement(responseDoc, roleSizesElement, 'CORES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (coresElement !== null && coresElement !== undefined && coresElement.length !== 0) {
                var coresInstance = parseInt(coresElement, 10);
                roleSizeInstance.cores = coresInstance;
              }
              
              var memoryInMbElement = js2xml.getElement(responseDoc, roleSizesElement, 'MEMORYINMB', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (memoryInMbElement !== null && memoryInMbElement !== undefined && memoryInMbElement.length !== 0) {
                var memoryInMbInstance = parseInt(memoryInMbElement, 10);
                roleSizeInstance.memoryInMb = memoryInMbInstance;
              }
              
              var supportedByWebWorkerRolesElement = js2xml.getElement(responseDoc, roleSizesElement, 'SUPPORTEDBYWEBWORKERROLES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (supportedByWebWorkerRolesElement !== null && supportedByWebWorkerRolesElement !== undefined && supportedByWebWorkerRolesElement.length !== 0) {
                var supportedByWebWorkerRolesInstance = supportedByWebWorkerRolesElement === 'true';
                roleSizeInstance.supportedByWebWorkerRoles = supportedByWebWorkerRolesInstance;
              }
              
              var supportedByVirtualMachinesElement = js2xml.getElement(responseDoc, roleSizesElement, 'SUPPORTEDBYVIRTUALMACHINES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (supportedByVirtualMachinesElement !== null && supportedByVirtualMachinesElement !== undefined && supportedByVirtualMachinesElement.length !== 0) {
                var supportedByVirtualMachinesInstance = supportedByVirtualMachinesElement === 'true';
                roleSizeInstance.supportedByVirtualMachines = supportedByVirtualMachinesInstance;
              }
              
              var maxDataDiskCountElement = js2xml.getElement(responseDoc, roleSizesElement, 'MAXDATADISKCOUNT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (maxDataDiskCountElement !== null && maxDataDiskCountElement !== undefined && maxDataDiskCountElement.length !== 0) {
                var maxDataDiskCountInstance = parseInt(maxDataDiskCountElement, 10);
                roleSizeInstance.maxDataDiskCount = maxDataDiskCountInstance;
              }
              
              var webWorkerResourceDiskSizeInMbElement = js2xml.getElement(responseDoc, roleSizesElement, 'WEBWORKERRESOURCEDISKSIZEINMB', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (webWorkerResourceDiskSizeInMbElement !== null && webWorkerResourceDiskSizeInMbElement !== undefined && webWorkerResourceDiskSizeInMbElement.length !== 0) {
                var webWorkerResourceDiskSizeInMbInstance = parseInt(webWorkerResourceDiskSizeInMbElement, 10);
                roleSizeInstance.webWorkerResourceDiskSizeInMb = webWorkerResourceDiskSizeInMbInstance;
              }
              
              var virtualMachineResourceDiskSizeInMbElement = js2xml.getElement(responseDoc, roleSizesElement, 'VIRTUALMACHINERESOURCEDISKSIZEINMB', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (virtualMachineResourceDiskSizeInMbElement !== null && virtualMachineResourceDiskSizeInMbElement !== undefined && virtualMachineResourceDiskSizeInMbElement.length !== 0) {
                var virtualMachineResourceDiskSizeInMbInstance = parseInt(virtualMachineResourceDiskSizeInMbElement, 10);
                roleSizeInstance.virtualMachineResourceDiskSizeInMb = virtualMachineResourceDiskSizeInMbInstance;
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return RoleSizeOperations;
})();

var SubscriptionOperations = ( /** @lends SubscriptionOperations */ function() {
  /**
   * @class
   * Operations for listing subscription details.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/gg715315.aspx for
   * more information)
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [ManagementClient] {@link
   * ManagementClient~ManagementClient}.
   * See [subscriptions] {@link
   * ManagementClient~ManagementClient#subscriptions}.
   * Initializes a new instance of the SubscriptionOperations class.
   * @constructor
   * 
   * @param {ManagementClient} client Reference to the service client.
   */
  function SubscriptionOperations(client) {
    this.client = client;
  }
  
  /**
   * The Get Subscription operation returns account and resource allocation
   * information for the specified subscription.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/hh403995.aspx for
   * more information)
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  SubscriptionOperations.prototype.get = 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);
    }
    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'] = '2014-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 subscriptionElement = js2xml.getElement(responseDoc, responseDoc, 'SUBSCRIPTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (subscriptionElement !== null && subscriptionElement !== undefined) {
            var subscriptionIDElement = js2xml.getElement(responseDoc, subscriptionElement, 'SUBSCRIPTIONID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (subscriptionIDElement !== null && subscriptionIDElement !== undefined) {
              var subscriptionIDInstance = subscriptionIDElement;
              result.subscriptionID = subscriptionIDInstance;
            }
            
            var subscriptionNameElement = js2xml.getElement(responseDoc, subscriptionElement, 'SUBSCRIPTIONNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (subscriptionNameElement !== null && subscriptionNameElement !== undefined) {
              var subscriptionNameInstance = subscriptionNameElement;
              result.subscriptionName = subscriptionNameInstance;
            }
            
            var subscriptionStatusElement = js2xml.getElement(responseDoc, subscriptionElement, 'SUBSCRIPTIONSTATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (subscriptionStatusElement !== null && subscriptionStatusElement !== undefined && subscriptionStatusElement.length !== 0) {
              var subscriptionStatusInstance = subscriptionStatusElement;
              result.subscriptionStatus = subscriptionStatusInstance;
            }
            
            var accountAdminLiveEmailIdElement = js2xml.getElement(responseDoc, subscriptionElement, 'ACCOUNTADMINLIVEEMAILID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (accountAdminLiveEmailIdElement !== null && accountAdminLiveEmailIdElement !== undefined) {
              var accountAdminLiveEmailIdInstance = accountAdminLiveEmailIdElement;
              result.accountAdminLiveEmailId = accountAdminLiveEmailIdInstance;
            }
            
            var serviceAdminLiveEmailIdElement = js2xml.getElement(responseDoc, subscriptionElement, 'SERVICEADMINLIVEEMAILID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (serviceAdminLiveEmailIdElement !== null && serviceAdminLiveEmailIdElement !== undefined) {
              var serviceAdminLiveEmailIdInstance = serviceAdminLiveEmailIdElement;
              result.serviceAdminLiveEmailId = serviceAdminLiveEmailIdInstance;
            }
            
            var maxCoreCountElement = js2xml.getElement(responseDoc, subscriptionElement, 'MAXCORECOUNT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (maxCoreCountElement !== null && maxCoreCountElement !== undefined && maxCoreCountElement.length !== 0) {
              var maxCoreCountInstance = parseInt(maxCoreCountElement, 10);
              result.maximumCoreCount = maxCoreCountInstance;
            }
            
            var maxStorageAccountsElement = js2xml.getElement(responseDoc, subscriptionElement, 'MAXSTORAGEACCOUNTS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (maxStorageAccountsElement !== null && maxStorageAccountsElement !== undefined && maxStorageAccountsElement.length !== 0) {
              var maxStorageAccountsInstance = parseInt(maxStorageAccountsElement, 10);
              result.maximumStorageAccounts = maxStorageAccountsInstance;
            }
            
            var maxHostedServicesElement = js2xml.getElement(responseDoc, subscriptionElement, 'MAXHOSTEDSERVICES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (maxHostedServicesElement !== null && maxHostedServicesElement !== undefined && maxHostedServicesElement.length !== 0) {
              var maxHostedServicesInstance = parseInt(maxHostedServicesElement, 10);
              result.maximumHostedServices = maxHostedServicesInstance;
            }
            
            var currentCoreCountElement = js2xml.getElement(responseDoc, subscriptionElement, 'CURRENTCORECOUNT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (currentCoreCountElement !== null && currentCoreCountElement !== undefined && currentCoreCountElement.length !== 0) {
              var currentCoreCountInstance = parseInt(currentCoreCountElement, 10);
              result.currentCoreCount = currentCoreCountInstance;
            }
            
            var currentStorageAccountsElement = js2xml.getElement(responseDoc, subscriptionElement, 'CURRENTSTORAGEACCOUNTS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (currentStorageAccountsElement !== null && currentStorageAccountsElement !== undefined && currentStorageAccountsElement.length !== 0) {
              var currentStorageAccountsInstance = parseInt(currentStorageAccountsElement, 10);
              result.currentStorageAccounts = currentStorageAccountsInstance;
            }
            
            var currentHostedServicesElement = js2xml.getElement(responseDoc, subscriptionElement, 'CURRENTHOSTEDSERVICES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (currentHostedServicesElement !== null && currentHostedServicesElement !== undefined && currentHostedServicesElement.length !== 0) {
              var currentHostedServicesInstance = parseInt(currentHostedServicesElement, 10);
              result.currentHostedServices = currentHostedServicesInstance;
            }
            
            var maxVirtualNetworkSitesElement = js2xml.getElement(responseDoc, subscriptionElement, 'MAXVIRTUALNETWORKSITES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (maxVirtualNetworkSitesElement !== null && maxVirtualNetworkSitesElement !== undefined && maxVirtualNetworkSitesElement.length !== 0) {
              var maxVirtualNetworkSitesInstance = parseInt(maxVirtualNetworkSitesElement, 10);
              result.maximumVirtualNetworkSites = maxVirtualNetworkSitesInstance;
            }
            
            var currentVirtualNetworkSitesElement = js2xml.getElement(responseDoc, subscriptionElement, 'CURRENTVIRTUALNETWORKSITES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (currentVirtualNetworkSitesElement !== null && currentVirtualNetworkSitesElement !== undefined && currentVirtualNetworkSitesElement.length !== 0) {
              var currentVirtualNetworkSitesInstance = parseInt(currentVirtualNetworkSitesElement, 10);
              result.currentVirtualNetworkSites = currentVirtualNetworkSitesInstance;
            }
            
            var maxLocalNetworkSitesElement = js2xml.getElement(responseDoc, subscriptionElement, 'MAXLOCALNETWORKSITES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (maxLocalNetworkSitesElement !== null && maxLocalNetworkSitesElement !== undefined && maxLocalNetworkSitesElement.length !== 0) {
              var maxLocalNetworkSitesInstance = parseInt(maxLocalNetworkSitesElement, 10);
              result.maximumLocalNetworkSites = maxLocalNetworkSitesInstance;
            }
            
            var maxDnsServersElement = js2xml.getElement(responseDoc, subscriptionElement, 'MAXDNSSERVERS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (maxDnsServersElement !== null && maxDnsServersElement !== undefined && maxDnsServersElement.length !== 0) {
              var maxDnsServersInstance = parseInt(maxDnsServersElement, 10);
              result.maximumDnsServers = maxDnsServersInstance;
            }
            
            var currentLocalNetworkSitesElement = js2xml.getElement(responseDoc, subscriptionElement, 'CURRENTLOCALNETWORKSITES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (currentLocalNetworkSitesElement !== null && currentLocalNetworkSitesElement !== undefined && currentLocalNetworkSitesElement.length !== 0) {
              var currentLocalNetworkSitesInstance = parseInt(currentLocalNetworkSitesElement, 10);
              result.currentLocalNetworkSites = currentLocalNetworkSitesInstance;
            }
            
            var currentDnsServersElement = js2xml.getElement(responseDoc, subscriptionElement, 'CURRENTDNSSERVERS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (currentDnsServersElement !== null && currentDnsServersElement !== undefined && currentDnsServersElement.length !== 0) {
              var currentDnsServersInstance = parseInt(currentDnsServersElement, 10);
              result.currentDnsServers = currentDnsServersInstance;
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The List Subscription Operations operation returns a list of create,
   * update, and delete operations that were performed on a subscription
   * during the specified timeframe.  (see
   * http://msdn.microsoft.com/en-us/library/windowsazure/gg715318.aspx for
   * more information)
   * 
   * @param {SubscriptionListOperationsParameters} parameters Parameters
   * supplied to the List Subscription Operations operation.
   * 
   * @param {date} parameters.startTime The start of the timeframe to begin
   * listing subscription operations in UTC format. This parameter and the
   * EndTime parameter indicate the timeframe to retrieve subscription
   * operations. This parameter cannot indicate a start date of more than 90
   * days in the past.
   * 
   * @param {date} parameters.endTime The end of the timeframe to begin listing
   * subscription operations in UTC format. This parameter and the StartTime
   * parameter indicate the timeframe to retrieve subscription operations.
   * 
   * @param {string} [parameters.objectIdFilter] Returns subscription
   * operations only for the specified object type and object ID. This
   * parameter must be set equal to the URL value for performing an HTTP GET
   * on the object. If no object is specified, a filter is not applied.
   * 
   * @param {OperationStatus} [parameters.operationStatus] Returns subscription
   * operations only for the specified result status, either Succeeded,
   * Failed, or InProgress. This filter can be combined with the
   * ObjectIdFilter to select subscription operations for an object with a
   * specific result status. If no result status is specified, a filter is not
   * applied.
   * 
   * @param {string} [parameters.continuationToken] When there are too many
   * operations to list, such as when the requested timeframe is very large,
   * the response includes an incomplete list and a token that can be used to
   * return the rest of the list. Subsequent requests must include this
   * parameter to continue listing operations from where the last response
   * left off. If no token is specified, a filter is not applied and the
   * response will begin at the specified StartTime.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  SubscriptionOperations.prototype.listOperations = 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.endTime === null || parameters.endTime === undefined) {
      return callback(new Error('parameters.endTime cannot be null.'));
    }
    if (parameters.startTime === null || parameters.startTime === undefined) {
      return callback(new Error('parameters.startTime 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 + '/operations';
    var queryParameters = [];
    queryParameters.push('StartTime=' + encodeURIComponent(parameters.startTime.toISOString()));
    queryParameters.push('EndTime=' + encodeURIComponent(parameters.endTime.toISOString()));
    if (parameters.objectIdFilter !== null && parameters.objectIdFilter !== undefined) {
      queryParameters.push('ObjectIdFilter=' + encodeURIComponent(parameters.objectIdFilter));
    }
    if (parameters.operationStatus !== null && parameters.operationStatus !== undefined) {
      queryParameters.push('OperationResultFilter=' + encodeURIComponent(parameters.operationStatus !== null && parameters.operationStatus !== undefined ? parameters.operationStatus.toString() : 'InProgress'));
    }
    if (parameters.continuationToken !== null && parameters.continuationToken !== undefined) {
      queryParameters.push('ContinuationToken=' + encodeURIComponent(parameters.continuationToken));
    }
    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'] = '2014-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 = { subscriptionOperations: [] };
        var options = {};
        options.trim = false;
        options.strict = false;
        xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var subscriptionOperationCollectionElement = js2xml.getElement(responseDoc, responseDoc, 'SUBSCRIPTIONOPERATIONCOLLECTION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (subscriptionOperationCollectionElement !== null && subscriptionOperationCollectionElement !== undefined) {
            var continuationTokenElement = js2xml.getElement(responseDoc, subscriptionOperationCollectionElement, 'CONTINUATIONTOKEN', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (continuationTokenElement !== null && continuationTokenElement !== undefined) {
              var continuationTokenInstance = continuationTokenElement;
              result.continuationToken = continuationTokenInstance;
            }
            
            var subscriptionOperationsSequenceElement = js2xml.getElement(responseDoc, subscriptionOperationCollectionElement, 'SUBSCRIPTIONOPERATIONS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (subscriptionOperationsSequenceElement !== null && subscriptionOperationsSequenceElement !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, subscriptionOperationsSequenceElement, 'SUBSCRIPTIONOPERATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
                var subscriptionOperationsElement = js2xml.getElements(responseDoc, subscriptionOperationsSequenceElement, 'SUBSCRIPTIONOPERATION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
                var subscriptionOperationInstance = { operationParameters: {} };
                result.subscriptionOperations.push(subscriptionOperationInstance);
                
                var operationIdElement = js2xml.getElement(responseDoc, subscriptionOperationsElement, 'OPERATIONID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (operationIdElement !== null && operationIdElement !== undefined) {
                  var operationIdInstance = operationIdElement;
                  subscriptionOperationInstance.operationId = operationIdInstance;
                }
                
                var operationObjectIdElement = js2xml.getElement(responseDoc, subscriptionOperationsElement, 'OPERATIONOBJECTID', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (operationObjectIdElement !== null && operationObjectIdElement !== undefined) {
                  var operationObjectIdInstance = operationObjectIdElement;
                  subscriptionOperationInstance.operationObjectId = operationObjectIdInstance;
                }
                
                var operationNameElement = js2xml.getElement(responseDoc, subscriptionOperationsElement, 'OPERATIONNAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (operationNameElement !== null && operationNameElement !== undefined) {
                  var operationNameInstance = operationNameElement;
                  subscriptionOperationInstance.operationName = operationNameInstance;
                }
                
                var operationParametersSequenceElement = js2xml.getElement(responseDoc, subscriptionOperationsElement, 'OPERATIONPARAMETERS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (operationParametersSequenceElement !== null && operationParametersSequenceElement !== undefined) {
                  for (var loweredIndex2 = 0; loweredIndex2 < js2xml.getElements(responseDoc, operationParametersSequenceElement, 'OPERATIONPARAMETER', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex2 = loweredIndex2 + 1) {
                    var operationParametersElement = js2xml.getElements(responseDoc, operationParametersSequenceElement, 'OPERATIONPARAMETER', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex2];
                    var operationParametersKey = js2xml.getElement(responseDoc, operationParametersElement, 'NAME', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.WINDOWSAZURE.SERVICEMANAGEMENT');
                    var operationParametersValue = js2xml.getElement(responseDoc, operationParametersElement, 'VALUE', 'HTTP://SCHEMAS.DATACONTRACT.ORG/2004/07/MICROSOFT.WINDOWSAZURE.SERVICEMANAGEMENT');
                    subscriptionOperationInstance.operationParameters[operationParametersKey] = operationParametersValue;
                  }
                }
                
                var operationCallerElement = js2xml.getElement(responseDoc, subscriptionOperationsElement, 'OPERATIONCALLER', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (operationCallerElement !== null && operationCallerElement !== undefined) {
                  var operationCallerInstance = {};
                  subscriptionOperationInstance.operationCaller = operationCallerInstance;
                  
                  var usedServiceManagementApiElement = js2xml.getElement(responseDoc, operationCallerElement, 'USEDSERVICEMANAGEMENTAPI', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (usedServiceManagementApiElement !== null && usedServiceManagementApiElement !== undefined && usedServiceManagementApiElement.length !== 0) {
                    var usedServiceManagementApiInstance = usedServiceManagementApiElement === 'true';
                    operationCallerInstance.usedServiceManagementApi = usedServiceManagementApiInstance;
                  }
                  
                  var userEmailAddressElement = js2xml.getElement(responseDoc, operationCallerElement, 'USEREMAILADDRESS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (userEmailAddressElement !== null && userEmailAddressElement !== undefined) {
                    var userEmailAddressInstance = userEmailAddressElement;
                    operationCallerInstance.userEmailAddress = userEmailAddressInstance;
                  }
                  
                  var subscriptionCertificateThumbprintElement = js2xml.getElement(responseDoc, operationCallerElement, 'SUBSCRIPTIONCERTIFICATETHUMBPRINT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (subscriptionCertificateThumbprintElement !== null && subscriptionCertificateThumbprintElement !== undefined) {
                    var subscriptionCertificateThumbprintInstance = subscriptionCertificateThumbprintElement;
                    operationCallerInstance.subscriptionCertificateThumbprint = subscriptionCertificateThumbprintInstance;
                  }
                  
                  var clientIPElement = js2xml.getElement(responseDoc, operationCallerElement, 'CLIENTIP', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (clientIPElement !== null && clientIPElement !== undefined) {
                    var clientIPInstance = clientIPElement;
                    operationCallerInstance.clientIPAddress = clientIPInstance;
                  }
                }
                
                var operationStatusElement = js2xml.getElement(responseDoc, subscriptionOperationsElement, 'OPERATIONSTATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (operationStatusElement !== null && operationStatusElement !== undefined) {
                  var operationStatusInstance = operationStatusElement;
                  subscriptionOperationInstance.operationStatus = operationStatusInstance;
                }
                
                var operationStartedTimeElement = js2xml.getElement(responseDoc, subscriptionOperationsElement, 'OPERATIONSTARTEDTIME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (operationStartedTimeElement !== null && operationStartedTimeElement !== undefined && operationStartedTimeElement.length !== 0) {
                  var operationStartedTimeInstance = new Date(operationStartedTimeElement);
                  subscriptionOperationInstance.operationStartedTime = operationStartedTimeInstance;
                }
                
                var operationCompletedTimeElement = js2xml.getElement(responseDoc, subscriptionOperationsElement, 'OPERATIONCOMPLETEDTIME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (operationCompletedTimeElement !== null && operationCompletedTimeElement !== undefined && operationCompletedTimeElement.length !== 0) {
                  var operationCompletedTimeInstance = new Date(operationCompletedTimeElement);
                  subscriptionOperationInstance.operationCompletedTime = operationCompletedTimeInstance;
                }
              }
            }
          }
          
        });
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Register a resource with your subscription.
   * 
   * @param {string} resourceName Name of the resource to register.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  SubscriptionOperations.prototype.registerResource = function(resourceName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceName === null || resourceName === undefined) {
      return callback(new Error('resourceName 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';
    var queryParameters = [];
    queryParameters.push('service=' + encodeURIComponent(resourceName));
    queryParameters.push('action=register');
    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 = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2014-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 && statusCode !== 202) {
        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);
    });
  };
  
  /**
   * Unregister a resource with your subscription.
   * 
   * @param {string} resourceName Name of the resource to unregister.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  SubscriptionOperations.prototype.unregisterResource = function(resourceName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceName === null || resourceName === undefined) {
      return callback(new Error('resourceName 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';
    var queryParameters = [];
    queryParameters.push('service=' + encodeURIComponent(resourceName));
    queryParameters.push('action=unregister');
    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 = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/xml';
    httpRequest.headers['x-ms-version'] = '2014-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 && statusCode !== 202) {
        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 SubscriptionOperations;
})();
