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

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

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

'use strict';

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

var WebSiteExtensionsClient = ( /** @lends WebSiteExtensionsClient */ function() {
  /**
   * @class
   * The websites extensions client manages the web sites deployments, web jobs
   * and other extensions.
   * 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] Gets the URI used as the base for all cloud
   * service requests.
   * 
   * @param {Array} filters
   */
  function WebSiteExtensionsClient(siteName, credentials, baseUri, filters) {
    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, filters);
    
    this.siteName = siteName;
    this.credentials = credentials;
    this.baseUri = baseUri;
    if (this.baseUri === null || this.baseUri === undefined) {
      this.baseUri = 'https://' + this.siteName + '.scm.azurewebsites.net:443';
    }
    if (this.apiVersion === null || this.apiVersion === undefined) {
      this.apiVersion = '2';
    }
    if (this.longRunningOperationInitialTimeout === null || this.longRunningOperationInitialTimeout === undefined) {
      this.longRunningOperationInitialTimeout = -1;
    }
    if (this.longRunningOperationRetryTimeout === null || this.longRunningOperationRetryTimeout === undefined) {
      this.longRunningOperationRetryTimeout = -1;
    }
    /**
     * Provides an instance of the
     * [CommandsOperations](-CommandsOperations.html) object.
     * @type {object}
     */
    this.commands = new CommandsOperations(this);
    /**
     * Provides an instance of the
     * [ContinuousWebJobOperations](-ContinuousWebJobOperations.html) object.
     * @type {object}
     */
    this.continuousWebJobs = new ContinuousWebJobOperations(this);
    /**
     * Provides an instance of the
     * [DeploymentOperations](-DeploymentOperations.html) object.
     * @type {object}
     */
    this.deployments = 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
     * [TriggeredWebJobOperations](-TriggeredWebJobOperations.html) object.
     * @type {object}
     */
    this.triggeredWebJobs = new TriggeredWebJobOperations(this);
  }
  
  util.inherits(WebSiteExtensionsClient, Service);
  
  
  return WebSiteExtensionsClient;
})();
exports.WebSiteExtensionsClient = WebSiteExtensionsClient;

