/// <summary> /// Retrieve a list of watcher streams identified by watcher name. /// (see http://aka.ms/azureautomationsdk/watcherstreamoperations for /// more information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.Automation.IWatcherStreamOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group. /// </param> /// <param name='automationAccount'> /// Required. The automation account name. /// </param> /// <param name='watcherName'> /// Required. The watcher name. /// </param> /// <param name='parameters'> /// Optional. The parameters supplied to the list watcher's stream /// items operation. /// </param> /// <returns> /// The response model for the list watcher stream operation. /// </returns> public static WatcherStreamListResponse List(this IWatcherStreamOperations operations, string resourceGroupName, string automationAccount, string watcherName, WatcherStreamListParameters parameters) { return(Task.Factory.StartNew((object s) => { return ((IWatcherStreamOperations)s).ListAsync(resourceGroupName, automationAccount, watcherName, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Retrieve a list of watcher streams identified by watcher name. /// (see http://aka.ms/azureautomationsdk/watcherstreamoperations for /// more information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.Automation.IWatcherStreamOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group. /// </param> /// <param name='automationAccount'> /// Required. The automation account name. /// </param> /// <param name='watcherName'> /// Required. The watcher name. /// </param> /// <param name='parameters'> /// Optional. The parameters supplied to the list watcher's stream /// items operation. /// </param> /// <returns> /// The response model for the list watcher stream operation. /// </returns> public static Task <WatcherStreamListResponse> ListAsync(this IWatcherStreamOperations operations, string resourceGroupName, string automationAccount, string watcherName, WatcherStreamListParameters parameters) { return(operations.ListAsync(resourceGroupName, automationAccount, watcherName, parameters, CancellationToken.None)); }
/// <summary> /// Retrieve a list of watcher streams identified by watcher name. /// (see http://aka.ms/azureautomationsdk/watcherstreamoperations 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='watcherName'> /// Required. The watcher name. /// </param> /// <param name='parameters'> /// Optional. The parameters supplied to the list watcher's stream /// items operation. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The response model for the list watcher stream operation. /// </returns> public async Task <WatcherStreamListResponse> ListAsync(string resourceGroupName, string automationAccount, string watcherName, WatcherStreamListParameters parameters, CancellationToken cancellationToken) { // Validate if (resourceGroupName == null) { throw new ArgumentNullException("resourceGroupName"); } if (automationAccount == null) { throw new ArgumentNullException("automationAccount"); } if (watcherName == null) { throw new ArgumentNullException("watcherName"); } // 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("watcherName", watcherName); 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 + "/watchers/"; url = url + Uri.EscapeDataString(watcherName); url = url + "/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=2017-05-15-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 WatcherStreamListResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new WatcherStreamListResponse(); 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)) { WatcherStream watcherStreamInstance = new WatcherStream(); result.WatcherStreams.Add(watcherStreamInstance); JToken idValue = valueValue["id"]; if (idValue != null && idValue.Type != JTokenType.Null) { string idInstance = ((string)idValue); watcherStreamInstance.Id = idInstance; } JToken propertiesValue = valueValue["properties"]; if (propertiesValue != null && propertiesValue.Type != JTokenType.Null) { WatcherStreamProperties propertiesInstance = new WatcherStreamProperties(); watcherStreamInstance.Properties = propertiesInstance; JToken watcherStreamIdValue = propertiesValue["watcherStreamId"]; if (watcherStreamIdValue != null && watcherStreamIdValue.Type != JTokenType.Null) { string watcherStreamIdInstance = ((string)watcherStreamIdValue); propertiesInstance.WatcherStreamId = watcherStreamIdInstance; } 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 = property.Value.ToString(Newtonsoft.Json.Formatting.Indented); propertiesInstance.Value.Add(valueKey, valueValue2); } } } } } 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(); } } }