private async Task checkTestJob()
        {
            TestJobGetResponse response = await iseClient.automationManagementClient.TestJobs.GetAsync(iseClient.accountResourceGroups[iseClient.currAccount].Name,
                                                                                                       iseClient.currAccount.Name, runbookName, new System.Threading.CancellationToken());

            JobDetails.Content  = runbookName + " test job created at " + response.TestJob.CreationTime.LocalDateTime;
            JobDetails.Content += "\r\nLast refreshed at " + DateTime.Now;
            JobStatus.Content   = response.TestJob.Status;
            if (response.TestJob.Status == "Failed")
            {
                updateJobOutputTextBlockWithException(response.TestJob.Exception);
            }
            else
            {
                JobStreamListResponse jslResponse = await iseClient.automationManagementClient.JobStreams.ListTestJobStreamsAsync(iseClient.accountResourceGroups[iseClient.currAccount].Name,
                                                                                                                                  iseClient.currAccount.Name, runbookName, null, new System.Threading.CancellationToken());

                /* Write out each stream's output */
                foreach (JobStream stream in jslResponse.JobStreams)
                {
                    var jslStream = await iseClient.automationManagementClient.JobStreams.GetTestJobStreamAsync(iseClient.accountResourceGroups[iseClient.currAccount].Name,
                                                                                                                iseClient.currAccount.Name, runbookName, stream.Properties.JobStreamId, new System.Threading.CancellationToken());

                    updateJobOutputTextBlock(jslStream);
                }
                if (response.TestJob.Status == "Suspended")
                {
                    updateJobOutputTextBlockWithException(response.TestJob.Exception);
                }
            }
        }
        private async Task checkJob()
        {
            CancellationTokenSource cts = new CancellationTokenSource();

            cts.CancelAfter(TIMEOUT_MS);
            JobGetResponse response = await iseClient.automationManagementClient.Jobs.GetAsync(iseClient.accountResourceGroups[iseClient.currAccount].Name,
                                                                                               iseClient.currAccount.Name, jobCreateResponse.Job.Properties.JobId, cts.Token);

            JobDetails.Content  = runbookName + " test job created at " + response.Job.Properties.CreationTime.LocalDateTime;
            JobDetails.Content += "\r\nLast refreshed at " + DateTime.Now;
            JobStatus.Content   = response.Job.Properties.Status;

            cts = new CancellationTokenSource();
            cts.CancelAfter(TIMEOUT_MS);
            JobStreamListResponse jslResponse = await iseClient.automationManagementClient.JobStreams.ListAsync(iseClient.accountResourceGroups[iseClient.currAccount].Name,
                                                                                                                iseClient.currAccount.Name, jobCreateResponse.Job.Properties.JobId, jobParams, cts.Token);

            foreach (JobStream stream in jslResponse.JobStreams)
            {
                cts = new CancellationTokenSource();
                cts.CancelAfter(TIMEOUT_MS);
                var jslStream = await iseClient.automationManagementClient.JobStreams.GetAsync(iseClient.accountResourceGroups[iseClient.currAccount].Name,
                                                                                               iseClient.currAccount.Name, jobCreateResponse.Job.Properties.JobId, stream.Properties.JobStreamId, cts.Token);

                if (jslStream.JobStream.Properties.Time.DateTime > Convert.ToDateTime(jobParams.Time))
                {
                    jobParams.Time = stream.Properties.Time.ToString("o");
                    updateJobOutputTextBlock(jslStream);
                }
            }
            refreshTimer.Enabled = true;
        }
        private async Task checkJob()
        {
            JobGetResponse response = await iseClient.automationManagementClient.Jobs.GetAsync(iseClient.accountResourceGroups[iseClient.currAccount].Name,
                                                                                               iseClient.currAccount.Name, jobCreateResponse.Job.Properties.JobId, new System.Threading.CancellationToken());

            JobDetails.Content  = runbookName + " test job created at " + response.Job.Properties.CreationTime.LocalDateTime;
            JobDetails.Content += "\r\nLast refreshed at " + DateTime.Now;
            JobStatus.Content   = response.Job.Properties.Status;

            JobStreamListResponse jslResponse = await iseClient.automationManagementClient.JobStreams.ListAsync(iseClient.accountResourceGroups[iseClient.currAccount].Name,
                                                                                                                iseClient.currAccount.Name, jobCreateResponse.Job.Properties.JobId, null, new System.Threading.CancellationToken());

            foreach (JobStream stream in jslResponse.JobStreams)
            {
                var jslStream = await iseClient.automationManagementClient.JobStreams.GetAsync(iseClient.accountResourceGroups[iseClient.currAccount].Name,
                                                                                               iseClient.currAccount.Name, jobCreateResponse.Job.Properties.JobId, stream.Properties.JobStreamId, new System.Threading.CancellationToken());

                updateJobOutputTextBlock(jslStream);
            }
        }
        private async Task checkTestJob(bool showWarning = false)
        {
            CancellationTokenSource cts = new CancellationTokenSource();

            cts.CancelAfter(TIMEOUT_MS);
            TestJobGetResponse response = await iseClient.automationManagementClient.TestJobs.GetAsync(iseClient.accountResourceGroups[iseClient.currAccount].Name,
                                                                                                       iseClient.currAccount.Name, runbookName, cts.Token);

            // Set cancel output to false so we show the output of this job
            cancelOutput = false;
            if (showWarning)
            {
                JobDetails.FontWeight = FontWeights.Bold;
                JobDetails.Content    = "This is a past test job for " + runbookName + " created at " + response.TestJob.CreationTime.LocalDateTime;
            }
            else
            {
                JobDetails.FontWeight = FontWeights.Normal;
                JobDetails.Content    = runbookName + " test job created at " + response.TestJob.CreationTime.LocalDateTime;
            }
            JobDetails.Content += "\r\nLast refreshed at " + DateTime.Now;
            JobStatus.Content   = response.TestJob.Status;
            if (response.TestJob.Status == "Failed")
            {
                updateJobOutputTextBlockWithException(response.TestJob.Exception);
                StartJobButton.IsEnabled = true;
                StopJobButton.IsEnabled  = false;
            }
            else
            {
                cts = new CancellationTokenSource();
                cts.CancelAfter(TIMEOUT_MS);
                JobStreamListResponse jslResponse = await iseClient.automationManagementClient.JobStreams.ListTestJobStreamsAsync(iseClient.accountResourceGroups[iseClient.currAccount].Name,
                                                                                                                                  iseClient.currAccount.Name, runbookName, jobParams, cts.Token);

                if (jslResponse.JobStreams.Count > 0)
                {
                    jobParams.Time = jslResponse.JobStreams.Last().Properties.Time.UtcDateTime.ToString("o");
                }

                /* Write out each stream's output */
                foreach (JobStream stream in jslResponse.JobStreams)
                {
                    // If cancelOutput is set to true, then we should break out and stop writing output
                    if (cancelOutput)
                    {
                        break;
                    }
                    cts = new CancellationTokenSource();
                    cts.CancelAfter(TIMEOUT_MS);
                    var jslStream = await iseClient.automationManagementClient.JobStreams.GetTestJobStreamAsync(iseClient.accountResourceGroups[iseClient.currAccount].Name,
                                                                                                                iseClient.currAccount.Name, runbookName, stream.Properties.JobStreamId, cts.Token);

                    // Current issue sending back previous streams so ensuring we have not already processed the job before outputing
                    if ((processedStreamIDs.IndexOf(stream.Properties.JobStreamId) == -1))
                    {
                        processedStreamIDs.Add(stream.Properties.JobStreamId);
                        updateJobOutputTextBlock(jslStream);
                    }
                }
                if (response.TestJob.Status == "Suspended")
                {
                    updateJobOutputTextBlockWithException(response.TestJob.Exception);
                    StartJobButton.IsEnabled = false;
                    StopJobButton.IsEnabled  = true;
                }
                else if (response.TestJob.Status == "Completed")
                {
                    StartJobButton.IsEnabled = true;
                    StopJobButton.IsEnabled  = false;
                }
                else if (response.TestJob.Status == "Stopped")
                {
                    StartJobButton.IsEnabled = true;
                    StopJobButton.IsEnabled  = false;
                }
                else if (!IsRetryStatusCode(response.StatusCode))
                {
                    StartJobButton.IsEnabled = true;
                    StopJobButton.IsEnabled  = false;
                }
                else
                {
                    StartJobButton.IsEnabled = false;
                    StopJobButton.IsEnabled  = true;
                    refreshTimer.Enabled     = true;
                }
            }
        }
        private async Task checkCompilationJob(bool showPreviousJobOutput = false)
        {
            CancellationTokenSource cts = new CancellationTokenSource();

            cts.CancelAfter(TIMEOUT_MS);

            if (showPreviousJobOutput)
            {
                DscCompilationJobListParameters jobParams = new DscCompilationJobListParameters();

                jobParams.ConfigurationName = configurationName;
                // Look for jobs compiled in the last hour so we can show the status of the last job and also the paramaters
                jobParams.StartTime = DateTime.Now.AddMinutes(-60).ToString("o");

                DscCompilationJobListResponse listResponse = await iseClient.automationManagementClient.CompilationJobs.ListAsync(iseClient.accountResourceGroups[iseClient.currAccount].Name,
                                                                                                                                  iseClient.currAccount.Name, jobParams, cts.Token);

                if (listResponse.DscCompilationJobs.Count > 0)
                {
                    lastJobID = listResponse.DscCompilationJobs.LastOrDefault().Properties.JobId;
                }
                else
                {
                    return;
                }
            }

            DscCompilationJobGetResponse response = await iseClient.automationManagementClient.CompilationJobs.GetAsync(iseClient.accountResourceGroups[iseClient.currAccount].Name,
                                                                                                                        iseClient.currAccount.Name, lastJobID, cts.Token);

            // Set cancel output to false so we show the output of this job
            cancelOutput          = false;
            JobDetails.FontWeight = FontWeights.Normal;
            JobDetails.Content    = configurationName + " compilation job created at " + response.DscCompilationJob.Properties.CreationTime.LocalDateTime;
            JobDetails.Content   += "\r\nLast refreshed at " + DateTime.Now;
            JobStatus.Content     = response.DscCompilationJob.Properties.Status;
            if (response.DscCompilationJob.Properties.Status == "Failed")
            {
                updateJobOutputTextBlockWithException(response.DscCompilationJob.Properties.Exception);
                CompileConfigurationButton.IsEnabled = true;
            }
            else if (response.DscCompilationJob.Properties.Status == "Suspended")
            {
                updateJobOutputTextBlockWithException(response.DscCompilationJob.Properties.Exception);
                CompileConfigurationButton.IsEnabled = true;
            }
            else
            {
                cts = new CancellationTokenSource();
                cts.CancelAfter(TIMEOUT_MS);
                JobStreamListResponse jslResponse = await iseClient.automationManagementClient.JobStreams.ListAsync(iseClient.accountResourceGroups[iseClient.currAccount].Name,
                                                                                                                    iseClient.currAccount.Name, lastJobID, jobStreamParams, cts.Token);

                if (jslResponse.JobStreams.Count > 0)
                {
                    jobStreamParams.Time = jslResponse.JobStreams.Last().Properties.Time.UtcDateTime.ToString("o");
                }

                /* Write out each stream's output */
                foreach (JobStream stream in jslResponse.JobStreams)
                {
                    // If cancelOutput is set to true, then we should break out and stop writing output
                    if (cancelOutput)
                    {
                        break;
                    }
                    cts = new CancellationTokenSource();
                    cts.CancelAfter(TIMEOUT_MS);
                    var jslStream = await iseClient.automationManagementClient.JobStreams.GetAsync(iseClient.accountResourceGroups[iseClient.currAccount].Name,
                                                                                                   iseClient.currAccount.Name, lastJobID, stream.Properties.JobStreamId, cts.Token);

                    // Current issue sending back previous streams so ensuring we have not already processed the job before outputing
                    if ((processedStreamIDs.IndexOf(stream.Properties.JobStreamId) == -1))
                    {
                        processedStreamIDs.Add(stream.Properties.JobStreamId);
                        updateJobOutputTextBlock(jslStream);
                    }
                }
                if (response.DscCompilationJob.Properties.Status == "Completed")
                {
                    CompileConfigurationButton.IsEnabled = true;
                }
                else if (response.DscCompilationJob.Properties.Status == "Stopped")
                {
                    CompileConfigurationButton.IsEnabled = true;
                }
                else if (!IsRetryStatusCode(response.StatusCode))
                {
                    CompileConfigurationButton.IsEnabled = true;
                }
                else
                {
                    CompileConfigurationButton.IsEnabled = false;
                    refreshTimer.Enabled = true;
                }
            }
        }
Ejemplo n.º 6
0
        private async Task checkTestJob(bool showWarning = false)
        {
            CancellationTokenSource cts = new CancellationTokenSource();

            cts.CancelAfter(TIMEOUT_MS);
            TestJobGetResponse response = await iseClient.automationManagementClient.TestJobs.GetAsync(iseClient.accountResourceGroups[iseClient.currAccount].Name,
                                                                                                       iseClient.currAccount.Name, runbookName, cts.Token);

            if (showWarning)
            {
                JobDetails.FontWeight = FontWeights.Bold;
                JobDetails.Content    = "This is a past test job for " + runbookName + " created at " + response.TestJob.CreationTime.LocalDateTime;
            }
            else
            {
                JobDetails.FontWeight = FontWeights.Normal;
                JobDetails.Content    = runbookName + " test job created at " + response.TestJob.CreationTime.LocalDateTime;
            }
            JobDetails.Content += "\r\nLast refreshed at " + DateTime.Now;
            JobStatus.Content   = response.TestJob.Status;
            if (response.TestJob.Status == "Failed")
            {
                updateJobOutputTextBlockWithException(response.TestJob.Exception);
                StartJobButton.IsEnabled = true;
                refreshTimer.Stop();
            }
            else
            {
                cts = new CancellationTokenSource();
                cts.CancelAfter(TIMEOUT_MS);
                JobStreamListResponse jslResponse = await iseClient.automationManagementClient.JobStreams.ListTestJobStreamsAsync(iseClient.accountResourceGroups[iseClient.currAccount].Name,
                                                                                                                                  iseClient.currAccount.Name, runbookName, null, cts.Token);

                /* Write out each stream's output */
                foreach (JobStream stream in jslResponse.JobStreams)
                {
                    cts = new CancellationTokenSource();
                    cts.CancelAfter(TIMEOUT_MS);
                    var jslStream = await iseClient.automationManagementClient.JobStreams.GetTestJobStreamAsync(iseClient.accountResourceGroups[iseClient.currAccount].Name,
                                                                                                                iseClient.currAccount.Name, runbookName, stream.Properties.JobStreamId, cts.Token);

                    updateJobOutputTextBlock(jslStream);
                }
                if (response.TestJob.Status == "Suspended")
                {
                    updateJobOutputTextBlockWithException(response.TestJob.Exception);
                    StartJobButton.IsEnabled = false;
                    refreshTimer.Stop();
                }
                else if (response.TestJob.Status == "Completed")
                {
                    StartJobButton.IsEnabled = true;
                    refreshTimer.Stop();
                }
                else if (response.TestJob.Status == "Stopped")
                {
                    StartJobButton.IsEnabled = true;
                }
                else
                {
                    StartJobButton.IsEnabled = false;
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Retrieve a list of test job streams identified by runbook name.
        /// (see http://aka.ms/azureautomationsdk/jobstreamoperations for
        /// more information)
        /// </summary>
        /// <param name='automationAccount'>
        /// Required. The automation account name.
        /// </param>
        /// <param name='runbookName'>
        /// Required. The runbook name.
        /// </param>
        /// <param name='parameters'>
        /// Optional. The parameters supplied to the list job stream's stream
        /// items operation.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The response model for the list job stream operation.
        /// </returns>
        public async Task <JobStreamListResponse> ListTestJobStreamsAsync(string automationAccount, string runbookName, JobStreamListParameters parameters, CancellationToken cancellationToken)
        {
            // Validate
            if (automationAccount == null)
            {
                throw new ArgumentNullException("automationAccount");
            }
            if (runbookName == null)
            {
                throw new ArgumentNullException("runbookName");
            }

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

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

            // Construct URL
            string url = "";

            url = url + "/";
            if (this.Client.Credentials.SubscriptionId != null)
            {
                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
            }
            url = url + "/cloudservices/OaaSCS/resources/";
            if (this.Client.ResourceNamespace != null)
            {
                url = url + Uri.EscapeDataString(this.Client.ResourceNamespace);
            }
            url = url + "/~/automationAccounts/";
            url = url + Uri.EscapeDataString(automationAccount);
            url = url + "/runbooks/";
            url = url + Uri.EscapeDataString(runbookName);
            url = url + "/draft/testJob/streams";
            List <string> queryParameters = new List <string>();
            List <string> odataFilter     = new List <string>();

            if (parameters != null && parameters.Time != null)
            {
                odataFilter.Add("properties/time ge " + Uri.EscapeDataString(parameters.Time));
            }
            if (parameters != null && parameters.StreamType != null)
            {
                odataFilter.Add("properties/streamType eq '" + Uri.EscapeDataString(parameters.StreamType) + "'");
            }
            if (odataFilter.Count > 0)
            {
                queryParameters.Add("$filter=" + string.Join(" and ", odataFilter));
            }
            queryParameters.Add("api-version=2014-12-08");
            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", "2013-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
                    JobStreamListResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new JobStreamListResponse();
                        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))
                                {
                                    JobStream jobStreamInstance = new JobStream();
                                    result.JobStreams.Add(jobStreamInstance);

                                    JToken propertiesValue = valueValue["properties"];
                                    if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
                                    {
                                        JobStreamProperties propertiesInstance = new JobStreamProperties();
                                        jobStreamInstance.Properties = propertiesInstance;

                                        JToken jobStreamIdValue = propertiesValue["jobStreamId"];
                                        if (jobStreamIdValue != null && jobStreamIdValue.Type != JTokenType.Null)
                                        {
                                            string jobStreamIdInstance = ((string)jobStreamIdValue);
                                            propertiesInstance.JobStreamId = jobStreamIdInstance;
                                        }

                                        JToken timeValue = propertiesValue["time"];
                                        if (timeValue != null && timeValue.Type != JTokenType.Null)
                                        {
                                            DateTimeOffset timeInstance = ((DateTimeOffset)timeValue);
                                            propertiesInstance.Time = timeInstance;
                                        }

                                        JToken streamTypeValue = propertiesValue["streamType"];
                                        if (streamTypeValue != null && streamTypeValue.Type != JTokenType.Null)
                                        {
                                            string streamTypeInstance = ((string)streamTypeValue);
                                            propertiesInstance.StreamType = streamTypeInstance;
                                        }

                                        JToken streamTextValue = propertiesValue["streamText"];
                                        if (streamTextValue != null && streamTextValue.Type != JTokenType.Null)
                                        {
                                            string streamTextInstance = ((string)streamTextValue);
                                            propertiesInstance.StreamText = streamTextInstance;
                                        }

                                        JToken summaryValue = propertiesValue["summary"];
                                        if (summaryValue != null && summaryValue.Type != JTokenType.Null)
                                        {
                                            string summaryInstance = ((string)summaryValue);
                                            propertiesInstance.Summary = summaryInstance;
                                        }

                                        JToken valueSequenceElement = ((JToken)propertiesValue["value"]);
                                        if (valueSequenceElement != null && valueSequenceElement.Type != JTokenType.Null)
                                        {
                                            foreach (JProperty property in valueSequenceElement)
                                            {
                                                string valueKey    = ((string)property.Name);
                                                object valueValue2 = ((string)property.Value);
                                                propertiesInstance.Value.Add(valueKey, valueValue2);
                                            }
                                        }
                                    }
                                }
                            }

                            JToken nextLinkValue = responseDoc["nextLink"];
                            if (nextLinkValue != null && nextLinkValue.Type != JTokenType.Null)
                            {
                                string nextLinkInstance = ((string)nextLinkValue);
                                result.NextLink = nextLinkInstance;
                            }

                            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;
                            }
                        }
                    }
                    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();
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the next page of job streams using next link.
        /// </summary>
        /// <param name='nextLink'>
        /// Required. NextLink from the previous successful call to List
        /// operation.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The response model for the list job stream operation.
        /// </returns>
        public async Task <JobStreamListResponse> 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 + Uri.EscapeDataString(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", "2013-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
                    JobStreamListResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new JobStreamListResponse();
                        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))
                                {
                                    JobStream jobStreamInstance = new JobStream();
                                    result.JobStreams.Add(jobStreamInstance);

                                    JToken propertiesValue = valueValue["properties"];
                                    if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
                                    {
                                        JobStreamProperties propertiesInstance = new JobStreamProperties();
                                        jobStreamInstance.Properties = propertiesInstance;

                                        JToken jobStreamIdValue = propertiesValue["jobStreamId"];
                                        if (jobStreamIdValue != null && jobStreamIdValue.Type != JTokenType.Null)
                                        {
                                            string jobStreamIdInstance = ((string)jobStreamIdValue);
                                            propertiesInstance.JobStreamId = jobStreamIdInstance;
                                        }

                                        JToken timeValue = propertiesValue["time"];
                                        if (timeValue != null && timeValue.Type != JTokenType.Null)
                                        {
                                            DateTimeOffset timeInstance = ((DateTimeOffset)timeValue);
                                            propertiesInstance.Time = timeInstance;
                                        }

                                        JToken streamTypeValue = propertiesValue["streamType"];
                                        if (streamTypeValue != null && streamTypeValue.Type != JTokenType.Null)
                                        {
                                            string streamTypeInstance = ((string)streamTypeValue);
                                            propertiesInstance.StreamType = streamTypeInstance;
                                        }

                                        JToken streamTextValue = propertiesValue["streamText"];
                                        if (streamTextValue != null && streamTextValue.Type != JTokenType.Null)
                                        {
                                            string streamTextInstance = ((string)streamTextValue);
                                            propertiesInstance.StreamText = streamTextInstance;
                                        }

                                        JToken summaryValue = propertiesValue["summary"];
                                        if (summaryValue != null && summaryValue.Type != JTokenType.Null)
                                        {
                                            string summaryInstance = ((string)summaryValue);
                                            propertiesInstance.Summary = summaryInstance;
                                        }

                                        JToken valueSequenceElement = ((JToken)propertiesValue["value"]);
                                        if (valueSequenceElement != null && valueSequenceElement.Type != JTokenType.Null)
                                        {
                                            foreach (JProperty property in valueSequenceElement)
                                            {
                                                string valueKey    = ((string)property.Name);
                                                object valueValue2 = ((string)property.Value);
                                                propertiesInstance.Value.Add(valueKey, valueValue2);
                                            }
                                        }
                                    }
                                }
                            }

                            JToken nextLinkValue = responseDoc["nextLink"];
                            if (nextLinkValue != null && nextLinkValue.Type != JTokenType.Null)
                            {
                                string nextLinkInstance = ((string)nextLinkValue);
                                result.NextLink = nextLinkInstance;
                            }

                            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;
                            }
                        }
                    }
                    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();
                }
            }
        }