/src/WebSiteManagement/Generated/WebSiteOperations.cs
C# | 8390 lines | 6603 code | 761 blank | 1026 comment | 1906 complexity | 955f7dc13d603a866526bac09b8acbc8 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- //
- // Copyright (c) Microsoft and contributors. All rights reserved.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- //
- // See the License for the specific language governing permissions and
- // limitations under the License.
- //
- // Warning: This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the
- // code is regenerated.
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Net.Http.Headers;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Xml.Linq;
- using Hyak.Common;
- using Hyak.Common.Internals;
- using Microsoft.Azure;
- using Microsoft.WindowsAzure.Management.WebSites;
- using Microsoft.WindowsAzure.Management.WebSites.Models;
- using Newtonsoft.Json.Linq;
- namespace Microsoft.WindowsAzure.Management.WebSites
- {
- /// <summary>
- /// Operations for managing the web sites in a web space. (see
- /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166981.aspx for
- /// more information)
- /// </summary>
- internal partial class WebSiteOperations : IServiceOperations<WebSiteManagementClient>, IWebSiteOperations
- {
- /// <summary>
- /// Initializes a new instance of the WebSiteOperations class.
- /// </summary>
- /// <param name='client'>
- /// Reference to the service client.
- /// </param>
- internal WebSiteOperations(WebSiteManagementClient client)
- {
- this._client = client;
- }
-
- private WebSiteManagementClient _client;
-
- /// <summary>
- /// Gets a reference to the
- /// Microsoft.WindowsAzure.Management.WebSites.WebSiteManagementClient.
- /// </summary>
- public WebSiteManagementClient Client
- {
- get { return this._client; }
- }
-
- /// <param name='webSpaceName'>
- /// Required. The name of the web space.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='targetSwapSlot'>
- /// Required. The name of the target slot to be swapped with.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// A standard service response including an HTTP status code and
- /// request ID.
- /// </returns>
- public async Task<AzureOperationResponse> ApplySlotConfigurationAsync(string webSpaceName, string webSiteName, string targetSwapSlot, CancellationToken cancellationToken)
- {
- // Validate
- if (webSpaceName == null)
- {
- throw new ArgumentNullException("webSpaceName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
- if (targetSwapSlot == null)
- {
- throw new ArgumentNullException("targetSwapSlot");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("webSpaceName", webSpaceName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("targetSwapSlot", targetSwapSlot);
- TracingAdapter.Enter(invocationId, this, "ApplySlotConfigurationAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/services/WebSpaces/";
- url = url + Uri.EscapeDataString(webSpaceName);
- url = url + "/sites/";
- url = url + Uri.EscapeDataString(webSiteName);
- url = url + "/applySlotConfig";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("targetSwapSlot=" + Uri.EscapeDataString(targetSwapSlot));
- 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.Post;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
- httpRequest.Headers.Add("accept", "application/json");
- httpRequest.Headers.Add("x-ms-version", "2014-04-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
- AzureOperationResponse result = null;
- // Deserialize Response
- result = new AzureOperationResponse();
- 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>
- /// Backups a site on-demand.
- /// </summary>
- /// <param name='webSpaceName'>
- /// Required. The name of the web space.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='backupRequest'>
- /// Required. A backup specification.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// The backup record created based on the backup request.
- /// </returns>
- public async Task<WebSiteBackupResponse> BackupAsync(string webSpaceName, string webSiteName, BackupRequest backupRequest, CancellationToken cancellationToken)
- {
- // Validate
- if (webSpaceName == null)
- {
- throw new ArgumentNullException("webSpaceName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
- if (backupRequest == null)
- {
- throw new ArgumentNullException("backupRequest");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("webSpaceName", webSpaceName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("backupRequest", backupRequest);
- TracingAdapter.Enter(invocationId, this, "BackupAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/services/WebSpaces/";
- url = url + Uri.EscapeDataString(webSpaceName);
- url = url + "/sites/";
- url = url + Uri.EscapeDataString(webSiteName);
- url = url + "/backup";
- 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", "2014-04-01");
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Serialize Request
- string requestContent = null;
- XDocument requestDoc = new XDocument();
-
- XElement backupRequestElement = new XElement(XName.Get("BackupRequest", "http://schemas.microsoft.com/windowsazure"));
- requestDoc.Add(backupRequestElement);
-
- if (backupRequest.BackupSchedule != null)
- {
- XElement backupScheduleElement = new XElement(XName.Get("BackupSchedule", "http://schemas.microsoft.com/windowsazure"));
- backupRequestElement.Add(backupScheduleElement);
-
- XElement frequencyIntervalElement = new XElement(XName.Get("FrequencyInterval", "http://schemas.microsoft.com/windowsazure"));
- frequencyIntervalElement.Value = backupRequest.BackupSchedule.FrequencyInterval.ToString();
- backupScheduleElement.Add(frequencyIntervalElement);
-
- XElement frequencyUnitElement = new XElement(XName.Get("FrequencyUnit", "http://schemas.microsoft.com/windowsazure"));
- frequencyUnitElement.Value = backupRequest.BackupSchedule.FrequencyUnit.ToString();
- backupScheduleElement.Add(frequencyUnitElement);
-
- XElement keepAtLeastOneBackupElement = new XElement(XName.Get("KeepAtLeastOneBackup", "http://schemas.microsoft.com/windowsazure"));
- keepAtLeastOneBackupElement.Value = backupRequest.BackupSchedule.KeepAtLeastOneBackup.ToString().ToLower();
- backupScheduleElement.Add(keepAtLeastOneBackupElement);
-
- if (backupRequest.BackupSchedule.LastExecutionTime != null)
- {
- XElement lastExecutionTimeElement = new XElement(XName.Get("LastExecutionTime", "http://schemas.microsoft.com/windowsazure"));
- lastExecutionTimeElement.Value = string.Format(CultureInfo.InvariantCulture, "{0:O}", backupRequest.BackupSchedule.LastExecutionTime.Value.ToUniversalTime());
- backupScheduleElement.Add(lastExecutionTimeElement);
- }
-
- XElement retentionPeriodInDaysElement = new XElement(XName.Get("RetentionPeriodInDays", "http://schemas.microsoft.com/windowsazure"));
- retentionPeriodInDaysElement.Value = backupRequest.BackupSchedule.RetentionPeriodInDays.ToString();
- backupScheduleElement.Add(retentionPeriodInDaysElement);
-
- if (backupRequest.BackupSchedule.StartTime != null)
- {
- XElement startTimeElement = new XElement(XName.Get("StartTime", "http://schemas.microsoft.com/windowsazure"));
- startTimeElement.Value = string.Format(CultureInfo.InvariantCulture, "{0:O}", backupRequest.BackupSchedule.StartTime.Value.ToUniversalTime());
- backupScheduleElement.Add(startTimeElement);
- }
- }
-
- if (backupRequest.Databases != null)
- {
- if (backupRequest.Databases is ILazyCollection == false || ((ILazyCollection)backupRequest.Databases).IsInitialized)
- {
- XElement databasesSequenceElement = new XElement(XName.Get("Databases", "http://schemas.microsoft.com/windowsazure"));
- foreach (DatabaseBackupSetting databasesItem in backupRequest.Databases)
- {
- XElement databaseBackupSettingElement = new XElement(XName.Get("DatabaseBackupSetting", "http://schemas.microsoft.com/windowsazure"));
- databasesSequenceElement.Add(databaseBackupSettingElement);
-
- if (databasesItem.ConnectionString != null)
- {
- XElement connectionStringElement = new XElement(XName.Get("ConnectionString", "http://schemas.microsoft.com/windowsazure"));
- connectionStringElement.Value = databasesItem.ConnectionString;
- databaseBackupSettingElement.Add(connectionStringElement);
- }
-
- if (databasesItem.ConnectionStringName != null)
- {
- XElement connectionStringNameElement = new XElement(XName.Get("ConnectionStringName", "http://schemas.microsoft.com/windowsazure"));
- connectionStringNameElement.Value = databasesItem.ConnectionStringName;
- databaseBackupSettingElement.Add(connectionStringNameElement);
- }
-
- if (databasesItem.DatabaseType != null)
- {
- XElement databaseTypeElement = new XElement(XName.Get("DatabaseType", "http://schemas.microsoft.com/windowsazure"));
- databaseTypeElement.Value = databasesItem.DatabaseType;
- databaseBackupSettingElement.Add(databaseTypeElement);
- }
-
- if (databasesItem.Name != null)
- {
- XElement nameElement = new XElement(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
- nameElement.Value = databasesItem.Name;
- databaseBackupSettingElement.Add(nameElement);
- }
- }
- backupRequestElement.Add(databasesSequenceElement);
- }
- }
-
- if (backupRequest.Enabled != null)
- {
- XElement enabledElement = new XElement(XName.Get("Enabled", "http://schemas.microsoft.com/windowsazure"));
- enabledElement.Value = backupRequest.Enabled.ToString().ToLower();
- backupRequestElement.Add(enabledElement);
- }
-
- if (backupRequest.Name != null)
- {
- XElement nameElement2 = new XElement(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
- nameElement2.Value = backupRequest.Name;
- backupRequestElement.Add(nameElement2);
- }
-
- if (backupRequest.StorageAccountUrl != null)
- {
- XElement storageAccountUrlElement = new XElement(XName.Get("StorageAccountUrl", "http://schemas.microsoft.com/windowsazure"));
- storageAccountUrlElement.Value = backupRequest.StorageAccountUrl;
- backupRequestElement.Add(storageAccountUrlElement);
- }
-
- requestContent = requestDoc.ToString();
- httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
- httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/xml");
-
- // 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, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteBackupResponse result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteBackupResponse();
- XDocument responseDoc = XDocument.Parse(responseContent);
-
- XElement backupItemElement = responseDoc.Element(XName.Get("BackupItem", "http://schemas.microsoft.com/windowsazure"));
- if (backupItemElement != null)
- {
- BackupItem backupItemInstance = new BackupItem();
- result.BackupItem = backupItemInstance;
-
- XElement storageAccountUrlElement2 = backupItemElement.Element(XName.Get("StorageAccountUrl", "http://schemas.microsoft.com/windowsazure"));
- if (storageAccountUrlElement2 != null)
- {
- string storageAccountUrlInstance = storageAccountUrlElement2.Value;
- backupItemInstance.StorageAccountUrl = storageAccountUrlInstance;
- }
-
- XElement blobNameElement = backupItemElement.Element(XName.Get("BlobName", "http://schemas.microsoft.com/windowsazure"));
- if (blobNameElement != null)
- {
- string blobNameInstance = blobNameElement.Value;
- backupItemInstance.BlobName = blobNameInstance;
- }
-
- XElement nameElement3 = backupItemElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
- if (nameElement3 != null)
- {
- string nameInstance = nameElement3.Value;
- backupItemInstance.Name = nameInstance;
- }
-
- XElement statusElement = backupItemElement.Element(XName.Get("Status", "http://schemas.microsoft.com/windowsazure"));
- if (statusElement != null)
- {
- BackupItemStatus statusInstance = ((BackupItemStatus)Enum.Parse(typeof(BackupItemStatus), statusElement.Value, true));
- backupItemInstance.Status = statusInstance;
- }
-
- XElement sizeInBytesElement = backupItemElement.Element(XName.Get("SizeInBytes", "http://schemas.microsoft.com/windowsazure"));
- if (sizeInBytesElement != null)
- {
- long sizeInBytesInstance = long.Parse(sizeInBytesElement.Value, CultureInfo.InvariantCulture);
- backupItemInstance.SizeInBytes = sizeInBytesInstance;
- }
-
- XElement createdElement = backupItemElement.Element(XName.Get("Created", "http://schemas.microsoft.com/windowsazure"));
- if (createdElement != null && !string.IsNullOrEmpty(createdElement.Value))
- {
- DateTime createdInstance = DateTime.Parse(createdElement.Value, CultureInfo.InvariantCulture);
- backupItemInstance.Created = createdInstance;
- }
-
- XElement logElement = backupItemElement.Element(XName.Get("Log", "http://schemas.microsoft.com/windowsazure"));
- if (logElement != null)
- {
- string logInstance = logElement.Value;
- backupItemInstance.Log = logInstance;
- }
-
- XElement databasesSequenceElement2 = backupItemElement.Element(XName.Get("Databases", "http://schemas.microsoft.com/windowsazure"));
- if (databasesSequenceElement2 != null)
- {
- foreach (XElement databasesElement in databasesSequenceElement2.Elements(XName.Get("DatabaseBackupSetting", "http://schemas.microsoft.com/windowsazure")))
- {
- DatabaseBackupSetting databaseBackupSettingInstance = new DatabaseBackupSetting();
- backupItemInstance.Databases.Add(databaseBackupSettingInstance);
-
- XElement connectionStringElement2 = databasesElement.Element(XName.Get("ConnectionString", "http://schemas.microsoft.com/windowsazure"));
- if (connectionStringElement2 != null)
- {
- string connectionStringInstance = connectionStringElement2.Value;
- databaseBackupSettingInstance.ConnectionString = connectionStringInstance;
- }
-
- XElement connectionStringNameElement2 = databasesElement.Element(XName.Get("ConnectionStringName", "http://schemas.microsoft.com/windowsazure"));
- if (connectionStringNameElement2 != null)
- {
- string connectionStringNameInstance = connectionStringNameElement2.Value;
- databaseBackupSettingInstance.ConnectionStringName = connectionStringNameInstance;
- }
-
- XElement databaseTypeElement2 = databasesElement.Element(XName.Get("DatabaseType", "http://schemas.microsoft.com/windowsazure"));
- if (databaseTypeElement2 != null)
- {
- string databaseTypeInstance = databaseTypeElement2.Value;
- databaseBackupSettingInstance.DatabaseType = databaseTypeInstance;
- }
-
- XElement nameElement4 = databasesElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
- if (nameElement4 != null)
- {
- string nameInstance2 = nameElement4.Value;
- databaseBackupSettingInstance.Name = nameInstance2;
- }
- }
- }
-
- XElement scheduledElement = backupItemElement.Element(XName.Get("Scheduled", "http://schemas.microsoft.com/windowsazure"));
- if (scheduledElement != null)
- {
- bool scheduledInstance = bool.Parse(scheduledElement.Value);
- backupItemInstance.Scheduled = scheduledInstance;
- }
-
- XElement lastRestoreTimeStampElement = backupItemElement.Element(XName.Get("LastRestoreTimeStamp", "http://schemas.microsoft.com/windowsazure"));
- if (lastRestoreTimeStampElement != null && !string.IsNullOrEmpty(lastRestoreTimeStampElement.Value))
- {
- DateTime lastRestoreTimeStampInstance = DateTime.Parse(lastRestoreTimeStampElement.Value, CultureInfo.InvariantCulture);
- backupItemInstance.LastRestoreTimeStamp = lastRestoreTimeStampInstance;
- }
-
- XElement finishedTimeStampElement = backupItemElement.Element(XName.Get("FinishedTimeStamp", "http://schemas.microsoft.com/windowsazure"));
- if (finishedTimeStampElement != null && !string.IsNullOrEmpty(finishedTimeStampElement.Value))
- {
- DateTime finishedTimeStampInstance = DateTime.Parse(finishedTimeStampElement.Value, CultureInfo.InvariantCulture);
- backupItemInstance.FinishedTimeStamp = finishedTimeStampInstance;
- }
-
- XElement correlationIdElement = backupItemElement.Element(XName.Get("CorrelationId", "http://schemas.microsoft.com/windowsazure"));
- if (correlationIdElement != null)
- {
- string correlationIdInstance = correlationIdElement.Value;
- backupItemInstance.CorrelationId = correlationIdInstance;
- }
- }
-
- }
- 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>
- /// You can swap a web site from one slot to another slot.
- /// </summary>
- /// <param name='webSpaceName'>
- /// Required. The name of the web space.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='sourceSlotName'>
- /// Required. The name of the first web site slot to swap (source).
- /// </param>
- /// <param name='targetSlotName'>
- /// Required. The name of the second web site slot to swap with
- /// (target).
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// The response body contains the status of the specified long-running
- /// operation, indicating whether it has succeeded, is inprogress, has
- /// timed out, or has failed. Note that this status is distinct from
- /// the HTTP status code returned for the Get Operation Status
- /// operation itself. If the long-running operation failed, the
- /// response body includes error information regarding the failure.
- /// </returns>
- public async Task<WebSiteOperationStatusResponse> BeginSwappingSlotsAsync(string webSpaceName, string webSiteName, string sourceSlotName, string targetSlotName, CancellationToken cancellationToken)
- {
- // Validate
- if (webSpaceName == null)
- {
- throw new ArgumentNullException("webSpaceName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
- if (sourceSlotName == null)
- {
- throw new ArgumentNullException("sourceSlotName");
- }
- if (targetSlotName == null)
- {
- throw new ArgumentNullException("targetSlotName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("webSpaceName", webSpaceName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("sourceSlotName", sourceSlotName);
- tracingParameters.Add("targetSlotName", targetSlotName);
- TracingAdapter.Enter(invocationId, this, "BeginSwappingSlotsAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/services/WebSpaces/";
- url = url + Uri.EscapeDataString(webSpaceName);
- url = url + "/sites/";
- url = url + Uri.EscapeDataString(webSiteName);
- url = url + "(";
- url = url + Uri.EscapeDataString(sourceSlotName);
- url = url + ")/slots";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("Command=swap");
- queryParameters.Add("targetSlot=" + Uri.EscapeDataString(targetSlotName));
- 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.Post;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
- httpRequest.Headers.Add("x-ms-version", "2014-04-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
- WebSiteOperationStatusResponse result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteOperationStatusResponse();
- XDocument responseDoc = XDocument.Parse(responseContent);
-
- XElement operationElement = responseDoc.Element(XName.Get("Operation", "http://schemas.microsoft.com/windowsazure"));
- if (operationElement != null)
- {
- XElement createdTimeElement = operationElement.Element(XName.Get("CreatedTime", "http://schemas.microsoft.com/windowsazure"));
- if (createdTimeElement != null)
- {
- DateTime createdTimeInstance = DateTime.Parse(createdTimeElement.Value, CultureInfo.InvariantCulture);
- result.CreatedTime = createdTimeInstance;
- }
-
- XElement errorsSequenceElement = operationElement.Element(XName.Get("Errors", "http://schemas.microsoft.com/windowsazure"));
- if (errorsSequenceElement != null)
- {
- bool isNil = false;
- XAttribute nilAttribute = errorsSequenceElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
- if (nilAttribute != null)
- {
- isNil = nilAttribute.Value == "true";
- }
- if (isNil == false)
- {
- foreach (XElement errorsElement in errorsSequenceElement.Elements(XName.Get("Error", "http://schemas.microsoft.com/windowsazure")))
- {
- WebSiteOperationStatusResponse.Error errorInstance = new WebSiteOperationStatusResponse.Error();
- result.Errors.Add(errorInstance);
-
- XElement codeElement = errorsElement.Element(XName.Get("Code", "http://schemas.microsoft.com/windowsazure"));
- if (codeElement != null)
- {
- bool isNil2 = false;
- XAttribute nilAttribute2 = codeElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
- if (nilAttribute2 != null)
- {
- isNil2 = nilAttribute2.Value == "true";
- }
- if (isNil2 == false)
- {
- string codeInstance = codeElement.Value;
- errorInstance.Code = codeInstance;
- }
- }
-
- XElement messageElement = errorsElement.Element(XName.Get("Message", "http://schemas.microsoft.com/windowsazure"));
- if (messageElement != null)
- {
- bool isNil3 = false;
- XAttribute nilAttribute3 = messageElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
- if (nilAttribute3 != null)
- {
- isNil3 = nilAttribute3.Value == "true";
- }
- if (isNil3 == false)
- {
- string messageInstance = messageElement.Value;
- errorInstance.Message = messageInstance;
- }
- }
-
- XElement extendedCodeElement = errorsElement.Element(XName.Get("ExtendedCode", "http://schemas.microsoft.com/windowsazure"));
- if (extendedCodeElement != null)
- {
- bool isNil4 = false;
- XAttribute nilAttribute4 = extendedCodeElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
- if (nilAttribute4 != null)
- {
- isNil4 = nilAttribute4.Value == "true";
- }
- if (isNil4 == false)
- {
- string extendedCodeInstance = extendedCodeElement.Value;
- errorInstance.ExtendedCode = extendedCodeInstance;
- }
- }
-
- XElement messageTemplateElement = errorsElement.Element(XName.Get("MessageTemplate", "http://schemas.microsoft.com/windowsazure"));
- if (messageTemplateElement != null)
- {
- bool isNil5 = false;
- XAttribute nilAttribute5 = messageTemplateElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
- if (nilAttribute5 != null)
- {
- isNil5 = nilAttribute5.Value == "true";
- }
- if (isNil5 == false)
- {
- string messageTemplateInstance = messageTemplateElement.Value;
- errorInstance.MessageTemplate = messageTemplateInstance;
- }
- }
-
- XElement parametersSequenceElement = errorsElement.Element(XName.Get("Parameters", "http://schemas.microsoft.com/windowsazure"));
- if (parametersSequenceElement != null)
- {
- bool isNil6 = false;
- XAttribute nilAttribute6 = parametersSequenceElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
- if (nilAttribute6 != null)
- {
- isNil6 = nilAttribute6.Value == "true";
- }
- if (isNil6 == false)
- {
- foreach (XElement parametersElement in parametersSequenceElement.Elements(XName.Get("string", "http://schemas.microsoft.com/2003/10/Serialization/Arrays")))
- {
- errorInstance.Parameters.Add(parametersElement.Value);
- }
- }
- else
- {
- errorInstance.Parameters = null;
- }
- }
-
- XElement innerErrorsElement = errorsElement.Element(XName.Get("InnerErrors", "http://schemas.microsoft.com/windowsazure"));
- if (innerErrorsElement != null)
- {
- bool isNil7 = false;
- XAttribute nilAttribute7 = innerErrorsElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
- if (nilAttribute7 != null)
- {
- isNil7 = nilAttribute7.Value == "true";
- }
- if (isNil7 == false)
- {
- string innerErrorsInstance = innerErrorsElement.Value;
- errorInstance.InnerErrors = innerErrorsInstance;
- }
- }
- }
- }
- else
- {
- result.Errors = null;
- }
- }
-
- XElement expirationTimeElement = operationElement.Element(XName.Get("ExpirationTime", "http://schemas.microsoft.com/windowsazure"));
- if (expirationTimeElement != null)
- {
- DateTime expirationTimeInstance = DateTime.Parse(expirationTimeElement.Value, CultureInfo.InvariantCulture);
- result.ExpirationTime = expirationTimeInstance;
- }
-
- XElement geoMasterOperationIdElement = operationElement.Element(XName.Get("GeoMasterOperationId", "http://schemas.microsoft.com/windowsazure"));
- if (geoMasterOperationIdElement != null)
- {
- bool isNil8 = false;
- XAttribute nilAttribute8 = geoMasterOperationIdElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
- if (nilAttribute8 != null)
- {
- isNil8 = nilAttribute8.Value == "true";
- }
- if (isNil8 == false)
- {
- string geoMasterOperationIdInstance = geoMasterOperationIdElement.Value;
- result.GeoMasterOperationId = geoMasterOperationIdInstance;
- }
- }
-
- XElement idElement = operationElement.Element(XName.Get("Id", "http://schemas.microsoft.com/windowsazure"));
- if (idElement != null)
- {
- bool isNil9 = false;
- XAttribute nilAttribute9 = idElement.Attribut…
Large files files are truncated, but you can click here to view the full file