/// <summary>
 /// Retrieve a list of stream items of the job identified by jobId.
 /// (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/XXXXXXX.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Automation.IJobStreamOperation.
 /// </param>
 /// <param name='automationAccount'>
 /// Required. The automation account name.
 /// </param>
 /// <param name='parameters'>
 /// Required. The parameters supplied to the list job stream's stream
 /// items operation.
 /// </param>
 /// <returns>
 /// The response model for the get job output operation.
 /// </returns>
 public static Task <JobStreamListStreamItemsResponse> ListStreamItemsAsync(this IJobStreamOperation operations, string automationAccount, JobStreamListStreamItemsParameters parameters)
 {
     return(operations.ListStreamItemsAsync(automationAccount, parameters, CancellationToken.None));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Retrieve a list of stream items of the job identified by jobId.
        /// (see
        /// http://msdn.microsoft.com/en-us/library/windowsazure/XXXXXXX.aspx
        /// for more information)
        /// </summary>
        /// <param name='automationAccount'>
        /// Required. The automation account name.
        /// </param>
        /// <param name='parameters'>
        /// Required. 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 get job output operation.
        /// </returns>
        public async Task <JobStreamListStreamItemsResponse> ListStreamItemsAsync(string automationAccount, JobStreamListStreamItemsParameters parameters, CancellationToken cancellationToken)
        {
            // Validate
            if (automationAccount == null)
            {
                throw new ArgumentNullException("automationAccount");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            if (parameters.JobId == null)
            {
                throw new ArgumentNullException("parameters.JobId");
            }
            if (parameters.StartTime == null)
            {
                throw new ArgumentNullException("parameters.StartTime");
            }

            // 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("parameters", parameters);
                TracingAdapter.Enter(invocationId, this, "ListStreamItemsAsync", 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/";
            url = url + "automation";
            url = url + "/~/Accounts/";
            url = url + Uri.EscapeDataString(automationAccount);
            url = url + "/JobStreams/GetStreamItems";
            List <string> queryParameters = new List <string>();

            queryParameters.Add("jobId='" + Uri.EscapeDataString(parameters.JobId) + "'");
            queryParameters.Add("streamsCreatedSinceDateTime='" + Uri.EscapeDataString(parameters.StartTime) + "'");
            List <string> odataFilter = new List <string>();

            if (parameters.StreamType != null)
            {
                odataFilter.Add("StreamTypeName eq '" + Uri.EscapeDataString(parameters.StreamType) + "'");
            }
            if (odataFilter.Count > 0)
            {
                queryParameters.Add("$filter=" + string.Join(null, odataFilter));
            }
            if (parameters.SkipToken != null)
            {
                queryParameters.Add("$skiptoken=" + Uri.EscapeDataString(parameters.SkipToken));
            }
            queryParameters.Add("api-version=2014-03-13_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("MaxDataServiceVersion", "3.0");
                httpRequest.Headers.Add("MinDataServiceVersion", "3.0");
                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
                    JobStreamListStreamItemsResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new JobStreamListStreamItemsResponse();
                        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))
                                {
                                    JobStreamItem jobStreamItemInstance = new JobStreamItem();
                                    result.JobStreamItems.Add(jobStreamItemInstance);

                                    JToken accountIdValue = valueValue["AccountId"];
                                    if (accountIdValue != null && accountIdValue.Type != JTokenType.Null)
                                    {
                                        string accountIdInstance = ((string)accountIdValue);
                                        jobStreamItemInstance.AccountId = accountIdInstance;
                                    }

                                    JToken jobIdValue = valueValue["JobId"];
                                    if (jobIdValue != null && jobIdValue.Type != JTokenType.Null)
                                    {
                                        string jobIdInstance = ((string)jobIdValue);
                                        jobStreamItemInstance.JobId = jobIdInstance;
                                    }

                                    JToken runbookVersionIdValue = valueValue["RunbookVersionId"];
                                    if (runbookVersionIdValue != null && runbookVersionIdValue.Type != JTokenType.Null)
                                    {
                                        string runbookVersionIdInstance = ((string)runbookVersionIdValue);
                                        jobStreamItemInstance.RunbookVersionId = runbookVersionIdInstance;
                                    }

                                    JToken streamTextValue = valueValue["StreamText"];
                                    if (streamTextValue != null && streamTextValue.Type != JTokenType.Null)
                                    {
                                        string streamTextInstance = ((string)streamTextValue);
                                        jobStreamItemInstance.Text = streamTextInstance;
                                    }

                                    JToken streamTimeValue = valueValue["StreamTime"];
                                    if (streamTimeValue != null && streamTimeValue.Type != JTokenType.Null)
                                    {
                                        DateTime streamTimeInstance = ((DateTime)streamTimeValue);
                                        jobStreamItemInstance.Time = streamTimeInstance;
                                    }

                                    JToken streamTypeNameValue = valueValue["StreamTypeName"];
                                    if (streamTypeNameValue != null && streamTypeNameValue.Type != JTokenType.Null)
                                    {
                                        string streamTypeNameInstance = ((string)streamTypeNameValue);
                                        jobStreamItemInstance.Type = streamTypeNameInstance;
                                    }
                                }
                            }

                            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();
                }
            }
        }
 /// <summary>
 /// Retrieve a list of stream items of the job identified by jobId.
 /// (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/XXXXXXX.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Automation.IJobStreamOperation.
 /// </param>
 /// <param name='automationAccount'>
 /// Required. The automation account name.
 /// </param>
 /// <param name='parameters'>
 /// Required. The parameters supplied to the list job stream's stream
 /// items operation.
 /// </param>
 /// <returns>
 /// The response model for the get job output operation.
 /// </returns>
 public static JobStreamListStreamItemsResponse ListStreamItems(this IJobStreamOperation operations, string automationAccount, JobStreamListStreamItemsParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IJobStreamOperation)s).ListStreamItemsAsync(automationAccount, parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }