/// <summary>
        /// Retrieve the Dsc node report list by node id and report id.  (see
        /// http://aka.ms/azureautomationsdk/dscnodereportoperations for more
        /// information)
        /// </summary>
        /// <param name='nextLink'>
        /// Required. The link to retrieve next set of items.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The response model for the list dsc nodes operation.
        /// </returns>
        public async Task <DscNodeReportListResponse> ListNextAsync(string nextLink, CancellationToken cancellationToken)
        {
            // Validate
            if (nextLink == null)
            {
                throw new ArgumentNullException("nextLink");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("nextLink", nextLink);
                TracingAdapter.Enter(invocationId, this, "ListNextAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + nextLink;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Get;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("Accept", "application/json");
                httpRequest.Headers.Add("ocp-referer", url);
                httpRequest.Headers.Add("x-ms-version", "2014-06-01");

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        TracingAdapter.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    DscNodeReportListResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new DscNodeReportListResponse();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            JToken valueArray = responseDoc["value"];
                            if (valueArray != null && valueArray.Type != JTokenType.Null)
                            {
                                foreach (JToken valueValue in ((JArray)valueArray))
                                {
                                    DscNodeReport dscNodeReportInstance = new DscNodeReport();
                                    result.NodeReports.Add(dscNodeReportInstance);

                                    JToken endTimeValue = valueValue["endTime"];
                                    if (endTimeValue != null && endTimeValue.Type != JTokenType.Null)
                                    {
                                        DateTimeOffset endTimeInstance = ((DateTimeOffset)endTimeValue);
                                        dscNodeReportInstance.EndTime = endTimeInstance;
                                    }

                                    JToken lastModifiedTimeValue = valueValue["lastModifiedTime"];
                                    if (lastModifiedTimeValue != null && lastModifiedTimeValue.Type != JTokenType.Null)
                                    {
                                        DateTimeOffset lastModifiedTimeInstance = ((DateTimeOffset)lastModifiedTimeValue);
                                        dscNodeReportInstance.LastModifiedTime = lastModifiedTimeInstance;
                                    }

                                    JToken startTimeValue = valueValue["startTime"];
                                    if (startTimeValue != null && startTimeValue.Type != JTokenType.Null)
                                    {
                                        DateTimeOffset startTimeInstance = ((DateTimeOffset)startTimeValue);
                                        dscNodeReportInstance.StartTime = startTimeInstance;
                                    }

                                    JToken typeValue = valueValue["type"];
                                    if (typeValue != null && typeValue.Type != JTokenType.Null)
                                    {
                                        string typeInstance = ((string)typeValue);
                                        dscNodeReportInstance.Type = typeInstance;
                                    }

                                    JToken idValue = valueValue["id"];
                                    if (idValue != null && idValue.Type != JTokenType.Null)
                                    {
                                        Guid idInstance = Guid.Parse(((string)idValue));
                                        dscNodeReportInstance.Id = idInstance;
                                    }

                                    JToken statusValue = valueValue["status"];
                                    if (statusValue != null && statusValue.Type != JTokenType.Null)
                                    {
                                        string statusInstance = ((string)statusValue);
                                        dscNodeReportInstance.Status = statusInstance;
                                    }

                                    JToken refreshModeValue = valueValue["refreshMode"];
                                    if (refreshModeValue != null && refreshModeValue.Type != JTokenType.Null)
                                    {
                                        string refreshModeInstance = ((string)refreshModeValue);
                                        dscNodeReportInstance.RefreshMode = refreshModeInstance;
                                    }

                                    JToken rebootRequestedValue = valueValue["rebootRequested"];
                                    if (rebootRequestedValue != null && rebootRequestedValue.Type != JTokenType.Null)
                                    {
                                        string rebootRequestedInstance = ((string)rebootRequestedValue);
                                        dscNodeReportInstance.RebootRequested = rebootRequestedInstance;
                                    }

                                    JToken reportFormatVersionValue = valueValue["reportFormatVersion"];
                                    if (reportFormatVersionValue != null && reportFormatVersionValue.Type != JTokenType.Null)
                                    {
                                        string reportFormatVersionInstance = ((string)reportFormatVersionValue);
                                        dscNodeReportInstance.ReportFormatVersion = reportFormatVersionInstance;
                                    }

                                    JToken configurationVersionValue = valueValue["configurationVersion"];
                                    if (configurationVersionValue != null && configurationVersionValue.Type != JTokenType.Null)
                                    {
                                        string configurationVersionInstance = ((string)configurationVersionValue);
                                        dscNodeReportInstance.ConfigurationVersion = configurationVersionInstance;
                                    }
                                }
                            }

                            JToken odatanextLinkValue = responseDoc["odata.nextLink"];
                            if (odatanextLinkValue != null && odatanextLinkValue.Type != JTokenType.Null)
                            {
                                string odatanextLinkInstance = Regex.Match(((string)odatanextLinkValue), "^.*[&\\?]\\$skiptoken=([^&]*)(&.*)?").Groups[1].Value;
                                result.SkipToken = odatanextLinkInstance;
                            }

                            JToken nextLinkValue = responseDoc["nextLink"];
                            if (nextLinkValue != null && nextLinkValue.Type != JTokenType.Null)
                            {
                                string nextLinkInstance = ((string)nextLinkValue);
                                result.NextLink = nextLinkInstance;
                            }
                        }
                    }
                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
        /// <summary>
        /// Retrieve the Dsc node report list by node id and report id.  (see
        /// http://aka.ms/azureautomationsdk/dscnodereportoperations for more
        /// information)
        /// </summary>
        /// <param name='resourceGroupName'>
        /// Required. The name of the resource group
        /// </param>
        /// <param name='automationAccount'>
        /// Required. The automation account name.
        /// </param>
        /// <param name='parameters'>
        /// Optional. The parameters supplied to the list operation.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The response model for the list dsc nodes operation.
        /// </returns>
        public async Task <DscNodeReportListResponse> ListAsync(string resourceGroupName, string automationAccount, DscNodeReportListParameters parameters, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException("resourceGroupName");
            }
            if (automationAccount == null)
            {
                throw new ArgumentNullException("automationAccount");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("resourceGroupName", resourceGroupName);
                tracingParameters.Add("automationAccount", automationAccount);
                tracingParameters.Add("parameters", parameters);
                TracingAdapter.Enter(invocationId, this, "ListAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/subscriptions/";
            if (this.Client.Credentials.SubscriptionId != null)
            {
                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
            }
            url = url + "/resourceGroups/";
            url = url + Uri.EscapeDataString(resourceGroupName);
            url = url + "/providers/";
            if (this.Client.ResourceNamespace != null)
            {
                url = url + Uri.EscapeDataString(this.Client.ResourceNamespace);
            }
            url = url + "/automationAccounts/";
            url = url + Uri.EscapeDataString(automationAccount);
            url = url + "/nodes/";
            if (parameters != null && parameters.NodeId != null)
            {
                url = url + Uri.EscapeDataString(parameters.NodeId.ToString());
            }
            url = url + "/reports";
            List <string> queryParameters = new List <string>();
            List <string> odataFilter     = new List <string>();

            if (parameters != null && parameters.StartTime != null)
            {
                odataFilter.Add("endTime ge " + Uri.EscapeDataString(parameters.StartTime));
            }
            if (parameters != null && parameters.EndTime != null)
            {
                odataFilter.Add("endTime le " + Uri.EscapeDataString(parameters.EndTime));
            }
            if (parameters != null && parameters.Type != null)
            {
                odataFilter.Add("type eq '" + Uri.EscapeDataString(parameters.Type) + "'");
            }
            if (odataFilter.Count > 0)
            {
                queryParameters.Add("$filter=" + string.Join(" and ", odataFilter));
            }
            queryParameters.Add("api-version=2015-01-01-preview");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Get;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("Accept", "application/json");
                httpRequest.Headers.Add("ocp-referer", url);
                httpRequest.Headers.Add("x-ms-version", "2014-06-01");

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        TracingAdapter.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    DscNodeReportListResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new DscNodeReportListResponse();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            JToken valueArray = responseDoc["value"];
                            if (valueArray != null && valueArray.Type != JTokenType.Null)
                            {
                                foreach (JToken valueValue in ((JArray)valueArray))
                                {
                                    DscNodeReport dscNodeReportInstance = new DscNodeReport();
                                    result.NodeReports.Add(dscNodeReportInstance);

                                    JToken endTimeValue = valueValue["endTime"];
                                    if (endTimeValue != null && endTimeValue.Type != JTokenType.Null)
                                    {
                                        DateTimeOffset endTimeInstance = ((DateTimeOffset)endTimeValue);
                                        dscNodeReportInstance.EndTime = endTimeInstance;
                                    }

                                    JToken lastModifiedTimeValue = valueValue["lastModifiedTime"];
                                    if (lastModifiedTimeValue != null && lastModifiedTimeValue.Type != JTokenType.Null)
                                    {
                                        DateTimeOffset lastModifiedTimeInstance = ((DateTimeOffset)lastModifiedTimeValue);
                                        dscNodeReportInstance.LastModifiedTime = lastModifiedTimeInstance;
                                    }

                                    JToken startTimeValue = valueValue["startTime"];
                                    if (startTimeValue != null && startTimeValue.Type != JTokenType.Null)
                                    {
                                        DateTimeOffset startTimeInstance = ((DateTimeOffset)startTimeValue);
                                        dscNodeReportInstance.StartTime = startTimeInstance;
                                    }

                                    JToken typeValue = valueValue["type"];
                                    if (typeValue != null && typeValue.Type != JTokenType.Null)
                                    {
                                        string typeInstance = ((string)typeValue);
                                        dscNodeReportInstance.Type = typeInstance;
                                    }

                                    JToken idValue = valueValue["id"];
                                    if (idValue != null && idValue.Type != JTokenType.Null)
                                    {
                                        Guid idInstance = Guid.Parse(((string)idValue));
                                        dscNodeReportInstance.Id = idInstance;
                                    }

                                    JToken statusValue = valueValue["status"];
                                    if (statusValue != null && statusValue.Type != JTokenType.Null)
                                    {
                                        string statusInstance = ((string)statusValue);
                                        dscNodeReportInstance.Status = statusInstance;
                                    }

                                    JToken refreshModeValue = valueValue["refreshMode"];
                                    if (refreshModeValue != null && refreshModeValue.Type != JTokenType.Null)
                                    {
                                        string refreshModeInstance = ((string)refreshModeValue);
                                        dscNodeReportInstance.RefreshMode = refreshModeInstance;
                                    }

                                    JToken rebootRequestedValue = valueValue["rebootRequested"];
                                    if (rebootRequestedValue != null && rebootRequestedValue.Type != JTokenType.Null)
                                    {
                                        string rebootRequestedInstance = ((string)rebootRequestedValue);
                                        dscNodeReportInstance.RebootRequested = rebootRequestedInstance;
                                    }

                                    JToken reportFormatVersionValue = valueValue["reportFormatVersion"];
                                    if (reportFormatVersionValue != null && reportFormatVersionValue.Type != JTokenType.Null)
                                    {
                                        string reportFormatVersionInstance = ((string)reportFormatVersionValue);
                                        dscNodeReportInstance.ReportFormatVersion = reportFormatVersionInstance;
                                    }

                                    JToken configurationVersionValue = valueValue["configurationVersion"];
                                    if (configurationVersionValue != null && configurationVersionValue.Type != JTokenType.Null)
                                    {
                                        string configurationVersionInstance = ((string)configurationVersionValue);
                                        dscNodeReportInstance.ConfigurationVersion = configurationVersionInstance;
                                    }
                                }
                            }

                            JToken odatanextLinkValue = responseDoc["odata.nextLink"];
                            if (odatanextLinkValue != null && odatanextLinkValue.Type != JTokenType.Null)
                            {
                                string odatanextLinkInstance = Regex.Match(((string)odatanextLinkValue), "^.*[&\\?]\\$skiptoken=([^&]*)(&.*)?").Groups[1].Value;
                                result.SkipToken = odatanextLinkInstance;
                            }

                            JToken nextLinkValue = responseDoc["nextLink"];
                            if (nextLinkValue != null && nextLinkValue.Type != JTokenType.Null)
                            {
                                string nextLinkInstance = ((string)nextLinkValue);
                                result.NextLink = nextLinkInstance;
                            }
                        }
                    }
                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }