text: /* jshint latedef:false */
  /* jshint forin:false */
  /* jshint noempty:false */
  
  // 
  // Copyright (c) Microsoft and contributors.  All rights reserved.
  // 
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //   http://www.apache.org/licenses/LICENSE-2.0
  // 
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // 
  // See the License for the specific language governing permissions and
  // limitations under the License.
  // 
  
  // Warning: This code was generated by a tool.
  // 
  // Changes to this file may cause incorrect behavior and will be lost if the
  // code is regenerated.
  
  'use strict';
  
  var util = require('util');
  var moment = require('moment');
  var azureCommon = require('azure-common');
  var Service = azureCommon.Service;
  var WebResource = azureCommon.WebResource;
  
  var InsightsManagementClient = ( /** @lends InsightsManagementClient */ function() {
    /**
     * @class
     * Initializes a new instance of the InsightsManagementClient class.
     * @constructor
     * 
     * @param {SubscriptionCloudCredentials} credentials Gets subscription
     * credentials which uniquely identify Microsoft Azure subscription. The
     * subscription ID forms part of the URI for every service call.
     * 
     * @param {string} [credentials.subscriptionId]
     * 
     * @param {string} [baseUri] Gets the URI used as the base for all cloud
     * service requests.
     * 
     * @param {Array} filters
     */
    function InsightsManagementClient(credentials, baseUri, filters) {
      if (credentials === null || credentials === undefined) {
        throw new Error('credentials cannot be null.');
      }
      
      InsightsManagementClient['super_'].call(this, credentials, filters);
      
      this.credentials = credentials;
      this.baseUri = baseUri;
      if (this.baseUri === null || this.baseUri === undefined) {
        this.baseUri = 'https://management.azure.com';
      }
      if (this.apiVersion === null || this.apiVersion === undefined) {
        this.apiVersion = '2014-04-01';
      }
      if (this.longRunningOperationInitialTimeout === null || this.longRunningOperationInitialTimeout === undefined) {
        this.longRunningOperationInitialTimeout = -1;
      }
      if (this.longRunningOperationRetryTimeout === null || this.longRunningOperationRetryTimeout === undefined) {
        this.longRunningOperationRetryTimeout = -1;
      }
      /**
       * Provides an instance of the
       * [AgentDiagnosticSettingsOperations](-AgentDiagnosticSettingsOperations.html)
       * object.
       * @type {object}
       */
      this.agentDiagnosticSettingsOperations = new AgentDiagnosticSettingsOperations(this);
      /**
       * Provides an instance of the [AlertOperations](-AlertOperations.html)
       * object.
       * @type {object}
       */
      this.alertOperations = new AlertOperations(this);
      /**
       * Provides an instance of the
       * [AutomatedExportOperations](-AutomatedExportOperations.html) object.
       * @type {object}
       */
      this.automatedExportOperations = new AutomatedExportOperations(this);
      /**
       * Provides an instance of the
       * [AutoscaleOperations](-AutoscaleOperations.html) object.
       * @type {object}
       */
      this.autoscaleOperations = new AutoscaleOperations(this);
      /**
       * Provides an instance of the
       * [MonitoringConfigurationOperations](-MonitoringConfigurationOperations.html)
       * object.
       * @type {object}
       */
      this.monitoringConfigurationOperations = new MonitoringConfigurationOperations(this);
      /**
       * Provides an instance of the
       * [ServiceDiagnosticSettingsOperations](-ServiceDiagnosticSettingsOperations.html)
       * object.
       * @type {object}
       */
      this.serviceDiagnosticSettingsOperations = new ServiceDiagnosticSettingsOperations(this);
      /**
       * Provides an instance of the [SkuOperations](-SkuOperations.html) object.
       * @type {object}
       */
      this.skuOperations = new SkuOperations(this);
      /**
       * Provides an instance of the
       * [StorageDiagnosticSettingsOperations](-StorageDiagnosticSettingsOperations.html)
       * object.
       * @type {object}
       */
      this.storageDiagnosticSettingsOperations = new StorageDiagnosticSettingsOperations(this);
    }
    
    util.inherits(InsightsManagementClient, Service);
    
    
    return InsightsManagementClient;
  })();
  exports.InsightsManagementClient = InsightsManagementClient;
  
  var AgentDiagnosticSettingsOperations = ( /** @lends AgentDiagnosticSettingsOperations */ function() {
    /**
     * @class
     * Operations for managing agent diagnostic settings.
     * __NOTE__: An instance of this class is automatically created for an
     * instance of the [InsightsManagementClient] {@link
     * InsightsManagementClient~InsightsManagementClient}.
     * See [agentDiagnosticSettingsOperations] {@link
     * InsightsManagementClient~InsightsManagementClient#agentDiagnosticSettingsOperations}.
     * Initializes a new instance of the AgentDiagnosticSettingsOperations class.
     * @constructor
     * 
     * @param {InsightsManagementClient} client Reference to the service client.
     */
    function AgentDiagnosticSettingsOperations(client) {
      this.client = client;
    }
    
    /**
     * Gets the diagnostic settings.
     * 
     * @param {string} resourceUri The resource uri.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    AgentDiagnosticSettingsOperations.prototype.get = function(resourceUri, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceUri === null || resourceUri === undefined) {
        return callback(new Error('resourceUri cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/';
      url2 = url2 + encodeURIComponent(resourceUri);
      url2 = url2 + '/diagnosticSettings/agent';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'GET';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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 nameValue = responseDoc['name'];
            if (nameValue !== null && nameValue !== undefined) {
              var nameInstance = nameValue;
              result.name = nameInstance;
            }
            
            var locationValue = responseDoc['location'];
            if (locationValue !== null && locationValue !== undefined) {
              var locationInstance = locationValue;
              result.location = locationInstance;
            }
            
            var propertiesValue = responseDoc['properties'];
            if (propertiesValue !== null && propertiesValue !== undefined) {
              var propertiesInstance = {};
              result.properties = propertiesInstance;
              
              var nameValue2 = propertiesValue['name'];
              if (nameValue2 !== null && nameValue2 !== undefined) {
                var nameInstance2 = nameValue2;
                propertiesInstance.name = nameInstance2;
              }
              
              var descriptionValue = propertiesValue['description'];
              if (descriptionValue !== null && descriptionValue !== undefined) {
                var descriptionInstance = descriptionValue;
                propertiesInstance.description = descriptionInstance;
              }
              
              var publicConfigurationValue = propertiesValue['publicConfiguration'];
              if (publicConfigurationValue !== null && publicConfigurationValue !== undefined) {
                var typeName = publicConfigurationValue['odata.type'];
              }
            }
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * Puts the new diagnostic settings.
     * 
     * @param {string} resourceUri The resource uri.
     * 
     * @param {AgentDiagnosticSettgingsPutParameters} parameters Parameters
     * supplied to the operation.
     * 
     * @param {AgentDiagnosticSettings} [parameters.properties] Gets or sets the
     * public configuration settings.
     * 
     * @param {string} [parameters.properties.name] Gets or sets the setting name.
     * 
     * @param {string} [parameters.properties.description] Gets or sets the
     * setting description.
     * 
     * @param {PublicMonitoringConfiguration}
     * [parameters.properties.publicConfiguration] Gets or sets the public
     * diagnostic configuration.
     * 
     * @param {DiagnosticMonitorConfiguration}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration]
     * Gets or sets the configuration settings for the telemetry data to be
     * collected.
     * 
     * @param {number}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.overallQuotaInMB]
     * Gets or sets the maximum amount of local disk space that may be consumed
     * by the various types of diagnostic data collected by the agent. The
     * default setting is 5120MB.
     * 
     * @param {DiagnosticInfrastructureLogs}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs]
     * Gets or sets the diagnostics infrastructure logs property. Enable
     * collection of logs generated by the agent. The diagnostic infrastructure
     * logs are useful for troubleshooting the diagnostics system itself.
     * 
     * @param {LogLevel}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs.scheduledTransferLogLevelFilter]
     * Gets or sets the minimum severity level of the logs collected.
     * 
     * @param {TimeSpan}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs.scheduledTransferPeriod]
     * Gets or sets the interval between scheduled transfers to storage rounded
     * up to the nearest minute.
     * 
     * @param {Metrics}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.metrics]
     * Gets or sets the metrics. This element allows the generation of a
     * performance counter table that is optimized for fast queries. Each
     * performance counter that is defined in the PerformanceCounters element is
     * stored in the Metrics table in addition to the Performance Counter table.
     * 
     * @param {string}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.metrics.resourceId]
     * Gets or sets the resource ID of the resource the agent runs on.
     * 
     * @param {array}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.metrics.metricAggregations]
     * Gets or sets the list of aggregations to generate.
     * 
     * @param {Directories}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.directories]
     * Gets or sets the directories. Enable the collection of the contents of a
     * directory, IIS failed access request logs and/or IIS logs.
     * 
     * @param {array}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.directories.dataSources]
     * Gets or sets the list of directories to monitor.
     * 
     * @param {string}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.directories.iISLogs]
     * Gets or sets the IIS logs. Including this element in the configuration
     * enables the collection of IIS logs.
     * 
     * @param {string}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.directories.failedRequestLogs]
     * Gets or sets the failed request logs. Including this element in the
     * configuration enables collection of logs about failed requests to an IIS
     * site or application. You must also enable tracing options under
     * system.WebServer in Web.config.
     * 
     * @param {TimeSpan}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.directories.scheduledTransferPeriod]
     * Gets or sets the interval between scheduled transfers to storage rounded
     * up to the nearest minute.
     * 
     * @param {PerformanceCounters}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.performanceCounters]
     * Gets or sets the performance counters. Enable the collection of
     * Performance Counters.
     * 
     * @param {array}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.performanceCounters.counters]
     * Gets or sets the list of performance counters.
     * 
     * @param {TimeSpan}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.performanceCounters.scheduledTransferPeriod]
     * Gets or sets the interval between scheduled transfers to storage rounded
     * up to the nearest minute.
     * 
     * @param {WindowsEventLog}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.windowsEventLog]
     * Gets or sets the windows event log. Enable the collection of Windows
     * Event Logs.
     * 
     * @param {array}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.windowsEventLog.dataSources]
     * Gets or sets the Windows Event logs to collect. A list of XPath queries
     * describing the windows events to be collected. For example:
     * "System!*[System[(Level &lt;=3)]]". To collect all events specify "*".
     * 
     * @param {TimeSpan}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.windowsEventLog.scheduledTransferPeriod]
     * Gets or sets the interval between scheduled transfers to storage rounded
     * up to the nearest minute.
     * 
     * @param {EtwProviders}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.etwProviders]
     * Gets or sets the ETW providers. Configures the collection of ETW events
     * from EventSource and/or ETW Manifest based providers.
     * 
     * @param {array}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.etwProviders.eventSourceProviders]
     * Gets or sets the collection of ETW events from EventSource providers.
     * 
     * @param {array}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.etwProviders.manifestProviders]
     * Gets or sets the collection of ETW events from ETW Manifest providers.
     * 
     * @param {CrashDumps}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.crashDumps]
     * Gets or sets the crash dumps. Enable collection of crash dumps.
     * 
     * @param {number}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.crashDumps.directoryQuotaPercentage]
     * Gets or sets the configures the percentage of overallQuotaInMB that will
     * be reserved for crash dumps.
     * 
     * @param {CrashDumpType}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.crashDumps.dumpType]
     * Gets or sets the crash dump type. Configures collection of Mini or Full
     * cash dumps.
     * 
     * @param {string}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.crashDumps.containerName]
     * Gets or sets the name of the blob container in your Azure Storage account
     * that will be used to store crash dumps.
     * 
     * @param {array}
     * [parameters.properties.publicConfiguration.diagnosticMonitorConfiguration.crashDumps.processes]
     * Gets or sets the names of the process you want to collect a crash dump
     * for.
     * 
     * @param {DirectoryAbsolute}
     * [parameters.properties.publicConfiguration.localResourceDirectory] Gets
     * or sets the directory on the virtual machine to be used by the Monitoring
     * Agent to store event data. If not set the default directory will be used.
     * 
     * @param {boolean}
     * [parameters.properties.publicConfiguration.localResourceDirectory.expandEnvironment]
     * Gets or sets the expand environment flag. Configures whether or not
     * environment variables in Path will be expanded.
     * 
     * @param {string}
     * [parameters.properties.publicConfiguration.localResourceDirectory.path]
     * Gets or sets the absolute path to the directory to monitor.
     * 
     * @param {string} [parameters.properties.publicConfiguration.storageAccount]
     * Gets or sets the name of the Azure Storage account to store the data in.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    AgentDiagnosticSettingsOperations.prototype.put = function(resourceUri, parameters, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceUri === null || resourceUri === undefined) {
        return callback(new Error('resourceUri cannot be null.'));
      }
      if (parameters === null || parameters === undefined) {
        return callback(new Error('parameters cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/';
      url2 = url2 + encodeURIComponent(resourceUri);
      url2 = url2 + '/diagnosticSettings/agent';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'PUT';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // Serialize Request
      var requestContent = null;
      var requestDoc = null;
      
      var agentDiagnosticSettgingsPutParametersValue = {};
      requestDoc = agentDiagnosticSettgingsPutParametersValue;
      
      if (parameters.properties !== null && parameters.properties !== undefined) {
        var propertiesValue = {};
        agentDiagnosticSettgingsPutParametersValue['properties'] = propertiesValue;
        
        if (parameters.properties.name !== null && parameters.properties.name !== undefined) {
          propertiesValue['name'] = parameters.properties.name;
        }
        
        if (parameters.properties.description !== null && parameters.properties.description !== undefined) {
          propertiesValue['description'] = parameters.properties.description;
        }
        
        if (parameters.properties.publicConfiguration !== null && parameters.properties.publicConfiguration !== undefined) {
          var publicConfigurationValue = {};
          propertiesValue['publicConfiguration'] = publicConfigurationValue;
        }
      }
      
      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 && statusCode !== 201 && statusCode !== 202) {
          var error = new Error(body);
          error.statusCode = response.statusCode;
          return callback(error);
        }
        
        // Create Result
        var result = null;
        // Deserialize Response
        if (statusCode === 200 || statusCode === 201 || statusCode === 202) {
          var responseContent = body;
          result = {};
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    return AgentDiagnosticSettingsOperations;
  })();
  
  var AlertOperations = ( /** @lends AlertOperations */ function() {
    /**
     * @class
     * Operations for managing alert rules and incidents.
     * __NOTE__: An instance of this class is automatically created for an
     * instance of the [InsightsManagementClient] {@link
     * InsightsManagementClient~InsightsManagementClient}.
     * See [alertOperations] {@link
     * InsightsManagementClient~InsightsManagementClient#alertOperations}.
     * Initializes a new instance of the AlertOperations class.
     * @constructor
     * 
     * @param {InsightsManagementClient} client Reference to the service client.
     */
    function AlertOperations(client) {
      this.client = client;
    }
    
    /**
     * 
     * @param {string} resourceGroupName The name of the resource group.
     * 
     * @param {RuleCreateOrUpdateParameters} parameters The rule to create or
     * update.
     * 
     * @param {string} [parameters.location] Gets or sets the location of the
     * rule.
     * 
     * @param {object} [parameters.tags] Gets or sets the tags of the rule.
     * 
     * @param {Rule} [parameters.properties] Gets or sets the rule to create or
     * update.
     * 
     * @param {string} [parameters.properties.name] Gets or sets the name of the
     * alert rule.
     * 
     * @param {string} [parameters.properties.description] Gets or sets the
     * description of the alert rule that will be included in the alert email.
     * 
     * @param {boolean} [parameters.properties.isEnabled] Gets or sets the flag
     * that indicates whether the alert rule is enabled.
     * 
     * @param {RuleCondition} [parameters.properties.condition] Gets or sets the
     * condition that results in the alert rule being activated.
     * 
     * @param {RuleAction} [parameters.properties.action] Gets or sets the action
     * that is performed when the alert rule becomes active, and when an alert
     * condition is resolved.
     * 
     * @param {date} [parameters.properties.lastUpdatedTime] Last time the rule
     * was updated.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    AlertOperations.prototype.createOrUpdateRule = function(resourceGroupName, parameters, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceGroupName === null || resourceGroupName === undefined) {
        return callback(new Error('resourceGroupName cannot be null.'));
      }
      if (parameters === null || parameters === undefined) {
        return callback(new Error('parameters cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/subscriptions/';
      if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
        url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
      }
      url2 = url2 + '/resourcegroups/';
      url2 = url2 + encodeURIComponent(resourceGroupName);
      url2 = url2 + '/providers/microsoft.insights/alertrules/';
      if (parameters.properties !== null && parameters.properties !== undefined && parameters.properties.name !== null && parameters.properties.name !== undefined) {
        url2 = url2 + encodeURIComponent(parameters.properties.name);
      }
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'PUT';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // Serialize Request
      var requestContent = null;
      var requestDoc = null;
      
      var ruleCreateOrUpdateParametersValue = {};
      requestDoc = ruleCreateOrUpdateParametersValue;
      
      if (parameters.location !== null && parameters.location !== undefined) {
        ruleCreateOrUpdateParametersValue['location'] = parameters.location;
      }
      
      if (parameters.tags !== null && parameters.tags !== undefined) {
        var tagsDictionary = {};
        for (var tagsKey in parameters.tags) {
          var tagsValue = parameters.tags[tagsKey];
          tagsDictionary[tagsKey] = tagsValue;
        }
        ruleCreateOrUpdateParametersValue['tags'] = tagsDictionary;
      }
      
      if (parameters.properties !== null && parameters.properties !== undefined) {
        var propertiesValue = {};
        ruleCreateOrUpdateParametersValue['properties'] = propertiesValue;
        
        if (parameters.properties.name !== null && parameters.properties.name !== undefined) {
          propertiesValue['name'] = parameters.properties.name;
        }
        
        if (parameters.properties.description !== null && parameters.properties.description !== undefined) {
          propertiesValue['description'] = parameters.properties.description;
        }
        
        if (parameters.properties.isEnabled !== null && parameters.properties.isEnabled !== undefined) {
          propertiesValue['isEnabled'] = parameters.properties.isEnabled;
        }
        
        if (parameters.properties.condition !== null && parameters.properties.condition !== undefined) {
          var conditionValue = {};
          propertiesValue['condition'] = conditionValue;
          if (parameters.properties.condition.type === 'Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition') {
            conditionValue['odata.type'] = parameters.properties.condition.type;
            var derived = parameters.properties.condition;
            
            if (derived.dataSource !== null && derived.dataSource !== undefined) {
              var dataSourceValue = {};
              conditionValue['dataSource'] = dataSourceValue;
              if (derived.dataSource.type === 'Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource') {
                dataSourceValue['odata.type'] = derived.dataSource.type;
                var derived2 = derived.dataSource;
                
                if (derived2.resourceUri !== null && derived2.resourceUri !== undefined) {
                  dataSourceValue['resourceUri'] = derived2.resourceUri;
                }
                
                if (derived2.metricNamespace !== null && derived2.metricNamespace !== undefined) {
                  dataSourceValue['metricNamespace'] = derived2.metricNamespace;
                }
                
                if (derived2.metricName !== null && derived2.metricName !== undefined) {
                  dataSourceValue['metricName'] = derived2.metricName;
                }
              }
              if (derived.dataSource.type === 'Microsoft.Azure.Management.Insights.Models.RuleManagementEventDataSource') {
                dataSourceValue['odata.type'] = derived.dataSource.type;
                var derived3 = derived.dataSource;
                
                if (derived3.eventName !== null && derived3.eventName !== undefined) {
                  dataSourceValue['eventName'] = derived3.eventName;
                }
                
                if (derived3.eventSource !== null && derived3.eventSource !== undefined) {
                  dataSourceValue['eventSource'] = derived3.eventSource;
                }
                
                if (derived3.level !== null && derived3.level !== undefined) {
                  dataSourceValue['level'] = derived3.level;
                }
                
                if (derived3.operationName !== null && derived3.operationName !== undefined) {
                  dataSourceValue['operationName'] = derived3.operationName;
                }
                
                if (derived3.resourceGroupName !== null && derived3.resourceGroupName !== undefined) {
                  dataSourceValue['resourceGroupName'] = derived3.resourceGroupName;
                }
                
                if (derived3.resourceProviderName !== null && derived3.resourceProviderName !== undefined) {
                  dataSourceValue['resourceProviderName'] = derived3.resourceProviderName;
                }
                
                if (derived3.resourceUri !== null && derived3.resourceUri !== undefined) {
                  dataSourceValue['resourceUri'] = derived3.resourceUri;
                }
                
                if (derived3.status !== null && derived3.status !== undefined) {
                  dataSourceValue['status'] = derived3.status;
                }
                
                if (derived3.subStatus !== null && derived3.subStatus !== undefined) {
                  dataSourceValue['subStatus'] = derived3.subStatus;
                }
                
                if (derived3.claims !== null && derived3.claims !== undefined) {
                  var claimsValue = {};
                  dataSourceValue['claims'] = claimsValue;
                  
                  if (derived3.claims.emailAddress !== null && derived3.claims.emailAddress !== undefined) {
                    claimsValue['emailAddress'] = derived3.claims.emailAddress;
                  }
                }
              }
            }
            
            if (derived.operator !== null && derived.operator !== undefined) {
              conditionValue['operator'] = derived.operator !== null && derived.operator !== undefined ? derived.operator.toString() : 'GreaterThan';
            }
            
            if (derived.threshold !== null && derived.threshold !== undefined) {
              conditionValue['threshold'] = derived.threshold;
            }
            
            if (derived.windowSize !== null && derived.windowSize !== undefined) {
              conditionValue['windowSize'] = derived.windowSize.toIsoString();
            }
            
            if (derived.timeAggregation !== null && derived.timeAggregation !== undefined) {
              conditionValue['timeAggregation'] = derived.timeAggregation !== null && derived.timeAggregation !== undefined ? derived.timeAggregation.toString() : 'Average';
            }
          }
          if (parameters.properties.condition.type === 'Microsoft.Azure.Management.Insights.Models.LocationThresholdRuleCondition') {
            conditionValue['odata.type'] = parameters.properties.condition.type;
            var derived4 = parameters.properties.condition;
            
            if (derived4.dataSource !== null && derived4.dataSource !== undefined) {
              var dataSourceValue2 = {};
              conditionValue['dataSource'] = dataSourceValue2;
              if (derived4.dataSource.type === 'Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource') {
                dataSourceValue2['odata.type'] = derived4.dataSource.type;
                var derived5 = derived4.dataSource;
                
                if (derived5.resourceUri !== null && derived5.resourceUri !== undefined) {
                  dataSourceValue2['resourceUri'] = derived5.resourceUri;
                }
                
                if (derived5.metricNamespace !== null && derived5.metricNamespace !== undefined) {
                  dataSourceValue2['metricNamespace'] = derived5.metricNamespace;
                }
                
                if (derived5.metricName !== null && derived5.metricName !== undefined) {
                  dataSourceValue2['metricName'] = derived5.metricName;
                }
              }
              if (derived4.dataSource.type === 'Microsoft.Azure.Management.Insights.Models.RuleManagementEventDataSource') {
                dataSourceValue2['odata.type'] = derived4.dataSource.type;
                var derived6 = derived4.dataSource;
                
                if (derived6.eventName !== null && derived6.eventName !== undefined) {
                  dataSourceValue2['eventName'] = derived6.eventName;
                }
                
                if (derived6.eventSource !== null && derived6.eventSource !== undefined) {
                  dataSourceValue2['eventSource'] = derived6.eventSource;
                }
                
                if (derived6.level !== null && derived6.level !== undefined) {
                  dataSourceValue2['level'] = derived6.level;
                }
                
                if (derived6.operationName !== null && derived6.operationName !== undefined) {
                  dataSourceValue2['operationName'] = derived6.operationName;
                }
                
                if (derived6.resourceGroupName !== null && derived6.resourceGroupName !== undefined) {
                  dataSourceValue2['resourceGroupName'] = derived6.resourceGroupName;
                }
                
                if (derived6.resourceProviderName !== null && derived6.resourceProviderName !== undefined) {
                  dataSourceValue2['resourceProviderName'] = derived6.resourceProviderName;
                }
                
                if (derived6.resourceUri !== null && derived6.resourceUri !== undefined) {
                  dataSourceValue2['resourceUri'] = derived6.resourceUri;
                }
                
                if (derived6.status !== null && derived6.status !== undefined) {
                  dataSourceValue2['status'] = derived6.status;
                }
                
                if (derived6.subStatus !== null && derived6.subStatus !== undefined) {
                  dataSourceValue2['subStatus'] = derived6.subStatus;
                }
                
                if (derived6.claims !== null && derived6.claims !== undefined) {
                  var claimsValue2 = {};
                  dataSourceValue2['claims'] = claimsValue2;
                  
                  if (derived6.claims.emailAddress !== null && derived6.claims.emailAddress !== undefined) {
                    claimsValue2['emailAddress'] = derived6.claims.emailAddress;
                  }
                }
              }
            }
            
            if (derived4.windowSize !== null && derived4.windowSize !== undefined) {
              conditionValue['windowSize'] = derived4.windowSize.toIsoString();
            }
            
            if (derived4.failedLocationCount !== null && derived4.failedLocationCount !== undefined) {
              conditionValue['failedLocationCount'] = derived4.failedLocationCount;
            }
          }
          if (parameters.properties.condition.type === 'Microsoft.Azure.Management.Insights.Models.ManagementEventRuleCondition') {
            conditionValue['odata.type'] = parameters.properties.condition.type;
            var derived7 = parameters.properties.condition;
            
            if (derived7.dataSource !== null && derived7.dataSource !== undefined) {
              var dataSourceValue3 = {};
              conditionValue['dataSource'] = dataSourceValue3;
              if (derived7.dataSource.type === 'Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource') {
                dataSourceValue3['odata.type'] = derived7.dataSource.type;
                var derived8 = derived7.dataSource;
                
                if (derived8.resourceUri !== null && derived8.resourceUri !== undefined) {
                  dataSourceValue3['resourceUri'] = derived8.resourceUri;
                }
                
                if (derived8.metricNamespace !== null && derived8.metricNamespace !== undefined) {
                  dataSourceValue3['metricNamespace'] = derived8.metricNamespace;
                }
                
                if (derived8.metricName !== null && derived8.metricName !== undefined) {
                  dataSourceValue3['metricName'] = derived8.metricName;
                }
              }
              if (derived7.dataSource.type === 'Microsoft.Azure.Management.Insights.Models.RuleManagementEventDataSource') {
                dataSourceValue3['odata.type'] = derived7.dataSource.type;
                var derived9 = derived7.dataSource;
                
                if (derived9.eventName !== null && derived9.eventName !== undefined) {
                  dataSourceValue3['eventName'] = derived9.eventName;
                }
                
                if (derived9.eventSource !== null && derived9.eventSource !== undefined) {
                  dataSourceValue3['eventSource'] = derived9.eventSource;
                }
                
                if (derived9.level !== null && derived9.level !== undefined) {
                  dataSourceValue3['level'] = derived9.level;
                }
                
                if (derived9.operationName !== null && derived9.operationName !== undefined) {
                  dataSourceValue3['operationName'] = derived9.operationName;
                }
                
                if (derived9.resourceGroupName !== null && derived9.resourceGroupName !== undefined) {
                  dataSourceValue3['resourceGroupName'] = derived9.resourceGroupName;
                }
                
                if (derived9.resourceProviderName !== null && derived9.resourceProviderName !== undefined) {
                  dataSourceValue3['resourceProviderName'] = derived9.resourceProviderName;
                }
                
                if (derived9.resourceUri !== null && derived9.resourceUri !== undefined) {
                  dataSourceValue3['resourceUri'] = derived9.resourceUri;
                }
                
                if (derived9.status !== null && derived9.status !== undefined) {
                  dataSourceValue3['status'] = derived9.status;
                }
                
                if (derived9.subStatus !== null && derived9.subStatus !== undefined) {
                  dataSourceValue3['subStatus'] = derived9.subStatus;
                }
                
                if (derived9.claims !== null && derived9.claims !== undefined) {
                  var claimsValue3 = {};
                  dataSourceValue3['claims'] = claimsValue3;
                  
                  if (derived9.claims.emailAddress !== null && derived9.claims.emailAddress !== undefined) {
                    claimsValue3['emailAddress'] = derived9.claims.emailAddress;
                  }
                }
              }
            }
            
            if (derived7.aggregation !== null && derived7.aggregation !== undefined) {
              var aggregationValue = {};
              conditionValue['aggregation'] = aggregationValue;
              
              if (derived7.aggregation.operator !== null && derived7.aggregation.operator !== undefined) {
                aggregationValue['operator'] = derived7.aggregation.operator !== null && derived7.aggregation.operator !== undefined ? derived7.aggregation.operator.toString() : 'GreaterThan';
              }
              
              if (derived7.aggregation.threshold !== null && derived7.aggregation.threshold !== undefined) {
                aggregationValue['threshold'] = derived7.aggregation.threshold;
              }
              
              if (derived7.aggregation.windowSize !== null && derived7.aggregation.windowSize !== undefined) {
                aggregationValue['windowSize'] = derived7.aggregation.windowSize.toIsoString();
              }
            }
          }
        }
        
        if (parameters.properties.action !== null && parameters.properties.action !== undefined) {
          var actionValue = {};
          propertiesValue['action'] = actionValue;
          if (parameters.properties.action.type === 'Microsoft.Azure.Management.Insights.Models.RuleEmailAction') {
            actionValue['odata.type'] = parameters.properties.action.type;
            var derived10 = parameters.properties.action;
            
            if (derived10.sendToServiceOwners !== null && derived10.sendToServiceOwners !== undefined) {
              actionValue['sendToServiceOwners'] = derived10.sendToServiceOwners;
            }
            
            if (derived10.customEmails !== null && derived10.customEmails !== undefined) {
              var customEmailsArray = [];
              for (var loweredIndex1 = 0; loweredIndex1 < derived10.customEmails.length; loweredIndex1 = loweredIndex1 + 1) {
                var customEmailsItem = derived10.customEmails[loweredIndex1];
                customEmailsArray.push(customEmailsItem);
              }
              actionValue['customEmails'] = customEmailsArray;
            }
          }
        }
        
        if (parameters.properties.lastUpdatedTime !== null && parameters.properties.lastUpdatedTime !== undefined) {
          propertiesValue['lastUpdatedTime'] = parameters.properties.lastUpdatedTime;
        }
      }
      
      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 && statusCode !== 201) {
          var error = new Error(body);
          error.statusCode = response.statusCode;
          return callback(error);
        }
        
        // Create Result
        var result = null;
        // Deserialize Response
        if (statusCode === 200 || statusCode === 201) {
          var responseContent = body;
          result = {};
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceGroupName The name of the resource group.
     * 
     * @param {string} ruleName The name of the rule to delete.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    AlertOperations.prototype.deleteRule = function(resourceGroupName, ruleName, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceGroupName === null || resourceGroupName === undefined) {
        return callback(new Error('resourceGroupName cannot be null.'));
      }
      if (ruleName === null || ruleName === undefined) {
        return callback(new Error('ruleName cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/subscriptions/';
      if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
        url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
      }
      url2 = url2 + '/resourcegroups/';
      url2 = url2 + encodeURIComponent(resourceGroupName);
      url2 = url2 + '/providers/microsoft.insights/alertrules/';
      url2 = url2 + encodeURIComponent(ruleName);
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      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 = 'DELETE';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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
        if (statusCode === 200 || statusCode === 204) {
          var responseContent = body;
          result = {};
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceGroupName The name of the resource group.
     * 
     * @param {string} ruleName The name of the rule.
     * 
     * @param {string} incidentName The name of the incident to retrieve.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    AlertOperations.prototype.getIncident = function(resourceGroupName, ruleName, incidentName, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceGroupName === null || resourceGroupName === undefined) {
        return callback(new Error('resourceGroupName cannot be null.'));
      }
      if (ruleName === null || ruleName === undefined) {
        return callback(new Error('ruleName cannot be null.'));
      }
      if (incidentName === null || incidentName === undefined) {
        return callback(new Error('incidentName cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/subscriptions/';
      if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
        url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
      }
      url2 = url2 + '/resourcegroups/';
      url2 = url2 + encodeURIComponent(resourceGroupName);
      url2 = url2 + '/providers/microsoft.insights/alertrules/';
      url2 = url2 + encodeURIComponent(ruleName);
      url2 = url2 + '/incidents/';
      url2 = url2 + encodeURIComponent(incidentName);
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'GET';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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 incidentInstance = {};
            result.incident = incidentInstance;
            
            var nameValue = responseDoc['name'];
            if (nameValue !== null && nameValue !== undefined) {
              var nameInstance = nameValue;
              incidentInstance.name = nameInstance;
            }
            
            var ruleNameValue = responseDoc['ruleName'];
            if (ruleNameValue !== null && ruleNameValue !== undefined) {
              var ruleNameInstance = ruleNameValue;
              incidentInstance.ruleName = ruleNameInstance;
            }
            
            var isActiveValue = responseDoc['isActive'];
            if (isActiveValue !== null && isActiveValue !== undefined) {
              var isActiveInstance = isActiveValue;
              incidentInstance.isActive = isActiveInstance;
            }
            
            var activatedTimeValue = responseDoc['activatedTime'];
            if (activatedTimeValue !== null && activatedTimeValue !== undefined) {
              var activatedTimeInstance = activatedTimeValue;
              incidentInstance.activatedTime = activatedTimeInstance;
            }
            
            var resolvedTimeValue = responseDoc['resolvedTime'];
            if (resolvedTimeValue !== null && resolvedTimeValue !== undefined) {
              var resolvedTimeInstance = resolvedTimeValue;
              incidentInstance.resolvedTime = resolvedTimeInstance;
            }
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceGroupName The name of the resource group.
     * 
     * @param {string} ruleName The name of the rule to retrieve.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    AlertOperations.prototype.getRule = function(resourceGroupName, ruleName, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceGroupName === null || resourceGroupName === undefined) {
        return callback(new Error('resourceGroupName cannot be null.'));
      }
      if (ruleName === null || ruleName === undefined) {
        return callback(new Error('ruleName cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/subscriptions/';
      if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
        url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
      }
      url2 = url2 + '/resourcegroups/';
      url2 = url2 + encodeURIComponent(resourceGroupName);
      url2 = url2 + '/providers/microsoft.insights/alertrules/';
      url2 = url2 + encodeURIComponent(ruleName);
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'GET';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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 = { tags: {} };
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
            var idValue = responseDoc['id'];
            if (idValue !== null && idValue !== undefined) {
              var idInstance = idValue;
              result.id = idInstance;
            }
            
            var nameValue = responseDoc['name'];
            if (nameValue !== null && nameValue !== undefined) {
              var nameInstance = nameValue;
              result.name = nameInstance;
            }
            
            var locationValue = responseDoc['location'];
            if (locationValue !== null && locationValue !== undefined) {
              var locationInstance = locationValue;
              result.location = locationInstance;
            }
            
            var tagsSequenceElement = responseDoc['tags'];
            if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
              for (var property in tagsSequenceElement) {
                var tagsKey = property;
                var tagsValue = tagsSequenceElement[property];
                result.tags[tagsKey] = tagsValue;
              }
            }
            
            var propertiesValue = responseDoc['properties'];
            if (propertiesValue !== null && propertiesValue !== undefined) {
              var propertiesInstance = {};
              result.properties = propertiesInstance;
              
              var nameValue2 = propertiesValue['name'];
              if (nameValue2 !== null && nameValue2 !== undefined) {
                var nameInstance2 = nameValue2;
                propertiesInstance.name = nameInstance2;
              }
              
              var descriptionValue = propertiesValue['description'];
              if (descriptionValue !== null && descriptionValue !== undefined) {
                var descriptionInstance = descriptionValue;
                propertiesInstance.description = descriptionInstance;
              }
              
              var isEnabledValue = propertiesValue['isEnabled'];
              if (isEnabledValue !== null && isEnabledValue !== undefined) {
                var isEnabledInstance = isEnabledValue;
                propertiesInstance.isEnabled = isEnabledInstance;
              }
              
              var conditionValue = propertiesValue['condition'];
              if (conditionValue !== null && conditionValue !== undefined) {
                var typeName = conditionValue['odata.type'];
                if (typeName === 'Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition') {
                  var thresholdRuleConditionInstance = {};
                  
                  var dataSourceValue = conditionValue['dataSource'];
                  if (dataSourceValue !== null && dataSourceValue !== undefined) {
                    var typeName2 = dataSourceValue['odata.type'];
                    if (typeName2 === 'Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource') {
                      var ruleMetricDataSourceInstance = {};
                      
                      var resourceUriValue = dataSourceValue['resourceUri'];
                      if (resourceUriValue !== null && resourceUriValue !== undefined) {
                        var resourceUriInstance = resourceUriValue;
                        ruleMetricDataSourceInstance.resourceUri = resourceUriInstance;
                      }
                      
                      var metricNamespaceValue = dataSourceValue['metricNamespace'];
                      if (metricNamespaceValue !== null && metricNamespaceValue !== undefined) {
                        var metricNamespaceInstance = metricNamespaceValue;
                        ruleMetricDataSourceInstance.metricNamespace = metricNamespaceInstance;
                      }
                      
                      var metricNameValue = dataSourceValue['metricName'];
                      if (metricNameValue !== null && metricNameValue !== undefined) {
                        var metricNameInstance = metricNameValue;
                        ruleMetricDataSourceInstance.metricName = metricNameInstance;
                      }
                      thresholdRuleConditionInstance.dataSource = ruleMetricDataSourceInstance;
                    }
                    if (typeName2 === 'Microsoft.Azure.Management.Insights.Models.RuleManagementEventDataSource') {
                      var ruleManagementEventDataSourceInstance = {};
                      
                      var eventNameValue = dataSourceValue['eventName'];
                      if (eventNameValue !== null && eventNameValue !== undefined) {
                        var eventNameInstance = eventNameValue;
                        ruleManagementEventDataSourceInstance.eventName = eventNameInstance;
                      }
                      
                      var eventSourceValue = dataSourceValue['eventSource'];
                      if (eventSourceValue !== null && eventSourceValue !== undefined) {
                        var eventSourceInstance = eventSourceValue;
                        ruleManagementEventDataSourceInstance.eventSource = eventSourceInstance;
                      }
                      
                      var levelValue = dataSourceValue['level'];
                      if (levelValue !== null && levelValue !== undefined) {
                        var levelInstance = levelValue;
                        ruleManagementEventDataSourceInstance.level = levelInstance;
                      }
                      
                      var operationNameValue = dataSourceValue['operationName'];
                      if (operationNameValue !== null && operationNameValue !== undefined) {
                        var operationNameInstance = operationNameValue;
                        ruleManagementEventDataSourceInstance.operationName = operationNameInstance;
                      }
                      
                      var resourceGroupNameValue = dataSourceValue['resourceGroupName'];
                      if (resourceGroupNameValue !== null && resourceGroupNameValue !== undefined) {
                        var resourceGroupNameInstance = resourceGroupNameValue;
                        ruleManagementEventDataSourceInstance.resourceGroupName = resourceGroupNameInstance;
                      }
                      
                      var resourceProviderNameValue = dataSourceValue['resourceProviderName'];
                      if (resourceProviderNameValue !== null && resourceProviderNameValue !== undefined) {
                        var resourceProviderNameInstance = resourceProviderNameValue;
                        ruleManagementEventDataSourceInstance.resourceProviderName = resourceProviderNameInstance;
                      }
                      
                      var resourceUriValue2 = dataSourceValue['resourceUri'];
                      if (resourceUriValue2 !== null && resourceUriValue2 !== undefined) {
                        var resourceUriInstance2 = resourceUriValue2;
                        ruleManagementEventDataSourceInstance.resourceUri = resourceUriInstance2;
                      }
                      
                      var statusValue = dataSourceValue['status'];
                      if (statusValue !== null && statusValue !== undefined) {
                        var statusInstance = statusValue;
                        ruleManagementEventDataSourceInstance.status = statusInstance;
                      }
                      
                      var subStatusValue = dataSourceValue['subStatus'];
                      if (subStatusValue !== null && subStatusValue !== undefined) {
                        var subStatusInstance = subStatusValue;
                        ruleManagementEventDataSourceInstance.subStatus = subStatusInstance;
                      }
                      
                      var claimsValue = dataSourceValue['claims'];
                      if (claimsValue !== null && claimsValue !== undefined) {
                        var claimsInstance = {};
                        ruleManagementEventDataSourceInstance.claims = claimsInstance;
                        
                        var emailAddressValue = claimsValue['emailAddress'];
                        if (emailAddressValue !== null && emailAddressValue !== undefined) {
                          var emailAddressInstance = emailAddressValue;
                          claimsInstance.emailAddress = emailAddressInstance;
                        }
                      }
                      thresholdRuleConditionInstance.dataSource = ruleManagementEventDataSourceInstance;
                    }
                  }
                  
                  var operatorValue = conditionValue['operator'];
                  if (operatorValue !== null && operatorValue !== undefined) {
                    var operatorInstance = operatorValue;
                    thresholdRuleConditionInstance.operator = operatorInstance;
                  }
                  
                  var thresholdValue = conditionValue['threshold'];
                  if (thresholdValue !== null && thresholdValue !== undefined) {
                    var thresholdInstance = thresholdValue;
                    thresholdRuleConditionInstance.threshold = thresholdInstance;
                  }
                  
                  var windowSizeValue = conditionValue['windowSize'];
                  if (windowSizeValue !== null && windowSizeValue !== undefined) {
                    var windowSizeInstance = moment.duration(windowSizeValue);
                    thresholdRuleConditionInstance.windowSize = windowSizeInstance;
                  }
                  
                  var timeAggregationValue = conditionValue['timeAggregation'];
                  if (timeAggregationValue !== null && timeAggregationValue !== undefined) {
                    var timeAggregationInstance = timeAggregationValue;
                    thresholdRuleConditionInstance.timeAggregation = timeAggregationInstance;
                  }
                  propertiesInstance.condition = thresholdRuleConditionInstance;
                }
                if (typeName === 'Microsoft.Azure.Management.Insights.Models.LocationThresholdRuleCondition') {
                  var locationThresholdRuleConditionInstance = {};
                  
                  var dataSourceValue2 = conditionValue['dataSource'];
                  if (dataSourceValue2 !== null && dataSourceValue2 !== undefined) {
                    var typeName3 = dataSourceValue2['odata.type'];
                    if (typeName3 === 'Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource') {
                      var ruleMetricDataSourceInstance2 = {};
                      
                      var resourceUriValue3 = dataSourceValue2['resourceUri'];
                      if (resourceUriValue3 !== null && resourceUriValue3 !== undefined) {
                        var resourceUriInstance3 = resourceUriValue3;
                        ruleMetricDataSourceInstance2.resourceUri = resourceUriInstance3;
                      }
                      
                      var metricNamespaceValue2 = dataSourceValue2['metricNamespace'];
                      if (metricNamespaceValue2 !== null && metricNamespaceValue2 !== undefined) {
                        var metricNamespaceInstance2 = metricNamespaceValue2;
                        ruleMetricDataSourceInstance2.metricNamespace = metricNamespaceInstance2;
                      }
                      
                      var metricNameValue2 = dataSourceValue2['metricName'];
                      if (metricNameValue2 !== null && metricNameValue2 !== undefined) {
                        var metricNameInstance2 = metricNameValue2;
                        ruleMetricDataSourceInstance2.metricName = metricNameInstance2;
                      }
                      locationThresholdRuleConditionInstance.dataSource = ruleMetricDataSourceInstance2;
                    }
                    if (typeName3 === 'Microsoft.Azure.Management.Insights.Models.RuleManagementEventDataSource') {
                      var ruleManagementEventDataSourceInstance2 = {};
                      
                      var eventNameValue2 = dataSourceValue2['eventName'];
                      if (eventNameValue2 !== null && eventNameValue2 !== undefined) {
                        var eventNameInstance2 = eventNameValue2;
                        ruleManagementEventDataSourceInstance2.eventName = eventNameInstance2;
                      }
                      
                      var eventSourceValue2 = dataSourceValue2['eventSource'];
                      if (eventSourceValue2 !== null && eventSourceValue2 !== undefined) {
                        var eventSourceInstance2 = eventSourceValue2;
                        ruleManagementEventDataSourceInstance2.eventSource = eventSourceInstance2;
                      }
                      
                      var levelValue2 = dataSourceValue2['level'];
                      if (levelValue2 !== null && levelValue2 !== undefined) {
                        var levelInstance2 = levelValue2;
                        ruleManagementEventDataSourceInstance2.level = levelInstance2;
                      }
                      
                      var operationNameValue2 = dataSourceValue2['operationName'];
                      if (operationNameValue2 !== null && operationNameValue2 !== undefined) {
                        var operationNameInstance2 = operationNameValue2;
                        ruleManagementEventDataSourceInstance2.operationName = operationNameInstance2;
                      }
                      
                      var resourceGroupNameValue2 = dataSourceValue2['resourceGroupName'];
                      if (resourceGroupNameValue2 !== null && resourceGroupNameValue2 !== undefined) {
                        var resourceGroupNameInstance2 = resourceGroupNameValue2;
                        ruleManagementEventDataSourceInstance2.resourceGroupName = resourceGroupNameInstance2;
                      }
                      
                      var resourceProviderNameValue2 = dataSourceValue2['resourceProviderName'];
                      if (resourceProviderNameValue2 !== null && resourceProviderNameValue2 !== undefined) {
                        var resourceProviderNameInstance2 = resourceProviderNameValue2;
                        ruleManagementEventDataSourceInstance2.resourceProviderName = resourceProviderNameInstance2;
                      }
                      
                      var resourceUriValue4 = dataSourceValue2['resourceUri'];
                      if (resourceUriValue4 !== null && resourceUriValue4 !== undefined) {
                        var resourceUriInstance4 = resourceUriValue4;
                        ruleManagementEventDataSourceInstance2.resourceUri = resourceUriInstance4;
                      }
                      
                      var statusValue2 = dataSourceValue2['status'];
                      if (statusValue2 !== null && statusValue2 !== undefined) {
                        var statusInstance2 = statusValue2;
                        ruleManagementEventDataSourceInstance2.status = statusInstance2;
                      }
                      
                      var subStatusValue2 = dataSourceValue2['subStatus'];
                      if (subStatusValue2 !== null && subStatusValue2 !== undefined) {
                        var subStatusInstance2 = subStatusValue2;
                        ruleManagementEventDataSourceInstance2.subStatus = subStatusInstance2;
                      }
                      
                      var claimsValue2 = dataSourceValue2['claims'];
                      if (claimsValue2 !== null && claimsValue2 !== undefined) {
                        var claimsInstance2 = {};
                        ruleManagementEventDataSourceInstance2.claims = claimsInstance2;
                        
                        var emailAddressValue2 = claimsValue2['emailAddress'];
                        if (emailAddressValue2 !== null && emailAddressValue2 !== undefined) {
                          var emailAddressInstance2 = emailAddressValue2;
                          claimsInstance2.emailAddress = emailAddressInstance2;
                        }
                      }
                      locationThresholdRuleConditionInstance.dataSource = ruleManagementEventDataSourceInstance2;
                    }
                  }
                  
                  var windowSizeValue2 = conditionValue['windowSize'];
                  if (windowSizeValue2 !== null && windowSizeValue2 !== undefined) {
                    var windowSizeInstance2 = moment.duration(windowSizeValue2);
                    locationThresholdRuleConditionInstance.windowSize = windowSizeInstance2;
                  }
                  
                  var failedLocationCountValue = conditionValue['failedLocationCount'];
                  if (failedLocationCountValue !== null && failedLocationCountValue !== undefined) {
                    var failedLocationCountInstance = failedLocationCountValue;
                    locationThresholdRuleConditionInstance.failedLocationCount = failedLocationCountInstance;
                  }
                  propertiesInstance.condition = locationThresholdRuleConditionInstance;
                }
                if (typeName === 'Microsoft.Azure.Management.Insights.Models.ManagementEventRuleCondition') {
                  var managementEventRuleConditionInstance = {};
                  
                  var dataSourceValue3 = conditionValue['dataSource'];
                  if (dataSourceValue3 !== null && dataSourceValue3 !== undefined) {
                    var typeName4 = dataSourceValue3['odata.type'];
                    if (typeName4 === 'Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource') {
                      var ruleMetricDataSourceInstance3 = {};
                      
                      var resourceUriValue5 = dataSourceValue3['resourceUri'];
                      if (resourceUriValue5 !== null && resourceUriValue5 !== undefined) {
                        var resourceUriInstance5 = resourceUriValue5;
                        ruleMetricDataSourceInstance3.resourceUri = resourceUriInstance5;
                      }
                      
                      var metricNamespaceValue3 = dataSourceValue3['metricNamespace'];
                      if (metricNamespaceValue3 !== null && metricNamespaceValue3 !== undefined) {
                        var metricNamespaceInstance3 = metricNamespaceValue3;
                        ruleMetricDataSourceInstance3.metricNamespace = metricNamespaceInstance3;
                      }
                      
                      var metricNameValue3 = dataSourceValue3['metricName'];
                      if (metricNameValue3 !== null && metricNameValue3 !== undefined) {
                        var metricNameInstance3 = metricNameValue3;
                        ruleMetricDataSourceInstance3.metricName = metricNameInstance3;
                      }
                      managementEventRuleConditionInstance.dataSource = ruleMetricDataSourceInstance3;
                    }
                    if (typeName4 === 'Microsoft.Azure.Management.Insights.Models.RuleManagementEventDataSource') {
                      var ruleManagementEventDataSourceInstance3 = {};
                      
                      var eventNameValue3 = dataSourceValue3['eventName'];
                      if (eventNameValue3 !== null && eventNameValue3 !== undefined) {
                        var eventNameInstance3 = eventNameValue3;
                        ruleManagementEventDataSourceInstance3.eventName = eventNameInstance3;
                      }
                      
                      var eventSourceValue3 = dataSourceValue3['eventSource'];
                      if (eventSourceValue3 !== null && eventSourceValue3 !== undefined) {
                        var eventSourceInstance3 = eventSourceValue3;
                        ruleManagementEventDataSourceInstance3.eventSource = eventSourceInstance3;
                      }
                      
                      var levelValue3 = dataSourceValue3['level'];
                      if (levelValue3 !== null && levelValue3 !== undefined) {
                        var levelInstance3 = levelValue3;
                        ruleManagementEventDataSourceInstance3.level = levelInstance3;
                      }
                      
                      var operationNameValue3 = dataSourceValue3['operationName'];
                      if (operationNameValue3 !== null && operationNameValue3 !== undefined) {
                        var operationNameInstance3 = operationNameValue3;
                        ruleManagementEventDataSourceInstance3.operationName = operationNameInstance3;
                      }
                      
                      var resourceGroupNameValue3 = dataSourceValue3['resourceGroupName'];
                      if (resourceGroupNameValue3 !== null && resourceGroupNameValue3 !== undefined) {
                        var resourceGroupNameInstance3 = resourceGroupNameValue3;
                        ruleManagementEventDataSourceInstance3.resourceGroupName = resourceGroupNameInstance3;
                      }
                      
                      var resourceProviderNameValue3 = dataSourceValue3['resourceProviderName'];
                      if (resourceProviderNameValue3 !== null && resourceProviderNameValue3 !== undefined) {
                        var resourceProviderNameInstance3 = resourceProviderNameValue3;
                        ruleManagementEventDataSourceInstance3.resourceProviderName = resourceProviderNameInstance3;
                      }
                      
                      var resourceUriValue6 = dataSourceValue3['resourceUri'];
                      if (resourceUriValue6 !== null && resourceUriValue6 !== undefined) {
                        var resourceUriInstance6 = resourceUriValue6;
                        ruleManagementEventDataSourceInstance3.resourceUri = resourceUriInstance6;
                      }
                      
                      var statusValue3 = dataSourceValue3['status'];
                      if (statusValue3 !== null && statusValue3 !== undefined) {
                        var statusInstance3 = statusValue3;
                        ruleManagementEventDataSourceInstance3.status = statusInstance3;
                      }
                      
                      var subStatusValue3 = dataSourceValue3['subStatus'];
                      if (subStatusValue3 !== null && subStatusValue3 !== undefined) {
                        var subStatusInstance3 = subStatusValue3;
                        ruleManagementEventDataSourceInstance3.subStatus = subStatusInstance3;
                      }
                      
                      var claimsValue3 = dataSourceValue3['claims'];
                      if (claimsValue3 !== null && claimsValue3 !== undefined) {
                        var claimsInstance3 = {};
                        ruleManagementEventDataSourceInstance3.claims = claimsInstance3;
                        
                        var emailAddressValue3 = claimsValue3['emailAddress'];
                        if (emailAddressValue3 !== null && emailAddressValue3 !== undefined) {
                          var emailAddressInstance3 = emailAddressValue3;
                          claimsInstance3.emailAddress = emailAddressInstance3;
                        }
                      }
                      managementEventRuleConditionInstance.dataSource = ruleManagementEventDataSourceInstance3;
                    }
                  }
                  
                  var aggregationValue = conditionValue['aggregation'];
                  if (aggregationValue !== null && aggregationValue !== undefined) {
                    var aggregationInstance = {};
                    managementEventRuleConditionInstance.aggregation = aggregationInstance;
                    
                    var operatorValue2 = aggregationValue['operator'];
                    if (operatorValue2 !== null && operatorValue2 !== undefined) {
                      var operatorInstance2 = operatorValue2;
                      aggregationInstance.operator = operatorInstance2;
                    }
                    
                    var thresholdValue2 = aggregationValue['threshold'];
                    if (thresholdValue2 !== null && thresholdValue2 !== undefined) {
                      var thresholdInstance2 = thresholdValue2;
                      aggregationInstance.threshold = thresholdInstance2;
                    }
                    
                    var windowSizeValue3 = aggregationValue['windowSize'];
                    if (windowSizeValue3 !== null && windowSizeValue3 !== undefined) {
                      var windowSizeInstance3 = moment.duration(windowSizeValue3);
                      aggregationInstance.windowSize = windowSizeInstance3;
                    }
                  }
                  propertiesInstance.condition = managementEventRuleConditionInstance;
                }
              }
              
              var actionValue = propertiesValue['action'];
              if (actionValue !== null && actionValue !== undefined) {
                var typeName5 = actionValue['odata.type'];
                if (typeName5 === 'Microsoft.Azure.Management.Insights.Models.RuleEmailAction') {
                  var ruleEmailActionInstance = { customEmails: [] };
                  
                  var sendToServiceOwnersValue = actionValue['sendToServiceOwners'];
                  if (sendToServiceOwnersValue !== null && sendToServiceOwnersValue !== undefined) {
                    var sendToServiceOwnersInstance = sendToServiceOwnersValue;
                    ruleEmailActionInstance.sendToServiceOwners = sendToServiceOwnersInstance;
                  }
                  
                  var customEmailsArray = actionValue['customEmails'];
                  if (customEmailsArray !== null && customEmailsArray !== undefined) {
                    for (var loweredIndex1 = 0; loweredIndex1 < customEmailsArray.length; loweredIndex1 = loweredIndex1 + 1) {
                      var customEmailsValue = customEmailsArray[loweredIndex1];
                      ruleEmailActionInstance.customEmails.push(customEmailsValue);
                    }
                  }
                  propertiesInstance.action = ruleEmailActionInstance;
                }
              }
              
              var lastUpdatedTimeValue = propertiesValue['lastUpdatedTime'];
              if (lastUpdatedTimeValue !== null && lastUpdatedTimeValue !== undefined) {
                var lastUpdatedTimeInstance = lastUpdatedTimeValue;
                propertiesInstance.lastUpdatedTime = lastUpdatedTimeInstance;
              }
            }
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceGroupName The name of the resource group.
     * 
     * @param {string} ruleName The name of the rule.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    AlertOperations.prototype.listIncidentsForRule = function(resourceGroupName, ruleName, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceGroupName === null || resourceGroupName === undefined) {
        return callback(new Error('resourceGroupName cannot be null.'));
      }
      if (ruleName === null || ruleName === undefined) {
        return callback(new Error('ruleName cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/subscriptions/';
      if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
        url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
      }
      url2 = url2 + '/resourcegroups/';
      url2 = url2 + encodeURIComponent(resourceGroupName);
      url2 = url2 + '/providers/microsoft.insights/alertrules/';
      url2 = url2 + encodeURIComponent(ruleName);
      url2 = url2 + '/incidents';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'GET';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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 = { value: [] };
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
            var valueArray = responseDoc['value'];
            if (valueArray !== null && valueArray !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
                var valueValue = valueArray[loweredIndex1];
                var incidentInstance = {};
                result.value.push(incidentInstance);
                
                var nameValue = valueValue['name'];
                if (nameValue !== null && nameValue !== undefined) {
                  var nameInstance = nameValue;
                  incidentInstance.name = nameInstance;
                }
                
                var ruleNameValue = valueValue['ruleName'];
                if (ruleNameValue !== null && ruleNameValue !== undefined) {
                  var ruleNameInstance = ruleNameValue;
                  incidentInstance.ruleName = ruleNameInstance;
                }
                
                var isActiveValue = valueValue['isActive'];
                if (isActiveValue !== null && isActiveValue !== undefined) {
                  var isActiveInstance = isActiveValue;
                  incidentInstance.isActive = isActiveInstance;
                }
                
                var activatedTimeValue = valueValue['activatedTime'];
                if (activatedTimeValue !== null && activatedTimeValue !== undefined) {
                  var activatedTimeInstance = activatedTimeValue;
                  incidentInstance.activatedTime = activatedTimeInstance;
                }
                
                var resolvedTimeValue = valueValue['resolvedTime'];
                if (resolvedTimeValue !== null && resolvedTimeValue !== undefined) {
                  var resolvedTimeInstance = resolvedTimeValue;
                  incidentInstance.resolvedTime = resolvedTimeInstance;
                }
              }
            }
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * List the alert rules within a resource group.
     * 
     * @param {string} resourceGroupName The name of the resource group.
     * 
     * @param {string} [targetResourceUri] The resource identifier of the target
     * of the alert rule.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    AlertOperations.prototype.listRules = function(resourceGroupName, targetResourceUri, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceGroupName === null || resourceGroupName === undefined) {
        return callback(new Error('resourceGroupName cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/subscriptions/';
      if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
        url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
      }
      url2 = url2 + '/resourcegroups/';
      url2 = url2 + encodeURIComponent(resourceGroupName);
      url2 = url2 + '/providers/microsoft.insights/alertrules';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      var odataFilter = [];
      if (targetResourceUri !== null && targetResourceUri !== undefined) {
        odataFilter.push('targetResourceUri eq ' + encodeURIComponent(targetResourceUri));
      }
      if (odataFilter.length > 0) {
        queryParameters.push('$filter=' + odataFilter.join(null));
      }
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'GET';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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 ruleResourceCollectionInstance = { value: [] };
            result.ruleResourceCollection = ruleResourceCollectionInstance;
            
            var valueArray = responseDoc['value'];
            if (valueArray !== null && valueArray !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
                var valueValue = valueArray[loweredIndex1];
                var ruleResourceInstance = { tags: {} };
                ruleResourceCollectionInstance.value.push(ruleResourceInstance);
                
                var idValue = valueValue['id'];
                if (idValue !== null && idValue !== undefined) {
                  var idInstance = idValue;
                  ruleResourceInstance.id = idInstance;
                }
                
                var nameValue = valueValue['name'];
                if (nameValue !== null && nameValue !== undefined) {
                  var nameInstance = nameValue;
                  ruleResourceInstance.name = nameInstance;
                }
                
                var locationValue = valueValue['location'];
                if (locationValue !== null && locationValue !== undefined) {
                  var locationInstance = locationValue;
                  ruleResourceInstance.location = locationInstance;
                }
                
                var tagsSequenceElement = valueValue['tags'];
                if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
                  for (var property in tagsSequenceElement) {
                    var tagsKey = property;
                    var tagsValue = tagsSequenceElement[property];
                    ruleResourceInstance.tags[tagsKey] = tagsValue;
                  }
                }
                
                var propertiesValue = valueValue['properties'];
                if (propertiesValue !== null && propertiesValue !== undefined) {
                  var propertiesInstance = {};
                  ruleResourceInstance.properties = propertiesInstance;
                  
                  var nameValue2 = propertiesValue['name'];
                  if (nameValue2 !== null && nameValue2 !== undefined) {
                    var nameInstance2 = nameValue2;
                    propertiesInstance.name = nameInstance2;
                  }
                  
                  var descriptionValue = propertiesValue['description'];
                  if (descriptionValue !== null && descriptionValue !== undefined) {
                    var descriptionInstance = descriptionValue;
                    propertiesInstance.description = descriptionInstance;
                  }
                  
                  var isEnabledValue = propertiesValue['isEnabled'];
                  if (isEnabledValue !== null && isEnabledValue !== undefined) {
                    var isEnabledInstance = isEnabledValue;
                    propertiesInstance.isEnabled = isEnabledInstance;
                  }
                  
                  var conditionValue = propertiesValue['condition'];
                  if (conditionValue !== null && conditionValue !== undefined) {
                    var typeName = conditionValue['odata.type'];
                    if (typeName === 'Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition') {
                      var thresholdRuleConditionInstance = {};
                      
                      var dataSourceValue = conditionValue['dataSource'];
                      if (dataSourceValue !== null && dataSourceValue !== undefined) {
                        var typeName2 = dataSourceValue['odata.type'];
                        if (typeName2 === 'Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource') {
                          var ruleMetricDataSourceInstance = {};
                          
                          var resourceUriValue = dataSourceValue['resourceUri'];
                          if (resourceUriValue !== null && resourceUriValue !== undefined) {
                            var resourceUriInstance = resourceUriValue;
                            ruleMetricDataSourceInstance.resourceUri = resourceUriInstance;
                          }
                          
                          var metricNamespaceValue = dataSourceValue['metricNamespace'];
                          if (metricNamespaceValue !== null && metricNamespaceValue !== undefined) {
                            var metricNamespaceInstance = metricNamespaceValue;
                            ruleMetricDataSourceInstance.metricNamespace = metricNamespaceInstance;
                          }
                          
                          var metricNameValue = dataSourceValue['metricName'];
                          if (metricNameValue !== null && metricNameValue !== undefined) {
                            var metricNameInstance = metricNameValue;
                            ruleMetricDataSourceInstance.metricName = metricNameInstance;
                          }
                          thresholdRuleConditionInstance.dataSource = ruleMetricDataSourceInstance;
                        }
                        if (typeName2 === 'Microsoft.Azure.Management.Insights.Models.RuleManagementEventDataSource') {
                          var ruleManagementEventDataSourceInstance = {};
                          
                          var eventNameValue = dataSourceValue['eventName'];
                          if (eventNameValue !== null && eventNameValue !== undefined) {
                            var eventNameInstance = eventNameValue;
                            ruleManagementEventDataSourceInstance.eventName = eventNameInstance;
                          }
                          
                          var eventSourceValue = dataSourceValue['eventSource'];
                          if (eventSourceValue !== null && eventSourceValue !== undefined) {
                            var eventSourceInstance = eventSourceValue;
                            ruleManagementEventDataSourceInstance.eventSource = eventSourceInstance;
                          }
                          
                          var levelValue = dataSourceValue['level'];
                          if (levelValue !== null && levelValue !== undefined) {
                            var levelInstance = levelValue;
                            ruleManagementEventDataSourceInstance.level = levelInstance;
                          }
                          
                          var operationNameValue = dataSourceValue['operationName'];
                          if (operationNameValue !== null && operationNameValue !== undefined) {
                            var operationNameInstance = operationNameValue;
                            ruleManagementEventDataSourceInstance.operationName = operationNameInstance;
                          }
                          
                          var resourceGroupNameValue = dataSourceValue['resourceGroupName'];
                          if (resourceGroupNameValue !== null && resourceGroupNameValue !== undefined) {
                            var resourceGroupNameInstance = resourceGroupNameValue;
                            ruleManagementEventDataSourceInstance.resourceGroupName = resourceGroupNameInstance;
                          }
                          
                          var resourceProviderNameValue = dataSourceValue['resourceProviderName'];
                          if (resourceProviderNameValue !== null && resourceProviderNameValue !== undefined) {
                            var resourceProviderNameInstance = resourceProviderNameValue;
                            ruleManagementEventDataSourceInstance.resourceProviderName = resourceProviderNameInstance;
                          }
                          
                          var resourceUriValue2 = dataSourceValue['resourceUri'];
                          if (resourceUriValue2 !== null && resourceUriValue2 !== undefined) {
                            var resourceUriInstance2 = resourceUriValue2;
                            ruleManagementEventDataSourceInstance.resourceUri = resourceUriInstance2;
                          }
                          
                          var statusValue = dataSourceValue['status'];
                          if (statusValue !== null && statusValue !== undefined) {
                            var statusInstance = statusValue;
                            ruleManagementEventDataSourceInstance.status = statusInstance;
                          }
                          
                          var subStatusValue = dataSourceValue['subStatus'];
                          if (subStatusValue !== null && subStatusValue !== undefined) {
                            var subStatusInstance = subStatusValue;
                            ruleManagementEventDataSourceInstance.subStatus = subStatusInstance;
                          }
                          
                          var claimsValue = dataSourceValue['claims'];
                          if (claimsValue !== null && claimsValue !== undefined) {
                            var claimsInstance = {};
                            ruleManagementEventDataSourceInstance.claims = claimsInstance;
                            
                            var emailAddressValue = claimsValue['emailAddress'];
                            if (emailAddressValue !== null && emailAddressValue !== undefined) {
                              var emailAddressInstance = emailAddressValue;
                              claimsInstance.emailAddress = emailAddressInstance;
                            }
                          }
                          thresholdRuleConditionInstance.dataSource = ruleManagementEventDataSourceInstance;
                        }
                      }
                      
                      var operatorValue = conditionValue['operator'];
                      if (operatorValue !== null && operatorValue !== undefined) {
                        var operatorInstance = operatorValue;
                        thresholdRuleConditionInstance.operator = operatorInstance;
                      }
                      
                      var thresholdValue = conditionValue['threshold'];
                      if (thresholdValue !== null && thresholdValue !== undefined) {
                        var thresholdInstance = thresholdValue;
                        thresholdRuleConditionInstance.threshold = thresholdInstance;
                      }
                      
                      var windowSizeValue = conditionValue['windowSize'];
                      if (windowSizeValue !== null && windowSizeValue !== undefined) {
                        var windowSizeInstance = moment.duration(windowSizeValue);
                        thresholdRuleConditionInstance.windowSize = windowSizeInstance;
                      }
                      
                      var timeAggregationValue = conditionValue['timeAggregation'];
                      if (timeAggregationValue !== null && timeAggregationValue !== undefined) {
                        var timeAggregationInstance = timeAggregationValue;
                        thresholdRuleConditionInstance.timeAggregation = timeAggregationInstance;
                      }
                      propertiesInstance.condition = thresholdRuleConditionInstance;
                    }
                    if (typeName === 'Microsoft.Azure.Management.Insights.Models.LocationThresholdRuleCondition') {
                      var locationThresholdRuleConditionInstance = {};
                      
                      var dataSourceValue2 = conditionValue['dataSource'];
                      if (dataSourceValue2 !== null && dataSourceValue2 !== undefined) {
                        var typeName3 = dataSourceValue2['odata.type'];
                        if (typeName3 === 'Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource') {
                          var ruleMetricDataSourceInstance2 = {};
                          
                          var resourceUriValue3 = dataSourceValue2['resourceUri'];
                          if (resourceUriValue3 !== null && resourceUriValue3 !== undefined) {
                            var resourceUriInstance3 = resourceUriValue3;
                            ruleMetricDataSourceInstance2.resourceUri = resourceUriInstance3;
                          }
                          
                          var metricNamespaceValue2 = dataSourceValue2['metricNamespace'];
                          if (metricNamespaceValue2 !== null && metricNamespaceValue2 !== undefined) {
                            var metricNamespaceInstance2 = metricNamespaceValue2;
                            ruleMetricDataSourceInstance2.metricNamespace = metricNamespaceInstance2;
                          }
                          
                          var metricNameValue2 = dataSourceValue2['metricName'];
                          if (metricNameValue2 !== null && metricNameValue2 !== undefined) {
                            var metricNameInstance2 = metricNameValue2;
                            ruleMetricDataSourceInstance2.metricName = metricNameInstance2;
                          }
                          locationThresholdRuleConditionInstance.dataSource = ruleMetricDataSourceInstance2;
                        }
                        if (typeName3 === 'Microsoft.Azure.Management.Insights.Models.RuleManagementEventDataSource') {
                          var ruleManagementEventDataSourceInstance2 = {};
                          
                          var eventNameValue2 = dataSourceValue2['eventName'];
                          if (eventNameValue2 !== null && eventNameValue2 !== undefined) {
                            var eventNameInstance2 = eventNameValue2;
                            ruleManagementEventDataSourceInstance2.eventName = eventNameInstance2;
                          }
                          
                          var eventSourceValue2 = dataSourceValue2['eventSource'];
                          if (eventSourceValue2 !== null && eventSourceValue2 !== undefined) {
                            var eventSourceInstance2 = eventSourceValue2;
                            ruleManagementEventDataSourceInstance2.eventSource = eventSourceInstance2;
                          }
                          
                          var levelValue2 = dataSourceValue2['level'];
                          if (levelValue2 !== null && levelValue2 !== undefined) {
                            var levelInstance2 = levelValue2;
                            ruleManagementEventDataSourceInstance2.level = levelInstance2;
                          }
                          
                          var operationNameValue2 = dataSourceValue2['operationName'];
                          if (operationNameValue2 !== null && operationNameValue2 !== undefined) {
                            var operationNameInstance2 = operationNameValue2;
                            ruleManagementEventDataSourceInstance2.operationName = operationNameInstance2;
                          }
                          
                          var resourceGroupNameValue2 = dataSourceValue2['resourceGroupName'];
                          if (resourceGroupNameValue2 !== null && resourceGroupNameValue2 !== undefined) {
                            var resourceGroupNameInstance2 = resourceGroupNameValue2;
                            ruleManagementEventDataSourceInstance2.resourceGroupName = resourceGroupNameInstance2;
                          }
                          
                          var resourceProviderNameValue2 = dataSourceValue2['resourceProviderName'];
                          if (resourceProviderNameValue2 !== null && resourceProviderNameValue2 !== undefined) {
                            var resourceProviderNameInstance2 = resourceProviderNameValue2;
                            ruleManagementEventDataSourceInstance2.resourceProviderName = resourceProviderNameInstance2;
                          }
                          
                          var resourceUriValue4 = dataSourceValue2['resourceUri'];
                          if (resourceUriValue4 !== null && resourceUriValue4 !== undefined) {
                            var resourceUriInstance4 = resourceUriValue4;
                            ruleManagementEventDataSourceInstance2.resourceUri = resourceUriInstance4;
                          }
                          
                          var statusValue2 = dataSourceValue2['status'];
                          if (statusValue2 !== null && statusValue2 !== undefined) {
                            var statusInstance2 = statusValue2;
                            ruleManagementEventDataSourceInstance2.status = statusInstance2;
                          }
                          
                          var subStatusValue2 = dataSourceValue2['subStatus'];
                          if (subStatusValue2 !== null && subStatusValue2 !== undefined) {
                            var subStatusInstance2 = subStatusValue2;
                            ruleManagementEventDataSourceInstance2.subStatus = subStatusInstance2;
                          }
                          
                          var claimsValue2 = dataSourceValue2['claims'];
                          if (claimsValue2 !== null && claimsValue2 !== undefined) {
                            var claimsInstance2 = {};
                            ruleManagementEventDataSourceInstance2.claims = claimsInstance2;
                            
                            var emailAddressValue2 = claimsValue2['emailAddress'];
                            if (emailAddressValue2 !== null && emailAddressValue2 !== undefined) {
                              var emailAddressInstance2 = emailAddressValue2;
                              claimsInstance2.emailAddress = emailAddressInstance2;
                            }
                          }
                          locationThresholdRuleConditionInstance.dataSource = ruleManagementEventDataSourceInstance2;
                        }
                      }
                      
                      var windowSizeValue2 = conditionValue['windowSize'];
                      if (windowSizeValue2 !== null && windowSizeValue2 !== undefined) {
                        var windowSizeInstance2 = moment.duration(windowSizeValue2);
                        locationThresholdRuleConditionInstance.windowSize = windowSizeInstance2;
                      }
                      
                      var failedLocationCountValue = conditionValue['failedLocationCount'];
                      if (failedLocationCountValue !== null && failedLocationCountValue !== undefined) {
                        var failedLocationCountInstance = failedLocationCountValue;
                        locationThresholdRuleConditionInstance.failedLocationCount = failedLocationCountInstance;
                      }
                      propertiesInstance.condition = locationThresholdRuleConditionInstance;
                    }
                    if (typeName === 'Microsoft.Azure.Management.Insights.Models.ManagementEventRuleCondition') {
                      var managementEventRuleConditionInstance = {};
                      
                      var dataSourceValue3 = conditionValue['dataSource'];
                      if (dataSourceValue3 !== null && dataSourceValue3 !== undefined) {
                        var typeName4 = dataSourceValue3['odata.type'];
                        if (typeName4 === 'Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource') {
                          var ruleMetricDataSourceInstance3 = {};
                          
                          var resourceUriValue5 = dataSourceValue3['resourceUri'];
                          if (resourceUriValue5 !== null && resourceUriValue5 !== undefined) {
                            var resourceUriInstance5 = resourceUriValue5;
                            ruleMetricDataSourceInstance3.resourceUri = resourceUriInstance5;
                          }
                          
                          var metricNamespaceValue3 = dataSourceValue3['metricNamespace'];
                          if (metricNamespaceValue3 !== null && metricNamespaceValue3 !== undefined) {
                            var metricNamespaceInstance3 = metricNamespaceValue3;
                            ruleMetricDataSourceInstance3.metricNamespace = metricNamespaceInstance3;
                          }
                          
                          var metricNameValue3 = dataSourceValue3['metricName'];
                          if (metricNameValue3 !== null && metricNameValue3 !== undefined) {
                            var metricNameInstance3 = metricNameValue3;
                            ruleMetricDataSourceInstance3.metricName = metricNameInstance3;
                          }
                          managementEventRuleConditionInstance.dataSource = ruleMetricDataSourceInstance3;
                        }
                        if (typeName4 === 'Microsoft.Azure.Management.Insights.Models.RuleManagementEventDataSource') {
                          var ruleManagementEventDataSourceInstance3 = {};
                          
                          var eventNameValue3 = dataSourceValue3['eventName'];
                          if (eventNameValue3 !== null && eventNameValue3 !== undefined) {
                            var eventNameInstance3 = eventNameValue3;
                            ruleManagementEventDataSourceInstance3.eventName = eventNameInstance3;
                          }
                          
                          var eventSourceValue3 = dataSourceValue3['eventSource'];
                          if (eventSourceValue3 !== null && eventSourceValue3 !== undefined) {
                            var eventSourceInstance3 = eventSourceValue3;
                            ruleManagementEventDataSourceInstance3.eventSource = eventSourceInstance3;
                          }
                          
                          var levelValue3 = dataSourceValue3['level'];
                          if (levelValue3 !== null && levelValue3 !== undefined) {
                            var levelInstance3 = levelValue3;
                            ruleManagementEventDataSourceInstance3.level = levelInstance3;
                          }
                          
                          var operationNameValue3 = dataSourceValue3['operationName'];
                          if (operationNameValue3 !== null && operationNameValue3 !== undefined) {
                            var operationNameInstance3 = operationNameValue3;
                            ruleManagementEventDataSourceInstance3.operationName = operationNameInstance3;
                          }
                          
                          var resourceGroupNameValue3 = dataSourceValue3['resourceGroupName'];
                          if (resourceGroupNameValue3 !== null && resourceGroupNameValue3 !== undefined) {
                            var resourceGroupNameInstance3 = resourceGroupNameValue3;
                            ruleManagementEventDataSourceInstance3.resourceGroupName = resourceGroupNameInstance3;
                          }
                          
                          var resourceProviderNameValue3 = dataSourceValue3['resourceProviderName'];
                          if (resourceProviderNameValue3 !== null && resourceProviderNameValue3 !== undefined) {
                            var resourceProviderNameInstance3 = resourceProviderNameValue3;
                            ruleManagementEventDataSourceInstance3.resourceProviderName = resourceProviderNameInstance3;
                          }
                          
                          var resourceUriValue6 = dataSourceValue3['resourceUri'];
                          if (resourceUriValue6 !== null && resourceUriValue6 !== undefined) {
                            var resourceUriInstance6 = resourceUriValue6;
                            ruleManagementEventDataSourceInstance3.resourceUri = resourceUriInstance6;
                          }
                          
                          var statusValue3 = dataSourceValue3['status'];
                          if (statusValue3 !== null && statusValue3 !== undefined) {
                            var statusInstance3 = statusValue3;
                            ruleManagementEventDataSourceInstance3.status = statusInstance3;
                          }
                          
                          var subStatusValue3 = dataSourceValue3['subStatus'];
                          if (subStatusValue3 !== null && subStatusValue3 !== undefined) {
                            var subStatusInstance3 = subStatusValue3;
                            ruleManagementEventDataSourceInstance3.subStatus = subStatusInstance3;
                          }
                          
                          var claimsValue3 = dataSourceValue3['claims'];
                          if (claimsValue3 !== null && claimsValue3 !== undefined) {
                            var claimsInstance3 = {};
                            ruleManagementEventDataSourceInstance3.claims = claimsInstance3;
                            
                            var emailAddressValue3 = claimsValue3['emailAddress'];
                            if (emailAddressValue3 !== null && emailAddressValue3 !== undefined) {
                              var emailAddressInstance3 = emailAddressValue3;
                              claimsInstance3.emailAddress = emailAddressInstance3;
                            }
                          }
                          managementEventRuleConditionInstance.dataSource = ruleManagementEventDataSourceInstance3;
                        }
                      }
                      
                      var aggregationValue = conditionValue['aggregation'];
                      if (aggregationValue !== null && aggregationValue !== undefined) {
                        var aggregationInstance = {};
                        managementEventRuleConditionInstance.aggregation = aggregationInstance;
                        
                        var operatorValue2 = aggregationValue['operator'];
                        if (operatorValue2 !== null && operatorValue2 !== undefined) {
                          var operatorInstance2 = operatorValue2;
                          aggregationInstance.operator = operatorInstance2;
                        }
                        
                        var thresholdValue2 = aggregationValue['threshold'];
                        if (thresholdValue2 !== null && thresholdValue2 !== undefined) {
                          var thresholdInstance2 = thresholdValue2;
                          aggregationInstance.threshold = thresholdInstance2;
                        }
                        
                        var windowSizeValue3 = aggregationValue['windowSize'];
                        if (windowSizeValue3 !== null && windowSizeValue3 !== undefined) {
                          var windowSizeInstance3 = moment.duration(windowSizeValue3);
                          aggregationInstance.windowSize = windowSizeInstance3;
                        }
                      }
                      propertiesInstance.condition = managementEventRuleConditionInstance;
                    }
                  }
                  
                  var actionValue = propertiesValue['action'];
                  if (actionValue !== null && actionValue !== undefined) {
                    var typeName5 = actionValue['odata.type'];
                    if (typeName5 === 'Microsoft.Azure.Management.Insights.Models.RuleEmailAction') {
                      var ruleEmailActionInstance = { customEmails: [] };
                      
                      var sendToServiceOwnersValue = actionValue['sendToServiceOwners'];
                      if (sendToServiceOwnersValue !== null && sendToServiceOwnersValue !== undefined) {
                        var sendToServiceOwnersInstance = sendToServiceOwnersValue;
                        ruleEmailActionInstance.sendToServiceOwners = sendToServiceOwnersInstance;
                      }
                      
                      var customEmailsArray = actionValue['customEmails'];
                      if (customEmailsArray !== null && customEmailsArray !== undefined) {
                        for (var loweredIndex2 = 0; loweredIndex2 < customEmailsArray.length; loweredIndex2 = loweredIndex2 + 1) {
                          var customEmailsValue = customEmailsArray[loweredIndex2];
                          ruleEmailActionInstance.customEmails.push(customEmailsValue);
                        }
                      }
                      propertiesInstance.action = ruleEmailActionInstance;
                    }
                  }
                  
                  var lastUpdatedTimeValue = propertiesValue['lastUpdatedTime'];
                  if (lastUpdatedTimeValue !== null && lastUpdatedTimeValue !== undefined) {
                    var lastUpdatedTimeInstance = lastUpdatedTimeValue;
                    propertiesInstance.lastUpdatedTime = lastUpdatedTimeInstance;
                  }
                }
              }
            }
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceGroupName The name of the resource group.
     * 
     * @param {RuleCreateOrUpdateParameters} parameters The rule to update.
     * 
     * @param {string} [parameters.location] Gets or sets the location of the
     * rule.
     * 
     * @param {object} [parameters.tags] Gets or sets the tags of the rule.
     * 
     * @param {Rule} [parameters.properties] Gets or sets the rule to create or
     * update.
     * 
     * @param {string} [parameters.properties.name] Gets or sets the name of the
     * alert rule.
     * 
     * @param {string} [parameters.properties.description] Gets or sets the
     * description of the alert rule that will be included in the alert email.
     * 
     * @param {boolean} [parameters.properties.isEnabled] Gets or sets the flag
     * that indicates whether the alert rule is enabled.
     * 
     * @param {RuleCondition} [parameters.properties.condition] Gets or sets the
     * condition that results in the alert rule being activated.
     * 
     * @param {RuleAction} [parameters.properties.action] Gets or sets the action
     * that is performed when the alert rule becomes active, and when an alert
     * condition is resolved.
     * 
     * @param {date} [parameters.properties.lastUpdatedTime] Last time the rule
     * was updated.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    AlertOperations.prototype.updateRule = function(resourceGroupName, parameters, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceGroupName === null || resourceGroupName === undefined) {
        return callback(new Error('resourceGroupName cannot be null.'));
      }
      if (parameters === null || parameters === undefined) {
        return callback(new Error('parameters cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/subscriptions/';
      if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
        url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
      }
      url2 = url2 + '/resourcegroups/';
      url2 = url2 + encodeURIComponent(resourceGroupName);
      url2 = url2 + '/providers/microsoft.insights/alertrules/';
      if (parameters.properties !== null && parameters.properties !== undefined && parameters.properties.name !== null && parameters.properties.name !== undefined) {
        url2 = url2 + encodeURIComponent(parameters.properties.name);
      }
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      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 = 'PATCH';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // Serialize Request
      var requestContent = null;
      var requestDoc = null;
      
      var ruleCreateOrUpdateParametersValue = {};
      requestDoc = ruleCreateOrUpdateParametersValue;
      
      if (parameters.location !== null && parameters.location !== undefined) {
        ruleCreateOrUpdateParametersValue['location'] = parameters.location;
      }
      
      if (parameters.tags !== null && parameters.tags !== undefined) {
        var tagsDictionary = {};
        for (var tagsKey in parameters.tags) {
          var tagsValue = parameters.tags[tagsKey];
          tagsDictionary[tagsKey] = tagsValue;
        }
        ruleCreateOrUpdateParametersValue['tags'] = tagsDictionary;
      }
      
      if (parameters.properties !== null && parameters.properties !== undefined) {
        var propertiesValue = {};
        ruleCreateOrUpdateParametersValue['properties'] = propertiesValue;
        
        if (parameters.properties.name !== null && parameters.properties.name !== undefined) {
          propertiesValue['name'] = parameters.properties.name;
        }
        
        if (parameters.properties.description !== null && parameters.properties.description !== undefined) {
          propertiesValue['description'] = parameters.properties.description;
        }
        
        if (parameters.properties.isEnabled !== null && parameters.properties.isEnabled !== undefined) {
          propertiesValue['isEnabled'] = parameters.properties.isEnabled;
        }
        
        if (parameters.properties.condition !== null && parameters.properties.condition !== undefined) {
          var conditionValue = {};
          propertiesValue['condition'] = conditionValue;
          if (parameters.properties.condition.type === 'Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition') {
            conditionValue['odata.type'] = parameters.properties.condition.type;
            var derived = parameters.properties.condition;
            
            if (derived.dataSource !== null && derived.dataSource !== undefined) {
              var dataSourceValue = {};
              conditionValue['dataSource'] = dataSourceValue;
              if (derived.dataSource.type === 'Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource') {
                dataSourceValue['odata.type'] = derived.dataSource.type;
                var derived2 = derived.dataSource;
                
                if (derived2.resourceUri !== null && derived2.resourceUri !== undefined) {
                  dataSourceValue['resourceUri'] = derived2.resourceUri;
                }
                
                if (derived2.metricNamespace !== null && derived2.metricNamespace !== undefined) {
                  dataSourceValue['metricNamespace'] = derived2.metricNamespace;
                }
                
                if (derived2.metricName !== null && derived2.metricName !== undefined) {
                  dataSourceValue['metricName'] = derived2.metricName;
                }
              }
              if (derived.dataSource.type === 'Microsoft.Azure.Management.Insights.Models.RuleManagementEventDataSource') {
                dataSourceValue['odata.type'] = derived.dataSource.type;
                var derived3 = derived.dataSource;
                
                if (derived3.eventName !== null && derived3.eventName !== undefined) {
                  dataSourceValue['eventName'] = derived3.eventName;
                }
                
                if (derived3.eventSource !== null && derived3.eventSource !== undefined) {
                  dataSourceValue['eventSource'] = derived3.eventSource;
                }
                
                if (derived3.level !== null && derived3.level !== undefined) {
                  dataSourceValue['level'] = derived3.level;
                }
                
                if (derived3.operationName !== null && derived3.operationName !== undefined) {
                  dataSourceValue['operationName'] = derived3.operationName;
                }
                
                if (derived3.resourceGroupName !== null && derived3.resourceGroupName !== undefined) {
                  dataSourceValue['resourceGroupName'] = derived3.resourceGroupName;
                }
                
                if (derived3.resourceProviderName !== null && derived3.resourceProviderName !== undefined) {
                  dataSourceValue['resourceProviderName'] = derived3.resourceProviderName;
                }
                
                if (derived3.resourceUri !== null && derived3.resourceUri !== undefined) {
                  dataSourceValue['resourceUri'] = derived3.resourceUri;
                }
                
                if (derived3.status !== null && derived3.status !== undefined) {
                  dataSourceValue['status'] = derived3.status;
                }
                
                if (derived3.subStatus !== null && derived3.subStatus !== undefined) {
                  dataSourceValue['subStatus'] = derived3.subStatus;
                }
                
                if (derived3.claims !== null && derived3.claims !== undefined) {
                  var claimsValue = {};
                  dataSourceValue['claims'] = claimsValue;
                  
                  if (derived3.claims.emailAddress !== null && derived3.claims.emailAddress !== undefined) {
                    claimsValue['emailAddress'] = derived3.claims.emailAddress;
                  }
                }
              }
            }
            
            if (derived.operator !== null && derived.operator !== undefined) {
              conditionValue['operator'] = derived.operator !== null && derived.operator !== undefined ? derived.operator.toString() : 'GreaterThan';
            }
            
            if (derived.threshold !== null && derived.threshold !== undefined) {
              conditionValue['threshold'] = derived.threshold;
            }
            
            if (derived.windowSize !== null && derived.windowSize !== undefined) {
              conditionValue['windowSize'] = derived.windowSize.toIsoString();
            }
            
            if (derived.timeAggregation !== null && derived.timeAggregation !== undefined) {
              conditionValue['timeAggregation'] = derived.timeAggregation !== null && derived.timeAggregation !== undefined ? derived.timeAggregation.toString() : 'Average';
            }
          }
          if (parameters.properties.condition.type === 'Microsoft.Azure.Management.Insights.Models.LocationThresholdRuleCondition') {
            conditionValue['odata.type'] = parameters.properties.condition.type;
            var derived4 = parameters.properties.condition;
            
            if (derived4.dataSource !== null && derived4.dataSource !== undefined) {
              var dataSourceValue2 = {};
              conditionValue['dataSource'] = dataSourceValue2;
              if (derived4.dataSource.type === 'Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource') {
                dataSourceValue2['odata.type'] = derived4.dataSource.type;
                var derived5 = derived4.dataSource;
                
                if (derived5.resourceUri !== null && derived5.resourceUri !== undefined) {
                  dataSourceValue2['resourceUri'] = derived5.resourceUri;
                }
                
                if (derived5.metricNamespace !== null && derived5.metricNamespace !== undefined) {
                  dataSourceValue2['metricNamespace'] = derived5.metricNamespace;
                }
                
                if (derived5.metricName !== null && derived5.metricName !== undefined) {
                  dataSourceValue2['metricName'] = derived5.metricName;
                }
              }
              if (derived4.dataSource.type === 'Microsoft.Azure.Management.Insights.Models.RuleManagementEventDataSource') {
                dataSourceValue2['odata.type'] = derived4.dataSource.type;
                var derived6 = derived4.dataSource;
                
                if (derived6.eventName !== null && derived6.eventName !== undefined) {
                  dataSourceValue2['eventName'] = derived6.eventName;
                }
                
                if (derived6.eventSource !== null && derived6.eventSource !== undefined) {
                  dataSourceValue2['eventSource'] = derived6.eventSource;
                }
                
                if (derived6.level !== null && derived6.level !== undefined) {
                  dataSourceValue2['level'] = derived6.level;
                }
                
                if (derived6.operationName !== null && derived6.operationName !== undefined) {
                  dataSourceValue2['operationName'] = derived6.operationName;
                }
                
                if (derived6.resourceGroupName !== null && derived6.resourceGroupName !== undefined) {
                  dataSourceValue2['resourceGroupName'] = derived6.resourceGroupName;
                }
                
                if (derived6.resourceProviderName !== null && derived6.resourceProviderName !== undefined) {
                  dataSourceValue2['resourceProviderName'] = derived6.resourceProviderName;
                }
                
                if (derived6.resourceUri !== null && derived6.resourceUri !== undefined) {
                  dataSourceValue2['resourceUri'] = derived6.resourceUri;
                }
                
                if (derived6.status !== null && derived6.status !== undefined) {
                  dataSourceValue2['status'] = derived6.status;
                }
                
                if (derived6.subStatus !== null && derived6.subStatus !== undefined) {
                  dataSourceValue2['subStatus'] = derived6.subStatus;
                }
                
                if (derived6.claims !== null && derived6.claims !== undefined) {
                  var claimsValue2 = {};
                  dataSourceValue2['claims'] = claimsValue2;
                  
                  if (derived6.claims.emailAddress !== null && derived6.claims.emailAddress !== undefined) {
                    claimsValue2['emailAddress'] = derived6.claims.emailAddress;
                  }
                }
              }
            }
            
            if (derived4.windowSize !== null && derived4.windowSize !== undefined) {
              conditionValue['windowSize'] = derived4.windowSize.toIsoString();
            }
            
            if (derived4.failedLocationCount !== null && derived4.failedLocationCount !== undefined) {
              conditionValue['failedLocationCount'] = derived4.failedLocationCount;
            }
          }
          if (parameters.properties.condition.type === 'Microsoft.Azure.Management.Insights.Models.ManagementEventRuleCondition') {
            conditionValue['odata.type'] = parameters.properties.condition.type;
            var derived7 = parameters.properties.condition;
            
            if (derived7.dataSource !== null && derived7.dataSource !== undefined) {
              var dataSourceValue3 = {};
              conditionValue['dataSource'] = dataSourceValue3;
              if (derived7.dataSource.type === 'Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource') {
                dataSourceValue3['odata.type'] = derived7.dataSource.type;
                var derived8 = derived7.dataSource;
                
                if (derived8.resourceUri !== null && derived8.resourceUri !== undefined) {
                  dataSourceValue3['resourceUri'] = derived8.resourceUri;
                }
                
                if (derived8.metricNamespace !== null && derived8.metricNamespace !== undefined) {
                  dataSourceValue3['metricNamespace'] = derived8.metricNamespace;
                }
                
                if (derived8.metricName !== null && derived8.metricName !== undefined) {
                  dataSourceValue3['metricName'] = derived8.metricName;
                }
              }
              if (derived7.dataSource.type === 'Microsoft.Azure.Management.Insights.Models.RuleManagementEventDataSource') {
                dataSourceValue3['odata.type'] = derived7.dataSource.type;
                var derived9 = derived7.dataSource;
                
                if (derived9.eventName !== null && derived9.eventName !== undefined) {
                  dataSourceValue3['eventName'] = derived9.eventName;
                }
                
                if (derived9.eventSource !== null && derived9.eventSource !== undefined) {
                  dataSourceValue3['eventSource'] = derived9.eventSource;
                }
                
                if (derived9.level !== null && derived9.level !== undefined) {
                  dataSourceValue3['level'] = derived9.level;
                }
                
                if (derived9.operationName !== null && derived9.operationName !== undefined) {
                  dataSourceValue3['operationName'] = derived9.operationName;
                }
                
                if (derived9.resourceGroupName !== null && derived9.resourceGroupName !== undefined) {
                  dataSourceValue3['resourceGroupName'] = derived9.resourceGroupName;
                }
                
                if (derived9.resourceProviderName !== null && derived9.resourceProviderName !== undefined) {
                  dataSourceValue3['resourceProviderName'] = derived9.resourceProviderName;
                }
                
                if (derived9.resourceUri !== null && derived9.resourceUri !== undefined) {
                  dataSourceValue3['resourceUri'] = derived9.resourceUri;
                }
                
                if (derived9.status !== null && derived9.status !== undefined) {
                  dataSourceValue3['status'] = derived9.status;
                }
                
                if (derived9.subStatus !== null && derived9.subStatus !== undefined) {
                  dataSourceValue3['subStatus'] = derived9.subStatus;
                }
                
                if (derived9.claims !== null && derived9.claims !== undefined) {
                  var claimsValue3 = {};
                  dataSourceValue3['claims'] = claimsValue3;
                  
                  if (derived9.claims.emailAddress !== null && derived9.claims.emailAddress !== undefined) {
                    claimsValue3['emailAddress'] = derived9.claims.emailAddress;
                  }
                }
              }
            }
            
            if (derived7.aggregation !== null && derived7.aggregation !== undefined) {
              var aggregationValue = {};
              conditionValue['aggregation'] = aggregationValue;
              
              if (derived7.aggregation.operator !== null && derived7.aggregation.operator !== undefined) {
                aggregationValue['operator'] = derived7.aggregation.operator !== null && derived7.aggregation.operator !== undefined ? derived7.aggregation.operator.toString() : 'GreaterThan';
              }
              
              if (derived7.aggregation.threshold !== null && derived7.aggregation.threshold !== undefined) {
                aggregationValue['threshold'] = derived7.aggregation.threshold;
              }
              
              if (derived7.aggregation.windowSize !== null && derived7.aggregation.windowSize !== undefined) {
                aggregationValue['windowSize'] = derived7.aggregation.windowSize.toIsoString();
              }
            }
          }
        }
        
        if (parameters.properties.action !== null && parameters.properties.action !== undefined) {
          var actionValue = {};
          propertiesValue['action'] = actionValue;
          if (parameters.properties.action.type === 'Microsoft.Azure.Management.Insights.Models.RuleEmailAction') {
            actionValue['odata.type'] = parameters.properties.action.type;
            var derived10 = parameters.properties.action;
            
            if (derived10.sendToServiceOwners !== null && derived10.sendToServiceOwners !== undefined) {
              actionValue['sendToServiceOwners'] = derived10.sendToServiceOwners;
            }
            
            if (derived10.customEmails !== null && derived10.customEmails !== undefined) {
              var customEmailsArray = [];
              for (var loweredIndex1 = 0; loweredIndex1 < derived10.customEmails.length; loweredIndex1 = loweredIndex1 + 1) {
                var customEmailsItem = derived10.customEmails[loweredIndex1];
                customEmailsArray.push(customEmailsItem);
              }
              actionValue['customEmails'] = customEmailsArray;
            }
          }
        }
        
        if (parameters.properties.lastUpdatedTime !== null && parameters.properties.lastUpdatedTime !== undefined) {
          propertiesValue['lastUpdatedTime'] = parameters.properties.lastUpdatedTime;
        }
      }
      
      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 && statusCode !== 201) {
          var error = new Error(body);
          error.statusCode = response.statusCode;
          return callback(error);
        }
        
        // Create Result
        var result = null;
        // Deserialize Response
        if (statusCode === 200 || statusCode === 201) {
          var responseContent = body;
          result = {};
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    return AlertOperations;
  })();
  
  var AutomatedExportOperations = ( /** @lends AutomatedExportOperations */ function() {
    /**
     * @class
     * Operations for managing automated export.
     * __NOTE__: An instance of this class is automatically created for an
     * instance of the [InsightsManagementClient] {@link
     * InsightsManagementClient~InsightsManagementClient}.
     * See [automatedExportOperations] {@link
     * InsightsManagementClient~InsightsManagementClient#automatedExportOperations}.
     * Initializes a new instance of the AutomatedExportOperations class.
     * @constructor
     * 
     * @param {InsightsManagementClient} client Reference to the service client.
     */
    function AutomatedExportOperations(client) {
      this.client = client;
    }
    
    /**
     * 
     * @param {string} resourceGroupName The resource group name.
     * 
     * @param {string} serverName The server name.
     * 
     * @param {string} databaseName The database name.
     * 
     * @param {AutomatedExportSettingCreateOrUpdateParameters} parameters
     * Parameters supplied to the operation.
     * 
     * @param {string} [parameters.location] Gets or sets the location of the
     * setting.
     * 
     * @param {object} [parameters.tags] Gets or sets the tags of the rule.
     * 
     * @param {AutomatedExportSetting} [parameters.properties] Gets or sets the
     * setting to create or update.
     * 
     * @param {DatabaseServerCredential}
     * [parameters.properties.databaseCredential] Gets or sets the credential
     * for the server hosting the database.
     * 
     * @param {string}
     * [parameters.properties.databaseCredential.databaseUserName] Gets or sets
     * the database user name.
     * 
     * @param {string}
     * [parameters.properties.databaseCredential.databasePassword] Gets or sets
     * the database password.
     * 
     * @param {BackupLocationProfile} [parameters.properties.blobStorageSetting]
     * Gets or sets the blob storage settings, where the exported file will be
     * written.
     * 
     * @param {string} [parameters.properties.blobStorageSetting.storageAccount]
     * Gets or sets the name of the storage account.
     * 
     * @param {DatabaseBackupOption} [parameters.properties.backupOption] Gets or
     * sets the backup job options.
     * 
     * @param {date} [parameters.properties.backupOption.startTime] Gets or sets
     * the start time for the job.
     * 
     * @param {TimeSpan} [parameters.properties.backupOption.repeatInterval] Gets
     * or sets the repeat interval.How often the automated export job will run.
     * 
     * @param {TimeSpan} [parameters.properties.backupOption.retentionPeriod]
     * Gets or sets the retention period.How long the exported files will be
     * saved.
     * 
     * @param {boolean} [parameters.properties.backupOption.keepAtLeastOneBackup]
     * Gets or sets the keep at least one backup flag.Whether at least one
     * exported file will be kept.
     * 
     * @param {DatabaseConsistencyOption}
     * [parameters.properties.backupOption.consistencyOption] Gets or sets the
     * database consistency option.
     * 
     * @param {boolean} [parameters.properties.enabled] Gets or sets the enable
     * flag. Specifies whether automated export is enabled for the resource.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    AutomatedExportOperations.prototype.createOrUpdateSetting = function(resourceGroupName, serverName, databaseName, parameters, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceGroupName === null || resourceGroupName === undefined) {
        return callback(new Error('resourceGroupName cannot be null.'));
      }
      if (serverName === null || serverName === undefined) {
        return callback(new Error('serverName cannot be null.'));
      }
      if (databaseName === null || databaseName === undefined) {
        return callback(new Error('databaseName cannot be null.'));
      }
      if (parameters === null || parameters === undefined) {
        return callback(new Error('parameters cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/subscriptions/';
      if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
        url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
      }
      url2 = url2 + '/resourcegroups/';
      url2 = url2 + encodeURIComponent(resourceGroupName);
      url2 = url2 + '/providers/microsoft.sql/servers/';
      url2 = url2 + encodeURIComponent(serverName);
      url2 = url2 + '/databases/';
      url2 = url2 + encodeURIComponent(databaseName);
      url2 = url2 + '/providers/microsoft.insights/automatedexportsettings/default';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'PUT';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // Serialize Request
      var requestContent = null;
      var requestDoc = null;
      
      var automatedExportSettingCreateOrUpdateParametersValue = {};
      requestDoc = automatedExportSettingCreateOrUpdateParametersValue;
      
      if (parameters.location !== null && parameters.location !== undefined) {
        automatedExportSettingCreateOrUpdateParametersValue['location'] = parameters.location;
      }
      
      if (parameters.tags !== null && parameters.tags !== undefined) {
        var tagsDictionary = {};
        for (var tagsKey in parameters.tags) {
          var tagsValue = parameters.tags[tagsKey];
          tagsDictionary[tagsKey] = tagsValue;
        }
        automatedExportSettingCreateOrUpdateParametersValue['tags'] = tagsDictionary;
      }
      
      if (parameters.properties !== null && parameters.properties !== undefined) {
        var propertiesValue = {};
        automatedExportSettingCreateOrUpdateParametersValue['properties'] = propertiesValue;
        
        if (parameters.properties.databaseCredential !== null && parameters.properties.databaseCredential !== undefined) {
          var databaseCredentialValue = {};
          propertiesValue['databaseCredential'] = databaseCredentialValue;
          
          if (parameters.properties.databaseCredential.databaseUserName !== null && parameters.properties.databaseCredential.databaseUserName !== undefined) {
            databaseCredentialValue['databaseUserName'] = parameters.properties.databaseCredential.databaseUserName;
          }
          
          if (parameters.properties.databaseCredential.databasePassword !== null && parameters.properties.databaseCredential.databasePassword !== undefined) {
            databaseCredentialValue['databasePassword'] = parameters.properties.databaseCredential.databasePassword;
          }
        }
        
        if (parameters.properties.blobStorageSetting !== null && parameters.properties.blobStorageSetting !== undefined) {
          var blobStorageSettingValue = {};
          propertiesValue['blobStorageSetting'] = blobStorageSettingValue;
          
          if (parameters.properties.blobStorageSetting.storageAccount !== null && parameters.properties.blobStorageSetting.storageAccount !== undefined) {
            blobStorageSettingValue['storageAccount'] = parameters.properties.blobStorageSetting.storageAccount;
          }
        }
        
        if (parameters.properties.backupOption !== null && parameters.properties.backupOption !== undefined) {
          var backupOptionValue = {};
          propertiesValue['backupOption'] = backupOptionValue;
          
          if (parameters.properties.backupOption.startTime !== null && parameters.properties.backupOption.startTime !== undefined) {
            backupOptionValue['startTime'] = parameters.properties.backupOption.startTime;
          }
          
          if (parameters.properties.backupOption.repeatInterval !== null && parameters.properties.backupOption.repeatInterval !== undefined) {
            backupOptionValue['repeatInterval'] = parameters.properties.backupOption.repeatInterval.toIsoString();
          }
          
          if (parameters.properties.backupOption.retentionPeriod !== null && parameters.properties.backupOption.retentionPeriod !== undefined) {
            backupOptionValue['retentionPeriod'] = parameters.properties.backupOption.retentionPeriod.toIsoString();
          }
          
          if (parameters.properties.backupOption.keepAtLeastOneBackup !== null && parameters.properties.backupOption.keepAtLeastOneBackup !== undefined) {
            backupOptionValue['keepAtLeastOneBackup'] = parameters.properties.backupOption.keepAtLeastOneBackup;
          }
          
          if (parameters.properties.backupOption.consistencyOption !== null && parameters.properties.backupOption.consistencyOption !== undefined) {
            backupOptionValue['consistencyOption'] = parameters.properties.backupOption.consistencyOption !== null && parameters.properties.backupOption.consistencyOption !== undefined ? parameters.properties.backupOption.consistencyOption.toString() : 'CreateCopy';
          }
        }
        
        if (parameters.properties.enabled !== null && parameters.properties.enabled !== undefined) {
          propertiesValue['enabled'] = parameters.properties.enabled;
        }
      }
      
      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 && statusCode !== 201) {
          var error = new Error(body);
          error.statusCode = response.statusCode;
          return callback(error);
        }
        
        // Create Result
        var result = null;
        // Deserialize Response
        if (statusCode === 200 || statusCode === 201) {
          var responseContent = body;
          result = {};
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceGroupName The resource name.
     * 
     * @param {string} serverName The server name.
     * 
     * @param {string} databaseName The database name.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    AutomatedExportOperations.prototype.deleteSetting = function(resourceGroupName, serverName, databaseName, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceGroupName === null || resourceGroupName === undefined) {
        return callback(new Error('resourceGroupName cannot be null.'));
      }
      if (serverName === null || serverName === undefined) {
        return callback(new Error('serverName cannot be null.'));
      }
      if (databaseName === null || databaseName === undefined) {
        return callback(new Error('databaseName cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/subscriptions/';
      if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
        url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
      }
      url2 = url2 + '/resourcegroups/';
      url2 = url2 + encodeURIComponent(resourceGroupName);
      url2 = url2 + '/providers/microsoft.sql/servers/';
      url2 = url2 + encodeURIComponent(serverName);
      url2 = url2 + '/databases/';
      url2 = url2 + encodeURIComponent(databaseName);
      url2 = url2 + '/providers/microsoft.insights/automatedexportsettings/default';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      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 = 'DELETE';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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
        if (statusCode === 200 || statusCode === 204) {
          var responseContent = body;
          result = {};
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceGroupName The resource name.
     * 
     * @param {string} serverName The server name.
     * 
     * @param {string} databaseName The database name.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    AutomatedExportOperations.prototype.getSetting = function(resourceGroupName, serverName, databaseName, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceGroupName === null || resourceGroupName === undefined) {
        return callback(new Error('resourceGroupName cannot be null.'));
      }
      if (serverName === null || serverName === undefined) {
        return callback(new Error('serverName cannot be null.'));
      }
      if (databaseName === null || databaseName === undefined) {
        return callback(new Error('databaseName cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/subscriptions/';
      if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
        url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
      }
      url2 = url2 + '/resourcegroups/';
      url2 = url2 + encodeURIComponent(resourceGroupName);
      url2 = url2 + '/providers/microsoft.sql/servers/';
      url2 = url2 + encodeURIComponent(serverName);
      url2 = url2 + '/databases/';
      url2 = url2 + encodeURIComponent(databaseName);
      url2 = url2 + '/providers/microsoft.insights/automatedexportsettings/default';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'GET';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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 = { tags: {} };
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
            var idValue = responseDoc['id'];
            if (idValue !== null && idValue !== undefined) {
              var idInstance = idValue;
              result.id = idInstance;
            }
            
            var locationValue = responseDoc['location'];
            if (locationValue !== null && locationValue !== undefined) {
              var locationInstance = locationValue;
              result.location = locationInstance;
            }
            
            var tagsSequenceElement = responseDoc['tags'];
            if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
              for (var property in tagsSequenceElement) {
                var tagsKey = property;
                var tagsValue = tagsSequenceElement[property];
                result.tags[tagsKey] = tagsValue;
              }
            }
            
            var propertiesValue = responseDoc['properties'];
            if (propertiesValue !== null && propertiesValue !== undefined) {
              var propertiesInstance = {};
              result.properties = propertiesInstance;
              
              var databaseCredentialValue = propertiesValue['databaseCredential'];
              if (databaseCredentialValue !== null && databaseCredentialValue !== undefined) {
                var databaseCredentialInstance = {};
                propertiesInstance.databaseCredential = databaseCredentialInstance;
                
                var databaseUserNameValue = databaseCredentialValue['databaseUserName'];
                if (databaseUserNameValue !== null && databaseUserNameValue !== undefined) {
                  var databaseUserNameInstance = databaseUserNameValue;
                  databaseCredentialInstance.databaseUserName = databaseUserNameInstance;
                }
                
                var databasePasswordValue = databaseCredentialValue['databasePassword'];
                if (databasePasswordValue !== null && databasePasswordValue !== undefined) {
                  var databasePasswordInstance = databasePasswordValue;
                  databaseCredentialInstance.databasePassword = databasePasswordInstance;
                }
              }
              
              var blobStorageSettingValue = propertiesValue['blobStorageSetting'];
              if (blobStorageSettingValue !== null && blobStorageSettingValue !== undefined) {
                var blobStorageSettingInstance = {};
                propertiesInstance.blobStorageSetting = blobStorageSettingInstance;
                
                var storageAccountValue = blobStorageSettingValue['storageAccount'];
                if (storageAccountValue !== null && storageAccountValue !== undefined) {
                  var storageAccountInstance = storageAccountValue;
                  blobStorageSettingInstance.storageAccount = storageAccountInstance;
                }
              }
              
              var backupOptionValue = propertiesValue['backupOption'];
              if (backupOptionValue !== null && backupOptionValue !== undefined) {
                var backupOptionInstance = {};
                propertiesInstance.backupOption = backupOptionInstance;
                
                var startTimeValue = backupOptionValue['startTime'];
                if (startTimeValue !== null && startTimeValue !== undefined) {
                  var startTimeInstance = startTimeValue;
                  backupOptionInstance.startTime = startTimeInstance;
                }
                
                var repeatIntervalValue = backupOptionValue['repeatInterval'];
                if (repeatIntervalValue !== null && repeatIntervalValue !== undefined) {
                  var repeatIntervalInstance = moment.duration(repeatIntervalValue);
                  backupOptionInstance.repeatInterval = repeatIntervalInstance;
                }
                
                var retentionPeriodValue = backupOptionValue['retentionPeriod'];
                if (retentionPeriodValue !== null && retentionPeriodValue !== undefined) {
                  var retentionPeriodInstance = moment.duration(retentionPeriodValue);
                  backupOptionInstance.retentionPeriod = retentionPeriodInstance;
                }
                
                var keepAtLeastOneBackupValue = backupOptionValue['keepAtLeastOneBackup'];
                if (keepAtLeastOneBackupValue !== null && keepAtLeastOneBackupValue !== undefined) {
                  var keepAtLeastOneBackupInstance = keepAtLeastOneBackupValue;
                  backupOptionInstance.keepAtLeastOneBackup = keepAtLeastOneBackupInstance;
                }
                
                var consistencyOptionValue = backupOptionValue['consistencyOption'];
                if (consistencyOptionValue !== null && consistencyOptionValue !== undefined) {
                  var consistencyOptionInstance = consistencyOptionValue;
                  backupOptionInstance.consistencyOption = consistencyOptionInstance;
                }
              }
              
              var enabledValue = propertiesValue['enabled'];
              if (enabledValue !== null && enabledValue !== undefined) {
                var enabledInstance = enabledValue;
                propertiesInstance.enabled = enabledInstance;
              }
            }
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceGroupName The resource name.
     * 
     * @param {string} serverName The server name.
     * 
     * @param {string} databaseName The database name.
     * 
     * @param {AutomatedExportSettingCreateOrUpdateParameters} parameters
     * Parameters supplied to the operation.
     * 
     * @param {string} [parameters.location] Gets or sets the location of the
     * setting.
     * 
     * @param {object} [parameters.tags] Gets or sets the tags of the rule.
     * 
     * @param {AutomatedExportSetting} [parameters.properties] Gets or sets the
     * setting to create or update.
     * 
     * @param {DatabaseServerCredential}
     * [parameters.properties.databaseCredential] Gets or sets the credential
     * for the server hosting the database.
     * 
     * @param {string}
     * [parameters.properties.databaseCredential.databaseUserName] Gets or sets
     * the database user name.
     * 
     * @param {string}
     * [parameters.properties.databaseCredential.databasePassword] Gets or sets
     * the database password.
     * 
     * @param {BackupLocationProfile} [parameters.properties.blobStorageSetting]
     * Gets or sets the blob storage settings, where the exported file will be
     * written.
     * 
     * @param {string} [parameters.properties.blobStorageSetting.storageAccount]
     * Gets or sets the name of the storage account.
     * 
     * @param {DatabaseBackupOption} [parameters.properties.backupOption] Gets or
     * sets the backup job options.
     * 
     * @param {date} [parameters.properties.backupOption.startTime] Gets or sets
     * the start time for the job.
     * 
     * @param {TimeSpan} [parameters.properties.backupOption.repeatInterval] Gets
     * or sets the repeat interval.How often the automated export job will run.
     * 
     * @param {TimeSpan} [parameters.properties.backupOption.retentionPeriod]
     * Gets or sets the retention period.How long the exported files will be
     * saved.
     * 
     * @param {boolean} [parameters.properties.backupOption.keepAtLeastOneBackup]
     * Gets or sets the keep at least one backup flag.Whether at least one
     * exported file will be kept.
     * 
     * @param {DatabaseConsistencyOption}
     * [parameters.properties.backupOption.consistencyOption] Gets or sets the
     * database consistency option.
     * 
     * @param {boolean} [parameters.properties.enabled] Gets or sets the enable
     * flag. Specifies whether automated export is enabled for the resource.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    AutomatedExportOperations.prototype.updateSetting = function(resourceGroupName, serverName, databaseName, parameters, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceGroupName === null || resourceGroupName === undefined) {
        return callback(new Error('resourceGroupName cannot be null.'));
      }
      if (serverName === null || serverName === undefined) {
        return callback(new Error('serverName cannot be null.'));
      }
      if (databaseName === null || databaseName === undefined) {
        return callback(new Error('databaseName cannot be null.'));
      }
      if (parameters === null || parameters === undefined) {
        return callback(new Error('parameters cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/subscriptions/';
      if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
        url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
      }
      url2 = url2 + '/resourcegroups/';
      url2 = url2 + encodeURIComponent(resourceGroupName);
      url2 = url2 + '/providers/microsoft.sql/servers/';
      url2 = url2 + encodeURIComponent(serverName);
      url2 = url2 + '/databases/';
      url2 = url2 + encodeURIComponent(databaseName);
      url2 = url2 + '/providers/microsoft.insights/automatedexportsettings/default';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      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 = 'PATCH';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // Serialize Request
      var requestContent = null;
      var requestDoc = null;
      
      var automatedExportSettingCreateOrUpdateParametersValue = {};
      requestDoc = automatedExportSettingCreateOrUpdateParametersValue;
      
      if (parameters.location !== null && parameters.location !== undefined) {
        automatedExportSettingCreateOrUpdateParametersValue['location'] = parameters.location;
      }
      
      if (parameters.tags !== null && parameters.tags !== undefined) {
        var tagsDictionary = {};
        for (var tagsKey in parameters.tags) {
          var tagsValue = parameters.tags[tagsKey];
          tagsDictionary[tagsKey] = tagsValue;
        }
        automatedExportSettingCreateOrUpdateParametersValue['tags'] = tagsDictionary;
      }
      
      if (parameters.properties !== null && parameters.properties !== undefined) {
        var propertiesValue = {};
        automatedExportSettingCreateOrUpdateParametersValue['properties'] = propertiesValue;
        
        if (parameters.properties.databaseCredential !== null && parameters.properties.databaseCredential !== undefined) {
          var databaseCredentialValue = {};
          propertiesValue['databaseCredential'] = databaseCredentialValue;
          
          if (parameters.properties.databaseCredential.databaseUserName !== null && parameters.properties.databaseCredential.databaseUserName !== undefined) {
            databaseCredentialValue['databaseUserName'] = parameters.properties.databaseCredential.databaseUserName;
          }
          
          if (parameters.properties.databaseCredential.databasePassword !== null && parameters.properties.databaseCredential.databasePassword !== undefined) {
            databaseCredentialValue['databasePassword'] = parameters.properties.databaseCredential.databasePassword;
          }
        }
        
        if (parameters.properties.blobStorageSetting !== null && parameters.properties.blobStorageSetting !== undefined) {
          var blobStorageSettingValue = {};
          propertiesValue['blobStorageSetting'] = blobStorageSettingValue;
          
          if (parameters.properties.blobStorageSetting.storageAccount !== null && parameters.properties.blobStorageSetting.storageAccount !== undefined) {
            blobStorageSettingValue['storageAccount'] = parameters.properties.blobStorageSetting.storageAccount;
          }
        }
        
        if (parameters.properties.backupOption !== null && parameters.properties.backupOption !== undefined) {
          var backupOptionValue = {};
          propertiesValue['backupOption'] = backupOptionValue;
          
          if (parameters.properties.backupOption.startTime !== null && parameters.properties.backupOption.startTime !== undefined) {
            backupOptionValue['startTime'] = parameters.properties.backupOption.startTime;
          }
          
          if (parameters.properties.backupOption.repeatInterval !== null && parameters.properties.backupOption.repeatInterval !== undefined) {
            backupOptionValue['repeatInterval'] = parameters.properties.backupOption.repeatInterval.toIsoString();
          }
          
          if (parameters.properties.backupOption.retentionPeriod !== null && parameters.properties.backupOption.retentionPeriod !== undefined) {
            backupOptionValue['retentionPeriod'] = parameters.properties.backupOption.retentionPeriod.toIsoString();
          }
          
          if (parameters.properties.backupOption.keepAtLeastOneBackup !== null && parameters.properties.backupOption.keepAtLeastOneBackup !== undefined) {
            backupOptionValue['keepAtLeastOneBackup'] = parameters.properties.backupOption.keepAtLeastOneBackup;
          }
          
          if (parameters.properties.backupOption.consistencyOption !== null && parameters.properties.backupOption.consistencyOption !== undefined) {
            backupOptionValue['consistencyOption'] = parameters.properties.backupOption.consistencyOption !== null && parameters.properties.backupOption.consistencyOption !== undefined ? parameters.properties.backupOption.consistencyOption.toString() : 'CreateCopy';
          }
        }
        
        if (parameters.properties.enabled !== null && parameters.properties.enabled !== undefined) {
          propertiesValue['enabled'] = parameters.properties.enabled;
        }
      }
      
      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 && statusCode !== 201) {
          var error = new Error(body);
          error.statusCode = response.statusCode;
          return callback(error);
        }
        
        // Create Result
        var result = null;
        // Deserialize Response
        if (statusCode === 200 || statusCode === 201) {
          var responseContent = body;
          result = {};
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    return AutomatedExportOperations;
  })();
  
  var AutoscaleOperations = ( /** @lends AutoscaleOperations */ function() {
    /**
     * @class
     * Operations for managing autoscale.
     * __NOTE__: An instance of this class is automatically created for an
     * instance of the [InsightsManagementClient] {@link
     * InsightsManagementClient~InsightsManagementClient}.
     * See [autoscaleOperations] {@link
     * InsightsManagementClient~InsightsManagementClient#autoscaleOperations}.
     * Initializes a new instance of the AutoscaleOperations class.
     * @constructor
     * 
     * @param {InsightsManagementClient} client Reference to the service client.
     */
    function AutoscaleOperations(client) {
      this.client = client;
    }
    
    /**
     * 
     * @param {string} resourceGroupName The resource name.
     * 
     * @param {string} autoscaleSettingName The autoscale setting name.
     * 
     * @param {AutoscaleSettingCreateOrUpdateParameters} parameters Parameters
     * supplied to the operation.
     * 
     * @param {string} [parameters.location] Gets or sets the location of the
     * setting.
     * 
     * @param {object} [parameters.tags] Gets or sets the tags of the rule.
     * 
     * @param {AutoscaleSetting} [parameters.properties] Gets or sets the setting
     * to create or update.
     * 
     * @param {array} [parameters.properties.profiles] Gets or sets the
     * collection of automatic scaling profiles that specify different scaling
     * parameters for different time periods. A maximum of 20 profiles can be
     * specified.
     * 
     * @param {boolean} [parameters.properties.enabled] Gets or sets the enabled
     * flag.Specifies whether automatic scaling is enabled for the resource.
     * 
     * @param {string} [parameters.properties.name] Gets or sets the name of the
     * autoscale setting.
     * 
     * @param {string} [parameters.properties.targetResourceUri] Gets or sets the
     * resource identifier of the resource that the autoscale setting should be
     * added to.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    AutoscaleOperations.prototype.createOrUpdateSetting = function(resourceGroupName, autoscaleSettingName, parameters, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceGroupName === null || resourceGroupName === undefined) {
        return callback(new Error('resourceGroupName cannot be null.'));
      }
      if (autoscaleSettingName === null || autoscaleSettingName === undefined) {
        return callback(new Error('autoscaleSettingName cannot be null.'));
      }
      if (parameters === null || parameters === undefined) {
        return callback(new Error('parameters cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/subscriptions/';
      if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
        url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
      }
      url2 = url2 + '/resourcegroups/';
      url2 = url2 + encodeURIComponent(resourceGroupName);
      url2 = url2 + '/providers/microsoft.insights/autoscalesettings/';
      url2 = url2 + encodeURIComponent(autoscaleSettingName);
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'PUT';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // Serialize Request
      var requestContent = null;
      var requestDoc = null;
      
      var autoscaleSettingCreateOrUpdateParametersValue = {};
      requestDoc = autoscaleSettingCreateOrUpdateParametersValue;
      
      if (parameters.location !== null && parameters.location !== undefined) {
        autoscaleSettingCreateOrUpdateParametersValue['location'] = parameters.location;
      }
      
      if (parameters.tags !== null && parameters.tags !== undefined) {
        var tagsDictionary = {};
        for (var tagsKey in parameters.tags) {
          var tagsValue = parameters.tags[tagsKey];
          tagsDictionary[tagsKey] = tagsValue;
        }
        autoscaleSettingCreateOrUpdateParametersValue['tags'] = tagsDictionary;
      }
      
      if (parameters.properties !== null && parameters.properties !== undefined) {
        var propertiesValue = {};
        autoscaleSettingCreateOrUpdateParametersValue['properties'] = propertiesValue;
        
        if (parameters.properties.profiles !== null && parameters.properties.profiles !== undefined) {
          var profilesArray = [];
          for (var loweredIndex1 = 0; loweredIndex1 < parameters.properties.profiles.length; loweredIndex1 = loweredIndex1 + 1) {
            var profilesItem = parameters.properties.profiles[loweredIndex1];
            var autoscaleProfileValue = {};
            profilesArray.push(autoscaleProfileValue);
            
            if (profilesItem.name !== null && profilesItem.name !== undefined) {
              autoscaleProfileValue['name'] = profilesItem.name;
            }
            
            if (profilesItem.capacity !== null && profilesItem.capacity !== undefined) {
              var capacityValue = {};
              autoscaleProfileValue['capacity'] = capacityValue;
              
              if (profilesItem.capacity.minimum !== null && profilesItem.capacity.minimum !== undefined) {
                capacityValue['minimum'] = profilesItem.capacity.minimum;
              }
              
              if (profilesItem.capacity.maximum !== null && profilesItem.capacity.maximum !== undefined) {
                capacityValue['maximum'] = profilesItem.capacity.maximum;
              }
              
              if (profilesItem.capacity.default !== null && profilesItem.capacity.default !== undefined) {
                capacityValue['default'] = profilesItem.capacity.default;
              }
            }
            
            if (profilesItem.rules !== null && profilesItem.rules !== undefined) {
              var rulesArray = [];
              for (var loweredIndex2 = 0; loweredIndex2 < profilesItem.rules.length; loweredIndex2 = loweredIndex2 + 1) {
                var rulesItem = profilesItem.rules[loweredIndex2];
                var scaleRuleValue = {};
                rulesArray.push(scaleRuleValue);
                
                if (rulesItem.metricTrigger !== null && rulesItem.metricTrigger !== undefined) {
                  var metricTriggerValue = {};
                  scaleRuleValue['metricTrigger'] = metricTriggerValue;
                  
                  if (rulesItem.metricTrigger.metricName !== null && rulesItem.metricTrigger.metricName !== undefined) {
                    metricTriggerValue['metricName'] = rulesItem.metricTrigger.metricName;
                  }
                  
                  if (rulesItem.metricTrigger.metricNamespace !== null && rulesItem.metricTrigger.metricNamespace !== undefined) {
                    metricTriggerValue['metricNamespace'] = rulesItem.metricTrigger.metricNamespace;
                  }
                  
                  if (rulesItem.metricTrigger.metricResourceUri !== null && rulesItem.metricTrigger.metricResourceUri !== undefined) {
                    metricTriggerValue['metricResourceUri'] = rulesItem.metricTrigger.metricResourceUri;
                  }
                  
                  if (rulesItem.metricTrigger.timeGrain !== null && rulesItem.metricTrigger.timeGrain !== undefined) {
                    metricTriggerValue['timeGrain'] = rulesItem.metricTrigger.timeGrain.toIsoString();
                  }
                  
                  if (rulesItem.metricTrigger.statistic !== null && rulesItem.metricTrigger.statistic !== undefined) {
                    metricTriggerValue['statistic'] = rulesItem.metricTrigger.statistic !== null && rulesItem.metricTrigger.statistic !== undefined ? rulesItem.metricTrigger.statistic.toString() : 'Average';
                  }
                  
                  if (rulesItem.metricTrigger.timeWindow !== null && rulesItem.metricTrigger.timeWindow !== undefined) {
                    metricTriggerValue['timeWindow'] = rulesItem.metricTrigger.timeWindow.toIsoString();
                  }
                  
                  if (rulesItem.metricTrigger.timeAggregation !== null && rulesItem.metricTrigger.timeAggregation !== undefined) {
                    metricTriggerValue['timeAggregation'] = rulesItem.metricTrigger.timeAggregation !== null && rulesItem.metricTrigger.timeAggregation !== undefined ? rulesItem.metricTrigger.timeAggregation.toString() : 'Average';
                  }
                  
                  if (rulesItem.metricTrigger.operator !== null && rulesItem.metricTrigger.operator !== undefined) {
                    metricTriggerValue['operator'] = rulesItem.metricTrigger.operator !== null && rulesItem.metricTrigger.operator !== undefined ? rulesItem.metricTrigger.operator.toString() : 'Equals';
                  }
                  
                  if (rulesItem.metricTrigger.threshold !== null && rulesItem.metricTrigger.threshold !== undefined) {
                    metricTriggerValue['threshold'] = rulesItem.metricTrigger.threshold;
                  }
                }
                
                if (rulesItem.scaleAction !== null && rulesItem.scaleAction !== undefined) {
                  var scaleActionValue = {};
                  scaleRuleValue['scaleAction'] = scaleActionValue;
                  
                  if (rulesItem.scaleAction.direction !== null && rulesItem.scaleAction.direction !== undefined) {
                    scaleActionValue['direction'] = rulesItem.scaleAction.direction !== null && rulesItem.scaleAction.direction !== undefined ? rulesItem.scaleAction.direction.toString() : 'None';
                  }
                  
                  if (rulesItem.scaleAction.type !== null && rulesItem.scaleAction.type !== undefined) {
                    scaleActionValue['type'] = rulesItem.scaleAction.type !== null && rulesItem.scaleAction.type !== undefined ? rulesItem.scaleAction.type.toString() : 'ChangeSize';
                  }
                  
                  if (rulesItem.scaleAction.value !== null && rulesItem.scaleAction.value !== undefined) {
                    scaleActionValue['value'] = rulesItem.scaleAction.value;
                  }
                  
                  if (rulesItem.scaleAction.cooldown !== null && rulesItem.scaleAction.cooldown !== undefined) {
                    scaleActionValue['cooldown'] = rulesItem.scaleAction.cooldown.toIsoString();
                  }
                }
              }
              autoscaleProfileValue['rules'] = rulesArray;
            }
            
            if (profilesItem.fixedDate !== null && profilesItem.fixedDate !== undefined) {
              var fixedDateValue = {};
              autoscaleProfileValue['fixedDate'] = fixedDateValue;
              
              if (profilesItem.fixedDate.timeZone !== null && profilesItem.fixedDate.timeZone !== undefined) {
                fixedDateValue['timeZone'] = profilesItem.fixedDate.timeZone;
              }
              
              if (profilesItem.fixedDate.start !== null && profilesItem.fixedDate.start !== undefined) {
                fixedDateValue['start'] = profilesItem.fixedDate.start;
              }
              
              if (profilesItem.fixedDate.end !== null && profilesItem.fixedDate.end !== undefined) {
                fixedDateValue['end'] = profilesItem.fixedDate.end;
              }
            }
            
            if (profilesItem.recurrence !== null && profilesItem.recurrence !== undefined) {
              var recurrenceValue = {};
              autoscaleProfileValue['recurrence'] = recurrenceValue;
              
              if (profilesItem.recurrence.frequency !== null && profilesItem.recurrence.frequency !== undefined) {
                recurrenceValue['frequency'] = profilesItem.recurrence.frequency !== null && profilesItem.recurrence.frequency !== undefined ? profilesItem.recurrence.frequency.toString() : 'None';
              }
              
              if (profilesItem.recurrence.schedule !== null && profilesItem.recurrence.schedule !== undefined) {
                var scheduleValue = {};
                recurrenceValue['schedule'] = scheduleValue;
                
                if (profilesItem.recurrence.schedule.timeZone !== null && profilesItem.recurrence.schedule.timeZone !== undefined) {
                  scheduleValue['timeZone'] = profilesItem.recurrence.schedule.timeZone;
                }
                
                if (profilesItem.recurrence.schedule.days !== null && profilesItem.recurrence.schedule.days !== undefined) {
                  var daysArray = [];
                  for (var loweredIndex3 = 0; loweredIndex3 < profilesItem.recurrence.schedule.days.length; loweredIndex3 = loweredIndex3 + 1) {
                    var daysItem = profilesItem.recurrence.schedule.days[loweredIndex3];
                    daysArray.push(daysItem);
                  }
                  scheduleValue['days'] = daysArray;
                }
                
                if (profilesItem.recurrence.schedule.hours !== null && profilesItem.recurrence.schedule.hours !== undefined) {
                  var hoursArray = [];
                  for (var loweredIndex4 = 0; loweredIndex4 < profilesItem.recurrence.schedule.hours.length; loweredIndex4 = loweredIndex4 + 1) {
                    var hoursItem = profilesItem.recurrence.schedule.hours[loweredIndex4];
                    hoursArray.push(hoursItem);
                  }
                  scheduleValue['hours'] = hoursArray;
                }
                
                if (profilesItem.recurrence.schedule.minutes !== null && profilesItem.recurrence.schedule.minutes !== undefined) {
                  var minutesArray = [];
                  for (var loweredIndex5 = 0; loweredIndex5 < profilesItem.recurrence.schedule.minutes.length; loweredIndex5 = loweredIndex5 + 1) {
                    var minutesItem = profilesItem.recurrence.schedule.minutes[loweredIndex5];
                    minutesArray.push(minutesItem);
                  }
                  scheduleValue['minutes'] = minutesArray;
                }
              }
            }
          }
          propertiesValue['profiles'] = profilesArray;
        }
        
        if (parameters.properties.enabled !== null && parameters.properties.enabled !== undefined) {
          propertiesValue['enabled'] = parameters.properties.enabled;
        }
        
        if (parameters.properties.name !== null && parameters.properties.name !== undefined) {
          propertiesValue['name'] = parameters.properties.name;
        }
        
        if (parameters.properties.targetResourceUri !== null && parameters.properties.targetResourceUri !== undefined) {
          propertiesValue['targetResourceUri'] = parameters.properties.targetResourceUri;
        }
      }
      
      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 && statusCode !== 201) {
          var error = new Error(body);
          error.statusCode = response.statusCode;
          return callback(error);
        }
        
        // Create Result
        var result = null;
        // Deserialize Response
        if (statusCode === 200 || statusCode === 201) {
          var responseContent = body;
          result = {};
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceGroupName The resource name.
     * 
     * @param {string} autoscaleSettingName The autoscale setting name.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    AutoscaleOperations.prototype.deleteSetting = function(resourceGroupName, autoscaleSettingName, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceGroupName === null || resourceGroupName === undefined) {
        return callback(new Error('resourceGroupName cannot be null.'));
      }
      if (autoscaleSettingName === null || autoscaleSettingName === undefined) {
        return callback(new Error('autoscaleSettingName cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/subscriptions/';
      if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
        url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
      }
      url2 = url2 + '/resourcegroups/';
      url2 = url2 + encodeURIComponent(resourceGroupName);
      url2 = url2 + '/providers/microsoft.insights/autoscalesettings/';
      url2 = url2 + encodeURIComponent(autoscaleSettingName);
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      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 = 'DELETE';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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
        if (statusCode === 200 || statusCode === 204) {
          var responseContent = body;
          result = {};
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceGroupName The resource name.
     * 
     * @param {string} autoscaleSettingName The autoscale setting name.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    AutoscaleOperations.prototype.getSetting = function(resourceGroupName, autoscaleSettingName, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceGroupName === null || resourceGroupName === undefined) {
        return callback(new Error('resourceGroupName cannot be null.'));
      }
      if (autoscaleSettingName === null || autoscaleSettingName === undefined) {
        return callback(new Error('autoscaleSettingName cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/subscriptions/';
      if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
        url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
      }
      url2 = url2 + '/resourcegroups/';
      url2 = url2 + encodeURIComponent(resourceGroupName);
      url2 = url2 + '/providers/microsoft.insights/autoscalesettings/';
      url2 = url2 + encodeURIComponent(autoscaleSettingName);
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'GET';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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 = { tags: {} };
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
            var idValue = responseDoc['id'];
            if (idValue !== null && idValue !== undefined) {
              var idInstance = idValue;
              result.id = idInstance;
            }
            
            var nameValue = responseDoc['name'];
            if (nameValue !== null && nameValue !== undefined) {
              var nameInstance = nameValue;
              result.name = nameInstance;
            }
            
            var locationValue = responseDoc['location'];
            if (locationValue !== null && locationValue !== undefined) {
              var locationInstance = locationValue;
              result.location = locationInstance;
            }
            
            var tagsSequenceElement = responseDoc['tags'];
            if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
              for (var property in tagsSequenceElement) {
                var tagsKey = property;
                var tagsValue = tagsSequenceElement[property];
                result.tags[tagsKey] = tagsValue;
              }
            }
            
            var propertiesValue = responseDoc['properties'];
            if (propertiesValue !== null && propertiesValue !== undefined) {
              var propertiesInstance = { profiles: [] };
              result.properties = propertiesInstance;
              
              var profilesArray = propertiesValue['profiles'];
              if (profilesArray !== null && profilesArray !== undefined) {
                for (var loweredIndex1 = 0; loweredIndex1 < profilesArray.length; loweredIndex1 = loweredIndex1 + 1) {
                  var profilesValue = profilesArray[loweredIndex1];
                  var autoscaleProfileInstance = { rules: [] };
                  propertiesInstance.profiles.push(autoscaleProfileInstance);
                  
                  var nameValue2 = profilesValue['name'];
                  if (nameValue2 !== null && nameValue2 !== undefined) {
                    var nameInstance2 = nameValue2;
                    autoscaleProfileInstance.name = nameInstance2;
                  }
                  
                  var capacityValue = profilesValue['capacity'];
                  if (capacityValue !== null && capacityValue !== undefined) {
                    var capacityInstance = {};
                    autoscaleProfileInstance.capacity = capacityInstance;
                    
                    var minimumValue = capacityValue['minimum'];
                    if (minimumValue !== null && minimumValue !== undefined) {
                      var minimumInstance = minimumValue;
                      capacityInstance.minimum = minimumInstance;
                    }
                    
                    var maximumValue = capacityValue['maximum'];
                    if (maximumValue !== null && maximumValue !== undefined) {
                      var maximumInstance = maximumValue;
                      capacityInstance.maximum = maximumInstance;
                    }
                    
                    var defaultValue = capacityValue['default'];
                    if (defaultValue !== null && defaultValue !== undefined) {
                      var defaultInstance = defaultValue;
                      capacityInstance.default = defaultInstance;
                    }
                  }
                  
                  var rulesArray = profilesValue['rules'];
                  if (rulesArray !== null && rulesArray !== undefined) {
                    for (var loweredIndex2 = 0; loweredIndex2 < rulesArray.length; loweredIndex2 = loweredIndex2 + 1) {
                      var rulesValue = rulesArray[loweredIndex2];
                      var scaleRuleInstance = {};
                      autoscaleProfileInstance.rules.push(scaleRuleInstance);
                      
                      var metricTriggerValue = rulesValue['metricTrigger'];
                      if (metricTriggerValue !== null && metricTriggerValue !== undefined) {
                        var metricTriggerInstance = {};
                        scaleRuleInstance.metricTrigger = metricTriggerInstance;
                        
                        var metricNameValue = metricTriggerValue['metricName'];
                        if (metricNameValue !== null && metricNameValue !== undefined) {
                          var metricNameInstance = metricNameValue;
                          metricTriggerInstance.metricName = metricNameInstance;
                        }
                        
                        var metricNamespaceValue = metricTriggerValue['metricNamespace'];
                        if (metricNamespaceValue !== null && metricNamespaceValue !== undefined) {
                          var metricNamespaceInstance = metricNamespaceValue;
                          metricTriggerInstance.metricNamespace = metricNamespaceInstance;
                        }
                        
                        var metricResourceUriValue = metricTriggerValue['metricResourceUri'];
                        if (metricResourceUriValue !== null && metricResourceUriValue !== undefined) {
                          var metricResourceUriInstance = metricResourceUriValue;
                          metricTriggerInstance.metricResourceUri = metricResourceUriInstance;
                        }
                        
                        var timeGrainValue = metricTriggerValue['timeGrain'];
                        if (timeGrainValue !== null && timeGrainValue !== undefined) {
                          var timeGrainInstance = moment.duration(timeGrainValue);
                          metricTriggerInstance.timeGrain = timeGrainInstance;
                        }
                        
                        var statisticValue = metricTriggerValue['statistic'];
                        if (statisticValue !== null && statisticValue !== undefined) {
                          var statisticInstance = statisticValue;
                          metricTriggerInstance.statistic = statisticInstance;
                        }
                        
                        var timeWindowValue = metricTriggerValue['timeWindow'];
                        if (timeWindowValue !== null && timeWindowValue !== undefined) {
                          var timeWindowInstance = moment.duration(timeWindowValue);
                          metricTriggerInstance.timeWindow = timeWindowInstance;
                        }
                        
                        var timeAggregationValue = metricTriggerValue['timeAggregation'];
                        if (timeAggregationValue !== null && timeAggregationValue !== undefined) {
                          var timeAggregationInstance = timeAggregationValue;
                          metricTriggerInstance.timeAggregation = timeAggregationInstance;
                        }
                        
                        var operatorValue = metricTriggerValue['operator'];
                        if (operatorValue !== null && operatorValue !== undefined) {
                          var operatorInstance = operatorValue;
                          metricTriggerInstance.operator = operatorInstance;
                        }
                        
                        var thresholdValue = metricTriggerValue['threshold'];
                        if (thresholdValue !== null && thresholdValue !== undefined) {
                          var thresholdInstance = thresholdValue;
                          metricTriggerInstance.threshold = thresholdInstance;
                        }
                      }
                      
                      var scaleActionValue = rulesValue['scaleAction'];
                      if (scaleActionValue !== null && scaleActionValue !== undefined) {
                        var scaleActionInstance = {};
                        scaleRuleInstance.scaleAction = scaleActionInstance;
                        
                        var directionValue = scaleActionValue['direction'];
                        if (directionValue !== null && directionValue !== undefined) {
                          var directionInstance = directionValue;
                          scaleActionInstance.direction = directionInstance;
                        }
                        
                        var typeValue = scaleActionValue['type'];
                        if (typeValue !== null && typeValue !== undefined) {
                          var typeInstance = typeValue;
                          scaleActionInstance.type = typeInstance;
                        }
                        
                        var valueValue = scaleActionValue['value'];
                        if (valueValue !== null && valueValue !== undefined) {
                          var valueInstance = valueValue;
                          scaleActionInstance.value = valueInstance;
                        }
                        
                        var cooldownValue = scaleActionValue['cooldown'];
                        if (cooldownValue !== null && cooldownValue !== undefined) {
                          var cooldownInstance = moment.duration(cooldownValue);
                          scaleActionInstance.cooldown = cooldownInstance;
                        }
                      }
                    }
                  }
                  
                  var fixedDateValue = profilesValue['fixedDate'];
                  if (fixedDateValue !== null && fixedDateValue !== undefined) {
                    var fixedDateInstance = {};
                    autoscaleProfileInstance.fixedDate = fixedDateInstance;
                    
                    var timeZoneValue = fixedDateValue['timeZone'];
                    if (timeZoneValue !== null && timeZoneValue !== undefined) {
                      var timeZoneInstance = timeZoneValue;
                      fixedDateInstance.timeZone = timeZoneInstance;
                    }
                    
                    var startValue = fixedDateValue['start'];
                    if (startValue !== null && startValue !== undefined) {
                      var startInstance = startValue;
                      fixedDateInstance.start = startInstance;
                    }
                    
                    var endValue = fixedDateValue['end'];
                    if (endValue !== null && endValue !== undefined) {
                      var endInstance = endValue;
                      fixedDateInstance.end = endInstance;
                    }
                  }
                  
                  var recurrenceValue = profilesValue['recurrence'];
                  if (recurrenceValue !== null && recurrenceValue !== undefined) {
                    var recurrenceInstance = {};
                    autoscaleProfileInstance.recurrence = recurrenceInstance;
                    
                    var frequencyValue = recurrenceValue['frequency'];
                    if (frequencyValue !== null && frequencyValue !== undefined) {
                      var frequencyInstance = frequencyValue;
                      recurrenceInstance.frequency = frequencyInstance;
                    }
                    
                    var scheduleValue = recurrenceValue['schedule'];
                    if (scheduleValue !== null && scheduleValue !== undefined) {
                      var scheduleInstance = { days: [], hours: [], minutes: [] };
                      recurrenceInstance.schedule = scheduleInstance;
                      
                      var timeZoneValue2 = scheduleValue['timeZone'];
                      if (timeZoneValue2 !== null && timeZoneValue2 !== undefined) {
                        var timeZoneInstance2 = timeZoneValue2;
                        scheduleInstance.timeZone = timeZoneInstance2;
                      }
                      
                      var daysArray = scheduleValue['days'];
                      if (daysArray !== null && daysArray !== undefined) {
                        for (var loweredIndex3 = 0; loweredIndex3 < daysArray.length; loweredIndex3 = loweredIndex3 + 1) {
                          var daysValue = daysArray[loweredIndex3];
                          scheduleInstance.days.push(daysValue);
                        }
                      }
                      
                      var hoursArray = scheduleValue['hours'];
                      if (hoursArray !== null && hoursArray !== undefined) {
                        for (var loweredIndex4 = 0; loweredIndex4 < hoursArray.length; loweredIndex4 = loweredIndex4 + 1) {
                          var hoursValue = hoursArray[loweredIndex4];
                          scheduleInstance.hours.push(hoursValue);
                        }
                      }
                      
                      var minutesArray = scheduleValue['minutes'];
                      if (minutesArray !== null && minutesArray !== undefined) {
                        for (var loweredIndex5 = 0; loweredIndex5 < minutesArray.length; loweredIndex5 = loweredIndex5 + 1) {
                          var minutesValue = minutesArray[loweredIndex5];
                          scheduleInstance.minutes.push(minutesValue);
                        }
                      }
                    }
                  }
                }
              }
              
              var enabledValue = propertiesValue['enabled'];
              if (enabledValue !== null && enabledValue !== undefined) {
                var enabledInstance = enabledValue;
                propertiesInstance.enabled = enabledInstance;
              }
              
              var nameValue3 = propertiesValue['name'];
              if (nameValue3 !== null && nameValue3 !== undefined) {
                var nameInstance3 = nameValue3;
                propertiesInstance.name = nameInstance3;
              }
              
              var targetResourceUriValue = propertiesValue['targetResourceUri'];
              if (targetResourceUriValue !== null && targetResourceUriValue !== undefined) {
                var targetResourceUriInstance = targetResourceUriValue;
                propertiesInstance.targetResourceUri = targetResourceUriInstance;
              }
            }
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceGroupName The resource name.
     * 
     * @param {string} [targetResourceUri] The resource identifier of the target
     * of the autoscale setting.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    AutoscaleOperations.prototype.listSettings = function(resourceGroupName, targetResourceUri, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceGroupName === null || resourceGroupName === undefined) {
        return callback(new Error('resourceGroupName cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/subscriptions/';
      if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
        url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
      }
      url2 = url2 + '/resourcegroups/';
      url2 = url2 + encodeURIComponent(resourceGroupName);
      url2 = url2 + '/providers/microsoft.insights/autoscalesettings';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      var odataFilter = [];
      if (targetResourceUri !== null && targetResourceUri !== undefined) {
        odataFilter.push('targetResourceUri eq ' + encodeURIComponent(targetResourceUri));
      }
      if (odataFilter.length > 0) {
        queryParameters.push('$filter=' + odataFilter.join(null));
      }
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'GET';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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 autoscaleSettingResourceCollectionInstance = { value: [] };
            result.autoscaleSettingResourceCollection = autoscaleSettingResourceCollectionInstance;
            
            var valueArray = responseDoc['value'];
            if (valueArray !== null && valueArray !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
                var valueValue = valueArray[loweredIndex1];
                var autoscaleSettingResourceInstance = { tags: {} };
                autoscaleSettingResourceCollectionInstance.value.push(autoscaleSettingResourceInstance);
                
                var idValue = valueValue['id'];
                if (idValue !== null && idValue !== undefined) {
                  var idInstance = idValue;
                  autoscaleSettingResourceInstance.id = idInstance;
                }
                
                var nameValue = valueValue['name'];
                if (nameValue !== null && nameValue !== undefined) {
                  var nameInstance = nameValue;
                  autoscaleSettingResourceInstance.name = nameInstance;
                }
                
                var locationValue = valueValue['location'];
                if (locationValue !== null && locationValue !== undefined) {
                  var locationInstance = locationValue;
                  autoscaleSettingResourceInstance.location = locationInstance;
                }
                
                var tagsSequenceElement = valueValue['tags'];
                if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
                  for (var property in tagsSequenceElement) {
                    var tagsKey = property;
                    var tagsValue = tagsSequenceElement[property];
                    autoscaleSettingResourceInstance.tags[tagsKey] = tagsValue;
                  }
                }
                
                var propertiesValue = valueValue['properties'];
                if (propertiesValue !== null && propertiesValue !== undefined) {
                  var propertiesInstance = { profiles: [] };
                  autoscaleSettingResourceInstance.properties = propertiesInstance;
                  
                  var profilesArray = propertiesValue['profiles'];
                  if (profilesArray !== null && profilesArray !== undefined) {
                    for (var loweredIndex2 = 0; loweredIndex2 < profilesArray.length; loweredIndex2 = loweredIndex2 + 1) {
                      var profilesValue = profilesArray[loweredIndex2];
                      var autoscaleProfileInstance = { rules: [] };
                      propertiesInstance.profiles.push(autoscaleProfileInstance);
                      
                      var nameValue2 = profilesValue['name'];
                      if (nameValue2 !== null && nameValue2 !== undefined) {
                        var nameInstance2 = nameValue2;
                        autoscaleProfileInstance.name = nameInstance2;
                      }
                      
                      var capacityValue = profilesValue['capacity'];
                      if (capacityValue !== null && capacityValue !== undefined) {
                        var capacityInstance = {};
                        autoscaleProfileInstance.capacity = capacityInstance;
                        
                        var minimumValue = capacityValue['minimum'];
                        if (minimumValue !== null && minimumValue !== undefined) {
                          var minimumInstance = minimumValue;
                          capacityInstance.minimum = minimumInstance;
                        }
                        
                        var maximumValue = capacityValue['maximum'];
                        if (maximumValue !== null && maximumValue !== undefined) {
                          var maximumInstance = maximumValue;
                          capacityInstance.maximum = maximumInstance;
                        }
                        
                        var defaultValue = capacityValue['default'];
                        if (defaultValue !== null && defaultValue !== undefined) {
                          var defaultInstance = defaultValue;
                          capacityInstance.default = defaultInstance;
                        }
                      }
                      
                      var rulesArray = profilesValue['rules'];
                      if (rulesArray !== null && rulesArray !== undefined) {
                        for (var loweredIndex3 = 0; loweredIndex3 < rulesArray.length; loweredIndex3 = loweredIndex3 + 1) {
                          var rulesValue = rulesArray[loweredIndex3];
                          var scaleRuleInstance = {};
                          autoscaleProfileInstance.rules.push(scaleRuleInstance);
                          
                          var metricTriggerValue = rulesValue['metricTrigger'];
                          if (metricTriggerValue !== null && metricTriggerValue !== undefined) {
                            var metricTriggerInstance = {};
                            scaleRuleInstance.metricTrigger = metricTriggerInstance;
                            
                            var metricNameValue = metricTriggerValue['metricName'];
                            if (metricNameValue !== null && metricNameValue !== undefined) {
                              var metricNameInstance = metricNameValue;
                              metricTriggerInstance.metricName = metricNameInstance;
                            }
                            
                            var metricNamespaceValue = metricTriggerValue['metricNamespace'];
                            if (metricNamespaceValue !== null && metricNamespaceValue !== undefined) {
                              var metricNamespaceInstance = metricNamespaceValue;
                              metricTriggerInstance.metricNamespace = metricNamespaceInstance;
                            }
                            
                            var metricResourceUriValue = metricTriggerValue['metricResourceUri'];
                            if (metricResourceUriValue !== null && metricResourceUriValue !== undefined) {
                              var metricResourceUriInstance = metricResourceUriValue;
                              metricTriggerInstance.metricResourceUri = metricResourceUriInstance;
                            }
                            
                            var timeGrainValue = metricTriggerValue['timeGrain'];
                            if (timeGrainValue !== null && timeGrainValue !== undefined) {
                              var timeGrainInstance = moment.duration(timeGrainValue);
                              metricTriggerInstance.timeGrain = timeGrainInstance;
                            }
                            
                            var statisticValue = metricTriggerValue['statistic'];
                            if (statisticValue !== null && statisticValue !== undefined) {
                              var statisticInstance = statisticValue;
                              metricTriggerInstance.statistic = statisticInstance;
                            }
                            
                            var timeWindowValue = metricTriggerValue['timeWindow'];
                            if (timeWindowValue !== null && timeWindowValue !== undefined) {
                              var timeWindowInstance = moment.duration(timeWindowValue);
                              metricTriggerInstance.timeWindow = timeWindowInstance;
                            }
                            
                            var timeAggregationValue = metricTriggerValue['timeAggregation'];
                            if (timeAggregationValue !== null && timeAggregationValue !== undefined) {
                              var timeAggregationInstance = timeAggregationValue;
                              metricTriggerInstance.timeAggregation = timeAggregationInstance;
                            }
                            
                            var operatorValue = metricTriggerValue['operator'];
                            if (operatorValue !== null && operatorValue !== undefined) {
                              var operatorInstance = operatorValue;
                              metricTriggerInstance.operator = operatorInstance;
                            }
                            
                            var thresholdValue = metricTriggerValue['threshold'];
                            if (thresholdValue !== null && thresholdValue !== undefined) {
                              var thresholdInstance = thresholdValue;
                              metricTriggerInstance.threshold = thresholdInstance;
                            }
                          }
                          
                          var scaleActionValue = rulesValue['scaleAction'];
                          if (scaleActionValue !== null && scaleActionValue !== undefined) {
                            var scaleActionInstance = {};
                            scaleRuleInstance.scaleAction = scaleActionInstance;
                            
                            var directionValue = scaleActionValue['direction'];
                            if (directionValue !== null && directionValue !== undefined) {
                              var directionInstance = directionValue;
                              scaleActionInstance.direction = directionInstance;
                            }
                            
                            var typeValue = scaleActionValue['type'];
                            if (typeValue !== null && typeValue !== undefined) {
                              var typeInstance = typeValue;
                              scaleActionInstance.type = typeInstance;
                            }
                            
                            var valueValue2 = scaleActionValue['value'];
                            if (valueValue2 !== null && valueValue2 !== undefined) {
                              var valueInstance = valueValue2;
                              scaleActionInstance.value = valueInstance;
                            }
                            
                            var cooldownValue = scaleActionValue['cooldown'];
                            if (cooldownValue !== null && cooldownValue !== undefined) {
                              var cooldownInstance = moment.duration(cooldownValue);
                              scaleActionInstance.cooldown = cooldownInstance;
                            }
                          }
                        }
                      }
                      
                      var fixedDateValue = profilesValue['fixedDate'];
                      if (fixedDateValue !== null && fixedDateValue !== undefined) {
                        var fixedDateInstance = {};
                        autoscaleProfileInstance.fixedDate = fixedDateInstance;
                        
                        var timeZoneValue = fixedDateValue['timeZone'];
                        if (timeZoneValue !== null && timeZoneValue !== undefined) {
                          var timeZoneInstance = timeZoneValue;
                          fixedDateInstance.timeZone = timeZoneInstance;
                        }
                        
                        var startValue = fixedDateValue['start'];
                        if (startValue !== null && startValue !== undefined) {
                          var startInstance = startValue;
                          fixedDateInstance.start = startInstance;
                        }
                        
                        var endValue = fixedDateValue['end'];
                        if (endValue !== null && endValue !== undefined) {
                          var endInstance = endValue;
                          fixedDateInstance.end = endInstance;
                        }
                      }
                      
                      var recurrenceValue = profilesValue['recurrence'];
                      if (recurrenceValue !== null && recurrenceValue !== undefined) {
                        var recurrenceInstance = {};
                        autoscaleProfileInstance.recurrence = recurrenceInstance;
                        
                        var frequencyValue = recurrenceValue['frequency'];
                        if (frequencyValue !== null && frequencyValue !== undefined) {
                          var frequencyInstance = frequencyValue;
                          recurrenceInstance.frequency = frequencyInstance;
                        }
                        
                        var scheduleValue = recurrenceValue['schedule'];
                        if (scheduleValue !== null && scheduleValue !== undefined) {
                          var scheduleInstance = { days: [], hours: [], minutes: [] };
                          recurrenceInstance.schedule = scheduleInstance;
                          
                          var timeZoneValue2 = scheduleValue['timeZone'];
                          if (timeZoneValue2 !== null && timeZoneValue2 !== undefined) {
                            var timeZoneInstance2 = timeZoneValue2;
                            scheduleInstance.timeZone = timeZoneInstance2;
                          }
                          
                          var daysArray = scheduleValue['days'];
                          if (daysArray !== null && daysArray !== undefined) {
                            for (var loweredIndex4 = 0; loweredIndex4 < daysArray.length; loweredIndex4 = loweredIndex4 + 1) {
                              var daysValue = daysArray[loweredIndex4];
                              scheduleInstance.days.push(daysValue);
                            }
                          }
                          
                          var hoursArray = scheduleValue['hours'];
                          if (hoursArray !== null && hoursArray !== undefined) {
                            for (var loweredIndex5 = 0; loweredIndex5 < hoursArray.length; loweredIndex5 = loweredIndex5 + 1) {
                              var hoursValue = hoursArray[loweredIndex5];
                              scheduleInstance.hours.push(hoursValue);
                            }
                          }
                          
                          var minutesArray = scheduleValue['minutes'];
                          if (minutesArray !== null && minutesArray !== undefined) {
                            for (var loweredIndex6 = 0; loweredIndex6 < minutesArray.length; loweredIndex6 = loweredIndex6 + 1) {
                              var minutesValue = minutesArray[loweredIndex6];
                              scheduleInstance.minutes.push(minutesValue);
                            }
                          }
                        }
                      }
                    }
                  }
                  
                  var enabledValue = propertiesValue['enabled'];
                  if (enabledValue !== null && enabledValue !== undefined) {
                    var enabledInstance = enabledValue;
                    propertiesInstance.enabled = enabledInstance;
                  }
                  
                  var nameValue3 = propertiesValue['name'];
                  if (nameValue3 !== null && nameValue3 !== undefined) {
                    var nameInstance3 = nameValue3;
                    propertiesInstance.name = nameInstance3;
                  }
                  
                  var targetResourceUriValue = propertiesValue['targetResourceUri'];
                  if (targetResourceUriValue !== null && targetResourceUriValue !== undefined) {
                    var targetResourceUriInstance = targetResourceUriValue;
                    propertiesInstance.targetResourceUri = targetResourceUriInstance;
                  }
                }
              }
            }
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceGroupName The resource name.
     * 
     * @param {string} autoscaleSettingName The autoscale setting name.
     * 
     * @param {AutoscaleSettingCreateOrUpdateParameters} parameters Parameters
     * supplied to the operation.
     * 
     * @param {string} [parameters.location] Gets or sets the location of the
     * setting.
     * 
     * @param {object} [parameters.tags] Gets or sets the tags of the rule.
     * 
     * @param {AutoscaleSetting} [parameters.properties] Gets or sets the setting
     * to create or update.
     * 
     * @param {array} [parameters.properties.profiles] Gets or sets the
     * collection of automatic scaling profiles that specify different scaling
     * parameters for different time periods. A maximum of 20 profiles can be
     * specified.
     * 
     * @param {boolean} [parameters.properties.enabled] Gets or sets the enabled
     * flag.Specifies whether automatic scaling is enabled for the resource.
     * 
     * @param {string} [parameters.properties.name] Gets or sets the name of the
     * autoscale setting.
     * 
     * @param {string} [parameters.properties.targetResourceUri] Gets or sets the
     * resource identifier of the resource that the autoscale setting should be
     * added to.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    AutoscaleOperations.prototype.updateSetting = function(resourceGroupName, autoscaleSettingName, parameters, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceGroupName === null || resourceGroupName === undefined) {
        return callback(new Error('resourceGroupName cannot be null.'));
      }
      if (autoscaleSettingName === null || autoscaleSettingName === undefined) {
        return callback(new Error('autoscaleSettingName cannot be null.'));
      }
      if (parameters === null || parameters === undefined) {
        return callback(new Error('parameters cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/subscriptions/';
      if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
        url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
      }
      url2 = url2 + '/resourcegroups/';
      url2 = url2 + encodeURIComponent(resourceGroupName);
      url2 = url2 + '/providers/microsoft.insights/autoscalesettings/';
      url2 = url2 + encodeURIComponent(autoscaleSettingName);
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      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 = 'PATCH';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // Serialize Request
      var requestContent = null;
      var requestDoc = null;
      
      var autoscaleSettingCreateOrUpdateParametersValue = {};
      requestDoc = autoscaleSettingCreateOrUpdateParametersValue;
      
      if (parameters.location !== null && parameters.location !== undefined) {
        autoscaleSettingCreateOrUpdateParametersValue['location'] = parameters.location;
      }
      
      if (parameters.tags !== null && parameters.tags !== undefined) {
        var tagsDictionary = {};
        for (var tagsKey in parameters.tags) {
          var tagsValue = parameters.tags[tagsKey];
          tagsDictionary[tagsKey] = tagsValue;
        }
        autoscaleSettingCreateOrUpdateParametersValue['tags'] = tagsDictionary;
      }
      
      if (parameters.properties !== null && parameters.properties !== undefined) {
        var propertiesValue = {};
        autoscaleSettingCreateOrUpdateParametersValue['properties'] = propertiesValue;
        
        if (parameters.properties.profiles !== null && parameters.properties.profiles !== undefined) {
          var profilesArray = [];
          for (var loweredIndex1 = 0; loweredIndex1 < parameters.properties.profiles.length; loweredIndex1 = loweredIndex1 + 1) {
            var profilesItem = parameters.properties.profiles[loweredIndex1];
            var autoscaleProfileValue = {};
            profilesArray.push(autoscaleProfileValue);
            
            if (profilesItem.name !== null && profilesItem.name !== undefined) {
              autoscaleProfileValue['name'] = profilesItem.name;
            }
            
            if (profilesItem.capacity !== null && profilesItem.capacity !== undefined) {
              var capacityValue = {};
              autoscaleProfileValue['capacity'] = capacityValue;
              
              if (profilesItem.capacity.minimum !== null && profilesItem.capacity.minimum !== undefined) {
                capacityValue['minimum'] = profilesItem.capacity.minimum;
              }
              
              if (profilesItem.capacity.maximum !== null && profilesItem.capacity.maximum !== undefined) {
                capacityValue['maximum'] = profilesItem.capacity.maximum;
              }
              
              if (profilesItem.capacity.default !== null && profilesItem.capacity.default !== undefined) {
                capacityValue['default'] = profilesItem.capacity.default;
              }
            }
            
            if (profilesItem.rules !== null && profilesItem.rules !== undefined) {
              var rulesArray = [];
              for (var loweredIndex2 = 0; loweredIndex2 < profilesItem.rules.length; loweredIndex2 = loweredIndex2 + 1) {
                var rulesItem = profilesItem.rules[loweredIndex2];
                var scaleRuleValue = {};
                rulesArray.push(scaleRuleValue);
                
                if (rulesItem.metricTrigger !== null && rulesItem.metricTrigger !== undefined) {
                  var metricTriggerValue = {};
                  scaleRuleValue['metricTrigger'] = metricTriggerValue;
                  
                  if (rulesItem.metricTrigger.metricName !== null && rulesItem.metricTrigger.metricName !== undefined) {
                    metricTriggerValue['metricName'] = rulesItem.metricTrigger.metricName;
                  }
                  
                  if (rulesItem.metricTrigger.metricNamespace !== null && rulesItem.metricTrigger.metricNamespace !== undefined) {
                    metricTriggerValue['metricNamespace'] = rulesItem.metricTrigger.metricNamespace;
                  }
                  
                  if (rulesItem.metricTrigger.metricResourceUri !== null && rulesItem.metricTrigger.metricResourceUri !== undefined) {
                    metricTriggerValue['metricResourceUri'] = rulesItem.metricTrigger.metricResourceUri;
                  }
                  
                  if (rulesItem.metricTrigger.timeGrain !== null && rulesItem.metricTrigger.timeGrain !== undefined) {
                    metricTriggerValue['timeGrain'] = rulesItem.metricTrigger.timeGrain.toIsoString();
                  }
                  
                  if (rulesItem.metricTrigger.statistic !== null && rulesItem.metricTrigger.statistic !== undefined) {
                    metricTriggerValue['statistic'] = rulesItem.metricTrigger.statistic !== null && rulesItem.metricTrigger.statistic !== undefined ? rulesItem.metricTrigger.statistic.toString() : 'Average';
                  }
                  
                  if (rulesItem.metricTrigger.timeWindow !== null && rulesItem.metricTrigger.timeWindow !== undefined) {
                    metricTriggerValue['timeWindow'] = rulesItem.metricTrigger.timeWindow.toIsoString();
                  }
                  
                  if (rulesItem.metricTrigger.timeAggregation !== null && rulesItem.metricTrigger.timeAggregation !== undefined) {
                    metricTriggerValue['timeAggregation'] = rulesItem.metricTrigger.timeAggregation !== null && rulesItem.metricTrigger.timeAggregation !== undefined ? rulesItem.metricTrigger.timeAggregation.toString() : 'Average';
                  }
                  
                  if (rulesItem.metricTrigger.operator !== null && rulesItem.metricTrigger.operator !== undefined) {
                    metricTriggerValue['operator'] = rulesItem.metricTrigger.operator !== null && rulesItem.metricTrigger.operator !== undefined ? rulesItem.metricTrigger.operator.toString() : 'Equals';
                  }
                  
                  if (rulesItem.metricTrigger.threshold !== null && rulesItem.metricTrigger.threshold !== undefined) {
                    metricTriggerValue['threshold'] = rulesItem.metricTrigger.threshold;
                  }
                }
                
                if (rulesItem.scaleAction !== null && rulesItem.scaleAction !== undefined) {
                  var scaleActionValue = {};
                  scaleRuleValue['scaleAction'] = scaleActionValue;
                  
                  if (rulesItem.scaleAction.direction !== null && rulesItem.scaleAction.direction !== undefined) {
                    scaleActionValue['direction'] = rulesItem.scaleAction.direction !== null && rulesItem.scaleAction.direction !== undefined ? rulesItem.scaleAction.direction.toString() : 'None';
                  }
                  
                  if (rulesItem.scaleAction.type !== null && rulesItem.scaleAction.type !== undefined) {
                    scaleActionValue['type'] = rulesItem.scaleAction.type !== null && rulesItem.scaleAction.type !== undefined ? rulesItem.scaleAction.type.toString() : 'ChangeSize';
                  }
                  
                  if (rulesItem.scaleAction.value !== null && rulesItem.scaleAction.value !== undefined) {
                    scaleActionValue['value'] = rulesItem.scaleAction.value;
                  }
                  
                  if (rulesItem.scaleAction.cooldown !== null && rulesItem.scaleAction.cooldown !== undefined) {
                    scaleActionValue['cooldown'] = rulesItem.scaleAction.cooldown.toIsoString();
                  }
                }
              }
              autoscaleProfileValue['rules'] = rulesArray;
            }
            
            if (profilesItem.fixedDate !== null && profilesItem.fixedDate !== undefined) {
              var fixedDateValue = {};
              autoscaleProfileValue['fixedDate'] = fixedDateValue;
              
              if (profilesItem.fixedDate.timeZone !== null && profilesItem.fixedDate.timeZone !== undefined) {
                fixedDateValue['timeZone'] = profilesItem.fixedDate.timeZone;
              }
              
              if (profilesItem.fixedDate.start !== null && profilesItem.fixedDate.start !== undefined) {
                fixedDateValue['start'] = profilesItem.fixedDate.start;
              }
              
              if (profilesItem.fixedDate.end !== null && profilesItem.fixedDate.end !== undefined) {
                fixedDateValue['end'] = profilesItem.fixedDate.end;
              }
            }
            
            if (profilesItem.recurrence !== null && profilesItem.recurrence !== undefined) {
              var recurrenceValue = {};
              autoscaleProfileValue['recurrence'] = recurrenceValue;
              
              if (profilesItem.recurrence.frequency !== null && profilesItem.recurrence.frequency !== undefined) {
                recurrenceValue['frequency'] = profilesItem.recurrence.frequency !== null && profilesItem.recurrence.frequency !== undefined ? profilesItem.recurrence.frequency.toString() : 'None';
              }
              
              if (profilesItem.recurrence.schedule !== null && profilesItem.recurrence.schedule !== undefined) {
                var scheduleValue = {};
                recurrenceValue['schedule'] = scheduleValue;
                
                if (profilesItem.recurrence.schedule.timeZone !== null && profilesItem.recurrence.schedule.timeZone !== undefined) {
                  scheduleValue['timeZone'] = profilesItem.recurrence.schedule.timeZone;
                }
                
                if (profilesItem.recurrence.schedule.days !== null && profilesItem.recurrence.schedule.days !== undefined) {
                  var daysArray = [];
                  for (var loweredIndex3 = 0; loweredIndex3 < profilesItem.recurrence.schedule.days.length; loweredIndex3 = loweredIndex3 + 1) {
                    var daysItem = profilesItem.recurrence.schedule.days[loweredIndex3];
                    daysArray.push(daysItem);
                  }
                  scheduleValue['days'] = daysArray;
                }
                
                if (profilesItem.recurrence.schedule.hours !== null && profilesItem.recurrence.schedule.hours !== undefined) {
                  var hoursArray = [];
                  for (var loweredIndex4 = 0; loweredIndex4 < profilesItem.recurrence.schedule.hours.length; loweredIndex4 = loweredIndex4 + 1) {
                    var hoursItem = profilesItem.recurrence.schedule.hours[loweredIndex4];
                    hoursArray.push(hoursItem);
                  }
                  scheduleValue['hours'] = hoursArray;
                }
                
                if (profilesItem.recurrence.schedule.minutes !== null && profilesItem.recurrence.schedule.minutes !== undefined) {
                  var minutesArray = [];
                  for (var loweredIndex5 = 0; loweredIndex5 < profilesItem.recurrence.schedule.minutes.length; loweredIndex5 = loweredIndex5 + 1) {
                    var minutesItem = profilesItem.recurrence.schedule.minutes[loweredIndex5];
                    minutesArray.push(minutesItem);
                  }
                  scheduleValue['minutes'] = minutesArray;
                }
              }
            }
          }
          propertiesValue['profiles'] = profilesArray;
        }
        
        if (parameters.properties.enabled !== null && parameters.properties.enabled !== undefined) {
          propertiesValue['enabled'] = parameters.properties.enabled;
        }
        
        if (parameters.properties.name !== null && parameters.properties.name !== undefined) {
          propertiesValue['name'] = parameters.properties.name;
        }
        
        if (parameters.properties.targetResourceUri !== null && parameters.properties.targetResourceUri !== undefined) {
          propertiesValue['targetResourceUri'] = parameters.properties.targetResourceUri;
        }
      }
      
      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 && statusCode !== 201) {
          var error = new Error(body);
          error.statusCode = response.statusCode;
          return callback(error);
        }
        
        // Create Result
        var result = null;
        // Deserialize Response
        if (statusCode === 200 || statusCode === 201) {
          var responseContent = body;
          result = {};
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    return AutoscaleOperations;
  })();
  
  var MonitoringConfigurationOperations = ( /** @lends MonitoringConfigurationOperations */ function() {
    /**
     * @class
     * Operations for managing the collection of diagonstics and monitoring data.
     * __NOTE__: An instance of this class is automatically created for an
     * instance of the [InsightsManagementClient] {@link
     * InsightsManagementClient~InsightsManagementClient}.
     * See [monitoringConfigurationOperations] {@link
     * InsightsManagementClient~InsightsManagementClient#monitoringConfigurationOperations}.
     * Initializes a new instance of the MonitoringConfigurationOperations class.
     * @constructor
     * 
     * @param {InsightsManagementClient} client Reference to the service client.
     */
    function MonitoringConfigurationOperations(client) {
      this.client = client;
    }
    
    /**
     * 
     * @param {string} resourceUri The resource identifier of the configuration.
     * 
     * @param {MonitoringConfigurationCreateOrUpdateParameters} parameters
     * Parameters supplied to the operation.
     * 
     * @param {DiagnosticSettings} [parameters.properties] Gets or sets the
     * public configuration settings.
     * 
     * @param {string} [parameters.properties.name] Gets or sets the setting name.
     * 
     * @param {string} [parameters.properties.description] Gets or sets the
     * setting description.
     * 
     * @param {PublicConfiguration} [parameters.properties.publicConfiguration]
     * Gets or sets the public diagnostic configuration.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    MonitoringConfigurationOperations.prototype.createOrUpdateConfiguration = function(resourceUri, parameters, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceUri === null || resourceUri === undefined) {
        return callback(new Error('resourceUri cannot be null.'));
      }
      if (parameters === null || parameters === undefined) {
        return callback(new Error('parameters cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/';
      url2 = url2 + encodeURIComponent(resourceUri);
      url2 = url2 + '/diagnosticSettings/agent';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'PUT';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // Serialize Request
      var requestContent = null;
      var requestDoc = null;
      
      var monitoringConfigurationCreateOrUpdateParametersValue = {};
      requestDoc = monitoringConfigurationCreateOrUpdateParametersValue;
      
      if (parameters.properties !== null && parameters.properties !== undefined) {
        var propertiesValue = {};
        monitoringConfigurationCreateOrUpdateParametersValue['properties'] = propertiesValue;
        
        if (parameters.properties.name !== null && parameters.properties.name !== undefined) {
          propertiesValue['name'] = parameters.properties.name;
        }
        
        if (parameters.properties.description !== null && parameters.properties.description !== undefined) {
          propertiesValue['description'] = parameters.properties.description;
        }
        
        if (parameters.properties.publicConfiguration !== null && parameters.properties.publicConfiguration !== undefined) {
          var publicConfigurationValue = {};
          propertiesValue['publicConfiguration'] = publicConfigurationValue;
          if (parameters.properties.publicConfiguration.type === 'Microsoft.Azure.Management.Insights.Models.PublicMonitoringConfiguration') {
            publicConfigurationValue['odata.type'] = parameters.properties.publicConfiguration.type;
            var derived = parameters.properties.publicConfiguration;
            
            if (derived.diagnosticMonitorConfiguration !== null && derived.diagnosticMonitorConfiguration !== undefined) {
              var diagnosticMonitorConfigurationValue = {};
              publicConfigurationValue['diagnosticMonitorConfiguration'] = diagnosticMonitorConfigurationValue;
              
              if (derived.diagnosticMonitorConfiguration.overallQuotaInMB !== null && derived.diagnosticMonitorConfiguration.overallQuotaInMB !== undefined) {
                diagnosticMonitorConfigurationValue['overallQuotaInMB'] = derived.diagnosticMonitorConfiguration.overallQuotaInMB;
              }
              
              if (derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs !== null && derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs !== undefined) {
                var diagnosticInfrastructureLogsValue = {};
                diagnosticMonitorConfigurationValue['diagnosticInfrastructureLogs'] = diagnosticInfrastructureLogsValue;
                
                if (derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs.scheduledTransferLogLevelFilter !== null && derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs.scheduledTransferLogLevelFilter !== undefined) {
                  diagnosticInfrastructureLogsValue['scheduledTransferLogLevelFilter'] = derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs.scheduledTransferLogLevelFilter !== null && derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs.scheduledTransferLogLevelFilter !== undefined ? derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs.scheduledTransferLogLevelFilter.toString() : 'Undefined';
                }
                
                if (derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs.scheduledTransferPeriod !== null && derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs.scheduledTransferPeriod !== undefined) {
                  diagnosticInfrastructureLogsValue['scheduledTransferPeriod'] = derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs.scheduledTransferPeriod.toIsoString();
                }
              }
              
              if (derived.diagnosticMonitorConfiguration.metrics !== null && derived.diagnosticMonitorConfiguration.metrics !== undefined) {
                var metricsValue = {};
                diagnosticMonitorConfigurationValue['metrics'] = metricsValue;
                
                if (derived.diagnosticMonitorConfiguration.metrics.resourceId !== null && derived.diagnosticMonitorConfiguration.metrics.resourceId !== undefined) {
                  metricsValue['resourceId'] = derived.diagnosticMonitorConfiguration.metrics.resourceId;
                }
                
                if (derived.diagnosticMonitorConfiguration.metrics.metricAggregations !== null && derived.diagnosticMonitorConfiguration.metrics.metricAggregations !== undefined) {
                  var aggregationsArray = [];
                  for (var loweredIndex1 = 0; loweredIndex1 < derived.diagnosticMonitorConfiguration.metrics.metricAggregations.length; loweredIndex1 = loweredIndex1 + 1) {
                    var aggregationsItem = derived.diagnosticMonitorConfiguration.metrics.metricAggregations[loweredIndex1];
                    var metricsValue2 = {};
                    aggregationsArray.push(metricsValue2);
                    
                    if (aggregationsItem.scheduledTransferPeriod !== null && aggregationsItem.scheduledTransferPeriod !== undefined) {
                      metricsValue2['scheduledTransferPeriod'] = aggregationsItem.scheduledTransferPeriod.toIsoString();
                    }
                  }
                  metricsValue['aggregations'] = aggregationsArray;
                }
              }
              
              if (derived.diagnosticMonitorConfiguration.directories !== null && derived.diagnosticMonitorConfiguration.directories !== undefined) {
                var directoriesValue = {};
                diagnosticMonitorConfigurationValue['directories'] = directoriesValue;
                
                if (derived.diagnosticMonitorConfiguration.directories.dataSources !== null && derived.diagnosticMonitorConfiguration.directories.dataSources !== undefined) {
                  var dataSourcesArray = [];
                  for (var loweredIndex2 = 0; loweredIndex2 < derived.diagnosticMonitorConfiguration.directories.dataSources.length; loweredIndex2 = loweredIndex2 + 1) {
                    var dataSourcesItem = derived.diagnosticMonitorConfiguration.directories.dataSources[loweredIndex2];
                    var directoryConfigurationValue = {};
                    dataSourcesArray.push(directoryConfigurationValue);
                    
                    if (dataSourcesItem.containerName !== null && dataSourcesItem.containerName !== undefined) {
                      directoryConfigurationValue['containerName'] = dataSourcesItem.containerName;
                    }
                    
                    if (dataSourcesItem.path !== null && dataSourcesItem.path !== undefined) {
                      var pathValue = {};
                      directoryConfigurationValue['path'] = pathValue;
                      if (dataSourcesItem.path.type === 'Microsoft.Azure.Management.Insights.Models.DirectoryAbsolute') {
                        pathValue['odata.type'] = dataSourcesItem.path.type;
                        var derived2 = dataSourcesItem.path;
                        
                        if (derived2.expandEnvironment !== null && derived2.expandEnvironment !== undefined) {
                          pathValue['expandEnvironment'] = derived2.expandEnvironment;
                        }
                        
                        if (derived2.path !== null && derived2.path !== undefined) {
                          pathValue['path'] = derived2.path;
                        }
                      }
                      if (dataSourcesItem.path.type === 'Microsoft.Azure.Management.Insights.Models.DirectoryLocal') {
                        pathValue['odata.type'] = dataSourcesItem.path.type;
                        var derived3 = dataSourcesItem.path;
                        
                        if (derived3.relativePath !== null && derived3.relativePath !== undefined) {
                          pathValue['relativePath'] = derived3.relativePath;
                        }
                        
                        if (derived3.name !== null && derived3.name !== undefined) {
                          pathValue['name'] = derived3.name;
                        }
                      }
                    }
                  }
                  directoriesValue['dataSources'] = dataSourcesArray;
                }
                
                if (derived.diagnosticMonitorConfiguration.directories.iISLogs !== null && derived.diagnosticMonitorConfiguration.directories.iISLogs !== undefined) {
                  directoriesValue['iisLogs'] = derived.diagnosticMonitorConfiguration.directories.iISLogs;
                }
                
                if (derived.diagnosticMonitorConfiguration.directories.failedRequestLogs !== null && derived.diagnosticMonitorConfiguration.directories.failedRequestLogs !== undefined) {
                  directoriesValue['failedRequestLogs'] = derived.diagnosticMonitorConfiguration.directories.failedRequestLogs;
                }
                
                if (derived.diagnosticMonitorConfiguration.directories.scheduledTransferPeriod !== null && derived.diagnosticMonitorConfiguration.directories.scheduledTransferPeriod !== undefined) {
                  directoriesValue['scheduledTransferPeriod'] = derived.diagnosticMonitorConfiguration.directories.scheduledTransferPeriod.toIsoString();
                }
              }
              
              if (derived.diagnosticMonitorConfiguration.performanceCounters !== null && derived.diagnosticMonitorConfiguration.performanceCounters !== undefined) {
                var performanceCountersValue = {};
                diagnosticMonitorConfigurationValue['performanceCounters'] = performanceCountersValue;
                
                if (derived.diagnosticMonitorConfiguration.performanceCounters.counters !== null && derived.diagnosticMonitorConfiguration.performanceCounters.counters !== undefined) {
                  var countersArray = [];
                  for (var loweredIndex3 = 0; loweredIndex3 < derived.diagnosticMonitorConfiguration.performanceCounters.counters.length; loweredIndex3 = loweredIndex3 + 1) {
                    var countersItem = derived.diagnosticMonitorConfiguration.performanceCounters.counters[loweredIndex3];
                    var performanceCounterConfigurationValue = {};
                    countersArray.push(performanceCounterConfigurationValue);
                    
                    if (countersItem.annotations !== null && countersItem.annotations !== undefined) {
                      var annotationsArray = [];
                      for (var loweredIndex4 = 0; loweredIndex4 < countersItem.annotations.length; loweredIndex4 = loweredIndex4 + 1) {
                        var annotationsItem = countersItem.annotations[loweredIndex4];
                        var localizedStringValue = {};
                        annotationsArray.push(localizedStringValue);
                        
                        if (annotationsItem.value !== null && annotationsItem.value !== undefined) {
                          localizedStringValue['value'] = annotationsItem.value;
                        }
                        
                        if (annotationsItem.locale !== null && annotationsItem.locale !== undefined) {
                          localizedStringValue['locale'] = annotationsItem.locale;
                        }
                      }
                      performanceCounterConfigurationValue['annotations'] = annotationsArray;
                    }
                    
                    if (countersItem.counterSpecifier !== null && countersItem.counterSpecifier !== undefined) {
                      performanceCounterConfigurationValue['counterSpecifier'] = countersItem.counterSpecifier;
                    }
                    
                    if (countersItem.sampleRate !== null && countersItem.sampleRate !== undefined) {
                      performanceCounterConfigurationValue['sampleRate'] = countersItem.sampleRate.toIsoString();
                    }
                    
                    if (countersItem.unit !== null && countersItem.unit !== undefined) {
                      performanceCounterConfigurationValue['unit'] = countersItem.unit !== null && countersItem.unit !== undefined ? countersItem.unit.toString() : 'Count';
                    }
                  }
                  performanceCountersValue['counters'] = countersArray;
                }
                
                if (derived.diagnosticMonitorConfiguration.performanceCounters.scheduledTransferPeriod !== null && derived.diagnosticMonitorConfiguration.performanceCounters.scheduledTransferPeriod !== undefined) {
                  performanceCountersValue['scheduledTransferPeriod'] = derived.diagnosticMonitorConfiguration.performanceCounters.scheduledTransferPeriod.toIsoString();
                }
              }
              
              if (derived.diagnosticMonitorConfiguration.windowsEventLog !== null && derived.diagnosticMonitorConfiguration.windowsEventLog !== undefined) {
                var windowsEventLogValue = {};
                diagnosticMonitorConfigurationValue['windowsEventLog'] = windowsEventLogValue;
                
                if (derived.diagnosticMonitorConfiguration.windowsEventLog.dataSources !== null && derived.diagnosticMonitorConfiguration.windowsEventLog.dataSources !== undefined) {
                  var dataSourcesArray2 = [];
                  for (var loweredIndex5 = 0; loweredIndex5 < derived.diagnosticMonitorConfiguration.windowsEventLog.dataSources.length; loweredIndex5 = loweredIndex5 + 1) {
                    var dataSourcesItem2 = derived.diagnosticMonitorConfiguration.windowsEventLog.dataSources[loweredIndex5];
                    dataSourcesArray2.push(dataSourcesItem2);
                  }
                  windowsEventLogValue['dataSources'] = dataSourcesArray2;
                }
                
                if (derived.diagnosticMonitorConfiguration.windowsEventLog.scheduledTransferPeriod !== null && derived.diagnosticMonitorConfiguration.windowsEventLog.scheduledTransferPeriod !== undefined) {
                  windowsEventLogValue['scheduledTransferPeriod'] = derived.diagnosticMonitorConfiguration.windowsEventLog.scheduledTransferPeriod.toIsoString();
                }
              }
              
              if (derived.diagnosticMonitorConfiguration.etwProviders !== null && derived.diagnosticMonitorConfiguration.etwProviders !== undefined) {
                var etwProvidersValue = {};
                diagnosticMonitorConfigurationValue['etwProviders'] = etwProvidersValue;
                
                if (derived.diagnosticMonitorConfiguration.etwProviders.eventSourceProviders !== null && derived.diagnosticMonitorConfiguration.etwProviders.eventSourceProviders !== undefined) {
                  var eventSourceProvidersArray = [];
                  for (var loweredIndex6 = 0; loweredIndex6 < derived.diagnosticMonitorConfiguration.etwProviders.eventSourceProviders.length; loweredIndex6 = loweredIndex6 + 1) {
                    var eventSourceProvidersItem = derived.diagnosticMonitorConfiguration.etwProviders.eventSourceProviders[loweredIndex6];
                    var etwProviderValue = {};
                    eventSourceProvidersArray.push(etwProviderValue);
                    
                    if (eventSourceProvidersItem.scheduledTransferPeriod !== null && eventSourceProvidersItem.scheduledTransferPeriod !== undefined) {
                      etwProviderValue['scheduledTransferPeriod'] = eventSourceProvidersItem.scheduledTransferPeriod.toIsoString();
                    }
                    
                    if (eventSourceProvidersItem.scheduledTransferLogLevelFilter !== null && eventSourceProvidersItem.scheduledTransferLogLevelFilter !== undefined) {
                      etwProviderValue['scheduledTransferLogLevelFilter'] = eventSourceProvidersItem.scheduledTransferLogLevelFilter !== null && eventSourceProvidersItem.scheduledTransferLogLevelFilter !== undefined ? eventSourceProvidersItem.scheduledTransferLogLevelFilter.toString() : 'Undefined';
                    }
                    
                    if (eventSourceProvidersItem.provider !== null && eventSourceProvidersItem.provider !== undefined) {
                      etwProviderValue['provider'] = eventSourceProvidersItem.provider;
                    }
                    
                    if (eventSourceProvidersItem.scheduledTransferKeywordFilter !== null && eventSourceProvidersItem.scheduledTransferKeywordFilter !== undefined) {
                      etwProviderValue['scheduledTransferKeywordFilter'] = eventSourceProvidersItem.scheduledTransferKeywordFilter;
                    }
                    
                    if (eventSourceProvidersItem.events !== null && eventSourceProvidersItem.events !== undefined) {
                      var eventsArray = [];
                      for (var loweredIndex7 = 0; loweredIndex7 < eventSourceProvidersItem.events.length; loweredIndex7 = loweredIndex7 + 1) {
                        var eventsItem = eventSourceProvidersItem.events[loweredIndex7];
                        var etwEventConfigurationValue = {};
                        eventsArray.push(etwEventConfigurationValue);
                        
                        if (eventsItem.eventId !== null && eventsItem.eventId !== undefined) {
                          etwEventConfigurationValue['eventId'] = eventsItem.eventId;
                        }
                        
                        if (eventsItem.destination !== null && eventsItem.destination !== undefined) {
                          etwEventConfigurationValue['destination'] = eventsItem.destination;
                        }
                      }
                      etwProviderValue['events'] = eventsArray;
                    }
                    
                    if (eventSourceProvidersItem.defaultDestination !== null && eventSourceProvidersItem.defaultDestination !== undefined) {
                      etwProviderValue['defaultDestination'] = eventSourceProvidersItem.defaultDestination;
                    }
                  }
                  etwProvidersValue['eventSourceProviders'] = eventSourceProvidersArray;
                }
                
                if (derived.diagnosticMonitorConfiguration.etwProviders.manifestProviders !== null && derived.diagnosticMonitorConfiguration.etwProviders.manifestProviders !== undefined) {
                  var manifestProvidersArray = [];
                  for (var loweredIndex8 = 0; loweredIndex8 < derived.diagnosticMonitorConfiguration.etwProviders.manifestProviders.length; loweredIndex8 = loweredIndex8 + 1) {
                    var manifestProvidersItem = derived.diagnosticMonitorConfiguration.etwProviders.manifestProviders[loweredIndex8];
                    var etwProviderValue2 = {};
                    manifestProvidersArray.push(etwProviderValue2);
                    
                    if (manifestProvidersItem.scheduledTransferPeriod !== null && manifestProvidersItem.scheduledTransferPeriod !== undefined) {
                      etwProviderValue2['scheduledTransferPeriod'] = manifestProvidersItem.scheduledTransferPeriod.toIsoString();
                    }
                    
                    if (manifestProvidersItem.scheduledTransferLogLevelFilter !== null && manifestProvidersItem.scheduledTransferLogLevelFilter !== undefined) {
                      etwProviderValue2['scheduledTransferLogLevelFilter'] = manifestProvidersItem.scheduledTransferLogLevelFilter !== null && manifestProvidersItem.scheduledTransferLogLevelFilter !== undefined ? manifestProvidersItem.scheduledTransferLogLevelFilter.toString() : 'Undefined';
                    }
                    
                    if (manifestProvidersItem.provider !== null && manifestProvidersItem.provider !== undefined) {
                      etwProviderValue2['provider'] = manifestProvidersItem.provider;
                    }
                    
                    if (manifestProvidersItem.scheduledTransferKeywordFilter !== null && manifestProvidersItem.scheduledTransferKeywordFilter !== undefined) {
                      etwProviderValue2['scheduledTransferKeywordFilter'] = manifestProvidersItem.scheduledTransferKeywordFilter;
                    }
                    
                    if (manifestProvidersItem.events !== null && manifestProvidersItem.events !== undefined) {
                      var eventsArray2 = [];
                      for (var loweredIndex9 = 0; loweredIndex9 < manifestProvidersItem.events.length; loweredIndex9 = loweredIndex9 + 1) {
                        var eventsItem2 = manifestProvidersItem.events[loweredIndex9];
                        var etwEventConfigurationValue2 = {};
                        eventsArray2.push(etwEventConfigurationValue2);
                        
                        if (eventsItem2.eventId !== null && eventsItem2.eventId !== undefined) {
                          etwEventConfigurationValue2['eventId'] = eventsItem2.eventId;
                        }
                        
                        if (eventsItem2.destination !== null && eventsItem2.destination !== undefined) {
                          etwEventConfigurationValue2['destination'] = eventsItem2.destination;
                        }
                      }
                      etwProviderValue2['events'] = eventsArray2;
                    }
                    
                    if (manifestProvidersItem.defaultDestination !== null && manifestProvidersItem.defaultDestination !== undefined) {
                      etwProviderValue2['defaultDestination'] = manifestProvidersItem.defaultDestination;
                    }
                  }
                  etwProvidersValue['manifestProviders'] = manifestProvidersArray;
                }
              }
              
              if (derived.diagnosticMonitorConfiguration.crashDumps !== null && derived.diagnosticMonitorConfiguration.crashDumps !== undefined) {
                var crashDumpsValue = {};
                diagnosticMonitorConfigurationValue['crashDumps'] = crashDumpsValue;
                
                if (derived.diagnosticMonitorConfiguration.crashDumps.directoryQuotaPercentage !== null && derived.diagnosticMonitorConfiguration.crashDumps.directoryQuotaPercentage !== undefined) {
                  crashDumpsValue['directoryQuotaPercentage'] = derived.diagnosticMonitorConfiguration.crashDumps.directoryQuotaPercentage;
                }
                
                if (derived.diagnosticMonitorConfiguration.crashDumps.dumpType !== null && derived.diagnosticMonitorConfiguration.crashDumps.dumpType !== undefined) {
                  crashDumpsValue['dumpType'] = derived.diagnosticMonitorConfiguration.crashDumps.dumpType !== null && derived.diagnosticMonitorConfiguration.crashDumps.dumpType !== undefined ? derived.diagnosticMonitorConfiguration.crashDumps.dumpType.toString() : 'Mini';
                }
                
                if (derived.diagnosticMonitorConfiguration.crashDumps.containerName !== null && derived.diagnosticMonitorConfiguration.crashDumps.containerName !== undefined) {
                  crashDumpsValue['containerName'] = derived.diagnosticMonitorConfiguration.crashDumps.containerName;
                }
                
                if (derived.diagnosticMonitorConfiguration.crashDumps.processes !== null && derived.diagnosticMonitorConfiguration.crashDumps.processes !== undefined) {
                  var processesArray = [];
                  for (var loweredIndex10 = 0; loweredIndex10 < derived.diagnosticMonitorConfiguration.crashDumps.processes.length; loweredIndex10 = loweredIndex10 + 1) {
                    var processesItem = derived.diagnosticMonitorConfiguration.crashDumps.processes[loweredIndex10];
                    processesArray.push(processesItem);
                  }
                  crashDumpsValue['processes'] = processesArray;
                }
              }
            }
            
            if (derived.localResourceDirectory !== null && derived.localResourceDirectory !== undefined) {
              var localResourceDirectoryValue = {};
              publicConfigurationValue['localResourceDirectory'] = localResourceDirectoryValue;
              
              if (derived.localResourceDirectory.expandEnvironment !== null && derived.localResourceDirectory.expandEnvironment !== undefined) {
                localResourceDirectoryValue['expandEnvironment'] = derived.localResourceDirectory.expandEnvironment;
              }
              
              if (derived.localResourceDirectory.path !== null && derived.localResourceDirectory.path !== undefined) {
                localResourceDirectoryValue['path'] = derived.localResourceDirectory.path;
              }
            }
            
            if (derived.storageAccount !== null && derived.storageAccount !== undefined) {
              publicConfigurationValue['storageAccount'] = derived.storageAccount;
            }
          }
        }
      }
      
      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 && statusCode !== 201 && statusCode !== 202) {
          var error = new Error(body);
          error.statusCode = response.statusCode;
          return callback(error);
        }
        
        // Create Result
        var result = null;
        // Deserialize Response
        if (statusCode === 200 || statusCode === 201 || statusCode === 202) {
          var responseContent = body;
          result = {};
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceUri The resource identifier of the configuration.
     * 
     * @param {CreateOrUpdateStorageConfigurationParameters} parameters
     * Parameters supplied to the operation.
     * 
     * @param {StorageConfiguration} [parameters.properties] Gets or sets the
     * public configuration settings.
     * 
     * @param {StorageLoggingConfiguration}
     * [parameters.properties.loggingConfiguration] Gets or sets the storage
     * logging configuration. Settings for logging successful and failed
     * requests to a storage service. This information can be used to monitor
     * individual requests and to diagnose issues with a storage service.
     * Requests are logged on a best-effort basis.
     * 
     * @param {boolean} [parameters.properties.loggingConfiguration.delete] Gets
     * or sets the delete flag. Indicates whether all delete requests should be
     * logged.
     * 
     * @param {boolean} [parameters.properties.loggingConfiguration.read] Gets or
     * sets the read flag. Indicates whether all read requests should be logged.
     * 
     * @param {boolean} [parameters.properties.loggingConfiguration.write] Gets
     * or sets the write flag. Indicates whether all write requests should be
     * logged.
     * 
     * @param {TimeSpan} [parameters.properties.loggingConfiguration.retention]
     * Gets or sets the retention flag. Indicates the how long log data should
     * be retained (must be an even number of days). All data older than this
     * value will be deleted. The minimum number of days is 1; the largest value
     * is 365 (one year).
     * 
     * @param {StorageMetricConfiguration}
     * [parameters.properties.metricConfiguration] Gets or sets the settings for
     * metrics that include aggregated transaction statistics and capacity data
     * about requests to a storage service.
     * 
     * @param {array}
     * [parameters.properties.metricConfiguration.metricAggregations] Gets or
     * sets the list of aggregations to generate.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    MonitoringConfigurationOperations.prototype.createOrUpdateStorageConfiguration = function(resourceUri, parameters, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceUri === null || resourceUri === undefined) {
        return callback(new Error('resourceUri cannot be null.'));
      }
      if (parameters === null || parameters === undefined) {
        return callback(new Error('parameters cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/';
      url2 = url2 + encodeURIComponent(resourceUri);
      url2 = url2 + '/diagnosticSettings/storage';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'PUT';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // Serialize Request
      var requestContent = null;
      var requestDoc = null;
      
      var createOrUpdateStorageConfigurationParametersValue = {};
      requestDoc = createOrUpdateStorageConfigurationParametersValue;
      
      if (parameters.properties !== null && parameters.properties !== undefined) {
        var propertiesValue = {};
        createOrUpdateStorageConfigurationParametersValue['properties'] = propertiesValue;
        
        if (parameters.properties.loggingConfiguration !== null && parameters.properties.loggingConfiguration !== undefined) {
          var loggingValue = {};
          propertiesValue['logging'] = loggingValue;
          
          if (parameters.properties.loggingConfiguration.delete !== null && parameters.properties.loggingConfiguration.delete !== undefined) {
            loggingValue['delete'] = parameters.properties.loggingConfiguration.delete;
          }
          
          if (parameters.properties.loggingConfiguration.read !== null && parameters.properties.loggingConfiguration.read !== undefined) {
            loggingValue['read'] = parameters.properties.loggingConfiguration.read;
          }
          
          if (parameters.properties.loggingConfiguration.write !== null && parameters.properties.loggingConfiguration.write !== undefined) {
            loggingValue['write'] = parameters.properties.loggingConfiguration.write;
          }
          
          if (parameters.properties.loggingConfiguration.retention !== null && parameters.properties.loggingConfiguration.retention !== undefined) {
            loggingValue['retention'] = parameters.properties.loggingConfiguration.retention.toIsoString();
          }
        }
        
        if (parameters.properties.metricConfiguration !== null && parameters.properties.metricConfiguration !== undefined) {
          var metricsValue = {};
          propertiesValue['metrics'] = metricsValue;
          
          if (parameters.properties.metricConfiguration.metricAggregations !== null && parameters.properties.metricConfiguration.metricAggregations !== undefined) {
            var aggregationsArray = [];
            for (var loweredIndex1 = 0; loweredIndex1 < parameters.properties.metricConfiguration.metricAggregations.length; loweredIndex1 = loweredIndex1 + 1) {
              var aggregationsItem = parameters.properties.metricConfiguration.metricAggregations[loweredIndex1];
              var storageMetricAggregationValue = {};
              aggregationsArray.push(storageMetricAggregationValue);
              
              if (aggregationsItem.scheduledTransferPeriod !== null && aggregationsItem.scheduledTransferPeriod !== undefined) {
                storageMetricAggregationValue['scheduledTransferPeriod'] = aggregationsItem.scheduledTransferPeriod.toIsoString();
              }
              
              if (aggregationsItem.retention !== null && aggregationsItem.retention !== undefined) {
                storageMetricAggregationValue['retention'] = aggregationsItem.retention.toIsoString();
              }
              
              if (aggregationsItem.level !== null && aggregationsItem.level !== undefined) {
                storageMetricAggregationValue['level'] = aggregationsItem.level !== null && aggregationsItem.level !== undefined ? aggregationsItem.level.toString() : 'None';
              }
            }
            metricsValue['aggregations'] = aggregationsArray;
          }
        }
      }
      
      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 && statusCode !== 201 && statusCode !== 202) {
          var error = new Error(body);
          error.statusCode = response.statusCode;
          return callback(error);
        }
        
        // Create Result
        var result = null;
        // Deserialize Response
        if (statusCode === 200 || statusCode === 201 || statusCode === 202) {
          var responseContent = body;
          result = {};
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceUri The resource identifier of the configuration.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    MonitoringConfigurationOperations.prototype.getConfiguration = function(resourceUri, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceUri === null || resourceUri === undefined) {
        return callback(new Error('resourceUri cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/';
      url2 = url2 + encodeURIComponent(resourceUri);
      url2 = url2 + '/diagnosticSettings/agent';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'GET';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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 nameValue = responseDoc['name'];
            if (nameValue !== null && nameValue !== undefined) {
              var nameInstance = nameValue;
              result.name = nameInstance;
            }
            
            var locationValue = responseDoc['location'];
            if (locationValue !== null && locationValue !== undefined) {
              var locationInstance = locationValue;
              result.location = locationInstance;
            }
            
            var propertiesValue = responseDoc['properties'];
            if (propertiesValue !== null && propertiesValue !== undefined) {
              var propertiesInstance = {};
              result.properties = propertiesInstance;
              
              var nameValue2 = propertiesValue['name'];
              if (nameValue2 !== null && nameValue2 !== undefined) {
                var nameInstance2 = nameValue2;
                propertiesInstance.name = nameInstance2;
              }
              
              var descriptionValue = propertiesValue['description'];
              if (descriptionValue !== null && descriptionValue !== undefined) {
                var descriptionInstance = descriptionValue;
                propertiesInstance.description = descriptionInstance;
              }
              
              var publicConfigurationValue = propertiesValue['publicConfiguration'];
              if (publicConfigurationValue !== null && publicConfigurationValue !== undefined) {
                var typeName = publicConfigurationValue['odata.type'];
                if (typeName === 'Microsoft.Azure.Management.Insights.Models.PublicMonitoringConfiguration') {
                  var publicMonitoringConfigurationInstance = {};
                  
                  var diagnosticMonitorConfigurationValue = publicConfigurationValue['diagnosticMonitorConfiguration'];
                  if (diagnosticMonitorConfigurationValue !== null && diagnosticMonitorConfigurationValue !== undefined) {
                    var diagnosticMonitorConfigurationInstance = {};
                    publicMonitoringConfigurationInstance.diagnosticMonitorConfiguration = diagnosticMonitorConfigurationInstance;
                    
                    var overallQuotaInMBValue = diagnosticMonitorConfigurationValue['overallQuotaInMB'];
                    if (overallQuotaInMBValue !== null && overallQuotaInMBValue !== undefined) {
                      var overallQuotaInMBInstance = overallQuotaInMBValue;
                      diagnosticMonitorConfigurationInstance.overallQuotaInMB = overallQuotaInMBInstance;
                    }
                    
                    var diagnosticInfrastructureLogsValue = diagnosticMonitorConfigurationValue['diagnosticInfrastructureLogs'];
                    if (diagnosticInfrastructureLogsValue !== null && diagnosticInfrastructureLogsValue !== undefined) {
                      var diagnosticInfrastructureLogsInstance = {};
                      diagnosticMonitorConfigurationInstance.diagnosticInfrastructureLogs = diagnosticInfrastructureLogsInstance;
                      
                      var scheduledTransferLogLevelFilterValue = diagnosticInfrastructureLogsValue['scheduledTransferLogLevelFilter'];
                      if (scheduledTransferLogLevelFilterValue !== null && scheduledTransferLogLevelFilterValue !== undefined) {
                        var scheduledTransferLogLevelFilterInstance = scheduledTransferLogLevelFilterValue;
                        diagnosticInfrastructureLogsInstance.scheduledTransferLogLevelFilter = scheduledTransferLogLevelFilterInstance;
                      }
                      
                      var scheduledTransferPeriodValue = diagnosticInfrastructureLogsValue['scheduledTransferPeriod'];
                      if (scheduledTransferPeriodValue !== null && scheduledTransferPeriodValue !== undefined) {
                        var scheduledTransferPeriodInstance = moment.duration(scheduledTransferPeriodValue);
                        diagnosticInfrastructureLogsInstance.scheduledTransferPeriod = scheduledTransferPeriodInstance;
                      }
                    }
                    
                    var metricsValue = diagnosticMonitorConfigurationValue['metrics'];
                    if (metricsValue !== null && metricsValue !== undefined) {
                      var metricsInstance = { metricAggregations: [] };
                      diagnosticMonitorConfigurationInstance.metrics = metricsInstance;
                      
                      var resourceIdValue = metricsValue['resourceId'];
                      if (resourceIdValue !== null && resourceIdValue !== undefined) {
                        var resourceIdInstance = resourceIdValue;
                        metricsInstance.resourceId = resourceIdInstance;
                      }
                      
                      var aggregationsArray = metricsValue['aggregations'];
                      if (aggregationsArray !== null && aggregationsArray !== undefined) {
                        for (var loweredIndex1 = 0; loweredIndex1 < aggregationsArray.length; loweredIndex1 = loweredIndex1 + 1) {
                          var aggregationsValue = aggregationsArray[loweredIndex1];
                          var metricsInstance2 = {};
                          metricsInstance.metricAggregations.push(metricsInstance2);
                          
                          var scheduledTransferPeriodValue2 = aggregationsValue['scheduledTransferPeriod'];
                          if (scheduledTransferPeriodValue2 !== null && scheduledTransferPeriodValue2 !== undefined) {
                            var scheduledTransferPeriodInstance2 = moment.duration(scheduledTransferPeriodValue2);
                            metricsInstance2.scheduledTransferPeriod = scheduledTransferPeriodInstance2;
                          }
                        }
                      }
                    }
                    
                    var directoriesValue = diagnosticMonitorConfigurationValue['directories'];
                    if (directoriesValue !== null && directoriesValue !== undefined) {
                      var directoriesInstance = { dataSources: [] };
                      diagnosticMonitorConfigurationInstance.directories = directoriesInstance;
                      
                      var dataSourcesArray = directoriesValue['dataSources'];
                      if (dataSourcesArray !== null && dataSourcesArray !== undefined) {
                        for (var loweredIndex2 = 0; loweredIndex2 < dataSourcesArray.length; loweredIndex2 = loweredIndex2 + 1) {
                          var dataSourcesValue = dataSourcesArray[loweredIndex2];
                          var directoryConfigurationInstance = {};
                          directoriesInstance.dataSources.push(directoryConfigurationInstance);
                          
                          var containerNameValue = dataSourcesValue['containerName'];
                          if (containerNameValue !== null && containerNameValue !== undefined) {
                            var containerNameInstance = containerNameValue;
                            directoryConfigurationInstance.containerName = containerNameInstance;
                          }
                          
                          var pathValue = dataSourcesValue['path'];
                          if (pathValue !== null && pathValue !== undefined) {
                            var typeName2 = pathValue['odata.type'];
                            if (typeName2 === 'Microsoft.Azure.Management.Insights.Models.DirectoryAbsolute') {
                              var directoryAbsoluteInstance = {};
                              
                              var expandEnvironmentValue = pathValue['expandEnvironment'];
                              if (expandEnvironmentValue !== null && expandEnvironmentValue !== undefined) {
                                var expandEnvironmentInstance = expandEnvironmentValue;
                                directoryAbsoluteInstance.expandEnvironment = expandEnvironmentInstance;
                              }
                              
                              var pathValue2 = pathValue['path'];
                              if (pathValue2 !== null && pathValue2 !== undefined) {
                                var pathInstance = pathValue2;
                                directoryAbsoluteInstance.path = pathInstance;
                              }
                              directoryConfigurationInstance.path = directoryAbsoluteInstance;
                            }
                            if (typeName2 === 'Microsoft.Azure.Management.Insights.Models.DirectoryLocal') {
                              var directoryLocalInstance = {};
                              
                              var relativePathValue = pathValue['relativePath'];
                              if (relativePathValue !== null && relativePathValue !== undefined) {
                                var relativePathInstance = relativePathValue;
                                directoryLocalInstance.relativePath = relativePathInstance;
                              }
                              
                              var nameValue3 = pathValue['name'];
                              if (nameValue3 !== null && nameValue3 !== undefined) {
                                var nameInstance3 = nameValue3;
                                directoryLocalInstance.name = nameInstance3;
                              }
                              directoryConfigurationInstance.path = directoryLocalInstance;
                            }
                          }
                        }
                      }
                      
                      var iisLogsValue = directoriesValue['iisLogs'];
                      if (iisLogsValue !== null && iisLogsValue !== undefined) {
                        var iisLogsInstance = iisLogsValue;
                        directoriesInstance.iISLogs = iisLogsInstance;
                      }
                      
                      var failedRequestLogsValue = directoriesValue['failedRequestLogs'];
                      if (failedRequestLogsValue !== null && failedRequestLogsValue !== undefined) {
                        var failedRequestLogsInstance = failedRequestLogsValue;
                        directoriesInstance.failedRequestLogs = failedRequestLogsInstance;
                      }
                      
                      var scheduledTransferPeriodValue3 = directoriesValue['scheduledTransferPeriod'];
                      if (scheduledTransferPeriodValue3 !== null && scheduledTransferPeriodValue3 !== undefined) {
                        var scheduledTransferPeriodInstance3 = moment.duration(scheduledTransferPeriodValue3);
                        directoriesInstance.scheduledTransferPeriod = scheduledTransferPeriodInstance3;
                      }
                    }
                    
                    var performanceCountersValue = diagnosticMonitorConfigurationValue['performanceCounters'];
                    if (performanceCountersValue !== null && performanceCountersValue !== undefined) {
                      var performanceCountersInstance = { counters: [] };
                      diagnosticMonitorConfigurationInstance.performanceCounters = performanceCountersInstance;
                      
                      var countersArray = performanceCountersValue['counters'];
                      if (countersArray !== null && countersArray !== undefined) {
                        for (var loweredIndex3 = 0; loweredIndex3 < countersArray.length; loweredIndex3 = loweredIndex3 + 1) {
                          var countersValue = countersArray[loweredIndex3];
                          var performanceCounterConfigurationInstance = { annotations: [] };
                          performanceCountersInstance.counters.push(performanceCounterConfigurationInstance);
                          
                          var annotationsArray = countersValue['annotations'];
                          if (annotationsArray !== null && annotationsArray !== undefined) {
                            for (var loweredIndex4 = 0; loweredIndex4 < annotationsArray.length; loweredIndex4 = loweredIndex4 + 1) {
                              var annotationsValue = annotationsArray[loweredIndex4];
                              var localizedStringInstance = {};
                              performanceCounterConfigurationInstance.annotations.push(localizedStringInstance);
                              
                              var valueValue = annotationsValue['value'];
                              if (valueValue !== null && valueValue !== undefined) {
                                var valueInstance = valueValue;
                                localizedStringInstance.value = valueInstance;
                              }
                              
                              var localeValue = annotationsValue['locale'];
                              if (localeValue !== null && localeValue !== undefined) {
                                var localeInstance = localeValue;
                                localizedStringInstance.locale = localeInstance;
                              }
                            }
                          }
                          
                          var counterSpecifierValue = countersValue['counterSpecifier'];
                          if (counterSpecifierValue !== null && counterSpecifierValue !== undefined) {
                            var counterSpecifierInstance = counterSpecifierValue;
                            performanceCounterConfigurationInstance.counterSpecifier = counterSpecifierInstance;
                          }
                          
                          var sampleRateValue = countersValue['sampleRate'];
                          if (sampleRateValue !== null && sampleRateValue !== undefined) {
                            var sampleRateInstance = moment.duration(sampleRateValue);
                            performanceCounterConfigurationInstance.sampleRate = sampleRateInstance;
                          }
                          
                          var unitValue = countersValue['unit'];
                          if (unitValue !== null && unitValue !== undefined) {
                            var unitInstance = unitValue;
                            performanceCounterConfigurationInstance.unit = unitInstance;
                          }
                        }
                      }
                      
                      var scheduledTransferPeriodValue4 = performanceCountersValue['scheduledTransferPeriod'];
                      if (scheduledTransferPeriodValue4 !== null && scheduledTransferPeriodValue4 !== undefined) {
                        var scheduledTransferPeriodInstance4 = moment.duration(scheduledTransferPeriodValue4);
                        performanceCountersInstance.scheduledTransferPeriod = scheduledTransferPeriodInstance4;
                      }
                    }
                    
                    var windowsEventLogValue = diagnosticMonitorConfigurationValue['windowsEventLog'];
                    if (windowsEventLogValue !== null && windowsEventLogValue !== undefined) {
                      var windowsEventLogInstance = { dataSources: [] };
                      diagnosticMonitorConfigurationInstance.windowsEventLog = windowsEventLogInstance;
                      
                      var dataSourcesArray2 = windowsEventLogValue['dataSources'];
                      if (dataSourcesArray2 !== null && dataSourcesArray2 !== undefined) {
                        for (var loweredIndex5 = 0; loweredIndex5 < dataSourcesArray2.length; loweredIndex5 = loweredIndex5 + 1) {
                          var dataSourcesValue2 = dataSourcesArray2[loweredIndex5];
                          windowsEventLogInstance.dataSources.push(dataSourcesValue2);
                        }
                      }
                      
                      var scheduledTransferPeriodValue5 = windowsEventLogValue['scheduledTransferPeriod'];
                      if (scheduledTransferPeriodValue5 !== null && scheduledTransferPeriodValue5 !== undefined) {
                        var scheduledTransferPeriodInstance5 = moment.duration(scheduledTransferPeriodValue5);
                        windowsEventLogInstance.scheduledTransferPeriod = scheduledTransferPeriodInstance5;
                      }
                    }
                    
                    var etwProvidersValue = diagnosticMonitorConfigurationValue['etwProviders'];
                    if (etwProvidersValue !== null && etwProvidersValue !== undefined) {
                      var etwProvidersInstance = { eventSourceProviders: [], manifestProviders: [] };
                      diagnosticMonitorConfigurationInstance.etwProviders = etwProvidersInstance;
                      
                      var eventSourceProvidersArray = etwProvidersValue['eventSourceProviders'];
                      if (eventSourceProvidersArray !== null && eventSourceProvidersArray !== undefined) {
                        for (var loweredIndex6 = 0; loweredIndex6 < eventSourceProvidersArray.length; loweredIndex6 = loweredIndex6 + 1) {
                          var eventSourceProvidersValue = eventSourceProvidersArray[loweredIndex6];
                          var etwProviderInstance = { events: [] };
                          etwProvidersInstance.eventSourceProviders.push(etwProviderInstance);
                          
                          var scheduledTransferPeriodValue6 = eventSourceProvidersValue['scheduledTransferPeriod'];
                          if (scheduledTransferPeriodValue6 !== null && scheduledTransferPeriodValue6 !== undefined) {
                            var scheduledTransferPeriodInstance6 = moment.duration(scheduledTransferPeriodValue6);
                            etwProviderInstance.scheduledTransferPeriod = scheduledTransferPeriodInstance6;
                          }
                          
                          var scheduledTransferLogLevelFilterValue2 = eventSourceProvidersValue['scheduledTransferLogLevelFilter'];
                          if (scheduledTransferLogLevelFilterValue2 !== null && scheduledTransferLogLevelFilterValue2 !== undefined) {
                            var scheduledTransferLogLevelFilterInstance2 = scheduledTransferLogLevelFilterValue2;
                            etwProviderInstance.scheduledTransferLogLevelFilter = scheduledTransferLogLevelFilterInstance2;
                          }
                          
                          var providerValue = eventSourceProvidersValue['provider'];
                          if (providerValue !== null && providerValue !== undefined) {
                            var providerInstance = providerValue;
                            etwProviderInstance.provider = providerInstance;
                          }
                          
                          var scheduledTransferKeywordFilterValue = eventSourceProvidersValue['scheduledTransferKeywordFilter'];
                          if (scheduledTransferKeywordFilterValue !== null && scheduledTransferKeywordFilterValue !== undefined) {
                            var scheduledTransferKeywordFilterInstance = scheduledTransferKeywordFilterValue;
                            etwProviderInstance.scheduledTransferKeywordFilter = scheduledTransferKeywordFilterInstance;
                          }
                          
                          var eventsArray = eventSourceProvidersValue['events'];
                          if (eventsArray !== null && eventsArray !== undefined) {
                            for (var loweredIndex7 = 0; loweredIndex7 < eventsArray.length; loweredIndex7 = loweredIndex7 + 1) {
                              var eventsValue = eventsArray[loweredIndex7];
                              var etwEventConfigurationInstance = {};
                              etwProviderInstance.events.push(etwEventConfigurationInstance);
                              
                              var eventIdValue = eventsValue['eventId'];
                              if (eventIdValue !== null && eventIdValue !== undefined) {
                                var eventIdInstance = eventIdValue;
                                etwEventConfigurationInstance.eventId = eventIdInstance;
                              }
                              
                              var destinationValue = eventsValue['destination'];
                              if (destinationValue !== null && destinationValue !== undefined) {
                                var destinationInstance = destinationValue;
                                etwEventConfigurationInstance.destination = destinationInstance;
                              }
                            }
                          }
                          
                          var defaultDestinationValue = eventSourceProvidersValue['defaultDestination'];
                          if (defaultDestinationValue !== null && defaultDestinationValue !== undefined) {
                            var defaultDestinationInstance = defaultDestinationValue;
                            etwProviderInstance.defaultDestination = defaultDestinationInstance;
                          }
                        }
                      }
                      
                      var manifestProvidersArray = etwProvidersValue['manifestProviders'];
                      if (manifestProvidersArray !== null && manifestProvidersArray !== undefined) {
                        for (var loweredIndex8 = 0; loweredIndex8 < manifestProvidersArray.length; loweredIndex8 = loweredIndex8 + 1) {
                          var manifestProvidersValue = manifestProvidersArray[loweredIndex8];
                          var etwProviderInstance2 = { events: [] };
                          etwProvidersInstance.manifestProviders.push(etwProviderInstance2);
                          
                          var scheduledTransferPeriodValue7 = manifestProvidersValue['scheduledTransferPeriod'];
                          if (scheduledTransferPeriodValue7 !== null && scheduledTransferPeriodValue7 !== undefined) {
                            var scheduledTransferPeriodInstance7 = moment.duration(scheduledTransferPeriodValue7);
                            etwProviderInstance2.scheduledTransferPeriod = scheduledTransferPeriodInstance7;
                          }
                          
                          var scheduledTransferLogLevelFilterValue3 = manifestProvidersValue['scheduledTransferLogLevelFilter'];
                          if (scheduledTransferLogLevelFilterValue3 !== null && scheduledTransferLogLevelFilterValue3 !== undefined) {
                            var scheduledTransferLogLevelFilterInstance3 = scheduledTransferLogLevelFilterValue3;
                            etwProviderInstance2.scheduledTransferLogLevelFilter = scheduledTransferLogLevelFilterInstance3;
                          }
                          
                          var providerValue2 = manifestProvidersValue['provider'];
                          if (providerValue2 !== null && providerValue2 !== undefined) {
                            var providerInstance2 = providerValue2;
                            etwProviderInstance2.provider = providerInstance2;
                          }
                          
                          var scheduledTransferKeywordFilterValue2 = manifestProvidersValue['scheduledTransferKeywordFilter'];
                          if (scheduledTransferKeywordFilterValue2 !== null && scheduledTransferKeywordFilterValue2 !== undefined) {
                            var scheduledTransferKeywordFilterInstance2 = scheduledTransferKeywordFilterValue2;
                            etwProviderInstance2.scheduledTransferKeywordFilter = scheduledTransferKeywordFilterInstance2;
                          }
                          
                          var eventsArray2 = manifestProvidersValue['events'];
                          if (eventsArray2 !== null && eventsArray2 !== undefined) {
                            for (var loweredIndex9 = 0; loweredIndex9 < eventsArray2.length; loweredIndex9 = loweredIndex9 + 1) {
                              var eventsValue2 = eventsArray2[loweredIndex9];
                              var etwEventConfigurationInstance2 = {};
                              etwProviderInstance2.events.push(etwEventConfigurationInstance2);
                              
                              var eventIdValue2 = eventsValue2['eventId'];
                              if (eventIdValue2 !== null && eventIdValue2 !== undefined) {
                                var eventIdInstance2 = eventIdValue2;
                                etwEventConfigurationInstance2.eventId = eventIdInstance2;
                              }
                              
                              var destinationValue2 = eventsValue2['destination'];
                              if (destinationValue2 !== null && destinationValue2 !== undefined) {
                                var destinationInstance2 = destinationValue2;
                                etwEventConfigurationInstance2.destination = destinationInstance2;
                              }
                            }
                          }
                          
                          var defaultDestinationValue2 = manifestProvidersValue['defaultDestination'];
                          if (defaultDestinationValue2 !== null && defaultDestinationValue2 !== undefined) {
                            var defaultDestinationInstance2 = defaultDestinationValue2;
                            etwProviderInstance2.defaultDestination = defaultDestinationInstance2;
                          }
                        }
                      }
                    }
                    
                    var crashDumpsValue = diagnosticMonitorConfigurationValue['crashDumps'];
                    if (crashDumpsValue !== null && crashDumpsValue !== undefined) {
                      var crashDumpsInstance = { processes: [] };
                      diagnosticMonitorConfigurationInstance.crashDumps = crashDumpsInstance;
                      
                      var directoryQuotaPercentageValue = crashDumpsValue['directoryQuotaPercentage'];
                      if (directoryQuotaPercentageValue !== null && directoryQuotaPercentageValue !== undefined) {
                        var directoryQuotaPercentageInstance = directoryQuotaPercentageValue;
                        crashDumpsInstance.directoryQuotaPercentage = directoryQuotaPercentageInstance;
                      }
                      
                      var dumpTypeValue = crashDumpsValue['dumpType'];
                      if (dumpTypeValue !== null && dumpTypeValue !== undefined) {
                        var dumpTypeInstance = dumpTypeValue;
                        crashDumpsInstance.dumpType = dumpTypeInstance;
                      }
                      
                      var containerNameValue2 = crashDumpsValue['containerName'];
                      if (containerNameValue2 !== null && containerNameValue2 !== undefined) {
                        var containerNameInstance2 = containerNameValue2;
                        crashDumpsInstance.containerName = containerNameInstance2;
                      }
                      
                      var processesArray = crashDumpsValue['processes'];
                      if (processesArray !== null && processesArray !== undefined) {
                        for (var loweredIndex10 = 0; loweredIndex10 < processesArray.length; loweredIndex10 = loweredIndex10 + 1) {
                          var processesValue = processesArray[loweredIndex10];
                          crashDumpsInstance.processes.push(processesValue);
                        }
                      }
                    }
                  }
                  
                  var localResourceDirectoryValue = publicConfigurationValue['localResourceDirectory'];
                  if (localResourceDirectoryValue !== null && localResourceDirectoryValue !== undefined) {
                    var localResourceDirectoryInstance = {};
                    publicMonitoringConfigurationInstance.localResourceDirectory = localResourceDirectoryInstance;
                    
                    var expandEnvironmentValue2 = localResourceDirectoryValue['expandEnvironment'];
                    if (expandEnvironmentValue2 !== null && expandEnvironmentValue2 !== undefined) {
                      var expandEnvironmentInstance2 = expandEnvironmentValue2;
                      localResourceDirectoryInstance.expandEnvironment = expandEnvironmentInstance2;
                    }
                    
                    var pathValue3 = localResourceDirectoryValue['path'];
                    if (pathValue3 !== null && pathValue3 !== undefined) {
                      var pathInstance2 = pathValue3;
                      localResourceDirectoryInstance.path = pathInstance2;
                    }
                  }
                  
                  var storageAccountValue = publicConfigurationValue['storageAccount'];
                  if (storageAccountValue !== null && storageAccountValue !== undefined) {
                    var storageAccountInstance = storageAccountValue;
                    publicMonitoringConfigurationInstance.storageAccount = storageAccountInstance;
                  }
                  propertiesInstance.publicConfiguration = publicMonitoringConfigurationInstance;
                }
              }
            }
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceUri The resource identifier of the configuration.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    MonitoringConfigurationOperations.prototype.getStorageConfiguration = function(resourceUri, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceUri === null || resourceUri === undefined) {
        return callback(new Error('resourceUri cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/';
      url2 = url2 + encodeURIComponent(resourceUri);
      url2 = url2 + '/diagnosticSettings/storage';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'GET';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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 nameValue = responseDoc['name'];
            if (nameValue !== null && nameValue !== undefined) {
              var nameInstance = nameValue;
              result.name = nameInstance;
            }
            
            var locationValue = responseDoc['location'];
            if (locationValue !== null && locationValue !== undefined) {
              var locationInstance = locationValue;
              result.location = locationInstance;
            }
            
            var propertiesValue = responseDoc['properties'];
            if (propertiesValue !== null && propertiesValue !== undefined) {
              var propertiesInstance = {};
              result.properties = propertiesInstance;
              
              var loggingValue = propertiesValue['logging'];
              if (loggingValue !== null && loggingValue !== undefined) {
                var loggingInstance = {};
                propertiesInstance.loggingConfiguration = loggingInstance;
                
                var deleteValue = loggingValue['delete'];
                if (deleteValue !== null && deleteValue !== undefined) {
                  var deleteInstance = deleteValue;
                  loggingInstance.delete = deleteInstance;
                }
                
                var readValue = loggingValue['read'];
                if (readValue !== null && readValue !== undefined) {
                  var readInstance = readValue;
                  loggingInstance.read = readInstance;
                }
                
                var writeValue = loggingValue['write'];
                if (writeValue !== null && writeValue !== undefined) {
                  var writeInstance = writeValue;
                  loggingInstance.write = writeInstance;
                }
                
                var retentionValue = loggingValue['retention'];
                if (retentionValue !== null && retentionValue !== undefined) {
                  var retentionInstance = moment.duration(retentionValue);
                  loggingInstance.retention = retentionInstance;
                }
              }
              
              var metricsValue = propertiesValue['metrics'];
              if (metricsValue !== null && metricsValue !== undefined) {
                var metricsInstance = { metricAggregations: [] };
                propertiesInstance.metricConfiguration = metricsInstance;
                
                var aggregationsArray = metricsValue['aggregations'];
                if (aggregationsArray !== null && aggregationsArray !== undefined) {
                  for (var loweredIndex1 = 0; loweredIndex1 < aggregationsArray.length; loweredIndex1 = loweredIndex1 + 1) {
                    var aggregationsValue = aggregationsArray[loweredIndex1];
                    var storageMetricAggregationInstance = {};
                    metricsInstance.metricAggregations.push(storageMetricAggregationInstance);
                    
                    var scheduledTransferPeriodValue = aggregationsValue['scheduledTransferPeriod'];
                    if (scheduledTransferPeriodValue !== null && scheduledTransferPeriodValue !== undefined) {
                      var scheduledTransferPeriodInstance = moment.duration(scheduledTransferPeriodValue);
                      storageMetricAggregationInstance.scheduledTransferPeriod = scheduledTransferPeriodInstance;
                    }
                    
                    var retentionValue2 = aggregationsValue['retention'];
                    if (retentionValue2 !== null && retentionValue2 !== undefined) {
                      var retentionInstance2 = moment.duration(retentionValue2);
                      storageMetricAggregationInstance.retention = retentionInstance2;
                    }
                    
                    var levelValue = aggregationsValue['level'];
                    if (levelValue !== null && levelValue !== undefined) {
                      var levelInstance = levelValue;
                      storageMetricAggregationInstance.level = levelInstance;
                    }
                  }
                }
              }
            }
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceUri The resource identifier for the configuration.
     * 
     * @param {MonitoringConfigurationCreateOrUpdateParameters} parameters
     * Parameters supplied to the operation.
     * 
     * @param {DiagnosticSettings} [parameters.properties] Gets or sets the
     * public configuration settings.
     * 
     * @param {string} [parameters.properties.name] Gets or sets the setting name.
     * 
     * @param {string} [parameters.properties.description] Gets or sets the
     * setting description.
     * 
     * @param {PublicConfiguration} [parameters.properties.publicConfiguration]
     * Gets or sets the public diagnostic configuration.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    MonitoringConfigurationOperations.prototype.updateConfiguration = function(resourceUri, parameters, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceUri === null || resourceUri === undefined) {
        return callback(new Error('resourceUri cannot be null.'));
      }
      if (parameters === null || parameters === undefined) {
        return callback(new Error('parameters cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/';
      url2 = url2 + encodeURIComponent(resourceUri);
      url2 = url2 + '/diagnosticSettings/agent';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      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 = 'PATCH';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // Serialize Request
      var requestContent = null;
      var requestDoc = null;
      
      var monitoringConfigurationCreateOrUpdateParametersValue = {};
      requestDoc = monitoringConfigurationCreateOrUpdateParametersValue;
      
      if (parameters.properties !== null && parameters.properties !== undefined) {
        var propertiesValue = {};
        monitoringConfigurationCreateOrUpdateParametersValue['properties'] = propertiesValue;
        
        if (parameters.properties.name !== null && parameters.properties.name !== undefined) {
          propertiesValue['name'] = parameters.properties.name;
        }
        
        if (parameters.properties.description !== null && parameters.properties.description !== undefined) {
          propertiesValue['description'] = parameters.properties.description;
        }
        
        if (parameters.properties.publicConfiguration !== null && parameters.properties.publicConfiguration !== undefined) {
          var publicConfigurationValue = {};
          propertiesValue['publicConfiguration'] = publicConfigurationValue;
          if (parameters.properties.publicConfiguration.type === 'Microsoft.Azure.Management.Insights.Models.PublicMonitoringConfiguration') {
            publicConfigurationValue['odata.type'] = parameters.properties.publicConfiguration.type;
            var derived = parameters.properties.publicConfiguration;
            
            if (derived.diagnosticMonitorConfiguration !== null && derived.diagnosticMonitorConfiguration !== undefined) {
              var diagnosticMonitorConfigurationValue = {};
              publicConfigurationValue['diagnosticMonitorConfiguration'] = diagnosticMonitorConfigurationValue;
              
              if (derived.diagnosticMonitorConfiguration.overallQuotaInMB !== null && derived.diagnosticMonitorConfiguration.overallQuotaInMB !== undefined) {
                diagnosticMonitorConfigurationValue['overallQuotaInMB'] = derived.diagnosticMonitorConfiguration.overallQuotaInMB;
              }
              
              if (derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs !== null && derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs !== undefined) {
                var diagnosticInfrastructureLogsValue = {};
                diagnosticMonitorConfigurationValue['diagnosticInfrastructureLogs'] = diagnosticInfrastructureLogsValue;
                
                if (derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs.scheduledTransferLogLevelFilter !== null && derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs.scheduledTransferLogLevelFilter !== undefined) {
                  diagnosticInfrastructureLogsValue['scheduledTransferLogLevelFilter'] = derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs.scheduledTransferLogLevelFilter !== null && derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs.scheduledTransferLogLevelFilter !== undefined ? derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs.scheduledTransferLogLevelFilter.toString() : 'Undefined';
                }
                
                if (derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs.scheduledTransferPeriod !== null && derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs.scheduledTransferPeriod !== undefined) {
                  diagnosticInfrastructureLogsValue['scheduledTransferPeriod'] = derived.diagnosticMonitorConfiguration.diagnosticInfrastructureLogs.scheduledTransferPeriod.toIsoString();
                }
              }
              
              if (derived.diagnosticMonitorConfiguration.metrics !== null && derived.diagnosticMonitorConfiguration.metrics !== undefined) {
                var metricsValue = {};
                diagnosticMonitorConfigurationValue['metrics'] = metricsValue;
                
                if (derived.diagnosticMonitorConfiguration.metrics.resourceId !== null && derived.diagnosticMonitorConfiguration.metrics.resourceId !== undefined) {
                  metricsValue['resourceId'] = derived.diagnosticMonitorConfiguration.metrics.resourceId;
                }
                
                if (derived.diagnosticMonitorConfiguration.metrics.metricAggregations !== null && derived.diagnosticMonitorConfiguration.metrics.metricAggregations !== undefined) {
                  var aggregationsArray = [];
                  for (var loweredIndex1 = 0; loweredIndex1 < derived.diagnosticMonitorConfiguration.metrics.metricAggregations.length; loweredIndex1 = loweredIndex1 + 1) {
                    var aggregationsItem = derived.diagnosticMonitorConfiguration.metrics.metricAggregations[loweredIndex1];
                    var metricsValue2 = {};
                    aggregationsArray.push(metricsValue2);
                    
                    if (aggregationsItem.scheduledTransferPeriod !== null && aggregationsItem.scheduledTransferPeriod !== undefined) {
                      metricsValue2['scheduledTransferPeriod'] = aggregationsItem.scheduledTransferPeriod.toIsoString();
                    }
                  }
                  metricsValue['aggregations'] = aggregationsArray;
                }
              }
              
              if (derived.diagnosticMonitorConfiguration.directories !== null && derived.diagnosticMonitorConfiguration.directories !== undefined) {
                var directoriesValue = {};
                diagnosticMonitorConfigurationValue['directories'] = directoriesValue;
                
                if (derived.diagnosticMonitorConfiguration.directories.dataSources !== null && derived.diagnosticMonitorConfiguration.directories.dataSources !== undefined) {
                  var dataSourcesArray = [];
                  for (var loweredIndex2 = 0; loweredIndex2 < derived.diagnosticMonitorConfiguration.directories.dataSources.length; loweredIndex2 = loweredIndex2 + 1) {
                    var dataSourcesItem = derived.diagnosticMonitorConfiguration.directories.dataSources[loweredIndex2];
                    var directoryConfigurationValue = {};
                    dataSourcesArray.push(directoryConfigurationValue);
                    
                    if (dataSourcesItem.containerName !== null && dataSourcesItem.containerName !== undefined) {
                      directoryConfigurationValue['containerName'] = dataSourcesItem.containerName;
                    }
                    
                    if (dataSourcesItem.path !== null && dataSourcesItem.path !== undefined) {
                      var pathValue = {};
                      directoryConfigurationValue['path'] = pathValue;
                      if (dataSourcesItem.path.type === 'Microsoft.Azure.Management.Insights.Models.DirectoryAbsolute') {
                        pathValue['odata.type'] = dataSourcesItem.path.type;
                        var derived2 = dataSourcesItem.path;
                        
                        if (derived2.expandEnvironment !== null && derived2.expandEnvironment !== undefined) {
                          pathValue['expandEnvironment'] = derived2.expandEnvironment;
                        }
                        
                        if (derived2.path !== null && derived2.path !== undefined) {
                          pathValue['path'] = derived2.path;
                        }
                      }
                      if (dataSourcesItem.path.type === 'Microsoft.Azure.Management.Insights.Models.DirectoryLocal') {
                        pathValue['odata.type'] = dataSourcesItem.path.type;
                        var derived3 = dataSourcesItem.path;
                        
                        if (derived3.relativePath !== null && derived3.relativePath !== undefined) {
                          pathValue['relativePath'] = derived3.relativePath;
                        }
                        
                        if (derived3.name !== null && derived3.name !== undefined) {
                          pathValue['name'] = derived3.name;
                        }
                      }
                    }
                  }
                  directoriesValue['dataSources'] = dataSourcesArray;
                }
                
                if (derived.diagnosticMonitorConfiguration.directories.iISLogs !== null && derived.diagnosticMonitorConfiguration.directories.iISLogs !== undefined) {
                  directoriesValue['iisLogs'] = derived.diagnosticMonitorConfiguration.directories.iISLogs;
                }
                
                if (derived.diagnosticMonitorConfiguration.directories.failedRequestLogs !== null && derived.diagnosticMonitorConfiguration.directories.failedRequestLogs !== undefined) {
                  directoriesValue['failedRequestLogs'] = derived.diagnosticMonitorConfiguration.directories.failedRequestLogs;
                }
                
                if (derived.diagnosticMonitorConfiguration.directories.scheduledTransferPeriod !== null && derived.diagnosticMonitorConfiguration.directories.scheduledTransferPeriod !== undefined) {
                  directoriesValue['scheduledTransferPeriod'] = derived.diagnosticMonitorConfiguration.directories.scheduledTransferPeriod.toIsoString();
                }
              }
              
              if (derived.diagnosticMonitorConfiguration.performanceCounters !== null && derived.diagnosticMonitorConfiguration.performanceCounters !== undefined) {
                var performanceCountersValue = {};
                diagnosticMonitorConfigurationValue['performanceCounters'] = performanceCountersValue;
                
                if (derived.diagnosticMonitorConfiguration.performanceCounters.counters !== null && derived.diagnosticMonitorConfiguration.performanceCounters.counters !== undefined) {
                  var countersArray = [];
                  for (var loweredIndex3 = 0; loweredIndex3 < derived.diagnosticMonitorConfiguration.performanceCounters.counters.length; loweredIndex3 = loweredIndex3 + 1) {
                    var countersItem = derived.diagnosticMonitorConfiguration.performanceCounters.counters[loweredIndex3];
                    var performanceCounterConfigurationValue = {};
                    countersArray.push(performanceCounterConfigurationValue);
                    
                    if (countersItem.annotations !== null && countersItem.annotations !== undefined) {
                      var annotationsArray = [];
                      for (var loweredIndex4 = 0; loweredIndex4 < countersItem.annotations.length; loweredIndex4 = loweredIndex4 + 1) {
                        var annotationsItem = countersItem.annotations[loweredIndex4];
                        var localizedStringValue = {};
                        annotationsArray.push(localizedStringValue);
                        
                        if (annotationsItem.value !== null && annotationsItem.value !== undefined) {
                          localizedStringValue['value'] = annotationsItem.value;
                        }
                        
                        if (annotationsItem.locale !== null && annotationsItem.locale !== undefined) {
                          localizedStringValue['locale'] = annotationsItem.locale;
                        }
                      }
                      performanceCounterConfigurationValue['annotations'] = annotationsArray;
                    }
                    
                    if (countersItem.counterSpecifier !== null && countersItem.counterSpecifier !== undefined) {
                      performanceCounterConfigurationValue['counterSpecifier'] = countersItem.counterSpecifier;
                    }
                    
                    if (countersItem.sampleRate !== null && countersItem.sampleRate !== undefined) {
                      performanceCounterConfigurationValue['sampleRate'] = countersItem.sampleRate.toIsoString();
                    }
                    
                    if (countersItem.unit !== null && countersItem.unit !== undefined) {
                      performanceCounterConfigurationValue['unit'] = countersItem.unit !== null && countersItem.unit !== undefined ? countersItem.unit.toString() : 'Count';
                    }
                  }
                  performanceCountersValue['counters'] = countersArray;
                }
                
                if (derived.diagnosticMonitorConfiguration.performanceCounters.scheduledTransferPeriod !== null && derived.diagnosticMonitorConfiguration.performanceCounters.scheduledTransferPeriod !== undefined) {
                  performanceCountersValue['scheduledTransferPeriod'] = derived.diagnosticMonitorConfiguration.performanceCounters.scheduledTransferPeriod.toIsoString();
                }
              }
              
              if (derived.diagnosticMonitorConfiguration.windowsEventLog !== null && derived.diagnosticMonitorConfiguration.windowsEventLog !== undefined) {
                var windowsEventLogValue = {};
                diagnosticMonitorConfigurationValue['windowsEventLog'] = windowsEventLogValue;
                
                if (derived.diagnosticMonitorConfiguration.windowsEventLog.dataSources !== null && derived.diagnosticMonitorConfiguration.windowsEventLog.dataSources !== undefined) {
                  var dataSourcesArray2 = [];
                  for (var loweredIndex5 = 0; loweredIndex5 < derived.diagnosticMonitorConfiguration.windowsEventLog.dataSources.length; loweredIndex5 = loweredIndex5 + 1) {
                    var dataSourcesItem2 = derived.diagnosticMonitorConfiguration.windowsEventLog.dataSources[loweredIndex5];
                    dataSourcesArray2.push(dataSourcesItem2);
                  }
                  windowsEventLogValue['dataSources'] = dataSourcesArray2;
                }
                
                if (derived.diagnosticMonitorConfiguration.windowsEventLog.scheduledTransferPeriod !== null && derived.diagnosticMonitorConfiguration.windowsEventLog.scheduledTransferPeriod !== undefined) {
                  windowsEventLogValue['scheduledTransferPeriod'] = derived.diagnosticMonitorConfiguration.windowsEventLog.scheduledTransferPeriod.toIsoString();
                }
              }
              
              if (derived.diagnosticMonitorConfiguration.etwProviders !== null && derived.diagnosticMonitorConfiguration.etwProviders !== undefined) {
                var etwProvidersValue = {};
                diagnosticMonitorConfigurationValue['etwProviders'] = etwProvidersValue;
                
                if (derived.diagnosticMonitorConfiguration.etwProviders.eventSourceProviders !== null && derived.diagnosticMonitorConfiguration.etwProviders.eventSourceProviders !== undefined) {
                  var eventSourceProvidersArray = [];
                  for (var loweredIndex6 = 0; loweredIndex6 < derived.diagnosticMonitorConfiguration.etwProviders.eventSourceProviders.length; loweredIndex6 = loweredIndex6 + 1) {
                    var eventSourceProvidersItem = derived.diagnosticMonitorConfiguration.etwProviders.eventSourceProviders[loweredIndex6];
                    var etwProviderValue = {};
                    eventSourceProvidersArray.push(etwProviderValue);
                    
                    if (eventSourceProvidersItem.scheduledTransferPeriod !== null && eventSourceProvidersItem.scheduledTransferPeriod !== undefined) {
                      etwProviderValue['scheduledTransferPeriod'] = eventSourceProvidersItem.scheduledTransferPeriod.toIsoString();
                    }
                    
                    if (eventSourceProvidersItem.scheduledTransferLogLevelFilter !== null && eventSourceProvidersItem.scheduledTransferLogLevelFilter !== undefined) {
                      etwProviderValue['scheduledTransferLogLevelFilter'] = eventSourceProvidersItem.scheduledTransferLogLevelFilter !== null && eventSourceProvidersItem.scheduledTransferLogLevelFilter !== undefined ? eventSourceProvidersItem.scheduledTransferLogLevelFilter.toString() : 'Undefined';
                    }
                    
                    if (eventSourceProvidersItem.provider !== null && eventSourceProvidersItem.provider !== undefined) {
                      etwProviderValue['provider'] = eventSourceProvidersItem.provider;
                    }
                    
                    if (eventSourceProvidersItem.scheduledTransferKeywordFilter !== null && eventSourceProvidersItem.scheduledTransferKeywordFilter !== undefined) {
                      etwProviderValue['scheduledTransferKeywordFilter'] = eventSourceProvidersItem.scheduledTransferKeywordFilter;
                    }
                    
                    if (eventSourceProvidersItem.events !== null && eventSourceProvidersItem.events !== undefined) {
                      var eventsArray = [];
                      for (var loweredIndex7 = 0; loweredIndex7 < eventSourceProvidersItem.events.length; loweredIndex7 = loweredIndex7 + 1) {
                        var eventsItem = eventSourceProvidersItem.events[loweredIndex7];
                        var etwEventConfigurationValue = {};
                        eventsArray.push(etwEventConfigurationValue);
                        
                        if (eventsItem.eventId !== null && eventsItem.eventId !== undefined) {
                          etwEventConfigurationValue['eventId'] = eventsItem.eventId;
                        }
                        
                        if (eventsItem.destination !== null && eventsItem.destination !== undefined) {
                          etwEventConfigurationValue['destination'] = eventsItem.destination;
                        }
                      }
                      etwProviderValue['events'] = eventsArray;
                    }
                    
                    if (eventSourceProvidersItem.defaultDestination !== null && eventSourceProvidersItem.defaultDestination !== undefined) {
                      etwProviderValue['defaultDestination'] = eventSourceProvidersItem.defaultDestination;
                    }
                  }
                  etwProvidersValue['eventSourceProviders'] = eventSourceProvidersArray;
                }
                
                if (derived.diagnosticMonitorConfiguration.etwProviders.manifestProviders !== null && derived.diagnosticMonitorConfiguration.etwProviders.manifestProviders !== undefined) {
                  var manifestProvidersArray = [];
                  for (var loweredIndex8 = 0; loweredIndex8 < derived.diagnosticMonitorConfiguration.etwProviders.manifestProviders.length; loweredIndex8 = loweredIndex8 + 1) {
                    var manifestProvidersItem = derived.diagnosticMonitorConfiguration.etwProviders.manifestProviders[loweredIndex8];
                    var etwProviderValue2 = {};
                    manifestProvidersArray.push(etwProviderValue2);
                    
                    if (manifestProvidersItem.scheduledTransferPeriod !== null && manifestProvidersItem.scheduledTransferPeriod !== undefined) {
                      etwProviderValue2['scheduledTransferPeriod'] = manifestProvidersItem.scheduledTransferPeriod.toIsoString();
                    }
                    
                    if (manifestProvidersItem.scheduledTransferLogLevelFilter !== null && manifestProvidersItem.scheduledTransferLogLevelFilter !== undefined) {
                      etwProviderValue2['scheduledTransferLogLevelFilter'] = manifestProvidersItem.scheduledTransferLogLevelFilter !== null && manifestProvidersItem.scheduledTransferLogLevelFilter !== undefined ? manifestProvidersItem.scheduledTransferLogLevelFilter.toString() : 'Undefined';
                    }
                    
                    if (manifestProvidersItem.provider !== null && manifestProvidersItem.provider !== undefined) {
                      etwProviderValue2['provider'] = manifestProvidersItem.provider;
                    }
                    
                    if (manifestProvidersItem.scheduledTransferKeywordFilter !== null && manifestProvidersItem.scheduledTransferKeywordFilter !== undefined) {
                      etwProviderValue2['scheduledTransferKeywordFilter'] = manifestProvidersItem.scheduledTransferKeywordFilter;
                    }
                    
                    if (manifestProvidersItem.events !== null && manifestProvidersItem.events !== undefined) {
                      var eventsArray2 = [];
                      for (var loweredIndex9 = 0; loweredIndex9 < manifestProvidersItem.events.length; loweredIndex9 = loweredIndex9 + 1) {
                        var eventsItem2 = manifestProvidersItem.events[loweredIndex9];
                        var etwEventConfigurationValue2 = {};
                        eventsArray2.push(etwEventConfigurationValue2);
                        
                        if (eventsItem2.eventId !== null && eventsItem2.eventId !== undefined) {
                          etwEventConfigurationValue2['eventId'] = eventsItem2.eventId;
                        }
                        
                        if (eventsItem2.destination !== null && eventsItem2.destination !== undefined) {
                          etwEventConfigurationValue2['destination'] = eventsItem2.destination;
                        }
                      }
                      etwProviderValue2['events'] = eventsArray2;
                    }
                    
                    if (manifestProvidersItem.defaultDestination !== null && manifestProvidersItem.defaultDestination !== undefined) {
                      etwProviderValue2['defaultDestination'] = manifestProvidersItem.defaultDestination;
                    }
                  }
                  etwProvidersValue['manifestProviders'] = manifestProvidersArray;
                }
              }
              
              if (derived.diagnosticMonitorConfiguration.crashDumps !== null && derived.diagnosticMonitorConfiguration.crashDumps !== undefined) {
                var crashDumpsValue = {};
                diagnosticMonitorConfigurationValue['crashDumps'] = crashDumpsValue;
                
                if (derived.diagnosticMonitorConfiguration.crashDumps.directoryQuotaPercentage !== null && derived.diagnosticMonitorConfiguration.crashDumps.directoryQuotaPercentage !== undefined) {
                  crashDumpsValue['directoryQuotaPercentage'] = derived.diagnosticMonitorConfiguration.crashDumps.directoryQuotaPercentage;
                }
                
                if (derived.diagnosticMonitorConfiguration.crashDumps.dumpType !== null && derived.diagnosticMonitorConfiguration.crashDumps.dumpType !== undefined) {
                  crashDumpsValue['dumpType'] = derived.diagnosticMonitorConfiguration.crashDumps.dumpType !== null && derived.diagnosticMonitorConfiguration.crashDumps.dumpType !== undefined ? derived.diagnosticMonitorConfiguration.crashDumps.dumpType.toString() : 'Mini';
                }
                
                if (derived.diagnosticMonitorConfiguration.crashDumps.containerName !== null && derived.diagnosticMonitorConfiguration.crashDumps.containerName !== undefined) {
                  crashDumpsValue['containerName'] = derived.diagnosticMonitorConfiguration.crashDumps.containerName;
                }
                
                if (derived.diagnosticMonitorConfiguration.crashDumps.processes !== null && derived.diagnosticMonitorConfiguration.crashDumps.processes !== undefined) {
                  var processesArray = [];
                  for (var loweredIndex10 = 0; loweredIndex10 < derived.diagnosticMonitorConfiguration.crashDumps.processes.length; loweredIndex10 = loweredIndex10 + 1) {
                    var processesItem = derived.diagnosticMonitorConfiguration.crashDumps.processes[loweredIndex10];
                    processesArray.push(processesItem);
                  }
                  crashDumpsValue['processes'] = processesArray;
                }
              }
            }
            
            if (derived.localResourceDirectory !== null && derived.localResourceDirectory !== undefined) {
              var localResourceDirectoryValue = {};
              publicConfigurationValue['localResourceDirectory'] = localResourceDirectoryValue;
              
              if (derived.localResourceDirectory.expandEnvironment !== null && derived.localResourceDirectory.expandEnvironment !== undefined) {
                localResourceDirectoryValue['expandEnvironment'] = derived.localResourceDirectory.expandEnvironment;
              }
              
              if (derived.localResourceDirectory.path !== null && derived.localResourceDirectory.path !== undefined) {
                localResourceDirectoryValue['path'] = derived.localResourceDirectory.path;
              }
            }
            
            if (derived.storageAccount !== null && derived.storageAccount !== undefined) {
              publicConfigurationValue['storageAccount'] = derived.storageAccount;
            }
          }
        }
      }
      
      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 && statusCode !== 201) {
          var error = new Error(body);
          error.statusCode = response.statusCode;
          return callback(error);
        }
        
        // Create Result
        var result = null;
        // Deserialize Response
        if (statusCode === 200 || statusCode === 201) {
          var responseContent = body;
          result = {};
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceUri The resource identifier of the configuration.
     * 
     * @param {CreateOrUpdateStorageConfigurationParameters} parameters
     * Parameters supplied to the operation.
     * 
     * @param {StorageConfiguration} [parameters.properties] Gets or sets the
     * public configuration settings.
     * 
     * @param {StorageLoggingConfiguration}
     * [parameters.properties.loggingConfiguration] Gets or sets the storage
     * logging configuration. Settings for logging successful and failed
     * requests to a storage service. This information can be used to monitor
     * individual requests and to diagnose issues with a storage service.
     * Requests are logged on a best-effort basis.
     * 
     * @param {boolean} [parameters.properties.loggingConfiguration.delete] Gets
     * or sets the delete flag. Indicates whether all delete requests should be
     * logged.
     * 
     * @param {boolean} [parameters.properties.loggingConfiguration.read] Gets or
     * sets the read flag. Indicates whether all read requests should be logged.
     * 
     * @param {boolean} [parameters.properties.loggingConfiguration.write] Gets
     * or sets the write flag. Indicates whether all write requests should be
     * logged.
     * 
     * @param {TimeSpan} [parameters.properties.loggingConfiguration.retention]
     * Gets or sets the retention flag. Indicates the how long log data should
     * be retained (must be an even number of days). All data older than this
     * value will be deleted. The minimum number of days is 1; the largest value
     * is 365 (one year).
     * 
     * @param {StorageMetricConfiguration}
     * [parameters.properties.metricConfiguration] Gets or sets the settings for
     * metrics that include aggregated transaction statistics and capacity data
     * about requests to a storage service.
     * 
     * @param {array}
     * [parameters.properties.metricConfiguration.metricAggregations] Gets or
     * sets the list of aggregations to generate.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    MonitoringConfigurationOperations.prototype.updateStorageConfiguration = function(resourceUri, parameters, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceUri === null || resourceUri === undefined) {
        return callback(new Error('resourceUri cannot be null.'));
      }
      if (parameters === null || parameters === undefined) {
        return callback(new Error('parameters cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/';
      url2 = url2 + encodeURIComponent(resourceUri);
      url2 = url2 + '/diagnosticSettings/storage';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      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 = 'PATCH';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // Serialize Request
      var requestContent = null;
      var requestDoc = null;
      
      var createOrUpdateStorageConfigurationParametersValue = {};
      requestDoc = createOrUpdateStorageConfigurationParametersValue;
      
      if (parameters.properties !== null && parameters.properties !== undefined) {
        var propertiesValue = {};
        createOrUpdateStorageConfigurationParametersValue['properties'] = propertiesValue;
        
        if (parameters.properties.loggingConfiguration !== null && parameters.properties.loggingConfiguration !== undefined) {
          var loggingValue = {};
          propertiesValue['logging'] = loggingValue;
          
          if (parameters.properties.loggingConfiguration.delete !== null && parameters.properties.loggingConfiguration.delete !== undefined) {
            loggingValue['delete'] = parameters.properties.loggingConfiguration.delete;
          }
          
          if (parameters.properties.loggingConfiguration.read !== null && parameters.properties.loggingConfiguration.read !== undefined) {
            loggingValue['read'] = parameters.properties.loggingConfiguration.read;
          }
          
          if (parameters.properties.loggingConfiguration.write !== null && parameters.properties.loggingConfiguration.write !== undefined) {
            loggingValue['write'] = parameters.properties.loggingConfiguration.write;
          }
          
          if (parameters.properties.loggingConfiguration.retention !== null && parameters.properties.loggingConfiguration.retention !== undefined) {
            loggingValue['retention'] = parameters.properties.loggingConfiguration.retention.toIsoString();
          }
        }
        
        if (parameters.properties.metricConfiguration !== null && parameters.properties.metricConfiguration !== undefined) {
          var metricsValue = {};
          propertiesValue['metrics'] = metricsValue;
          
          if (parameters.properties.metricConfiguration.metricAggregations !== null && parameters.properties.metricConfiguration.metricAggregations !== undefined) {
            var aggregationsArray = [];
            for (var loweredIndex1 = 0; loweredIndex1 < parameters.properties.metricConfiguration.metricAggregations.length; loweredIndex1 = loweredIndex1 + 1) {
              var aggregationsItem = parameters.properties.metricConfiguration.metricAggregations[loweredIndex1];
              var storageMetricAggregationValue = {};
              aggregationsArray.push(storageMetricAggregationValue);
              
              if (aggregationsItem.scheduledTransferPeriod !== null && aggregationsItem.scheduledTransferPeriod !== undefined) {
                storageMetricAggregationValue['scheduledTransferPeriod'] = aggregationsItem.scheduledTransferPeriod.toIsoString();
              }
              
              if (aggregationsItem.retention !== null && aggregationsItem.retention !== undefined) {
                storageMetricAggregationValue['retention'] = aggregationsItem.retention.toIsoString();
              }
              
              if (aggregationsItem.level !== null && aggregationsItem.level !== undefined) {
                storageMetricAggregationValue['level'] = aggregationsItem.level !== null && aggregationsItem.level !== undefined ? aggregationsItem.level.toString() : 'None';
              }
            }
            metricsValue['aggregations'] = aggregationsArray;
          }
        }
      }
      
      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 && statusCode !== 201 && statusCode !== 202) {
          var error = new Error(body);
          error.statusCode = response.statusCode;
          return callback(error);
        }
        
        // Create Result
        var result = null;
        // Deserialize Response
        if (statusCode === 200 || statusCode === 201 || statusCode === 202) {
          var responseContent = body;
          result = {};
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    return MonitoringConfigurationOperations;
  })();
  
  var ServiceDiagnosticSettingsOperations = ( /** @lends ServiceDiagnosticSettingsOperations */ function() {
    /**
     * @class
     * Operations for managing service diagnostic settings.
     * __NOTE__: An instance of this class is automatically created for an
     * instance of the [InsightsManagementClient] {@link
     * InsightsManagementClient~InsightsManagementClient}.
     * See [serviceDiagnosticSettingsOperations] {@link
     * InsightsManagementClient~InsightsManagementClient#serviceDiagnosticSettingsOperations}.
     * Initializes a new instance of the ServiceDiagnosticSettingsOperations
     * class.
     * @constructor
     * 
     * @param {InsightsManagementClient} client Reference to the service client.
     */
    function ServiceDiagnosticSettingsOperations(client) {
      this.client = client;
    }
    
    /**
     * Deletes the diagnostic settings for the specified resource.
     * 
     * @param {string} resourceUri The resource identifier of the configuration.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    ServiceDiagnosticSettingsOperations.prototype.deleteMethod = function(resourceUri, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceUri === null || resourceUri === undefined) {
        return callback(new Error('resourceUri cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/';
      url2 = url2 + encodeURIComponent(resourceUri);
      url2 = url2 + '/diagnosticSettings/service';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      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 = 'DELETE';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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) {
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * Gets the active diagnostic settings. To get the diagnostic settings being
     * applied, use GetStatus.
     * 
     * @param {string} resourceUri The resource identifier of the configuration.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    ServiceDiagnosticSettingsOperations.prototype.get = function(resourceUri, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceUri === null || resourceUri === undefined) {
        return callback(new Error('resourceUri cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/';
      url2 = url2 + encodeURIComponent(resourceUri);
      url2 = url2 + '/diagnosticSettings/service';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'GET';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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 nameValue = responseDoc['name'];
            if (nameValue !== null && nameValue !== undefined) {
              var nameInstance = nameValue;
              result.name = nameInstance;
            }
            
            var locationValue = responseDoc['location'];
            if (locationValue !== null && locationValue !== undefined) {
              var locationInstance = locationValue;
              result.location = locationInstance;
            }
            
            var propertiesValue = responseDoc['properties'];
            if (propertiesValue !== null && propertiesValue !== undefined) {
              var propertiesInstance = {};
              result.properties = propertiesInstance;
              
              var storageAccountNameValue = propertiesValue['storageAccountName'];
              if (storageAccountNameValue !== null && storageAccountNameValue !== undefined) {
                var storageAccountNameInstance = storageAccountNameValue;
                propertiesInstance.storageAccountName = storageAccountNameInstance;
              }
              
              var statusValue = propertiesValue['status'];
              if (statusValue !== null && statusValue !== undefined) {
                var statusInstance = statusValue;
                propertiesInstance.status = statusInstance;
              }
            }
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * Gets the status of the diagnostic settings being applied. Once it is
     * successfull, it will replace the current diagnostic settings. To get the
     * active one, use Get.
     * 
     * @param {string} resourceUri The resource identifier of the configuration.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    ServiceDiagnosticSettingsOperations.prototype.getStatus = function(resourceUri, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceUri === null || resourceUri === undefined) {
        return callback(new Error('resourceUri cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/';
      url2 = url2 + encodeURIComponent(resourceUri);
      url2 = url2 + '/diagnosticSettings/service/poll';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'GET';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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 nameValue = responseDoc['name'];
            if (nameValue !== null && nameValue !== undefined) {
              var nameInstance = nameValue;
              result.name = nameInstance;
            }
            
            var locationValue = responseDoc['location'];
            if (locationValue !== null && locationValue !== undefined) {
              var locationInstance = locationValue;
              result.location = locationInstance;
            }
            
            var propertiesValue = responseDoc['properties'];
            if (propertiesValue !== null && propertiesValue !== undefined) {
              var propertiesInstance = {};
              result.properties = propertiesInstance;
              
              var storageAccountNameValue = propertiesValue['storageAccountName'];
              if (storageAccountNameValue !== null && storageAccountNameValue !== undefined) {
                var storageAccountNameInstance = storageAccountNameValue;
                propertiesInstance.storageAccountName = storageAccountNameInstance;
              }
              
              var statusValue = propertiesValue['status'];
              if (statusValue !== null && statusValue !== undefined) {
                var statusInstance = statusValue;
                propertiesInstance.status = statusInstance;
              }
            }
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * Create or update new diagnostic settings for the specified resource. This
     * operation is long running. Use GetStatus to check the status of this
     * operation.
     * 
     * @param {string} resourceUri The resource identifier of the configuration.
     * 
     * @param {ServiceDiagnosticSettingsPutParameters} parameters Parameters
     * supplied to the operation.
     * 
     * @param {ServiceDiagnosticSettings} [parameters.properties] Gets or sets
     * the public configuration settings.
     * 
     * @param {string} [parameters.properties.storageAccountName] Gets or sets
     * the name of the Azure Storage account to store the data in.
     * 
     * @param {DiagnosticSettingsStatus} [parameters.properties.status] Gets or
     * sets the diagnostic setting status. Indicates the status of the last call
     * to set the configuration. Don't need to set this flag when applying
     * configuration.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    ServiceDiagnosticSettingsOperations.prototype.put = function(resourceUri, parameters, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceUri === null || resourceUri === undefined) {
        return callback(new Error('resourceUri cannot be null.'));
      }
      if (parameters === null || parameters === undefined) {
        return callback(new Error('parameters cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/';
      url2 = url2 + encodeURIComponent(resourceUri);
      url2 = url2 + '/diagnosticSettings/service';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'PUT';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // Serialize Request
      var requestContent = null;
      var requestDoc = null;
      
      var serviceDiagnosticSettingsPutParametersValue = {};
      requestDoc = serviceDiagnosticSettingsPutParametersValue;
      
      if (parameters.properties !== null && parameters.properties !== undefined) {
        var propertiesValue = {};
        serviceDiagnosticSettingsPutParametersValue['properties'] = propertiesValue;
        
        if (parameters.properties.storageAccountName !== null && parameters.properties.storageAccountName !== undefined) {
          propertiesValue['storageAccountName'] = parameters.properties.storageAccountName;
        }
        
        if (parameters.properties.status !== null && parameters.properties.status !== undefined) {
          propertiesValue['status'] = parameters.properties.status !== null && parameters.properties.status !== undefined ? parameters.properties.status.toString() : 'Succeeded';
        }
      }
      
      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 && statusCode !== 201 && statusCode !== 202) {
          var error = new Error(body);
          error.statusCode = response.statusCode;
          return callback(error);
        }
        
        // Create Result
        var result = null;
        // Deserialize Response
        if (statusCode === 200 || statusCode === 201 || statusCode === 202) {
          var responseContent = body;
          result = {};
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    return ServiceDiagnosticSettingsOperations;
  })();
  
  var SkuOperations = ( /** @lends SkuOperations */ function() {
    /**
     * @class
     * Operations for managing resources sku.
     * __NOTE__: An instance of this class is automatically created for an
     * instance of the [InsightsManagementClient] {@link
     * InsightsManagementClient~InsightsManagementClient}.
     * See [skuOperations] {@link
     * InsightsManagementClient~InsightsManagementClient#skuOperations}.
     * Initializes a new instance of the SkuOperations class.
     * @constructor
     * 
     * @param {InsightsManagementClient} client Reference to the service client.
     */
    function SkuOperations(client) {
      this.client = client;
    }
    
    /**
     * 
     * @param {string} resourceId The resource id.
     * 
     * @param {string} apiVersion The resource provider api version.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    SkuOperations.prototype.getAntaresCurrentSkuInternal = function(resourceId, apiVersion, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceId === null || resourceId === undefined) {
        return callback(new Error('resourceId cannot be null.'));
      }
      if (apiVersion === null || apiVersion === undefined) {
        return callback(new Error('apiVersion cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/';
      url2 = url2 + encodeURIComponent(resourceId);
      var queryParameters = [];
      queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'GET';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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 propertiesValue = responseDoc['properties'];
            if (propertiesValue !== null && propertiesValue !== undefined) {
              var propertiesInstance = {};
              result.properties = propertiesInstance;
              
              var skuValue = propertiesValue['sku'];
              if (skuValue !== null && skuValue !== undefined) {
                var skuInstance = skuValue;
                propertiesInstance.sku = skuInstance;
              }
              
              var currentNumberOfWorkersValue = propertiesValue['currentNumberOfWorkers'];
              if (currentNumberOfWorkersValue !== null && currentNumberOfWorkersValue !== undefined) {
                var currentNumberOfWorkersInstance = currentNumberOfWorkersValue;
                propertiesInstance.currentNumberOfWorkers = currentNumberOfWorkersInstance;
              }
              
              var currentWorkerSizeValue = propertiesValue['currentWorkerSize'];
              if (currentWorkerSizeValue !== null && currentWorkerSizeValue !== undefined) {
                var currentWorkerSizeInstance = currentWorkerSizeValue;
                propertiesInstance.currentWorkerSize = currentWorkerSizeInstance;
              }
            }
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceId The resource id.
     * 
     * @param {string} apiVersion The resource provider api version.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    SkuOperations.prototype.getCurrentSkuInternal = function(resourceId, apiVersion, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceId === null || resourceId === undefined) {
        return callback(new Error('resourceId cannot be null.'));
      }
      if (apiVersion === null || apiVersion === undefined) {
        return callback(new Error('apiVersion cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/';
      url2 = url2 + encodeURIComponent(resourceId);
      var queryParameters = [];
      queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'GET';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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 propertiesValue = responseDoc['properties'];
            if (propertiesValue !== null && propertiesValue !== undefined) {
              var propertiesInstance = {};
              result.properties = propertiesInstance;
              
              var skuValue = propertiesValue['sku'];
              if (skuValue !== null && skuValue !== undefined) {
                var skuInstance = {};
                propertiesInstance.sku = skuInstance;
                
                var nameValue = skuValue['name'];
                if (nameValue !== null && nameValue !== undefined) {
                  var nameInstance = nameValue;
                  skuInstance.name = nameInstance;
                }
                
                var tierValue = skuValue['tier'];
                if (tierValue !== null && tierValue !== undefined) {
                  var tierInstance = tierValue;
                  skuInstance.tier = tierInstance;
                }
                
                var capacityValue = skuValue['capacity'];
                if (capacityValue !== null && capacityValue !== undefined) {
                  var capacityInstance = capacityValue;
                  skuInstance.capacity = capacityInstance;
                }
              }
            }
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceId The resource id.
     * 
     * @param {string} apiVersion The resource provider api version.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    SkuOperations.prototype.listSkuDefinitionsInternal = function(resourceId, apiVersion, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceId === null || resourceId === undefined) {
        return callback(new Error('resourceId cannot be null.'));
      }
      if (apiVersion === null || apiVersion === undefined) {
        return callback(new Error('apiVersion cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/';
      url2 = url2 + encodeURIComponent(resourceId);
      url2 = url2 + '/skuDefinitions';
      var queryParameters = [];
      queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'GET';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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 = { value: [] };
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
            var valueArray = responseDoc['value'];
            if (valueArray !== null && valueArray !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
                var valueValue = valueArray[loweredIndex1];
                var skuDefinitionInstance = {};
                result.value.push(skuDefinitionInstance);
                
                var skuValue = valueValue['sku'];
                if (skuValue !== null && skuValue !== undefined) {
                  var skuInstance = {};
                  skuDefinitionInstance.sku = skuInstance;
                  
                  var nameValue = skuValue['name'];
                  if (nameValue !== null && nameValue !== undefined) {
                    var nameInstance = nameValue;
                    skuInstance.name = nameInstance;
                  }
                  
                  var tierValue = skuValue['tier'];
                  if (tierValue !== null && tierValue !== undefined) {
                    var tierInstance = tierValue;
                    skuInstance.tier = tierInstance;
                  }
                }
                
                var capacityValue = valueValue['capacity'];
                if (capacityValue !== null && capacityValue !== undefined) {
                  var capacityInstance = {};
                  skuDefinitionInstance.capacity = capacityInstance;
                  
                  var minimumValue = capacityValue['minimum'];
                  if (minimumValue !== null && minimumValue !== undefined) {
                    var minimumInstance = minimumValue;
                    capacityInstance.minimum = minimumInstance;
                  }
                  
                  var maximumValue = capacityValue['maximum'];
                  if (maximumValue !== null && maximumValue !== undefined) {
                    var maximumInstance = maximumValue;
                    capacityInstance.maximum = maximumInstance;
                  }
                  
                  var defaultValue = capacityValue['default'];
                  if (defaultValue !== null && defaultValue !== undefined) {
                    var defaultInstance = defaultValue;
                    capacityInstance.default = defaultInstance;
                  }
                  
                  var scaleTypeValue = capacityValue['scaleType'];
                  if (scaleTypeValue !== null && scaleTypeValue !== undefined) {
                    var scaleTypeInstance = scaleTypeValue;
                    capacityInstance.scaleType = scaleTypeInstance;
                  }
                }
                
                var displayValue = valueValue['display'];
                if (displayValue !== null && displayValue !== undefined) {
                  var displayInstance = {};
                  skuDefinitionInstance.display = displayInstance;
                  
                  var titleValue = displayValue['title'];
                  if (titleValue !== null && titleValue !== undefined) {
                    var titleInstance = titleValue;
                    displayInstance.title = titleInstance;
                  }
                }
              }
            }
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceId
     * 
     * @param {AntaresSkuUpdateRequest} parameters
     * 
     * @param {string} [parameters.sku] Gets or sets the sku.
     * 
     * @param {number} [parameters.workerSize] Gets or sets the worker size
     * 
     * @param {number} [parameters.numberOfWorkers] Gets or sets the number of
     * workers
     * 
     * @param {string} apiVersion The resource provider api version.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    SkuOperations.prototype.updateAntaresCurrentSkuInternal = function(resourceId, parameters, apiVersion, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceId === null || resourceId === undefined) {
        return callback(new Error('resourceId cannot be null.'));
      }
      if (parameters === null || parameters === undefined) {
        return callback(new Error('parameters cannot be null.'));
      }
      if (apiVersion === null || apiVersion === undefined) {
        return callback(new Error('apiVersion cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/';
      url2 = url2 + encodeURIComponent(resourceId);
      var queryParameters = [];
      queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
      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 = 'PATCH';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // Serialize Request
      var requestContent = null;
      var requestDoc = null;
      
      var propertiesValue = {};
      requestDoc = propertiesValue;
      
      if (parameters.sku !== null && parameters.sku !== undefined) {
        propertiesValue['sku'] = parameters.sku;
      }
      
      if (parameters.workerSize !== null && parameters.workerSize !== undefined) {
        propertiesValue['workerSize'] = parameters.workerSize;
      }
      
      if (parameters.numberOfWorkers !== null && parameters.numberOfWorkers !== undefined) {
        propertiesValue['numberOfWorkers'] = parameters.numberOfWorkers;
      }
      
      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) {
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * 
     * @param {string} resourceId
     * 
     * @param {SkuUpdateParameters} parameters
     * 
     * @param {CurrentSku} [parameters.sku] Gets or sets the current sku.
     * 
     * @param {string} [parameters.sku.name] Gets or sets the name of the sku.
     * 
     * @param {string} [parameters.sku.tier] Gets or sets the tier of the sku.
     * 
     * @param {number} [parameters.sku.capacity] Gets or sets the current
     * capacity.
     * 
     * @param {string} apiVersion The resource provider api version.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    SkuOperations.prototype.updateCurrentSkuInternal = function(resourceId, parameters, apiVersion, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceId === null || resourceId === undefined) {
        return callback(new Error('resourceId cannot be null.'));
      }
      if (parameters === null || parameters === undefined) {
        return callback(new Error('parameters cannot be null.'));
      }
      if (apiVersion === null || apiVersion === undefined) {
        return callback(new Error('apiVersion cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/';
      url2 = url2 + encodeURIComponent(resourceId);
      var queryParameters = [];
      queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
      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 = 'PATCH';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // Serialize Request
      var requestContent = null;
      var requestDoc = null;
      
      var propertiesValue = {};
      requestDoc = propertiesValue;
      
      if (parameters.sku !== null && parameters.sku !== undefined) {
        var skuValue = {};
        propertiesValue['sku'] = skuValue;
        
        if (parameters.sku.name !== null && parameters.sku.name !== undefined) {
          skuValue['name'] = parameters.sku.name;
        }
        
        if (parameters.sku.tier !== null && parameters.sku.tier !== undefined) {
          skuValue['tier'] = parameters.sku.tier;
        }
        
        if (parameters.sku.capacity !== null && parameters.sku.capacity !== undefined) {
          skuValue['capacity'] = parameters.sku.capacity;
        }
      }
      
      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) {
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    return SkuOperations;
  })();
  
  var StorageDiagnosticSettingsOperations = ( /** @lends StorageDiagnosticSettingsOperations */ function() {
    /**
     * @class
     * Operations for managing storage diagnostic settings.
     * __NOTE__: An instance of this class is automatically created for an
     * instance of the [InsightsManagementClient] {@link
     * InsightsManagementClient~InsightsManagementClient}.
     * See [storageDiagnosticSettingsOperations] {@link
     * InsightsManagementClient~InsightsManagementClient#storageDiagnosticSettingsOperations}.
     * Initializes a new instance of the StorageDiagnosticSettingsOperations
     * class.
     * @constructor
     * 
     * @param {InsightsManagementClient} client Reference to the service client.
     */
    function StorageDiagnosticSettingsOperations(client) {
      this.client = client;
    }
    
    /**
     * Gets the diagnostic settings for the specified storage service.
     * 
     * @param {string} resourceUri The resource identifier of the storage service.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    StorageDiagnosticSettingsOperations.prototype.get = function(resourceUri, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceUri === null || resourceUri === undefined) {
        return callback(new Error('resourceUri cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/';
      url2 = url2 + encodeURIComponent(resourceUri);
      url2 = url2 + '/diagnosticSettings/storage';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'GET';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // 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 nameValue = responseDoc['name'];
            if (nameValue !== null && nameValue !== undefined) {
              var nameInstance = nameValue;
              result.name = nameInstance;
            }
            
            var locationValue = responseDoc['location'];
            if (locationValue !== null && locationValue !== undefined) {
              var locationInstance = locationValue;
              result.location = locationInstance;
            }
            
            var propertiesValue = responseDoc['properties'];
            if (propertiesValue !== null && propertiesValue !== undefined) {
              var propertiesInstance = {};
              result.properties = propertiesInstance;
              
              var loggingValue = propertiesValue['logging'];
              if (loggingValue !== null && loggingValue !== undefined) {
                var loggingInstance = {};
                propertiesInstance.loggingDiagnosticSettings = loggingInstance;
                
                var deleteValue = loggingValue['delete'];
                if (deleteValue !== null && deleteValue !== undefined) {
                  var deleteInstance = deleteValue;
                  loggingInstance.delete = deleteInstance;
                }
                
                var readValue = loggingValue['read'];
                if (readValue !== null && readValue !== undefined) {
                  var readInstance = readValue;
                  loggingInstance.read = readInstance;
                }
                
                var writeValue = loggingValue['write'];
                if (writeValue !== null && writeValue !== undefined) {
                  var writeInstance = writeValue;
                  loggingInstance.write = writeInstance;
                }
                
                var retentionValue = loggingValue['retention'];
                if (retentionValue !== null && retentionValue !== undefined) {
                  var retentionInstance = moment.duration(retentionValue);
                  loggingInstance.retention = retentionInstance;
                }
              }
              
              var metricsValue = propertiesValue['metrics'];
              if (metricsValue !== null && metricsValue !== undefined) {
                var metricsInstance = { metricAggregations: [] };
                propertiesInstance.metricDiagnosticSettings = metricsInstance;
                
                var aggregationsArray = metricsValue['aggregations'];
                if (aggregationsArray !== null && aggregationsArray !== undefined) {
                  for (var loweredIndex1 = 0; loweredIndex1 < aggregationsArray.length; loweredIndex1 = loweredIndex1 + 1) {
                    var aggregationsValue = aggregationsArray[loweredIndex1];
                    var storageMetricAggregationInstance = {};
                    metricsInstance.metricAggregations.push(storageMetricAggregationInstance);
                    
                    var scheduledTransferPeriodValue = aggregationsValue['scheduledTransferPeriod'];
                    if (scheduledTransferPeriodValue !== null && scheduledTransferPeriodValue !== undefined) {
                      var scheduledTransferPeriodInstance = moment.duration(scheduledTransferPeriodValue);
                      storageMetricAggregationInstance.scheduledTransferPeriod = scheduledTransferPeriodInstance;
                    }
                    
                    var retentionValue2 = aggregationsValue['retention'];
                    if (retentionValue2 !== null && retentionValue2 !== undefined) {
                      var retentionInstance2 = moment.duration(retentionValue2);
                      storageMetricAggregationInstance.retention = retentionInstance2;
                    }
                    
                    var levelValue = aggregationsValue['level'];
                    if (levelValue !== null && levelValue !== undefined) {
                      var levelInstance = levelValue;
                      storageMetricAggregationInstance.level = levelInstance;
                    }
                  }
                }
              }
            }
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    /**
     * Creates or update the diagnostic settings for the specified storage
     * service.
     * 
     * @param {string} resourceUri The resource identifier of the storage service.
     * 
     * @param {StorageDiagnosticSettingsPutParameters} parameters The storage
     * diagnostic settings parameters.
     * 
     * @param {StorageDiagnosticSettings} [parameters.properties] Gets or sets
     * the storage diagnostic settings.
     * 
     * @param {StorageLoggingDiagnosticSettings}
     * [parameters.properties.loggingDiagnosticSettings] Gets or sets the
     * logging diagnostic settings.
     * 
     * @param {boolean} [parameters.properties.loggingDiagnosticSettings.delete]
     * Gets or sets a value indicating whether delete operations should be
     * logged.
     * 
     * @param {boolean} [parameters.properties.loggingDiagnosticSettings.read]
     * Gets or sets a value indicating whether read operations should be logged.
     * 
     * @param {boolean} [parameters.properties.loggingDiagnosticSettings.write]
     * Gets or sets a value indicating whether write operations should be logged.
     * 
     * @param {TimeSpan}
     * [parameters.properties.loggingDiagnosticSettings.retention] Gets or sets
     * a value indicating whether retention operations should be logged.
     * 
     * @param {StorageMetricDiagnosticSettings}
     * [parameters.properties.metricDiagnosticSettings] Gets or sets the metrics
     * diagnostic settings.
     * 
     * @param {array}
     * [parameters.properties.metricDiagnosticSettings.metricAggregations] Gets
     * or sets the list of aggregations to generate.
     * 
     * @param {function} callback
     * 
     * @returns {Stream} The response stream.
     */
    StorageDiagnosticSettingsOperations.prototype.put = function(resourceUri, parameters, callback) {
      if (callback === null || callback === undefined) {
        throw new Error('callback cannot be null.');
      }
      // Validate
      if (resourceUri === null || resourceUri === undefined) {
        return callback(new Error('resourceUri cannot be null.'));
      }
      if (parameters === null || parameters === undefined) {
        return callback(new Error('parameters cannot be null.'));
      }
      
      // Tracing
      
      // Construct URL
      var url2 = '';
      url2 = url2 + '/';
      url2 = url2 + encodeURIComponent(resourceUri);
      url2 = url2 + '/diagnosticSettings/storage';
      var queryParameters = [];
      queryParameters.push('api-version=2014-04-01');
      if (queryParameters.length > 0) {
        url2 = url2 + '?' + queryParameters.join('&');
      }
      var baseUrl = this.client.baseUri;
      // Trim '/' character from the end of baseUrl and beginning of url.
      if (baseUrl[baseUrl.length - 1] === '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
      }
      if (url2[0] === '/') {
        url2 = url2.substring(1);
      }
      url2 = baseUrl + '/' + url2;
      url2 = url2.replace(' ', '%20');
      
      // Create HTTP transport objects
      var httpRequest = new WebResource();
      httpRequest.method = 'PUT';
      httpRequest.headers = {};
      httpRequest.url = url2;
      
      // Set Headers
      httpRequest.headers['Accept'] = 'application/json';
      httpRequest.headers['Content-Type'] = 'application/json';
      
      // Serialize Request
      var requestContent = null;
      var requestDoc = null;
      
      var storageDiagnosticSettingsPutParametersValue = {};
      requestDoc = storageDiagnosticSettingsPutParametersValue;
      
      if (parameters.properties !== null && parameters.properties !== undefined) {
        var propertiesValue = {};
        storageDiagnosticSettingsPutParametersValue['properties'] = propertiesValue;
        
        if (parameters.properties.loggingDiagnosticSettings !== null && parameters.properties.loggingDiagnosticSettings !== undefined) {
          var loggingValue = {};
          propertiesValue['logging'] = loggingValue;
          
          if (parameters.properties.loggingDiagnosticSettings.delete !== null && parameters.properties.loggingDiagnosticSettings.delete !== undefined) {
            loggingValue['delete'] = parameters.properties.loggingDiagnosticSettings.delete;
          }
          
          if (parameters.properties.loggingDiagnosticSettings.read !== null && parameters.properties.loggingDiagnosticSettings.read !== undefined) {
            loggingValue['read'] = parameters.properties.loggingDiagnosticSettings.read;
          }
          
          if (parameters.properties.loggingDiagnosticSettings.write !== null && parameters.properties.loggingDiagnosticSettings.write !== undefined) {
            loggingValue['write'] = parameters.properties.loggingDiagnosticSettings.write;
          }
          
          if (parameters.properties.loggingDiagnosticSettings.retention !== null && parameters.properties.loggingDiagnosticSettings.retention !== undefined) {
            loggingValue['retention'] = parameters.properties.loggingDiagnosticSettings.retention.toIsoString();
          }
        }
        
        if (parameters.properties.metricDiagnosticSettings !== null && parameters.properties.metricDiagnosticSettings !== undefined) {
          var metricsValue = {};
          propertiesValue['metrics'] = metricsValue;
          
          if (parameters.properties.metricDiagnosticSettings.metricAggregations !== null && parameters.properties.metricDiagnosticSettings.metricAggregations !== undefined) {
            var aggregationsArray = [];
            for (var loweredIndex1 = 0; loweredIndex1 < parameters.properties.metricDiagnosticSettings.metricAggregations.length; loweredIndex1 = loweredIndex1 + 1) {
              var aggregationsItem = parameters.properties.metricDiagnosticSettings.metricAggregations[loweredIndex1];
              var storageMetricAggregationValue = {};
              aggregationsArray.push(storageMetricAggregationValue);
              
              if (aggregationsItem.scheduledTransferPeriod !== null && aggregationsItem.scheduledTransferPeriod !== undefined) {
                storageMetricAggregationValue['scheduledTransferPeriod'] = aggregationsItem.scheduledTransferPeriod.toIsoString();
              }
              
              if (aggregationsItem.retention !== null && aggregationsItem.retention !== undefined) {
                storageMetricAggregationValue['retention'] = aggregationsItem.retention.toIsoString();
              }
              
              if (aggregationsItem.level !== null && aggregationsItem.level !== undefined) {
                storageMetricAggregationValue['level'] = aggregationsItem.level !== null && aggregationsItem.level !== undefined ? aggregationsItem.level.toString() : 'None';
              }
            }
            metricsValue['aggregations'] = aggregationsArray;
          }
        }
      }
      
      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 && statusCode !== 201 && statusCode !== 202) {
          var error = new Error(body);
          error.statusCode = response.statusCode;
          return callback(error);
        }
        
        // Create Result
        var result = null;
        // Deserialize Response
        if (statusCode === 200 || statusCode === 201 || statusCode === 202) {
          var responseContent = body;
          result = {};
          var responseDoc = null;
          if (responseContent) {
            responseDoc = JSON.parse(responseContent);
          }
          
          if (responseDoc !== null && responseDoc !== undefined) {
          }
          
        }
        result.statusCode = statusCode;
        result.requestId = response.headers['x-ms-request-id'];
        
        return callback(null, result);
      });
    };
    
    return StorageDiagnosticSettingsOperations;
  })();
  