public void UpdateProfileStatus(string profileName, ProfileDefinitionStatus targetStatus) { ProfileDefinitionStatus currentStatus = this.GetStatus(profileName); if (currentStatus != targetStatus) { this.Client.Profiles.Update(profileName, targetStatus, 1); } }
/// <summary> /// Enables or disables a profile. (see /// http://msdn.microsoft.com/en-us/library/hh758250.aspx for more /// information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.TrafficManager.IProfileOperations. /// </param> /// <param name='profileName'> /// Required. The name of the profile. /// </param> /// <param name='profileStatus'> /// Required. Specifies whether the profile should be enabled or /// disabled. /// </param> /// <param name='definitionVersionNumber'> /// Required. Version of the definition associated with the profile /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static AzureOperationResponse Update(this IProfileOperations operations, string profileName, ProfileDefinitionStatus profileStatus, int definitionVersionNumber) { return(Task.Factory.StartNew((object s) => { return ((IProfileOperations)s).UpdateAsync(profileName, profileStatus, definitionVersionNumber); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Enables or disables a profile. (see /// http://msdn.microsoft.com/en-us/library/hh758250.aspx for more /// information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.TrafficManager.IProfileOperations. /// </param> /// <param name='profileName'> /// Required. The name of the profile. /// </param> /// <param name='profileStatus'> /// Required. Specifies whether the profile should be enabled or /// disabled. /// </param> /// <param name='definitionVersionNumber'> /// Required. Version of the definition associated with the profile /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static Task <AzureOperationResponse> UpdateAsync(this IProfileOperations operations, string profileName, ProfileDefinitionStatus profileStatus, int definitionVersionNumber) { return(operations.UpdateAsync(profileName, profileStatus, definitionVersionNumber, CancellationToken.None)); }
/// <summary> /// Enables or disables a profile. (see /// http://msdn.microsoft.com/en-us/library/hh758250.aspx for more /// information) /// </summary> /// <param name='profileName'> /// Required. The name of the profile. /// </param> /// <param name='profileStatus'> /// Required. Specifies whether the profile should be enabled or /// disabled. /// </param> /// <param name='definitionVersionNumber'> /// Required. Version of the definition associated with the profile /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public async System.Threading.Tasks.Task <OperationResponse> UpdateAsync(string profileName, ProfileDefinitionStatus profileStatus, int definitionVersionNumber, CancellationToken cancellationToken) { // Validate if (profileName == null) { throw new ArgumentNullException("profileName"); } // 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("profileName", profileName); tracingParameters.Add("profileStatus", profileStatus); tracingParameters.Add("definitionVersionNumber", definitionVersionNumber); Tracing.Enter(invocationId, this, "UpdateAsync", tracingParameters); } // Construct URL string url = "/" + (this.Client.Credentials.SubscriptionId != null ? this.Client.Credentials.SubscriptionId.Trim() : "") + "/services/WATM/profiles/" + profileName.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.Put; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("x-ms-version", "2011-10-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Serialize Request string requestContent = null; XDocument requestDoc = new XDocument(); XElement profileElement = new XElement(XName.Get("Profile", "http://schemas.microsoft.com/windowsazure")); requestDoc.Add(profileElement); XElement statusElement = new XElement(XName.Get("Status", "http://schemas.microsoft.com/windowsazure")); statusElement.Value = profileStatus.ToString(); profileElement.Add(statusElement); XElement statusDetailsElement = new XElement(XName.Get("StatusDetails", "http://schemas.microsoft.com/windowsazure")); profileElement.Add(statusDetailsElement); XElement enabledVersionElement = new XElement(XName.Get("EnabledVersion", "http://schemas.microsoft.com/windowsazure")); enabledVersionElement.Value = definitionVersionNumber.ToString(); statusDetailsElement.Add(enabledVersionElement); requestContent = requestDoc.ToString(); httpRequest.Content = new StringContent(requestContent, Encoding.UTF8); httpRequest.Content.Headers.ContentType = new MediaTypeHeaderValue("application/xml"); httpRequest.Content.Headers.ContentType.CharSet = "utf-8"; // 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, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { Tracing.Error(invocationId, ex); } throw ex; } // Create Result OperationResponse result = null; result = new OperationResponse(); 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> /// Returns all profiles owned by a subscription. (see /// http://msdn.microsoft.com/en-us/library/hh758249.aspx for more /// information) /// </summary> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The List Profiles operation response. /// </returns> public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.TrafficManager.Models.ProfilesListResponse> ListAsync(CancellationToken cancellationToken) { // Validate // Tracing bool shouldTrace = CloudContext.Configuration.Tracing.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = Tracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); Tracing.Enter(invocationId, this, "ListAsync", tracingParameters); } // Construct URL string url = "/" + (this.Client.Credentials.SubscriptionId != null ? this.Client.Credentials.SubscriptionId.Trim() : "") + "/services/WATM/profiles"; 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", "2011-10-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 ProfilesListResponse result = null; // Deserialize Response cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new ProfilesListResponse(); XDocument responseDoc = XDocument.Parse(responseContent); XElement profilesSequenceElement = responseDoc.Element(XName.Get("Profiles", "http://schemas.microsoft.com/windowsazure")); if (profilesSequenceElement != null) { foreach (XElement profilesElement in profilesSequenceElement.Elements(XName.Get("Profile", "http://schemas.microsoft.com/windowsazure"))) { Profile profileInstance = new Profile(); result.Profiles.Add(profileInstance); XElement domainNameElement = profilesElement.Element(XName.Get("DomainName", "http://schemas.microsoft.com/windowsazure")); if (domainNameElement != null) { string domainNameInstance = domainNameElement.Value; profileInstance.DomainName = domainNameInstance; } XElement nameElement = profilesElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure")); if (nameElement != null) { string nameInstance = nameElement.Value; profileInstance.Name = nameInstance; } XElement statusElement = profilesElement.Element(XName.Get("Status", "http://schemas.microsoft.com/windowsazure")); if (statusElement != null) { ProfileDefinitionStatus statusInstance = ((ProfileDefinitionStatus)Enum.Parse(typeof(ProfileDefinitionStatus), statusElement.Value, true)); profileInstance.Status = statusInstance; } XElement statusDetailsElement = profilesElement.Element(XName.Get("StatusDetails", "http://schemas.microsoft.com/windowsazure")); if (statusDetailsElement != null) { ProfileStatusDetails statusDetailsInstance = new ProfileStatusDetails(); profileInstance.StatusDetails = statusDetailsInstance; XElement enabledVersionElement = statusDetailsElement.Element(XName.Get("EnabledVersion", "http://schemas.microsoft.com/windowsazure")); if (enabledVersionElement != null) { int enabledVersionInstance = int.Parse(enabledVersionElement.Value, CultureInfo.InvariantCulture); statusDetailsInstance.EnabledDefinitionVersion = enabledVersionInstance; } } XElement definitionsSequenceElement = profilesElement.Element(XName.Get("Definitions", "http://schemas.microsoft.com/windowsazure")); if (definitionsSequenceElement != null) { foreach (XElement definitionsElement in definitionsSequenceElement.Elements(XName.Get("Definition", "http://schemas.microsoft.com/windowsazure"))) { DefinitionStatusAndVersion definitionInstance = new DefinitionStatusAndVersion(); profileInstance.Definitions.Add(definitionInstance); XElement statusElement2 = definitionsElement.Element(XName.Get("Status", "http://schemas.microsoft.com/windowsazure")); if (statusElement2 != null) { ProfileDefinitionStatus statusInstance2 = ((ProfileDefinitionStatus)Enum.Parse(typeof(ProfileDefinitionStatus), statusElement2.Value, true)); definitionInstance.Status = statusInstance2; } XElement versionElement = definitionsElement.Element(XName.Get("Version", "http://schemas.microsoft.com/windowsazure")); if (versionElement != null) { int versionInstance = int.Parse(versionElement.Value, CultureInfo.InvariantCulture); definitionInstance.Version = versionInstance; } } } } } 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(); } } }
public void UpdateProfileStatus(string profileName, ProfileDefinitionStatus targetStatus) { ProfileDefinitionStatus currentStatus = this.GetStatus(profileName); if (currentStatus != targetStatus) { this.Client.Profiles.Update(profileName, targetStatus, 1); } }
/// <summary> /// Enables or disables a profile. (see /// http://msdn.microsoft.com/en-us/library/hh758250.aspx for more /// information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.TrafficManager.IProfileOperations. /// </param> /// <param name='profileName'> /// Required. The name of the profile. /// </param> /// <param name='profileStatus'> /// Required. Specifies whether the profile should be enabled or /// disabled. /// </param> /// <param name='definitionVersionNumber'> /// Required. Version of the definition associated with the profile /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static Task<OperationResponse> UpdateAsync(this IProfileOperations operations, string profileName, ProfileDefinitionStatus profileStatus, int definitionVersionNumber) { return operations.UpdateAsync(profileName, profileStatus, definitionVersionNumber, CancellationToken.None); }
/// <summary> /// Enables or disables a profile. (see /// http://msdn.microsoft.com/en-us/library/hh758250.aspx for more /// information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.WindowsAzure.Management.TrafficManager.IProfileOperations. /// </param> /// <param name='profileName'> /// Required. The name of the profile. /// </param> /// <param name='profileStatus'> /// Required. Specifies whether the profile should be enabled or /// disabled. /// </param> /// <param name='definitionVersionNumber'> /// Required. Version of the definition associated with the profile /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static OperationResponse Update(this IProfileOperations operations, string profileName, ProfileDefinitionStatus profileStatus, int definitionVersionNumber) { return Task.Factory.StartNew((object s) => { return ((IProfileOperations)s).UpdateAsync(profileName, profileStatus, definitionVersionNumber); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }