private void updateJobOutputTextBlock(JobStreamGetResponse stream)
        {
            String streamText = stream.JobStream.Properties.StreamText;

            OutputTextBlockParagraph.Inlines.Add("\r\n");
            if (stream.JobStream.Properties.StreamType == "Output")
            {
                OutputTextBlockParagraph.Inlines.Add(streamText);
            }
            else if (stream.JobStream.Properties.StreamType == "Verbose")
            {
                streamText = "VERBOSE: " + streamText;
                OutputTextBlockParagraph.Inlines.Add(new Run(streamText)
                {
                    Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom(VerboseForegroundColorCode)),
                    Background = (SolidColorBrush)(new BrushConverter().ConvertFrom(VerboseBackgroundColorCode))
                });
            }
            else if (stream.JobStream.Properties.StreamType == "Error")
            {
                streamText = "ERROR: " + streamText;
                OutputTextBlockParagraph.Inlines.Add(new Run(streamText)
                {
                    Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom(ErrorForegroundColorCode)),
                    Background = (SolidColorBrush)(new BrushConverter().ConvertFrom(ErrorBackgroundColorCode))
                });
            }
            else if (stream.JobStream.Properties.StreamType == "Warning")
            {
                streamText = "WARNING: " + streamText;
                OutputTextBlockParagraph.Inlines.Add(new Run(streamText)
                {
                    Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom(WarningForegroundColorCode)),
                    Background = (SolidColorBrush)(new BrushConverter().ConvertFrom(WarningBackgroundColorCode))
                });
            }
            else
            {
                Debug.WriteLine("Unknown stream type couldn't be colored properly: " + stream.JobStream.Properties.StreamType);
                OutputTextBlockParagraph.Inlines.Add(stream.JobStream.Properties.StreamType.ToUpper() + ":  " + streamText);
            }
            OutputTextBlock.ScrollToEnd();
        }
Пример #2
0
        /// <summary>
        /// Retrieve the job stream identified by job stream id.  (see
        /// http://aka.ms/azureautomationsdk/jobstreamoperations for more
        /// information)
        /// </summary>
        /// <param name='automationAccount'>
        /// Required. The automation account name.
        /// </param>
        /// <param name='jobId'>
        /// Required. The job id.
        /// </param>
        /// <param name='jobStreamId'>
        /// Required. The job stream id.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The response model for the get job stream operation.
        /// </returns>
        public async Task <JobStreamGetResponse> GetAsync(string automationAccount, Guid jobId, string jobStreamId, CancellationToken cancellationToken)
        {
            // Validate
            if (automationAccount == null)
            {
                throw new ArgumentNullException("automationAccount");
            }
            if (jobStreamId == null)
            {
                throw new ArgumentNullException("jobStreamId");
            }

            // 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("jobId", jobId);
                tracingParameters.Add("jobStreamId", jobStreamId);
                TracingAdapter.Enter(invocationId, this, "GetAsync", 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 + "/Jobs/";
            url = url + Uri.EscapeDataString(jobId.ToString());
            url = url + "/streams/";
            url = url + Uri.EscapeDataString(jobStreamId);
            List <string> queryParameters = new List <string>();

            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("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
                    JobStreamGetResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

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

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            JobStream jobStreamInstance = new JobStream();
                            result.JobStream = jobStreamInstance;

                            JToken propertiesValue = responseDoc["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 valueValue = ((string)property.Value);
                                        propertiesInstance.Value.Add(valueKey, valueValue);
                                    }
                                }
                            }
                        }
                    }
                    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();
                }
            }
        }