/* 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.

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

var WebSiteExtensionsClient = ( /** @lends WebSiteExtensionsClient */ function() {
  /**
   * @class
   * TBD.
   * Initializes a new instance of the WebSiteExtensionsClient class.
   * @constructor
   * 
   * @param {string} siteName The site name.
   * 
   * @param {BasicAuthenticationCloudCredentials} credentials TBD.
   * 
   * @param {string} [credentials.siteName]
   * 
   * @param {string} [credentials.username]
   * 
   * @param {string} [credentials.password]
   * 
   * @param {string} [baseUri] The URI used as the base for all kudu requests.
   */
  function WebSiteExtensionsClient(siteName, credentials, baseUri) {
    if (siteName === null || siteName === undefined) {
      throw new Error('siteName cannot be null.');
    }
    if (credentials === null || credentials === undefined) {
      throw new Error('credentials cannot be null.');
    }
    
    WebSiteExtensionsClient['super_'].call(this, credentials);
    
    this.siteName = siteName;
    this.credentials = credentials;
    this.baseUri = baseUri;
    if (this.baseUri === null || this.baseUri === undefined) {
      this.baseUri = 'https://' + siteName + '.scm.azurewebsites.net:443';
    }
    /**
     * Provides an instance of the
     * [DeploymentOperations](-DeploymentOperations.html) object.
     * @type {object}
     */
    this.deployment = new DeploymentOperations(this);
    /**
     * Provides an instance of the
     * [DiagnosticOperations](-DiagnosticOperations.html) object.
     * @type {object}
     */
    this.diagnostics = new DiagnosticOperations(this);
    /**
     * Provides an instance of the
     * [RepositoryOperations](-RepositoryOperations.html) object.
     * @type {object}
     */
    this.repository = new RepositoryOperations(this);
    /**
     * Provides an instance of the
     * [SettingsOperations](-SettingsOperations.html) object.
     * @type {object}
     */
    this.settings = new SettingsOperations(this);
    /**
     * Provides an instance of the [WebJobOperations](-WebJobOperations.html)
     * object.
     * @type {object}
     */
    this.webJobs = new WebJobOperations(this);
  }
  
  util.inherits(WebSiteExtensionsClient, Service);
  
  
  return WebSiteExtensionsClient;
})();
exports.WebSiteExtensionsClient = WebSiteExtensionsClient;

