PageRenderTime 66ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 3ms

/src/WebSiteManagement2/Generated/WebSiteOperations.cs

https://github.com/edumunoz/azure-sdk-for-net
C# | 9288 lines | 7390 code | 875 blank | 1023 comment | 2881 complexity | 19364238039f91d3ea332dc8a6ac8162 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.Azure.Management.WebSites;
  35. using Microsoft.Azure.Management.WebSites.Models;
  36. using Newtonsoft.Json.Linq;
  37. namespace Microsoft.Azure.Management.WebSites
  38. {
  39. /// <summary>
  40. /// Operations for managing the web sites in a web space.
  41. /// </summary>
  42. internal partial class WebSiteOperations : IServiceOperations<WebSiteManagementClient>, IWebSiteOperations
  43. {
  44. /// <summary>
  45. /// Initializes a new instance of the WebSiteOperations class.
  46. /// </summary>
  47. /// <param name='client'>
  48. /// Reference to the service client.
  49. /// </param>
  50. internal WebSiteOperations(WebSiteManagementClient client)
  51. {
  52. this._client = client;
  53. }
  54. private WebSiteManagementClient _client;
  55. /// <summary>
  56. /// Gets a reference to the
  57. /// Microsoft.Azure.Management.WebSites.WebSiteManagementClient.
  58. /// </summary>
  59. public WebSiteManagementClient Client
  60. {
  61. get { return this._client; }
  62. }
  63. /// <summary>
  64. /// Backups a site on-demand.
  65. /// </summary>
  66. /// <param name='resourceGroupName'>
  67. /// Required. The name of the web space.
  68. /// </param>
  69. /// <param name='webSiteName'>
  70. /// Required. The name of the web site.
  71. /// </param>
  72. /// <param name='slotName'>
  73. /// Optional. The name of the slot.
  74. /// </param>
  75. /// <param name='backupRequestEnvelope'>
  76. /// Required. A backup specification.
  77. /// </param>
  78. /// <param name='cancellationToken'>
  79. /// Cancellation token.
  80. /// </param>
  81. /// <returns>
  82. /// The backup record created based on the backup request.
  83. /// </returns>
  84. public async Task<WebSiteBackupResponse> BackupAsync(string resourceGroupName, string webSiteName, string slotName, BackupRequestEnvelope backupRequestEnvelope, CancellationToken cancellationToken)
  85. {
  86. // Validate
  87. if (resourceGroupName == null)
  88. {
  89. throw new ArgumentNullException("resourceGroupName");
  90. }
  91. if (webSiteName == null)
  92. {
  93. throw new ArgumentNullException("webSiteName");
  94. }
  95. if (backupRequestEnvelope == null)
  96. {
  97. throw new ArgumentNullException("backupRequestEnvelope");
  98. }
  99. if (backupRequestEnvelope.Location == null)
  100. {
  101. throw new ArgumentNullException("backupRequestEnvelope.Location");
  102. }
  103. // Tracing
  104. bool shouldTrace = TracingAdapter.IsEnabled;
  105. string invocationId = null;
  106. if (shouldTrace)
  107. {
  108. invocationId = TracingAdapter.NextInvocationId.ToString();
  109. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  110. tracingParameters.Add("resourceGroupName", resourceGroupName);
  111. tracingParameters.Add("webSiteName", webSiteName);
  112. tracingParameters.Add("slotName", slotName);
  113. tracingParameters.Add("backupRequestEnvelope", backupRequestEnvelope);
  114. TracingAdapter.Enter(invocationId, this, "BackupAsync", tracingParameters);
  115. }
  116. // Construct URL
  117. string url = "";
  118. url = url + "/subscriptions/";
  119. if (this.Client.Credentials.SubscriptionId != null)
  120. {
  121. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  122. }
  123. url = url + "/resourceGroups/";
  124. url = url + Uri.EscapeDataString(resourceGroupName);
  125. url = url + "/providers/";
  126. url = url + "Microsoft.Web";
  127. url = url + "/";
  128. url = url + "sites";
  129. url = url + "/";
  130. url = url + Uri.EscapeDataString(webSiteName);
  131. if (slotName != null)
  132. {
  133. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  134. }
  135. url = url + "/backup";
  136. List<string> queryParameters = new List<string>();
  137. queryParameters.Add("api-version=2014-06-01");
  138. if (queryParameters.Count > 0)
  139. {
  140. url = url + "?" + string.Join("&", queryParameters);
  141. }
  142. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  143. // Trim '/' character from the end of baseUrl and beginning of url.
  144. if (baseUrl[baseUrl.Length - 1] == '/')
  145. {
  146. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  147. }
  148. if (url[0] == '/')
  149. {
  150. url = url.Substring(1);
  151. }
  152. url = baseUrl + "/" + url;
  153. url = url.Replace(" ", "%20");
  154. // Create HTTP transport objects
  155. HttpRequestMessage httpRequest = null;
  156. try
  157. {
  158. httpRequest = new HttpRequestMessage();
  159. httpRequest.Method = HttpMethod.Put;
  160. httpRequest.RequestUri = new Uri(url);
  161. // Set Headers
  162. httpRequest.Headers.Add("x-ms-version", "2014-06-01");
  163. // Set Credentials
  164. cancellationToken.ThrowIfCancellationRequested();
  165. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  166. // Serialize Request
  167. string requestContent = null;
  168. JToken requestDoc = null;
  169. JObject backupRequestEnvelopeValue = new JObject();
  170. requestDoc = backupRequestEnvelopeValue;
  171. if (backupRequestEnvelope.Request != null)
  172. {
  173. JObject propertiesValue = new JObject();
  174. backupRequestEnvelopeValue["properties"] = propertiesValue;
  175. if (backupRequestEnvelope.Request.BackupSchedule != null)
  176. {
  177. JObject backupScheduleValue = new JObject();
  178. propertiesValue["backupSchedule"] = backupScheduleValue;
  179. backupScheduleValue["frequencyInterval"] = backupRequestEnvelope.Request.BackupSchedule.FrequencyInterval;
  180. backupScheduleValue["frequencyUnit"] = backupRequestEnvelope.Request.BackupSchedule.FrequencyUnit.ToString();
  181. backupScheduleValue["keepAtLeastOneBackup"] = backupRequestEnvelope.Request.BackupSchedule.KeepAtLeastOneBackup;
  182. if (backupRequestEnvelope.Request.BackupSchedule.LastExecutionTime != null)
  183. {
  184. backupScheduleValue["lastExecutionTime"] = backupRequestEnvelope.Request.BackupSchedule.LastExecutionTime.Value;
  185. }
  186. backupScheduleValue["retentionPeriodInDays"] = backupRequestEnvelope.Request.BackupSchedule.RetentionPeriodInDays;
  187. if (backupRequestEnvelope.Request.BackupSchedule.StartTime != null)
  188. {
  189. backupScheduleValue["startTime"] = backupRequestEnvelope.Request.BackupSchedule.StartTime.Value;
  190. }
  191. }
  192. if (backupRequestEnvelope.Request.Databases != null)
  193. {
  194. if (backupRequestEnvelope.Request.Databases is ILazyCollection == false || ((ILazyCollection)backupRequestEnvelope.Request.Databases).IsInitialized)
  195. {
  196. JArray databasesArray = new JArray();
  197. foreach (DatabaseBackupSetting databasesItem in backupRequestEnvelope.Request.Databases)
  198. {
  199. JObject databaseBackupSettingValue = new JObject();
  200. databasesArray.Add(databaseBackupSettingValue);
  201. if (databasesItem.ConnectionString != null)
  202. {
  203. databaseBackupSettingValue["connectionString"] = databasesItem.ConnectionString;
  204. }
  205. if (databasesItem.ConnectionStringName != null)
  206. {
  207. databaseBackupSettingValue["connectionStringName"] = databasesItem.ConnectionStringName;
  208. }
  209. if (databasesItem.DatabaseType != null)
  210. {
  211. databaseBackupSettingValue["databaseType"] = databasesItem.DatabaseType;
  212. }
  213. if (databasesItem.Name != null)
  214. {
  215. databaseBackupSettingValue["name"] = databasesItem.Name;
  216. }
  217. }
  218. propertiesValue["databases"] = databasesArray;
  219. }
  220. }
  221. if (backupRequestEnvelope.Request.Enabled != null)
  222. {
  223. propertiesValue["enabled"] = backupRequestEnvelope.Request.Enabled.Value;
  224. }
  225. if (backupRequestEnvelope.Request.Name != null)
  226. {
  227. propertiesValue["name"] = backupRequestEnvelope.Request.Name;
  228. }
  229. if (backupRequestEnvelope.Request.StorageAccountUrl != null)
  230. {
  231. propertiesValue["storageAccountUrl"] = backupRequestEnvelope.Request.StorageAccountUrl;
  232. }
  233. }
  234. if (backupRequestEnvelope.Id != null)
  235. {
  236. backupRequestEnvelopeValue["id"] = backupRequestEnvelope.Id;
  237. }
  238. if (backupRequestEnvelope.Name != null)
  239. {
  240. backupRequestEnvelopeValue["name"] = backupRequestEnvelope.Name;
  241. }
  242. backupRequestEnvelopeValue["location"] = backupRequestEnvelope.Location;
  243. if (backupRequestEnvelope.Tags != null)
  244. {
  245. JObject tagsDictionary = new JObject();
  246. foreach (KeyValuePair<string, string> pair in backupRequestEnvelope.Tags)
  247. {
  248. string tagsKey = pair.Key;
  249. string tagsValue = pair.Value;
  250. tagsDictionary[tagsKey] = tagsValue;
  251. }
  252. backupRequestEnvelopeValue["tags"] = tagsDictionary;
  253. }
  254. if (backupRequestEnvelope.Type != null)
  255. {
  256. backupRequestEnvelopeValue["type"] = backupRequestEnvelope.Type;
  257. }
  258. requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
  259. httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
  260. httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
  261. // Send Request
  262. HttpResponseMessage httpResponse = null;
  263. try
  264. {
  265. if (shouldTrace)
  266. {
  267. TracingAdapter.SendRequest(invocationId, httpRequest);
  268. }
  269. cancellationToken.ThrowIfCancellationRequested();
  270. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  271. if (shouldTrace)
  272. {
  273. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  274. }
  275. HttpStatusCode statusCode = httpResponse.StatusCode;
  276. if (statusCode != HttpStatusCode.OK)
  277. {
  278. cancellationToken.ThrowIfCancellationRequested();
  279. CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  280. if (shouldTrace)
  281. {
  282. TracingAdapter.Error(invocationId, ex);
  283. }
  284. throw ex;
  285. }
  286. // Create Result
  287. WebSiteBackupResponse result = null;
  288. // Deserialize Response
  289. if (statusCode == HttpStatusCode.OK)
  290. {
  291. cancellationToken.ThrowIfCancellationRequested();
  292. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  293. result = new WebSiteBackupResponse();
  294. JToken responseDoc = null;
  295. if (string.IsNullOrEmpty(responseContent) == false)
  296. {
  297. responseDoc = JToken.Parse(responseContent);
  298. }
  299. if (responseDoc != null && responseDoc.Type != JTokenType.Null)
  300. {
  301. BackupItemEnvelope backupItemInstance = new BackupItemEnvelope();
  302. result.BackupItem = backupItemInstance;
  303. JToken propertiesValue2 = responseDoc["properties"];
  304. if (propertiesValue2 != null && propertiesValue2.Type != JTokenType.Null)
  305. {
  306. BackupItem propertiesInstance = new BackupItem();
  307. backupItemInstance.Properties = propertiesInstance;
  308. JToken storageAccountUrlValue = propertiesValue2["storageAccountUrl"];
  309. if (storageAccountUrlValue != null && storageAccountUrlValue.Type != JTokenType.Null)
  310. {
  311. string storageAccountUrlInstance = ((string)storageAccountUrlValue);
  312. propertiesInstance.StorageAccountUrl = storageAccountUrlInstance;
  313. }
  314. JToken blobNameValue = propertiesValue2["blobName"];
  315. if (blobNameValue != null && blobNameValue.Type != JTokenType.Null)
  316. {
  317. string blobNameInstance = ((string)blobNameValue);
  318. propertiesInstance.BlobName = blobNameInstance;
  319. }
  320. JToken nameValue = propertiesValue2["name"];
  321. if (nameValue != null && nameValue.Type != JTokenType.Null)
  322. {
  323. string nameInstance = ((string)nameValue);
  324. propertiesInstance.Name = nameInstance;
  325. }
  326. JToken statusValue = propertiesValue2["status"];
  327. if (statusValue != null && statusValue.Type != JTokenType.Null)
  328. {
  329. BackupItemStatus statusInstance = ((BackupItemStatus)Enum.Parse(typeof(BackupItemStatus), ((string)statusValue), true));
  330. propertiesInstance.Status = statusInstance;
  331. }
  332. JToken sizeInBytesValue = propertiesValue2["sizeInBytes"];
  333. if (sizeInBytesValue != null && sizeInBytesValue.Type != JTokenType.Null)
  334. {
  335. long sizeInBytesInstance = ((long)sizeInBytesValue);
  336. propertiesInstance.SizeInBytes = sizeInBytesInstance;
  337. }
  338. JToken createdValue = propertiesValue2["created"];
  339. if (createdValue != null && createdValue.Type != JTokenType.Null)
  340. {
  341. DateTime createdInstance = ((DateTime)createdValue);
  342. propertiesInstance.Created = createdInstance;
  343. }
  344. JToken logValue = propertiesValue2["log"];
  345. if (logValue != null && logValue.Type != JTokenType.Null)
  346. {
  347. string logInstance = ((string)logValue);
  348. propertiesInstance.Log = logInstance;
  349. }
  350. JToken databasesArray2 = propertiesValue2["databases"];
  351. if (databasesArray2 != null && databasesArray2.Type != JTokenType.Null)
  352. {
  353. foreach (JToken databasesValue in ((JArray)databasesArray2))
  354. {
  355. DatabaseBackupSetting databaseBackupSettingInstance = new DatabaseBackupSetting();
  356. propertiesInstance.Databases.Add(databaseBackupSettingInstance);
  357. JToken connectionStringValue = databasesValue["connectionString"];
  358. if (connectionStringValue != null && connectionStringValue.Type != JTokenType.Null)
  359. {
  360. string connectionStringInstance = ((string)connectionStringValue);
  361. databaseBackupSettingInstance.ConnectionString = connectionStringInstance;
  362. }
  363. JToken connectionStringNameValue = databasesValue["connectionStringName"];
  364. if (connectionStringNameValue != null && connectionStringNameValue.Type != JTokenType.Null)
  365. {
  366. string connectionStringNameInstance = ((string)connectionStringNameValue);
  367. databaseBackupSettingInstance.ConnectionStringName = connectionStringNameInstance;
  368. }
  369. JToken databaseTypeValue = databasesValue["databaseType"];
  370. if (databaseTypeValue != null && databaseTypeValue.Type != JTokenType.Null)
  371. {
  372. string databaseTypeInstance = ((string)databaseTypeValue);
  373. databaseBackupSettingInstance.DatabaseType = databaseTypeInstance;
  374. }
  375. JToken nameValue2 = databasesValue["name"];
  376. if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
  377. {
  378. string nameInstance2 = ((string)nameValue2);
  379. databaseBackupSettingInstance.Name = nameInstance2;
  380. }
  381. }
  382. }
  383. JToken scheduledValue = propertiesValue2["scheduled"];
  384. if (scheduledValue != null && scheduledValue.Type != JTokenType.Null)
  385. {
  386. bool scheduledInstance = ((bool)scheduledValue);
  387. propertiesInstance.Scheduled = scheduledInstance;
  388. }
  389. JToken lastRestoreTimeStampValue = propertiesValue2["lastRestoreTimeStamp"];
  390. if (lastRestoreTimeStampValue != null && lastRestoreTimeStampValue.Type != JTokenType.Null)
  391. {
  392. DateTime lastRestoreTimeStampInstance = ((DateTime)lastRestoreTimeStampValue);
  393. propertiesInstance.LastRestoreTimeStamp = lastRestoreTimeStampInstance;
  394. }
  395. JToken finishedTimeStampValue = propertiesValue2["finishedTimeStamp"];
  396. if (finishedTimeStampValue != null && finishedTimeStampValue.Type != JTokenType.Null)
  397. {
  398. DateTime finishedTimeStampInstance = ((DateTime)finishedTimeStampValue);
  399. propertiesInstance.FinishedTimeStamp = finishedTimeStampInstance;
  400. }
  401. JToken correlationIdValue = propertiesValue2["correlationId"];
  402. if (correlationIdValue != null && correlationIdValue.Type != JTokenType.Null)
  403. {
  404. string correlationIdInstance = ((string)correlationIdValue);
  405. propertiesInstance.CorrelationId = correlationIdInstance;
  406. }
  407. }
  408. JToken idValue = responseDoc["id"];
  409. if (idValue != null && idValue.Type != JTokenType.Null)
  410. {
  411. string idInstance = ((string)idValue);
  412. backupItemInstance.Id = idInstance;
  413. }
  414. JToken nameValue3 = responseDoc["name"];
  415. if (nameValue3 != null && nameValue3.Type != JTokenType.Null)
  416. {
  417. string nameInstance3 = ((string)nameValue3);
  418. backupItemInstance.Name = nameInstance3;
  419. }
  420. JToken locationValue = responseDoc["location"];
  421. if (locationValue != null && locationValue.Type != JTokenType.Null)
  422. {
  423. string locationInstance = ((string)locationValue);
  424. backupItemInstance.Location = locationInstance;
  425. }
  426. JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
  427. if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
  428. {
  429. foreach (JProperty property in tagsSequenceElement)
  430. {
  431. string tagsKey2 = ((string)property.Name);
  432. string tagsValue2 = ((string)property.Value);
  433. backupItemInstance.Tags.Add(tagsKey2, tagsValue2);
  434. }
  435. }
  436. JToken typeValue = responseDoc["type"];
  437. if (typeValue != null && typeValue.Type != JTokenType.Null)
  438. {
  439. string typeInstance = ((string)typeValue);
  440. backupItemInstance.Type = typeInstance;
  441. }
  442. }
  443. }
  444. result.StatusCode = statusCode;
  445. if (httpResponse.Headers.Contains("x-ms-request-id"))
  446. {
  447. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  448. }
  449. if (shouldTrace)
  450. {
  451. TracingAdapter.Exit(invocationId, result);
  452. }
  453. return result;
  454. }
  455. finally
  456. {
  457. if (httpResponse != null)
  458. {
  459. httpResponse.Dispose();
  460. }
  461. }
  462. }
  463. finally
  464. {
  465. if (httpRequest != null)
  466. {
  467. httpRequest.Dispose();
  468. }
  469. }
  470. }
  471. /// <summary>
  472. /// You can clone a web site by using a PUT request that includes the
  473. /// name of the web site and other information in the request body.
  474. /// (see
  475. /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166986.aspx
  476. /// for more information)
  477. /// </summary>
  478. /// <param name='resourceGroupName'>
  479. /// Required. The name of the resource group.
  480. /// </param>
  481. /// <param name='webSiteName'>
  482. /// Required. The name of the web site.
  483. /// </param>
  484. /// <param name='slotName'>
  485. /// Optional. The name of the slot.
  486. /// </param>
  487. /// <param name='parameters'>
  488. /// Required. Parameters supplied to the clone Web Site operation.
  489. /// </param>
  490. /// <param name='cancellationToken'>
  491. /// Cancellation token.
  492. /// </param>
  493. /// <returns>
  494. /// The website operation response.
  495. /// </returns>
  496. public async Task<WebSiteAsyncOperationResponse> CloneAsync(string resourceGroupName, string webSiteName, string slotName, WebSiteCloneParameters parameters, CancellationToken cancellationToken)
  497. {
  498. // Validate
  499. if (resourceGroupName == null)
  500. {
  501. throw new ArgumentNullException("resourceGroupName");
  502. }
  503. if (webSiteName == null)
  504. {
  505. throw new ArgumentNullException("webSiteName");
  506. }
  507. if (parameters == null)
  508. {
  509. throw new ArgumentNullException("parameters");
  510. }
  511. if (parameters.WebSiteClone == null)
  512. {
  513. throw new ArgumentNullException("parameters.WebSiteClone");
  514. }
  515. if (parameters.WebSiteClone.Location == null)
  516. {
  517. throw new ArgumentNullException("parameters.WebSiteClone.Location");
  518. }
  519. // Tracing
  520. bool shouldTrace = TracingAdapter.IsEnabled;
  521. string invocationId = null;
  522. if (shouldTrace)
  523. {
  524. invocationId = TracingAdapter.NextInvocationId.ToString();
  525. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  526. tracingParameters.Add("resourceGroupName", resourceGroupName);
  527. tracingParameters.Add("webSiteName", webSiteName);
  528. tracingParameters.Add("slotName", slotName);
  529. tracingParameters.Add("parameters", parameters);
  530. TracingAdapter.Enter(invocationId, this, "CloneAsync", tracingParameters);
  531. }
  532. // Construct URL
  533. string url = "";
  534. url = url + "/subscriptions/";
  535. if (this.Client.Credentials.SubscriptionId != null)
  536. {
  537. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  538. }
  539. url = url + "/resourceGroups/";
  540. url = url + Uri.EscapeDataString(resourceGroupName);
  541. url = url + "/providers/";
  542. url = url + "Microsoft.Web";
  543. url = url + "/";
  544. url = url + "sites";
  545. url = url + "/";
  546. url = url + Uri.EscapeDataString(webSiteName);
  547. if (slotName != null)
  548. {
  549. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  550. }
  551. List<string> queryParameters = new List<string>();
  552. queryParameters.Add("api-version=2014-06-01");
  553. if (queryParameters.Count > 0)
  554. {
  555. url = url + "?" + string.Join("&", queryParameters);
  556. }
  557. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  558. // Trim '/' character from the end of baseUrl and beginning of url.
  559. if (baseUrl[baseUrl.Length - 1] == '/')
  560. {
  561. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  562. }
  563. if (url[0] == '/')
  564. {
  565. url = url.Substring(1);
  566. }
  567. url = baseUrl + "/" + url;
  568. url = url.Replace(" ", "%20");
  569. // Create HTTP transport objects
  570. HttpRequestMessage httpRequest = null;
  571. try
  572. {
  573. httpRequest = new HttpRequestMessage();
  574. httpRequest.Method = HttpMethod.Put;
  575. httpRequest.RequestUri = new Uri(url);
  576. // Set Headers
  577. // Set Credentials
  578. cancellationToken.ThrowIfCancellationRequested();
  579. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  580. // Serialize Request
  581. string requestContent = null;
  582. JToken requestDoc = null;
  583. JObject webSiteCloneParametersValue = new JObject();
  584. requestDoc = webSiteCloneParametersValue;
  585. if (parameters.WebSiteClone.Properties != null)
  586. {
  587. JObject propertiesValue = new JObject();
  588. webSiteCloneParametersValue["properties"] = propertiesValue;
  589. if (parameters.WebSiteClone.Properties.ServerFarm != null)
  590. {
  591. propertiesValue["ServerFarm"] = parameters.WebSiteClone.Properties.ServerFarm;
  592. }
  593. if (parameters.WebSiteClone.Properties.CloningInfo != null)
  594. {
  595. JObject cloningInfoValue = new JObject();
  596. propertiesValue["cloningInfo"] = cloningInfoValue;
  597. cloningInfoValue["CorrelationId"] = parameters.WebSiteClone.Properties.CloningInfo.CorrelationId.ToString();
  598. cloningInfoValue["Overwrite"] = parameters.WebSiteClone.Properties.CloningInfo.Overwrite;
  599. cloningInfoValue["CloneCustomHostNames"] = parameters.WebSiteClone.Properties.CloningInfo.CloneCustomHostNames;
  600. if (parameters.WebSiteClone.Properties.CloningInfo.Source != null)
  601. {
  602. JObject sourceValue = new JObject();
  603. cloningInfoValue["Source"] = sourceValue;
  604. if (parameters.WebSiteClone.Properties.CloningInfo.Source.Name != null)
  605. {
  606. sourceValue["Name"] = parameters.WebSiteClone.Properties.CloningInfo.Source.Name;
  607. }
  608. if (parameters.WebSiteClone.Properties.CloningInfo.Source.Location != null)
  609. {
  610. sourceValue["Location"] = parameters.WebSiteClone.Properties.CloningInfo.Source.Location;
  611. }
  612. if (parameters.WebSiteClone.Properties.CloningInfo.Source.ResourceGroupName != null)
  613. {
  614. sourceValue["ResourceGroupName"] = parameters.WebSiteClone.Properties.CloningInfo.Source.ResourceGroupName;
  615. }
  616. if (parameters.WebSiteClone.Properties.CloningInfo.Source.SubscriptionId != null)
  617. {
  618. sourceValue["SubscriptionId"] = parameters.WebSiteClone.Properties.CloningInfo.Source.SubscriptionId;
  619. }
  620. if (parameters.WebSiteClone.Properties.CloningInfo.Source.Slot != null)
  621. {
  622. sourceValue["Slot"] = parameters.WebSiteClone.Properties.CloningInfo.Source.Slot;
  623. }
  624. }
  625. if (parameters.WebSiteClone.Properties.CloningInfo.HostingEnvironment != null)
  626. {
  627. cloningInfoValue["HostingEnvironment"] = parameters.WebSiteClone.Properties.CloningInfo.HostingEnvironment;
  628. }
  629. }
  630. }
  631. if (parameters.WebSiteClone.Id != null)
  632. {
  633. webSiteCloneParametersValue["id"] = parameters.WebSiteClone.Id;
  634. }
  635. if (parameters.WebSiteClone.Name != null)
  636. {
  637. webSiteCloneParametersValue["name"] = parameters.WebSiteClone.Name;
  638. }
  639. webSiteCloneParametersValue["location"] = parameters.WebSiteClone.Location;
  640. if (parameters.WebSiteClone.Tags != null)
  641. {
  642. JObject tagsDictionary = new JObject();
  643. foreach (KeyValuePair<string, string> pair in parameters.WebSiteClone.Tags)
  644. {
  645. string tagsKey = pair.Key;
  646. string tagsValue = pair.Value;
  647. tagsDictionary[tagsKey] = tagsValue;
  648. }
  649. webSiteCloneParametersValue["tags"] = tagsDictionary;
  650. }
  651. if (parameters.WebSiteClone.Type != null)
  652. {
  653. webSiteCloneParametersValue["type"] = parameters.WebSiteClone.Type;
  654. }
  655. requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
  656. httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
  657. httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
  658. // Send Request
  659. HttpResponseMessage httpResponse = null;
  660. try
  661. {
  662. if (shouldTrace)
  663. {
  664. TracingAdapter.SendRequest(invocationId, httpRequest);
  665. }
  666. cancellationToken.ThrowIfCancellationRequested();
  667. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  668. if (shouldTrace)
  669. {
  670. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  671. }
  672. HttpStatusCode statusCode = httpResponse.StatusCode;
  673. if (statusCode != HttpStatusCode.Accepted)
  674. {
  675. cancellationToken.ThrowIfCancellationRequested();
  676. CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  677. if (shouldTrace)
  678. {
  679. TracingAdapter.Error(invocationId, ex);
  680. }
  681. throw ex;
  682. }
  683. // Create Result
  684. WebSiteAsyncOperationResponse result = null;
  685. // Deserialize Response
  686. if (statusCode == HttpStatusCode.Accepted)
  687. {
  688. cancellationToken.ThrowIfCancellationRequested();
  689. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  690. result = new WebSiteAsyncOperationResponse();
  691. JToken responseDoc = null;
  692. if (string.IsNullOrEmpty(responseContent) == false)
  693. {
  694. responseDoc = JToken.Parse(responseContent);
  695. }
  696. if (responseDoc != null && responseDoc.Type != JTokenType.Null)
  697. {
  698. JToken locationValue = responseDoc["location"];
  699. if (locationValue != null && locationValue.Type != JTokenType.Null)
  700. {
  701. string locationInstance = ((string)locationValue);
  702. result.Location = locationInstance;
  703. }
  704. JToken retryAfterValue = responseDoc["retry-after"];
  705. if (retryAfterValue != null && retryAfterValue.Type != JTokenType.Null)
  706. {
  707. string retryAfterInstance = ((string)retryAfterValue);
  708. result.RetryAfter = retryAfterInstance;
  709. }
  710. }
  711. }
  712. result.StatusCode = statusCode;
  713. if (httpResponse.Headers.Contains("location"))
  714. {
  715. result.Location = httpResponse.Headers.GetValues("location").FirstOrDefault();
  716. }
  717. if (httpResponse.Headers.Contains("retry-after"))
  718. {
  719. result.RetryAfter = httpResponse.Headers.GetValues("retry-after").FirstOrDefault();
  720. }
  721. if (httpResponse.Headers.Contains("x-ms-request-id"))
  722. {
  723. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  724. }
  725. if (shouldTrace)
  726. {
  727. TracingAdapter.Exit(invocationId, result);
  728. }
  729. return result;
  730. }
  731. finally
  732. {
  733. if (httpResponse != null)
  734. {
  735. httpResponse.Dispose();
  736. }
  737. }
  738. }
  739. finally
  740. {
  741. if (httpRequest != null)
  742. {
  743. httpRequest.Dispose();
  744. }
  745. }
  746. }
  747. /// <summary>
  748. /// You can create a web site by using a POST request that includes the
  749. /// name of the web site and other information in the request body.
  750. /// (see
  751. /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166986.aspx
  752. /// for more information)
  753. /// </summary>
  754. /// <param name='resourceGroupName'>
  755. /// Required. The name of the resource group.
  756. /// </param>
  757. /// <param name='webSiteName'>
  758. /// Required. The name of the web site.
  759. /// </param>
  760. /// <param name='slotName'>
  761. /// Optional. The name of the slot.
  762. /// </param>
  763. /// <param name='parameters'>
  764. /// Required. Parameters supplied to the Create Web Site operation.
  765. /// </param>
  766. /// <param name='cancellationToken'>
  767. /// Cancellation token.
  768. /// </param>
  769. /// <returns>
  770. /// The Create Web Space operation response.
  771. /// </returns>
  772. public async Task<WebSiteCreateResponse> CreateOrUpdateAsync(string resourceGroupName, string webSiteName, string slotName, WebSiteCreateOrUpdateParameters parameters, CancellationToken cancellationToken)
  773. {
  774. // Validate
  775. if (resourceGroupName == null)
  776. {
  777. throw new ArgumentNullException("resourceGroupName");
  778. }
  779. if (webSiteName == null)
  780. {
  781. throw new ArgumentNullException("webSiteName");
  782. }
  783. if (parameters == null)
  784. {
  785. throw new ArgumentNullException("parameters");
  786. }
  787. if (parameters.WebSite == null)
  788. {
  789. throw new ArgumentNullException("parameters.WebSite");
  790. }
  791. if (parameters.WebSite.Location == null)
  792. {
  793. throw new ArgumentNullException("parameters.WebSite.Location");
  794. }
  795. if (parameters.WebSite.Properties != null)
  796. {
  797. if (parameters.WebSite.Properties.ServerFarm == null)
  798. {
  799. throw new ArgumentNullException("parameters.WebSite.Properties.ServerFarm");
  800. }
  801. }
  802. // Tracing
  803. bool shouldTrace = TracingAdapter.IsEnabled;
  804. string invocationId = null;
  805. if (shouldTrace)
  806. {
  807. invocationId = TracingAdapter.NextInvocationId.ToString();
  808. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  809. tracingParameters.Add("resourceGroupName", resourceGroupName);
  810. tracingParameters.Add("webSiteName", webSiteName);
  811. tracingParameters.Add("slotName", slotName);
  812. tracingParameters.Add("parameters", parameters);
  813. TracingAdapter.Enter(invocationId, this, "CreateOrUpdateAsync", tracingParameters);
  814. }
  815. // Construct URL
  816. string url = "";
  817. url = url + "/subscriptions/";
  818. if (this.Client.Credentials.SubscriptionId != null)
  819. {
  820. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  821. }
  822. url = url + "/resourceGroups/";
  823. url = url + Uri.EscapeDataString(resourceGroupName);
  824. url = url + "/providers/";
  825. url = url + "Microsoft.Web";
  826. url = url + "/";
  827. url = url + "sites";
  828. url = url + "/";
  829. url = url + Uri.EscapeDataString(webSiteName);
  830. if (slotName != null)
  831. {
  832. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  833. }
  834. List<string> queryParameters = new List<string>();
  835. queryParameters.Add("api-version=2014-06-01");
  836. if (queryParameters.Count > 0)
  837. {
  838. url = url + "?" + string.Join("&", queryParameters);
  839. }
  840. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  841. // Trim '/' character from the end of baseUrl and beginning of url.
  842. if (baseUrl[baseUrl.Length - 1] == '/')
  843. {
  844. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  845. }
  846. if (url[0] == '/')
  847. {
  848. url = url.Substring(1);
  849. }
  850. url = baseUrl + "/" + url;
  851. url = url.Replace(" ", "%20");
  852. // Create HTTP transport objects
  853. HttpRequestMessage httpRequest = null;
  854. try
  855. {
  856. httpRequest = new HttpRequestMessage();
  857. httpRequest.Method = HttpMethod.Put;
  858. httpRequest.RequestUri = new Uri(url);
  859. // Set Headers
  860. // Set Credentials
  861. cancellationToken.ThrowIfCancellationRequested();
  862. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  863. // Serialize Request
  864. string requestContent = null;
  865. JToken requestDoc = null;
  866. JObject webSiteCreateOrUpdateParametersValue = new JObject();
  867. requestDoc = webSiteCreateOrUpdateParametersValue;
  868. if (parameters.WebSite.Properties != null)
  869. {
  870. JObject propertiesValue = new JObject();
  871. webSiteCreateOrUpdateParametersValue["properties"] = propertiesValue;
  872. propertiesValue["ServerFarm"] = parameters.WebSite.Properties.ServerFarm;
  873. }
  874. if (parameters.WebSite.Id != null)
  875. {
  876. webSiteCreateOrUpdateParametersValue["id"] = parameters.WebSite.Id;
  877. }
  878. if (parameters.WebSite.Name != null)
  879. {
  880. webSiteCreateOrUpdateParametersValue["name"] = parameters.WebSite.Name;
  881. }
  882. webSiteCreateOrUpdateParametersValue["location"] = parameters.WebSite.Location;
  883. if (parameters.WebSite.Tags != null)
  884. {
  885. JObject tagsDictionary = new JObject();
  886. foreach (KeyValuePair<string, string> pair in parameters.WebSite.Tags)
  887. {
  888. string tagsKey = pair.Key;
  889. string tagsValue = pair.Value;
  890. tagsDictionary[tagsKey] = tagsValue;
  891. }
  892. webSiteCreateOrUpdateParametersValue["tags"] = tagsDictionary;
  893. }
  894. if (parameters.WebSite.Type != null)
  895. {
  896. webSiteCreateOrUpdateParametersValue["type"] = parameters.WebSite.Type;
  897. }
  898. requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
  899. httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
  900. httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
  901. // Send Request
  902. HttpResponseMessage httpResponse = null;
  903. try
  904. {
  905. if (shouldTrace)
  906. {
  907. TracingAdapter.SendRequest(invocationId, httpRequest);
  908. }
  909. cancellationToken.ThrowIfCancellationRequested();
  910. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  911. if (shouldTrace)
  912. {
  913. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  914. }
  915. HttpStatusCode statusCode = httpResponse.StatusCode;
  916. if (statusCode != HttpStatusCode.OK)
  917. {
  918. cancellationToken.ThrowIfCancellationRequested();

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