var CommandsOperations = ( /** @lends CommandsOperations */ function() {
  /**
   * @class
   * Operations for invoking commands.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [WebSiteExtensionsClient] {@link
   * WebSiteExtensionsClient~WebSiteExtensionsClient}.
   * See [commands] {@link
   * WebSiteExtensionsClient~WebSiteExtensionsClient#commands}.
   * Initializes a new instance of the CommandsOperations class.
   * @constructor
   * 
   * @param {WebSiteExtensionsClient} client Reference to the service client.
   */
  function CommandsOperations(client) {
    this.client = client;
  }
  
  /**
   * Invoke a command on the website's VM.
   * 
   * @param {InvokeCommandParameters} parameters The invoke command parameters.
   * 
   * @param {string} [parameters.command] The command to invoke.
   * 
   * @param {string} [parameters.directory] The directory to invoke command in.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  CommandsOperations.prototype.invoke = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/api/command';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var invokeCommandParametersValue = {};
    requestDoc = invokeCommandParametersValue;
    
    if (parameters.command !== null && parameters.command !== undefined) {
      invokeCommandParametersValue['command'] = parameters.command;
    }
    
    if (parameters.directory !== null && parameters.directory !== undefined) {
      invokeCommandParametersValue['dir'] = parameters.directory;
    }
    
    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 !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var commandResultInstance = {};
          result.commandResult = commandResultInstance;
          
          var outputValue = responseDoc['Output'];
          if (outputValue !== null && outputValue !== undefined) {
            var outputInstance = outputValue;
            commandResultInstance.output = outputInstance;
          }
          
          var errorValue = responseDoc['Error'];
          if (errorValue !== null && errorValue !== undefined) {
            var errorInstance = errorValue;
            commandResultInstance.error = errorInstance;
          }
          
          var exitCodeValue = responseDoc['ExitCode'];
          if (exitCodeValue !== null && exitCodeValue !== undefined) {
            var exitCodeInstance = exitCodeValue;
            commandResultInstance.exitCode = exitCodeInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return CommandsOperations;
})();

var ContinuousWebJobOperations = ( /** @lends ContinuousWebJobOperations */ function() {
  /**
   * @class
   * Operations for managing continuous WebJobs.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [WebSiteExtensionsClient] {@link
   * WebSiteExtensionsClient~WebSiteExtensionsClient}.
   * See [continuousWebJobs] {@link
   * WebSiteExtensionsClient~WebSiteExtensionsClient#continuousWebJobs}.
   * Initializes a new instance of the ContinuousWebJobOperations class.
   * @constructor
   * 
   * @param {WebSiteExtensionsClient} client Reference to the service client.
   */
  function ContinuousWebJobOperations(client) {
    this.client = client;
  }
  
  /**
   * Delete a continuous job.
   * 
   * @param {string} jobName The continuous WebJob name.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ContinuousWebJobOperations.prototype.deleteMethod = 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 = '';
    url2 = url2 + '/api/jobs/continuous/';
    url2 = url2 + encodeURIComponent(jobName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Get a continuous WebJob.
   * 
   * @param {string} jobName The continuous WebJob name.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ContinuousWebJobOperations.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 = '';
    url2 = url2 + '/api/jobs/continuous/';
    url2 = url2 + encodeURIComponent(jobName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var continuousWebJobInstance = {};
          result.continuousWebJob = continuousWebJobInstance;
          
          var logUrlValue = responseDoc['log_url'];
          if (logUrlValue !== null && logUrlValue !== undefined) {
            var logUrlInstance = logUrlValue;
            continuousWebJobInstance.logUrl = logUrlInstance;
          }
          
          var statusValue = responseDoc['status'];
          if (statusValue !== null && statusValue !== undefined) {
            var statusInstance = statusValue;
            continuousWebJobInstance.status = statusInstance;
          }
          
          var detailedStatusValue = responseDoc['detailed_status'];
          if (detailedStatusValue !== null && detailedStatusValue !== undefined) {
            var detailedStatusInstance = detailedStatusValue;
            continuousWebJobInstance.detailedStatus = detailedStatusInstance;
          }
          
          var nameValue = responseDoc['name'];
          if (nameValue !== null && nameValue !== undefined) {
            var nameInstance = nameValue;
            continuousWebJobInstance.name = nameInstance;
          }
          
          var runCommandValue = responseDoc['run_command'];
          if (runCommandValue !== null && runCommandValue !== undefined) {
            var runCommandInstance = runCommandValue;
            continuousWebJobInstance.runCommand = runCommandInstance;
          }
          
          var typeValue = responseDoc['type'];
          if (typeValue !== null && typeValue !== undefined) {
            var typeInstance = typeValue;
            continuousWebJobInstance.type = typeInstance;
          }
          
          var urlValue = responseDoc['url'];
          if (urlValue !== null && urlValue !== undefined) {
            var urlInstance = urlValue;
            continuousWebJobInstance.url = urlInstance;
          }
          
          var extraInfoUrlValue = responseDoc['extra_info_url'];
          if (extraInfoUrlValue !== null && extraInfoUrlValue !== undefined) {
            var extraInfoUrlInstance = extraInfoUrlValue;
            continuousWebJobInstance.extraInfoUrl = extraInfoUrlInstance;
          }
          
          var errorValue = responseDoc['error'];
          if (errorValue !== null && errorValue !== undefined) {
            var errorInstance = errorValue;
            continuousWebJobInstance.error = errorInstance;
          }
          
          var usingSdkValue = responseDoc['using_sdk'];
          if (usingSdkValue !== null && usingSdkValue !== undefined) {
            var usingSdkInstance = usingSdkValue;
            continuousWebJobInstance.usingSdk = usingSdkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Get the settings of a continuous WebJob.
   * 
   * @param {string} jobName The continuous WebJob name.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ContinuousWebJobOperations.prototype.getSettings = 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 = '';
    url2 = url2 + '/api/jobs/continuous/';
    url2 = url2 + encodeURIComponent(jobName);
    url2 = url2 + '/settings';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var isSingletonValue = responseDoc['IsSingleton'];
          if (isSingletonValue !== null && isSingletonValue !== undefined) {
            var isSingletonInstance = isSingletonValue;
            result.isSingleton = isSingletonInstance;
          }
          
          var shutdownGraceTimeInSecondsValue = responseDoc['ShutdownGraceTimeInSeconds'];
          if (shutdownGraceTimeInSecondsValue !== null && shutdownGraceTimeInSecondsValue !== undefined) {
            var shutdownGraceTimeInSecondsInstance = shutdownGraceTimeInSecondsValue;
            result.shutdownGraceTimeInSeconds = shutdownGraceTimeInSecondsInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * List the continuous web jobs.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ContinuousWebJobOperations.prototype.list = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/api/jobs/continuous';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { continuousWebJobs: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var continuousWebJobsArray = responseDoc;
          if (continuousWebJobsArray !== null && continuousWebJobsArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < continuousWebJobsArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var continuousWebJobsValue = continuousWebJobsArray[loweredIndex1];
              var continuousWebJobInstance = {};
              result.continuousWebJobs.push(continuousWebJobInstance);
              
              var logUrlValue = continuousWebJobsValue['log_url'];
              if (logUrlValue !== null && logUrlValue !== undefined) {
                var logUrlInstance = logUrlValue;
                continuousWebJobInstance.logUrl = logUrlInstance;
              }
              
              var statusValue = continuousWebJobsValue['status'];
              if (statusValue !== null && statusValue !== undefined) {
                var statusInstance = statusValue;
                continuousWebJobInstance.status = statusInstance;
              }
              
              var detailedStatusValue = continuousWebJobsValue['detailed_status'];
              if (detailedStatusValue !== null && detailedStatusValue !== undefined) {
                var detailedStatusInstance = detailedStatusValue;
                continuousWebJobInstance.detailedStatus = detailedStatusInstance;
              }
              
              var nameValue = continuousWebJobsValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                continuousWebJobInstance.name = nameInstance;
              }
              
              var runCommandValue = continuousWebJobsValue['run_command'];
              if (runCommandValue !== null && runCommandValue !== undefined) {
                var runCommandInstance = runCommandValue;
                continuousWebJobInstance.runCommand = runCommandInstance;
              }
              
              var typeValue = continuousWebJobsValue['type'];
              if (typeValue !== null && typeValue !== undefined) {
                var typeInstance = typeValue;
                continuousWebJobInstance.type = typeInstance;
              }
              
              var urlValue = continuousWebJobsValue['url'];
              if (urlValue !== null && urlValue !== undefined) {
                var urlInstance = urlValue;
                continuousWebJobInstance.url = urlInstance;
              }
              
              var extraInfoUrlValue = continuousWebJobsValue['extra_info_url'];
              if (extraInfoUrlValue !== null && extraInfoUrlValue !== undefined) {
                var extraInfoUrlInstance = extraInfoUrlValue;
                continuousWebJobInstance.extraInfoUrl = extraInfoUrlInstance;
              }
              
              var errorValue = continuousWebJobsValue['error'];
              if (errorValue !== null && errorValue !== undefined) {
                var errorInstance = errorValue;
                continuousWebJobInstance.error = errorInstance;
              }
              
              var usingSdkValue = continuousWebJobsValue['using_sdk'];
              if (usingSdkValue !== null && usingSdkValue !== undefined) {
                var usingSdkInstance = usingSdkValue;
                continuousWebJobInstance.usingSdk = usingSdkInstance;
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Set the settings of a continuous WebJob (will replace the current settings
   * of the WebJob).
   * 
   * @param {string} jobName The continuous WebJob name.
   * 
   * @param {ContinuousWebJobSettingsUpdateParameters} settings The continuous
   * WebJob settings.
   * 
   * @param {boolean} [settings.isSingleton] If a continuous job is set as
   * singleton it'll run only on a single instance opposed to running on all
   * instances.
   * 
   * @param {number} [settings.shutdownGraceTimeInSeconds] Specify the time in
   * seconds to wait for the WebJob to gracefully shutdown.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ContinuousWebJobOperations.prototype.setSettings = function(jobName, settings, 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 (settings === null || settings === undefined) {
      return callback(new Error('settings cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/api/jobs/continuous/';
    url2 = url2 + encodeURIComponent(jobName);
    url2 = url2 + '/settings';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var continuousWebJobSettingsUpdateParametersValue = {};
    requestDoc = continuousWebJobSettingsUpdateParametersValue;
    
    if (settings.isSingleton !== null && settings.isSingleton !== undefined) {
      continuousWebJobSettingsUpdateParametersValue['IsSingleton'] = settings.isSingleton;
    }
    
    if (settings.shutdownGraceTimeInSeconds !== null && settings.shutdownGraceTimeInSeconds !== undefined) {
      continuousWebJobSettingsUpdateParametersValue['ShutdownGraceTimeInSeconds'] = settings.shutdownGraceTimeInSeconds;
    }
    
    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 !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Start a continuous WebJob.
   * 
   * @param {string} jobName The WebJob name.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ContinuousWebJobOperations.prototype.start = 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 = '';
    url2 = url2 + '/api/jobs/continuous/';
    url2 = url2 + encodeURIComponent(jobName);
    url2 = url2 + '/start';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Stop a continuous WebJob.
   * 
   * @param {string} jobName The WebJob name.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ContinuousWebJobOperations.prototype.stop = 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 = '';
    url2 = url2 + '/api/jobs/continuous/';
    url2 = url2 + encodeURIComponent(jobName);
    url2 = url2 + '/stop';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Create or replace a continuous WebJob with a script file (.exe, .bat,
   * .php, .js...).
   * 
   * @param {string} jobName The continuous WebJob name.
   * 
   * @param {string} fileName The file name.
   * 
   * @param {Stream} jobContent The file content.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ContinuousWebJobOperations.prototype.uploadFile = function(jobName, fileName, 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 (fileName === null || fileName === undefined) {
      return callback(new Error('fileName cannot be null.'));
    }
    if (jobContent === null || jobContent === undefined) {
      return callback(new Error('jobContent cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/api/jobs/continuous/';
    url2 = url2 + encodeURIComponent(jobName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    if (fileName !== null && fileName !== undefined) {
      httpRequest.headers['Content-Disposition'] = 'attachment; filename=' + fileName;
    }
    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 !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Create or replace a continuous WebJob with a zip file (containing the
   * WebJob binaries).
   * 
   * @param {string} jobName The continuous WebJob name.
   * 
   * @param {string} fileName The zip file name.
   * 
   * @param {Stream} jobContent The zip file content.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ContinuousWebJobOperations.prototype.uploadZip = function(jobName, fileName, 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 (fileName === null || fileName === undefined) {
      return callback(new Error('fileName cannot be null.'));
    }
    if (jobContent === null || jobContent === undefined) {
      return callback(new Error('jobContent cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/api/jobs/continuous/';
    url2 = url2 + encodeURIComponent(jobName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    if (fileName !== null && fileName !== undefined) {
      httpRequest.headers['Content-Disposition'] = 'attachment; filename=' + fileName;
    }
    httpRequest.headers['Content-Type'] = 'application/zip';
    
    // 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 !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return ContinuousWebJobOperations;
})();

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 [deployments] {@link
   * WebSiteExtensionsClient~WebSiteExtensionsClient#deployments}.
   * 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 = '';
    url2 = url2 + '/api/deployments/';
    url2 = url2 + encodeURIComponent(deploymentId);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var deploymentInstance = {};
          result.deployment = deploymentInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            deploymentInstance.id = idInstance;
          }
          
          var statusValue = responseDoc['status'];
          if (statusValue !== null && statusValue !== undefined) {
            var statusInstance = statusValue;
            deploymentInstance.status = statusInstance;
          }
          
          var statusTextValue = responseDoc['status_text'];
          if (statusTextValue !== null && statusTextValue !== undefined) {
            var statusTextInstance = statusTextValue;
            deploymentInstance.statusText = statusTextInstance;
          }
          
          var authorEmailValue = responseDoc['author_email'];
          if (authorEmailValue !== null && authorEmailValue !== undefined) {
            var authorEmailInstance = authorEmailValue;
            deploymentInstance.authorEmail = authorEmailInstance;
          }
          
          var authorValue = responseDoc['author'];
          if (authorValue !== null && authorValue !== undefined) {
            var authorInstance = authorValue;
            deploymentInstance.author = authorInstance;
          }
          
          var deployerValue = responseDoc['deployer'];
          if (deployerValue !== null && deployerValue !== undefined) {
            var deployerInstance = deployerValue;
            deploymentInstance.deployer = deployerInstance;
          }
          
          var messageValue = responseDoc['message'];
          if (messageValue !== null && messageValue !== undefined) {
            var messageInstance = messageValue;
            deploymentInstance.message = messageInstance;
          }
          
          var progressValue = responseDoc['progress'];
          if (progressValue !== null && progressValue !== undefined) {
            var progressInstance = progressValue;
            deploymentInstance.progress = progressInstance;
          }
          
          var receivedTimeValue = responseDoc['received_time'];
          if (receivedTimeValue !== null && receivedTimeValue !== undefined) {
            var receivedTimeInstance = receivedTimeValue;
            deploymentInstance.receivedTime = receivedTimeInstance;
          }
          
          var startTimeValue = responseDoc['start_time'];
          if (startTimeValue !== null && startTimeValue !== undefined) {
            var startTimeInstance = startTimeValue;
            deploymentInstance.startTime = startTimeInstance;
          }
          
          var endTimeValue = responseDoc['end_time'];
          if (endTimeValue !== null && endTimeValue !== undefined) {
            var endTimeInstance = endTimeValue;
            deploymentInstance.endTime = endTimeInstance;
          }
          
          var lastSuccessEndTimeValue = responseDoc['last_success_end_time'];
          if (lastSuccessEndTimeValue !== null && lastSuccessEndTimeValue !== undefined) {
            var lastSuccessEndTimeInstance = lastSuccessEndTimeValue;
            deploymentInstance.lastSuccessEndTime = lastSuccessEndTimeInstance;
          }
          
          var completeValue = responseDoc['complete'];
          if (completeValue !== null && completeValue !== undefined) {
            var completeInstance = completeValue;
            deploymentInstance.complete = completeInstance;
          }
          
          var activeValue = responseDoc['active'];
          if (activeValue !== null && activeValue !== undefined) {
            var activeInstance = activeValue;
            deploymentInstance.active = activeInstance;
          }
          
          var isTempValue = responseDoc['is_temp'];
          if (isTempValue !== null && isTempValue !== undefined) {
            var isTempInstance = isTempValue;
            deploymentInstance.isTemp = isTempInstance;
          }
          
          var isReadonlyValue = responseDoc['is_readonly'];
          if (isReadonlyValue !== null && isReadonlyValue !== undefined) {
            var isReadonlyInstance = isReadonlyValue;
            deploymentInstance.isReadOnly = isReadonlyInstance;
          }
          
          var urlValue = responseDoc['url'];
          if (urlValue !== null && urlValue !== undefined) {
            var urlInstance = urlValue;
            deploymentInstance.url = urlInstance;
          }
          
          var logUrlValue = responseDoc['log_url'];
          if (logUrlValue !== null && logUrlValue !== undefined) {
            var logUrlInstance = logUrlValue;
            deploymentInstance.logUrl = logUrlInstance;
          }
          
          var siteNameValue = responseDoc['site_name'];
          if (siteNameValue !== null && siteNameValue !== undefined) {
            var siteNameInstance = siteNameValue;
            deploymentInstance.siteName = siteNameInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets a deployment log for a website.
   * 
   * @param {string} deploymentId The deployment identifier.
   * 
   * @param {string} deploymentLogId The deployment log identifier.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DeploymentOperations.prototype.getLog = function(deploymentId, deploymentLogId, 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.'));
    }
    if (deploymentLogId === null || deploymentLogId === undefined) {
      return callback(new Error('deploymentLogId cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/api/deployments/';
    url2 = url2 + encodeURIComponent(deploymentId);
    url2 = url2 + '/log/';
    url2 = url2 + encodeURIComponent(deploymentLogId);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var logInstance = {};
          result.log = logInstance;
          
          var logTimeValue = responseDoc['log_time'];
          if (logTimeValue !== null && logTimeValue !== undefined) {
            var logTimeInstance = logTimeValue;
            logInstance.logTime = logTimeInstance;
          }
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            logInstance.id = idInstance;
          }
          
          var messageValue = responseDoc['message'];
          if (messageValue !== null && messageValue !== undefined) {
            var messageInstance = messageValue;
            logInstance.message = messageInstance;
          }
          
          var typeValue = responseDoc['type'];
          if (typeValue !== null && typeValue !== undefined) {
            var typeInstance = typeValue;
            logInstance.type = typeInstance;
          }
          
          var detailsUrlValue = responseDoc['details_url'];
          if (detailsUrlValue !== null && detailsUrlValue !== undefined) {
            var detailsUrlInstance = detailsUrlValue;
            logInstance.detailsUrl = detailsUrlInstance;
          }
        }
        
      }
      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 = '';
    url2 = url2 + '/api/deployments/';
    var queryParameters = [];
    if (parameters !== null && parameters !== undefined && parameters.top !== null && parameters.top !== undefined) {
      queryParameters.push('$top=' + encodeURIComponent(parameters.top));
    }
    if (parameters !== null && parameters !== undefined && parameters.orderBy !== null && parameters.orderBy !== undefined) {
      queryParameters.push('$orderBy=' + encodeURIComponent(parameters.orderBy));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { deployments: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var deploymentsArray = responseDoc;
          if (deploymentsArray !== null && deploymentsArray !== undefined) {
            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 !== null && idValue !== undefined) {
                var idInstance = idValue;
                deploymentInstance.id = idInstance;
              }
              
              var statusValue = deploymentsValue['status'];
              if (statusValue !== null && statusValue !== undefined) {
                var statusInstance = statusValue;
                deploymentInstance.status = statusInstance;
              }
              
              var statusTextValue = deploymentsValue['status_text'];
              if (statusTextValue !== null && statusTextValue !== undefined) {
                var statusTextInstance = statusTextValue;
                deploymentInstance.statusText = statusTextInstance;
              }
              
              var authorEmailValue = deploymentsValue['author_email'];
              if (authorEmailValue !== null && authorEmailValue !== undefined) {
                var authorEmailInstance = authorEmailValue;
                deploymentInstance.authorEmail = authorEmailInstance;
              }
              
              var authorValue = deploymentsValue['author'];
              if (authorValue !== null && authorValue !== undefined) {
                var authorInstance = authorValue;
                deploymentInstance.author = authorInstance;
              }
              
              var deployerValue = deploymentsValue['deployer'];
              if (deployerValue !== null && deployerValue !== undefined) {
                var deployerInstance = deployerValue;
                deploymentInstance.deployer = deployerInstance;
              }
              
              var messageValue = deploymentsValue['message'];
              if (messageValue !== null && messageValue !== undefined) {
                var messageInstance = messageValue;
                deploymentInstance.message = messageInstance;
              }
              
              var progressValue = deploymentsValue['progress'];
              if (progressValue !== null && progressValue !== undefined) {
                var progressInstance = progressValue;
                deploymentInstance.progress = progressInstance;
              }
              
              var receivedTimeValue = deploymentsValue['received_time'];
              if (receivedTimeValue !== null && receivedTimeValue !== undefined) {
                var receivedTimeInstance = receivedTimeValue;
                deploymentInstance.receivedTime = receivedTimeInstance;
              }
              
              var startTimeValue = deploymentsValue['start_time'];
              if (startTimeValue !== null && startTimeValue !== undefined) {
                var startTimeInstance = startTimeValue;
                deploymentInstance.startTime = startTimeInstance;
              }
              
              var endTimeValue = deploymentsValue['end_time'];
              if (endTimeValue !== null && endTimeValue !== undefined) {
                var endTimeInstance = endTimeValue;
                deploymentInstance.endTime = endTimeInstance;
              }
              
              var lastSuccessEndTimeValue = deploymentsValue['last_success_end_time'];
              if (lastSuccessEndTimeValue !== null && lastSuccessEndTimeValue !== undefined) {
                var lastSuccessEndTimeInstance = lastSuccessEndTimeValue;
                deploymentInstance.lastSuccessEndTime = lastSuccessEndTimeInstance;
              }
              
              var completeValue = deploymentsValue['complete'];
              if (completeValue !== null && completeValue !== undefined) {
                var completeInstance = completeValue;
                deploymentInstance.complete = completeInstance;
              }
              
              var activeValue = deploymentsValue['active'];
              if (activeValue !== null && activeValue !== undefined) {
                var activeInstance = activeValue;
                deploymentInstance.active = activeInstance;
              }
              
              var isTempValue = deploymentsValue['is_temp'];
              if (isTempValue !== null && isTempValue !== undefined) {
                var isTempInstance = isTempValue;
                deploymentInstance.isTemp = isTempInstance;
              }
              
              var isReadonlyValue = deploymentsValue['is_readonly'];
              if (isReadonlyValue !== null && isReadonlyValue !== undefined) {
                var isReadonlyInstance = isReadonlyValue;
                deploymentInstance.isReadOnly = isReadonlyInstance;
              }
              
              var urlValue = deploymentsValue['url'];
              if (urlValue !== null && urlValue !== undefined) {
                var urlInstance = urlValue;
                deploymentInstance.url = urlInstance;
              }
              
              var logUrlValue = deploymentsValue['log_url'];
              if (logUrlValue !== null && logUrlValue !== undefined) {
                var logUrlInstance = logUrlValue;
                deploymentInstance.logUrl = logUrlInstance;
              }
              
              var siteNameValue = deploymentsValue['site_name'];
              if (siteNameValue !== null && siteNameValue !== undefined) {
                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 = '';
    url2 = url2 + '/api/deployments/';
    url2 = url2 + encodeURIComponent(deploymentId);
    url2 = url2 + '/log';
    var queryParameters = [];
    if (parameters !== null && parameters !== undefined && parameters.top !== null && parameters.top !== undefined) {
      queryParameters.push('$top=' + encodeURIComponent(parameters.top));
    }
    if (parameters !== null && parameters !== undefined && parameters.orderBy !== null && parameters.orderBy !== undefined) {
      queryParameters.push('$orderBy=' + encodeURIComponent(parameters.orderBy));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { logs: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var logsArray = responseDoc;
          if (logsArray !== null && logsArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < logsArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var logsValue = logsArray[loweredIndex1];
              var deploymentLogInstance = {};
              result.logs.push(deploymentLogInstance);
              
              var logTimeValue = logsValue['log_time'];
              if (logTimeValue !== null && logTimeValue !== undefined) {
                var logTimeInstance = logTimeValue;
                deploymentLogInstance.logTime = logTimeInstance;
              }
              
              var idValue = logsValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                deploymentLogInstance.id = idInstance;
              }
              
              var messageValue = logsValue['message'];
              if (messageValue !== null && messageValue !== undefined) {
                var messageInstance = messageValue;
                deploymentLogInstance.message = messageInstance;
              }
              
              var typeValue = logsValue['type'];
              if (typeValue !== null && typeValue !== undefined) {
                var typeInstance = typeValue;
                deploymentLogInstance.type = typeInstance;
              }
              
              var detailsUrlValue = logsValue['details_url'];
              if (detailsUrlValue !== null && detailsUrlValue !== undefined) {
                var detailsUrlInstance = detailsUrlValue;
                deploymentLogInstance.detailsUrl = detailsUrlInstance;
              }
            }
          }
        }
        
      }
      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.redeploy = 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 = '';
    url2 = url2 + '/api/deployments/';
    url2 = url2 + encodeURIComponent(deploymentId);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return 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;
  }
  
  /**
   * Get diagnostics settings.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DiagnosticOperations.prototype.getSettings = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/api/diagnostics/settings/';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { settings: {} };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var settingsSequenceElement = responseDoc;
          if (settingsSequenceElement !== null && settingsSequenceElement !== undefined) {
            for (var property in settingsSequenceElement) {
              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);
    });
  };
  
  /**
   * Update diagnostics settings.
   * 
   * @param {DiagnosticUpdateParameters} parameters The diagnostics setting
   * information new values.
   * 
   * @param {object} [parameters.settings] The setting values.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DiagnosticOperations.prototype.updateSettings = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/api/diagnostics/settings/';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    if (parameters.settings !== null && parameters.settings !== undefined) {
      var settingsDictionary = {};
      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 !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 204) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return 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.deleteMethod = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/api/scm';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 204) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return 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.deleteMethod = 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 = '';
    url2 = url2 + '/api/settings/';
    url2 = url2 + encodeURIComponent(settingId);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * 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 = '';
    url2 = url2 + '/api/settings/';
    url2 = url2 + encodeURIComponent(settingId);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          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 = '';
    url2 = url2 + '/api/settings';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { settings: {} };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var settingsSequenceElement = responseDoc;
          if (settingsSequenceElement !== null && settingsSequenceElement !== undefined) {
            for (var property in settingsSequenceElement) {
              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 {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 = '';
    url2 = url2 + '/api/settings';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    if (parameters.settings !== null && parameters.settings !== undefined) {
      var settingsDictionary = {};
      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 !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 204) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return SettingsOperations;
})();

var TriggeredWebJobOperations = ( /** @lends TriggeredWebJobOperations */ function() {
  /**
   * @class
   * Operations for managing Triggered WebJobs.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [WebSiteExtensionsClient] {@link
   * WebSiteExtensionsClient~WebSiteExtensionsClient}.
   * See [triggeredWebJobs] {@link
   * WebSiteExtensionsClient~WebSiteExtensionsClient#triggeredWebJobs}.
   * Initializes a new instance of the TriggeredWebJobOperations class.
   * @constructor
   * 
   * @param {WebSiteExtensionsClient} client Reference to the service client.
   */
  function TriggeredWebJobOperations(client) {
    this.client = client;
  }
  
  /**
   * Delete a triggered WebJob.
   * 
   * @param {string} jobName The triggered WebJob name.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  TriggeredWebJobOperations.prototype.deleteMethod = 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 = '';
    url2 = url2 + '/api/jobs/triggered/';
    url2 = url2 + encodeURIComponent(jobName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Get a triggered web job.
   * 
   * @param {string} jobName The triggered WebJob name.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  TriggeredWebJobOperations.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 = '';
    url2 = url2 + '/api/jobs/triggered/';
    url2 = url2 + encodeURIComponent(jobName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var triggeredWebJobInstance = {};
          result.triggeredWebJob = triggeredWebJobInstance;
          
          var latestRunValue = responseDoc['latest_run'];
          if (latestRunValue !== null && latestRunValue !== undefined) {
            var latestRunInstance = {};
            triggeredWebJobInstance.latestRun = latestRunInstance;
            
            var idValue = latestRunValue['id'];
            if (idValue !== null && idValue !== undefined) {
              var idInstance = idValue;
              latestRunInstance.id = idInstance;
            }
            
            var statusValue = latestRunValue['status'];
            if (statusValue !== null && statusValue !== undefined) {
              var statusInstance = statusValue;
              latestRunInstance.status = statusInstance;
            }
            
            var startTimeValue = latestRunValue['start_time'];
            if (startTimeValue !== null && startTimeValue !== undefined) {
              var startTimeInstance = startTimeValue;
              latestRunInstance.startTime = startTimeInstance;
            }
            
            var endTimeValue = latestRunValue['end_time'];
            if (endTimeValue !== null && endTimeValue !== undefined) {
              var endTimeInstance = endTimeValue;
              latestRunInstance.endTime = endTimeInstance;
            }
            
            var durationValue = latestRunValue['duration'];
            if (durationValue !== null && durationValue !== undefined) {
              var durationInstance = moment.duration(durationValue);
              latestRunInstance.duration = durationInstance;
            }
            
            var outputUrlValue = latestRunValue['output_url'];
            if (outputUrlValue !== null && outputUrlValue !== undefined) {
              var outputUrlInstance = outputUrlValue;
              latestRunInstance.outputUrl = outputUrlInstance;
            }
            
            var urlValue = latestRunValue['url'];
            if (urlValue !== null && urlValue !== undefined) {
              var urlInstance = urlValue;
              latestRunInstance.url = urlInstance;
            }
            
            var jobNameValue = latestRunValue['job_name'];
            if (jobNameValue !== null && jobNameValue !== undefined) {
              var jobNameInstance = jobNameValue;
              latestRunInstance.jobName = jobNameInstance;
            }
          }
          
          var historyUrlValue = responseDoc['history_url'];
          if (historyUrlValue !== null && historyUrlValue !== undefined) {
            var historyUrlInstance = historyUrlValue;
            triggeredWebJobInstance.historyUrl = historyUrlInstance;
          }
          
          var nameValue = responseDoc['name'];
          if (nameValue !== null && nameValue !== undefined) {
            var nameInstance = nameValue;
            triggeredWebJobInstance.name = nameInstance;
          }
          
          var runCommandValue = responseDoc['run_command'];
          if (runCommandValue !== null && runCommandValue !== undefined) {
            var runCommandInstance = runCommandValue;
            triggeredWebJobInstance.runCommand = runCommandInstance;
          }
          
          var typeValue = responseDoc['type'];
          if (typeValue !== null && typeValue !== undefined) {
            var typeInstance = typeValue;
            triggeredWebJobInstance.type = typeInstance;
          }
          
          var urlValue2 = responseDoc['url'];
          if (urlValue2 !== null && urlValue2 !== undefined) {
            var urlInstance2 = urlValue2;
            triggeredWebJobInstance.url = urlInstance2;
          }
          
          var extraInfoUrlValue = responseDoc['extra_info_url'];
          if (extraInfoUrlValue !== null && extraInfoUrlValue !== undefined) {
            var extraInfoUrlInstance = extraInfoUrlValue;
            triggeredWebJobInstance.extraInfoUrl = extraInfoUrlInstance;
          }
          
          var errorValue = responseDoc['error'];
          if (errorValue !== null && errorValue !== undefined) {
            var errorInstance = errorValue;
            triggeredWebJobInstance.error = errorInstance;
          }
          
          var usingSdkValue = responseDoc['using_sdk'];
          if (usingSdkValue !== null && usingSdkValue !== undefined) {
            var usingSdkInstance = usingSdkValue;
            triggeredWebJobInstance.usingSdk = usingSdkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Get a web job run.
   * 
   * @param {string} jobName The triggered WebJob name.
   * 
   * @param {string} jobRunId The triggered WebJob run identifier.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  TriggeredWebJobOperations.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 = '';
    url2 = url2 + '/api/jobs/triggered/';
    url2 = url2 + encodeURIComponent(jobName);
    url2 = url2 + '/history/';
    url2 = url2 + encodeURIComponent(jobRunId);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var triggeredJobRunInstance = {};
          result.triggeredJobRun = triggeredJobRunInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            triggeredJobRunInstance.id = idInstance;
          }
          
          var statusValue = responseDoc['status'];
          if (statusValue !== null && statusValue !== undefined) {
            var statusInstance = statusValue;
            triggeredJobRunInstance.status = statusInstance;
          }
          
          var startTimeValue = responseDoc['start_time'];
          if (startTimeValue !== null && startTimeValue !== undefined) {
            var startTimeInstance = startTimeValue;
            triggeredJobRunInstance.startTime = startTimeInstance;
          }
          
          var endTimeValue = responseDoc['end_time'];
          if (endTimeValue !== null && endTimeValue !== undefined) {
            var endTimeInstance = endTimeValue;
            triggeredJobRunInstance.endTime = endTimeInstance;
          }
          
          var durationValue = responseDoc['duration'];
          if (durationValue !== null && durationValue !== undefined) {
            var durationInstance = moment.duration(durationValue);
            triggeredJobRunInstance.duration = durationInstance;
          }
          
          var outputUrlValue = responseDoc['output_url'];
          if (outputUrlValue !== null && outputUrlValue !== undefined) {
            var outputUrlInstance = outputUrlValue;
            triggeredJobRunInstance.outputUrl = outputUrlInstance;
          }
          
          var urlValue = responseDoc['url'];
          if (urlValue !== null && urlValue !== undefined) {
            var urlInstance = urlValue;
            triggeredJobRunInstance.url = urlInstance;
          }
          
          var jobNameValue = responseDoc['job_name'];
          if (jobNameValue !== null && jobNameValue !== undefined) {
            var jobNameInstance = jobNameValue;
            triggeredJobRunInstance.jobName = jobNameInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Get the settings of a triggered WebJob.
   * 
   * @param {string} jobName The triggered WebJob name.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  TriggeredWebJobOperations.prototype.getSettings = 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 = '';
    url2 = url2 + '/api/jobs/triggered/';
    url2 = url2 + encodeURIComponent(jobName);
    url2 = url2 + '/settings';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var shutdownGraceTimeInSecondsValue = responseDoc['ShutdownGraceTimeInSeconds'];
          if (shutdownGraceTimeInSecondsValue !== null && shutdownGraceTimeInSecondsValue !== undefined) {
            var shutdownGraceTimeInSecondsInstance = shutdownGraceTimeInSecondsValue;
            result.shutdownGraceTimeInSeconds = shutdownGraceTimeInSecondsInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * List the triggered WebJobs.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  TriggeredWebJobOperations.prototype.list = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/api/jobs/triggered';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { triggeredWebJobs: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var triggeredWebJobsArray = responseDoc;
          if (triggeredWebJobsArray !== null && triggeredWebJobsArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < triggeredWebJobsArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var triggeredWebJobsValue = triggeredWebJobsArray[loweredIndex1];
              var triggeredWebJobInstance = {};
              result.triggeredWebJobs.push(triggeredWebJobInstance);
              
              var latestRunValue = triggeredWebJobsValue['latest_run'];
              if (latestRunValue !== null && latestRunValue !== undefined) {
                var latestRunInstance = {};
                triggeredWebJobInstance.latestRun = latestRunInstance;
                
                var idValue = latestRunValue['id'];
                if (idValue !== null && idValue !== undefined) {
                  var idInstance = idValue;
                  latestRunInstance.id = idInstance;
                }
                
                var statusValue = latestRunValue['status'];
                if (statusValue !== null && statusValue !== undefined) {
                  var statusInstance = statusValue;
                  latestRunInstance.status = statusInstance;
                }
                
                var startTimeValue = latestRunValue['start_time'];
                if (startTimeValue !== null && startTimeValue !== undefined) {
                  var startTimeInstance = startTimeValue;
                  latestRunInstance.startTime = startTimeInstance;
                }
                
                var endTimeValue = latestRunValue['end_time'];
                if (endTimeValue !== null && endTimeValue !== undefined) {
                  var endTimeInstance = endTimeValue;
                  latestRunInstance.endTime = endTimeInstance;
                }
                
                var durationValue = latestRunValue['duration'];
                if (durationValue !== null && durationValue !== undefined) {
                  var durationInstance = moment.duration(durationValue);
                  latestRunInstance.duration = durationInstance;
                }
                
                var outputUrlValue = latestRunValue['output_url'];
                if (outputUrlValue !== null && outputUrlValue !== undefined) {
                  var outputUrlInstance = outputUrlValue;
                  latestRunInstance.outputUrl = outputUrlInstance;
                }
                
                var urlValue = latestRunValue['url'];
                if (urlValue !== null && urlValue !== undefined) {
                  var urlInstance = urlValue;
                  latestRunInstance.url = urlInstance;
                }
                
                var jobNameValue = latestRunValue['job_name'];
                if (jobNameValue !== null && jobNameValue !== undefined) {
                  var jobNameInstance = jobNameValue;
                  latestRunInstance.jobName = jobNameInstance;
                }
              }
              
              var historyUrlValue = triggeredWebJobsValue['history_url'];
              if (historyUrlValue !== null && historyUrlValue !== undefined) {
                var historyUrlInstance = historyUrlValue;
                triggeredWebJobInstance.historyUrl = historyUrlInstance;
              }
              
              var nameValue = triggeredWebJobsValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                triggeredWebJobInstance.name = nameInstance;
              }
              
              var runCommandValue = triggeredWebJobsValue['run_command'];
              if (runCommandValue !== null && runCommandValue !== undefined) {
                var runCommandInstance = runCommandValue;
                triggeredWebJobInstance.runCommand = runCommandInstance;
              }
              
              var typeValue = triggeredWebJobsValue['type'];
              if (typeValue !== null && typeValue !== undefined) {
                var typeInstance = typeValue;
                triggeredWebJobInstance.type = typeInstance;
              }
              
              var urlValue2 = triggeredWebJobsValue['url'];
              if (urlValue2 !== null && urlValue2 !== undefined) {
                var urlInstance2 = urlValue2;
                triggeredWebJobInstance.url = urlInstance2;
              }
              
              var extraInfoUrlValue = triggeredWebJobsValue['extra_info_url'];
              if (extraInfoUrlValue !== null && extraInfoUrlValue !== undefined) {
                var extraInfoUrlInstance = extraInfoUrlValue;
                triggeredWebJobInstance.extraInfoUrl = extraInfoUrlInstance;
              }
              
              var errorValue = triggeredWebJobsValue['error'];
              if (errorValue !== null && errorValue !== undefined) {
                var errorInstance = errorValue;
                triggeredWebJobInstance.error = errorInstance;
              }
              
              var usingSdkValue = triggeredWebJobsValue['using_sdk'];
              if (usingSdkValue !== null && usingSdkValue !== undefined) {
                var usingSdkInstance = usingSdkValue;
                triggeredWebJobInstance.usingSdk = usingSdkInstance;
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * List the triggered WebJob runs.
   * 
   * @param {string} jobName The triggered WebJob name.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  TriggeredWebJobOperations.prototype.listRuns = 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 = '';
    url2 = url2 + '/api/jobs/triggered/';
    url2 = url2 + encodeURIComponent(jobName);
    url2 = url2 + '/history';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { triggeredWebJobRuns: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var runsArray = responseDoc['runs'];
          if (runsArray !== null && runsArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < runsArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var runsValue = runsArray[loweredIndex1];
              var triggeredWebJobRunInstance = {};
              result.triggeredWebJobRuns.push(triggeredWebJobRunInstance);
              
              var idValue = runsValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                triggeredWebJobRunInstance.id = idInstance;
              }
              
              var statusValue = runsValue['status'];
              if (statusValue !== null && statusValue !== undefined) {
                var statusInstance = statusValue;
                triggeredWebJobRunInstance.status = statusInstance;
              }
              
              var startTimeValue = runsValue['start_time'];
              if (startTimeValue !== null && startTimeValue !== undefined) {
                var startTimeInstance = startTimeValue;
                triggeredWebJobRunInstance.startTime = startTimeInstance;
              }
              
              var endTimeValue = runsValue['end_time'];
              if (endTimeValue !== null && endTimeValue !== undefined) {
                var endTimeInstance = endTimeValue;
                triggeredWebJobRunInstance.endTime = endTimeInstance;
              }
              
              var durationValue = runsValue['duration'];
              if (durationValue !== null && durationValue !== undefined) {
                var durationInstance = moment.duration(durationValue);
                triggeredWebJobRunInstance.duration = durationInstance;
              }
              
              var outputUrlValue = runsValue['output_url'];
              if (outputUrlValue !== null && outputUrlValue !== undefined) {
                var outputUrlInstance = outputUrlValue;
                triggeredWebJobRunInstance.outputUrl = outputUrlInstance;
              }
              
              var urlValue = runsValue['url'];
              if (urlValue !== null && urlValue !== undefined) {
                var urlInstance = urlValue;
                triggeredWebJobRunInstance.url = urlInstance;
              }
              
              var jobNameValue = runsValue['job_name'];
              if (jobNameValue !== null && jobNameValue !== undefined) {
                var jobNameInstance = jobNameValue;
                triggeredWebJobRunInstance.jobName = jobNameInstance;
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Run a triggered WebJob.
   * 
   * @param {string} jobName The triggered WebJob name.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  TriggeredWebJobOperations.prototype.run = 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 = '';
    url2 = url2 + '/api/jobs/triggered/';
    url2 = url2 + encodeURIComponent(jobName);
    url2 = url2 + '/run';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 202) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Set the settings of a triggered WebJob (will replace the current settings
   * of the WebJob).
   * 
   * @param {string} jobName The triggered WebJob name.
   * 
   * @param {TriggeredWebJobSettingsUpdateParameters} settings The triggered
   * WebJob settings.
   * 
   * @param {number} [settings.shutdownGraceTimeInSeconds] Specify the time in
   * seconds to wait for the WebJob to gracefully shutdown.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  TriggeredWebJobOperations.prototype.setSettings = function(jobName, settings, 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 (settings === null || settings === undefined) {
      return callback(new Error('settings cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/api/jobs/triggered/';
    url2 = url2 + encodeURIComponent(jobName);
    url2 = url2 + '/settings';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var triggeredWebJobSettingsUpdateParametersValue = {};
    requestDoc = triggeredWebJobSettingsUpdateParametersValue;
    
    if (settings.shutdownGraceTimeInSeconds !== null && settings.shutdownGraceTimeInSeconds !== undefined) {
      triggeredWebJobSettingsUpdateParametersValue['ShutdownGraceTimeInSeconds'] = settings.shutdownGraceTimeInSeconds;
    }
    
    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 !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Create or replace a triggered WebJob with a script file (.exe, .bat, .php,
   * .js...).
   * 
   * @param {string} jobName The triggered WebJob name.
   * 
   * @param {string} fileName The file name.
   * 
   * @param {Stream} jobContent The file content.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  TriggeredWebJobOperations.prototype.uploadFile = function(jobName, fileName, 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 (fileName === null || fileName === undefined) {
      return callback(new Error('fileName cannot be null.'));
    }
    if (jobContent === null || jobContent === undefined) {
      return callback(new Error('jobContent cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/api/jobs/triggered/';
    url2 = url2 + encodeURIComponent(jobName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    if (fileName !== null && fileName !== undefined) {
      httpRequest.headers['Content-Disposition'] = 'attachment; filename=' + fileName;
    }
    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 !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Create or replace a triggered WebJob with a zip file (containing the
   * WebJob binaries).
   * 
   * @param {string} jobName The triggered WebJob name.
   * 
   * @param {string} fileName The zip file name.
   * 
   * @param {Stream} jobContent The zip file content.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  TriggeredWebJobOperations.prototype.uploadZip = function(jobName, fileName, 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 (fileName === null || fileName === undefined) {
      return callback(new Error('fileName cannot be null.'));
    }
    if (jobContent === null || jobContent === undefined) {
      return callback(new Error('jobContent cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/api/jobs/triggered/';
    url2 = url2 + encodeURIComponent(jobName);
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    if (fileName !== null && fileName !== undefined) {
      httpRequest.headers['Content-Disposition'] = 'attachment; filename=' + fileName;
    }
    httpRequest.headers['Content-Type'] = 'application/zip';
    
    // 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 !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return TriggeredWebJobOperations;
})();