var DeploymentOperations = ( /** @lends DeploymentOperations */ function() {
  /**
   * @class
   * Operations for managing the repositories.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [WebSiteExtensionsClient] {@link
   * WebSiteExtensionsClient~WebSiteExtensionsClient}.
   * See [deployment] {@link
   * WebSiteExtensionsClient~WebSiteExtensionsClient#deployment}.
   * Initializes a new instance of the DeploymentOperations class.
   * @constructor
   * 
   * @param {WebSiteExtensionsClient} client Reference to the service client.
   */
  function DeploymentOperations(client) {
    this.client = client;
  }
  
  /**
   * Gets a deployment for a website.
   * 
   * @param {string} deploymentId The deployment identifier.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DeploymentOperations.prototype.get = function(deploymentId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (deploymentId === null || deploymentId === undefined) {
      return callback(new Error('deploymentId cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/deployments/' + deploymentId + '?';
    url2 = url2 + 'version=2';
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      var responseDoc = JSON.parse(responseContent);
      
      if (responseDoc) {
        var deploymentInstance = {};
        result.deployment = deploymentInstance;
        
        var idValue = responseDoc['id'];
        if (idValue) {
          var idInstance = idValue;
          deploymentInstance.id = idInstance;
        }
        
        var statusValue = responseDoc['status'];
        if (statusValue) {
          var statusInstance = statusValue;
          deploymentInstance.status = statusInstance;
        }
        
        var statusTextValue = responseDoc['status_text'];
        if (statusTextValue) {
          var statusTextInstance = statusTextValue;
          deploymentInstance.statusText = statusTextInstance;
        }
        
        var authorEmailValue = responseDoc['author_email'];
        if (authorEmailValue) {
          var authorEmailInstance = authorEmailValue;
          deploymentInstance.authorEmail = authorEmailInstance;
        }
        
        var authorValue = responseDoc['author'];
        if (authorValue) {
          var authorInstance = authorValue;
          deploymentInstance.author = authorInstance;
        }
        
        var deployerValue = responseDoc['deployer'];
        if (deployerValue) {
          var deployerInstance = deployerValue;
          deploymentInstance.deployer = deployerInstance;
        }
        
        var messageValue = responseDoc['message'];
        if (messageValue) {
          var messageInstance = messageValue;
          deploymentInstance.message = messageInstance;
        }
        
        var progressValue = responseDoc['progress'];
        if (progressValue) {
          var progressInstance = progressValue;
          deploymentInstance.progress = progressInstance;
        }
        
        var receivedTimeValue = responseDoc['received_time'];
        if (receivedTimeValue) {
          var receivedTimeInstance = receivedTimeValue;
          deploymentInstance.receivedTime = receivedTimeInstance;
        }
        
        var startTimeValue = responseDoc['start_time'];
        if (startTimeValue) {
          var startTimeInstance = startTimeValue;
          deploymentInstance.startTime = startTimeInstance;
        }
        
        var endTimeValue = responseDoc['end_time'];
        if (endTimeValue) {
          var endTimeInstance = endTimeValue;
          deploymentInstance.endTime = endTimeInstance;
        }
        
        var lastSuccessEndTimeValue = responseDoc['last_success_end_time'];
        if (lastSuccessEndTimeValue) {
          var lastSuccessEndTimeInstance = lastSuccessEndTimeValue;
          deploymentInstance.lastSuccessEndTime = lastSuccessEndTimeInstance;
        }
        
        var completeValue = responseDoc['complete'];
        if (completeValue) {
          var completeInstance = completeValue;
          deploymentInstance.complete = completeInstance;
        }
        
        var activeValue = responseDoc['active'];
        if (activeValue) {
          var activeInstance = activeValue;
          deploymentInstance.active = activeInstance;
        }
        
        var isTempValue = responseDoc['is_temp'];
        if (isTempValue) {
          var isTempInstance = isTempValue;
          deploymentInstance.isTemp = isTempInstance;
        }
        
        var isReadonlyValue = responseDoc['is_readonly'];
        if (isReadonlyValue) {
          var isReadonlyInstance = isReadonlyValue;
          deploymentInstance.isReadOnly = isReadonlyInstance;
        }
        
        var urlValue = responseDoc['url'];
        if (urlValue) {
          var urlInstance = urlValue;
          deploymentInstance.url = urlInstance;
        }
        
        var logUrlValue = responseDoc['log_url'];
        if (logUrlValue) {
          var logUrlInstance = logUrlValue;
          deploymentInstance.logUrl = logUrlInstance;
        }
        
        var siteNameValue = responseDoc['site_name'];
        if (siteNameValue) {
          var siteNameInstance = siteNameValue;
          deploymentInstance.siteName = siteNameInstance;
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * List the deployments for a website.
   * 
   * @param {DeploymentListParameters} [parametersOrCallback] Additional
   * parameters.
   * 
   * @param {string} [parametersOrCallback.top] The top query criteria.
   * 
   * @param {string} [parametersOrCallback.orderBy] The order by query criteria.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DeploymentOperations.prototype.list = function(parametersOrCallback, callback) {
    var parameters = parametersOrCallback;
    if (_.isFunction(parameters)) {
      callback = parameters;
      parameters = null;
    }
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/deployments/?';
    url2 = url2 + 'version=2';
    if (parameters && parameters.top) {
      url2 = url2 + '&$top=' + encodeURIComponent(parameters.top);
    }
    if (parameters && parameters.orderBy) {
      url2 = url2 + '&$orderBy=' + encodeURIComponent(parameters.orderBy);
    }
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = { deployments: [] };
      var responseDoc = JSON.parse(responseContent);
      
      if (responseDoc) {
        var deploymentsArray = responseDoc;
        if (deploymentsArray) {
          for (var loweredIndex1 = 0; loweredIndex1 < deploymentsArray.length; loweredIndex1 = loweredIndex1 + 1) {
            var deploymentsValue = deploymentsArray[loweredIndex1];
            var deploymentInstance = {};
            result.deployments.push(deploymentInstance);
            
            var idValue = deploymentsValue['id'];
            if (idValue) {
              var idInstance = idValue;
              deploymentInstance.id = idInstance;
            }
            
            var statusValue = deploymentsValue['status'];
            if (statusValue) {
              var statusInstance = statusValue;
              deploymentInstance.status = statusInstance;
            }
            
            var statusTextValue = deploymentsValue['status_text'];
            if (statusTextValue) {
              var statusTextInstance = statusTextValue;
              deploymentInstance.statusText = statusTextInstance;
            }
            
            var authorEmailValue = deploymentsValue['author_email'];
            if (authorEmailValue) {
              var authorEmailInstance = authorEmailValue;
              deploymentInstance.authorEmail = authorEmailInstance;
            }
            
            var authorValue = deploymentsValue['author'];
            if (authorValue) {
              var authorInstance = authorValue;
              deploymentInstance.author = authorInstance;
            }
            
            var deployerValue = deploymentsValue['deployer'];
            if (deployerValue) {
              var deployerInstance = deployerValue;
              deploymentInstance.deployer = deployerInstance;
            }
            
            var messageValue = deploymentsValue['message'];
            if (messageValue) {
              var messageInstance = messageValue;
              deploymentInstance.message = messageInstance;
            }
            
            var progressValue = deploymentsValue['progress'];
            if (progressValue) {
              var progressInstance = progressValue;
              deploymentInstance.progress = progressInstance;
            }
            
            var receivedTimeValue = deploymentsValue['received_time'];
            if (receivedTimeValue) {
              var receivedTimeInstance = receivedTimeValue;
              deploymentInstance.receivedTime = receivedTimeInstance;
            }
            
            var startTimeValue = deploymentsValue['start_time'];
            if (startTimeValue) {
              var startTimeInstance = startTimeValue;
              deploymentInstance.startTime = startTimeInstance;
            }
            
            var endTimeValue = deploymentsValue['end_time'];
            if (endTimeValue) {
              var endTimeInstance = endTimeValue;
              deploymentInstance.endTime = endTimeInstance;
            }
            
            var lastSuccessEndTimeValue = deploymentsValue['last_success_end_time'];
            if (lastSuccessEndTimeValue) {
              var lastSuccessEndTimeInstance = lastSuccessEndTimeValue;
              deploymentInstance.lastSuccessEndTime = lastSuccessEndTimeInstance;
            }
            
            var completeValue = deploymentsValue['complete'];
            if (completeValue) {
              var completeInstance = completeValue;
              deploymentInstance.complete = completeInstance;
            }
            
            var activeValue = deploymentsValue['active'];
            if (activeValue) {
              var activeInstance = activeValue;
              deploymentInstance.active = activeInstance;
            }
            
            var isTempValue = deploymentsValue['is_temp'];
            if (isTempValue) {
              var isTempInstance = isTempValue;
              deploymentInstance.isTemp = isTempInstance;
            }
            
            var isReadonlyValue = deploymentsValue['is_readonly'];
            if (isReadonlyValue) {
              var isReadonlyInstance = isReadonlyValue;
              deploymentInstance.isReadOnly = isReadonlyInstance;
            }
            
            var urlValue = deploymentsValue['url'];
            if (urlValue) {
              var urlInstance = urlValue;
              deploymentInstance.url = urlInstance;
            }
            
            var logUrlValue = deploymentsValue['log_url'];
            if (logUrlValue) {
              var logUrlInstance = logUrlValue;
              deploymentInstance.logUrl = logUrlInstance;
            }
            
            var siteNameValue = deploymentsValue['site_name'];
            if (siteNameValue) {
              var siteNameInstance = siteNameValue;
              deploymentInstance.siteName = siteNameInstance;
            }
          }
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * List the logs for a deployment for a website.
   * 
   * @param {string} deploymentId The deployment identifier.
   * 
   * @param {DeploymentListParameters} [parametersOrCallback] Additional
   * parameters.
   * 
   * @param {string} [parametersOrCallback.top] The top query criteria.
   * 
   * @param {string} [parametersOrCallback.orderBy] The order by query criteria.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DeploymentOperations.prototype.listLogs = function(deploymentId, parametersOrCallback, callback) {
    var parameters = parametersOrCallback;
    if (_.isFunction(parameters)) {
      callback = parameters;
      parameters = null;
    }
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (deploymentId === null || deploymentId === undefined) {
      return callback(new Error('deploymentId cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/deployments/?';
    url2 = url2 + 'version=2';
    if (parameters && parameters.top) {
      url2 = url2 + '&$top=' + encodeURIComponent(parameters.top);
    }
    if (parameters && parameters.orderBy) {
      url2 = url2 + '&$orderBy=' + encodeURIComponent(parameters.orderBy);
    }
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = { deployments: [] };
      var responseDoc = JSON.parse(responseContent);
      
      if (responseDoc) {
        var deploymentsArray = responseDoc;
        if (deploymentsArray) {
          for (var loweredIndex1 = 0; loweredIndex1 < deploymentsArray.length; loweredIndex1 = loweredIndex1 + 1) {
            var deploymentsValue = deploymentsArray[loweredIndex1];
            var deploymentInstance = {};
            result.deployments.push(deploymentInstance);
            
            var idValue = deploymentsValue['id'];
            if (idValue) {
              var idInstance = idValue;
              deploymentInstance.id = idInstance;
            }
            
            var statusValue = deploymentsValue['status'];
            if (statusValue) {
              var statusInstance = statusValue;
              deploymentInstance.status = statusInstance;
            }
            
            var statusTextValue = deploymentsValue['status_text'];
            if (statusTextValue) {
              var statusTextInstance = statusTextValue;
              deploymentInstance.statusText = statusTextInstance;
            }
            
            var authorEmailValue = deploymentsValue['author_email'];
            if (authorEmailValue) {
              var authorEmailInstance = authorEmailValue;
              deploymentInstance.authorEmail = authorEmailInstance;
            }
            
            var authorValue = deploymentsValue['author'];
            if (authorValue) {
              var authorInstance = authorValue;
              deploymentInstance.author = authorInstance;
            }
            
            var deployerValue = deploymentsValue['deployer'];
            if (deployerValue) {
              var deployerInstance = deployerValue;
              deploymentInstance.deployer = deployerInstance;
            }
            
            var messageValue = deploymentsValue['message'];
            if (messageValue) {
              var messageInstance = messageValue;
              deploymentInstance.message = messageInstance;
            }
            
            var progressValue = deploymentsValue['progress'];
            if (progressValue) {
              var progressInstance = progressValue;
              deploymentInstance.progress = progressInstance;
            }
            
            var receivedTimeValue = deploymentsValue['received_time'];
            if (receivedTimeValue) {
              var receivedTimeInstance = receivedTimeValue;
              deploymentInstance.receivedTime = receivedTimeInstance;
            }
            
            var startTimeValue = deploymentsValue['start_time'];
            if (startTimeValue) {
              var startTimeInstance = startTimeValue;
              deploymentInstance.startTime = startTimeInstance;
            }
            
            var endTimeValue = deploymentsValue['end_time'];
            if (endTimeValue) {
              var endTimeInstance = endTimeValue;
              deploymentInstance.endTime = endTimeInstance;
            }
            
            var lastSuccessEndTimeValue = deploymentsValue['last_success_end_time'];
            if (lastSuccessEndTimeValue) {
              var lastSuccessEndTimeInstance = lastSuccessEndTimeValue;
              deploymentInstance.lastSuccessEndTime = lastSuccessEndTimeInstance;
            }
            
            var completeValue = deploymentsValue['complete'];
            if (completeValue) {
              var completeInstance = completeValue;
              deploymentInstance.complete = completeInstance;
            }
            
            var activeValue = deploymentsValue['active'];
            if (activeValue) {
              var activeInstance = activeValue;
              deploymentInstance.active = activeInstance;
            }
            
            var isTempValue = deploymentsValue['is_temp'];
            if (isTempValue) {
              var isTempInstance = isTempValue;
              deploymentInstance.isTemp = isTempInstance;
            }
            
            var isReadonlyValue = deploymentsValue['is_readonly'];
            if (isReadonlyValue) {
              var isReadonlyInstance = isReadonlyValue;
              deploymentInstance.isReadOnly = isReadonlyInstance;
            }
            
            var urlValue = deploymentsValue['url'];
            if (urlValue) {
              var urlInstance = urlValue;
              deploymentInstance.url = urlInstance;
            }
            
            var logUrlValue = deploymentsValue['log_url'];
            if (logUrlValue) {
              var logUrlInstance = logUrlValue;
              deploymentInstance.logUrl = logUrlInstance;
            }
            
            var siteNameValue = deploymentsValue['site_name'];
            if (siteNameValue) {
              var siteNameInstance = siteNameValue;
              deploymentInstance.siteName = siteNameInstance;
            }
          }
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Redeploys a specific website deployment.
   * 
   * @param {string} deploymentId The deployment identifier.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DeploymentOperations.prototype.reploy = function(deploymentId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (deploymentId === null || deploymentId === undefined) {
      return callback(new Error('deploymentId cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/deployments/' + deploymentId + '?';
    url2 = url2 + 'version=2';
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      var responseDoc = JSON.parse(responseContent);
      
      if (responseDoc) {
        var deploymentInstance = {};
        result.deployment = deploymentInstance;
        
        var idValue = responseDoc['id'];
        if (idValue) {
          var idInstance = idValue;
          deploymentInstance.id = idInstance;
        }
        
        var statusValue = responseDoc['status'];
        if (statusValue) {
          var statusInstance = statusValue;
          deploymentInstance.status = statusInstance;
        }
        
        var statusTextValue = responseDoc['status_text'];
        if (statusTextValue) {
          var statusTextInstance = statusTextValue;
          deploymentInstance.statusText = statusTextInstance;
        }
        
        var authorEmailValue = responseDoc['author_email'];
        if (authorEmailValue) {
          var authorEmailInstance = authorEmailValue;
          deploymentInstance.authorEmail = authorEmailInstance;
        }
        
        var authorValue = responseDoc['author'];
        if (authorValue) {
          var authorInstance = authorValue;
          deploymentInstance.author = authorInstance;
        }
        
        var deployerValue = responseDoc['deployer'];
        if (deployerValue) {
          var deployerInstance = deployerValue;
          deploymentInstance.deployer = deployerInstance;
        }
        
        var messageValue = responseDoc['message'];
        if (messageValue) {
          var messageInstance = messageValue;
          deploymentInstance.message = messageInstance;
        }
        
        var progressValue = responseDoc['progress'];
        if (progressValue) {
          var progressInstance = progressValue;
          deploymentInstance.progress = progressInstance;
        }
        
        var receivedTimeValue = responseDoc['received_time'];
        if (receivedTimeValue) {
          var receivedTimeInstance = receivedTimeValue;
          deploymentInstance.receivedTime = receivedTimeInstance;
        }
        
        var startTimeValue = responseDoc['start_time'];
        if (startTimeValue) {
          var startTimeInstance = startTimeValue;
          deploymentInstance.startTime = startTimeInstance;
        }
        
        var endTimeValue = responseDoc['end_time'];
        if (endTimeValue) {
          var endTimeInstance = endTimeValue;
          deploymentInstance.endTime = endTimeInstance;
        }
        
        var lastSuccessEndTimeValue = responseDoc['last_success_end_time'];
        if (lastSuccessEndTimeValue) {
          var lastSuccessEndTimeInstance = lastSuccessEndTimeValue;
          deploymentInstance.lastSuccessEndTime = lastSuccessEndTimeInstance;
        }
        
        var completeValue = responseDoc['complete'];
        if (completeValue) {
          var completeInstance = completeValue;
          deploymentInstance.complete = completeInstance;
        }
        
        var activeValue = responseDoc['active'];
        if (activeValue) {
          var activeInstance = activeValue;
          deploymentInstance.active = activeInstance;
        }
        
        var isTempValue = responseDoc['is_temp'];
        if (isTempValue) {
          var isTempInstance = isTempValue;
          deploymentInstance.isTemp = isTempInstance;
        }
        
        var isReadonlyValue = responseDoc['is_readonly'];
        if (isReadonlyValue) {
          var isReadonlyInstance = isReadonlyValue;
          deploymentInstance.isReadOnly = isReadonlyInstance;
        }
        
        var urlValue = responseDoc['url'];
        if (urlValue) {
          var urlInstance = urlValue;
          deploymentInstance.url = urlInstance;
        }
        
        var logUrlValue = responseDoc['log_url'];
        if (logUrlValue) {
          var logUrlInstance = logUrlValue;
          deploymentInstance.logUrl = logUrlInstance;
        }
        
        var siteNameValue = responseDoc['site_name'];
        if (siteNameValue) {
          var siteNameInstance = siteNameValue;
          deploymentInstance.siteName = siteNameInstance;
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return DeploymentOperations;
})();

var DiagnosticOperations = ( /** @lends DiagnosticOperations */ function() {
  /**
   * @class
   * Operations for managing the diagnostics settings.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [WebSiteExtensionsClient] {@link
   * WebSiteExtensionsClient~WebSiteExtensionsClient}.
   * See [diagnostics] {@link
   * WebSiteExtensionsClient~WebSiteExtensionsClient#diagnostics}.
   * Initializes a new instance of the DiagnosticOperations class.
   * @constructor
   * 
   * @param {WebSiteExtensionsClient} client Reference to the service client.
   */
  function DiagnosticOperations(client) {
    this.client = client;
  }
  
  
  return DiagnosticOperations;
})();

var RepositoryOperations = ( /** @lends RepositoryOperations */ function() {
  /**
   * @class
   * Operations for managing the repository.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [WebSiteExtensionsClient] {@link
   * WebSiteExtensionsClient~WebSiteExtensionsClient}.
   * See [repository] {@link
   * WebSiteExtensionsClient~WebSiteExtensionsClient#repository}.
   * Initializes a new instance of the RepositoryOperations class.
   * @constructor
   * 
   * @param {WebSiteExtensionsClient} client Reference to the service client.
   */
  function RepositoryOperations(client) {
    this.client = client;
  }
  
  /**
   * Deletes the repository.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RepositoryOperations.prototype.delete = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/scm?';
    url2 = url2 + 'version=2';
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Get diagnostics settings.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RepositoryOperations.prototype.getSettings = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/diagnostics/settings/?';
    url2 = url2 + 'version=2';
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      result = { settings: {} };
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Update diagnostics settings.
   * 
   * @param {object} settings The diagnostics setting information new values.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  RepositoryOperations.prototype.update = function(settings, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (settings === null || settings === undefined) {
      return callback(new Error('settings cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/diagnostics/settings/?';
    url2 = url2 + 'version=2';
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return RepositoryOperations;
})();

var SettingsOperations = ( /** @lends SettingsOperations */ function() {
  /**
   * @class
   * Operations for managing the settings.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [WebSiteExtensionsClient] {@link
   * WebSiteExtensionsClient~WebSiteExtensionsClient}.
   * See [settings] {@link
   * WebSiteExtensionsClient~WebSiteExtensionsClient#settings}.
   * Initializes a new instance of the SettingsOperations class.
   * @constructor
   * 
   * @param {WebSiteExtensionsClient} client Reference to the service client.
   */
  function SettingsOperations(client) {
    this.client = client;
  }
  
  /**
   * Gets a setting.
   * 
   * @param {string} settingId The setting identifier.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  SettingsOperations.prototype.delete = function(settingId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (settingId === null || settingId === undefined) {
      return callback(new Error('settingId cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/settings/' + settingId + '?';
    url2 = url2 + 'version=2';
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets a setting.
   * 
   * @param {string} settingId The setting identifier.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  SettingsOperations.prototype.get = function(settingId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (settingId === null || settingId === undefined) {
      return callback(new Error('settingId cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/settings/' + settingId + '?';
    url2 = url2 + 'version=2';
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      var responseDoc = JSON.parse(responseContent);
      
      if (responseDoc) {
        var valueInstance = responseDoc;
        result.value = valueInstance;
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Lists the settings.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  SettingsOperations.prototype.list = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/settings?';
    url2 = url2 + 'version=2';
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = { settings: {} };
      var responseDoc = JSON.parse(responseContent);
      
      if (responseDoc) {
        var settingsSequenceElement = responseDoc;
        if (settingsSequenceElement) {
          for (var loweredIndex1 = 0; loweredIndex1 < settingsSequenceElement.length; loweredIndex1 = loweredIndex1 + 1) {
            var property = settingsSequenceElement[loweredIndex1];
            var settingsKey = property;
            var settingsValue = settingsSequenceElement[property];
            result.settings[settingsKey] = settingsValue;
          }
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Updates a setting.
   * 
   * @param {SettingsUpdateParameters} parameters The setting value.
   * 
   * @param {object} [parameters.settings] The setting values.
   * 
   * @param {HttpStatusCode} parameters.statusCode
   * 
   * @param {string} [parameters.requestId]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  SettingsOperations.prototype.update = 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 = this.client.baseUri + '/settings?';
    url2 = url2 + 'version=2';
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var settingsDictionary = {};
    if (parameters.settings) {
      for (var settingsKey in parameters.settings) {
        var settingsValue = parameters.settings[settingsKey];
        settingsDictionary[settingsKey] = settingsValue;
      }
    }
    requestDoc = settingsDictionary;
    
    requestContent = JSON.stringify(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) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return SettingsOperations;
})();

var WebJobOperations = ( /** @lends WebJobOperations */ function() {
  /**
   * @class
   * Operations for managing the jobs.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [WebSiteExtensionsClient] {@link
   * WebSiteExtensionsClient~WebSiteExtensionsClient}.
   * See [webJobs] {@link
   * WebSiteExtensionsClient~WebSiteExtensionsClient#webJobs}.
   * Initializes a new instance of the WebJobOperations class.
   * @constructor
   * 
   * @param {WebSiteExtensionsClient} client Reference to the service client.
   */
  function WebJobOperations(client) {
    this.client = client;
  }
  
  /**
   * Delete a continuous job.
   * 
   * @param {string} jobName The job name.
   * 
   * @param {boolean} recursive Removing the specified directory and all its
   * files and subdirectories. The value must be set to true.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  WebJobOperations.prototype.deleteContinuous = function(jobName, recursive, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (jobName === null || jobName === undefined) {
      return callback(new Error('jobName cannot be null.'));
    }
    if (recursive === null || recursive === undefined) {
      return callback(new Error('recursive cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/vfs/site/wwwroot/App_Data/jobs/continuous/' + jobName + '?';
    url2 = url2 + 'version=2';
    url2 = url2 + '&recursive=' + encodeURIComponent(recursive.toString());
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Delete a triggered job.
   * 
   * @param {string} jobName The job name.
   * 
   * @param {boolean} recursive Removing the specified directory and all its
   * files and subdirectories. The value must be set to true.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  WebJobOperations.prototype.deleteTriggered = function(jobName, recursive, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (jobName === null || jobName === undefined) {
      return callback(new Error('jobName cannot be null.'));
    }
    if (recursive === null || recursive === undefined) {
      return callback(new Error('recursive cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/vfs/site/wwwroot/App_Data/jobs/triggered/' + jobName + '?';
    url2 = url2 + 'version=2';
    url2 = url2 + '&recursive=' + encodeURIComponent(recursive.toString());
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * TBD.
   * 
   * @param {string} jobName The job name.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  WebJobOperations.prototype.get = function(jobName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (jobName === null || jobName === undefined) {
      return callback(new Error('jobName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/jobs/' + jobName + '?';
    url2 = url2 + 'version=2';
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      var responseDoc = JSON.parse(responseContent);
      
      if (responseDoc) {
        var webJobInstance = {};
        result.webJob = webJobInstance;
        
        var nameValue = responseDoc['name'];
        if (nameValue) {
          var nameInstance = nameValue;
          webJobInstance.name = nameInstance;
        }
        
        var runCommandValue = responseDoc['run_command'];
        if (runCommandValue) {
          var runCommandInstance = runCommandValue;
          webJobInstance.runCommand = runCommandInstance;
        }
        
        var typeValue = responseDoc['type'];
        if (typeValue) {
          var typeInstance = typeValue;
          webJobInstance.type = typeInstance;
        }
        
        var urlValue = responseDoc['url'];
        if (urlValue) {
          var urlInstance = urlValue;
          webJobInstance.url = urlInstance;
        }
        
        var historyUrlValue = responseDoc['history_url'];
        if (historyUrlValue) {
          var historyUrlInstance = historyUrlValue;
          webJobInstance.historyUrl = historyUrlInstance;
        }
        
        var extraInfoUrlValue = responseDoc['extra_info_url'];
        if (extraInfoUrlValue) {
          var extraInfoUrlInstance = extraInfoUrlValue;
          webJobInstance.extraInfoUrl = extraInfoUrlInstance;
        }
        
        var latestRunValue = responseDoc['latest_run'];
        if (latestRunValue) {
          var latestRunInstance = {};
          webJobInstance.latestRun = latestRunInstance;
          
          var idValue = latestRunValue['id'];
          if (idValue) {
            var idInstance = idValue;
            latestRunInstance.id = idInstance;
          }
          
          var statusValue = latestRunValue['status'];
          if (statusValue) {
            var statusInstance = statusValue;
            latestRunInstance.status = statusInstance;
          }
          
          var startTimeValue = latestRunValue['start_time'];
          if (startTimeValue) {
            var startTimeInstance = startTimeValue;
            latestRunInstance.startTime = startTimeInstance;
          }
          
          var endTimeValue = latestRunValue['end_time'];
          if (endTimeValue) {
            var endTimeInstance = endTimeValue;
            latestRunInstance.endTime = endTimeInstance;
          }
          
          var durationValue = latestRunValue['duration'];
          if (durationValue) {
            var durationInstance = durationValue;
            latestRunInstance.duration = durationInstance;
          }
          
          var outputUrlValue = latestRunValue['output_url'];
          if (outputUrlValue) {
            var outputUrlInstance = outputUrlValue;
            latestRunInstance.outputUrl = outputUrlInstance;
          }
          
          var errorUrlValue = latestRunValue['error_url'];
          if (errorUrlValue) {
            var errorUrlInstance = errorUrlValue;
            latestRunInstance.errorUrl = errorUrlInstance;
          }
          
          var urlValue2 = latestRunValue['url'];
          if (urlValue2) {
            var urlInstance2 = urlValue2;
            latestRunInstance.url = urlInstance2;
          }
        }
        
        var statusValue2 = responseDoc['status'];
        if (statusValue2) {
          var statusInstance2 = statusValue2;
          webJobInstance.status = statusInstance2;
        }
        
        var detailedStatusValue = responseDoc['detailed_status'];
        if (detailedStatusValue) {
          var detailedStatusInstance = detailedStatusValue;
          webJobInstance.detailedStatus = detailedStatusInstance;
        }
        
        var logUrlValue = responseDoc['log_url'];
        if (logUrlValue) {
          var logUrlInstance = logUrlValue;
          webJobInstance.logUrl = logUrlInstance;
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Get a continuous web job.
   * 
   * @param {string} jobName The job name.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  WebJobOperations.prototype.getContinuous = function(jobName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (jobName === null || jobName === undefined) {
      return callback(new Error('jobName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/jobs/continuous/' + jobName + '?';
    url2 = url2 + 'version=2';
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      var responseDoc = JSON.parse(responseContent);
      
      if (responseDoc) {
        var webJobInstance = {};
        result.webJob = webJobInstance;
        
        var nameValue = responseDoc['name'];
        if (nameValue) {
          var nameInstance = nameValue;
          webJobInstance.name = nameInstance;
        }
        
        var runCommandValue = responseDoc['run_command'];
        if (runCommandValue) {
          var runCommandInstance = runCommandValue;
          webJobInstance.runCommand = runCommandInstance;
        }
        
        var typeValue = responseDoc['type'];
        if (typeValue) {
          var typeInstance = typeValue;
          webJobInstance.type = typeInstance;
        }
        
        var urlValue = responseDoc['url'];
        if (urlValue) {
          var urlInstance = urlValue;
          webJobInstance.url = urlInstance;
        }
        
        var historyUrlValue = responseDoc['history_url'];
        if (historyUrlValue) {
          var historyUrlInstance = historyUrlValue;
          webJobInstance.historyUrl = historyUrlInstance;
        }
        
        var extraInfoUrlValue = responseDoc['extra_info_url'];
        if (extraInfoUrlValue) {
          var extraInfoUrlInstance = extraInfoUrlValue;
          webJobInstance.extraInfoUrl = extraInfoUrlInstance;
        }
        
        var latestRunValue = responseDoc['latest_run'];
        if (latestRunValue) {
          var latestRunInstance = {};
          webJobInstance.latestRun = latestRunInstance;
          
          var idValue = latestRunValue['id'];
          if (idValue) {
            var idInstance = idValue;
            latestRunInstance.id = idInstance;
          }
          
          var statusValue = latestRunValue['status'];
          if (statusValue) {
            var statusInstance = statusValue;
            latestRunInstance.status = statusInstance;
          }
          
          var startTimeValue = latestRunValue['start_time'];
          if (startTimeValue) {
            var startTimeInstance = startTimeValue;
            latestRunInstance.startTime = startTimeInstance;
          }
          
          var endTimeValue = latestRunValue['end_time'];
          if (endTimeValue) {
            var endTimeInstance = endTimeValue;
            latestRunInstance.endTime = endTimeInstance;
          }
          
          var durationValue = latestRunValue['duration'];
          if (durationValue) {
            var durationInstance = durationValue;
            latestRunInstance.duration = durationInstance;
          }
          
          var outputUrlValue = latestRunValue['output_url'];
          if (outputUrlValue) {
            var outputUrlInstance = outputUrlValue;
            latestRunInstance.outputUrl = outputUrlInstance;
          }
          
          var errorUrlValue = latestRunValue['error_url'];
          if (errorUrlValue) {
            var errorUrlInstance = errorUrlValue;
            latestRunInstance.errorUrl = errorUrlInstance;
          }
          
          var urlValue2 = latestRunValue['url'];
          if (urlValue2) {
            var urlInstance2 = urlValue2;
            latestRunInstance.url = urlInstance2;
          }
        }
        
        var statusValue2 = responseDoc['status'];
        if (statusValue2) {
          var statusInstance2 = statusValue2;
          webJobInstance.status = statusInstance2;
        }
        
        var detailedStatusValue = responseDoc['detailed_status'];
        if (detailedStatusValue) {
          var detailedStatusInstance = detailedStatusValue;
          webJobInstance.detailedStatus = detailedStatusInstance;
        }
        
        var logUrlValue = responseDoc['log_url'];
        if (logUrlValue) {
          var logUrlInstance = logUrlValue;
          webJobInstance.logUrl = logUrlInstance;
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Get a web job run.
   * 
   * @param {string} jobName The job name.
   * 
   * @param {string} jobRunId The job run identifier.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  WebJobOperations.prototype.getRun = function(jobName, jobRunId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (jobName === null || jobName === undefined) {
      return callback(new Error('jobName cannot be null.'));
    }
    if (jobRunId === null || jobRunId === undefined) {
      return callback(new Error('jobRunId cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/jobs/triggered/' + jobName + '/history/' + jobRunId + '?';
    url2 = url2 + 'version=2';
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      var responseDoc = JSON.parse(responseContent);
      
      if (responseDoc) {
        var jobRunInstance = {};
        result.jobRun = jobRunInstance;
        
        var idValue = responseDoc['id'];
        if (idValue) {
          var idInstance = idValue;
          jobRunInstance.id = idInstance;
        }
        
        var statusValue = responseDoc['status'];
        if (statusValue) {
          var statusInstance = statusValue;
          jobRunInstance.status = statusInstance;
        }
        
        var startTimeValue = responseDoc['start_time'];
        if (startTimeValue) {
          var startTimeInstance = startTimeValue;
          jobRunInstance.startTime = startTimeInstance;
        }
        
        var endTimeValue = responseDoc['end_time'];
        if (endTimeValue) {
          var endTimeInstance = endTimeValue;
          jobRunInstance.endTime = endTimeInstance;
        }
        
        var durationValue = responseDoc['duration'];
        if (durationValue) {
          var durationInstance = durationValue;
          jobRunInstance.duration = durationInstance;
        }
        
        var outputUrlValue = responseDoc['output_url'];
        if (outputUrlValue) {
          var outputUrlInstance = outputUrlValue;
          jobRunInstance.outputUrl = outputUrlInstance;
        }
        
        var errorUrlValue = responseDoc['error_url'];
        if (errorUrlValue) {
          var errorUrlInstance = errorUrlValue;
          jobRunInstance.errorUrl = errorUrlInstance;
        }
        
        var urlValue = responseDoc['url'];
        if (urlValue) {
          var urlInstance = urlValue;
          jobRunInstance.url = urlInstance;
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Get a triggered web job.
   * 
   * @param {string} jobName The job name.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  WebJobOperations.prototype.getTriggered = function(jobName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (jobName === null || jobName === undefined) {
      return callback(new Error('jobName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/jobs/triggered/' + jobName + '?';
    url2 = url2 + 'version=2';
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      var responseDoc = JSON.parse(responseContent);
      
      if (responseDoc) {
        var webJobInstance = {};
        result.webJob = webJobInstance;
        
        var nameValue = responseDoc['name'];
        if (nameValue) {
          var nameInstance = nameValue;
          webJobInstance.name = nameInstance;
        }
        
        var runCommandValue = responseDoc['run_command'];
        if (runCommandValue) {
          var runCommandInstance = runCommandValue;
          webJobInstance.runCommand = runCommandInstance;
        }
        
        var typeValue = responseDoc['type'];
        if (typeValue) {
          var typeInstance = typeValue;
          webJobInstance.type = typeInstance;
        }
        
        var urlValue = responseDoc['url'];
        if (urlValue) {
          var urlInstance = urlValue;
          webJobInstance.url = urlInstance;
        }
        
        var historyUrlValue = responseDoc['history_url'];
        if (historyUrlValue) {
          var historyUrlInstance = historyUrlValue;
          webJobInstance.historyUrl = historyUrlInstance;
        }
        
        var extraInfoUrlValue = responseDoc['extra_info_url'];
        if (extraInfoUrlValue) {
          var extraInfoUrlInstance = extraInfoUrlValue;
          webJobInstance.extraInfoUrl = extraInfoUrlInstance;
        }
        
        var latestRunValue = responseDoc['latest_run'];
        if (latestRunValue) {
          var latestRunInstance = {};
          webJobInstance.latestRun = latestRunInstance;
          
          var idValue = latestRunValue['id'];
          if (idValue) {
            var idInstance = idValue;
            latestRunInstance.id = idInstance;
          }
          
          var statusValue = latestRunValue['status'];
          if (statusValue) {
            var statusInstance = statusValue;
            latestRunInstance.status = statusInstance;
          }
          
          var startTimeValue = latestRunValue['start_time'];
          if (startTimeValue) {
            var startTimeInstance = startTimeValue;
            latestRunInstance.startTime = startTimeInstance;
          }
          
          var endTimeValue = latestRunValue['end_time'];
          if (endTimeValue) {
            var endTimeInstance = endTimeValue;
            latestRunInstance.endTime = endTimeInstance;
          }
          
          var durationValue = latestRunValue['duration'];
          if (durationValue) {
            var durationInstance = durationValue;
            latestRunInstance.duration = durationInstance;
          }
          
          var outputUrlValue = latestRunValue['output_url'];
          if (outputUrlValue) {
            var outputUrlInstance = outputUrlValue;
            latestRunInstance.outputUrl = outputUrlInstance;
          }
          
          var errorUrlValue = latestRunValue['error_url'];
          if (errorUrlValue) {
            var errorUrlInstance = errorUrlValue;
            latestRunInstance.errorUrl = errorUrlInstance;
          }
          
          var urlValue2 = latestRunValue['url'];
          if (urlValue2) {
            var urlInstance2 = urlValue2;
            latestRunInstance.url = urlInstance2;
          }
        }
        
        var statusValue2 = responseDoc['status'];
        if (statusValue2) {
          var statusInstance2 = statusValue2;
          webJobInstance.status = statusInstance2;
        }
        
        var detailedStatusValue = responseDoc['detailed_status'];
        if (detailedStatusValue) {
          var detailedStatusInstance = detailedStatusValue;
          webJobInstance.detailedStatus = detailedStatusInstance;
        }
        
        var logUrlValue = responseDoc['log_url'];
        if (logUrlValue) {
          var logUrlInstance = logUrlValue;
          webJobInstance.logUrl = logUrlInstance;
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * List the web jobs.
   * 
   * @param {WebJobListParameters} [parametersOrCallback] Additional parameters.
   * 
   * @param {string} [parametersOrCallback.top] The top query parameter.
   * 
   * @param {string} [parametersOrCallback.orderBy] The order by query
   * parameter.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  WebJobOperations.prototype.list = function(parametersOrCallback, callback) {
    var parameters = parametersOrCallback;
    if (_.isFunction(parameters)) {
      callback = parameters;
      parameters = null;
    }
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/jobs?';
    url2 = url2 + 'version=2';
    if (parameters && parameters.top) {
      url2 = url2 + '&$top=' + encodeURIComponent(parameters.top);
    }
    if (parameters && parameters.orderBy) {
      url2 = url2 + '&$orderBy=' + encodeURIComponent(parameters.orderBy);
    }
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = { jobs: [] };
      var responseDoc = JSON.parse(responseContent);
      
      if (responseDoc) {
        var jobsArray = responseDoc;
        if (jobsArray) {
          for (var loweredIndex1 = 0; loweredIndex1 < jobsArray.length; loweredIndex1 = loweredIndex1 + 1) {
            var jobsValue = jobsArray[loweredIndex1];
            var webJobInstance = {};
            result.jobs.push(webJobInstance);
            
            var nameValue = jobsValue['name'];
            if (nameValue) {
              var nameInstance = nameValue;
              webJobInstance.name = nameInstance;
            }
            
            var runCommandValue = jobsValue['run_command'];
            if (runCommandValue) {
              var runCommandInstance = runCommandValue;
              webJobInstance.runCommand = runCommandInstance;
            }
            
            var typeValue = jobsValue['type'];
            if (typeValue) {
              var typeInstance = typeValue;
              webJobInstance.type = typeInstance;
            }
            
            var urlValue = jobsValue['url'];
            if (urlValue) {
              var urlInstance = urlValue;
              webJobInstance.url = urlInstance;
            }
            
            var historyUrlValue = jobsValue['history_url'];
            if (historyUrlValue) {
              var historyUrlInstance = historyUrlValue;
              webJobInstance.historyUrl = historyUrlInstance;
            }
            
            var extraInfoUrlValue = jobsValue['extra_info_url'];
            if (extraInfoUrlValue) {
              var extraInfoUrlInstance = extraInfoUrlValue;
              webJobInstance.extraInfoUrl = extraInfoUrlInstance;
            }
            
            var latestRunValue = jobsValue['latest_run'];
            if (latestRunValue) {
              var latestRunInstance = {};
              webJobInstance.latestRun = latestRunInstance;
              
              var idValue = latestRunValue['id'];
              if (idValue) {
                var idInstance = idValue;
                latestRunInstance.id = idInstance;
              }
              
              var statusValue = latestRunValue['status'];
              if (statusValue) {
                var statusInstance = statusValue;
                latestRunInstance.status = statusInstance;
              }
              
              var startTimeValue = latestRunValue['start_time'];
              if (startTimeValue) {
                var startTimeInstance = startTimeValue;
                latestRunInstance.startTime = startTimeInstance;
              }
              
              var endTimeValue = latestRunValue['end_time'];
              if (endTimeValue) {
                var endTimeInstance = endTimeValue;
                latestRunInstance.endTime = endTimeInstance;
              }
              
              var durationValue = latestRunValue['duration'];
              if (durationValue) {
                var durationInstance = durationValue;
                latestRunInstance.duration = durationInstance;
              }
              
              var outputUrlValue = latestRunValue['output_url'];
              if (outputUrlValue) {
                var outputUrlInstance = outputUrlValue;
                latestRunInstance.outputUrl = outputUrlInstance;
              }
              
              var errorUrlValue = latestRunValue['error_url'];
              if (errorUrlValue) {
                var errorUrlInstance = errorUrlValue;
                latestRunInstance.errorUrl = errorUrlInstance;
              }
              
              var urlValue2 = latestRunValue['url'];
              if (urlValue2) {
                var urlInstance2 = urlValue2;
                latestRunInstance.url = urlInstance2;
              }
            }
            
            var statusValue2 = jobsValue['status'];
            if (statusValue2) {
              var statusInstance2 = statusValue2;
              webJobInstance.status = statusInstance2;
            }
            
            var detailedStatusValue = jobsValue['detailed_status'];
            if (detailedStatusValue) {
              var detailedStatusInstance = detailedStatusValue;
              webJobInstance.detailedStatus = detailedStatusInstance;
            }
            
            var logUrlValue = jobsValue['log_url'];
            if (logUrlValue) {
              var logUrlInstance = logUrlValue;
              webJobInstance.logUrl = logUrlInstance;
            }
          }
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * List the continuous web jobs.
   * 
   * @param {WebJobListParameters} [parametersOrCallback] Additional parameters.
   * 
   * @param {string} [parametersOrCallback.top] The top query parameter.
   * 
   * @param {string} [parametersOrCallback.orderBy] The order by query
   * parameter.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  WebJobOperations.prototype.listContinuous = function(parametersOrCallback, callback) {
    var parameters = parametersOrCallback;
    if (_.isFunction(parameters)) {
      callback = parameters;
      parameters = null;
    }
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/jobs/continuous?';
    url2 = url2 + 'version=2';
    if (parameters && parameters.top) {
      url2 = url2 + '&$top=' + encodeURIComponent(parameters.top);
    }
    if (parameters && parameters.orderBy) {
      url2 = url2 + '&$orderBy=' + encodeURIComponent(parameters.orderBy);
    }
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = { jobs: [] };
      var responseDoc = JSON.parse(responseContent);
      
      if (responseDoc) {
        var jobsArray = responseDoc;
        if (jobsArray) {
          for (var loweredIndex1 = 0; loweredIndex1 < jobsArray.length; loweredIndex1 = loweredIndex1 + 1) {
            var jobsValue = jobsArray[loweredIndex1];
            var webJobInstance = {};
            result.jobs.push(webJobInstance);
            
            var nameValue = jobsValue['name'];
            if (nameValue) {
              var nameInstance = nameValue;
              webJobInstance.name = nameInstance;
            }
            
            var runCommandValue = jobsValue['run_command'];
            if (runCommandValue) {
              var runCommandInstance = runCommandValue;
              webJobInstance.runCommand = runCommandInstance;
            }
            
            var typeValue = jobsValue['type'];
            if (typeValue) {
              var typeInstance = typeValue;
              webJobInstance.type = typeInstance;
            }
            
            var urlValue = jobsValue['url'];
            if (urlValue) {
              var urlInstance = urlValue;
              webJobInstance.url = urlInstance;
            }
            
            var historyUrlValue = jobsValue['history_url'];
            if (historyUrlValue) {
              var historyUrlInstance = historyUrlValue;
              webJobInstance.historyUrl = historyUrlInstance;
            }
            
            var extraInfoUrlValue = jobsValue['extra_info_url'];
            if (extraInfoUrlValue) {
              var extraInfoUrlInstance = extraInfoUrlValue;
              webJobInstance.extraInfoUrl = extraInfoUrlInstance;
            }
            
            var latestRunValue = jobsValue['latest_run'];
            if (latestRunValue) {
              var latestRunInstance = {};
              webJobInstance.latestRun = latestRunInstance;
              
              var idValue = latestRunValue['id'];
              if (idValue) {
                var idInstance = idValue;
                latestRunInstance.id = idInstance;
              }
              
              var statusValue = latestRunValue['status'];
              if (statusValue) {
                var statusInstance = statusValue;
                latestRunInstance.status = statusInstance;
              }
              
              var startTimeValue = latestRunValue['start_time'];
              if (startTimeValue) {
                var startTimeInstance = startTimeValue;
                latestRunInstance.startTime = startTimeInstance;
              }
              
              var endTimeValue = latestRunValue['end_time'];
              if (endTimeValue) {
                var endTimeInstance = endTimeValue;
                latestRunInstance.endTime = endTimeInstance;
              }
              
              var durationValue = latestRunValue['duration'];
              if (durationValue) {
                var durationInstance = durationValue;
                latestRunInstance.duration = durationInstance;
              }
              
              var outputUrlValue = latestRunValue['output_url'];
              if (outputUrlValue) {
                var outputUrlInstance = outputUrlValue;
                latestRunInstance.outputUrl = outputUrlInstance;
              }
              
              var errorUrlValue = latestRunValue['error_url'];
              if (errorUrlValue) {
                var errorUrlInstance = errorUrlValue;
                latestRunInstance.errorUrl = errorUrlInstance;
              }
              
              var urlValue2 = latestRunValue['url'];
              if (urlValue2) {
                var urlInstance2 = urlValue2;
                latestRunInstance.url = urlInstance2;
              }
            }
            
            var statusValue2 = jobsValue['status'];
            if (statusValue2) {
              var statusInstance2 = statusValue2;
              webJobInstance.status = statusInstance2;
            }
            
            var detailedStatusValue = jobsValue['detailed_status'];
            if (detailedStatusValue) {
              var detailedStatusInstance = detailedStatusValue;
              webJobInstance.detailedStatus = detailedStatusInstance;
            }
            
            var logUrlValue = jobsValue['log_url'];
            if (logUrlValue) {
              var logUrlInstance = logUrlValue;
              webJobInstance.logUrl = logUrlInstance;
            }
          }
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * List the web job runs.
   * 
   * @param {string} jobName The job name.
   * 
   * @param {WebJobRunListParameters} [parametersOrCallback] Additional
   * parameters.
   * 
   * @param {string} [parametersOrCallback.top] The top query parameter.
   * 
   * @param {string} [parametersOrCallback.orderBy] The order by query
   * parameter.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  WebJobOperations.prototype.listRuns = function(jobName, parametersOrCallback, callback) {
    var parameters = parametersOrCallback;
    if (_.isFunction(parameters)) {
      callback = parameters;
      parameters = null;
    }
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (jobName === null || jobName === undefined) {
      return callback(new Error('jobName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/jobs/triggered/' + jobName + '/history?';
    url2 = url2 + 'version=2';
    if (parameters && parameters.top) {
      url2 = url2 + '&$top=' + encodeURIComponent(parameters.top);
    }
    if (parameters && parameters.orderBy) {
      url2 = url2 + '&$orderBy=' + encodeURIComponent(parameters.orderBy);
    }
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = { jobRuns: [] };
      var responseDoc = JSON.parse(responseContent);
      
      if (responseDoc) {
        var runsArray = responseDoc['runs'];
        if (runsArray) {
          for (var loweredIndex1 = 0; loweredIndex1 < runsArray.length; loweredIndex1 = loweredIndex1 + 1) {
            var runsValue = runsArray[loweredIndex1];
            var webJobRunInstance = {};
            result.jobRuns.push(webJobRunInstance);
            
            var idValue = runsValue['id'];
            if (idValue) {
              var idInstance = idValue;
              webJobRunInstance.id = idInstance;
            }
            
            var statusValue = runsValue['status'];
            if (statusValue) {
              var statusInstance = statusValue;
              webJobRunInstance.status = statusInstance;
            }
            
            var startTimeValue = runsValue['start_time'];
            if (startTimeValue) {
              var startTimeInstance = startTimeValue;
              webJobRunInstance.startTime = startTimeInstance;
            }
            
            var endTimeValue = runsValue['end_time'];
            if (endTimeValue) {
              var endTimeInstance = endTimeValue;
              webJobRunInstance.endTime = endTimeInstance;
            }
            
            var durationValue = runsValue['duration'];
            if (durationValue) {
              var durationInstance = durationValue;
              webJobRunInstance.duration = durationInstance;
            }
            
            var outputUrlValue = runsValue['output_url'];
            if (outputUrlValue) {
              var outputUrlInstance = outputUrlValue;
              webJobRunInstance.outputUrl = outputUrlInstance;
            }
            
            var errorUrlValue = runsValue['error_url'];
            if (errorUrlValue) {
              var errorUrlInstance = errorUrlValue;
              webJobRunInstance.errorUrl = errorUrlInstance;
            }
            
            var urlValue = runsValue['url'];
            if (urlValue) {
              var urlInstance = urlValue;
              webJobRunInstance.url = urlInstance;
            }
          }
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * List the triggered web jobs.
   * 
   * @param {WebJobListParameters} [parametersOrCallback] Additional parameters.
   * 
   * @param {string} [parametersOrCallback.top] The top query parameter.
   * 
   * @param {string} [parametersOrCallback.orderBy] The order by query
   * parameter.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  WebJobOperations.prototype.listTriggered = function(parametersOrCallback, callback) {
    var parameters = parametersOrCallback;
    if (_.isFunction(parameters)) {
      callback = parameters;
      parameters = null;
    }
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/jobs/triggered?';
    url2 = url2 + 'version=2';
    if (parameters && parameters.top) {
      url2 = url2 + '&$top=' + encodeURIComponent(parameters.top);
    }
    if (parameters && parameters.orderBy) {
      url2 = url2 + '&$orderBy=' + encodeURIComponent(parameters.orderBy);
    }
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = { jobs: [] };
      var responseDoc = JSON.parse(responseContent);
      
      if (responseDoc) {
        var jobsArray = responseDoc;
        if (jobsArray) {
          for (var loweredIndex1 = 0; loweredIndex1 < jobsArray.length; loweredIndex1 = loweredIndex1 + 1) {
            var jobsValue = jobsArray[loweredIndex1];
            var webJobInstance = {};
            result.jobs.push(webJobInstance);
            
            var nameValue = jobsValue['name'];
            if (nameValue) {
              var nameInstance = nameValue;
              webJobInstance.name = nameInstance;
            }
            
            var runCommandValue = jobsValue['run_command'];
            if (runCommandValue) {
              var runCommandInstance = runCommandValue;
              webJobInstance.runCommand = runCommandInstance;
            }
            
            var typeValue = jobsValue['type'];
            if (typeValue) {
              var typeInstance = typeValue;
              webJobInstance.type = typeInstance;
            }
            
            var urlValue = jobsValue['url'];
            if (urlValue) {
              var urlInstance = urlValue;
              webJobInstance.url = urlInstance;
            }
            
            var historyUrlValue = jobsValue['history_url'];
            if (historyUrlValue) {
              var historyUrlInstance = historyUrlValue;
              webJobInstance.historyUrl = historyUrlInstance;
            }
            
            var extraInfoUrlValue = jobsValue['extra_info_url'];
            if (extraInfoUrlValue) {
              var extraInfoUrlInstance = extraInfoUrlValue;
              webJobInstance.extraInfoUrl = extraInfoUrlInstance;
            }
            
            var latestRunValue = jobsValue['latest_run'];
            if (latestRunValue) {
              var latestRunInstance = {};
              webJobInstance.latestRun = latestRunInstance;
              
              var idValue = latestRunValue['id'];
              if (idValue) {
                var idInstance = idValue;
                latestRunInstance.id = idInstance;
              }
              
              var statusValue = latestRunValue['status'];
              if (statusValue) {
                var statusInstance = statusValue;
                latestRunInstance.status = statusInstance;
              }
              
              var startTimeValue = latestRunValue['start_time'];
              if (startTimeValue) {
                var startTimeInstance = startTimeValue;
                latestRunInstance.startTime = startTimeInstance;
              }
              
              var endTimeValue = latestRunValue['end_time'];
              if (endTimeValue) {
                var endTimeInstance = endTimeValue;
                latestRunInstance.endTime = endTimeInstance;
              }
              
              var durationValue = latestRunValue['duration'];
              if (durationValue) {
                var durationInstance = durationValue;
                latestRunInstance.duration = durationInstance;
              }
              
              var outputUrlValue = latestRunValue['output_url'];
              if (outputUrlValue) {
                var outputUrlInstance = outputUrlValue;
                latestRunInstance.outputUrl = outputUrlInstance;
              }
              
              var errorUrlValue = latestRunValue['error_url'];
              if (errorUrlValue) {
                var errorUrlInstance = errorUrlValue;
                latestRunInstance.errorUrl = errorUrlInstance;
              }
              
              var urlValue2 = latestRunValue['url'];
              if (urlValue2) {
                var urlInstance2 = urlValue2;
                latestRunInstance.url = urlInstance2;
              }
            }
            
            var statusValue2 = jobsValue['status'];
            if (statusValue2) {
              var statusInstance2 = statusValue2;
              webJobInstance.status = statusInstance2;
            }
            
            var detailedStatusValue = jobsValue['detailed_status'];
            if (detailedStatusValue) {
              var detailedStatusInstance = detailedStatusValue;
              webJobInstance.detailedStatus = detailedStatusInstance;
            }
            
            var logUrlValue = jobsValue['log_url'];
            if (logUrlValue) {
              var logUrlInstance = logUrlValue;
              webJobInstance.logUrl = logUrlInstance;
            }
          }
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Run a triggered web job.
   * 
   * @param {string} jobName The job name.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  WebJobOperations.prototype.runTriggered = function(jobName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (jobName === null || jobName === undefined) {
      return callback(new Error('jobName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/jobs/triggered/' + jobName + '/run?';
    url2 = url2 + 'version=2';
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 202) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * If a continuous job is set as singleton it'll run only on a single
   * instance opposed to running on all instances.
   * 
   * @param {string} jobName The job name.
   * 
   * @param {boolean} isSingleton Boolean value indicating if the job is
   * singleton or not.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  WebJobOperations.prototype.setSingleton = function(jobName, isSingleton, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (jobName === null || jobName === undefined) {
      return callback(new Error('jobName cannot be null.'));
    }
    if (isSingleton === null || isSingleton === undefined) {
      return callback(new Error('isSingleton cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/jobs/continuous/' + jobName + '/singleton?';
    url2 = url2 + 'isSingleton=' + encodeURIComponent(isSingleton.toString());
    url2 = url2 + '&version=2';
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Start a continuous web job.
   * 
   * @param {string} jobName The job name.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  WebJobOperations.prototype.startContinuous = function(jobName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (jobName === null || jobName === undefined) {
      return callback(new Error('jobName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/jobs/continuous/' + jobName + '/start/?';
    url2 = url2 + 'version=2';
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Stop a continuous web job.
   * 
   * @param {string} jobName The job name.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  WebJobOperations.prototype.stopContinuous = function(jobName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (jobName === null || jobName === undefined) {
      return callback(new Error('jobName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/jobs/continuous/' + jobName + '/stop/?';
    url2 = url2 + 'version=2';
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Upload a continuous web job.
   * 
   * @param {string} jobName The job name.
   * 
   * @param {Stream} jobContent The job content.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  WebJobOperations.prototype.uploadContinuous = function(jobName, jobContent, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (jobName === null || jobName === undefined) {
      return callback(new Error('jobName cannot be null.'));
    }
    if (jobContent === null || jobContent === undefined) {
      return callback(new Error('jobContent cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/zip/site/wwwroot/App_Data/jobs/continuous/' + jobName + '/?';
    url2 = url2 + 'version=2';
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/octet-stream';
    
    // Serialize Request
    var requestContent = jobContent;
    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) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Upload a triggered web job.
   * 
   * @param {string} jobName The job name.
   * 
   * @param {Stream} jobContent The job content.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  WebJobOperations.prototype.uploadTriggered = function(jobName, jobContent, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (jobName === null || jobName === undefined) {
      return callback(new Error('jobName cannot be null.'));
    }
    if (jobContent === null || jobContent === undefined) {
      return callback(new Error('jobContent cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = this.client.baseUri + '/zip/site/wwwroot/App_Data/jobs/triggered/' + jobName + '/?';
    url2 = url2 + 'version=2';
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/octet-stream';
    
    // Serialize Request
    var requestContent = jobContent;
    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) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        return callback(body);
      }
      
      // Create Result
      var result = null;
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return WebJobOperations;
})();
