PageRenderTime 58ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 3ms

/src/WebSiteManagement/Generated/WebSiteOperations.cs

https://github.com/edumunoz/azure-sdk-for-net
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

  1. //
  2. // Copyright (c) Microsoft and contributors. All rights reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. //
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. // Warning: This code was generated by a tool.
  17. //
  18. // Changes to this file may cause incorrect behavior and will be lost if the
  19. // code is regenerated.
  20. using System;
  21. using System.Collections.Generic;
  22. using System.Globalization;
  23. using System.Linq;
  24. using System.Net;
  25. using System.Net.Http;
  26. using System.Net.Http.Headers;
  27. using System.Text;
  28. using System.Threading;
  29. using System.Threading.Tasks;
  30. using System.Xml.Linq;
  31. using Hyak.Common;
  32. using Hyak.Common.Internals;
  33. using Microsoft.Azure;
  34. using Microsoft.WindowsAzure.Management.WebSites;
  35. using Microsoft.WindowsAzure.Management.WebSites.Models;
  36. using Newtonsoft.Json.Linq;
  37. namespace Microsoft.WindowsAzure.Management.WebSites
  38. {
  39. /// <summary>
  40. /// Operations for managing the web sites in a web space. (see
  41. /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166981.aspx for
  42. /// more information)
  43. /// </summary>
  44. internal partial class WebSiteOperations : IServiceOperations<WebSiteManagementClient>, IWebSiteOperations
  45. {
  46. /// <summary>
  47. /// Initializes a new instance of the WebSiteOperations class.
  48. /// </summary>
  49. /// <param name='client'>
  50. /// Reference to the service client.
  51. /// </param>
  52. internal WebSiteOperations(WebSiteManagementClient client)
  53. {
  54. this._client = client;
  55. }
  56. private WebSiteManagementClient _client;
  57. /// <summary>
  58. /// Gets a reference to the
  59. /// Microsoft.WindowsAzure.Management.WebSites.WebSiteManagementClient.
  60. /// </summary>
  61. public WebSiteManagementClient Client
  62. {
  63. get { return this._client; }
  64. }
  65. /// <param name='webSpaceName'>
  66. /// Required. The name of the web space.
  67. /// </param>
  68. /// <param name='webSiteName'>
  69. /// Required. The name of the web site.
  70. /// </param>
  71. /// <param name='targetSwapSlot'>
  72. /// Required. The name of the target slot to be swapped with.
  73. /// </param>
  74. /// <param name='cancellationToken'>
  75. /// Cancellation token.
  76. /// </param>
  77. /// <returns>
  78. /// A standard service response including an HTTP status code and
  79. /// request ID.
  80. /// </returns>
  81. public async Task<AzureOperationResponse> ApplySlotConfigurationAsync(string webSpaceName, string webSiteName, string targetSwapSlot, CancellationToken cancellationToken)
  82. {
  83. // Validate
  84. if (webSpaceName == null)
  85. {
  86. throw new ArgumentNullException("webSpaceName");
  87. }
  88. if (webSiteName == null)
  89. {
  90. throw new ArgumentNullException("webSiteName");
  91. }
  92. if (targetSwapSlot == null)
  93. {
  94. throw new ArgumentNullException("targetSwapSlot");
  95. }
  96. // Tracing
  97. bool shouldTrace = TracingAdapter.IsEnabled;
  98. string invocationId = null;
  99. if (shouldTrace)
  100. {
  101. invocationId = TracingAdapter.NextInvocationId.ToString();
  102. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  103. tracingParameters.Add("webSpaceName", webSpaceName);
  104. tracingParameters.Add("webSiteName", webSiteName);
  105. tracingParameters.Add("targetSwapSlot", targetSwapSlot);
  106. TracingAdapter.Enter(invocationId, this, "ApplySlotConfigurationAsync", tracingParameters);
  107. }
  108. // Construct URL
  109. string url = "";
  110. url = url + "/";
  111. if (this.Client.Credentials.SubscriptionId != null)
  112. {
  113. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  114. }
  115. url = url + "/services/WebSpaces/";
  116. url = url + Uri.EscapeDataString(webSpaceName);
  117. url = url + "/sites/";
  118. url = url + Uri.EscapeDataString(webSiteName);
  119. url = url + "/applySlotConfig";
  120. List<string> queryParameters = new List<string>();
  121. queryParameters.Add("targetSwapSlot=" + Uri.EscapeDataString(targetSwapSlot));
  122. if (queryParameters.Count > 0)
  123. {
  124. url = url + "?" + string.Join("&", queryParameters);
  125. }
  126. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  127. // Trim '/' character from the end of baseUrl and beginning of url.
  128. if (baseUrl[baseUrl.Length - 1] == '/')
  129. {
  130. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  131. }
  132. if (url[0] == '/')
  133. {
  134. url = url.Substring(1);
  135. }
  136. url = baseUrl + "/" + url;
  137. url = url.Replace(" ", "%20");
  138. // Create HTTP transport objects
  139. HttpRequestMessage httpRequest = null;
  140. try
  141. {
  142. httpRequest = new HttpRequestMessage();
  143. httpRequest.Method = HttpMethod.Post;
  144. httpRequest.RequestUri = new Uri(url);
  145. // Set Headers
  146. httpRequest.Headers.Add("accept", "application/json");
  147. httpRequest.Headers.Add("x-ms-version", "2014-04-01");
  148. // Set Credentials
  149. cancellationToken.ThrowIfCancellationRequested();
  150. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  151. // Send Request
  152. HttpResponseMessage httpResponse = null;
  153. try
  154. {
  155. if (shouldTrace)
  156. {
  157. TracingAdapter.SendRequest(invocationId, httpRequest);
  158. }
  159. cancellationToken.ThrowIfCancellationRequested();
  160. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  161. if (shouldTrace)
  162. {
  163. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  164. }
  165. HttpStatusCode statusCode = httpResponse.StatusCode;
  166. if (statusCode != HttpStatusCode.OK)
  167. {
  168. cancellationToken.ThrowIfCancellationRequested();
  169. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  170. if (shouldTrace)
  171. {
  172. TracingAdapter.Error(invocationId, ex);
  173. }
  174. throw ex;
  175. }
  176. // Create Result
  177. AzureOperationResponse result = null;
  178. // Deserialize Response
  179. result = new AzureOperationResponse();
  180. result.StatusCode = statusCode;
  181. if (httpResponse.Headers.Contains("x-ms-request-id"))
  182. {
  183. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  184. }
  185. if (shouldTrace)
  186. {
  187. TracingAdapter.Exit(invocationId, result);
  188. }
  189. return result;
  190. }
  191. finally
  192. {
  193. if (httpResponse != null)
  194. {
  195. httpResponse.Dispose();
  196. }
  197. }
  198. }
  199. finally
  200. {
  201. if (httpRequest != null)
  202. {
  203. httpRequest.Dispose();
  204. }
  205. }
  206. }
  207. /// <summary>
  208. /// Backups a site on-demand.
  209. /// </summary>
  210. /// <param name='webSpaceName'>
  211. /// Required. The name of the web space.
  212. /// </param>
  213. /// <param name='webSiteName'>
  214. /// Required. The name of the web site.
  215. /// </param>
  216. /// <param name='backupRequest'>
  217. /// Required. A backup specification.
  218. /// </param>
  219. /// <param name='cancellationToken'>
  220. /// Cancellation token.
  221. /// </param>
  222. /// <returns>
  223. /// The backup record created based on the backup request.
  224. /// </returns>
  225. public async Task<WebSiteBackupResponse> BackupAsync(string webSpaceName, string webSiteName, BackupRequest backupRequest, CancellationToken cancellationToken)
  226. {
  227. // Validate
  228. if (webSpaceName == null)
  229. {
  230. throw new ArgumentNullException("webSpaceName");
  231. }
  232. if (webSiteName == null)
  233. {
  234. throw new ArgumentNullException("webSiteName");
  235. }
  236. if (backupRequest == null)
  237. {
  238. throw new ArgumentNullException("backupRequest");
  239. }
  240. // Tracing
  241. bool shouldTrace = TracingAdapter.IsEnabled;
  242. string invocationId = null;
  243. if (shouldTrace)
  244. {
  245. invocationId = TracingAdapter.NextInvocationId.ToString();
  246. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  247. tracingParameters.Add("webSpaceName", webSpaceName);
  248. tracingParameters.Add("webSiteName", webSiteName);
  249. tracingParameters.Add("backupRequest", backupRequest);
  250. TracingAdapter.Enter(invocationId, this, "BackupAsync", tracingParameters);
  251. }
  252. // Construct URL
  253. string url = "";
  254. url = url + "/";
  255. if (this.Client.Credentials.SubscriptionId != null)
  256. {
  257. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  258. }
  259. url = url + "/services/WebSpaces/";
  260. url = url + Uri.EscapeDataString(webSpaceName);
  261. url = url + "/sites/";
  262. url = url + Uri.EscapeDataString(webSiteName);
  263. url = url + "/backup";
  264. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  265. // Trim '/' character from the end of baseUrl and beginning of url.
  266. if (baseUrl[baseUrl.Length - 1] == '/')
  267. {
  268. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  269. }
  270. if (url[0] == '/')
  271. {
  272. url = url.Substring(1);
  273. }
  274. url = baseUrl + "/" + url;
  275. url = url.Replace(" ", "%20");
  276. // Create HTTP transport objects
  277. HttpRequestMessage httpRequest = null;
  278. try
  279. {
  280. httpRequest = new HttpRequestMessage();
  281. httpRequest.Method = HttpMethod.Put;
  282. httpRequest.RequestUri = new Uri(url);
  283. // Set Headers
  284. httpRequest.Headers.Add("x-ms-version", "2014-04-01");
  285. // Set Credentials
  286. cancellationToken.ThrowIfCancellationRequested();
  287. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  288. // Serialize Request
  289. string requestContent = null;
  290. XDocument requestDoc = new XDocument();
  291. XElement backupRequestElement = new XElement(XName.Get("BackupRequest", "http://schemas.microsoft.com/windowsazure"));
  292. requestDoc.Add(backupRequestElement);
  293. if (backupRequest.BackupSchedule != null)
  294. {
  295. XElement backupScheduleElement = new XElement(XName.Get("BackupSchedule", "http://schemas.microsoft.com/windowsazure"));
  296. backupRequestElement.Add(backupScheduleElement);
  297. XElement frequencyIntervalElement = new XElement(XName.Get("FrequencyInterval", "http://schemas.microsoft.com/windowsazure"));
  298. frequencyIntervalElement.Value = backupRequest.BackupSchedule.FrequencyInterval.ToString();
  299. backupScheduleElement.Add(frequencyIntervalElement);
  300. XElement frequencyUnitElement = new XElement(XName.Get("FrequencyUnit", "http://schemas.microsoft.com/windowsazure"));
  301. frequencyUnitElement.Value = backupRequest.BackupSchedule.FrequencyUnit.ToString();
  302. backupScheduleElement.Add(frequencyUnitElement);
  303. XElement keepAtLeastOneBackupElement = new XElement(XName.Get("KeepAtLeastOneBackup", "http://schemas.microsoft.com/windowsazure"));
  304. keepAtLeastOneBackupElement.Value = backupRequest.BackupSchedule.KeepAtLeastOneBackup.ToString().ToLower();
  305. backupScheduleElement.Add(keepAtLeastOneBackupElement);
  306. if (backupRequest.BackupSchedule.LastExecutionTime != null)
  307. {
  308. XElement lastExecutionTimeElement = new XElement(XName.Get("LastExecutionTime", "http://schemas.microsoft.com/windowsazure"));
  309. lastExecutionTimeElement.Value = string.Format(CultureInfo.InvariantCulture, "{0:O}", backupRequest.BackupSchedule.LastExecutionTime.Value.ToUniversalTime());
  310. backupScheduleElement.Add(lastExecutionTimeElement);
  311. }
  312. XElement retentionPeriodInDaysElement = new XElement(XName.Get("RetentionPeriodInDays", "http://schemas.microsoft.com/windowsazure"));
  313. retentionPeriodInDaysElement.Value = backupRequest.BackupSchedule.RetentionPeriodInDays.ToString();
  314. backupScheduleElement.Add(retentionPeriodInDaysElement);
  315. if (backupRequest.BackupSchedule.StartTime != null)
  316. {
  317. XElement startTimeElement = new XElement(XName.Get("StartTime", "http://schemas.microsoft.com/windowsazure"));
  318. startTimeElement.Value = string.Format(CultureInfo.InvariantCulture, "{0:O}", backupRequest.BackupSchedule.StartTime.Value.ToUniversalTime());
  319. backupScheduleElement.Add(startTimeElement);
  320. }
  321. }
  322. if (backupRequest.Databases != null)
  323. {
  324. if (backupRequest.Databases is ILazyCollection == false || ((ILazyCollection)backupRequest.Databases).IsInitialized)
  325. {
  326. XElement databasesSequenceElement = new XElement(XName.Get("Databases", "http://schemas.microsoft.com/windowsazure"));
  327. foreach (DatabaseBackupSetting databasesItem in backupRequest.Databases)
  328. {
  329. XElement databaseBackupSettingElement = new XElement(XName.Get("DatabaseBackupSetting", "http://schemas.microsoft.com/windowsazure"));
  330. databasesSequenceElement.Add(databaseBackupSettingElement);
  331. if (databasesItem.ConnectionString != null)
  332. {
  333. XElement connectionStringElement = new XElement(XName.Get("ConnectionString", "http://schemas.microsoft.com/windowsazure"));
  334. connectionStringElement.Value = databasesItem.ConnectionString;
  335. databaseBackupSettingElement.Add(connectionStringElement);
  336. }
  337. if (databasesItem.ConnectionStringName != null)
  338. {
  339. XElement connectionStringNameElement = new XElement(XName.Get("ConnectionStringName", "http://schemas.microsoft.com/windowsazure"));
  340. connectionStringNameElement.Value = databasesItem.ConnectionStringName;
  341. databaseBackupSettingElement.Add(connectionStringNameElement);
  342. }
  343. if (databasesItem.DatabaseType != null)
  344. {
  345. XElement databaseTypeElement = new XElement(XName.Get("DatabaseType", "http://schemas.microsoft.com/windowsazure"));
  346. databaseTypeElement.Value = databasesItem.DatabaseType;
  347. databaseBackupSettingElement.Add(databaseTypeElement);
  348. }
  349. if (databasesItem.Name != null)
  350. {
  351. XElement nameElement = new XElement(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
  352. nameElement.Value = databasesItem.Name;
  353. databaseBackupSettingElement.Add(nameElement);
  354. }
  355. }
  356. backupRequestElement.Add(databasesSequenceElement);
  357. }
  358. }
  359. if (backupRequest.Enabled != null)
  360. {
  361. XElement enabledElement = new XElement(XName.Get("Enabled", "http://schemas.microsoft.com/windowsazure"));
  362. enabledElement.Value = backupRequest.Enabled.ToString().ToLower();
  363. backupRequestElement.Add(enabledElement);
  364. }
  365. if (backupRequest.Name != null)
  366. {
  367. XElement nameElement2 = new XElement(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
  368. nameElement2.Value = backupRequest.Name;
  369. backupRequestElement.Add(nameElement2);
  370. }
  371. if (backupRequest.StorageAccountUrl != null)
  372. {
  373. XElement storageAccountUrlElement = new XElement(XName.Get("StorageAccountUrl", "http://schemas.microsoft.com/windowsazure"));
  374. storageAccountUrlElement.Value = backupRequest.StorageAccountUrl;
  375. backupRequestElement.Add(storageAccountUrlElement);
  376. }
  377. requestContent = requestDoc.ToString();
  378. httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
  379. httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/xml");
  380. // Send Request
  381. HttpResponseMessage httpResponse = null;
  382. try
  383. {
  384. if (shouldTrace)
  385. {
  386. TracingAdapter.SendRequest(invocationId, httpRequest);
  387. }
  388. cancellationToken.ThrowIfCancellationRequested();
  389. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  390. if (shouldTrace)
  391. {
  392. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  393. }
  394. HttpStatusCode statusCode = httpResponse.StatusCode;
  395. if (statusCode != HttpStatusCode.OK)
  396. {
  397. cancellationToken.ThrowIfCancellationRequested();
  398. CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  399. if (shouldTrace)
  400. {
  401. TracingAdapter.Error(invocationId, ex);
  402. }
  403. throw ex;
  404. }
  405. // Create Result
  406. WebSiteBackupResponse result = null;
  407. // Deserialize Response
  408. if (statusCode == HttpStatusCode.OK)
  409. {
  410. cancellationToken.ThrowIfCancellationRequested();
  411. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  412. result = new WebSiteBackupResponse();
  413. XDocument responseDoc = XDocument.Parse(responseContent);
  414. XElement backupItemElement = responseDoc.Element(XName.Get("BackupItem", "http://schemas.microsoft.com/windowsazure"));
  415. if (backupItemElement != null)
  416. {
  417. BackupItem backupItemInstance = new BackupItem();
  418. result.BackupItem = backupItemInstance;
  419. XElement storageAccountUrlElement2 = backupItemElement.Element(XName.Get("StorageAccountUrl", "http://schemas.microsoft.com/windowsazure"));
  420. if (storageAccountUrlElement2 != null)
  421. {
  422. string storageAccountUrlInstance = storageAccountUrlElement2.Value;
  423. backupItemInstance.StorageAccountUrl = storageAccountUrlInstance;
  424. }
  425. XElement blobNameElement = backupItemElement.Element(XName.Get("BlobName", "http://schemas.microsoft.com/windowsazure"));
  426. if (blobNameElement != null)
  427. {
  428. string blobNameInstance = blobNameElement.Value;
  429. backupItemInstance.BlobName = blobNameInstance;
  430. }
  431. XElement nameElement3 = backupItemElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
  432. if (nameElement3 != null)
  433. {
  434. string nameInstance = nameElement3.Value;
  435. backupItemInstance.Name = nameInstance;
  436. }
  437. XElement statusElement = backupItemElement.Element(XName.Get("Status", "http://schemas.microsoft.com/windowsazure"));
  438. if (statusElement != null)
  439. {
  440. BackupItemStatus statusInstance = ((BackupItemStatus)Enum.Parse(typeof(BackupItemStatus), statusElement.Value, true));
  441. backupItemInstance.Status = statusInstance;
  442. }
  443. XElement sizeInBytesElement = backupItemElement.Element(XName.Get("SizeInBytes", "http://schemas.microsoft.com/windowsazure"));
  444. if (sizeInBytesElement != null)
  445. {
  446. long sizeInBytesInstance = long.Parse(sizeInBytesElement.Value, CultureInfo.InvariantCulture);
  447. backupItemInstance.SizeInBytes = sizeInBytesInstance;
  448. }
  449. XElement createdElement = backupItemElement.Element(XName.Get("Created", "http://schemas.microsoft.com/windowsazure"));
  450. if (createdElement != null && !string.IsNullOrEmpty(createdElement.Value))
  451. {
  452. DateTime createdInstance = DateTime.Parse(createdElement.Value, CultureInfo.InvariantCulture);
  453. backupItemInstance.Created = createdInstance;
  454. }
  455. XElement logElement = backupItemElement.Element(XName.Get("Log", "http://schemas.microsoft.com/windowsazure"));
  456. if (logElement != null)
  457. {
  458. string logInstance = logElement.Value;
  459. backupItemInstance.Log = logInstance;
  460. }
  461. XElement databasesSequenceElement2 = backupItemElement.Element(XName.Get("Databases", "http://schemas.microsoft.com/windowsazure"));
  462. if (databasesSequenceElement2 != null)
  463. {
  464. foreach (XElement databasesElement in databasesSequenceElement2.Elements(XName.Get("DatabaseBackupSetting", "http://schemas.microsoft.com/windowsazure")))
  465. {
  466. DatabaseBackupSetting databaseBackupSettingInstance = new DatabaseBackupSetting();
  467. backupItemInstance.Databases.Add(databaseBackupSettingInstance);
  468. XElement connectionStringElement2 = databasesElement.Element(XName.Get("ConnectionString", "http://schemas.microsoft.com/windowsazure"));
  469. if (connectionStringElement2 != null)
  470. {
  471. string connectionStringInstance = connectionStringElement2.Value;
  472. databaseBackupSettingInstance.ConnectionString = connectionStringInstance;
  473. }
  474. XElement connectionStringNameElement2 = databasesElement.Element(XName.Get("ConnectionStringName", "http://schemas.microsoft.com/windowsazure"));
  475. if (connectionStringNameElement2 != null)
  476. {
  477. string connectionStringNameInstance = connectionStringNameElement2.Value;
  478. databaseBackupSettingInstance.ConnectionStringName = connectionStringNameInstance;
  479. }
  480. XElement databaseTypeElement2 = databasesElement.Element(XName.Get("DatabaseType", "http://schemas.microsoft.com/windowsazure"));
  481. if (databaseTypeElement2 != null)
  482. {
  483. string databaseTypeInstance = databaseTypeElement2.Value;
  484. databaseBackupSettingInstance.DatabaseType = databaseTypeInstance;
  485. }
  486. XElement nameElement4 = databasesElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
  487. if (nameElement4 != null)
  488. {
  489. string nameInstance2 = nameElement4.Value;
  490. databaseBackupSettingInstance.Name = nameInstance2;
  491. }
  492. }
  493. }
  494. XElement scheduledElement = backupItemElement.Element(XName.Get("Scheduled", "http://schemas.microsoft.com/windowsazure"));
  495. if (scheduledElement != null)
  496. {
  497. bool scheduledInstance = bool.Parse(scheduledElement.Value);
  498. backupItemInstance.Scheduled = scheduledInstance;
  499. }
  500. XElement lastRestoreTimeStampElement = backupItemElement.Element(XName.Get("LastRestoreTimeStamp", "http://schemas.microsoft.com/windowsazure"));
  501. if (lastRestoreTimeStampElement != null && !string.IsNullOrEmpty(lastRestoreTimeStampElement.Value))
  502. {
  503. DateTime lastRestoreTimeStampInstance = DateTime.Parse(lastRestoreTimeStampElement.Value, CultureInfo.InvariantCulture);
  504. backupItemInstance.LastRestoreTimeStamp = lastRestoreTimeStampInstance;
  505. }
  506. XElement finishedTimeStampElement = backupItemElement.Element(XName.Get("FinishedTimeStamp", "http://schemas.microsoft.com/windowsazure"));
  507. if (finishedTimeStampElement != null && !string.IsNullOrEmpty(finishedTimeStampElement.Value))
  508. {
  509. DateTime finishedTimeStampInstance = DateTime.Parse(finishedTimeStampElement.Value, CultureInfo.InvariantCulture);
  510. backupItemInstance.FinishedTimeStamp = finishedTimeStampInstance;
  511. }
  512. XElement correlationIdElement = backupItemElement.Element(XName.Get("CorrelationId", "http://schemas.microsoft.com/windowsazure"));
  513. if (correlationIdElement != null)
  514. {
  515. string correlationIdInstance = correlationIdElement.Value;
  516. backupItemInstance.CorrelationId = correlationIdInstance;
  517. }
  518. }
  519. }
  520. result.StatusCode = statusCode;
  521. if (httpResponse.Headers.Contains("x-ms-request-id"))
  522. {
  523. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  524. }
  525. if (shouldTrace)
  526. {
  527. TracingAdapter.Exit(invocationId, result);
  528. }
  529. return result;
  530. }
  531. finally
  532. {
  533. if (httpResponse != null)
  534. {
  535. httpResponse.Dispose();
  536. }
  537. }
  538. }
  539. finally
  540. {
  541. if (httpRequest != null)
  542. {
  543. httpRequest.Dispose();
  544. }
  545. }
  546. }
  547. /// <summary>
  548. /// You can swap a web site from one slot to another slot.
  549. /// </summary>
  550. /// <param name='webSpaceName'>
  551. /// Required. The name of the web space.
  552. /// </param>
  553. /// <param name='webSiteName'>
  554. /// Required. The name of the web site.
  555. /// </param>
  556. /// <param name='sourceSlotName'>
  557. /// Required. The name of the first web site slot to swap (source).
  558. /// </param>
  559. /// <param name='targetSlotName'>
  560. /// Required. The name of the second web site slot to swap with
  561. /// (target).
  562. /// </param>
  563. /// <param name='cancellationToken'>
  564. /// Cancellation token.
  565. /// </param>
  566. /// <returns>
  567. /// The response body contains the status of the specified long-running
  568. /// operation, indicating whether it has succeeded, is inprogress, has
  569. /// timed out, or has failed. Note that this status is distinct from
  570. /// the HTTP status code returned for the Get Operation Status
  571. /// operation itself. If the long-running operation failed, the
  572. /// response body includes error information regarding the failure.
  573. /// </returns>
  574. public async Task<WebSiteOperationStatusResponse> BeginSwappingSlotsAsync(string webSpaceName, string webSiteName, string sourceSlotName, string targetSlotName, CancellationToken cancellationToken)
  575. {
  576. // Validate
  577. if (webSpaceName == null)
  578. {
  579. throw new ArgumentNullException("webSpaceName");
  580. }
  581. if (webSiteName == null)
  582. {
  583. throw new ArgumentNullException("webSiteName");
  584. }
  585. if (sourceSlotName == null)
  586. {
  587. throw new ArgumentNullException("sourceSlotName");
  588. }
  589. if (targetSlotName == null)
  590. {
  591. throw new ArgumentNullException("targetSlotName");
  592. }
  593. // Tracing
  594. bool shouldTrace = TracingAdapter.IsEnabled;
  595. string invocationId = null;
  596. if (shouldTrace)
  597. {
  598. invocationId = TracingAdapter.NextInvocationId.ToString();
  599. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  600. tracingParameters.Add("webSpaceName", webSpaceName);
  601. tracingParameters.Add("webSiteName", webSiteName);
  602. tracingParameters.Add("sourceSlotName", sourceSlotName);
  603. tracingParameters.Add("targetSlotName", targetSlotName);
  604. TracingAdapter.Enter(invocationId, this, "BeginSwappingSlotsAsync", tracingParameters);
  605. }
  606. // Construct URL
  607. string url = "";
  608. url = url + "/";
  609. if (this.Client.Credentials.SubscriptionId != null)
  610. {
  611. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  612. }
  613. url = url + "/services/WebSpaces/";
  614. url = url + Uri.EscapeDataString(webSpaceName);
  615. url = url + "/sites/";
  616. url = url + Uri.EscapeDataString(webSiteName);
  617. url = url + "(";
  618. url = url + Uri.EscapeDataString(sourceSlotName);
  619. url = url + ")/slots";
  620. List<string> queryParameters = new List<string>();
  621. queryParameters.Add("Command=swap");
  622. queryParameters.Add("targetSlot=" + Uri.EscapeDataString(targetSlotName));
  623. if (queryParameters.Count > 0)
  624. {
  625. url = url + "?" + string.Join("&", queryParameters);
  626. }
  627. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  628. // Trim '/' character from the end of baseUrl and beginning of url.
  629. if (baseUrl[baseUrl.Length - 1] == '/')
  630. {
  631. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  632. }
  633. if (url[0] == '/')
  634. {
  635. url = url.Substring(1);
  636. }
  637. url = baseUrl + "/" + url;
  638. url = url.Replace(" ", "%20");
  639. // Create HTTP transport objects
  640. HttpRequestMessage httpRequest = null;
  641. try
  642. {
  643. httpRequest = new HttpRequestMessage();
  644. httpRequest.Method = HttpMethod.Post;
  645. httpRequest.RequestUri = new Uri(url);
  646. // Set Headers
  647. httpRequest.Headers.Add("x-ms-version", "2014-04-01");
  648. // Set Credentials
  649. cancellationToken.ThrowIfCancellationRequested();
  650. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  651. // Send Request
  652. HttpResponseMessage httpResponse = null;
  653. try
  654. {
  655. if (shouldTrace)
  656. {
  657. TracingAdapter.SendRequest(invocationId, httpRequest);
  658. }
  659. cancellationToken.ThrowIfCancellationRequested();
  660. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  661. if (shouldTrace)
  662. {
  663. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  664. }
  665. HttpStatusCode statusCode = httpResponse.StatusCode;
  666. if (statusCode != HttpStatusCode.OK)
  667. {
  668. cancellationToken.ThrowIfCancellationRequested();
  669. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  670. if (shouldTrace)
  671. {
  672. TracingAdapter.Error(invocationId, ex);
  673. }
  674. throw ex;
  675. }
  676. // Create Result
  677. WebSiteOperationStatusResponse result = null;
  678. // Deserialize Response
  679. if (statusCode == HttpStatusCode.OK)
  680. {
  681. cancellationToken.ThrowIfCancellationRequested();
  682. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  683. result = new WebSiteOperationStatusResponse();
  684. XDocument responseDoc = XDocument.Parse(responseContent);
  685. XElement operationElement = responseDoc.Element(XName.Get("Operation", "http://schemas.microsoft.com/windowsazure"));
  686. if (operationElement != null)
  687. {
  688. XElement createdTimeElement = operationElement.Element(XName.Get("CreatedTime", "http://schemas.microsoft.com/windowsazure"));
  689. if (createdTimeElement != null)
  690. {
  691. DateTime createdTimeInstance = DateTime.Parse(createdTimeElement.Value, CultureInfo.InvariantCulture);
  692. result.CreatedTime = createdTimeInstance;
  693. }
  694. XElement errorsSequenceElement = operationElement.Element(XName.Get("Errors", "http://schemas.microsoft.com/windowsazure"));
  695. if (errorsSequenceElement != null)
  696. {
  697. bool isNil = false;
  698. XAttribute nilAttribute = errorsSequenceElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
  699. if (nilAttribute != null)
  700. {
  701. isNil = nilAttribute.Value == "true";
  702. }
  703. if (isNil == false)
  704. {
  705. foreach (XElement errorsElement in errorsSequenceElement.Elements(XName.Get("Error", "http://schemas.microsoft.com/windowsazure")))
  706. {
  707. WebSiteOperationStatusResponse.Error errorInstance = new WebSiteOperationStatusResponse.Error();
  708. result.Errors.Add(errorInstance);
  709. XElement codeElement = errorsElement.Element(XName.Get("Code", "http://schemas.microsoft.com/windowsazure"));
  710. if (codeElement != null)
  711. {
  712. bool isNil2 = false;
  713. XAttribute nilAttribute2 = codeElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
  714. if (nilAttribute2 != null)
  715. {
  716. isNil2 = nilAttribute2.Value == "true";
  717. }
  718. if (isNil2 == false)
  719. {
  720. string codeInstance = codeElement.Value;
  721. errorInstance.Code = codeInstance;
  722. }
  723. }
  724. XElement messageElement = errorsElement.Element(XName.Get("Message", "http://schemas.microsoft.com/windowsazure"));
  725. if (messageElement != null)
  726. {
  727. bool isNil3 = false;
  728. XAttribute nilAttribute3 = messageElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
  729. if (nilAttribute3 != null)
  730. {
  731. isNil3 = nilAttribute3.Value == "true";
  732. }
  733. if (isNil3 == false)
  734. {
  735. string messageInstance = messageElement.Value;
  736. errorInstance.Message = messageInstance;
  737. }
  738. }
  739. XElement extendedCodeElement = errorsElement.Element(XName.Get("ExtendedCode", "http://schemas.microsoft.com/windowsazure"));
  740. if (extendedCodeElement != null)
  741. {
  742. bool isNil4 = false;
  743. XAttribute nilAttribute4 = extendedCodeElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
  744. if (nilAttribute4 != null)
  745. {
  746. isNil4 = nilAttribute4.Value == "true";
  747. }
  748. if (isNil4 == false)
  749. {
  750. string extendedCodeInstance = extendedCodeElement.Value;
  751. errorInstance.ExtendedCode = extendedCodeInstance;
  752. }
  753. }
  754. XElement messageTemplateElement = errorsElement.Element(XName.Get("MessageTemplate", "http://schemas.microsoft.com/windowsazure"));
  755. if (messageTemplateElement != null)
  756. {
  757. bool isNil5 = false;
  758. XAttribute nilAttribute5 = messageTemplateElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
  759. if (nilAttribute5 != null)
  760. {
  761. isNil5 = nilAttribute5.Value == "true";
  762. }
  763. if (isNil5 == false)
  764. {
  765. string messageTemplateInstance = messageTemplateElement.Value;
  766. errorInstance.MessageTemplate = messageTemplateInstance;
  767. }
  768. }
  769. XElement parametersSequenceElement = errorsElement.Element(XName.Get("Parameters", "http://schemas.microsoft.com/windowsazure"));
  770. if (parametersSequenceElement != null)
  771. {
  772. bool isNil6 = false;
  773. XAttribute nilAttribute6 = parametersSequenceElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
  774. if (nilAttribute6 != null)
  775. {
  776. isNil6 = nilAttribute6.Value == "true";
  777. }
  778. if (isNil6 == false)
  779. {
  780. foreach (XElement parametersElement in parametersSequenceElement.Elements(XName.Get("string", "http://schemas.microsoft.com/2003/10/Serialization/Arrays")))
  781. {
  782. errorInstance.Parameters.Add(parametersElement.Value);
  783. }
  784. }
  785. else
  786. {
  787. errorInstance.Parameters = null;
  788. }
  789. }
  790. XElement innerErrorsElement = errorsElement.Element(XName.Get("InnerErrors", "http://schemas.microsoft.com/windowsazure"));
  791. if (innerErrorsElement != null)
  792. {
  793. bool isNil7 = false;
  794. XAttribute nilAttribute7 = innerErrorsElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
  795. if (nilAttribute7 != null)
  796. {
  797. isNil7 = nilAttribute7.Value == "true";
  798. }
  799. if (isNil7 == false)
  800. {
  801. string innerErrorsInstance = innerErrorsElement.Value;
  802. errorInstance.InnerErrors = innerErrorsInstance;
  803. }
  804. }
  805. }
  806. }
  807. else
  808. {
  809. result.Errors = null;
  810. }
  811. }
  812. XElement expirationTimeElement = operationElement.Element(XName.Get("ExpirationTime", "http://schemas.microsoft.com/windowsazure"));
  813. if (expirationTimeElement != null)
  814. {
  815. DateTime expirationTimeInstance = DateTime.Parse(expirationTimeElement.Value, CultureInfo.InvariantCulture);
  816. result.ExpirationTime = expirationTimeInstance;
  817. }
  818. XElement geoMasterOperationIdElement = operationElement.Element(XName.Get("GeoMasterOperationId", "http://schemas.microsoft.com/windowsazure"));
  819. if (geoMasterOperationIdElement != null)
  820. {
  821. bool isNil8 = false;
  822. XAttribute nilAttribute8 = geoMasterOperationIdElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
  823. if (nilAttribute8 != null)
  824. {
  825. isNil8 = nilAttribute8.Value == "true";
  826. }
  827. if (isNil8 == false)
  828. {
  829. string geoMasterOperationIdInstance = geoMasterOperationIdElement.Value;
  830. result.GeoMasterOperationId = geoMasterOperationIdInstance;
  831. }
  832. }
  833. XElement idElement = operationElement.Element(XName.Get("Id", "http://schemas.microsoft.com/windowsazure"));
  834. if (idElement != null)
  835. {
  836. bool isNil9 = false;
  837. XAttribute nilAttribute9 = idElement.Attribut

Large files files are truncated, but you can click here to view the full file