text: /* 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 SchedulerManagementClient = ( /** @lends SchedulerManagementClient */ function() {
    /**
     * @class
     * Initializes a new instance of the SchedulerManagementClient 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 SchedulerManagementClient(credentials, baseUri, filters) {
      if (credentials === null || credentials === undefined) {
        throw new Error('credentials cannot be null.');
      }
      
      SchedulerManagementClient['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 = '2013-03-01';
      }
      if (this.longRunningOperationInitialTimeout === null || this.longRunningOperationInitialTimeout === undefined) {
        this.longRunningOperationInitialTimeout = -1;
      }
      if (this.longRunningOperationRetryTimeout === null || this.longRunningOperationRetryTimeout === undefined) {
        this.longRunningOperationRetryTimeout = -1;
      }
      /**
       * Provides an instance of the
       * [JobCollectionOperations](-JobCollectionOperations.html) object.
       * @type {object}
       */
      this.jobCollections = new JobCollectionOperations(this);
    }
    
    util.inherits(SchedulerManagementClient, Service);
    
    /**
     * The Get Operation Status operation returns the status of thespecified
     * 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.
     */
    SchedulerManagementClient.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 = (this.credentials.subscriptionId !== null && this.credentials.subscriptionId !== undefined ? this.credentials.subscriptionId.trim() : '') + '/operations/' + requestId.trim();
      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'] = '2013-03-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
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        return 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) {
              var statusInstance = statusElement;
              result.status = statusInstance;
            }
            
            var httpStatusCodeElement = js2xml.getElement(responseDoc, operationElement, 'HTTPSTATUSCODE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (httpStatusCodeElement !== null && httpStatusCodeElement !== undefined) {
              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);
        });
      });
    };
    
    /**
     * Gets a list of properties for the resource provider, including supported
     * regions and plans.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    SchedulerManagementClient.prototype.getResourceProviderProperties = function(callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      
      // Tracing
      
      // Construct URL
      var url2 = (this.credentials.subscriptionId !== null && this.credentials.subscriptionId !== undefined ? this.credentials.subscriptionId.trim() : '') + '/resourceproviders/scheduler/Properties?';
      url2 = url2 + 'resourceType=JobCollections';
      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'] = '2013-03-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
        var responseContent = body;
        result = { properties: {} };
        var options = {};
        options.trim = false;
        options.strict = false;
        return xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var resourceProviderPropertiesSequenceElement = js2xml.getElement(responseDoc, responseDoc, 'RESOURCEPROVIDERPROPERTIES', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (resourceProviderPropertiesSequenceElement !== null && resourceProviderPropertiesSequenceElement !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < js2xml.getElements(responseDoc, resourceProviderPropertiesSequenceElement, 'RESOURCEPROVIDERPROPERTY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE').length; loweredIndex1 = loweredIndex1 + 1) {
              var resourceProviderPropertiesElement = js2xml.getElements(responseDoc, resourceProviderPropertiesSequenceElement, 'RESOURCEPROVIDERPROPERTY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE')[loweredIndex1];
              var resourceProviderPropertiesKey = js2xml.getElement(responseDoc, resourceProviderPropertiesElement, 'KEY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              var resourceProviderPropertiesValue = js2xml.getElement(responseDoc, resourceProviderPropertiesElement, 'VALUE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              result.properties[resourceProviderPropertiesKey] = resourceProviderPropertiesValue;
            }
          }
          
          result.statusCode = statusCode;
          result.requestId = response.headers['x-ms-request-id'];
          
          return callback(null, result);
        });
      });
    };
    
    /**
     * Register the Scheduler resource provider with your subscription.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    SchedulerManagementClient.prototype.registerResourceProvider = function(callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      
      // Tracing
      
      // Construct URL
      var url2 = (this.credentials.subscriptionId !== null && this.credentials.subscriptionId !== undefined ? this.credentials.subscriptionId.trim() : '') + '/services?';
      url2 = url2 + 'service=scheduler.JobCollections';
      url2 = url2 + '&action=register';
      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 = 'PUT';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['x-ms-version'] = '2013-03-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;
        result = {};
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * Unregister the Scheduler resource provider with your subscription.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    SchedulerManagementClient.prototype.unregisterResourceProvider = function(callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      
      // Tracing
      
      // Construct URL
      var url2 = (this.credentials.subscriptionId !== null && this.credentials.subscriptionId !== undefined ? this.credentials.subscriptionId.trim() : '') + '/services?';
      url2 = url2 + 'service=scheduler.JobCollections';
      url2 = url2 + '&action=unregister';
      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 = 'PUT';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['x-ms-version'] = '2013-03-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;
        result = {};
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    return SchedulerManagementClient;
  })();
  exports.SchedulerManagementClient = SchedulerManagementClient;
  
  var JobCollectionOperations = ( /** @lends JobCollectionOperations */ function() {
    /**
     * @class
     * __NOTE__: An instance of this class is automatically created for an
     * instance of the [SchedulerManagementClient] {@link
     * SchedulerManagementClient~SchedulerManagementClient}.
     * See [jobCollections] {@link
     * SchedulerManagementClient~SchedulerManagementClient#jobCollections}.
     * Initializes a new instance of the JobCollectionOperations class.
     * @constructor
     * 
     * @param {SchedulerManagementClient} client Reference to the service client.
     */
    function JobCollectionOperations(client) {
      this.client = client;
    }
    
    /**
     * Create a job collection.
     * 
     * @param {string} cloudServiceName The name of the cloud service containing
     * the job collection.
     * 
     * @param {string} jobCollectionName The name of the job collection to create.
     * 
     * @param {JobCollectionCreateParameters} parameters Parameters supplied to
     * the Create Job Collection operation.
     * 
     * @param {string} [parameters.schemaVersion] The version of the Intrinsic
     * Properties for your Resource. If not specified, you must conform to the
     * contract resource version you registered as default.
     * 
     * @param {string} [parameters.label] Label for the resource.
     * 
     * @param {JobCollectionIntrinsicSettings} [parameters.intrinsicSettings]
     * Intrinsic settings for the scheduler job collections.
     * 
     * @param {JobCollectionPlan} [parameters.intrinsicSettings.plan] The plan of
     * the resource.
     * 
     * @param {JobCollectionQuota} [parameters.intrinsicSettings.quota] Quota
     * settings for the job collection.
     * 
     * @param {number} [parameters.intrinsicSettings.quota.maxJobCount] Maximum
     * number of jobs that can be created in this job collection. Maximum value
     * is dependent on the plan.
     * 
     * @param {number} [parameters.intrinsicSettings.quota.maxJobOccurrence]
     * Maximum number of occurrences for all jobs in the job collection.
     * 
     * @param {JobCollectionMaxRecurrence}
     * [parameters.intrinsicSettings.quota.maxRecurrence] Defines the maximum
     * recurrences that can be specified in any job in this job collection.
     * 
     * @param {JobCollectionRecurrenceFrequency}
     * [parameters.intrinsicSettings.quota.maxRecurrence.frequency] Defines the
     * maximum recurrences that can be specified in any job in this job
     * collection.
     * 
     * @param {number}
     * [parameters.intrinsicSettings.quota.maxRecurrence.interval] Defines the
     * interval.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    JobCollectionOperations.prototype.beginCreating = function(cloudServiceName, jobCollectionName, parameters, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (cloudServiceName === null || cloudServiceName === undefined) {
        return callback(new Error('cloudServiceName cannot be null.'));
      }
      if (jobCollectionName === null || jobCollectionName === undefined) {
        return callback(new Error('jobCollectionName cannot be null.'));
      }
      if (jobCollectionName.length > 100) {
        return callback(new Error('jobCollectionName is outside the valid range.'));
      }
      if (parameters === null || parameters === undefined) {
        return callback(new Error('parameters cannot be null.'));
      }
      if (parameters.intrinsicSettings !== null && parameters.intrinsicSettings !== undefined) {
        if (parameters.intrinsicSettings.quota !== null && parameters.intrinsicSettings.quota !== undefined) {
          if (parameters.intrinsicSettings.quota.maxRecurrence !== null && parameters.intrinsicSettings.quota.maxRecurrence !== undefined) {
            if (parameters.intrinsicSettings.quota.maxRecurrence.interval === null || parameters.intrinsicSettings.quota.maxRecurrence.interval === undefined) {
              return callback(new Error('parameters.intrinsicSettings.quota.maxRecurrence.interval cannot be null.'));
            }
          }
        }
      }
      
      // Tracing
      
      // Construct URL
      var url2 = (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined ? this.client.credentials.subscriptionId.trim() : '') + '/cloudservices/' + cloudServiceName.trim() + '/resources/scheduler/JobCollections/' + jobCollectionName.trim();
      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'] = '2013-03-01';
      
      // Serialize Request
      var requestContent = null;
      var requestDoc = {};
      
      var resourceElement = js2xml.createElement('Resource', 'http://schemas.microsoft.com/windowsazure');
      js2xml.addChildElement(requestDoc, resourceElement);
      
      if (parameters.schemaVersion !== null && parameters.schemaVersion !== undefined) {
        var schemaVersionElement = js2xml.createElement('SchemaVersion', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(schemaVersionElement, parameters.schemaVersion);
        js2xml.addChildElement(resourceElement, schemaVersionElement);
      }
      
      if (parameters.intrinsicSettings !== null && parameters.intrinsicSettings !== undefined) {
        var intrinsicSettingsElement = js2xml.createElement('IntrinsicSettings', 'http://schemas.microsoft.com/windowsazure');
        js2xml.addChildElement(resourceElement, intrinsicSettingsElement);
        
        var planElement = js2xml.createElement('Plan', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(planElement, parameters.intrinsicSettings.plan !== null && parameters.intrinsicSettings.plan !== undefined ? parameters.intrinsicSettings.plan.toString() : 'Standard');
        js2xml.addChildElement(intrinsicSettingsElement, planElement);
        
        if (parameters.intrinsicSettings.quota !== null && parameters.intrinsicSettings.quota !== undefined) {
          var quotaElement = js2xml.createElement('Quota', 'http://schemas.microsoft.com/windowsazure');
          js2xml.addChildElement(intrinsicSettingsElement, quotaElement);
          
          if (parameters.intrinsicSettings.quota.maxJobCount !== null && parameters.intrinsicSettings.quota.maxJobCount !== undefined) {
            var maxJobCountElement = js2xml.createElement('MaxJobCount', 'http://schemas.microsoft.com/windowsazure');
            js2xml.setElementValue(maxJobCountElement, parameters.intrinsicSettings.quota.maxJobCount.toString());
            js2xml.addChildElement(quotaElement, maxJobCountElement);
          }
          
          if (parameters.intrinsicSettings.quota.maxJobOccurrence !== null && parameters.intrinsicSettings.quota.maxJobOccurrence !== undefined) {
            var maxJobOccurrenceElement = js2xml.createElement('MaxJobOccurrence', 'http://schemas.microsoft.com/windowsazure');
            js2xml.setElementValue(maxJobOccurrenceElement, parameters.intrinsicSettings.quota.maxJobOccurrence.toString());
            js2xml.addChildElement(quotaElement, maxJobOccurrenceElement);
          }
          
          if (parameters.intrinsicSettings.quota.maxRecurrence !== null && parameters.intrinsicSettings.quota.maxRecurrence !== undefined) {
            var maxRecurrenceElement = js2xml.createElement('MaxRecurrence', 'http://schemas.microsoft.com/windowsazure');
            js2xml.addChildElement(quotaElement, maxRecurrenceElement);
            
            var frequencyElement = js2xml.createElement('Frequency', 'http://schemas.microsoft.com/windowsazure');
            js2xml.setElementValue(frequencyElement, parameters.intrinsicSettings.quota.maxRecurrence.frequency !== null && parameters.intrinsicSettings.quota.maxRecurrence.frequency !== undefined ? parameters.intrinsicSettings.quota.maxRecurrence.frequency.toString() : 'Minute');
            js2xml.addChildElement(maxRecurrenceElement, frequencyElement);
            
            var intervalElement = js2xml.createElement('Interval', 'http://schemas.microsoft.com/windowsazure');
            js2xml.setElementValue(intervalElement, parameters.intrinsicSettings.quota.maxRecurrence.interval.toString());
            js2xml.addChildElement(maxRecurrenceElement, intervalElement);
          }
        }
      }
      
      if (parameters.label !== null && parameters.label !== undefined) {
        var labelElement = js2xml.createElement('Label', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(labelElement, new Buffer(parameters.label).toString('base64'));
        js2xml.addChildElement(resourceElement, labelElement);
      }
      
      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 !== 202) {
          var error = new Error(body);
          error.statusCode = response.statusCode;
          return callback(error);
        }
        
        // Create Result
        var result = null;
        result = {};
        result.statusCode = statusCode;
        result.eTag = response.headers['etag'];
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * Deletes a job collection.
     * 
     * @param {string} cloudServiceName The name of the cloud service.
     * 
     * @param {string} jobCollectionName The name of the job collection to delete.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    JobCollectionOperations.prototype.beginDeleting = function(cloudServiceName, jobCollectionName, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (cloudServiceName === null || cloudServiceName === undefined) {
        return callback(new Error('cloudServiceName cannot be null.'));
      }
      if (jobCollectionName === null || jobCollectionName === undefined) {
        return callback(new Error('jobCollectionName cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined ? this.client.credentials.subscriptionId.trim() : '') + '/cloudservices/' + cloudServiceName.trim() + '/resources/scheduler/JobCollections/' + jobCollectionName.trim();
      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'] = '2013-03-01';
      
      // Send Request
      return this.client.pipeline(httpRequest, function (err, response, body) {
        if (err !== null && err !== undefined) {
          return callback(err);
        }
        var statusCode = response.statusCode;
        if (statusCode !== 202) {
          var error = new Error(body);
          error.statusCode = response.statusCode;
          return callback(error);
        }
        
        // Create Result
        var result = null;
        result = {};
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * Update a job collection.
     * 
     * @param {string} cloudServiceName The name of the cloud service containing
     * the job collection.
     * 
     * @param {string} jobCollectionName The name of the job collection to update.
     * 
     * @param {JobCollectionUpdateParameters} parameters Parameters supplied to
     * the Update Job Collection operation.
     * 
     * @param {string} parameters.eTag The ETag of the job collection to update.
     * The update will fail ifthe ETag doesn't match.
     * 
     * @param {string} [parameters.schemaVersion] The version of the Intrinsic
     * Properties for your Resource. If not specified, you must conform to the
     * contract resource version you registered as default.
     * 
     * @param {string} [parameters.label] Label for the resource.
     * 
     * @param {JobCollectionIntrinsicSettings} [parameters.intrinsicSettings]
     * Intrinsic settings for the scheduler job collections.
     * 
     * @param {JobCollectionPlan} [parameters.intrinsicSettings.plan] The plan of
     * the resource.
     * 
     * @param {JobCollectionQuota} [parameters.intrinsicSettings.quota] Quota
     * settings for the job collection.
     * 
     * @param {number} [parameters.intrinsicSettings.quota.maxJobCount] Maximum
     * number of jobs that can be created in this job collection. Maximum value
     * is dependent on the plan.
     * 
     * @param {number} [parameters.intrinsicSettings.quota.maxJobOccurrence]
     * Maximum number of occurrences for all jobs in the job collection.
     * 
     * @param {JobCollectionMaxRecurrence}
     * [parameters.intrinsicSettings.quota.maxRecurrence] Defines the maximum
     * recurrences that can be specified in any job in this job collection.
     * 
     * @param {JobCollectionRecurrenceFrequency}
     * [parameters.intrinsicSettings.quota.maxRecurrence.frequency] Defines the
     * maximum recurrences that can be specified in any job in this job
     * collection.
     * 
     * @param {number}
     * [parameters.intrinsicSettings.quota.maxRecurrence.interval] Defines the
     * interval.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    JobCollectionOperations.prototype.beginUpdating = function(cloudServiceName, jobCollectionName, parameters, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (cloudServiceName === null || cloudServiceName === undefined) {
        return callback(new Error('cloudServiceName cannot be null.'));
      }
      if (jobCollectionName === null || jobCollectionName === undefined) {
        return callback(new Error('jobCollectionName cannot be null.'));
      }
      if (jobCollectionName.length > 100) {
        return callback(new Error('jobCollectionName is outside the valid range.'));
      }
      if (parameters === null || parameters === undefined) {
        return callback(new Error('parameters cannot be null.'));
      }
      if (parameters.eTag === null || parameters.eTag === undefined) {
        return callback(new Error('parameters.eTag cannot be null.'));
      }
      if (parameters.intrinsicSettings !== null && parameters.intrinsicSettings !== undefined) {
        if (parameters.intrinsicSettings.quota !== null && parameters.intrinsicSettings.quota !== undefined) {
          if (parameters.intrinsicSettings.quota.maxRecurrence !== null && parameters.intrinsicSettings.quota.maxRecurrence !== undefined) {
            if (parameters.intrinsicSettings.quota.maxRecurrence.interval === null || parameters.intrinsicSettings.quota.maxRecurrence.interval === undefined) {
              return callback(new Error('parameters.intrinsicSettings.quota.maxRecurrence.interval cannot be null.'));
            }
          }
        }
      }
      
      // Tracing
      
      // Construct URL
      var url2 = (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined ? this.client.credentials.subscriptionId.trim() : '') + '/cloudservices/' + cloudServiceName.trim() + '/resources/scheduler/JobCollections/' + jobCollectionName.trim();
      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['If-Match'] = parameters.eTag;
      httpRequest.headers['x-ms-version'] = '2013-03-01';
      
      // Serialize Request
      var requestContent = null;
      var requestDoc = {};
      
      var resourceElement = js2xml.createElement('Resource', 'http://schemas.microsoft.com/windowsazure');
      js2xml.addChildElement(requestDoc, resourceElement);
      
      if (parameters.schemaVersion !== null && parameters.schemaVersion !== undefined) {
        var schemaVersionElement = js2xml.createElement('SchemaVersion', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(schemaVersionElement, parameters.schemaVersion);
        js2xml.addChildElement(resourceElement, schemaVersionElement);
      }
      
      var eTagElement = js2xml.createElement('ETag', 'http://schemas.microsoft.com/windowsazure');
      js2xml.addChildElement(resourceElement, eTagElement);
      
      if (parameters.intrinsicSettings !== null && parameters.intrinsicSettings !== undefined) {
        var intrinsicSettingsElement = js2xml.createElement('IntrinsicSettings', 'http://schemas.microsoft.com/windowsazure');
        js2xml.addChildElement(resourceElement, intrinsicSettingsElement);
        
        var planElement = js2xml.createElement('Plan', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(planElement, parameters.intrinsicSettings.plan !== null && parameters.intrinsicSettings.plan !== undefined ? parameters.intrinsicSettings.plan.toString() : 'Standard');
        js2xml.addChildElement(intrinsicSettingsElement, planElement);
        
        if (parameters.intrinsicSettings.quota !== null && parameters.intrinsicSettings.quota !== undefined) {
          var quotaElement = js2xml.createElement('Quota', 'http://schemas.microsoft.com/windowsazure');
          js2xml.addChildElement(intrinsicSettingsElement, quotaElement);
          
          if (parameters.intrinsicSettings.quota.maxJobCount !== null && parameters.intrinsicSettings.quota.maxJobCount !== undefined) {
            var maxJobCountElement = js2xml.createElement('MaxJobCount', 'http://schemas.microsoft.com/windowsazure');
            js2xml.setElementValue(maxJobCountElement, parameters.intrinsicSettings.quota.maxJobCount.toString());
            js2xml.addChildElement(quotaElement, maxJobCountElement);
          }
          
          if (parameters.intrinsicSettings.quota.maxJobOccurrence !== null && parameters.intrinsicSettings.quota.maxJobOccurrence !== undefined) {
            var maxJobOccurrenceElement = js2xml.createElement('MaxJobOccurrence', 'http://schemas.microsoft.com/windowsazure');
            js2xml.setElementValue(maxJobOccurrenceElement, parameters.intrinsicSettings.quota.maxJobOccurrence.toString());
            js2xml.addChildElement(quotaElement, maxJobOccurrenceElement);
          }
          
          if (parameters.intrinsicSettings.quota.maxRecurrence !== null && parameters.intrinsicSettings.quota.maxRecurrence !== undefined) {
            var maxRecurrenceElement = js2xml.createElement('MaxRecurrence', 'http://schemas.microsoft.com/windowsazure');
            js2xml.addChildElement(quotaElement, maxRecurrenceElement);
            
            var frequencyElement = js2xml.createElement('Frequency', 'http://schemas.microsoft.com/windowsazure');
            js2xml.setElementValue(frequencyElement, parameters.intrinsicSettings.quota.maxRecurrence.frequency !== null && parameters.intrinsicSettings.quota.maxRecurrence.frequency !== undefined ? parameters.intrinsicSettings.quota.maxRecurrence.frequency.toString() : 'Minute');
            js2xml.addChildElement(maxRecurrenceElement, frequencyElement);
            
            var intervalElement = js2xml.createElement('Interval', 'http://schemas.microsoft.com/windowsazure');
            js2xml.setElementValue(intervalElement, parameters.intrinsicSettings.quota.maxRecurrence.interval.toString());
            js2xml.addChildElement(maxRecurrenceElement, intervalElement);
          }
        }
      }
      
      if (parameters.label !== null && parameters.label !== undefined) {
        var labelElement = js2xml.createElement('Label', 'http://schemas.microsoft.com/windowsazure');
        js2xml.setElementValue(labelElement, new Buffer(parameters.label).toString('base64'));
        js2xml.addChildElement(resourceElement, labelElement);
      }
      
      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 !== 202) {
          var error = new Error(body);
          error.statusCode = response.statusCode;
          return callback(error);
        }
        
        // Create Result
        var result = null;
        result = {};
        result.statusCode = statusCode;
        result.eTag = response.headers['etag'];
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * Determine if the JobCollection name is available to be used.
     * JobCollection names must be unique within a cloud-service.
     * 
     * @param {string} cloudServiceName The name of the cloud service.
     * 
     * @param {string} jobCollectionName A name for the JobCollection. The name
     * must be unique as scoped within the CloudService.  The name can be up to
     * 100 characters in length.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    JobCollectionOperations.prototype.checkNameAvailability = function(cloudServiceName, jobCollectionName, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (cloudServiceName === null || cloudServiceName === undefined) {
        return callback(new Error('cloudServiceName cannot be null.'));
      }
      if (jobCollectionName === null || jobCollectionName === undefined) {
        return callback(new Error('jobCollectionName cannot be null.'));
      }
      if (jobCollectionName.length > 100) {
        return callback(new Error('jobCollectionName is outside the valid range.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined ? this.client.credentials.subscriptionId.trim() : '') + '/cloudservices/' + cloudServiceName.trim() + '/resources/scheduler/JobCollections/?';
      url2 = url2 + 'op=checknameavailability';
      url2 = url2 + '&resourceName=' + encodeURIComponent(jobCollectionName.trim());
      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'] = '2013-03-01';
      
      // Send Request
      return this.client.pipeline(httpRequest, function (err, response, body) {
        if (err !== null && err !== undefined) {
          return callback(err);
        }
        var statusCode = response.statusCode;
        if (statusCode !== 200) {
          var error = new Error(body);
          error.statusCode = response.statusCode;
          return callback(error);
        }
        
        // Create Result
        var result = null;
        // Deserialize Response
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        return xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var resourceNameAvailabilityResponseElement = js2xml.getElement(responseDoc, responseDoc, 'RESOURCENAMEAVAILABILITYRESPONSE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (resourceNameAvailabilityResponseElement !== null && resourceNameAvailabilityResponseElement !== undefined) {
            var isAvailableElement = js2xml.getElement(responseDoc, resourceNameAvailabilityResponseElement, 'ISAVAILABLE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (isAvailableElement !== null && isAvailableElement !== undefined) {
              var isAvailableInstance = isAvailableElement === 'true';
              result.isAvailable = isAvailableInstance;
            }
          }
          
          result.statusCode = statusCode;
          result.requestId = response.headers['x-ms-request-id'];
          
          return callback(null, result);
        });
      });
    };
    
    /**
     * Create a job collection.
     * 
     * @param {string} cloudServiceName The name of the cloud service containing
     * the job collection.
     * 
     * @param {string} jobCollectionName The name of the job collection to create.
     * 
     * @param {JobCollectionCreateParameters} parameters Parameters supplied to
     * the Create Job Collection operation.
     * 
     * @param {string} [parameters.schemaVersion] The version of the Intrinsic
     * Properties for your Resource. If not specified, you must conform to the
     * contract resource version you registered as default.
     * 
     * @param {string} [parameters.label] Label for the resource.
     * 
     * @param {JobCollectionIntrinsicSettings} [parameters.intrinsicSettings]
     * Intrinsic settings for the scheduler job collections.
     * 
     * @param {JobCollectionPlan} [parameters.intrinsicSettings.plan] The plan of
     * the resource.
     * 
     * @param {JobCollectionQuota} [parameters.intrinsicSettings.quota] Quota
     * settings for the job collection.
     * 
     * @param {number} [parameters.intrinsicSettings.quota.maxJobCount] Maximum
     * number of jobs that can be created in this job collection. Maximum value
     * is dependent on the plan.
     * 
     * @param {number} [parameters.intrinsicSettings.quota.maxJobOccurrence]
     * Maximum number of occurrences for all jobs in the job collection.
     * 
     * @param {JobCollectionMaxRecurrence}
     * [parameters.intrinsicSettings.quota.maxRecurrence] Defines the maximum
     * recurrences that can be specified in any job in this job collection.
     * 
     * @param {JobCollectionRecurrenceFrequency}
     * [parameters.intrinsicSettings.quota.maxRecurrence.frequency] Defines the
     * maximum recurrences that can be specified in any job in this job
     * collection.
     * 
     * @param {number}
     * [parameters.intrinsicSettings.quota.maxRecurrence.interval] Defines the
     * interval.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    JobCollectionOperations.prototype.create = function(cloudServiceName, jobCollectionName, parameters, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      var client2 = this.client;
      
      return client2.jobCollections.beginCreating(cloudServiceName, jobCollectionName, parameters, function (err, result) {
        if (err !== null && err !== undefined) {
          return callback(err);
        }
        var delayInSeconds = 15;
        if (client2.longRunningOperationInitialTimeout >= 0) {
          delayInSeconds = client2.longRunningOperationInitialTimeout;
        }
        
        var pollOperation = function () {
          setTimeout(function () {
            return client2.getOperationStatus(result.requestId, function (err2, result2) {
              if (err2 !== null && err2 !== undefined) {
                return callback(err2);
              } else {
                if (result2.status !== 'InProgress') {
                  if (result2.status !== 'Succeeded') {
                    if (result2.error !== null && result2.error !== undefined) {
                      var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                      ex.errorCode = result2.error.code;
                      ex.errorMessage = result2.error.message;
                      return callback(ex);
                    } else {
                      var ex = new Error('');
                      return callback(ex);
                    }
                  }
                  
                  result2.eTag = result.eTag;
                  return callback(null, result2);
                } else {
                  delayInSeconds = 10;
                  if (client2.longRunningOperationRetryTimeout >= 0) {
                    delayInSeconds = client2.longRunningOperationRetryTimeout;
                  }
                  pollOperation();
                }
              }
            });
          }, delayInSeconds * 1000);
        };
        
        pollOperation();
      });
    };
    
    /**
     * Deletes a job collection.
     * 
     * @param {string} cloudServiceName The name of the cloud service.
     * 
     * @param {string} jobCollectionName The name of the job collection to delete.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    JobCollectionOperations.prototype.delete = function(cloudServiceName, jobCollectionName, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      var client2 = this.client;
      
      return client2.jobCollections.beginDeleting(cloudServiceName, jobCollectionName, function (err, result) {
        if (err !== null && err !== undefined) {
          return callback(err);
        }
        var delayInSeconds = 15;
        if (client2.longRunningOperationInitialTimeout >= 0) {
          delayInSeconds = client2.longRunningOperationInitialTimeout;
        }
        
        var pollOperation = function () {
          setTimeout(function () {
            return client2.getOperationStatus(result.requestId, function (err2, result2) {
              if (err2 !== null && err2 !== undefined) {
                return callback(err2);
              } else {
                if (result2.status !== 'InProgress') {
                  if (result2.status !== 'Succeeded') {
                    if (result2.error !== null && result2.error !== undefined) {
                      var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                      ex.errorCode = result2.error.code;
                      ex.errorMessage = result2.error.message;
                      return callback(ex);
                    } else {
                      var ex = new Error('');
                      return callback(ex);
                    }
                  }
                  
                  return callback(null, result2);
                } else {
                  delayInSeconds = 10;
                  if (client2.longRunningOperationRetryTimeout >= 0) {
                    delayInSeconds = client2.longRunningOperationRetryTimeout;
                  }
                  pollOperation();
                }
              }
            });
          }, delayInSeconds * 1000);
        };
        
        pollOperation();
      });
    };
    
    /**
     * Retreive a job collection.
     * 
     * @param {string} cloudServiceName Name of the cloud service.
     * 
     * @param {string} jobCollectionName Name of the job collection.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    JobCollectionOperations.prototype.get = function(cloudServiceName, jobCollectionName, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (cloudServiceName === null || cloudServiceName === undefined) {
        return callback(new Error('cloudServiceName cannot be null.'));
      }
      if (jobCollectionName === null || jobCollectionName === undefined) {
        return callback(new Error('jobCollectionName cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined ? this.client.credentials.subscriptionId.trim() : '') + '/cloudservices/' + cloudServiceName.trim() + '/resources/scheduler/~/JobCollections/' + jobCollectionName.trim();
      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'] = '2013-03-01';
      
      // Send Request
      return this.client.pipeline(httpRequest, function (err, response, body) {
        if (err !== null && err !== undefined) {
          return callback(err);
        }
        var statusCode = response.statusCode;
        if (statusCode !== 200) {
          var error = new Error(body);
          error.statusCode = response.statusCode;
          return callback(error);
        }
        
        // Create Result
        var result = null;
        // Deserialize Response
        var responseContent = body;
        result = {};
        var options = {};
        options.trim = false;
        options.strict = false;
        return xml.parseString(responseContent, options, function (err2, responseDoc) {
          if (err2 !== null && err2 !== undefined) {
            return callback(err2);
          }
          
          var resourceElement = js2xml.getElement(responseDoc, responseDoc, 'RESOURCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
          if (resourceElement !== null && resourceElement !== undefined) {
            var nameElement = js2xml.getElement(responseDoc, resourceElement, 'NAME', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (nameElement !== null && nameElement !== undefined) {
              var nameInstance = nameElement;
              result.name = nameInstance;
            }
            
            var eTagElement = js2xml.getElement(responseDoc, resourceElement, 'ETAG', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (eTagElement !== null && eTagElement !== undefined) {
              var eTagInstance = eTagElement;
              result.eTag = eTagInstance;
            }
            
            var stateElement = js2xml.getElement(responseDoc, resourceElement, 'STATE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (stateElement !== null && stateElement !== undefined) {
              var stateInstance = stateElement;
              result.state = stateInstance;
            }
            
            var schemaVersionElement = js2xml.getElement(responseDoc, resourceElement, 'SCHEMAVERSION', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (schemaVersionElement !== null && schemaVersionElement !== undefined) {
              var schemaVersionInstance = schemaVersionElement;
              result.schemaVersion = schemaVersionInstance;
            }
            
            var promotionCodeElement = js2xml.getElement(responseDoc, resourceElement, 'PROMOTIONCODE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (promotionCodeElement !== null && promotionCodeElement !== undefined) {
              var promotionCodeInstance = promotionCodeElement;
              result.promotionCode = promotionCodeInstance;
            }
            
            var intrinsicSettingsElement = js2xml.getElement(responseDoc, resourceElement, 'INTRINSICSETTINGS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (intrinsicSettingsElement !== null && intrinsicSettingsElement !== undefined) {
              var intrinsicSettingsInstance = {};
              result.intrinsicSettings = intrinsicSettingsInstance;
              
              var planElement = js2xml.getElement(responseDoc, intrinsicSettingsElement, 'PLAN', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (planElement !== null && planElement !== undefined) {
                var planInstance = planElement;
                intrinsicSettingsInstance.plan = planInstance;
              }
              
              var quotaElement = js2xml.getElement(responseDoc, intrinsicSettingsElement, 'QUOTA', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (quotaElement !== null && quotaElement !== undefined) {
                var quotaInstance = {};
                intrinsicSettingsInstance.quota = quotaInstance;
                
                var maxJobCountElement = js2xml.getElement(responseDoc, quotaElement, 'MAXJOBCOUNT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (maxJobCountElement !== null && maxJobCountElement !== undefined && (maxJobCountElement === null || maxJobCountElement === undefined || maxJobCountElement.length === 0) === false) {
                  var maxJobCountInstance = parseInt(maxJobCountElement, 10);
                  quotaInstance.maxJobCount = maxJobCountInstance;
                }
                
                var maxJobOccurrenceElement = js2xml.getElement(responseDoc, quotaElement, 'MAXJOBOCCURRENCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (maxJobOccurrenceElement !== null && maxJobOccurrenceElement !== undefined && (maxJobOccurrenceElement === null || maxJobOccurrenceElement === undefined || maxJobOccurrenceElement.length === 0) === false) {
                  var maxJobOccurrenceInstance = parseInt(maxJobOccurrenceElement, 10);
                  quotaInstance.maxJobOccurrence = maxJobOccurrenceInstance;
                }
                
                var maxRecurrenceElement = js2xml.getElement(responseDoc, quotaElement, 'MAXRECURRENCE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (maxRecurrenceElement !== null && maxRecurrenceElement !== undefined) {
                  var maxRecurrenceInstance = {};
                  quotaInstance.maxRecurrence = maxRecurrenceInstance;
                  
                  var frequencyElement = js2xml.getElement(responseDoc, maxRecurrenceElement, 'FREQUENCY', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (frequencyElement !== null && frequencyElement !== undefined) {
                    var frequencyInstance = frequencyElement;
                    maxRecurrenceInstance.frequency = frequencyInstance;
                  }
                  
                  var intervalElement = js2xml.getElement(responseDoc, maxRecurrenceElement, 'INTERVAL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                  if (intervalElement !== null && intervalElement !== undefined) {
                    var intervalInstance = parseInt(intervalElement, 10);
                    maxRecurrenceInstance.interval = intervalInstance;
                  }
                }
              }
            }
            
            var labelElement = js2xml.getElement(responseDoc, resourceElement, 'LABEL', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (labelElement !== null && labelElement !== undefined) {
              var labelInstance = new Buffer(labelElement, 'base64').toString('utf8');
              result.label = labelInstance;
            }
            
            var operationStatusElement = js2xml.getElement(responseDoc, resourceElement, 'OPERATIONSTATUS', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
            if (operationStatusElement !== null && operationStatusElement !== undefined) {
              var operationStatusInstance = {};
              result.lastOperationStatus = operationStatusInstance;
              
              var errorElement = js2xml.getElement(responseDoc, operationStatusElement, 'ERROR', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (errorElement !== null && errorElement !== undefined) {
                var errorInstance = {};
                operationStatusInstance.responseDetails = errorInstance;
                
                var httpCodeElement = js2xml.getElement(responseDoc, errorElement, 'HTTPCODE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (httpCodeElement !== null && httpCodeElement !== undefined) {
                  var httpCodeInstance = httpCodeElement;
                  errorInstance.statusCode = httpCodeInstance;
                }
                
                var messageElement = js2xml.getElement(responseDoc, errorElement, 'MESSAGE', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
                if (messageElement !== null && messageElement !== undefined) {
                  var messageInstance = messageElement;
                  errorInstance.message = messageInstance;
                }
              }
              
              var resultElement = js2xml.getElement(responseDoc, operationStatusElement, 'RESULT', 'HTTP://SCHEMAS.MICROSOFT.COM/WINDOWSAZURE');
              if (resultElement !== null && resultElement !== undefined) {
                var resultInstance = resultElement;
                operationStatusInstance.status = resultInstance;
              }
            }
          }
          
          result.statusCode = statusCode;
          result.requestId = response.headers['x-ms-request-id'];
          
          return callback(null, result);
        });
      });
    };
    
    /**
     * Update a job collection.
     * 
     * @param {string} cloudServiceName The name of the cloud service containing
     * the job collection.
     * 
     * @param {string} jobCollectionName The name of the job collection to update.
     * 
     * @param {JobCollectionUpdateParameters} parameters Parameters supplied to
     * the Update Job Collection operation.
     * 
     * @param {string} parameters.eTag The ETag of the job collection to update.
     * The update will fail ifthe ETag doesn't match.
     * 
     * @param {string} [parameters.schemaVersion] The version of the Intrinsic
     * Properties for your Resource. If not specified, you must conform to the
     * contract resource version you registered as default.
     * 
     * @param {string} [parameters.label] Label for the resource.
     * 
     * @param {JobCollectionIntrinsicSettings} [parameters.intrinsicSettings]
     * Intrinsic settings for the scheduler job collections.
     * 
     * @param {JobCollectionPlan} [parameters.intrinsicSettings.plan] The plan of
     * the resource.
     * 
     * @param {JobCollectionQuota} [parameters.intrinsicSettings.quota] Quota
     * settings for the job collection.
     * 
     * @param {number} [parameters.intrinsicSettings.quota.maxJobCount] Maximum
     * number of jobs that can be created in this job collection. Maximum value
     * is dependent on the plan.
     * 
     * @param {number} [parameters.intrinsicSettings.quota.maxJobOccurrence]
     * Maximum number of occurrences for all jobs in the job collection.
     * 
     * @param {JobCollectionMaxRecurrence}
     * [parameters.intrinsicSettings.quota.maxRecurrence] Defines the maximum
     * recurrences that can be specified in any job in this job collection.
     * 
     * @param {JobCollectionRecurrenceFrequency}
     * [parameters.intrinsicSettings.quota.maxRecurrence.frequency] Defines the
     * maximum recurrences that can be specified in any job in this job
     * collection.
     * 
     * @param {number}
     * [parameters.intrinsicSettings.quota.maxRecurrence.interval] Defines the
     * interval.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    JobCollectionOperations.prototype.update = function(cloudServiceName, jobCollectionName, parameters, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      var client2 = this.client;
      
      return client2.jobCollections.beginUpdating(cloudServiceName, jobCollectionName, parameters, function (err, result) {
        if (err !== null && err !== undefined) {
          return callback(err);
        }
        var delayInSeconds = 15;
        if (client2.longRunningOperationInitialTimeout >= 0) {
          delayInSeconds = client2.longRunningOperationInitialTimeout;
        }
        
        var pollOperation = function () {
          setTimeout(function () {
            return client2.getOperationStatus(result.requestId, function (err2, result2) {
              if (err2 !== null && err2 !== undefined) {
                return callback(err2);
              } else {
                if (result2.status !== 'InProgress') {
                  if (result2.status !== 'Succeeded') {
                    if (result2.error !== null && result2.error !== undefined) {
                      var ex = new Error(result2.error.code + ' : ' + result2.error.message);
                      ex.errorCode = result2.error.code;
                      ex.errorMessage = result2.error.message;
                      return callback(ex);
                    } else {
                      var ex = new Error('');
                      return callback(ex);
                    }
                  }
                  
                  result2.eTag = result.eTag;
                  return callback(null, result2);
                } else {
                  delayInSeconds = 10;
                  if (client2.longRunningOperationRetryTimeout >= 0) {
                    delayInSeconds = client2.longRunningOperationRetryTimeout;
                  }
                  pollOperation();
                }
              }
            });
          }, delayInSeconds * 1000);
        };
        
        pollOperation();
      });
    };
    
    return JobCollectionOperations;
  })();
  