/// <summary> /// The List Subscription Operations operation returns a list of /// create, update, and delete operations that were performed on a /// subscription during the specified timeframe. (see /// http://msdn.microsoft.com/en-us/library/windowsazure/gg715318.aspx /// for more information) /// </summary> /// <param name='parameters'> /// Required. Parameters supplied to the List Subscription Operations /// operation. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The List Subscription Operations operation response. /// </returns> public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.Models.SubscriptionListOperationsResponse> ListOperationsAsync(SubscriptionListOperationsParameters parameters, CancellationToken cancellationToken) { // Validate if (parameters == null) { throw new ArgumentNullException("parameters"); } // Tracing bool shouldTrace = CloudContext.Configuration.Tracing.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = Tracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("parameters", parameters); Tracing.Enter(invocationId, this, "ListOperationsAsync", tracingParameters); } // Construct URL string url = "/" + (this.Client.Credentials.SubscriptionId != null ? this.Client.Credentials.SubscriptionId.Trim() : "") + "/operations?"; url = url + "&StartTime=" + Uri.EscapeDataString(string.Format(CultureInfo.InvariantCulture, "{0:O}", parameters.StartTime.ToUniversalTime())); url = url + "&EndTime=" + Uri.EscapeDataString(string.Format(CultureInfo.InvariantCulture, "{0:O}", parameters.EndTime.ToUniversalTime())); if (parameters.ObjectIdFilter != null) { url = url + "&ObjectIdFilter=" + Uri.EscapeDataString(parameters.ObjectIdFilter != null ? parameters.ObjectIdFilter.Trim() : ""); } if (parameters.OperationStatus != null) { url = url + "&OperationResultFilter=" + Uri.EscapeDataString(parameters.OperationStatus.Value.ToString()); } if (parameters.ContinuationToken != null) { url = url + "&ContinuationToken=" + Uri.EscapeDataString(parameters.ContinuationToken != null ? parameters.ContinuationToken.Trim() : ""); } 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("x-ms-version", "2014-05-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { Tracing.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { Tracing.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) { Tracing.Error(invocationId, ex); } throw ex; } // Create Result SubscriptionListOperationsResponse result = null; // Deserialize Response cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new SubscriptionListOperationsResponse(); XDocument responseDoc = XDocument.Parse(responseContent); XElement subscriptionOperationCollectionElement = responseDoc.Element(XName.Get("SubscriptionOperationCollection", "http://schemas.microsoft.com/windowsazure")); if (subscriptionOperationCollectionElement != null) { XElement continuationTokenElement = subscriptionOperationCollectionElement.Element(XName.Get("ContinuationToken", "http://schemas.microsoft.com/windowsazure")); if (continuationTokenElement != null) { string continuationTokenInstance = continuationTokenElement.Value; result.ContinuationToken = continuationTokenInstance; } XElement subscriptionOperationsSequenceElement = subscriptionOperationCollectionElement.Element(XName.Get("SubscriptionOperations", "http://schemas.microsoft.com/windowsazure")); if (subscriptionOperationsSequenceElement != null) { result.SubscriptionOperations = new List <SubscriptionListOperationsResponse.SubscriptionOperation>(); foreach (XElement subscriptionOperationsElement in subscriptionOperationsSequenceElement.Elements(XName.Get("SubscriptionOperation", "http://schemas.microsoft.com/windowsazure"))) { SubscriptionListOperationsResponse.SubscriptionOperation subscriptionOperationInstance = new SubscriptionListOperationsResponse.SubscriptionOperation(); result.SubscriptionOperations.Add(subscriptionOperationInstance); XElement operationIdElement = subscriptionOperationsElement.Element(XName.Get("OperationId", "http://schemas.microsoft.com/windowsazure")); if (operationIdElement != null) { string operationIdInstance = operationIdElement.Value; subscriptionOperationInstance.OperationId = operationIdInstance; } XElement operationObjectIdElement = subscriptionOperationsElement.Element(XName.Get("OperationObjectId", "http://schemas.microsoft.com/windowsazure")); if (operationObjectIdElement != null) { string operationObjectIdInstance = operationObjectIdElement.Value; subscriptionOperationInstance.OperationObjectId = operationObjectIdInstance; } XElement operationNameElement = subscriptionOperationsElement.Element(XName.Get("OperationName", "http://schemas.microsoft.com/windowsazure")); if (operationNameElement != null) { string operationNameInstance = operationNameElement.Value; subscriptionOperationInstance.OperationName = operationNameInstance; } XElement operationParametersSequenceElement = subscriptionOperationsElement.Element(XName.Get("OperationParameters", "http://schemas.microsoft.com/windowsazure")); if (operationParametersSequenceElement != null) { subscriptionOperationInstance.OperationParameters = new Dictionary <string, string>(); foreach (XElement operationParametersElement in operationParametersSequenceElement.Elements(XName.Get("OperationParameter", "http://schemas.microsoft.com/windowsazure"))) { string operationParametersKey = operationParametersElement.Element(XName.Get("Name", "http://schemas.datacontract.org/2004/07/Microsoft.WindowsAzure.ServiceManagement")).Value; string operationParametersValue = operationParametersElement.Element(XName.Get("Value", "http://schemas.datacontract.org/2004/07/Microsoft.WindowsAzure.ServiceManagement")).Value; subscriptionOperationInstance.OperationParameters.Add(operationParametersKey, operationParametersValue); } } XElement operationCallerElement = subscriptionOperationsElement.Element(XName.Get("OperationCaller", "http://schemas.microsoft.com/windowsazure")); if (operationCallerElement != null) { SubscriptionListOperationsResponse.OperationCallerDetails operationCallerInstance = new SubscriptionListOperationsResponse.OperationCallerDetails(); subscriptionOperationInstance.OperationCaller = operationCallerInstance; XElement usedServiceManagementApiElement = operationCallerElement.Element(XName.Get("UsedServiceManagementApi", "http://schemas.microsoft.com/windowsazure")); if (usedServiceManagementApiElement != null) { bool usedServiceManagementApiInstance = bool.Parse(usedServiceManagementApiElement.Value); operationCallerInstance.UsedServiceManagementApi = usedServiceManagementApiInstance; } XElement userEmailAddressElement = operationCallerElement.Element(XName.Get("UserEmailAddress", "http://schemas.microsoft.com/windowsazure")); if (userEmailAddressElement != null) { string userEmailAddressInstance = userEmailAddressElement.Value; operationCallerInstance.UserEmailAddress = userEmailAddressInstance; } XElement subscriptionCertificateThumbprintElement = operationCallerElement.Element(XName.Get("SubscriptionCertificateThumbprint", "http://schemas.microsoft.com/windowsazure")); if (subscriptionCertificateThumbprintElement != null) { string subscriptionCertificateThumbprintInstance = subscriptionCertificateThumbprintElement.Value; operationCallerInstance.SubscriptionCertificateThumbprint = subscriptionCertificateThumbprintInstance; } XElement clientIPElement = operationCallerElement.Element(XName.Get("ClientIP", "http://schemas.microsoft.com/windowsazure")); if (clientIPElement != null) { string clientIPInstance = clientIPElement.Value; operationCallerInstance.ClientIPAddress = clientIPInstance; } } XElement operationStatusElement = subscriptionOperationsElement.Element(XName.Get("OperationStatus", "http://schemas.microsoft.com/windowsazure")); if (operationStatusElement != null) { string operationStatusInstance = operationStatusElement.Value; subscriptionOperationInstance.OperationStatus = operationStatusInstance; } XElement operationStartedTimeElement = subscriptionOperationsElement.Element(XName.Get("OperationStartedTime", "http://schemas.microsoft.com/windowsazure")); if (operationStartedTimeElement != null) { DateTime operationStartedTimeInstance = DateTime.Parse(operationStartedTimeElement.Value, CultureInfo.InvariantCulture); subscriptionOperationInstance.OperationStartedTime = operationStartedTimeInstance; } XElement operationCompletedTimeElement = subscriptionOperationsElement.Element(XName.Get("OperationCompletedTime", "http://schemas.microsoft.com/windowsazure")); if (operationCompletedTimeElement != null) { DateTime operationCompletedTimeInstance = DateTime.Parse(operationCompletedTimeElement.Value, CultureInfo.InvariantCulture); subscriptionOperationInstance.OperationCompletedTime = operationCompletedTimeInstance; } } } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { Tracing.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }
/// <summary> /// The List Subscription Operations operation returns a list of /// create, update, and delete operations that were performed on a /// subscription during the specified timeframe. (see /// http://msdn.microsoft.com/en-us/library/windowsazure/gg715318.aspx /// for more information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Internal.Management.Rdfe.ISubscriptionOperations. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the List Subscription Operations /// operation. /// </param> /// <returns> /// The List Subscription Operations operation response. /// </returns> public static Task <SubscriptionListOperationsResponse> ListOperationsAsync(this ISubscriptionOperations operations, SubscriptionListOperationsParameters parameters) { return(operations.ListOperationsAsync(parameters, CancellationToken.None)); }
/// <summary> /// The List Subscription Operations operation returns a list of /// create, update, and delete operations that were performed on a /// subscription during the specified timeframe. (see /// http://msdn.microsoft.com/en-us/library/windowsazure/gg715318.aspx /// for more information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Internal.Management.Rdfe.ISubscriptionOperations. /// </param> /// <param name='parameters'> /// Required. Parameters supplied to the List Subscription Operations /// operation. /// </param> /// <returns> /// The List Subscription Operations operation response. /// </returns> public static SubscriptionListOperationsResponse ListOperations(this ISubscriptionOperations operations, SubscriptionListOperationsParameters parameters) { return(Task.Factory.StartNew((object s) => { return ((ISubscriptionOperations)s).ListOperationsAsync(parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// The List Subscription Operations operation returns a list of /// create, update, and delete operations that were performed on a /// subscription during the specified timeframe. (see /// http://msdn.microsoft.com/en-us/library/windowsazure/gg715318.aspx /// for more information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.ISubscriptionOperations. /// </param> /// <param name='parameters'> /// Parameters supplied to the List Subscription Operations operation. /// </param> /// <returns> /// The List Subscription Operations operation response. /// </returns> public static SubscriptionListOperationsResponse ListOperations(this ISubscriptionOperations operations, SubscriptionListOperationsParameters parameters) { try { return(operations.ListOperationsAsync(parameters).Result); } catch (AggregateException ex) { if (ex.InnerExceptions.Count > 1) { throw; } else { throw ex.InnerException; } } }