PageRenderTime 147ms CodeModel.GetById 14ms RepoModel.GetById 3ms app.codeStats 2ms

/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
  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();
  919. CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  920. if (shouldTrace)
  921. {
  922. TracingAdapter.Error(invocationId, ex);
  923. }
  924. throw ex;
  925. }
  926. // Create Result
  927. WebSiteCreateResponse result = null;
  928. // Deserialize Response
  929. if (statusCode == HttpStatusCode.OK)
  930. {
  931. cancellationToken.ThrowIfCancellationRequested();
  932. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  933. result = new WebSiteCreateResponse();
  934. JToken responseDoc = null;
  935. if (string.IsNullOrEmpty(responseContent) == false)
  936. {
  937. responseDoc = JToken.Parse(responseContent);
  938. }
  939. if (responseDoc != null && responseDoc.Type != JTokenType.Null)
  940. {
  941. WebSite webSiteInstance = new WebSite();
  942. result.WebSite = webSiteInstance;
  943. JToken propertiesValue2 = responseDoc["properties"];
  944. if (propertiesValue2 != null && propertiesValue2.Type != JTokenType.Null)
  945. {
  946. WebSiteProperties propertiesInstance = new WebSiteProperties();
  947. webSiteInstance.Properties = propertiesInstance;
  948. JToken adminEnabledValue = propertiesValue2["adminEnabled"];
  949. if (adminEnabledValue != null && adminEnabledValue.Type != JTokenType.Null)
  950. {
  951. bool adminEnabledInstance = ((bool)adminEnabledValue);
  952. propertiesInstance.AdminEnabled = adminEnabledInstance;
  953. }
  954. JToken availabilityStateValue = propertiesValue2["availabilityState"];
  955. if (availabilityStateValue != null && availabilityStateValue.Type != JTokenType.Null)
  956. {
  957. WebSpaceAvailabilityState availabilityStateInstance = ((WebSpaceAvailabilityState)Enum.Parse(typeof(WebSpaceAvailabilityState), ((string)availabilityStateValue), true));
  958. propertiesInstance.AvailabilityState = availabilityStateInstance;
  959. }
  960. JToken enabledValue = propertiesValue2["enabled"];
  961. if (enabledValue != null && enabledValue.Type != JTokenType.Null)
  962. {
  963. bool enabledInstance = ((bool)enabledValue);
  964. propertiesInstance.Enabled = enabledInstance;
  965. }
  966. JToken enabledHostNamesArray = propertiesValue2["enabledHostNames"];
  967. if (enabledHostNamesArray != null && enabledHostNamesArray.Type != JTokenType.Null)
  968. {
  969. foreach (JToken enabledHostNamesValue in ((JArray)enabledHostNamesArray))
  970. {
  971. propertiesInstance.EnabledHostNames.Add(((string)enabledHostNamesValue));
  972. }
  973. }
  974. JToken hostNameSslStatesArray = propertiesValue2["hostNameSslStates"];
  975. if (hostNameSslStatesArray != null && hostNameSslStatesArray.Type != JTokenType.Null)
  976. {
  977. foreach (JToken hostNameSslStatesValue in ((JArray)hostNameSslStatesArray))
  978. {
  979. WebSiteProperties.WebSiteHostNameSslState webSiteHostNameSslStateInstance = new WebSiteProperties.WebSiteHostNameSslState();
  980. propertiesInstance.HostNameSslStates.Add(webSiteHostNameSslStateInstance);
  981. JToken nameValue = hostNameSslStatesValue["name"];
  982. if (nameValue != null && nameValue.Type != JTokenType.Null)
  983. {
  984. string nameInstance = ((string)nameValue);
  985. webSiteHostNameSslStateInstance.Name = nameInstance;
  986. }
  987. JToken sslStateValue = hostNameSslStatesValue["sslState"];
  988. if (sslStateValue != null && sslStateValue.Type != JTokenType.Null)
  989. {
  990. WebSiteSslState sslStateInstance = ((WebSiteSslState)Enum.Parse(typeof(WebSiteSslState), ((string)sslStateValue), true));
  991. webSiteHostNameSslStateInstance.SslState = sslStateInstance;
  992. }
  993. JToken thumbprintValue = hostNameSslStatesValue["thumbprint"];
  994. if (thumbprintValue != null && thumbprintValue.Type != JTokenType.Null)
  995. {
  996. string thumbprintInstance = ((string)thumbprintValue);
  997. webSiteHostNameSslStateInstance.Thumbprint = thumbprintInstance;
  998. }
  999. JToken virtualIPValue = hostNameSslStatesValue["virtualIP"];
  1000. if (virtualIPValue != null && virtualIPValue.Type != JTokenType.Null)
  1001. {
  1002. string virtualIPInstance = ((string)virtualIPValue);
  1003. webSiteHostNameSslStateInstance.VirtualIP = virtualIPInstance;
  1004. }
  1005. JToken ipBasedSslResultValue = hostNameSslStatesValue["ipBasedSslResult"];
  1006. if (ipBasedSslResultValue != null && ipBasedSslResultValue.Type != JTokenType.Null)
  1007. {
  1008. string ipBasedSslResultInstance = ((string)ipBasedSslResultValue);
  1009. webSiteHostNameSslStateInstance.IpBasedSslResult = ipBasedSslResultInstance;
  1010. }
  1011. JToken toUpdateValue = hostNameSslStatesValue["toUpdate"];
  1012. if (toUpdateValue != null && toUpdateValue.Type != JTokenType.Null)
  1013. {
  1014. bool toUpdateInstance = ((bool)toUpdateValue);
  1015. webSiteHostNameSslStateInstance.ToUpdate = toUpdateInstance;
  1016. }
  1017. JToken toUpdateIpBasedSslValue = hostNameSslStatesValue["toUpdateIpBasedSsl"];
  1018. if (toUpdateIpBasedSslValue != null && toUpdateIpBasedSslValue.Type != JTokenType.Null)
  1019. {
  1020. bool toUpdateIpBasedSslInstance = ((bool)toUpdateIpBasedSslValue);
  1021. webSiteHostNameSslStateInstance.ToUpdateIpBasedSsl = toUpdateIpBasedSslInstance;
  1022. }
  1023. }
  1024. }
  1025. JToken hostNamesArray = propertiesValue2["hostNames"];
  1026. if (hostNamesArray != null && hostNamesArray.Type != JTokenType.Null)
  1027. {
  1028. foreach (JToken hostNamesValue in ((JArray)hostNamesArray))
  1029. {
  1030. propertiesInstance.HostNames.Add(((string)hostNamesValue));
  1031. }
  1032. }
  1033. JToken lastModifiedTimeUtcValue = propertiesValue2["lastModifiedTimeUtc"];
  1034. if (lastModifiedTimeUtcValue != null && lastModifiedTimeUtcValue.Type != JTokenType.Null)
  1035. {
  1036. DateTime lastModifiedTimeUtcInstance = ((DateTime)lastModifiedTimeUtcValue);
  1037. propertiesInstance.LastModifiedTimeUtc = lastModifiedTimeUtcInstance;
  1038. }
  1039. JToken repositorySiteNameValue = propertiesValue2["repositorySiteName"];
  1040. if (repositorySiteNameValue != null && repositorySiteNameValue.Type != JTokenType.Null)
  1041. {
  1042. string repositorySiteNameInstance = ((string)repositorySiteNameValue);
  1043. propertiesInstance.RepositorySiteName = repositorySiteNameInstance;
  1044. }
  1045. JToken runtimeAvailabilityStateValue = propertiesValue2["runtimeAvailabilityState"];
  1046. if (runtimeAvailabilityStateValue != null && runtimeAvailabilityStateValue.Type != JTokenType.Null)
  1047. {
  1048. WebSiteRuntimeAvailabilityState runtimeAvailabilityStateInstance = ((WebSiteRuntimeAvailabilityState)Enum.Parse(typeof(WebSiteRuntimeAvailabilityState), ((string)runtimeAvailabilityStateValue), true));
  1049. propertiesInstance.RuntimeAvailabilityState = runtimeAvailabilityStateInstance;
  1050. }
  1051. JToken trafficManagerHostNamesArray = propertiesValue2["trafficManagerHostNames"];
  1052. if (trafficManagerHostNamesArray != null && trafficManagerHostNamesArray.Type != JTokenType.Null)
  1053. {
  1054. foreach (JToken trafficManagerHostNamesValue in ((JArray)trafficManagerHostNamesArray))
  1055. {
  1056. propertiesInstance.TrafficManagerHostNames.Add(((string)trafficManagerHostNamesValue));
  1057. }
  1058. }
  1059. JToken selfLinkValue = propertiesValue2["selfLink"];
  1060. if (selfLinkValue != null && selfLinkValue.Type != JTokenType.Null)
  1061. {
  1062. Uri selfLinkInstance = TypeConversion.TryParseUri(((string)selfLinkValue));
  1063. propertiesInstance.Uri = selfLinkInstance;
  1064. }
  1065. JToken serverFarmValue = propertiesValue2["serverFarm"];
  1066. if (serverFarmValue != null && serverFarmValue.Type != JTokenType.Null)
  1067. {
  1068. string serverFarmInstance = ((string)serverFarmValue);
  1069. propertiesInstance.ServerFarm = serverFarmInstance;
  1070. }
  1071. JToken serverFarmIdValue = propertiesValue2["serverFarmId"];
  1072. if (serverFarmIdValue != null && serverFarmIdValue.Type != JTokenType.Null)
  1073. {
  1074. string serverFarmIdInstance = ((string)serverFarmIdValue);
  1075. propertiesInstance.ServerFarmId = serverFarmIdInstance;
  1076. }
  1077. JToken skuValue = propertiesValue2["sku"];
  1078. if (skuValue != null && skuValue.Type != JTokenType.Null)
  1079. {
  1080. SkuOptions skuInstance = ((SkuOptions)Enum.Parse(typeof(SkuOptions), ((string)skuValue), true));
  1081. propertiesInstance.Sku = skuInstance;
  1082. }
  1083. JToken sitePropertiesValue = propertiesValue2["siteProperties"];
  1084. if (sitePropertiesValue != null && sitePropertiesValue.Type != JTokenType.Null)
  1085. {
  1086. WebSiteProperties.SiteProperties sitePropertiesInstance = new WebSiteProperties.SiteProperties();
  1087. propertiesInstance.Properties = sitePropertiesInstance;
  1088. JToken appSettingsSequenceElement = ((JToken)sitePropertiesValue["appSettings"]);
  1089. if (appSettingsSequenceElement != null && appSettingsSequenceElement.Type != JTokenType.Null)
  1090. {
  1091. foreach (JProperty property in appSettingsSequenceElement)
  1092. {
  1093. string appSettingsKey = ((string)property.Name);
  1094. string appSettingsValue = ((string)property.Value);
  1095. sitePropertiesInstance.AppSettings.Add(appSettingsKey, appSettingsValue);
  1096. }
  1097. }
  1098. JToken metadataSequenceElement = ((JToken)sitePropertiesValue["metadata"]);
  1099. if (metadataSequenceElement != null && metadataSequenceElement.Type != JTokenType.Null)
  1100. {
  1101. foreach (JProperty property2 in metadataSequenceElement)
  1102. {
  1103. string metadataKey = ((string)property2.Name);
  1104. string metadataValue = ((string)property2.Value);
  1105. sitePropertiesInstance.Metadata.Add(metadataKey, metadataValue);
  1106. }
  1107. }
  1108. JToken propertiesSequenceElement = ((JToken)sitePropertiesValue["properties"]);
  1109. if (propertiesSequenceElement != null && propertiesSequenceElement.Type != JTokenType.Null)
  1110. {
  1111. foreach (JProperty property3 in propertiesSequenceElement)
  1112. {
  1113. string propertiesKey = ((string)property3.Name);
  1114. string propertiesValue3 = ((string)property3.Value);
  1115. sitePropertiesInstance.Properties.Add(propertiesKey, propertiesValue3);
  1116. }
  1117. }
  1118. }
  1119. JToken siteConfigValue = propertiesValue2["siteConfig"];
  1120. if (siteConfigValue != null && siteConfigValue.Type != JTokenType.Null)
  1121. {
  1122. WebSiteConfiguration siteConfigInstance = new WebSiteConfiguration();
  1123. propertiesInstance.SiteConfig = siteConfigInstance;
  1124. JToken appSettingsSequenceElement2 = ((JToken)siteConfigValue["appSettings"]);
  1125. if (appSettingsSequenceElement2 != null && appSettingsSequenceElement2.Type != JTokenType.Null)
  1126. {
  1127. foreach (JProperty property4 in appSettingsSequenceElement2)
  1128. {
  1129. string appSettingsKey2 = ((string)property4.Name);
  1130. string appSettingsValue2 = ((string)property4.Value);
  1131. siteConfigInstance.AppSettings.Add(appSettingsKey2, appSettingsValue2);
  1132. }
  1133. }
  1134. JToken connectionStringsArray = siteConfigValue["connectionStrings"];
  1135. if (connectionStringsArray != null && connectionStringsArray.Type != JTokenType.Null)
  1136. {
  1137. foreach (JToken connectionStringsValue in ((JArray)connectionStringsArray))
  1138. {
  1139. ConnectionStringInfo connStringInfoInstance = new ConnectionStringInfo();
  1140. siteConfigInstance.ConnectionStrings.Add(connStringInfoInstance);
  1141. JToken connectionStringValue = connectionStringsValue["connectionString"];
  1142. if (connectionStringValue != null && connectionStringValue.Type != JTokenType.Null)
  1143. {
  1144. string connectionStringInstance = ((string)connectionStringValue);
  1145. connStringInfoInstance.ConnectionString = connectionStringInstance;
  1146. }
  1147. JToken nameValue2 = connectionStringsValue["name"];
  1148. if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
  1149. {
  1150. string nameInstance2 = ((string)nameValue2);
  1151. connStringInfoInstance.Name = nameInstance2;
  1152. }
  1153. JToken typeValue = connectionStringsValue["type"];
  1154. if (typeValue != null && typeValue.Type != JTokenType.Null)
  1155. {
  1156. DatabaseServerType typeInstance = ((DatabaseServerType)Enum.Parse(typeof(DatabaseServerType), ((string)typeValue), true));
  1157. connStringInfoInstance.Type = typeInstance;
  1158. }
  1159. }
  1160. }
  1161. JToken defaultDocumentsArray = siteConfigValue["defaultDocuments"];
  1162. if (defaultDocumentsArray != null && defaultDocumentsArray.Type != JTokenType.Null)
  1163. {
  1164. foreach (JToken defaultDocumentsValue in ((JArray)defaultDocumentsArray))
  1165. {
  1166. siteConfigInstance.DefaultDocuments.Add(((string)defaultDocumentsValue));
  1167. }
  1168. }
  1169. JToken detailedErrorLoggingEnabledValue = siteConfigValue["detailedErrorLoggingEnabled"];
  1170. if (detailedErrorLoggingEnabledValue != null && detailedErrorLoggingEnabledValue.Type != JTokenType.Null)
  1171. {
  1172. bool detailedErrorLoggingEnabledInstance = ((bool)detailedErrorLoggingEnabledValue);
  1173. siteConfigInstance.DetailedErrorLoggingEnabled = detailedErrorLoggingEnabledInstance;
  1174. }
  1175. JToken documentRootValue = siteConfigValue["documentRoot"];
  1176. if (documentRootValue != null && documentRootValue.Type != JTokenType.Null)
  1177. {
  1178. string documentRootInstance = ((string)documentRootValue);
  1179. siteConfigInstance.DocumentRoot = documentRootInstance;
  1180. }
  1181. JToken handlerMappingsArray = siteConfigValue["handlerMappings"];
  1182. if (handlerMappingsArray != null && handlerMappingsArray.Type != JTokenType.Null)
  1183. {
  1184. foreach (JToken handlerMappingsValue in ((JArray)handlerMappingsArray))
  1185. {
  1186. WebSiteConfiguration.HandlerMapping handlerMappingInstance = new WebSiteConfiguration.HandlerMapping();
  1187. siteConfigInstance.HandlerMappings.Add(handlerMappingInstance);
  1188. JToken argumentsValue = handlerMappingsValue["arguments"];
  1189. if (argumentsValue != null && argumentsValue.Type != JTokenType.Null)
  1190. {
  1191. string argumentsInstance = ((string)argumentsValue);
  1192. handlerMappingInstance.Arguments = argumentsInstance;
  1193. }
  1194. JToken extensionValue = handlerMappingsValue["extension"];
  1195. if (extensionValue != null && extensionValue.Type != JTokenType.Null)
  1196. {
  1197. string extensionInstance = ((string)extensionValue);
  1198. handlerMappingInstance.Extension = extensionInstance;
  1199. }
  1200. JToken scriptProcessorValue = handlerMappingsValue["scriptProcessor"];
  1201. if (scriptProcessorValue != null && scriptProcessorValue.Type != JTokenType.Null)
  1202. {
  1203. string scriptProcessorInstance = ((string)scriptProcessorValue);
  1204. handlerMappingInstance.ScriptProcessor = scriptProcessorInstance;
  1205. }
  1206. }
  1207. }
  1208. JToken httpLoggingEnabledValue = siteConfigValue["httpLoggingEnabled"];
  1209. if (httpLoggingEnabledValue != null && httpLoggingEnabledValue.Type != JTokenType.Null)
  1210. {
  1211. bool httpLoggingEnabledInstance = ((bool)httpLoggingEnabledValue);
  1212. siteConfigInstance.HttpLoggingEnabled = httpLoggingEnabledInstance;
  1213. }
  1214. JToken logsDirectorySizeLimitValue = siteConfigValue["logsDirectorySizeLimit"];
  1215. if (logsDirectorySizeLimitValue != null && logsDirectorySizeLimitValue.Type != JTokenType.Null)
  1216. {
  1217. int logsDirectorySizeLimitInstance = ((int)logsDirectorySizeLimitValue);
  1218. siteConfigInstance.LogsDirectorySizeLimit = logsDirectorySizeLimitInstance;
  1219. }
  1220. JToken managedPipelineModeValue = siteConfigValue["managedPipelineMode"];
  1221. if (managedPipelineModeValue != null && managedPipelineModeValue.Type != JTokenType.Null)
  1222. {
  1223. ManagedPipelineMode managedPipelineModeInstance = ((ManagedPipelineMode)Enum.Parse(typeof(ManagedPipelineMode), ((string)managedPipelineModeValue), true));
  1224. siteConfigInstance.ManagedPipelineMode = managedPipelineModeInstance;
  1225. }
  1226. JToken metadataSequenceElement2 = ((JToken)siteConfigValue["metadata"]);
  1227. if (metadataSequenceElement2 != null && metadataSequenceElement2.Type != JTokenType.Null)
  1228. {
  1229. foreach (JProperty property5 in metadataSequenceElement2)
  1230. {
  1231. string metadataKey2 = ((string)property5.Name);
  1232. string metadataValue2 = ((string)property5.Value);
  1233. siteConfigInstance.Metadata.Add(metadataKey2, metadataValue2);
  1234. }
  1235. }
  1236. JToken netFrameworkVersionValue = siteConfigValue["netFrameworkVersion"];
  1237. if (netFrameworkVersionValue != null && netFrameworkVersionValue.Type != JTokenType.Null)
  1238. {
  1239. string netFrameworkVersionInstance = ((string)netFrameworkVersionValue);
  1240. siteConfigInstance.NetFrameworkVersion = netFrameworkVersionInstance;
  1241. }
  1242. JToken numberOfWorkersValue = siteConfigValue["numberOfWorkers"];
  1243. if (numberOfWorkersValue != null && numberOfWorkersValue.Type != JTokenType.Null)
  1244. {
  1245. int numberOfWorkersInstance = ((int)numberOfWorkersValue);
  1246. siteConfigInstance.NumberOfWorkers = numberOfWorkersInstance;
  1247. }
  1248. JToken phpVersionValue = siteConfigValue["phpVersion"];
  1249. if (phpVersionValue != null && phpVersionValue.Type != JTokenType.Null)
  1250. {
  1251. string phpVersionInstance = ((string)phpVersionValue);
  1252. siteConfigInstance.PhpVersion = phpVersionInstance;
  1253. }
  1254. JToken pythonVersionValue = siteConfigValue["pythonVersion"];
  1255. if (pythonVersionValue != null && pythonVersionValue.Type != JTokenType.Null)
  1256. {
  1257. string pythonVersionInstance = ((string)pythonVersionValue);
  1258. siteConfigInstance.PythonVersion = pythonVersionInstance;
  1259. }
  1260. JToken publishingPasswordValue = siteConfigValue["publishingPassword"];
  1261. if (publishingPasswordValue != null && publishingPasswordValue.Type != JTokenType.Null)
  1262. {
  1263. string publishingPasswordInstance = ((string)publishingPasswordValue);
  1264. siteConfigInstance.PublishingPassword = publishingPasswordInstance;
  1265. }
  1266. JToken publishingUsernameValue = siteConfigValue["publishingUsername"];
  1267. if (publishingUsernameValue != null && publishingUsernameValue.Type != JTokenType.Null)
  1268. {
  1269. string publishingUsernameInstance = ((string)publishingUsernameValue);
  1270. siteConfigInstance.PublishingUserName = publishingUsernameInstance;
  1271. }
  1272. JToken remoteDebuggingEnabledValue = siteConfigValue["RemoteDebuggingEnabled"];
  1273. if (remoteDebuggingEnabledValue != null && remoteDebuggingEnabledValue.Type != JTokenType.Null)
  1274. {
  1275. bool remoteDebuggingEnabledInstance = ((bool)remoteDebuggingEnabledValue);
  1276. siteConfigInstance.RemoteDebuggingEnabled = remoteDebuggingEnabledInstance;
  1277. }
  1278. JToken remoteDebuggingVersionValue = siteConfigValue["remoteDebuggingVersion"];
  1279. if (remoteDebuggingVersionValue != null && remoteDebuggingVersionValue.Type != JTokenType.Null)
  1280. {
  1281. RemoteDebuggingVersion remoteDebuggingVersionInstance = ((RemoteDebuggingVersion)Enum.Parse(typeof(RemoteDebuggingVersion), ((string)remoteDebuggingVersionValue), true));
  1282. siteConfigInstance.RemoteDebuggingVersion = remoteDebuggingVersionInstance;
  1283. }
  1284. JToken requestTracingEnabledValue = siteConfigValue["requestTracingEnabled"];
  1285. if (requestTracingEnabledValue != null && requestTracingEnabledValue.Type != JTokenType.Null)
  1286. {
  1287. bool requestTracingEnabledInstance = ((bool)requestTracingEnabledValue);
  1288. siteConfigInstance.RequestTracingEnabled = requestTracingEnabledInstance;
  1289. }
  1290. JToken requestTracingExpirationTimeValue = siteConfigValue["requestTracingExpirationTime"];
  1291. if (requestTracingExpirationTimeValue != null && requestTracingExpirationTimeValue.Type != JTokenType.Null)
  1292. {
  1293. DateTime requestTracingExpirationTimeInstance = ((DateTime)requestTracingExpirationTimeValue);
  1294. siteConfigInstance.RequestTracingExpirationTime = requestTracingExpirationTimeInstance;
  1295. }
  1296. JToken scmTypeValue = siteConfigValue["scmType"];
  1297. if (scmTypeValue != null && scmTypeValue.Type != JTokenType.Null)
  1298. {
  1299. string scmTypeInstance = ((string)scmTypeValue);
  1300. siteConfigInstance.ScmType = scmTypeInstance;
  1301. }
  1302. JToken autoSwapSlotNameValue = siteConfigValue["autoSwapSlotName"];
  1303. if (autoSwapSlotNameValue != null && autoSwapSlotNameValue.Type != JTokenType.Null)
  1304. {
  1305. string autoSwapSlotNameInstance = ((string)autoSwapSlotNameValue);
  1306. siteConfigInstance.AutoSwapSlotName = autoSwapSlotNameInstance;
  1307. }
  1308. JToken use32BitWorkerProcessValue = siteConfigValue["use32BitWorkerProcess"];
  1309. if (use32BitWorkerProcessValue != null && use32BitWorkerProcessValue.Type != JTokenType.Null)
  1310. {
  1311. bool use32BitWorkerProcessInstance = ((bool)use32BitWorkerProcessValue);
  1312. siteConfigInstance.Use32BitWorkerProcess = use32BitWorkerProcessInstance;
  1313. }
  1314. JToken webSocketsEnabledValue = siteConfigValue["webSocketsEnabled"];
  1315. if (webSocketsEnabledValue != null && webSocketsEnabledValue.Type != JTokenType.Null)
  1316. {
  1317. bool webSocketsEnabledInstance = ((bool)webSocketsEnabledValue);
  1318. siteConfigInstance.WebSocketsEnabled = webSocketsEnabledInstance;
  1319. }
  1320. JToken limitsValue = siteConfigValue["limits"];
  1321. if (limitsValue != null && limitsValue.Type != JTokenType.Null)
  1322. {
  1323. SiteLimits limitsInstance = new SiteLimits();
  1324. siteConfigInstance.Limits = limitsInstance;
  1325. JToken maxPercentageCpuValue = limitsValue["maxPercentageCpu"];
  1326. if (maxPercentageCpuValue != null && maxPercentageCpuValue.Type != JTokenType.Null)
  1327. {
  1328. double maxPercentageCpuInstance = ((double)maxPercentageCpuValue);
  1329. limitsInstance.MaxPercentageCpu = maxPercentageCpuInstance;
  1330. }
  1331. JToken maxMemoryInMbValue = limitsValue["maxMemoryInMb"];
  1332. if (maxMemoryInMbValue != null && maxMemoryInMbValue.Type != JTokenType.Null)
  1333. {
  1334. long maxMemoryInMbInstance = ((long)maxMemoryInMbValue);
  1335. limitsInstance.MaxMemoryInMb = maxMemoryInMbInstance;
  1336. }
  1337. JToken maxDiskSizeInMbValue = limitsValue["maxDiskSizeInMb"];
  1338. if (maxDiskSizeInMbValue != null && maxDiskSizeInMbValue.Type != JTokenType.Null)
  1339. {
  1340. long maxDiskSizeInMbInstance = ((long)maxDiskSizeInMbValue);
  1341. limitsInstance.MaxDiskSizeInMb = maxDiskSizeInMbInstance;
  1342. }
  1343. }
  1344. }
  1345. JToken stateValue = propertiesValue2["state"];
  1346. if (stateValue != null && stateValue.Type != JTokenType.Null)
  1347. {
  1348. WebSiteState stateInstance = ((WebSiteState)Enum.Parse(typeof(WebSiteState), ((string)stateValue), true));
  1349. propertiesInstance.State = stateInstance;
  1350. }
  1351. JToken usageStateValue = propertiesValue2["usageState"];
  1352. if (usageStateValue != null && usageStateValue.Type != JTokenType.Null)
  1353. {
  1354. WebSiteUsageState usageStateInstance = ((WebSiteUsageState)Enum.Parse(typeof(WebSiteUsageState), ((string)usageStateValue), true));
  1355. propertiesInstance.UsageState = usageStateInstance;
  1356. }
  1357. JToken webSpaceValue = propertiesValue2["webSpace"];
  1358. if (webSpaceValue != null && webSpaceValue.Type != JTokenType.Null)
  1359. {
  1360. string webSpaceInstance = ((string)webSpaceValue);
  1361. propertiesInstance.WebSpace = webSpaceInstance;
  1362. }
  1363. JToken provisioningStateValue = propertiesValue2["provisioningState"];
  1364. if (provisioningStateValue != null && provisioningStateValue.Type != JTokenType.Null)
  1365. {
  1366. string provisioningStateInstance = ((string)provisioningStateValue);
  1367. propertiesInstance.ProvisioningState = provisioningStateInstance;
  1368. }
  1369. }
  1370. JToken idValue = responseDoc["id"];
  1371. if (idValue != null && idValue.Type != JTokenType.Null)
  1372. {
  1373. string idInstance = ((string)idValue);
  1374. webSiteInstance.Id = idInstance;
  1375. }
  1376. JToken nameValue3 = responseDoc["name"];
  1377. if (nameValue3 != null && nameValue3.Type != JTokenType.Null)
  1378. {
  1379. string nameInstance3 = ((string)nameValue3);
  1380. webSiteInstance.Name = nameInstance3;
  1381. }
  1382. JToken locationValue = responseDoc["location"];
  1383. if (locationValue != null && locationValue.Type != JTokenType.Null)
  1384. {
  1385. string locationInstance = ((string)locationValue);
  1386. webSiteInstance.Location = locationInstance;
  1387. }
  1388. JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
  1389. if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
  1390. {
  1391. foreach (JProperty property6 in tagsSequenceElement)
  1392. {
  1393. string tagsKey2 = ((string)property6.Name);
  1394. string tagsValue2 = ((string)property6.Value);
  1395. webSiteInstance.Tags.Add(tagsKey2, tagsValue2);
  1396. }
  1397. }
  1398. JToken typeValue2 = responseDoc["type"];
  1399. if (typeValue2 != null && typeValue2.Type != JTokenType.Null)
  1400. {
  1401. string typeInstance2 = ((string)typeValue2);
  1402. webSiteInstance.Type = typeInstance2;
  1403. }
  1404. }
  1405. }
  1406. result.StatusCode = statusCode;
  1407. if (httpResponse.Headers.Contains("x-ms-request-id"))
  1408. {
  1409. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  1410. }
  1411. if (shouldTrace)
  1412. {
  1413. TracingAdapter.Exit(invocationId, result);
  1414. }
  1415. return result;
  1416. }
  1417. finally
  1418. {
  1419. if (httpResponse != null)
  1420. {
  1421. httpResponse.Dispose();
  1422. }
  1423. }
  1424. }
  1425. finally
  1426. {
  1427. if (httpRequest != null)
  1428. {
  1429. httpRequest.Dispose();
  1430. }
  1431. }
  1432. }
  1433. /// <summary>
  1434. /// A web site repository is essentially a GIT repository that you can
  1435. /// use to manage your web site content. By using GIT source control
  1436. /// tools, you can push or pull version controlled changes to your
  1437. /// site. You can create a repository for your web site by issuing an
  1438. /// HTTP POST request, or retrieve information about the repository by
  1439. /// using HTTP GET. (see
  1440. /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166967.aspx
  1441. /// for more information)
  1442. /// </summary>
  1443. /// <param name='resourceGroupName'>
  1444. /// Required. The name of the resource group.
  1445. /// </param>
  1446. /// <param name='webSiteName'>
  1447. /// Required. The name of the web site.
  1448. /// </param>
  1449. /// <param name='slotName'>
  1450. /// Optional. The name of the slot.
  1451. /// </param>
  1452. /// <param name='cancellationToken'>
  1453. /// Cancellation token.
  1454. /// </param>
  1455. /// <returns>
  1456. /// A standard service response including an HTTP status code and
  1457. /// request ID.
  1458. /// </returns>
  1459. public async Task<AzureOperationResponse> CreateRepositoryAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
  1460. {
  1461. // Validate
  1462. if (resourceGroupName == null)
  1463. {
  1464. throw new ArgumentNullException("resourceGroupName");
  1465. }
  1466. if (webSiteName == null)
  1467. {
  1468. throw new ArgumentNullException("webSiteName");
  1469. }
  1470. // Tracing
  1471. bool shouldTrace = TracingAdapter.IsEnabled;
  1472. string invocationId = null;
  1473. if (shouldTrace)
  1474. {
  1475. invocationId = TracingAdapter.NextInvocationId.ToString();
  1476. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  1477. tracingParameters.Add("resourceGroupName", resourceGroupName);
  1478. tracingParameters.Add("webSiteName", webSiteName);
  1479. tracingParameters.Add("slotName", slotName);
  1480. TracingAdapter.Enter(invocationId, this, "CreateRepositoryAsync", tracingParameters);
  1481. }
  1482. // Construct URL
  1483. string url = "";
  1484. url = url + "/subscriptions/";
  1485. if (this.Client.Credentials.SubscriptionId != null)
  1486. {
  1487. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  1488. }
  1489. url = url + "/resourceGroups/";
  1490. url = url + Uri.EscapeDataString(resourceGroupName);
  1491. url = url + "/providers/";
  1492. url = url + "Microsoft.Web";
  1493. url = url + "/";
  1494. url = url + "sites";
  1495. url = url + "/";
  1496. url = url + Uri.EscapeDataString(webSiteName);
  1497. if (slotName != null)
  1498. {
  1499. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  1500. }
  1501. url = url + "/repository";
  1502. List<string> queryParameters = new List<string>();
  1503. queryParameters.Add("api-version=2014-06-01");
  1504. if (queryParameters.Count > 0)
  1505. {
  1506. url = url + "?" + string.Join("&", queryParameters);
  1507. }
  1508. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  1509. // Trim '/' character from the end of baseUrl and beginning of url.
  1510. if (baseUrl[baseUrl.Length - 1] == '/')
  1511. {
  1512. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  1513. }
  1514. if (url[0] == '/')
  1515. {
  1516. url = url.Substring(1);
  1517. }
  1518. url = baseUrl + "/" + url;
  1519. url = url.Replace(" ", "%20");
  1520. // Create HTTP transport objects
  1521. HttpRequestMessage httpRequest = null;
  1522. try
  1523. {
  1524. httpRequest = new HttpRequestMessage();
  1525. httpRequest.Method = HttpMethod.Post;
  1526. httpRequest.RequestUri = new Uri(url);
  1527. // Set Headers
  1528. // Set Credentials
  1529. cancellationToken.ThrowIfCancellationRequested();
  1530. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  1531. // Send Request
  1532. HttpResponseMessage httpResponse = null;
  1533. try
  1534. {
  1535. if (shouldTrace)
  1536. {
  1537. TracingAdapter.SendRequest(invocationId, httpRequest);
  1538. }
  1539. cancellationToken.ThrowIfCancellationRequested();
  1540. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  1541. if (shouldTrace)
  1542. {
  1543. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  1544. }
  1545. HttpStatusCode statusCode = httpResponse.StatusCode;
  1546. if (statusCode != HttpStatusCode.OK)
  1547. {
  1548. cancellationToken.ThrowIfCancellationRequested();
  1549. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  1550. if (shouldTrace)
  1551. {
  1552. TracingAdapter.Error(invocationId, ex);
  1553. }
  1554. throw ex;
  1555. }
  1556. // Create Result
  1557. AzureOperationResponse result = null;
  1558. // Deserialize Response
  1559. result = new AzureOperationResponse();
  1560. result.StatusCode = statusCode;
  1561. if (httpResponse.Headers.Contains("x-ms-request-id"))
  1562. {
  1563. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  1564. }
  1565. if (shouldTrace)
  1566. {
  1567. TracingAdapter.Exit(invocationId, result);
  1568. }
  1569. return result;
  1570. }
  1571. finally
  1572. {
  1573. if (httpResponse != null)
  1574. {
  1575. httpResponse.Dispose();
  1576. }
  1577. }
  1578. }
  1579. finally
  1580. {
  1581. if (httpRequest != null)
  1582. {
  1583. httpRequest.Dispose();
  1584. }
  1585. }
  1586. }
  1587. /// <summary>
  1588. /// Deletes the web site.
  1589. /// </summary>
  1590. /// <param name='resourceGroupName'>
  1591. /// Required. The name of the resource group..
  1592. /// </param>
  1593. /// <param name='webSiteName'>
  1594. /// Required. The name of the Web Site resource.
  1595. /// </param>
  1596. /// <param name='slotName'>
  1597. /// Optional. The name of the slot.
  1598. /// </param>
  1599. /// <param name='parameters'>
  1600. /// Required. The parameters to delete a web site.
  1601. /// </param>
  1602. /// <param name='cancellationToken'>
  1603. /// Cancellation token.
  1604. /// </param>
  1605. /// <returns>
  1606. /// A standard service response including an HTTP status code and
  1607. /// request ID.
  1608. /// </returns>
  1609. public async Task<AzureOperationResponse> DeleteAsync(string resourceGroupName, string webSiteName, string slotName, WebSiteDeleteParameters parameters, CancellationToken cancellationToken)
  1610. {
  1611. // Validate
  1612. if (resourceGroupName == null)
  1613. {
  1614. throw new ArgumentNullException("resourceGroupName");
  1615. }
  1616. if (webSiteName == null)
  1617. {
  1618. throw new ArgumentNullException("webSiteName");
  1619. }
  1620. if (parameters == null)
  1621. {
  1622. throw new ArgumentNullException("parameters");
  1623. }
  1624. // Tracing
  1625. bool shouldTrace = TracingAdapter.IsEnabled;
  1626. string invocationId = null;
  1627. if (shouldTrace)
  1628. {
  1629. invocationId = TracingAdapter.NextInvocationId.ToString();
  1630. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  1631. tracingParameters.Add("resourceGroupName", resourceGroupName);
  1632. tracingParameters.Add("webSiteName", webSiteName);
  1633. tracingParameters.Add("slotName", slotName);
  1634. tracingParameters.Add("parameters", parameters);
  1635. TracingAdapter.Enter(invocationId, this, "DeleteAsync", tracingParameters);
  1636. }
  1637. // Construct URL
  1638. string url = "";
  1639. url = url + "/subscriptions/";
  1640. if (this.Client.Credentials.SubscriptionId != null)
  1641. {
  1642. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  1643. }
  1644. url = url + "/resourceGroups/";
  1645. url = url + Uri.EscapeDataString(resourceGroupName);
  1646. url = url + "/providers/";
  1647. url = url + "Microsoft.Web";
  1648. url = url + "/";
  1649. url = url + "sites";
  1650. url = url + "/";
  1651. url = url + Uri.EscapeDataString(webSiteName);
  1652. if (slotName != null)
  1653. {
  1654. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  1655. }
  1656. List<string> queryParameters = new List<string>();
  1657. queryParameters.Add("api-version=2014-06-01");
  1658. queryParameters.Add("deleteEmptyServerFarm=" + Uri.EscapeDataString(parameters.DeleteEmptyServerFarm.ToString().ToLower()));
  1659. queryParameters.Add("deleteMetrics=" + Uri.EscapeDataString(parameters.DeleteMetrics.ToString().ToLower()));
  1660. queryParameters.Add("deleteAllSlots=" + Uri.EscapeDataString(parameters.DeleteAllSlots.ToString().ToLower()));
  1661. if (queryParameters.Count > 0)
  1662. {
  1663. url = url + "?" + string.Join("&", queryParameters);
  1664. }
  1665. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  1666. // Trim '/' character from the end of baseUrl and beginning of url.
  1667. if (baseUrl[baseUrl.Length - 1] == '/')
  1668. {
  1669. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  1670. }
  1671. if (url[0] == '/')
  1672. {
  1673. url = url.Substring(1);
  1674. }
  1675. url = baseUrl + "/" + url;
  1676. url = url.Replace(" ", "%20");
  1677. // Create HTTP transport objects
  1678. HttpRequestMessage httpRequest = null;
  1679. try
  1680. {
  1681. httpRequest = new HttpRequestMessage();
  1682. httpRequest.Method = HttpMethod.Delete;
  1683. httpRequest.RequestUri = new Uri(url);
  1684. // Set Headers
  1685. // Set Credentials
  1686. cancellationToken.ThrowIfCancellationRequested();
  1687. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  1688. // Send Request
  1689. HttpResponseMessage httpResponse = null;
  1690. try
  1691. {
  1692. if (shouldTrace)
  1693. {
  1694. TracingAdapter.SendRequest(invocationId, httpRequest);
  1695. }
  1696. cancellationToken.ThrowIfCancellationRequested();
  1697. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  1698. if (shouldTrace)
  1699. {
  1700. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  1701. }
  1702. HttpStatusCode statusCode = httpResponse.StatusCode;
  1703. if (statusCode != HttpStatusCode.OK)
  1704. {
  1705. cancellationToken.ThrowIfCancellationRequested();
  1706. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  1707. if (shouldTrace)
  1708. {
  1709. TracingAdapter.Error(invocationId, ex);
  1710. }
  1711. throw ex;
  1712. }
  1713. // Create Result
  1714. AzureOperationResponse result = null;
  1715. // Deserialize Response
  1716. result = new AzureOperationResponse();
  1717. result.StatusCode = statusCode;
  1718. if (httpResponse.Headers.Contains("x-ms-request-id"))
  1719. {
  1720. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  1721. }
  1722. if (shouldTrace)
  1723. {
  1724. TracingAdapter.Exit(invocationId, result);
  1725. }
  1726. return result;
  1727. }
  1728. finally
  1729. {
  1730. if (httpResponse != null)
  1731. {
  1732. httpResponse.Dispose();
  1733. }
  1734. }
  1735. }
  1736. finally
  1737. {
  1738. if (httpRequest != null)
  1739. {
  1740. httpRequest.Dispose();
  1741. }
  1742. }
  1743. }
  1744. /// <summary>
  1745. /// A web site repository is essentially a GIT repository that you can
  1746. /// use to manage your web site content. By using GIT source control
  1747. /// tools, you can push or pull version controlled changes to your
  1748. /// site. You can create a repository for your web site by issuing an
  1749. /// HTTP POST request, or retrieve information about the repository by
  1750. /// using HTTP GET. (see
  1751. /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166967.aspx
  1752. /// for more information)
  1753. /// </summary>
  1754. /// <param name='resourceGroupName'>
  1755. /// Required. The name of the resource group.
  1756. /// </param>
  1757. /// <param name='webSiteName'>
  1758. /// Required. The name of the web site.
  1759. /// </param>
  1760. /// <param name='slotName'>
  1761. /// Optional. The name of the slot.
  1762. /// </param>
  1763. /// <param name='cancellationToken'>
  1764. /// Cancellation token.
  1765. /// </param>
  1766. /// <returns>
  1767. /// The Delete Web Site Repository operation response.
  1768. /// </returns>
  1769. public async Task<WebSiteDeleteRepositoryResponse> DeleteRepositoryAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
  1770. {
  1771. // Validate
  1772. if (resourceGroupName == null)
  1773. {
  1774. throw new ArgumentNullException("resourceGroupName");
  1775. }
  1776. if (webSiteName == null)
  1777. {
  1778. throw new ArgumentNullException("webSiteName");
  1779. }
  1780. // Tracing
  1781. bool shouldTrace = TracingAdapter.IsEnabled;
  1782. string invocationId = null;
  1783. if (shouldTrace)
  1784. {
  1785. invocationId = TracingAdapter.NextInvocationId.ToString();
  1786. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  1787. tracingParameters.Add("resourceGroupName", resourceGroupName);
  1788. tracingParameters.Add("webSiteName", webSiteName);
  1789. tracingParameters.Add("slotName", slotName);
  1790. TracingAdapter.Enter(invocationId, this, "DeleteRepositoryAsync", tracingParameters);
  1791. }
  1792. // Construct URL
  1793. string url = "";
  1794. url = url + "/subscriptions/";
  1795. if (this.Client.Credentials.SubscriptionId != null)
  1796. {
  1797. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  1798. }
  1799. url = url + "/resourceGroups/";
  1800. url = url + Uri.EscapeDataString(resourceGroupName);
  1801. url = url + "/providers/";
  1802. url = url + "Microsoft.Web";
  1803. url = url + "/";
  1804. url = url + "sites";
  1805. url = url + "/";
  1806. url = url + Uri.EscapeDataString(webSiteName);
  1807. if (slotName != null)
  1808. {
  1809. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  1810. }
  1811. url = url + "/repository";
  1812. List<string> queryParameters = new List<string>();
  1813. queryParameters.Add("api-version=2014-06-01");
  1814. if (queryParameters.Count > 0)
  1815. {
  1816. url = url + "?" + string.Join("&", queryParameters);
  1817. }
  1818. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  1819. // Trim '/' character from the end of baseUrl and beginning of url.
  1820. if (baseUrl[baseUrl.Length - 1] == '/')
  1821. {
  1822. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  1823. }
  1824. if (url[0] == '/')
  1825. {
  1826. url = url.Substring(1);
  1827. }
  1828. url = baseUrl + "/" + url;
  1829. url = url.Replace(" ", "%20");
  1830. // Create HTTP transport objects
  1831. HttpRequestMessage httpRequest = null;
  1832. try
  1833. {
  1834. httpRequest = new HttpRequestMessage();
  1835. httpRequest.Method = HttpMethod.Delete;
  1836. httpRequest.RequestUri = new Uri(url);
  1837. // Set Headers
  1838. // Set Credentials
  1839. cancellationToken.ThrowIfCancellationRequested();
  1840. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  1841. // Send Request
  1842. HttpResponseMessage httpResponse = null;
  1843. try
  1844. {
  1845. if (shouldTrace)
  1846. {
  1847. TracingAdapter.SendRequest(invocationId, httpRequest);
  1848. }
  1849. cancellationToken.ThrowIfCancellationRequested();
  1850. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  1851. if (shouldTrace)
  1852. {
  1853. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  1854. }
  1855. HttpStatusCode statusCode = httpResponse.StatusCode;
  1856. if (statusCode != HttpStatusCode.OK)
  1857. {
  1858. cancellationToken.ThrowIfCancellationRequested();
  1859. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  1860. if (shouldTrace)
  1861. {
  1862. TracingAdapter.Error(invocationId, ex);
  1863. }
  1864. throw ex;
  1865. }
  1866. // Create Result
  1867. WebSiteDeleteRepositoryResponse result = null;
  1868. // Deserialize Response
  1869. if (statusCode == HttpStatusCode.OK)
  1870. {
  1871. cancellationToken.ThrowIfCancellationRequested();
  1872. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  1873. result = new WebSiteDeleteRepositoryResponse();
  1874. JToken responseDoc = null;
  1875. if (string.IsNullOrEmpty(responseContent) == false)
  1876. {
  1877. responseDoc = JToken.Parse(responseContent);
  1878. }
  1879. if (responseDoc != null && responseDoc.Type != JTokenType.Null)
  1880. {
  1881. JToken uriValue = responseDoc["uri"];
  1882. if (uriValue != null && uriValue.Type != JTokenType.Null)
  1883. {
  1884. Uri uriInstance = TypeConversion.TryParseUri(((string)uriValue));
  1885. result.Uri = uriInstance;
  1886. }
  1887. }
  1888. }
  1889. result.StatusCode = statusCode;
  1890. if (httpResponse.Headers.Contains("x-ms-request-id"))
  1891. {
  1892. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  1893. }
  1894. if (shouldTrace)
  1895. {
  1896. TracingAdapter.Exit(invocationId, result);
  1897. }
  1898. return result;
  1899. }
  1900. finally
  1901. {
  1902. if (httpResponse != null)
  1903. {
  1904. httpResponse.Dispose();
  1905. }
  1906. }
  1907. }
  1908. finally
  1909. {
  1910. if (httpRequest != null)
  1911. {
  1912. httpRequest.Dispose();
  1913. }
  1914. }
  1915. }
  1916. /// <summary>
  1917. /// Unlink source control from website
  1918. /// </summary>
  1919. /// <param name='resourceGroupName'>
  1920. /// Required. The name of the resource group.
  1921. /// </param>
  1922. /// <param name='webSiteName'>
  1923. /// Required. The name of the web site.
  1924. /// </param>
  1925. /// <param name='slotName'>
  1926. /// Optional. The name of the slot.
  1927. /// </param>
  1928. /// <param name='repoUrl'>
  1929. /// Required. The repository url.
  1930. /// </param>
  1931. /// <param name='cancellationToken'>
  1932. /// Cancellation token.
  1933. /// </param>
  1934. /// <returns>
  1935. /// A standard service response including an HTTP status code and
  1936. /// request ID.
  1937. /// </returns>
  1938. public async Task<AzureOperationResponse> DeleteSiteSourceControlAsync(string resourceGroupName, string webSiteName, string slotName, string repoUrl, CancellationToken cancellationToken)
  1939. {
  1940. // Validate
  1941. if (resourceGroupName == null)
  1942. {
  1943. throw new ArgumentNullException("resourceGroupName");
  1944. }
  1945. if (webSiteName == null)
  1946. {
  1947. throw new ArgumentNullException("webSiteName");
  1948. }
  1949. if (repoUrl == null)
  1950. {
  1951. throw new ArgumentNullException("repoUrl");
  1952. }
  1953. // Tracing
  1954. bool shouldTrace = TracingAdapter.IsEnabled;
  1955. string invocationId = null;
  1956. if (shouldTrace)
  1957. {
  1958. invocationId = TracingAdapter.NextInvocationId.ToString();
  1959. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  1960. tracingParameters.Add("resourceGroupName", resourceGroupName);
  1961. tracingParameters.Add("webSiteName", webSiteName);
  1962. tracingParameters.Add("slotName", slotName);
  1963. tracingParameters.Add("repoUrl", repoUrl);
  1964. TracingAdapter.Enter(invocationId, this, "DeleteSiteSourceControlAsync", tracingParameters);
  1965. }
  1966. // Construct URL
  1967. string url = "";
  1968. url = url + "/subscriptions/";
  1969. if (this.Client.Credentials.SubscriptionId != null)
  1970. {
  1971. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  1972. }
  1973. url = url + "/resourceGroups/";
  1974. url = url + Uri.EscapeDataString(resourceGroupName);
  1975. url = url + "/providers/";
  1976. url = url + "Microsoft.Web";
  1977. url = url + "/";
  1978. url = url + "sites";
  1979. url = url + "/";
  1980. url = url + Uri.EscapeDataString(webSiteName);
  1981. if (slotName != null)
  1982. {
  1983. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  1984. }
  1985. url = url + "/sourcecontrols/web";
  1986. List<string> queryParameters = new List<string>();
  1987. queryParameters.Add("api-version=2014-06-01");
  1988. if (queryParameters.Count > 0)
  1989. {
  1990. url = url + "?" + string.Join("&", queryParameters);
  1991. }
  1992. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  1993. // Trim '/' character from the end of baseUrl and beginning of url.
  1994. if (baseUrl[baseUrl.Length - 1] == '/')
  1995. {
  1996. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  1997. }
  1998. if (url[0] == '/')
  1999. {
  2000. url = url.Substring(1);
  2001. }
  2002. url = baseUrl + "/" + url;
  2003. url = url.Replace(" ", "%20");
  2004. // Create HTTP transport objects
  2005. HttpRequestMessage httpRequest = null;
  2006. try
  2007. {
  2008. httpRequest = new HttpRequestMessage();
  2009. httpRequest.Method = HttpMethod.Delete;
  2010. httpRequest.RequestUri = new Uri(url);
  2011. // Set Headers
  2012. // Set Credentials
  2013. cancellationToken.ThrowIfCancellationRequested();
  2014. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  2015. // Send Request
  2016. HttpResponseMessage httpResponse = null;
  2017. try
  2018. {
  2019. if (shouldTrace)
  2020. {
  2021. TracingAdapter.SendRequest(invocationId, httpRequest);
  2022. }
  2023. cancellationToken.ThrowIfCancellationRequested();
  2024. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  2025. if (shouldTrace)
  2026. {
  2027. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  2028. }
  2029. HttpStatusCode statusCode = httpResponse.StatusCode;
  2030. if (statusCode != HttpStatusCode.OK)
  2031. {
  2032. cancellationToken.ThrowIfCancellationRequested();
  2033. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  2034. if (shouldTrace)
  2035. {
  2036. TracingAdapter.Error(invocationId, ex);
  2037. }
  2038. throw ex;
  2039. }
  2040. // Create Result
  2041. AzureOperationResponse result = null;
  2042. // Deserialize Response
  2043. result = new AzureOperationResponse();
  2044. result.StatusCode = statusCode;
  2045. if (httpResponse.Headers.Contains("x-ms-request-id"))
  2046. {
  2047. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  2048. }
  2049. if (shouldTrace)
  2050. {
  2051. TracingAdapter.Exit(invocationId, result);
  2052. }
  2053. return result;
  2054. }
  2055. finally
  2056. {
  2057. if (httpResponse != null)
  2058. {
  2059. httpResponse.Dispose();
  2060. }
  2061. }
  2062. }
  2063. finally
  2064. {
  2065. if (httpRequest != null)
  2066. {
  2067. httpRequest.Dispose();
  2068. }
  2069. }
  2070. }
  2071. /// <summary>
  2072. /// Scans a backup in a storage account and returns database
  2073. /// information etc. Should be called before calling Restore to
  2074. /// discover what parameters are needed for the restore operation.
  2075. /// KNOWN BUG: This has to be called against an exisingsite, otherwise
  2076. /// will hit an error about non-existing resource.
  2077. /// </summary>
  2078. /// <param name='resourceGroupName'>
  2079. /// Required. The name of the web space.
  2080. /// </param>
  2081. /// <param name='webSiteName'>
  2082. /// Required. The name of the web site.
  2083. /// </param>
  2084. /// <param name='slotName'>
  2085. /// Optional. The name of the slot.
  2086. /// </param>
  2087. /// <param name='restoreRequestEnvelope'>
  2088. /// Required. A restore request.
  2089. /// </param>
  2090. /// <param name='cancellationToken'>
  2091. /// Cancellation token.
  2092. /// </param>
  2093. /// <returns>
  2094. /// The information gathered about a backup storaged in a storage
  2095. /// account.
  2096. /// </returns>
  2097. public async Task<WebSiteRestoreDiscoverResponse> DiscoverAsync(string resourceGroupName, string webSiteName, string slotName, RestoreRequestEnvelope restoreRequestEnvelope, CancellationToken cancellationToken)
  2098. {
  2099. // Validate
  2100. if (resourceGroupName == null)
  2101. {
  2102. throw new ArgumentNullException("resourceGroupName");
  2103. }
  2104. if (webSiteName == null)
  2105. {
  2106. throw new ArgumentNullException("webSiteName");
  2107. }
  2108. if (restoreRequestEnvelope == null)
  2109. {
  2110. throw new ArgumentNullException("restoreRequestEnvelope");
  2111. }
  2112. if (restoreRequestEnvelope.Location == null)
  2113. {
  2114. throw new ArgumentNullException("restoreRequestEnvelope.Location");
  2115. }
  2116. // Tracing
  2117. bool shouldTrace = TracingAdapter.IsEnabled;
  2118. string invocationId = null;
  2119. if (shouldTrace)
  2120. {
  2121. invocationId = TracingAdapter.NextInvocationId.ToString();
  2122. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  2123. tracingParameters.Add("resourceGroupName", resourceGroupName);
  2124. tracingParameters.Add("webSiteName", webSiteName);
  2125. tracingParameters.Add("slotName", slotName);
  2126. tracingParameters.Add("restoreRequestEnvelope", restoreRequestEnvelope);
  2127. TracingAdapter.Enter(invocationId, this, "DiscoverAsync", tracingParameters);
  2128. }
  2129. // Construct URL
  2130. string url = "";
  2131. url = url + "/subscriptions/";
  2132. if (this.Client.Credentials.SubscriptionId != null)
  2133. {
  2134. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  2135. }
  2136. url = url + "/resourceGroups/";
  2137. url = url + Uri.EscapeDataString(resourceGroupName);
  2138. url = url + "/providers/";
  2139. url = url + "Microsoft.Web";
  2140. url = url + "/";
  2141. url = url + "sites";
  2142. url = url + "/";
  2143. url = url + Uri.EscapeDataString(webSiteName);
  2144. if (slotName != null)
  2145. {
  2146. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  2147. }
  2148. url = url + "/restore/discover";
  2149. List<string> queryParameters = new List<string>();
  2150. queryParameters.Add("api-version=2014-06-01");
  2151. if (queryParameters.Count > 0)
  2152. {
  2153. url = url + "?" + string.Join("&", queryParameters);
  2154. }
  2155. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  2156. // Trim '/' character from the end of baseUrl and beginning of url.
  2157. if (baseUrl[baseUrl.Length - 1] == '/')
  2158. {
  2159. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  2160. }
  2161. if (url[0] == '/')
  2162. {
  2163. url = url.Substring(1);
  2164. }
  2165. url = baseUrl + "/" + url;
  2166. url = url.Replace(" ", "%20");
  2167. // Create HTTP transport objects
  2168. HttpRequestMessage httpRequest = null;
  2169. try
  2170. {
  2171. httpRequest = new HttpRequestMessage();
  2172. httpRequest.Method = HttpMethod.Put;
  2173. httpRequest.RequestUri = new Uri(url);
  2174. // Set Headers
  2175. httpRequest.Headers.Add("x-ms-version", "2014-06-01");
  2176. // Set Credentials
  2177. cancellationToken.ThrowIfCancellationRequested();
  2178. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  2179. // Serialize Request
  2180. string requestContent = null;
  2181. JToken requestDoc = null;
  2182. JObject restoreRequestEnvelopeValue = new JObject();
  2183. requestDoc = restoreRequestEnvelopeValue;
  2184. if (restoreRequestEnvelope.Request != null)
  2185. {
  2186. JObject propertiesValue = new JObject();
  2187. restoreRequestEnvelopeValue["properties"] = propertiesValue;
  2188. propertiesValue["AdjustConnectionStrings"] = restoreRequestEnvelope.Request.AdjustConnectionStrings;
  2189. if (restoreRequestEnvelope.Request.BlobName != null)
  2190. {
  2191. propertiesValue["BlobName"] = restoreRequestEnvelope.Request.BlobName;
  2192. }
  2193. if (restoreRequestEnvelope.Request.Databases != null)
  2194. {
  2195. if (restoreRequestEnvelope.Request.Databases is ILazyCollection == false || ((ILazyCollection)restoreRequestEnvelope.Request.Databases).IsInitialized)
  2196. {
  2197. JArray databasesArray = new JArray();
  2198. foreach (DatabaseBackupSetting databasesItem in restoreRequestEnvelope.Request.Databases)
  2199. {
  2200. JObject databaseBackupSettingValue = new JObject();
  2201. databasesArray.Add(databaseBackupSettingValue);
  2202. if (databasesItem.ConnectionString != null)
  2203. {
  2204. databaseBackupSettingValue["connectionString"] = databasesItem.ConnectionString;
  2205. }
  2206. if (databasesItem.ConnectionStringName != null)
  2207. {
  2208. databaseBackupSettingValue["connectionStringName"] = databasesItem.ConnectionStringName;
  2209. }
  2210. if (databasesItem.DatabaseType != null)
  2211. {
  2212. databaseBackupSettingValue["databaseType"] = databasesItem.DatabaseType;
  2213. }
  2214. if (databasesItem.Name != null)
  2215. {
  2216. databaseBackupSettingValue["name"] = databasesItem.Name;
  2217. }
  2218. }
  2219. propertiesValue["Databases"] = databasesArray;
  2220. }
  2221. }
  2222. propertiesValue["IgnoreConflictingHostNames"] = restoreRequestEnvelope.Request.IgnoreConflictingHostNames;
  2223. propertiesValue["Overwrite"] = restoreRequestEnvelope.Request.Overwrite;
  2224. if (restoreRequestEnvelope.Request.StorageAccountUrl != null)
  2225. {
  2226. propertiesValue["StorageAccountUrl"] = restoreRequestEnvelope.Request.StorageAccountUrl;
  2227. }
  2228. }
  2229. if (restoreRequestEnvelope.Id != null)
  2230. {
  2231. restoreRequestEnvelopeValue["id"] = restoreRequestEnvelope.Id;
  2232. }
  2233. if (restoreRequestEnvelope.Name != null)
  2234. {
  2235. restoreRequestEnvelopeValue["name"] = restoreRequestEnvelope.Name;
  2236. }
  2237. restoreRequestEnvelopeValue["location"] = restoreRequestEnvelope.Location;
  2238. if (restoreRequestEnvelope.Tags != null)
  2239. {
  2240. JObject tagsDictionary = new JObject();
  2241. foreach (KeyValuePair<string, string> pair in restoreRequestEnvelope.Tags)
  2242. {
  2243. string tagsKey = pair.Key;
  2244. string tagsValue = pair.Value;
  2245. tagsDictionary[tagsKey] = tagsValue;
  2246. }
  2247. restoreRequestEnvelopeValue["tags"] = tagsDictionary;
  2248. }
  2249. if (restoreRequestEnvelope.Type != null)
  2250. {
  2251. restoreRequestEnvelopeValue["type"] = restoreRequestEnvelope.Type;
  2252. }
  2253. requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
  2254. httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
  2255. httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
  2256. // Send Request
  2257. HttpResponseMessage httpResponse = null;
  2258. try
  2259. {
  2260. if (shouldTrace)
  2261. {
  2262. TracingAdapter.SendRequest(invocationId, httpRequest);
  2263. }
  2264. cancellationToken.ThrowIfCancellationRequested();
  2265. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  2266. if (shouldTrace)
  2267. {
  2268. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  2269. }
  2270. HttpStatusCode statusCode = httpResponse.StatusCode;
  2271. if (statusCode != HttpStatusCode.OK)
  2272. {
  2273. cancellationToken.ThrowIfCancellationRequested();
  2274. CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  2275. if (shouldTrace)
  2276. {
  2277. TracingAdapter.Error(invocationId, ex);
  2278. }
  2279. throw ex;
  2280. }
  2281. // Create Result
  2282. WebSiteRestoreDiscoverResponse result = null;
  2283. // Deserialize Response
  2284. if (statusCode == HttpStatusCode.OK)
  2285. {
  2286. cancellationToken.ThrowIfCancellationRequested();
  2287. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  2288. result = new WebSiteRestoreDiscoverResponse();
  2289. JToken responseDoc = null;
  2290. if (string.IsNullOrEmpty(responseContent) == false)
  2291. {
  2292. responseDoc = JToken.Parse(responseContent);
  2293. }
  2294. if (responseDoc != null && responseDoc.Type != JTokenType.Null)
  2295. {
  2296. WebSiteRestoreDiscover envelopeInstance = new WebSiteRestoreDiscover();
  2297. result.Envelope = envelopeInstance;
  2298. JToken propertiesValue2 = responseDoc["properties"];
  2299. if (propertiesValue2 != null && propertiesValue2.Type != JTokenType.Null)
  2300. {
  2301. WebSiteRestoreDiscoverProperties propertiesInstance = new WebSiteRestoreDiscoverProperties();
  2302. envelopeInstance.Properties = propertiesInstance;
  2303. JToken storageAccountUrlValue = propertiesValue2["storageAccountUrl"];
  2304. if (storageAccountUrlValue != null && storageAccountUrlValue.Type != JTokenType.Null)
  2305. {
  2306. string storageAccountUrlInstance = ((string)storageAccountUrlValue);
  2307. propertiesInstance.StorageAccountUrl = storageAccountUrlInstance;
  2308. }
  2309. JToken blobNameValue = propertiesValue2["blobName"];
  2310. if (blobNameValue != null && blobNameValue.Type != JTokenType.Null)
  2311. {
  2312. string blobNameInstance = ((string)blobNameValue);
  2313. propertiesInstance.BlobName = blobNameInstance;
  2314. }
  2315. JToken overwriteValue = propertiesValue2["overwrite"];
  2316. if (overwriteValue != null && overwriteValue.Type != JTokenType.Null)
  2317. {
  2318. bool overwriteInstance = ((bool)overwriteValue);
  2319. propertiesInstance.Overwrite = overwriteInstance;
  2320. }
  2321. JToken databasesArray2 = propertiesValue2["databases"];
  2322. if (databasesArray2 != null && databasesArray2.Type != JTokenType.Null)
  2323. {
  2324. foreach (JToken databasesValue in ((JArray)databasesArray2))
  2325. {
  2326. DatabaseBackupSetting databaseBackupSettingInstance = new DatabaseBackupSetting();
  2327. propertiesInstance.Databases.Add(databaseBackupSettingInstance);
  2328. JToken connectionStringValue = databasesValue["connectionString"];
  2329. if (connectionStringValue != null && connectionStringValue.Type != JTokenType.Null)
  2330. {
  2331. string connectionStringInstance = ((string)connectionStringValue);
  2332. databaseBackupSettingInstance.ConnectionString = connectionStringInstance;
  2333. }
  2334. JToken connectionStringNameValue = databasesValue["connectionStringName"];
  2335. if (connectionStringNameValue != null && connectionStringNameValue.Type != JTokenType.Null)
  2336. {
  2337. string connectionStringNameInstance = ((string)connectionStringNameValue);
  2338. databaseBackupSettingInstance.ConnectionStringName = connectionStringNameInstance;
  2339. }
  2340. JToken databaseTypeValue = databasesValue["databaseType"];
  2341. if (databaseTypeValue != null && databaseTypeValue.Type != JTokenType.Null)
  2342. {
  2343. string databaseTypeInstance = ((string)databaseTypeValue);
  2344. databaseBackupSettingInstance.DatabaseType = databaseTypeInstance;
  2345. }
  2346. JToken nameValue = databasesValue["name"];
  2347. if (nameValue != null && nameValue.Type != JTokenType.Null)
  2348. {
  2349. string nameInstance = ((string)nameValue);
  2350. databaseBackupSettingInstance.Name = nameInstance;
  2351. }
  2352. }
  2353. }
  2354. JToken ignoreConflictingHostNamesValue = propertiesValue2["ignoreConflictingHostNames"];
  2355. if (ignoreConflictingHostNamesValue != null && ignoreConflictingHostNamesValue.Type != JTokenType.Null)
  2356. {
  2357. bool ignoreConflictingHostNamesInstance = ((bool)ignoreConflictingHostNamesValue);
  2358. propertiesInstance.IgnoreConflictingHostNames = ignoreConflictingHostNamesInstance;
  2359. }
  2360. JToken adjustConnectionStringsValue = propertiesValue2["adjustConnectionStrings"];
  2361. if (adjustConnectionStringsValue != null && adjustConnectionStringsValue.Type != JTokenType.Null)
  2362. {
  2363. bool adjustConnectionStringsInstance = ((bool)adjustConnectionStringsValue);
  2364. propertiesInstance.AdjustConnectionStrings = adjustConnectionStringsInstance;
  2365. }
  2366. }
  2367. JToken idValue = responseDoc["id"];
  2368. if (idValue != null && idValue.Type != JTokenType.Null)
  2369. {
  2370. string idInstance = ((string)idValue);
  2371. envelopeInstance.Id = idInstance;
  2372. }
  2373. JToken nameValue2 = responseDoc["name"];
  2374. if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
  2375. {
  2376. string nameInstance2 = ((string)nameValue2);
  2377. envelopeInstance.Name = nameInstance2;
  2378. }
  2379. JToken locationValue = responseDoc["location"];
  2380. if (locationValue != null && locationValue.Type != JTokenType.Null)
  2381. {
  2382. string locationInstance = ((string)locationValue);
  2383. envelopeInstance.Location = locationInstance;
  2384. }
  2385. JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
  2386. if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
  2387. {
  2388. foreach (JProperty property in tagsSequenceElement)
  2389. {
  2390. string tagsKey2 = ((string)property.Name);
  2391. string tagsValue2 = ((string)property.Value);
  2392. envelopeInstance.Tags.Add(tagsKey2, tagsValue2);
  2393. }
  2394. }
  2395. JToken typeValue = responseDoc["type"];
  2396. if (typeValue != null && typeValue.Type != JTokenType.Null)
  2397. {
  2398. string typeInstance = ((string)typeValue);
  2399. envelopeInstance.Type = typeInstance;
  2400. }
  2401. }
  2402. }
  2403. result.StatusCode = statusCode;
  2404. if (httpResponse.Headers.Contains("x-ms-request-id"))
  2405. {
  2406. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  2407. }
  2408. if (shouldTrace)
  2409. {
  2410. TracingAdapter.Exit(invocationId, result);
  2411. }
  2412. return result;
  2413. }
  2414. finally
  2415. {
  2416. if (httpResponse != null)
  2417. {
  2418. httpResponse.Dispose();
  2419. }
  2420. }
  2421. }
  2422. finally
  2423. {
  2424. if (httpRequest != null)
  2425. {
  2426. httpRequest.Dispose();
  2427. }
  2428. }
  2429. }
  2430. /// <summary>
  2431. /// You can generate a new random password for publishing a site by
  2432. /// issuing an HTTP POST request. Tip: If you want to verify that the
  2433. /// publish password has changed, call HTTP GET on /publishxml before
  2434. /// calling /newpassword. In the publish XML, note the hash value in
  2435. /// the userPWD attribute. After calling /newpassword, call
  2436. /// /publishxml again. You can then compare the new value of userPWD
  2437. /// in the Publish XML with the one you noted earlier. (see
  2438. /// http://msdn.microsoft.com/en-us/library/windowsazure/dn236428.aspx
  2439. /// for more information)
  2440. /// </summary>
  2441. /// <param name='resourceGroupName'>
  2442. /// Required. The name of the resource group.
  2443. /// </param>
  2444. /// <param name='webSiteName'>
  2445. /// Required. The name of the web site.
  2446. /// </param>
  2447. /// <param name='slotName'>
  2448. /// Optional. The name of the slot.
  2449. /// </param>
  2450. /// <param name='cancellationToken'>
  2451. /// Cancellation token.
  2452. /// </param>
  2453. /// <returns>
  2454. /// A standard service response including an HTTP status code and
  2455. /// request ID.
  2456. /// </returns>
  2457. public async Task<AzureOperationResponse> GeneratePasswordAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
  2458. {
  2459. // Validate
  2460. if (resourceGroupName == null)
  2461. {
  2462. throw new ArgumentNullException("resourceGroupName");
  2463. }
  2464. if (webSiteName == null)
  2465. {
  2466. throw new ArgumentNullException("webSiteName");
  2467. }
  2468. // Tracing
  2469. bool shouldTrace = TracingAdapter.IsEnabled;
  2470. string invocationId = null;
  2471. if (shouldTrace)
  2472. {
  2473. invocationId = TracingAdapter.NextInvocationId.ToString();
  2474. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  2475. tracingParameters.Add("resourceGroupName", resourceGroupName);
  2476. tracingParameters.Add("webSiteName", webSiteName);
  2477. tracingParameters.Add("slotName", slotName);
  2478. TracingAdapter.Enter(invocationId, this, "GeneratePasswordAsync", tracingParameters);
  2479. }
  2480. // Construct URL
  2481. string url = "";
  2482. url = url + "/subscriptions/";
  2483. if (this.Client.Credentials.SubscriptionId != null)
  2484. {
  2485. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  2486. }
  2487. url = url + "/resourceGroups/";
  2488. url = url + Uri.EscapeDataString(resourceGroupName);
  2489. url = url + "/providers/";
  2490. url = url + "Microsoft.Web";
  2491. url = url + "/";
  2492. url = url + "sites";
  2493. url = url + "/";
  2494. url = url + Uri.EscapeDataString(webSiteName);
  2495. if (slotName != null)
  2496. {
  2497. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  2498. }
  2499. url = url + "/newPassword";
  2500. List<string> queryParameters = new List<string>();
  2501. queryParameters.Add("api-version=2014-06-01");
  2502. if (queryParameters.Count > 0)
  2503. {
  2504. url = url + "?" + string.Join("&", queryParameters);
  2505. }
  2506. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  2507. // Trim '/' character from the end of baseUrl and beginning of url.
  2508. if (baseUrl[baseUrl.Length - 1] == '/')
  2509. {
  2510. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  2511. }
  2512. if (url[0] == '/')
  2513. {
  2514. url = url.Substring(1);
  2515. }
  2516. url = baseUrl + "/" + url;
  2517. url = url.Replace(" ", "%20");
  2518. // Create HTTP transport objects
  2519. HttpRequestMessage httpRequest = null;
  2520. try
  2521. {
  2522. httpRequest = new HttpRequestMessage();
  2523. httpRequest.Method = HttpMethod.Post;
  2524. httpRequest.RequestUri = new Uri(url);
  2525. // Set Headers
  2526. // Set Credentials
  2527. cancellationToken.ThrowIfCancellationRequested();
  2528. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  2529. // Send Request
  2530. HttpResponseMessage httpResponse = null;
  2531. try
  2532. {
  2533. if (shouldTrace)
  2534. {
  2535. TracingAdapter.SendRequest(invocationId, httpRequest);
  2536. }
  2537. cancellationToken.ThrowIfCancellationRequested();
  2538. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  2539. if (shouldTrace)
  2540. {
  2541. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  2542. }
  2543. HttpStatusCode statusCode = httpResponse.StatusCode;
  2544. if (statusCode != HttpStatusCode.OK)
  2545. {
  2546. cancellationToken.ThrowIfCancellationRequested();
  2547. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  2548. if (shouldTrace)
  2549. {
  2550. TracingAdapter.Error(invocationId, ex);
  2551. }
  2552. throw ex;
  2553. }
  2554. // Create Result
  2555. AzureOperationResponse result = null;
  2556. // Deserialize Response
  2557. result = new AzureOperationResponse();
  2558. result.StatusCode = statusCode;
  2559. if (httpResponse.Headers.Contains("x-ms-request-id"))
  2560. {
  2561. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  2562. }
  2563. if (shouldTrace)
  2564. {
  2565. TracingAdapter.Exit(invocationId, result);
  2566. }
  2567. return result;
  2568. }
  2569. finally
  2570. {
  2571. if (httpResponse != null)
  2572. {
  2573. httpResponse.Dispose();
  2574. }
  2575. }
  2576. }
  2577. finally
  2578. {
  2579. if (httpRequest != null)
  2580. {
  2581. httpRequest.Dispose();
  2582. }
  2583. }
  2584. }
  2585. /// <summary>
  2586. /// You can retrieve details for a web site by issuing an HTTP GET
  2587. /// request. (see
  2588. /// http://msdn.microsoft.com/en-us/library/windowsazure/dn167007.aspx
  2589. /// for more information)
  2590. /// </summary>
  2591. /// <param name='resourceGroupName'>
  2592. /// Required. The name of the resource group.
  2593. /// </param>
  2594. /// <param name='webSiteName'>
  2595. /// Required. The name of the web site.
  2596. /// </param>
  2597. /// <param name='slotName'>
  2598. /// Optional. The name of the slot.
  2599. /// </param>
  2600. /// <param name='parameters'>
  2601. /// Optional. Additional parameters.
  2602. /// </param>
  2603. /// <param name='cancellationToken'>
  2604. /// Cancellation token.
  2605. /// </param>
  2606. /// <returns>
  2607. /// The Get Web Site Details operation response.
  2608. /// </returns>
  2609. public async Task<WebSiteGetResponse> GetAsync(string resourceGroupName, string webSiteName, string slotName, WebSiteGetParameters parameters, CancellationToken cancellationToken)
  2610. {
  2611. // Validate
  2612. if (resourceGroupName == null)
  2613. {
  2614. throw new ArgumentNullException("resourceGroupName");
  2615. }
  2616. if (webSiteName == null)
  2617. {
  2618. throw new ArgumentNullException("webSiteName");
  2619. }
  2620. // Tracing
  2621. bool shouldTrace = TracingAdapter.IsEnabled;
  2622. string invocationId = null;
  2623. if (shouldTrace)
  2624. {
  2625. invocationId = TracingAdapter.NextInvocationId.ToString();
  2626. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  2627. tracingParameters.Add("resourceGroupName", resourceGroupName);
  2628. tracingParameters.Add("webSiteName", webSiteName);
  2629. tracingParameters.Add("slotName", slotName);
  2630. tracingParameters.Add("parameters", parameters);
  2631. TracingAdapter.Enter(invocationId, this, "GetAsync", tracingParameters);
  2632. }
  2633. // Construct URL
  2634. string url = "";
  2635. url = url + "/subscriptions/";
  2636. if (this.Client.Credentials.SubscriptionId != null)
  2637. {
  2638. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  2639. }
  2640. url = url + "/resourceGroups/";
  2641. url = url + Uri.EscapeDataString(resourceGroupName);
  2642. url = url + "/providers/";
  2643. url = url + "Microsoft.Web";
  2644. url = url + "/";
  2645. url = url + "sites";
  2646. url = url + "/";
  2647. url = url + Uri.EscapeDataString(webSiteName);
  2648. if (slotName != null)
  2649. {
  2650. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  2651. }
  2652. List<string> queryParameters = new List<string>();
  2653. queryParameters.Add("api-version=2014-06-01");
  2654. if (parameters != null && parameters.PropertiesToInclude != null && parameters.PropertiesToInclude.Count > 0)
  2655. {
  2656. queryParameters.Add("propertiesToInclude=" + Uri.EscapeDataString(string.Join(",", parameters.PropertiesToInclude)));
  2657. }
  2658. if (queryParameters.Count > 0)
  2659. {
  2660. url = url + "?" + string.Join("&", queryParameters);
  2661. }
  2662. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  2663. // Trim '/' character from the end of baseUrl and beginning of url.
  2664. if (baseUrl[baseUrl.Length - 1] == '/')
  2665. {
  2666. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  2667. }
  2668. if (url[0] == '/')
  2669. {
  2670. url = url.Substring(1);
  2671. }
  2672. url = baseUrl + "/" + url;
  2673. url = url.Replace(" ", "%20");
  2674. // Create HTTP transport objects
  2675. HttpRequestMessage httpRequest = null;
  2676. try
  2677. {
  2678. httpRequest = new HttpRequestMessage();
  2679. httpRequest.Method = HttpMethod.Get;
  2680. httpRequest.RequestUri = new Uri(url);
  2681. // Set Headers
  2682. // Set Credentials
  2683. cancellationToken.ThrowIfCancellationRequested();
  2684. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  2685. // Send Request
  2686. HttpResponseMessage httpResponse = null;
  2687. try
  2688. {
  2689. if (shouldTrace)
  2690. {
  2691. TracingAdapter.SendRequest(invocationId, httpRequest);
  2692. }
  2693. cancellationToken.ThrowIfCancellationRequested();
  2694. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  2695. if (shouldTrace)
  2696. {
  2697. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  2698. }
  2699. HttpStatusCode statusCode = httpResponse.StatusCode;
  2700. if (statusCode != HttpStatusCode.OK)
  2701. {
  2702. cancellationToken.ThrowIfCancellationRequested();
  2703. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  2704. if (shouldTrace)
  2705. {
  2706. TracingAdapter.Error(invocationId, ex);
  2707. }
  2708. throw ex;
  2709. }
  2710. // Create Result
  2711. WebSiteGetResponse result = null;
  2712. // Deserialize Response
  2713. if (statusCode == HttpStatusCode.OK)
  2714. {
  2715. cancellationToken.ThrowIfCancellationRequested();
  2716. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  2717. result = new WebSiteGetResponse();
  2718. JToken responseDoc = null;
  2719. if (string.IsNullOrEmpty(responseContent) == false)
  2720. {
  2721. responseDoc = JToken.Parse(responseContent);
  2722. }
  2723. if (responseDoc != null && responseDoc.Type != JTokenType.Null)
  2724. {
  2725. WebSite webSiteInstance = new WebSite();
  2726. result.WebSite = webSiteInstance;
  2727. JToken propertiesValue = responseDoc["properties"];
  2728. if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
  2729. {
  2730. WebSiteProperties propertiesInstance = new WebSiteProperties();
  2731. webSiteInstance.Properties = propertiesInstance;
  2732. JToken adminEnabledValue = propertiesValue["adminEnabled"];
  2733. if (adminEnabledValue != null && adminEnabledValue.Type != JTokenType.Null)
  2734. {
  2735. bool adminEnabledInstance = ((bool)adminEnabledValue);
  2736. propertiesInstance.AdminEnabled = adminEnabledInstance;
  2737. }
  2738. JToken availabilityStateValue = propertiesValue["availabilityState"];
  2739. if (availabilityStateValue != null && availabilityStateValue.Type != JTokenType.Null)
  2740. {
  2741. WebSpaceAvailabilityState availabilityStateInstance = ((WebSpaceAvailabilityState)Enum.Parse(typeof(WebSpaceAvailabilityState), ((string)availabilityStateValue), true));
  2742. propertiesInstance.AvailabilityState = availabilityStateInstance;
  2743. }
  2744. JToken enabledValue = propertiesValue["enabled"];
  2745. if (enabledValue != null && enabledValue.Type != JTokenType.Null)
  2746. {
  2747. bool enabledInstance = ((bool)enabledValue);
  2748. propertiesInstance.Enabled = enabledInstance;
  2749. }
  2750. JToken enabledHostNamesArray = propertiesValue["enabledHostNames"];
  2751. if (enabledHostNamesArray != null && enabledHostNamesArray.Type != JTokenType.Null)
  2752. {
  2753. foreach (JToken enabledHostNamesValue in ((JArray)enabledHostNamesArray))
  2754. {
  2755. propertiesInstance.EnabledHostNames.Add(((string)enabledHostNamesValue));
  2756. }
  2757. }
  2758. JToken hostNameSslStatesArray = propertiesValue["hostNameSslStates"];
  2759. if (hostNameSslStatesArray != null && hostNameSslStatesArray.Type != JTokenType.Null)
  2760. {
  2761. foreach (JToken hostNameSslStatesValue in ((JArray)hostNameSslStatesArray))
  2762. {
  2763. WebSiteProperties.WebSiteHostNameSslState webSiteHostNameSslStateInstance = new WebSiteProperties.WebSiteHostNameSslState();
  2764. propertiesInstance.HostNameSslStates.Add(webSiteHostNameSslStateInstance);
  2765. JToken nameValue = hostNameSslStatesValue["name"];
  2766. if (nameValue != null && nameValue.Type != JTokenType.Null)
  2767. {
  2768. string nameInstance = ((string)nameValue);
  2769. webSiteHostNameSslStateInstance.Name = nameInstance;
  2770. }
  2771. JToken sslStateValue = hostNameSslStatesValue["sslState"];
  2772. if (sslStateValue != null && sslStateValue.Type != JTokenType.Null)
  2773. {
  2774. WebSiteSslState sslStateInstance = ((WebSiteSslState)Enum.Parse(typeof(WebSiteSslState), ((string)sslStateValue), true));
  2775. webSiteHostNameSslStateInstance.SslState = sslStateInstance;
  2776. }
  2777. JToken thumbprintValue = hostNameSslStatesValue["thumbprint"];
  2778. if (thumbprintValue != null && thumbprintValue.Type != JTokenType.Null)
  2779. {
  2780. string thumbprintInstance = ((string)thumbprintValue);
  2781. webSiteHostNameSslStateInstance.Thumbprint = thumbprintInstance;
  2782. }
  2783. JToken virtualIPValue = hostNameSslStatesValue["virtualIP"];
  2784. if (virtualIPValue != null && virtualIPValue.Type != JTokenType.Null)
  2785. {
  2786. string virtualIPInstance = ((string)virtualIPValue);
  2787. webSiteHostNameSslStateInstance.VirtualIP = virtualIPInstance;
  2788. }
  2789. JToken ipBasedSslResultValue = hostNameSslStatesValue["ipBasedSslResult"];
  2790. if (ipBasedSslResultValue != null && ipBasedSslResultValue.Type != JTokenType.Null)
  2791. {
  2792. string ipBasedSslResultInstance = ((string)ipBasedSslResultValue);
  2793. webSiteHostNameSslStateInstance.IpBasedSslResult = ipBasedSslResultInstance;
  2794. }
  2795. JToken toUpdateValue = hostNameSslStatesValue["toUpdate"];
  2796. if (toUpdateValue != null && toUpdateValue.Type != JTokenType.Null)
  2797. {
  2798. bool toUpdateInstance = ((bool)toUpdateValue);
  2799. webSiteHostNameSslStateInstance.ToUpdate = toUpdateInstance;
  2800. }
  2801. JToken toUpdateIpBasedSslValue = hostNameSslStatesValue["toUpdateIpBasedSsl"];
  2802. if (toUpdateIpBasedSslValue != null && toUpdateIpBasedSslValue.Type != JTokenType.Null)
  2803. {
  2804. bool toUpdateIpBasedSslInstance = ((bool)toUpdateIpBasedSslValue);
  2805. webSiteHostNameSslStateInstance.ToUpdateIpBasedSsl = toUpdateIpBasedSslInstance;
  2806. }
  2807. }
  2808. }
  2809. JToken hostNamesArray = propertiesValue["hostNames"];
  2810. if (hostNamesArray != null && hostNamesArray.Type != JTokenType.Null)
  2811. {
  2812. foreach (JToken hostNamesValue in ((JArray)hostNamesArray))
  2813. {
  2814. propertiesInstance.HostNames.Add(((string)hostNamesValue));
  2815. }
  2816. }
  2817. JToken lastModifiedTimeUtcValue = propertiesValue["lastModifiedTimeUtc"];
  2818. if (lastModifiedTimeUtcValue != null && lastModifiedTimeUtcValue.Type != JTokenType.Null)
  2819. {
  2820. DateTime lastModifiedTimeUtcInstance = ((DateTime)lastModifiedTimeUtcValue);
  2821. propertiesInstance.LastModifiedTimeUtc = lastModifiedTimeUtcInstance;
  2822. }
  2823. JToken repositorySiteNameValue = propertiesValue["repositorySiteName"];
  2824. if (repositorySiteNameValue != null && repositorySiteNameValue.Type != JTokenType.Null)
  2825. {
  2826. string repositorySiteNameInstance = ((string)repositorySiteNameValue);
  2827. propertiesInstance.RepositorySiteName = repositorySiteNameInstance;
  2828. }
  2829. JToken runtimeAvailabilityStateValue = propertiesValue["runtimeAvailabilityState"];
  2830. if (runtimeAvailabilityStateValue != null && runtimeAvailabilityStateValue.Type != JTokenType.Null)
  2831. {
  2832. WebSiteRuntimeAvailabilityState runtimeAvailabilityStateInstance = ((WebSiteRuntimeAvailabilityState)Enum.Parse(typeof(WebSiteRuntimeAvailabilityState), ((string)runtimeAvailabilityStateValue), true));
  2833. propertiesInstance.RuntimeAvailabilityState = runtimeAvailabilityStateInstance;
  2834. }
  2835. JToken trafficManagerHostNamesArray = propertiesValue["trafficManagerHostNames"];
  2836. if (trafficManagerHostNamesArray != null && trafficManagerHostNamesArray.Type != JTokenType.Null)
  2837. {
  2838. foreach (JToken trafficManagerHostNamesValue in ((JArray)trafficManagerHostNamesArray))
  2839. {
  2840. propertiesInstance.TrafficManagerHostNames.Add(((string)trafficManagerHostNamesValue));
  2841. }
  2842. }
  2843. JToken selfLinkValue = propertiesValue["selfLink"];
  2844. if (selfLinkValue != null && selfLinkValue.Type != JTokenType.Null)
  2845. {
  2846. Uri selfLinkInstance = TypeConversion.TryParseUri(((string)selfLinkValue));
  2847. propertiesInstance.Uri = selfLinkInstance;
  2848. }
  2849. JToken serverFarmValue = propertiesValue["serverFarm"];
  2850. if (serverFarmValue != null && serverFarmValue.Type != JTokenType.Null)
  2851. {
  2852. string serverFarmInstance = ((string)serverFarmValue);
  2853. propertiesInstance.ServerFarm = serverFarmInstance;
  2854. }
  2855. JToken serverFarmIdValue = propertiesValue["serverFarmId"];
  2856. if (serverFarmIdValue != null && serverFarmIdValue.Type != JTokenType.Null)
  2857. {
  2858. string serverFarmIdInstance = ((string)serverFarmIdValue);
  2859. propertiesInstance.ServerFarmId = serverFarmIdInstance;
  2860. }
  2861. JToken skuValue = propertiesValue["sku"];
  2862. if (skuValue != null && skuValue.Type != JTokenType.Null)
  2863. {
  2864. SkuOptions skuInstance = ((SkuOptions)Enum.Parse(typeof(SkuOptions), ((string)skuValue), true));
  2865. propertiesInstance.Sku = skuInstance;
  2866. }
  2867. JToken sitePropertiesValue = propertiesValue["siteProperties"];
  2868. if (sitePropertiesValue != null && sitePropertiesValue.Type != JTokenType.Null)
  2869. {
  2870. WebSiteProperties.SiteProperties sitePropertiesInstance = new WebSiteProperties.SiteProperties();
  2871. propertiesInstance.Properties = sitePropertiesInstance;
  2872. JToken appSettingsSequenceElement = ((JToken)sitePropertiesValue["appSettings"]);
  2873. if (appSettingsSequenceElement != null && appSettingsSequenceElement.Type != JTokenType.Null)
  2874. {
  2875. foreach (JProperty property in appSettingsSequenceElement)
  2876. {
  2877. string appSettingsKey = ((string)property.Name);
  2878. string appSettingsValue = ((string)property.Value);
  2879. sitePropertiesInstance.AppSettings.Add(appSettingsKey, appSettingsValue);
  2880. }
  2881. }
  2882. JToken metadataSequenceElement = ((JToken)sitePropertiesValue["metadata"]);
  2883. if (metadataSequenceElement != null && metadataSequenceElement.Type != JTokenType.Null)
  2884. {
  2885. foreach (JProperty property2 in metadataSequenceElement)
  2886. {
  2887. string metadataKey = ((string)property2.Name);
  2888. string metadataValue = ((string)property2.Value);
  2889. sitePropertiesInstance.Metadata.Add(metadataKey, metadataValue);
  2890. }
  2891. }
  2892. JToken propertiesSequenceElement = ((JToken)sitePropertiesValue["properties"]);
  2893. if (propertiesSequenceElement != null && propertiesSequenceElement.Type != JTokenType.Null)
  2894. {
  2895. foreach (JProperty property3 in propertiesSequenceElement)
  2896. {
  2897. string propertiesKey = ((string)property3.Name);
  2898. string propertiesValue2 = ((string)property3.Value);
  2899. sitePropertiesInstance.Properties.Add(propertiesKey, propertiesValue2);
  2900. }
  2901. }
  2902. }
  2903. JToken siteConfigValue = propertiesValue["siteConfig"];
  2904. if (siteConfigValue != null && siteConfigValue.Type != JTokenType.Null)
  2905. {
  2906. WebSiteConfiguration siteConfigInstance = new WebSiteConfiguration();
  2907. propertiesInstance.SiteConfig = siteConfigInstance;
  2908. JToken appSettingsSequenceElement2 = ((JToken)siteConfigValue["appSettings"]);
  2909. if (appSettingsSequenceElement2 != null && appSettingsSequenceElement2.Type != JTokenType.Null)
  2910. {
  2911. foreach (JProperty property4 in appSettingsSequenceElement2)
  2912. {
  2913. string appSettingsKey2 = ((string)property4.Name);
  2914. string appSettingsValue2 = ((string)property4.Value);
  2915. siteConfigInstance.AppSettings.Add(appSettingsKey2, appSettingsValue2);
  2916. }
  2917. }
  2918. JToken connectionStringsArray = siteConfigValue["connectionStrings"];
  2919. if (connectionStringsArray != null && connectionStringsArray.Type != JTokenType.Null)
  2920. {
  2921. foreach (JToken connectionStringsValue in ((JArray)connectionStringsArray))
  2922. {
  2923. ConnectionStringInfo connStringInfoInstance = new ConnectionStringInfo();
  2924. siteConfigInstance.ConnectionStrings.Add(connStringInfoInstance);
  2925. JToken connectionStringValue = connectionStringsValue["connectionString"];
  2926. if (connectionStringValue != null && connectionStringValue.Type != JTokenType.Null)
  2927. {
  2928. string connectionStringInstance = ((string)connectionStringValue);
  2929. connStringInfoInstance.ConnectionString = connectionStringInstance;
  2930. }
  2931. JToken nameValue2 = connectionStringsValue["name"];
  2932. if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
  2933. {
  2934. string nameInstance2 = ((string)nameValue2);
  2935. connStringInfoInstance.Name = nameInstance2;
  2936. }
  2937. JToken typeValue = connectionStringsValue["type"];
  2938. if (typeValue != null && typeValue.Type != JTokenType.Null)
  2939. {
  2940. DatabaseServerType typeInstance = ((DatabaseServerType)Enum.Parse(typeof(DatabaseServerType), ((string)typeValue), true));
  2941. connStringInfoInstance.Type = typeInstance;
  2942. }
  2943. }
  2944. }
  2945. JToken defaultDocumentsArray = siteConfigValue["defaultDocuments"];
  2946. if (defaultDocumentsArray != null && defaultDocumentsArray.Type != JTokenType.Null)
  2947. {
  2948. foreach (JToken defaultDocumentsValue in ((JArray)defaultDocumentsArray))
  2949. {
  2950. siteConfigInstance.DefaultDocuments.Add(((string)defaultDocumentsValue));
  2951. }
  2952. }
  2953. JToken detailedErrorLoggingEnabledValue = siteConfigValue["detailedErrorLoggingEnabled"];
  2954. if (detailedErrorLoggingEnabledValue != null && detailedErrorLoggingEnabledValue.Type != JTokenType.Null)
  2955. {
  2956. bool detailedErrorLoggingEnabledInstance = ((bool)detailedErrorLoggingEnabledValue);
  2957. siteConfigInstance.DetailedErrorLoggingEnabled = detailedErrorLoggingEnabledInstance;
  2958. }
  2959. JToken documentRootValue = siteConfigValue["documentRoot"];
  2960. if (documentRootValue != null && documentRootValue.Type != JTokenType.Null)
  2961. {
  2962. string documentRootInstance = ((string)documentRootValue);
  2963. siteConfigInstance.DocumentRoot = documentRootInstance;
  2964. }
  2965. JToken handlerMappingsArray = siteConfigValue["handlerMappings"];
  2966. if (handlerMappingsArray != null && handlerMappingsArray.Type != JTokenType.Null)
  2967. {
  2968. foreach (JToken handlerMappingsValue in ((JArray)handlerMappingsArray))
  2969. {
  2970. WebSiteConfiguration.HandlerMapping handlerMappingInstance = new WebSiteConfiguration.HandlerMapping();
  2971. siteConfigInstance.HandlerMappings.Add(handlerMappingInstance);
  2972. JToken argumentsValue = handlerMappingsValue["arguments"];
  2973. if (argumentsValue != null && argumentsValue.Type != JTokenType.Null)
  2974. {
  2975. string argumentsInstance = ((string)argumentsValue);
  2976. handlerMappingInstance.Arguments = argumentsInstance;
  2977. }
  2978. JToken extensionValue = handlerMappingsValue["extension"];
  2979. if (extensionValue != null && extensionValue.Type != JTokenType.Null)
  2980. {
  2981. string extensionInstance = ((string)extensionValue);
  2982. handlerMappingInstance.Extension = extensionInstance;
  2983. }
  2984. JToken scriptProcessorValue = handlerMappingsValue["scriptProcessor"];
  2985. if (scriptProcessorValue != null && scriptProcessorValue.Type != JTokenType.Null)
  2986. {
  2987. string scriptProcessorInstance = ((string)scriptProcessorValue);
  2988. handlerMappingInstance.ScriptProcessor = scriptProcessorInstance;
  2989. }
  2990. }
  2991. }
  2992. JToken httpLoggingEnabledValue = siteConfigValue["httpLoggingEnabled"];
  2993. if (httpLoggingEnabledValue != null && httpLoggingEnabledValue.Type != JTokenType.Null)
  2994. {
  2995. bool httpLoggingEnabledInstance = ((bool)httpLoggingEnabledValue);
  2996. siteConfigInstance.HttpLoggingEnabled = httpLoggingEnabledInstance;
  2997. }
  2998. JToken logsDirectorySizeLimitValue = siteConfigValue["logsDirectorySizeLimit"];
  2999. if (logsDirectorySizeLimitValue != null && logsDirectorySizeLimitValue.Type != JTokenType.Null)
  3000. {
  3001. int logsDirectorySizeLimitInstance = ((int)logsDirectorySizeLimitValue);
  3002. siteConfigInstance.LogsDirectorySizeLimit = logsDirectorySizeLimitInstance;
  3003. }
  3004. JToken managedPipelineModeValue = siteConfigValue["managedPipelineMode"];
  3005. if (managedPipelineModeValue != null && managedPipelineModeValue.Type != JTokenType.Null)
  3006. {
  3007. ManagedPipelineMode managedPipelineModeInstance = ((ManagedPipelineMode)Enum.Parse(typeof(ManagedPipelineMode), ((string)managedPipelineModeValue), true));
  3008. siteConfigInstance.ManagedPipelineMode = managedPipelineModeInstance;
  3009. }
  3010. JToken metadataSequenceElement2 = ((JToken)siteConfigValue["metadata"]);
  3011. if (metadataSequenceElement2 != null && metadataSequenceElement2.Type != JTokenType.Null)
  3012. {
  3013. foreach (JProperty property5 in metadataSequenceElement2)
  3014. {
  3015. string metadataKey2 = ((string)property5.Name);
  3016. string metadataValue2 = ((string)property5.Value);
  3017. siteConfigInstance.Metadata.Add(metadataKey2, metadataValue2);
  3018. }
  3019. }
  3020. JToken netFrameworkVersionValue = siteConfigValue["netFrameworkVersion"];
  3021. if (netFrameworkVersionValue != null && netFrameworkVersionValue.Type != JTokenType.Null)
  3022. {
  3023. string netFrameworkVersionInstance = ((string)netFrameworkVersionValue);
  3024. siteConfigInstance.NetFrameworkVersion = netFrameworkVersionInstance;
  3025. }
  3026. JToken numberOfWorkersValue = siteConfigValue["numberOfWorkers"];
  3027. if (numberOfWorkersValue != null && numberOfWorkersValue.Type != JTokenType.Null)
  3028. {
  3029. int numberOfWorkersInstance = ((int)numberOfWorkersValue);
  3030. siteConfigInstance.NumberOfWorkers = numberOfWorkersInstance;
  3031. }
  3032. JToken phpVersionValue = siteConfigValue["phpVersion"];
  3033. if (phpVersionValue != null && phpVersionValue.Type != JTokenType.Null)
  3034. {
  3035. string phpVersionInstance = ((string)phpVersionValue);
  3036. siteConfigInstance.PhpVersion = phpVersionInstance;
  3037. }
  3038. JToken pythonVersionValue = siteConfigValue["pythonVersion"];
  3039. if (pythonVersionValue != null && pythonVersionValue.Type != JTokenType.Null)
  3040. {
  3041. string pythonVersionInstance = ((string)pythonVersionValue);
  3042. siteConfigInstance.PythonVersion = pythonVersionInstance;
  3043. }
  3044. JToken publishingPasswordValue = siteConfigValue["publishingPassword"];
  3045. if (publishingPasswordValue != null && publishingPasswordValue.Type != JTokenType.Null)
  3046. {
  3047. string publishingPasswordInstance = ((string)publishingPasswordValue);
  3048. siteConfigInstance.PublishingPassword = publishingPasswordInstance;
  3049. }
  3050. JToken publishingUsernameValue = siteConfigValue["publishingUsername"];
  3051. if (publishingUsernameValue != null && publishingUsernameValue.Type != JTokenType.Null)
  3052. {
  3053. string publishingUsernameInstance = ((string)publishingUsernameValue);
  3054. siteConfigInstance.PublishingUserName = publishingUsernameInstance;
  3055. }
  3056. JToken remoteDebuggingEnabledValue = siteConfigValue["RemoteDebuggingEnabled"];
  3057. if (remoteDebuggingEnabledValue != null && remoteDebuggingEnabledValue.Type != JTokenType.Null)
  3058. {
  3059. bool remoteDebuggingEnabledInstance = ((bool)remoteDebuggingEnabledValue);
  3060. siteConfigInstance.RemoteDebuggingEnabled = remoteDebuggingEnabledInstance;
  3061. }
  3062. JToken remoteDebuggingVersionValue = siteConfigValue["remoteDebuggingVersion"];
  3063. if (remoteDebuggingVersionValue != null && remoteDebuggingVersionValue.Type != JTokenType.Null)
  3064. {
  3065. RemoteDebuggingVersion remoteDebuggingVersionInstance = ((RemoteDebuggingVersion)Enum.Parse(typeof(RemoteDebuggingVersion), ((string)remoteDebuggingVersionValue), true));
  3066. siteConfigInstance.RemoteDebuggingVersion = remoteDebuggingVersionInstance;
  3067. }
  3068. JToken requestTracingEnabledValue = siteConfigValue["requestTracingEnabled"];
  3069. if (requestTracingEnabledValue != null && requestTracingEnabledValue.Type != JTokenType.Null)
  3070. {
  3071. bool requestTracingEnabledInstance = ((bool)requestTracingEnabledValue);
  3072. siteConfigInstance.RequestTracingEnabled = requestTracingEnabledInstance;
  3073. }
  3074. JToken requestTracingExpirationTimeValue = siteConfigValue["requestTracingExpirationTime"];
  3075. if (requestTracingExpirationTimeValue != null && requestTracingExpirationTimeValue.Type != JTokenType.Null)
  3076. {
  3077. DateTime requestTracingExpirationTimeInstance = ((DateTime)requestTracingExpirationTimeValue);
  3078. siteConfigInstance.RequestTracingExpirationTime = requestTracingExpirationTimeInstance;
  3079. }
  3080. JToken scmTypeValue = siteConfigValue["scmType"];
  3081. if (scmTypeValue != null && scmTypeValue.Type != JTokenType.Null)
  3082. {
  3083. string scmTypeInstance = ((string)scmTypeValue);
  3084. siteConfigInstance.ScmType = scmTypeInstance;
  3085. }
  3086. JToken autoSwapSlotNameValue = siteConfigValue["autoSwapSlotName"];
  3087. if (autoSwapSlotNameValue != null && autoSwapSlotNameValue.Type != JTokenType.Null)
  3088. {
  3089. string autoSwapSlotNameInstance = ((string)autoSwapSlotNameValue);
  3090. siteConfigInstance.AutoSwapSlotName = autoSwapSlotNameInstance;
  3091. }
  3092. JToken use32BitWorkerProcessValue = siteConfigValue["use32BitWorkerProcess"];
  3093. if (use32BitWorkerProcessValue != null && use32BitWorkerProcessValue.Type != JTokenType.Null)
  3094. {
  3095. bool use32BitWorkerProcessInstance = ((bool)use32BitWorkerProcessValue);
  3096. siteConfigInstance.Use32BitWorkerProcess = use32BitWorkerProcessInstance;
  3097. }
  3098. JToken webSocketsEnabledValue = siteConfigValue["webSocketsEnabled"];
  3099. if (webSocketsEnabledValue != null && webSocketsEnabledValue.Type != JTokenType.Null)
  3100. {
  3101. bool webSocketsEnabledInstance = ((bool)webSocketsEnabledValue);
  3102. siteConfigInstance.WebSocketsEnabled = webSocketsEnabledInstance;
  3103. }
  3104. JToken limitsValue = siteConfigValue["limits"];
  3105. if (limitsValue != null && limitsValue.Type != JTokenType.Null)
  3106. {
  3107. SiteLimits limitsInstance = new SiteLimits();
  3108. siteConfigInstance.Limits = limitsInstance;
  3109. JToken maxPercentageCpuValue = limitsValue["maxPercentageCpu"];
  3110. if (maxPercentageCpuValue != null && maxPercentageCpuValue.Type != JTokenType.Null)
  3111. {
  3112. double maxPercentageCpuInstance = ((double)maxPercentageCpuValue);
  3113. limitsInstance.MaxPercentageCpu = maxPercentageCpuInstance;
  3114. }
  3115. JToken maxMemoryInMbValue = limitsValue["maxMemoryInMb"];
  3116. if (maxMemoryInMbValue != null && maxMemoryInMbValue.Type != JTokenType.Null)
  3117. {
  3118. long maxMemoryInMbInstance = ((long)maxMemoryInMbValue);
  3119. limitsInstance.MaxMemoryInMb = maxMemoryInMbInstance;
  3120. }
  3121. JToken maxDiskSizeInMbValue = limitsValue["maxDiskSizeInMb"];
  3122. if (maxDiskSizeInMbValue != null && maxDiskSizeInMbValue.Type != JTokenType.Null)
  3123. {
  3124. long maxDiskSizeInMbInstance = ((long)maxDiskSizeInMbValue);
  3125. limitsInstance.MaxDiskSizeInMb = maxDiskSizeInMbInstance;
  3126. }
  3127. }
  3128. }
  3129. JToken stateValue = propertiesValue["state"];
  3130. if (stateValue != null && stateValue.Type != JTokenType.Null)
  3131. {
  3132. WebSiteState stateInstance = ((WebSiteState)Enum.Parse(typeof(WebSiteState), ((string)stateValue), true));
  3133. propertiesInstance.State = stateInstance;
  3134. }
  3135. JToken usageStateValue = propertiesValue["usageState"];
  3136. if (usageStateValue != null && usageStateValue.Type != JTokenType.Null)
  3137. {
  3138. WebSiteUsageState usageStateInstance = ((WebSiteUsageState)Enum.Parse(typeof(WebSiteUsageState), ((string)usageStateValue), true));
  3139. propertiesInstance.UsageState = usageStateInstance;
  3140. }
  3141. JToken webSpaceValue = propertiesValue["webSpace"];
  3142. if (webSpaceValue != null && webSpaceValue.Type != JTokenType.Null)
  3143. {
  3144. string webSpaceInstance = ((string)webSpaceValue);
  3145. propertiesInstance.WebSpace = webSpaceInstance;
  3146. }
  3147. JToken provisioningStateValue = propertiesValue["provisioningState"];
  3148. if (provisioningStateValue != null && provisioningStateValue.Type != JTokenType.Null)
  3149. {
  3150. string provisioningStateInstance = ((string)provisioningStateValue);
  3151. propertiesInstance.ProvisioningState = provisioningStateInstance;
  3152. }
  3153. }
  3154. JToken idValue = responseDoc["id"];
  3155. if (idValue != null && idValue.Type != JTokenType.Null)
  3156. {
  3157. string idInstance = ((string)idValue);
  3158. webSiteInstance.Id = idInstance;
  3159. }
  3160. JToken nameValue3 = responseDoc["name"];
  3161. if (nameValue3 != null && nameValue3.Type != JTokenType.Null)
  3162. {
  3163. string nameInstance3 = ((string)nameValue3);
  3164. webSiteInstance.Name = nameInstance3;
  3165. }
  3166. JToken locationValue = responseDoc["location"];
  3167. if (locationValue != null && locationValue.Type != JTokenType.Null)
  3168. {
  3169. string locationInstance = ((string)locationValue);
  3170. webSiteInstance.Location = locationInstance;
  3171. }
  3172. JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
  3173. if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
  3174. {
  3175. foreach (JProperty property6 in tagsSequenceElement)
  3176. {
  3177. string tagsKey = ((string)property6.Name);
  3178. string tagsValue = ((string)property6.Value);
  3179. webSiteInstance.Tags.Add(tagsKey, tagsValue);
  3180. }
  3181. }
  3182. JToken typeValue2 = responseDoc["type"];
  3183. if (typeValue2 != null && typeValue2.Type != JTokenType.Null)
  3184. {
  3185. string typeInstance2 = ((string)typeValue2);
  3186. webSiteInstance.Type = typeInstance2;
  3187. }
  3188. }
  3189. }
  3190. result.StatusCode = statusCode;
  3191. if (httpResponse.Headers.Contains("x-ms-request-id"))
  3192. {
  3193. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  3194. }
  3195. if (shouldTrace)
  3196. {
  3197. TracingAdapter.Exit(invocationId, result);
  3198. }
  3199. return result;
  3200. }
  3201. finally
  3202. {
  3203. if (httpResponse != null)
  3204. {
  3205. httpResponse.Dispose();
  3206. }
  3207. }
  3208. }
  3209. finally
  3210. {
  3211. if (httpRequest != null)
  3212. {
  3213. httpRequest.Dispose();
  3214. }
  3215. }
  3216. }
  3217. /// <summary>
  3218. /// Restart the web site.
  3219. /// </summary>
  3220. /// <param name='resourceGroupName'>
  3221. /// Required. The name of the resource group
  3222. /// </param>
  3223. /// <param name='webSiteName'>
  3224. /// Required. Name of website
  3225. /// </param>
  3226. /// <param name='slotName'>
  3227. /// Optional. The name of the slot of the website
  3228. /// </param>
  3229. /// <param name='cancellationToken'>
  3230. /// Cancellation token.
  3231. /// </param>
  3232. /// <returns>
  3233. /// List of app settings for the website.
  3234. /// </returns>
  3235. public async Task<WebSiteAppSettingsResult> GetAppSettingsAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
  3236. {
  3237. // Validate
  3238. if (resourceGroupName == null)
  3239. {
  3240. throw new ArgumentNullException("resourceGroupName");
  3241. }
  3242. if (webSiteName == null)
  3243. {
  3244. throw new ArgumentNullException("webSiteName");
  3245. }
  3246. // Tracing
  3247. bool shouldTrace = TracingAdapter.IsEnabled;
  3248. string invocationId = null;
  3249. if (shouldTrace)
  3250. {
  3251. invocationId = TracingAdapter.NextInvocationId.ToString();
  3252. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  3253. tracingParameters.Add("resourceGroupName", resourceGroupName);
  3254. tracingParameters.Add("webSiteName", webSiteName);
  3255. tracingParameters.Add("slotName", slotName);
  3256. TracingAdapter.Enter(invocationId, this, "GetAppSettingsAsync", tracingParameters);
  3257. }
  3258. // Construct URL
  3259. string url = "";
  3260. url = url + "/subscriptions/";
  3261. if (this.Client.Credentials.SubscriptionId != null)
  3262. {
  3263. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  3264. }
  3265. url = url + "/resourceGroups/";
  3266. url = url + Uri.EscapeDataString(resourceGroupName);
  3267. url = url + "/providers/";
  3268. url = url + "Microsoft.Web";
  3269. url = url + "/";
  3270. url = url + "sites";
  3271. url = url + "/";
  3272. url = url + Uri.EscapeDataString(webSiteName);
  3273. if (slotName != null)
  3274. {
  3275. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  3276. }
  3277. url = url + "/config/appsettings/list";
  3278. List<string> queryParameters = new List<string>();
  3279. queryParameters.Add("api-version=2014-06-01");
  3280. if (queryParameters.Count > 0)
  3281. {
  3282. url = url + "?" + string.Join("&", queryParameters);
  3283. }
  3284. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  3285. // Trim '/' character from the end of baseUrl and beginning of url.
  3286. if (baseUrl[baseUrl.Length - 1] == '/')
  3287. {
  3288. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  3289. }
  3290. if (url[0] == '/')
  3291. {
  3292. url = url.Substring(1);
  3293. }
  3294. url = baseUrl + "/" + url;
  3295. url = url.Replace(" ", "%20");
  3296. // Create HTTP transport objects
  3297. HttpRequestMessage httpRequest = null;
  3298. try
  3299. {
  3300. httpRequest = new HttpRequestMessage();
  3301. httpRequest.Method = HttpMethod.Post;
  3302. httpRequest.RequestUri = new Uri(url);
  3303. // Set Headers
  3304. // Set Credentials
  3305. cancellationToken.ThrowIfCancellationRequested();
  3306. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  3307. // Send Request
  3308. HttpResponseMessage httpResponse = null;
  3309. try
  3310. {
  3311. if (shouldTrace)
  3312. {
  3313. TracingAdapter.SendRequest(invocationId, httpRequest);
  3314. }
  3315. cancellationToken.ThrowIfCancellationRequested();
  3316. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  3317. if (shouldTrace)
  3318. {
  3319. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  3320. }
  3321. HttpStatusCode statusCode = httpResponse.StatusCode;
  3322. if (statusCode != HttpStatusCode.OK)
  3323. {
  3324. cancellationToken.ThrowIfCancellationRequested();
  3325. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  3326. if (shouldTrace)
  3327. {
  3328. TracingAdapter.Error(invocationId, ex);
  3329. }
  3330. throw ex;
  3331. }
  3332. // Create Result
  3333. WebSiteAppSettingsResult result = null;
  3334. // Deserialize Response
  3335. if (statusCode == HttpStatusCode.OK)
  3336. {
  3337. cancellationToken.ThrowIfCancellationRequested();
  3338. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  3339. result = new WebSiteAppSettingsResult();
  3340. JToken responseDoc = null;
  3341. if (string.IsNullOrEmpty(responseContent) == false)
  3342. {
  3343. responseDoc = JToken.Parse(responseContent);
  3344. }
  3345. if (responseDoc != null && responseDoc.Type != JTokenType.Null)
  3346. {
  3347. WebSiteAppSettingsEnvelope resourceInstance = new WebSiteAppSettingsEnvelope();
  3348. result.Resource = resourceInstance;
  3349. JToken propertiesArray = responseDoc["properties"];
  3350. if (propertiesArray != null && propertiesArray.Type != JTokenType.Null)
  3351. {
  3352. foreach (JToken propertiesValue in ((JArray)propertiesArray))
  3353. {
  3354. NameValuePair nameValuePairInstance = new NameValuePair();
  3355. resourceInstance.Properties.Add(nameValuePairInstance);
  3356. JToken nameValue = propertiesValue["name"];
  3357. if (nameValue != null && nameValue.Type != JTokenType.Null)
  3358. {
  3359. string nameInstance = ((string)nameValue);
  3360. nameValuePairInstance.Name = nameInstance;
  3361. }
  3362. JToken valueValue = propertiesValue["value"];
  3363. if (valueValue != null && valueValue.Type != JTokenType.Null)
  3364. {
  3365. string valueInstance = ((string)valueValue);
  3366. nameValuePairInstance.Value = valueInstance;
  3367. }
  3368. }
  3369. }
  3370. JToken idValue = responseDoc["id"];
  3371. if (idValue != null && idValue.Type != JTokenType.Null)
  3372. {
  3373. string idInstance = ((string)idValue);
  3374. resourceInstance.Id = idInstance;
  3375. }
  3376. JToken nameValue2 = responseDoc["name"];
  3377. if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
  3378. {
  3379. string nameInstance2 = ((string)nameValue2);
  3380. resourceInstance.Name = nameInstance2;
  3381. }
  3382. JToken locationValue = responseDoc["location"];
  3383. if (locationValue != null && locationValue.Type != JTokenType.Null)
  3384. {
  3385. string locationInstance = ((string)locationValue);
  3386. resourceInstance.Location = locationInstance;
  3387. }
  3388. JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
  3389. if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
  3390. {
  3391. foreach (JProperty property in tagsSequenceElement)
  3392. {
  3393. string tagsKey = ((string)property.Name);
  3394. string tagsValue = ((string)property.Value);
  3395. resourceInstance.Tags.Add(tagsKey, tagsValue);
  3396. }
  3397. }
  3398. JToken typeValue = responseDoc["type"];
  3399. if (typeValue != null && typeValue.Type != JTokenType.Null)
  3400. {
  3401. string typeInstance = ((string)typeValue);
  3402. resourceInstance.Type = typeInstance;
  3403. }
  3404. }
  3405. }
  3406. result.StatusCode = statusCode;
  3407. if (httpResponse.Headers.Contains("x-ms-request-id"))
  3408. {
  3409. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  3410. }
  3411. if (shouldTrace)
  3412. {
  3413. TracingAdapter.Exit(invocationId, result);
  3414. }
  3415. return result;
  3416. }
  3417. finally
  3418. {
  3419. if (httpResponse != null)
  3420. {
  3421. httpResponse.Dispose();
  3422. }
  3423. }
  3424. }
  3425. finally
  3426. {
  3427. if (httpRequest != null)
  3428. {
  3429. httpRequest.Dispose();
  3430. }
  3431. }
  3432. }
  3433. /// <summary>
  3434. /// Gets a schedule configuration for site backups.
  3435. /// </summary>
  3436. /// <param name='resourceGroupName'>
  3437. /// Required. The name of the web space.
  3438. /// </param>
  3439. /// <param name='webSiteName'>
  3440. /// Required. The name of the web site.
  3441. /// </param>
  3442. /// <param name='slotName'>
  3443. /// Optional. The name of the slot.
  3444. /// </param>
  3445. /// <param name='cancellationToken'>
  3446. /// Cancellation token.
  3447. /// </param>
  3448. /// <returns>
  3449. /// Scheduled backup definition.
  3450. /// </returns>
  3451. public async Task<WebSiteGetBackupConfigurationResponse> GetBackupConfigurationAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
  3452. {
  3453. // Validate
  3454. if (resourceGroupName == null)
  3455. {
  3456. throw new ArgumentNullException("resourceGroupName");
  3457. }
  3458. if (webSiteName == null)
  3459. {
  3460. throw new ArgumentNullException("webSiteName");
  3461. }
  3462. // Tracing
  3463. bool shouldTrace = TracingAdapter.IsEnabled;
  3464. string invocationId = null;
  3465. if (shouldTrace)
  3466. {
  3467. invocationId = TracingAdapter.NextInvocationId.ToString();
  3468. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  3469. tracingParameters.Add("resourceGroupName", resourceGroupName);
  3470. tracingParameters.Add("webSiteName", webSiteName);
  3471. tracingParameters.Add("slotName", slotName);
  3472. TracingAdapter.Enter(invocationId, this, "GetBackupConfigurationAsync", tracingParameters);
  3473. }
  3474. // Construct URL
  3475. string url = "";
  3476. url = url + "/subscriptions/";
  3477. if (this.Client.Credentials.SubscriptionId != null)
  3478. {
  3479. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  3480. }
  3481. url = url + "/resourceGroups/";
  3482. url = url + Uri.EscapeDataString(resourceGroupName);
  3483. url = url + "/providers/";
  3484. url = url + "Microsoft.Web";
  3485. url = url + "/";
  3486. url = url + "sites";
  3487. url = url + "/";
  3488. url = url + Uri.EscapeDataString(webSiteName);
  3489. if (slotName != null)
  3490. {
  3491. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  3492. }
  3493. url = url + "/backup/config";
  3494. List<string> queryParameters = new List<string>();
  3495. queryParameters.Add("api-version=2014-06-01");
  3496. if (queryParameters.Count > 0)
  3497. {
  3498. url = url + "?" + string.Join("&", queryParameters);
  3499. }
  3500. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  3501. // Trim '/' character from the end of baseUrl and beginning of url.
  3502. if (baseUrl[baseUrl.Length - 1] == '/')
  3503. {
  3504. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  3505. }
  3506. if (url[0] == '/')
  3507. {
  3508. url = url.Substring(1);
  3509. }
  3510. url = baseUrl + "/" + url;
  3511. url = url.Replace(" ", "%20");
  3512. // Create HTTP transport objects
  3513. HttpRequestMessage httpRequest = null;
  3514. try
  3515. {
  3516. httpRequest = new HttpRequestMessage();
  3517. httpRequest.Method = HttpMethod.Get;
  3518. httpRequest.RequestUri = new Uri(url);
  3519. // Set Headers
  3520. httpRequest.Headers.Add("x-ms-version", "2014-06-01");
  3521. // Set Credentials
  3522. cancellationToken.ThrowIfCancellationRequested();
  3523. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  3524. // Send Request
  3525. HttpResponseMessage httpResponse = null;
  3526. try
  3527. {
  3528. if (shouldTrace)
  3529. {
  3530. TracingAdapter.SendRequest(invocationId, httpRequest);
  3531. }
  3532. cancellationToken.ThrowIfCancellationRequested();
  3533. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  3534. if (shouldTrace)
  3535. {
  3536. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  3537. }
  3538. HttpStatusCode statusCode = httpResponse.StatusCode;
  3539. if (statusCode != HttpStatusCode.OK)
  3540. {
  3541. cancellationToken.ThrowIfCancellationRequested();
  3542. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  3543. if (shouldTrace)
  3544. {
  3545. TracingAdapter.Error(invocationId, ex);
  3546. }
  3547. throw ex;
  3548. }
  3549. // Create Result
  3550. WebSiteGetBackupConfigurationResponse result = null;
  3551. // Deserialize Response
  3552. if (statusCode == HttpStatusCode.OK)
  3553. {
  3554. cancellationToken.ThrowIfCancellationRequested();
  3555. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  3556. result = new WebSiteGetBackupConfigurationResponse();
  3557. JToken responseDoc = null;
  3558. if (string.IsNullOrEmpty(responseContent) == false)
  3559. {
  3560. responseDoc = JToken.Parse(responseContent);
  3561. }
  3562. if (responseDoc != null && responseDoc.Type != JTokenType.Null)
  3563. {
  3564. BackupScheduleRequestEnvelope backupScheduleInstance = new BackupScheduleRequestEnvelope();
  3565. result.BackupSchedule = backupScheduleInstance;
  3566. JToken propertiesValue = responseDoc["properties"];
  3567. if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
  3568. {
  3569. BackupScheduleRequestResponse propertiesInstance = new BackupScheduleRequestResponse();
  3570. backupScheduleInstance.Properties = propertiesInstance;
  3571. JToken enabledValue = propertiesValue["enabled"];
  3572. if (enabledValue != null && enabledValue.Type != JTokenType.Null)
  3573. {
  3574. bool enabledInstance = ((bool)enabledValue);
  3575. propertiesInstance.Enabled = enabledInstance;
  3576. }
  3577. JToken nameValue = propertiesValue["name"];
  3578. if (nameValue != null && nameValue.Type != JTokenType.Null)
  3579. {
  3580. string nameInstance = ((string)nameValue);
  3581. propertiesInstance.Name = nameInstance;
  3582. }
  3583. JToken storageAccountUrlValue = propertiesValue["storageAccountUrl"];
  3584. if (storageAccountUrlValue != null && storageAccountUrlValue.Type != JTokenType.Null)
  3585. {
  3586. string storageAccountUrlInstance = ((string)storageAccountUrlValue);
  3587. propertiesInstance.StorageAccountUrl = storageAccountUrlInstance;
  3588. }
  3589. JToken backupScheduleValue = propertiesValue["backupSchedule"];
  3590. if (backupScheduleValue != null && backupScheduleValue.Type != JTokenType.Null)
  3591. {
  3592. BackupSchedule backupScheduleInstance2 = new BackupSchedule();
  3593. propertiesInstance.BackupSchedule = backupScheduleInstance2;
  3594. JToken frequencyIntervalValue = backupScheduleValue["frequencyInterval"];
  3595. if (frequencyIntervalValue != null && frequencyIntervalValue.Type != JTokenType.Null)
  3596. {
  3597. int frequencyIntervalInstance = ((int)frequencyIntervalValue);
  3598. backupScheduleInstance2.FrequencyInterval = frequencyIntervalInstance;
  3599. }
  3600. JToken frequencyUnitValue = backupScheduleValue["frequencyUnit"];
  3601. if (frequencyUnitValue != null && frequencyUnitValue.Type != JTokenType.Null)
  3602. {
  3603. FrequencyUnit frequencyUnitInstance = ((FrequencyUnit)Enum.Parse(typeof(FrequencyUnit), ((string)frequencyUnitValue), true));
  3604. backupScheduleInstance2.FrequencyUnit = frequencyUnitInstance;
  3605. }
  3606. JToken keepAtLeastOneBackupValue = backupScheduleValue["keepAtLeastOneBackup"];
  3607. if (keepAtLeastOneBackupValue != null && keepAtLeastOneBackupValue.Type != JTokenType.Null)
  3608. {
  3609. bool keepAtLeastOneBackupInstance = ((bool)keepAtLeastOneBackupValue);
  3610. backupScheduleInstance2.KeepAtLeastOneBackup = keepAtLeastOneBackupInstance;
  3611. }
  3612. JToken lastExecutionTimeValue = backupScheduleValue["lastExecutionTime"];
  3613. if (lastExecutionTimeValue != null && lastExecutionTimeValue.Type != JTokenType.Null)
  3614. {
  3615. DateTime lastExecutionTimeInstance = ((DateTime)lastExecutionTimeValue);
  3616. backupScheduleInstance2.LastExecutionTime = lastExecutionTimeInstance;
  3617. }
  3618. JToken retentionPeriodInDaysValue = backupScheduleValue["retentionPeriodInDays"];
  3619. if (retentionPeriodInDaysValue != null && retentionPeriodInDaysValue.Type != JTokenType.Null)
  3620. {
  3621. int retentionPeriodInDaysInstance = ((int)retentionPeriodInDaysValue);
  3622. backupScheduleInstance2.RetentionPeriodInDays = retentionPeriodInDaysInstance;
  3623. }
  3624. JToken startTimeValue = backupScheduleValue["startTime"];
  3625. if (startTimeValue != null && startTimeValue.Type != JTokenType.Null)
  3626. {
  3627. DateTime startTimeInstance = ((DateTime)startTimeValue);
  3628. backupScheduleInstance2.StartTime = startTimeInstance;
  3629. }
  3630. }
  3631. JToken databasesArray = propertiesValue["databases"];
  3632. if (databasesArray != null && databasesArray.Type != JTokenType.Null)
  3633. {
  3634. foreach (JToken databasesValue in ((JArray)databasesArray))
  3635. {
  3636. DatabaseBackupSetting databaseBackupSettingInstance = new DatabaseBackupSetting();
  3637. propertiesInstance.Databases.Add(databaseBackupSettingInstance);
  3638. JToken connectionStringValue = databasesValue["connectionString"];
  3639. if (connectionStringValue != null && connectionStringValue.Type != JTokenType.Null)
  3640. {
  3641. string connectionStringInstance = ((string)connectionStringValue);
  3642. databaseBackupSettingInstance.ConnectionString = connectionStringInstance;
  3643. }
  3644. JToken connectionStringNameValue = databasesValue["connectionStringName"];
  3645. if (connectionStringNameValue != null && connectionStringNameValue.Type != JTokenType.Null)
  3646. {
  3647. string connectionStringNameInstance = ((string)connectionStringNameValue);
  3648. databaseBackupSettingInstance.ConnectionStringName = connectionStringNameInstance;
  3649. }
  3650. JToken databaseTypeValue = databasesValue["databaseType"];
  3651. if (databaseTypeValue != null && databaseTypeValue.Type != JTokenType.Null)
  3652. {
  3653. string databaseTypeInstance = ((string)databaseTypeValue);
  3654. databaseBackupSettingInstance.DatabaseType = databaseTypeInstance;
  3655. }
  3656. JToken nameValue2 = databasesValue["name"];
  3657. if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
  3658. {
  3659. string nameInstance2 = ((string)nameValue2);
  3660. databaseBackupSettingInstance.Name = nameInstance2;
  3661. }
  3662. }
  3663. }
  3664. }
  3665. JToken idValue = responseDoc["id"];
  3666. if (idValue != null && idValue.Type != JTokenType.Null)
  3667. {
  3668. string idInstance = ((string)idValue);
  3669. backupScheduleInstance.Id = idInstance;
  3670. }
  3671. JToken nameValue3 = responseDoc["name"];
  3672. if (nameValue3 != null && nameValue3.Type != JTokenType.Null)
  3673. {
  3674. string nameInstance3 = ((string)nameValue3);
  3675. backupScheduleInstance.Name = nameInstance3;
  3676. }
  3677. JToken locationValue = responseDoc["location"];
  3678. if (locationValue != null && locationValue.Type != JTokenType.Null)
  3679. {
  3680. string locationInstance = ((string)locationValue);
  3681. backupScheduleInstance.Location = locationInstance;
  3682. }
  3683. JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
  3684. if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
  3685. {
  3686. foreach (JProperty property in tagsSequenceElement)
  3687. {
  3688. string tagsKey = ((string)property.Name);
  3689. string tagsValue = ((string)property.Value);
  3690. backupScheduleInstance.Tags.Add(tagsKey, tagsValue);
  3691. }
  3692. }
  3693. JToken typeValue = responseDoc["type"];
  3694. if (typeValue != null && typeValue.Type != JTokenType.Null)
  3695. {
  3696. string typeInstance = ((string)typeValue);
  3697. backupScheduleInstance.Type = typeInstance;
  3698. }
  3699. }
  3700. }
  3701. result.StatusCode = statusCode;
  3702. if (httpResponse.Headers.Contains("x-ms-request-id"))
  3703. {
  3704. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  3705. }
  3706. if (shouldTrace)
  3707. {
  3708. TracingAdapter.Exit(invocationId, result);
  3709. }
  3710. return result;
  3711. }
  3712. finally
  3713. {
  3714. if (httpResponse != null)
  3715. {
  3716. httpResponse.Dispose();
  3717. }
  3718. }
  3719. }
  3720. finally
  3721. {
  3722. if (httpRequest != null)
  3723. {
  3724. httpRequest.Dispose();
  3725. }
  3726. }
  3727. }
  3728. /// <summary>
  3729. /// You can retrieve the config settings for a web site by issuing an
  3730. /// HTTP GET request, or update them by using HTTP PUT with a request
  3731. /// body that contains the settings to be updated. (see
  3732. /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166985.aspx
  3733. /// for more information)
  3734. /// </summary>
  3735. /// <param name='resourceGroupName'>
  3736. /// Required. The name of the resource group.
  3737. /// </param>
  3738. /// <param name='webSiteName'>
  3739. /// Required. The name of the web site.
  3740. /// </param>
  3741. /// <param name='slotName'>
  3742. /// Optional. The name of the slot.
  3743. /// </param>
  3744. /// <param name='parameters'>
  3745. /// Optional. Additional parameters.
  3746. /// </param>
  3747. /// <param name='cancellationToken'>
  3748. /// Cancellation token.
  3749. /// </param>
  3750. /// <returns>
  3751. /// Config for the website.
  3752. /// </returns>
  3753. public async Task<WebSiteGetConfigurationResult> GetConfigurationAsync(string resourceGroupName, string webSiteName, string slotName, WebSiteGetConfigurationParameters parameters, CancellationToken cancellationToken)
  3754. {
  3755. // Validate
  3756. if (resourceGroupName == null)
  3757. {
  3758. throw new ArgumentNullException("resourceGroupName");
  3759. }
  3760. if (webSiteName == null)
  3761. {
  3762. throw new ArgumentNullException("webSiteName");
  3763. }
  3764. // Tracing
  3765. bool shouldTrace = TracingAdapter.IsEnabled;
  3766. string invocationId = null;
  3767. if (shouldTrace)
  3768. {
  3769. invocationId = TracingAdapter.NextInvocationId.ToString();
  3770. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  3771. tracingParameters.Add("resourceGroupName", resourceGroupName);
  3772. tracingParameters.Add("webSiteName", webSiteName);
  3773. tracingParameters.Add("slotName", slotName);
  3774. tracingParameters.Add("parameters", parameters);
  3775. TracingAdapter.Enter(invocationId, this, "GetConfigurationAsync", tracingParameters);
  3776. }
  3777. // Construct URL
  3778. string url = "";
  3779. url = url + "/subscriptions/";
  3780. if (this.Client.Credentials.SubscriptionId != null)
  3781. {
  3782. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  3783. }
  3784. url = url + "/resourceGroups/";
  3785. url = url + Uri.EscapeDataString(resourceGroupName);
  3786. url = url + "/providers/";
  3787. url = url + "Microsoft.Web";
  3788. url = url + "/";
  3789. url = url + "sites";
  3790. url = url + "/";
  3791. url = url + Uri.EscapeDataString(webSiteName);
  3792. if (slotName != null)
  3793. {
  3794. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  3795. }
  3796. url = url + "/config/web";
  3797. List<string> queryParameters = new List<string>();
  3798. queryParameters.Add("api-version=2014-06-01");
  3799. if (parameters != null && parameters.PropertiesToInclude != null && parameters.PropertiesToInclude.Count > 0)
  3800. {
  3801. queryParameters.Add("propertiesToInclude=" + Uri.EscapeDataString(string.Join(",", parameters.PropertiesToInclude)));
  3802. }
  3803. if (queryParameters.Count > 0)
  3804. {
  3805. url = url + "?" + string.Join("&", queryParameters);
  3806. }
  3807. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  3808. // Trim '/' character from the end of baseUrl and beginning of url.
  3809. if (baseUrl[baseUrl.Length - 1] == '/')
  3810. {
  3811. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  3812. }
  3813. if (url[0] == '/')
  3814. {
  3815. url = url.Substring(1);
  3816. }
  3817. url = baseUrl + "/" + url;
  3818. url = url.Replace(" ", "%20");
  3819. // Create HTTP transport objects
  3820. HttpRequestMessage httpRequest = null;
  3821. try
  3822. {
  3823. httpRequest = new HttpRequestMessage();
  3824. httpRequest.Method = HttpMethod.Get;
  3825. httpRequest.RequestUri = new Uri(url);
  3826. // Set Headers
  3827. // Set Credentials
  3828. cancellationToken.ThrowIfCancellationRequested();
  3829. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  3830. // Send Request
  3831. HttpResponseMessage httpResponse = null;
  3832. try
  3833. {
  3834. if (shouldTrace)
  3835. {
  3836. TracingAdapter.SendRequest(invocationId, httpRequest);
  3837. }
  3838. cancellationToken.ThrowIfCancellationRequested();
  3839. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  3840. if (shouldTrace)
  3841. {
  3842. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  3843. }
  3844. HttpStatusCode statusCode = httpResponse.StatusCode;
  3845. if (statusCode != HttpStatusCode.OK)
  3846. {
  3847. cancellationToken.ThrowIfCancellationRequested();
  3848. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  3849. if (shouldTrace)
  3850. {
  3851. TracingAdapter.Error(invocationId, ex);
  3852. }
  3853. throw ex;
  3854. }
  3855. // Create Result
  3856. WebSiteGetConfigurationResult result = null;
  3857. // Deserialize Response
  3858. if (statusCode == HttpStatusCode.OK)
  3859. {
  3860. cancellationToken.ThrowIfCancellationRequested();
  3861. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  3862. result = new WebSiteGetConfigurationResult();
  3863. JToken responseDoc = null;
  3864. if (string.IsNullOrEmpty(responseContent) == false)
  3865. {
  3866. responseDoc = JToken.Parse(responseContent);
  3867. }
  3868. if (responseDoc != null && responseDoc.Type != JTokenType.Null)
  3869. {
  3870. WebSiteConfigurationEnvelope resourceInstance = new WebSiteConfigurationEnvelope();
  3871. result.Resource = resourceInstance;
  3872. JToken propertiesValue = responseDoc["properties"];
  3873. if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
  3874. {
  3875. WebSiteConfiguration propertiesInstance = new WebSiteConfiguration();
  3876. resourceInstance.Properties = propertiesInstance;
  3877. JToken appSettingsSequenceElement = ((JToken)propertiesValue["appSettings"]);
  3878. if (appSettingsSequenceElement != null && appSettingsSequenceElement.Type != JTokenType.Null)
  3879. {
  3880. foreach (JProperty property in appSettingsSequenceElement)
  3881. {
  3882. string appSettingsKey = ((string)property.Name);
  3883. string appSettingsValue = ((string)property.Value);
  3884. propertiesInstance.AppSettings.Add(appSettingsKey, appSettingsValue);
  3885. }
  3886. }
  3887. JToken connectionStringsArray = propertiesValue["connectionStrings"];
  3888. if (connectionStringsArray != null && connectionStringsArray.Type != JTokenType.Null)
  3889. {
  3890. foreach (JToken connectionStringsValue in ((JArray)connectionStringsArray))
  3891. {
  3892. ConnectionStringInfo connStringInfoInstance = new ConnectionStringInfo();
  3893. propertiesInstance.ConnectionStrings.Add(connStringInfoInstance);
  3894. JToken connectionStringValue = connectionStringsValue["connectionString"];
  3895. if (connectionStringValue != null && connectionStringValue.Type != JTokenType.Null)
  3896. {
  3897. string connectionStringInstance = ((string)connectionStringValue);
  3898. connStringInfoInstance.ConnectionString = connectionStringInstance;
  3899. }
  3900. JToken nameValue = connectionStringsValue["name"];
  3901. if (nameValue != null && nameValue.Type != JTokenType.Null)
  3902. {
  3903. string nameInstance = ((string)nameValue);
  3904. connStringInfoInstance.Name = nameInstance;
  3905. }
  3906. JToken typeValue = connectionStringsValue["type"];
  3907. if (typeValue != null && typeValue.Type != JTokenType.Null)
  3908. {
  3909. DatabaseServerType typeInstance = ((DatabaseServerType)Enum.Parse(typeof(DatabaseServerType), ((string)typeValue), true));
  3910. connStringInfoInstance.Type = typeInstance;
  3911. }
  3912. }
  3913. }
  3914. JToken defaultDocumentsArray = propertiesValue["defaultDocuments"];
  3915. if (defaultDocumentsArray != null && defaultDocumentsArray.Type != JTokenType.Null)
  3916. {
  3917. foreach (JToken defaultDocumentsValue in ((JArray)defaultDocumentsArray))
  3918. {
  3919. propertiesInstance.DefaultDocuments.Add(((string)defaultDocumentsValue));
  3920. }
  3921. }
  3922. JToken detailedErrorLoggingEnabledValue = propertiesValue["detailedErrorLoggingEnabled"];
  3923. if (detailedErrorLoggingEnabledValue != null && detailedErrorLoggingEnabledValue.Type != JTokenType.Null)
  3924. {
  3925. bool detailedErrorLoggingEnabledInstance = ((bool)detailedErrorLoggingEnabledValue);
  3926. propertiesInstance.DetailedErrorLoggingEnabled = detailedErrorLoggingEnabledInstance;
  3927. }
  3928. JToken documentRootValue = propertiesValue["documentRoot"];
  3929. if (documentRootValue != null && documentRootValue.Type != JTokenType.Null)
  3930. {
  3931. string documentRootInstance = ((string)documentRootValue);
  3932. propertiesInstance.DocumentRoot = documentRootInstance;
  3933. }
  3934. JToken handlerMappingsArray = propertiesValue["handlerMappings"];
  3935. if (handlerMappingsArray != null && handlerMappingsArray.Type != JTokenType.Null)
  3936. {
  3937. foreach (JToken handlerMappingsValue in ((JArray)handlerMappingsArray))
  3938. {
  3939. WebSiteConfiguration.HandlerMapping handlerMappingInstance = new WebSiteConfiguration.HandlerMapping();
  3940. propertiesInstance.HandlerMappings.Add(handlerMappingInstance);
  3941. JToken argumentsValue = handlerMappingsValue["arguments"];
  3942. if (argumentsValue != null && argumentsValue.Type != JTokenType.Null)
  3943. {
  3944. string argumentsInstance = ((string)argumentsValue);
  3945. handlerMappingInstance.Arguments = argumentsInstance;
  3946. }
  3947. JToken extensionValue = handlerMappingsValue["extension"];
  3948. if (extensionValue != null && extensionValue.Type != JTokenType.Null)
  3949. {
  3950. string extensionInstance = ((string)extensionValue);
  3951. handlerMappingInstance.Extension = extensionInstance;
  3952. }
  3953. JToken scriptProcessorValue = handlerMappingsValue["scriptProcessor"];
  3954. if (scriptProcessorValue != null && scriptProcessorValue.Type != JTokenType.Null)
  3955. {
  3956. string scriptProcessorInstance = ((string)scriptProcessorValue);
  3957. handlerMappingInstance.ScriptProcessor = scriptProcessorInstance;
  3958. }
  3959. }
  3960. }
  3961. JToken httpLoggingEnabledValue = propertiesValue["httpLoggingEnabled"];
  3962. if (httpLoggingEnabledValue != null && httpLoggingEnabledValue.Type != JTokenType.Null)
  3963. {
  3964. bool httpLoggingEnabledInstance = ((bool)httpLoggingEnabledValue);
  3965. propertiesInstance.HttpLoggingEnabled = httpLoggingEnabledInstance;
  3966. }
  3967. JToken logsDirectorySizeLimitValue = propertiesValue["logsDirectorySizeLimit"];
  3968. if (logsDirectorySizeLimitValue != null && logsDirectorySizeLimitValue.Type != JTokenType.Null)
  3969. {
  3970. int logsDirectorySizeLimitInstance = ((int)logsDirectorySizeLimitValue);
  3971. propertiesInstance.LogsDirectorySizeLimit = logsDirectorySizeLimitInstance;
  3972. }
  3973. JToken managedPipelineModeValue = propertiesValue["managedPipelineMode"];
  3974. if (managedPipelineModeValue != null && managedPipelineModeValue.Type != JTokenType.Null)
  3975. {
  3976. ManagedPipelineMode managedPipelineModeInstance = ((ManagedPipelineMode)Enum.Parse(typeof(ManagedPipelineMode), ((string)managedPipelineModeValue), true));
  3977. propertiesInstance.ManagedPipelineMode = managedPipelineModeInstance;
  3978. }
  3979. JToken metadataSequenceElement = ((JToken)propertiesValue["metadata"]);
  3980. if (metadataSequenceElement != null && metadataSequenceElement.Type != JTokenType.Null)
  3981. {
  3982. foreach (JProperty property2 in metadataSequenceElement)
  3983. {
  3984. string metadataKey = ((string)property2.Name);
  3985. string metadataValue = ((string)property2.Value);
  3986. propertiesInstance.Metadata.Add(metadataKey, metadataValue);
  3987. }
  3988. }
  3989. JToken netFrameworkVersionValue = propertiesValue["netFrameworkVersion"];
  3990. if (netFrameworkVersionValue != null && netFrameworkVersionValue.Type != JTokenType.Null)
  3991. {
  3992. string netFrameworkVersionInstance = ((string)netFrameworkVersionValue);
  3993. propertiesInstance.NetFrameworkVersion = netFrameworkVersionInstance;
  3994. }
  3995. JToken numberOfWorkersValue = propertiesValue["numberOfWorkers"];
  3996. if (numberOfWorkersValue != null && numberOfWorkersValue.Type != JTokenType.Null)
  3997. {
  3998. int numberOfWorkersInstance = ((int)numberOfWorkersValue);
  3999. propertiesInstance.NumberOfWorkers = numberOfWorkersInstance;
  4000. }
  4001. JToken phpVersionValue = propertiesValue["phpVersion"];
  4002. if (phpVersionValue != null && phpVersionValue.Type != JTokenType.Null)
  4003. {
  4004. string phpVersionInstance = ((string)phpVersionValue);
  4005. propertiesInstance.PhpVersion = phpVersionInstance;
  4006. }
  4007. JToken pythonVersionValue = propertiesValue["pythonVersion"];
  4008. if (pythonVersionValue != null && pythonVersionValue.Type != JTokenType.Null)
  4009. {
  4010. string pythonVersionInstance = ((string)pythonVersionValue);
  4011. propertiesInstance.PythonVersion = pythonVersionInstance;
  4012. }
  4013. JToken publishingPasswordValue = propertiesValue["publishingPassword"];
  4014. if (publishingPasswordValue != null && publishingPasswordValue.Type != JTokenType.Null)
  4015. {
  4016. string publishingPasswordInstance = ((string)publishingPasswordValue);
  4017. propertiesInstance.PublishingPassword = publishingPasswordInstance;
  4018. }
  4019. JToken publishingUsernameValue = propertiesValue["publishingUsername"];
  4020. if (publishingUsernameValue != null && publishingUsernameValue.Type != JTokenType.Null)
  4021. {
  4022. string publishingUsernameInstance = ((string)publishingUsernameValue);
  4023. propertiesInstance.PublishingUserName = publishingUsernameInstance;
  4024. }
  4025. JToken remoteDebuggingEnabledValue = propertiesValue["RemoteDebuggingEnabled"];
  4026. if (remoteDebuggingEnabledValue != null && remoteDebuggingEnabledValue.Type != JTokenType.Null)
  4027. {
  4028. bool remoteDebuggingEnabledInstance = ((bool)remoteDebuggingEnabledValue);
  4029. propertiesInstance.RemoteDebuggingEnabled = remoteDebuggingEnabledInstance;
  4030. }
  4031. JToken remoteDebuggingVersionValue = propertiesValue["remoteDebuggingVersion"];
  4032. if (remoteDebuggingVersionValue != null && remoteDebuggingVersionValue.Type != JTokenType.Null)
  4033. {
  4034. RemoteDebuggingVersion remoteDebuggingVersionInstance = ((RemoteDebuggingVersion)Enum.Parse(typeof(RemoteDebuggingVersion), ((string)remoteDebuggingVersionValue), true));
  4035. propertiesInstance.RemoteDebuggingVersion = remoteDebuggingVersionInstance;
  4036. }
  4037. JToken requestTracingEnabledValue = propertiesValue["requestTracingEnabled"];
  4038. if (requestTracingEnabledValue != null && requestTracingEnabledValue.Type != JTokenType.Null)
  4039. {
  4040. bool requestTracingEnabledInstance = ((bool)requestTracingEnabledValue);
  4041. propertiesInstance.RequestTracingEnabled = requestTracingEnabledInstance;
  4042. }
  4043. JToken requestTracingExpirationTimeValue = propertiesValue["requestTracingExpirationTime"];
  4044. if (requestTracingExpirationTimeValue != null && requestTracingExpirationTimeValue.Type != JTokenType.Null)
  4045. {
  4046. DateTime requestTracingExpirationTimeInstance = ((DateTime)requestTracingExpirationTimeValue);
  4047. propertiesInstance.RequestTracingExpirationTime = requestTracingExpirationTimeInstance;
  4048. }
  4049. JToken scmTypeValue = propertiesValue["scmType"];
  4050. if (scmTypeValue != null && scmTypeValue.Type != JTokenType.Null)
  4051. {
  4052. string scmTypeInstance = ((string)scmTypeValue);
  4053. propertiesInstance.ScmType = scmTypeInstance;
  4054. }
  4055. JToken autoSwapSlotNameValue = propertiesValue["autoSwapSlotName"];
  4056. if (autoSwapSlotNameValue != null && autoSwapSlotNameValue.Type != JTokenType.Null)
  4057. {
  4058. string autoSwapSlotNameInstance = ((string)autoSwapSlotNameValue);
  4059. propertiesInstance.AutoSwapSlotName = autoSwapSlotNameInstance;
  4060. }
  4061. JToken use32BitWorkerProcessValue = propertiesValue["use32BitWorkerProcess"];
  4062. if (use32BitWorkerProcessValue != null && use32BitWorkerProcessValue.Type != JTokenType.Null)
  4063. {
  4064. bool use32BitWorkerProcessInstance = ((bool)use32BitWorkerProcessValue);
  4065. propertiesInstance.Use32BitWorkerProcess = use32BitWorkerProcessInstance;
  4066. }
  4067. JToken webSocketsEnabledValue = propertiesValue["webSocketsEnabled"];
  4068. if (webSocketsEnabledValue != null && webSocketsEnabledValue.Type != JTokenType.Null)
  4069. {
  4070. bool webSocketsEnabledInstance = ((bool)webSocketsEnabledValue);
  4071. propertiesInstance.WebSocketsEnabled = webSocketsEnabledInstance;
  4072. }
  4073. JToken limitsValue = propertiesValue["limits"];
  4074. if (limitsValue != null && limitsValue.Type != JTokenType.Null)
  4075. {
  4076. SiteLimits limitsInstance = new SiteLimits();
  4077. propertiesInstance.Limits = limitsInstance;
  4078. JToken maxPercentageCpuValue = limitsValue["maxPercentageCpu"];
  4079. if (maxPercentageCpuValue != null && maxPercentageCpuValue.Type != JTokenType.Null)
  4080. {
  4081. double maxPercentageCpuInstance = ((double)maxPercentageCpuValue);
  4082. limitsInstance.MaxPercentageCpu = maxPercentageCpuInstance;
  4083. }
  4084. JToken maxMemoryInMbValue = limitsValue["maxMemoryInMb"];
  4085. if (maxMemoryInMbValue != null && maxMemoryInMbValue.Type != JTokenType.Null)
  4086. {
  4087. long maxMemoryInMbInstance = ((long)maxMemoryInMbValue);
  4088. limitsInstance.MaxMemoryInMb = maxMemoryInMbInstance;
  4089. }
  4090. JToken maxDiskSizeInMbValue = limitsValue["maxDiskSizeInMb"];
  4091. if (maxDiskSizeInMbValue != null && maxDiskSizeInMbValue.Type != JTokenType.Null)
  4092. {
  4093. long maxDiskSizeInMbInstance = ((long)maxDiskSizeInMbValue);
  4094. limitsInstance.MaxDiskSizeInMb = maxDiskSizeInMbInstance;
  4095. }
  4096. }
  4097. }
  4098. JToken idValue = responseDoc["id"];
  4099. if (idValue != null && idValue.Type != JTokenType.Null)
  4100. {
  4101. string idInstance = ((string)idValue);
  4102. resourceInstance.Id = idInstance;
  4103. }
  4104. JToken nameValue2 = responseDoc["name"];
  4105. if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
  4106. {
  4107. string nameInstance2 = ((string)nameValue2);
  4108. resourceInstance.Name = nameInstance2;
  4109. }
  4110. JToken locationValue = responseDoc["location"];
  4111. if (locationValue != null && locationValue.Type != JTokenType.Null)
  4112. {
  4113. string locationInstance = ((string)locationValue);
  4114. resourceInstance.Location = locationInstance;
  4115. }
  4116. JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
  4117. if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
  4118. {
  4119. foreach (JProperty property3 in tagsSequenceElement)
  4120. {
  4121. string tagsKey = ((string)property3.Name);
  4122. string tagsValue = ((string)property3.Value);
  4123. resourceInstance.Tags.Add(tagsKey, tagsValue);
  4124. }
  4125. }
  4126. JToken typeValue2 = responseDoc["type"];
  4127. if (typeValue2 != null && typeValue2.Type != JTokenType.Null)
  4128. {
  4129. string typeInstance2 = ((string)typeValue2);
  4130. resourceInstance.Type = typeInstance2;
  4131. }
  4132. }
  4133. }
  4134. result.StatusCode = statusCode;
  4135. if (httpResponse.Headers.Contains("x-ms-request-id"))
  4136. {
  4137. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  4138. }
  4139. if (shouldTrace)
  4140. {
  4141. TracingAdapter.Exit(invocationId, result);
  4142. }
  4143. return result;
  4144. }
  4145. finally
  4146. {
  4147. if (httpResponse != null)
  4148. {
  4149. httpResponse.Dispose();
  4150. }
  4151. }
  4152. }
  4153. finally
  4154. {
  4155. if (httpRequest != null)
  4156. {
  4157. httpRequest.Dispose();
  4158. }
  4159. }
  4160. }
  4161. /// <summary>
  4162. /// Restart the web site.
  4163. /// </summary>
  4164. /// <param name='resourceGroupName'>
  4165. /// Required. The name of the resource group
  4166. /// </param>
  4167. /// <param name='webSiteName'>
  4168. /// Required. Name of website
  4169. /// </param>
  4170. /// <param name='slotName'>
  4171. /// Optional. The name of the slot of the web site
  4172. /// </param>
  4173. /// <param name='cancellationToken'>
  4174. /// Cancellation token.
  4175. /// </param>
  4176. /// <returns>
  4177. /// List of connection strings for the website.
  4178. /// </returns>
  4179. public async Task<WebSiteConnectionStringsResult> GetConnectionStringsAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
  4180. {
  4181. // Validate
  4182. if (resourceGroupName == null)
  4183. {
  4184. throw new ArgumentNullException("resourceGroupName");
  4185. }
  4186. if (webSiteName == null)
  4187. {
  4188. throw new ArgumentNullException("webSiteName");
  4189. }
  4190. // Tracing
  4191. bool shouldTrace = TracingAdapter.IsEnabled;
  4192. string invocationId = null;
  4193. if (shouldTrace)
  4194. {
  4195. invocationId = TracingAdapter.NextInvocationId.ToString();
  4196. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  4197. tracingParameters.Add("resourceGroupName", resourceGroupName);
  4198. tracingParameters.Add("webSiteName", webSiteName);
  4199. tracingParameters.Add("slotName", slotName);
  4200. TracingAdapter.Enter(invocationId, this, "GetConnectionStringsAsync", tracingParameters);
  4201. }
  4202. // Construct URL
  4203. string url = "";
  4204. url = url + "/subscriptions/";
  4205. if (this.Client.Credentials.SubscriptionId != null)
  4206. {
  4207. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  4208. }
  4209. url = url + "/resourceGroups/";
  4210. url = url + Uri.EscapeDataString(resourceGroupName);
  4211. url = url + "/providers/";
  4212. url = url + "Microsoft.Web";
  4213. url = url + "/";
  4214. url = url + "sites";
  4215. url = url + "/";
  4216. url = url + Uri.EscapeDataString(webSiteName);
  4217. if (slotName != null)
  4218. {
  4219. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  4220. }
  4221. url = url + "/config/connectionstrings/list";
  4222. List<string> queryParameters = new List<string>();
  4223. queryParameters.Add("api-version=2014-06-01");
  4224. if (queryParameters.Count > 0)
  4225. {
  4226. url = url + "?" + string.Join("&", queryParameters);
  4227. }
  4228. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  4229. // Trim '/' character from the end of baseUrl and beginning of url.
  4230. if (baseUrl[baseUrl.Length - 1] == '/')
  4231. {
  4232. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  4233. }
  4234. if (url[0] == '/')
  4235. {
  4236. url = url.Substring(1);
  4237. }
  4238. url = baseUrl + "/" + url;
  4239. url = url.Replace(" ", "%20");
  4240. // Create HTTP transport objects
  4241. HttpRequestMessage httpRequest = null;
  4242. try
  4243. {
  4244. httpRequest = new HttpRequestMessage();
  4245. httpRequest.Method = HttpMethod.Post;
  4246. httpRequest.RequestUri = new Uri(url);
  4247. // Set Headers
  4248. // Set Credentials
  4249. cancellationToken.ThrowIfCancellationRequested();
  4250. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  4251. // Send Request
  4252. HttpResponseMessage httpResponse = null;
  4253. try
  4254. {
  4255. if (shouldTrace)
  4256. {
  4257. TracingAdapter.SendRequest(invocationId, httpRequest);
  4258. }
  4259. cancellationToken.ThrowIfCancellationRequested();
  4260. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  4261. if (shouldTrace)
  4262. {
  4263. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  4264. }
  4265. HttpStatusCode statusCode = httpResponse.StatusCode;
  4266. if (statusCode != HttpStatusCode.OK)
  4267. {
  4268. cancellationToken.ThrowIfCancellationRequested();
  4269. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  4270. if (shouldTrace)
  4271. {
  4272. TracingAdapter.Error(invocationId, ex);
  4273. }
  4274. throw ex;
  4275. }
  4276. // Create Result
  4277. WebSiteConnectionStringsResult result = null;
  4278. // Deserialize Response
  4279. if (statusCode == HttpStatusCode.OK)
  4280. {
  4281. cancellationToken.ThrowIfCancellationRequested();
  4282. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  4283. result = new WebSiteConnectionStringsResult();
  4284. JToken responseDoc = null;
  4285. if (string.IsNullOrEmpty(responseContent) == false)
  4286. {
  4287. responseDoc = JToken.Parse(responseContent);
  4288. }
  4289. if (responseDoc != null && responseDoc.Type != JTokenType.Null)
  4290. {
  4291. WebSiteConnectionStringsEnvelope resourceInstance = new WebSiteConnectionStringsEnvelope();
  4292. result.Resource = resourceInstance;
  4293. JToken propertiesArray = responseDoc["properties"];
  4294. if (propertiesArray != null && propertiesArray.Type != JTokenType.Null)
  4295. {
  4296. foreach (JToken propertiesValue in ((JArray)propertiesArray))
  4297. {
  4298. ConnectionStringInfo connStringInfoInstance = new ConnectionStringInfo();
  4299. resourceInstance.Properties.Add(connStringInfoInstance);
  4300. JToken connectionStringValue = propertiesValue["connectionString"];
  4301. if (connectionStringValue != null && connectionStringValue.Type != JTokenType.Null)
  4302. {
  4303. string connectionStringInstance = ((string)connectionStringValue);
  4304. connStringInfoInstance.ConnectionString = connectionStringInstance;
  4305. }
  4306. JToken nameValue = propertiesValue["name"];
  4307. if (nameValue != null && nameValue.Type != JTokenType.Null)
  4308. {
  4309. string nameInstance = ((string)nameValue);
  4310. connStringInfoInstance.Name = nameInstance;
  4311. }
  4312. JToken typeValue = propertiesValue["type"];
  4313. if (typeValue != null && typeValue.Type != JTokenType.Null)
  4314. {
  4315. DatabaseServerType typeInstance = ((DatabaseServerType)Enum.Parse(typeof(DatabaseServerType), ((string)typeValue), true));
  4316. connStringInfoInstance.Type = typeInstance;
  4317. }
  4318. }
  4319. }
  4320. JToken idValue = responseDoc["id"];
  4321. if (idValue != null && idValue.Type != JTokenType.Null)
  4322. {
  4323. string idInstance = ((string)idValue);
  4324. resourceInstance.Id = idInstance;
  4325. }
  4326. JToken nameValue2 = responseDoc["name"];
  4327. if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
  4328. {
  4329. string nameInstance2 = ((string)nameValue2);
  4330. resourceInstance.Name = nameInstance2;
  4331. }
  4332. JToken locationValue = responseDoc["location"];
  4333. if (locationValue != null && locationValue.Type != JTokenType.Null)
  4334. {
  4335. string locationInstance = ((string)locationValue);
  4336. resourceInstance.Location = locationInstance;
  4337. }
  4338. JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
  4339. if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
  4340. {
  4341. foreach (JProperty property in tagsSequenceElement)
  4342. {
  4343. string tagsKey = ((string)property.Name);
  4344. string tagsValue = ((string)property.Value);
  4345. resourceInstance.Tags.Add(tagsKey, tagsValue);
  4346. }
  4347. }
  4348. JToken typeValue2 = responseDoc["type"];
  4349. if (typeValue2 != null && typeValue2.Type != JTokenType.Null)
  4350. {
  4351. string typeInstance2 = ((string)typeValue2);
  4352. resourceInstance.Type = typeInstance2;
  4353. }
  4354. }
  4355. }
  4356. result.StatusCode = statusCode;
  4357. if (httpResponse.Headers.Contains("x-ms-request-id"))
  4358. {
  4359. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  4360. }
  4361. if (shouldTrace)
  4362. {
  4363. TracingAdapter.Exit(invocationId, result);
  4364. }
  4365. return result;
  4366. }
  4367. finally
  4368. {
  4369. if (httpResponse != null)
  4370. {
  4371. httpResponse.Dispose();
  4372. }
  4373. }
  4374. }
  4375. finally
  4376. {
  4377. if (httpRequest != null)
  4378. {
  4379. httpRequest.Dispose();
  4380. }
  4381. }
  4382. }
  4383. /// <summary>
  4384. /// You can retrieve historical usage metrics for a site by issuing an
  4385. /// HTTP GET request. (see
  4386. /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166964.aspx
  4387. /// for more information)
  4388. /// </summary>
  4389. /// <param name='resourceGroupName'>
  4390. /// Required. The name of the resource group.
  4391. /// </param>
  4392. /// <param name='webSiteName'>
  4393. /// Required. The name of the web site.
  4394. /// </param>
  4395. /// <param name='slotName'>
  4396. /// Optional. The name of the slot.
  4397. /// </param>
  4398. /// <param name='parameters'>
  4399. /// Required. The Get Web Site Historical Usage Metrics parameters.
  4400. /// </param>
  4401. /// <param name='cancellationToken'>
  4402. /// Cancellation token.
  4403. /// </param>
  4404. /// <returns>
  4405. /// The Get Web Site Historical Usage Metrics operation response.
  4406. /// </returns>
  4407. public async Task<WebSiteGetHistoricalUsageMetricsResponse> GetHistoricalUsageMetricsAsync(string resourceGroupName, string webSiteName, string slotName, WebSiteGetHistoricalUsageMetricsParameters parameters, CancellationToken cancellationToken)
  4408. {
  4409. // Validate
  4410. if (resourceGroupName == null)
  4411. {
  4412. throw new ArgumentNullException("resourceGroupName");
  4413. }
  4414. if (webSiteName == null)
  4415. {
  4416. throw new ArgumentNullException("webSiteName");
  4417. }
  4418. if (parameters == null)
  4419. {
  4420. throw new ArgumentNullException("parameters");
  4421. }
  4422. // Tracing
  4423. bool shouldTrace = TracingAdapter.IsEnabled;
  4424. string invocationId = null;
  4425. if (shouldTrace)
  4426. {
  4427. invocationId = TracingAdapter.NextInvocationId.ToString();
  4428. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  4429. tracingParameters.Add("resourceGroupName", resourceGroupName);
  4430. tracingParameters.Add("webSiteName", webSiteName);
  4431. tracingParameters.Add("slotName", slotName);
  4432. tracingParameters.Add("parameters", parameters);
  4433. TracingAdapter.Enter(invocationId, this, "GetHistoricalUsageMetricsAsync", tracingParameters);
  4434. }
  4435. // Construct URL
  4436. string url = "";
  4437. url = url + "/subscriptions/";
  4438. if (this.Client.Credentials.SubscriptionId != null)
  4439. {
  4440. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  4441. }
  4442. url = url + "/resourceGroups/";
  4443. url = url + Uri.EscapeDataString(resourceGroupName);
  4444. url = url + "/providers/";
  4445. url = url + "Microsoft.Web";
  4446. url = url + "/";
  4447. url = url + "sites";
  4448. url = url + "/";
  4449. url = url + Uri.EscapeDataString(webSiteName);
  4450. if (slotName != null)
  4451. {
  4452. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  4453. }
  4454. url = url + "/metrics";
  4455. List<string> queryParameters = new List<string>();
  4456. queryParameters.Add("api-version=2014-06-01");
  4457. if (parameters.MetricNames != null && parameters.MetricNames.Count > 0)
  4458. {
  4459. queryParameters.Add("names=" + Uri.EscapeDataString(string.Join(",", parameters.MetricNames)));
  4460. }
  4461. if (parameters.StartTime != null)
  4462. {
  4463. queryParameters.Add("StartTime=" + Uri.EscapeDataString(string.Format(CultureInfo.InvariantCulture, "{0:O}", parameters.StartTime.Value.ToUniversalTime())));
  4464. }
  4465. if (parameters.EndTime != null)
  4466. {
  4467. queryParameters.Add("EndTime=" + Uri.EscapeDataString(string.Format(CultureInfo.InvariantCulture, "{0:O}", parameters.EndTime.Value.ToUniversalTime())));
  4468. }
  4469. if (parameters.TimeGrain != null)
  4470. {
  4471. queryParameters.Add("timeGrain=" + Uri.EscapeDataString(parameters.TimeGrain));
  4472. }
  4473. queryParameters.Add("details=" + Uri.EscapeDataString(parameters.IncludeInstanceBreakdown.ToString().ToLower()));
  4474. queryParameters.Add("slotView=" + Uri.EscapeDataString(parameters.SlotView.ToString().ToLower()));
  4475. if (queryParameters.Count > 0)
  4476. {
  4477. url = url + "?" + string.Join("&", queryParameters);
  4478. }
  4479. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  4480. // Trim '/' character from the end of baseUrl and beginning of url.
  4481. if (baseUrl[baseUrl.Length - 1] == '/')
  4482. {
  4483. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  4484. }
  4485. if (url[0] == '/')
  4486. {
  4487. url = url.Substring(1);
  4488. }
  4489. url = baseUrl + "/" + url;
  4490. url = url.Replace(" ", "%20");
  4491. // Create HTTP transport objects
  4492. HttpRequestMessage httpRequest = null;
  4493. try
  4494. {
  4495. httpRequest = new HttpRequestMessage();
  4496. httpRequest.Method = HttpMethod.Get;
  4497. httpRequest.RequestUri = new Uri(url);
  4498. // Set Headers
  4499. // Set Credentials
  4500. cancellationToken.ThrowIfCancellationRequested();
  4501. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  4502. // Send Request
  4503. HttpResponseMessage httpResponse = null;
  4504. try
  4505. {
  4506. if (shouldTrace)
  4507. {
  4508. TracingAdapter.SendRequest(invocationId, httpRequest);
  4509. }
  4510. cancellationToken.ThrowIfCancellationRequested();
  4511. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  4512. if (shouldTrace)
  4513. {
  4514. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  4515. }
  4516. HttpStatusCode statusCode = httpResponse.StatusCode;
  4517. if (statusCode != HttpStatusCode.OK)
  4518. {
  4519. cancellationToken.ThrowIfCancellationRequested();
  4520. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  4521. if (shouldTrace)
  4522. {
  4523. TracingAdapter.Error(invocationId, ex);
  4524. }
  4525. throw ex;
  4526. }
  4527. // Create Result
  4528. WebSiteGetHistoricalUsageMetricsResponse result = null;
  4529. // Deserialize Response
  4530. if (statusCode == HttpStatusCode.OK)
  4531. {
  4532. cancellationToken.ThrowIfCancellationRequested();
  4533. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  4534. result = new WebSiteGetHistoricalUsageMetricsResponse();
  4535. JToken responseDoc = null;
  4536. if (string.IsNullOrEmpty(responseContent) == false)
  4537. {
  4538. responseDoc = JToken.Parse(responseContent);
  4539. }
  4540. if (responseDoc != null && responseDoc.Type != JTokenType.Null)
  4541. {
  4542. JToken propertiesArray = responseDoc["properties"];
  4543. if (propertiesArray != null && propertiesArray.Type != JTokenType.Null)
  4544. {
  4545. foreach (JToken propertiesValue in ((JArray)propertiesArray))
  4546. {
  4547. HistoricalUsageMetric historicalUsageMetricInstance = new HistoricalUsageMetric();
  4548. result.UsageMetrics.Add(historicalUsageMetricInstance);
  4549. JToken codeValue = propertiesValue["code"];
  4550. if (codeValue != null && codeValue.Type != JTokenType.Null)
  4551. {
  4552. string codeInstance = ((string)codeValue);
  4553. historicalUsageMetricInstance.Code = codeInstance;
  4554. }
  4555. JToken dataValue = propertiesValue["data"];
  4556. if (dataValue != null && dataValue.Type != JTokenType.Null)
  4557. {
  4558. HistoricalUsageMetricData dataInstance = new HistoricalUsageMetricData();
  4559. historicalUsageMetricInstance.Data = dataInstance;
  4560. JToken displayNameValue = dataValue["displayName"];
  4561. if (displayNameValue != null && displayNameValue.Type != JTokenType.Null)
  4562. {
  4563. string displayNameInstance = ((string)displayNameValue);
  4564. dataInstance.DisplayName = displayNameInstance;
  4565. }
  4566. JToken endTimeValue = dataValue["EndTime"];
  4567. if (endTimeValue != null && endTimeValue.Type != JTokenType.Null)
  4568. {
  4569. DateTime endTimeInstance = ((DateTime)endTimeValue);
  4570. dataInstance.EndTime = endTimeInstance;
  4571. }
  4572. JToken nameValue = dataValue["name"];
  4573. if (nameValue != null && nameValue.Type != JTokenType.Null)
  4574. {
  4575. string nameInstance = ((string)nameValue);
  4576. dataInstance.Name = nameInstance;
  4577. }
  4578. JToken primaryAggregationTypeValue = dataValue["primaryAggregationType"];
  4579. if (primaryAggregationTypeValue != null && primaryAggregationTypeValue.Type != JTokenType.Null)
  4580. {
  4581. string primaryAggregationTypeInstance = ((string)primaryAggregationTypeValue);
  4582. dataInstance.PrimaryAggregationType = primaryAggregationTypeInstance;
  4583. }
  4584. JToken startTimeValue = dataValue["startTime"];
  4585. if (startTimeValue != null && startTimeValue.Type != JTokenType.Null)
  4586. {
  4587. DateTime startTimeInstance = ((DateTime)startTimeValue);
  4588. dataInstance.StartTime = startTimeInstance;
  4589. }
  4590. JToken timeGrainValue = dataValue["timeGrain"];
  4591. if (timeGrainValue != null && timeGrainValue.Type != JTokenType.Null)
  4592. {
  4593. string timeGrainInstance = ((string)timeGrainValue);
  4594. dataInstance.TimeGrain = timeGrainInstance;
  4595. }
  4596. JToken unitValue = dataValue["unit"];
  4597. if (unitValue != null && unitValue.Type != JTokenType.Null)
  4598. {
  4599. string unitInstance = ((string)unitValue);
  4600. dataInstance.Unit = unitInstance;
  4601. }
  4602. JToken valuesArray = dataValue["values"];
  4603. if (valuesArray != null && valuesArray.Type != JTokenType.Null)
  4604. {
  4605. foreach (JToken valuesValue in ((JArray)valuesArray))
  4606. {
  4607. HistoricalUsageMetricSample metricSampleInstance = new HistoricalUsageMetricSample();
  4608. dataInstance.Values.Add(metricSampleInstance);
  4609. JToken countValue = valuesValue["count"];
  4610. if (countValue != null && countValue.Type != JTokenType.Null)
  4611. {
  4612. int countInstance = ((int)countValue);
  4613. metricSampleInstance.Count = countInstance;
  4614. }
  4615. JToken maximumValue = valuesValue["maximum"];
  4616. if (maximumValue != null && maximumValue.Type != JTokenType.Null)
  4617. {
  4618. string maximumInstance = ((string)maximumValue);
  4619. metricSampleInstance.Maximum = maximumInstance;
  4620. }
  4621. JToken minimumValue = valuesValue["minimum"];
  4622. if (minimumValue != null && minimumValue.Type != JTokenType.Null)
  4623. {
  4624. string minimumInstance = ((string)minimumValue);
  4625. metricSampleInstance.Minimum = minimumInstance;
  4626. }
  4627. JToken timeCreatedValue = valuesValue["timeCreated"];
  4628. if (timeCreatedValue != null && timeCreatedValue.Type != JTokenType.Null)
  4629. {
  4630. DateTime timeCreatedInstance = ((DateTime)timeCreatedValue);
  4631. metricSampleInstance.TimeCreated = timeCreatedInstance;
  4632. }
  4633. JToken totalValue = valuesValue["total"];
  4634. if (totalValue != null && totalValue.Type != JTokenType.Null)
  4635. {
  4636. string totalInstance = ((string)totalValue);
  4637. metricSampleInstance.Total = totalInstance;
  4638. }
  4639. JToken instanceNameValue = valuesValue["instanceName"];
  4640. if (instanceNameValue != null && instanceNameValue.Type != JTokenType.Null)
  4641. {
  4642. string instanceNameInstance = ((string)instanceNameValue);
  4643. metricSampleInstance.InstanceName = instanceNameInstance;
  4644. }
  4645. }
  4646. }
  4647. }
  4648. JToken messageValue = propertiesValue["message"];
  4649. if (messageValue != null && messageValue.Type != JTokenType.Null)
  4650. {
  4651. string messageInstance = ((string)messageValue);
  4652. historicalUsageMetricInstance.Message = messageInstance;
  4653. }
  4654. }
  4655. }
  4656. }
  4657. }
  4658. result.StatusCode = statusCode;
  4659. if (httpResponse.Headers.Contains("x-ms-request-id"))
  4660. {
  4661. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  4662. }
  4663. if (shouldTrace)
  4664. {
  4665. TracingAdapter.Exit(invocationId, result);
  4666. }
  4667. return result;
  4668. }
  4669. finally
  4670. {
  4671. if (httpResponse != null)
  4672. {
  4673. httpResponse.Dispose();
  4674. }
  4675. }
  4676. }
  4677. finally
  4678. {
  4679. if (httpRequest != null)
  4680. {
  4681. httpRequest.Dispose();
  4682. }
  4683. }
  4684. }
  4685. /// <summary>
  4686. /// Restart the web site.
  4687. /// </summary>
  4688. /// <param name='resourceGroupName'>
  4689. /// Required. The name of the resource group
  4690. /// </param>
  4691. /// <param name='webSiteName'>
  4692. /// Required. Name of website
  4693. /// </param>
  4694. /// <param name='slotName'>
  4695. /// Optional. The name of the slot of the web site
  4696. /// </param>
  4697. /// <param name='cancellationToken'>
  4698. /// Cancellation token.
  4699. /// </param>
  4700. /// <returns>
  4701. /// List of metadata for the website.
  4702. /// </returns>
  4703. public async Task<WebSiteMetadataResult> GetMetadataAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
  4704. {
  4705. // Validate
  4706. if (resourceGroupName == null)
  4707. {
  4708. throw new ArgumentNullException("resourceGroupName");
  4709. }
  4710. if (webSiteName == null)
  4711. {
  4712. throw new ArgumentNullException("webSiteName");
  4713. }
  4714. // Tracing
  4715. bool shouldTrace = TracingAdapter.IsEnabled;
  4716. string invocationId = null;
  4717. if (shouldTrace)
  4718. {
  4719. invocationId = TracingAdapter.NextInvocationId.ToString();
  4720. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  4721. tracingParameters.Add("resourceGroupName", resourceGroupName);
  4722. tracingParameters.Add("webSiteName", webSiteName);
  4723. tracingParameters.Add("slotName", slotName);
  4724. TracingAdapter.Enter(invocationId, this, "GetMetadataAsync", tracingParameters);
  4725. }
  4726. // Construct URL
  4727. string url = "";
  4728. url = url + "/subscriptions/";
  4729. if (this.Client.Credentials.SubscriptionId != null)
  4730. {
  4731. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  4732. }
  4733. url = url + "/resourceGroups/";
  4734. url = url + Uri.EscapeDataString(resourceGroupName);
  4735. url = url + "/providers/";
  4736. url = url + "Microsoft.Web";
  4737. url = url + "/";
  4738. url = url + "sites";
  4739. url = url + "/";
  4740. url = url + Uri.EscapeDataString(webSiteName);
  4741. if (slotName != null)
  4742. {
  4743. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  4744. }
  4745. url = url + "/config/metadata/list";
  4746. List<string> queryParameters = new List<string>();
  4747. queryParameters.Add("api-version=2014-06-01");
  4748. if (queryParameters.Count > 0)
  4749. {
  4750. url = url + "?" + string.Join("&", queryParameters);
  4751. }
  4752. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  4753. // Trim '/' character from the end of baseUrl and beginning of url.
  4754. if (baseUrl[baseUrl.Length - 1] == '/')
  4755. {
  4756. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  4757. }
  4758. if (url[0] == '/')
  4759. {
  4760. url = url.Substring(1);
  4761. }
  4762. url = baseUrl + "/" + url;
  4763. url = url.Replace(" ", "%20");
  4764. // Create HTTP transport objects
  4765. HttpRequestMessage httpRequest = null;
  4766. try
  4767. {
  4768. httpRequest = new HttpRequestMessage();
  4769. httpRequest.Method = HttpMethod.Post;
  4770. httpRequest.RequestUri = new Uri(url);
  4771. // Set Headers
  4772. // Set Credentials
  4773. cancellationToken.ThrowIfCancellationRequested();
  4774. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  4775. // Send Request
  4776. HttpResponseMessage httpResponse = null;
  4777. try
  4778. {
  4779. if (shouldTrace)
  4780. {
  4781. TracingAdapter.SendRequest(invocationId, httpRequest);
  4782. }
  4783. cancellationToken.ThrowIfCancellationRequested();
  4784. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  4785. if (shouldTrace)
  4786. {
  4787. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  4788. }
  4789. HttpStatusCode statusCode = httpResponse.StatusCode;
  4790. if (statusCode != HttpStatusCode.OK)
  4791. {
  4792. cancellationToken.ThrowIfCancellationRequested();
  4793. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  4794. if (shouldTrace)
  4795. {
  4796. TracingAdapter.Error(invocationId, ex);
  4797. }
  4798. throw ex;
  4799. }
  4800. // Create Result
  4801. WebSiteMetadataResult result = null;
  4802. // Deserialize Response
  4803. if (statusCode == HttpStatusCode.OK)
  4804. {
  4805. cancellationToken.ThrowIfCancellationRequested();
  4806. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  4807. result = new WebSiteMetadataResult();
  4808. JToken responseDoc = null;
  4809. if (string.IsNullOrEmpty(responseContent) == false)
  4810. {
  4811. responseDoc = JToken.Parse(responseContent);
  4812. }
  4813. if (responseDoc != null && responseDoc.Type != JTokenType.Null)
  4814. {
  4815. WebSiteMetadataEnvelope resourceInstance = new WebSiteMetadataEnvelope();
  4816. result.Resource = resourceInstance;
  4817. JToken propertiesArray = responseDoc["properties"];
  4818. if (propertiesArray != null && propertiesArray.Type != JTokenType.Null)
  4819. {
  4820. foreach (JToken propertiesValue in ((JArray)propertiesArray))
  4821. {
  4822. NameValuePair nameValuePairInstance = new NameValuePair();
  4823. resourceInstance.Properties.Add(nameValuePairInstance);
  4824. JToken nameValue = propertiesValue["name"];
  4825. if (nameValue != null && nameValue.Type != JTokenType.Null)
  4826. {
  4827. string nameInstance = ((string)nameValue);
  4828. nameValuePairInstance.Name = nameInstance;
  4829. }
  4830. JToken valueValue = propertiesValue["value"];
  4831. if (valueValue != null && valueValue.Type != JTokenType.Null)
  4832. {
  4833. string valueInstance = ((string)valueValue);
  4834. nameValuePairInstance.Value = valueInstance;
  4835. }
  4836. }
  4837. }
  4838. JToken idValue = responseDoc["id"];
  4839. if (idValue != null && idValue.Type != JTokenType.Null)
  4840. {
  4841. string idInstance = ((string)idValue);
  4842. resourceInstance.Id = idInstance;
  4843. }
  4844. JToken nameValue2 = responseDoc["name"];
  4845. if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
  4846. {
  4847. string nameInstance2 = ((string)nameValue2);
  4848. resourceInstance.Name = nameInstance2;
  4849. }
  4850. JToken locationValue = responseDoc["location"];
  4851. if (locationValue != null && locationValue.Type != JTokenType.Null)
  4852. {
  4853. string locationInstance = ((string)locationValue);
  4854. resourceInstance.Location = locationInstance;
  4855. }
  4856. JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
  4857. if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
  4858. {
  4859. foreach (JProperty property in tagsSequenceElement)
  4860. {
  4861. string tagsKey = ((string)property.Name);
  4862. string tagsValue = ((string)property.Value);
  4863. resourceInstance.Tags.Add(tagsKey, tagsValue);
  4864. }
  4865. }
  4866. JToken typeValue = responseDoc["type"];
  4867. if (typeValue != null && typeValue.Type != JTokenType.Null)
  4868. {
  4869. string typeInstance = ((string)typeValue);
  4870. resourceInstance.Type = typeInstance;
  4871. }
  4872. }
  4873. }
  4874. result.StatusCode = statusCode;
  4875. if (httpResponse.Headers.Contains("x-ms-request-id"))
  4876. {
  4877. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  4878. }
  4879. if (shouldTrace)
  4880. {
  4881. TracingAdapter.Exit(invocationId, result);
  4882. }
  4883. return result;
  4884. }
  4885. finally
  4886. {
  4887. if (httpResponse != null)
  4888. {
  4889. httpResponse.Dispose();
  4890. }
  4891. }
  4892. }
  4893. finally
  4894. {
  4895. if (httpRequest != null)
  4896. {
  4897. httpRequest.Dispose();
  4898. }
  4899. }
  4900. }
  4901. /// <summary>
  4902. /// You can retrieve details for a web site by issuing an HTTP GET
  4903. /// request. (see
  4904. /// http://msdn.microsoft.com/en-us/library/windowsazure/dn167007.aspx
  4905. /// for more information)
  4906. /// </summary>
  4907. /// <param name='resourceGroupName'>
  4908. /// Required. The name of the resource group.
  4909. /// </param>
  4910. /// <param name='webSiteName'>
  4911. /// Required. The name of the web site.
  4912. /// </param>
  4913. /// <param name='slotName'>
  4914. /// Optional. The name of the slot.
  4915. /// </param>
  4916. /// <param name='operationId'>
  4917. /// Required. Additional parameters.
  4918. /// </param>
  4919. /// <param name='cancellationToken'>
  4920. /// Cancellation token.
  4921. /// </param>
  4922. /// <returns>
  4923. /// The website operation response.
  4924. /// </returns>
  4925. public async Task<WebSiteAsyncOperationResponse> GetOperationAsync(string resourceGroupName, string webSiteName, string slotName, Guid operationId, CancellationToken cancellationToken)
  4926. {
  4927. // Validate
  4928. if (resourceGroupName == null)
  4929. {
  4930. throw new ArgumentNullException("resourceGroupName");
  4931. }
  4932. if (webSiteName == null)
  4933. {
  4934. throw new ArgumentNullException("webSiteName");
  4935. }
  4936. // Tracing
  4937. bool shouldTrace = TracingAdapter.IsEnabled;
  4938. string invocationId = null;
  4939. if (shouldTrace)
  4940. {
  4941. invocationId = TracingAdapter.NextInvocationId.ToString();
  4942. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  4943. tracingParameters.Add("resourceGroupName", resourceGroupName);
  4944. tracingParameters.Add("webSiteName", webSiteName);
  4945. tracingParameters.Add("slotName", slotName);
  4946. tracingParameters.Add("operationId", operationId);
  4947. TracingAdapter.Enter(invocationId, this, "GetOperationAsync", tracingParameters);
  4948. }
  4949. // Construct URL
  4950. string url = "";
  4951. url = url + "/subscriptions/";
  4952. if (this.Client.Credentials.SubscriptionId != null)
  4953. {
  4954. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  4955. }
  4956. url = url + "/resourceGroups/";
  4957. url = url + Uri.EscapeDataString(resourceGroupName);
  4958. url = url + "/providers/";
  4959. url = url + "Microsoft.Web";
  4960. url = url + "/";
  4961. url = url + "sites";
  4962. url = url + "/";
  4963. url = url + Uri.EscapeDataString(webSiteName);
  4964. if (slotName != null)
  4965. {
  4966. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  4967. }
  4968. url = url + "/operations/";
  4969. url = url + Uri.EscapeDataString(operationId.ToString());
  4970. List<string> queryParameters = new List<string>();
  4971. queryParameters.Add("api-version=2014-06-01");
  4972. if (queryParameters.Count > 0)
  4973. {
  4974. url = url + "?" + string.Join("&", queryParameters);
  4975. }
  4976. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  4977. // Trim '/' character from the end of baseUrl and beginning of url.
  4978. if (baseUrl[baseUrl.Length - 1] == '/')
  4979. {
  4980. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  4981. }
  4982. if (url[0] == '/')
  4983. {
  4984. url = url.Substring(1);
  4985. }
  4986. url = baseUrl + "/" + url;
  4987. url = url.Replace(" ", "%20");
  4988. // Create HTTP transport objects
  4989. HttpRequestMessage httpRequest = null;
  4990. try
  4991. {
  4992. httpRequest = new HttpRequestMessage();
  4993. httpRequest.Method = HttpMethod.Get;
  4994. httpRequest.RequestUri = new Uri(url);
  4995. // Set Headers
  4996. // Set Credentials
  4997. cancellationToken.ThrowIfCancellationRequested();
  4998. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  4999. // Send Request
  5000. HttpResponseMessage httpResponse = null;
  5001. try
  5002. {
  5003. if (shouldTrace)
  5004. {
  5005. TracingAdapter.SendRequest(invocationId, httpRequest);
  5006. }
  5007. cancellationToken.ThrowIfCancellationRequested();
  5008. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  5009. if (shouldTrace)
  5010. {
  5011. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  5012. }
  5013. HttpStatusCode statusCode = httpResponse.StatusCode;
  5014. if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.Created && statusCode != HttpStatusCode.Accepted)
  5015. {
  5016. cancellationToken.ThrowIfCancellationRequested();
  5017. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  5018. if (shouldTrace)
  5019. {
  5020. TracingAdapter.Error(invocationId, ex);
  5021. }
  5022. throw ex;
  5023. }
  5024. // Create Result
  5025. WebSiteAsyncOperationResponse result = null;
  5026. // Deserialize Response
  5027. if (statusCode == HttpStatusCode.OK || statusCode == HttpStatusCode.Created || statusCode == HttpStatusCode.Accepted)
  5028. {
  5029. cancellationToken.ThrowIfCancellationRequested();
  5030. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  5031. result = new WebSiteAsyncOperationResponse();
  5032. JToken responseDoc = null;
  5033. if (string.IsNullOrEmpty(responseContent) == false)
  5034. {
  5035. responseDoc = JToken.Parse(responseContent);
  5036. }
  5037. if (responseDoc != null && responseDoc.Type != JTokenType.Null)
  5038. {
  5039. JToken locationValue = responseDoc["location"];
  5040. if (locationValue != null && locationValue.Type != JTokenType.Null)
  5041. {
  5042. string locationInstance = ((string)locationValue);
  5043. result.Location = locationInstance;
  5044. }
  5045. JToken retryAfterValue = responseDoc["retry-after"];
  5046. if (retryAfterValue != null && retryAfterValue.Type != JTokenType.Null)
  5047. {
  5048. string retryAfterInstance = ((string)retryAfterValue);
  5049. result.RetryAfter = retryAfterInstance;
  5050. }
  5051. }
  5052. }
  5053. result.StatusCode = statusCode;
  5054. if (httpResponse.Headers.Contains("location"))
  5055. {
  5056. result.Location = httpResponse.Headers.GetValues("location").FirstOrDefault();
  5057. }
  5058. if (httpResponse.Headers.Contains("retry-after"))
  5059. {
  5060. result.RetryAfter = httpResponse.Headers.GetValues("retry-after").FirstOrDefault();
  5061. }
  5062. if (httpResponse.Headers.Contains("x-ms-request-id"))
  5063. {
  5064. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  5065. }
  5066. if (shouldTrace)
  5067. {
  5068. TracingAdapter.Exit(invocationId, result);
  5069. }
  5070. return result;
  5071. }
  5072. finally
  5073. {
  5074. if (httpResponse != null)
  5075. {
  5076. httpResponse.Dispose();
  5077. }
  5078. }
  5079. }
  5080. finally
  5081. {
  5082. if (httpRequest != null)
  5083. {
  5084. httpRequest.Dispose();
  5085. }
  5086. }
  5087. }
  5088. /// <summary>
  5089. /// Get publishing credentials for the web site.
  5090. /// </summary>
  5091. /// <param name='resourceGroupName'>
  5092. /// Required. The name of the resource group.
  5093. /// </param>
  5094. /// <param name='webSiteName'>
  5095. /// Required. Name of website
  5096. /// </param>
  5097. /// <param name='slotName'>
  5098. /// Optional. The name of the slot of the web site.
  5099. /// </param>
  5100. /// <param name='cancellationToken'>
  5101. /// Cancellation token.
  5102. /// </param>
  5103. /// <returns>
  5104. /// Publishing credentials for the website.
  5105. /// </returns>
  5106. public async Task<WebSitePublishingCredentialsResult> GetPublishingCredentialsAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
  5107. {
  5108. // Validate
  5109. if (resourceGroupName == null)
  5110. {
  5111. throw new ArgumentNullException("resourceGroupName");
  5112. }
  5113. if (webSiteName == null)
  5114. {
  5115. throw new ArgumentNullException("webSiteName");
  5116. }
  5117. // Tracing
  5118. bool shouldTrace = TracingAdapter.IsEnabled;
  5119. string invocationId = null;
  5120. if (shouldTrace)
  5121. {
  5122. invocationId = TracingAdapter.NextInvocationId.ToString();
  5123. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  5124. tracingParameters.Add("resourceGroupName", resourceGroupName);
  5125. tracingParameters.Add("webSiteName", webSiteName);
  5126. tracingParameters.Add("slotName", slotName);
  5127. TracingAdapter.Enter(invocationId, this, "GetPublishingCredentialsAsync", tracingParameters);
  5128. }
  5129. // Construct URL
  5130. string url = "";
  5131. url = url + "/subscriptions/";
  5132. if (this.Client.Credentials.SubscriptionId != null)
  5133. {
  5134. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  5135. }
  5136. url = url + "/resourceGroups/";
  5137. url = url + Uri.EscapeDataString(resourceGroupName);
  5138. url = url + "/providers/";
  5139. url = url + "Microsoft.Web";
  5140. url = url + "/";
  5141. url = url + "sites";
  5142. url = url + "/";
  5143. url = url + Uri.EscapeDataString(webSiteName);
  5144. if (slotName != null)
  5145. {
  5146. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  5147. }
  5148. url = url + "/config/publishingcredentials/list";
  5149. List<string> queryParameters = new List<string>();
  5150. queryParameters.Add("api-version=2014-06-01");
  5151. if (queryParameters.Count > 0)
  5152. {
  5153. url = url + "?" + string.Join("&", queryParameters);
  5154. }
  5155. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  5156. // Trim '/' character from the end of baseUrl and beginning of url.
  5157. if (baseUrl[baseUrl.Length - 1] == '/')
  5158. {
  5159. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  5160. }
  5161. if (url[0] == '/')
  5162. {
  5163. url = url.Substring(1);
  5164. }
  5165. url = baseUrl + "/" + url;
  5166. url = url.Replace(" ", "%20");
  5167. // Create HTTP transport objects
  5168. HttpRequestMessage httpRequest = null;
  5169. try
  5170. {
  5171. httpRequest = new HttpRequestMessage();
  5172. httpRequest.Method = HttpMethod.Post;
  5173. httpRequest.RequestUri = new Uri(url);
  5174. // Set Headers
  5175. // Set Credentials
  5176. cancellationToken.ThrowIfCancellationRequested();
  5177. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  5178. // Send Request
  5179. HttpResponseMessage httpResponse = null;
  5180. try
  5181. {
  5182. if (shouldTrace)
  5183. {
  5184. TracingAdapter.SendRequest(invocationId, httpRequest);
  5185. }
  5186. cancellationToken.ThrowIfCancellationRequested();
  5187. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  5188. if (shouldTrace)
  5189. {
  5190. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  5191. }
  5192. HttpStatusCode statusCode = httpResponse.StatusCode;
  5193. if (statusCode != HttpStatusCode.OK)
  5194. {
  5195. cancellationToken.ThrowIfCancellationRequested();
  5196. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  5197. if (shouldTrace)
  5198. {
  5199. TracingAdapter.Error(invocationId, ex);
  5200. }
  5201. throw ex;
  5202. }
  5203. // Create Result
  5204. WebSitePublishingCredentialsResult result = null;
  5205. // Deserialize Response
  5206. if (statusCode == HttpStatusCode.OK)
  5207. {
  5208. cancellationToken.ThrowIfCancellationRequested();
  5209. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  5210. result = new WebSitePublishingCredentialsResult();
  5211. JToken responseDoc = null;
  5212. if (string.IsNullOrEmpty(responseContent) == false)
  5213. {
  5214. responseDoc = JToken.Parse(responseContent);
  5215. }
  5216. if (responseDoc != null && responseDoc.Type != JTokenType.Null)
  5217. {
  5218. WebSitePublishingCredentialsEnvelope resourceInstance = new WebSitePublishingCredentialsEnvelope();
  5219. result.Resource = resourceInstance;
  5220. JToken propertiesValue = responseDoc["properties"];
  5221. if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
  5222. {
  5223. PublishingCredentials propertiesInstance = new PublishingCredentials();
  5224. resourceInstance.Properties = propertiesInstance;
  5225. JToken publishingPasswordValue = propertiesValue["publishingPassword"];
  5226. if (publishingPasswordValue != null && publishingPasswordValue.Type != JTokenType.Null)
  5227. {
  5228. string publishingPasswordInstance = ((string)publishingPasswordValue);
  5229. propertiesInstance.PublishingPassword = publishingPasswordInstance;
  5230. }
  5231. JToken publishingUserNameValue = propertiesValue["publishingUserName"];
  5232. if (publishingUserNameValue != null && publishingUserNameValue.Type != JTokenType.Null)
  5233. {
  5234. string publishingUserNameInstance = ((string)publishingUserNameValue);
  5235. propertiesInstance.PublishingUserName = publishingUserNameInstance;
  5236. }
  5237. }
  5238. JToken idValue = responseDoc["id"];
  5239. if (idValue != null && idValue.Type != JTokenType.Null)
  5240. {
  5241. string idInstance = ((string)idValue);
  5242. resourceInstance.Id = idInstance;
  5243. }
  5244. JToken nameValue = responseDoc["name"];
  5245. if (nameValue != null && nameValue.Type != JTokenType.Null)
  5246. {
  5247. string nameInstance = ((string)nameValue);
  5248. resourceInstance.Name = nameInstance;
  5249. }
  5250. JToken locationValue = responseDoc["location"];
  5251. if (locationValue != null && locationValue.Type != JTokenType.Null)
  5252. {
  5253. string locationInstance = ((string)locationValue);
  5254. resourceInstance.Location = locationInstance;
  5255. }
  5256. JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
  5257. if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
  5258. {
  5259. foreach (JProperty property in tagsSequenceElement)
  5260. {
  5261. string tagsKey = ((string)property.Name);
  5262. string tagsValue = ((string)property.Value);
  5263. resourceInstance.Tags.Add(tagsKey, tagsValue);
  5264. }
  5265. }
  5266. JToken typeValue = responseDoc["type"];
  5267. if (typeValue != null && typeValue.Type != JTokenType.Null)
  5268. {
  5269. string typeInstance = ((string)typeValue);
  5270. resourceInstance.Type = typeInstance;
  5271. }
  5272. }
  5273. }
  5274. result.StatusCode = statusCode;
  5275. if (httpResponse.Headers.Contains("x-ms-request-id"))
  5276. {
  5277. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  5278. }
  5279. if (shouldTrace)
  5280. {
  5281. TracingAdapter.Exit(invocationId, result);
  5282. }
  5283. return result;
  5284. }
  5285. finally
  5286. {
  5287. if (httpResponse != null)
  5288. {
  5289. httpResponse.Dispose();
  5290. }
  5291. }
  5292. }
  5293. finally
  5294. {
  5295. if (httpRequest != null)
  5296. {
  5297. httpRequest.Dispose();
  5298. }
  5299. }
  5300. }
  5301. /// <summary>
  5302. /// Retrieve the publish settings information for a web site. (see
  5303. /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166996.aspx
  5304. /// for more information)
  5305. /// </summary>
  5306. /// <param name='resourceGroupName'>
  5307. /// Required. The name of the resource group.
  5308. /// </param>
  5309. /// <param name='webSiteName'>
  5310. /// Required. The name of the web site.
  5311. /// </param>
  5312. /// <param name='slotName'>
  5313. /// Optional. The name of the slot.
  5314. /// </param>
  5315. /// <param name='cancellationToken'>
  5316. /// Cancellation token.
  5317. /// </param>
  5318. /// <returns>
  5319. /// The Get Web Site Publish Profile operation response.
  5320. /// </returns>
  5321. public async Task<WebSiteGetPublishProfileResponse> GetPublishProfileAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
  5322. {
  5323. // Validate
  5324. if (resourceGroupName == null)
  5325. {
  5326. throw new ArgumentNullException("resourceGroupName");
  5327. }
  5328. if (webSiteName == null)
  5329. {
  5330. throw new ArgumentNullException("webSiteName");
  5331. }
  5332. // Tracing
  5333. bool shouldTrace = TracingAdapter.IsEnabled;
  5334. string invocationId = null;
  5335. if (shouldTrace)
  5336. {
  5337. invocationId = TracingAdapter.NextInvocationId.ToString();
  5338. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  5339. tracingParameters.Add("resourceGroupName", resourceGroupName);
  5340. tracingParameters.Add("webSiteName", webSiteName);
  5341. tracingParameters.Add("slotName", slotName);
  5342. TracingAdapter.Enter(invocationId, this, "GetPublishProfileAsync", tracingParameters);
  5343. }
  5344. // Construct URL
  5345. string url = "";
  5346. url = url + "/subscriptions/";
  5347. if (this.Client.Credentials.SubscriptionId != null)
  5348. {
  5349. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  5350. }
  5351. url = url + "/resourceGroups/";
  5352. url = url + Uri.EscapeDataString(resourceGroupName);
  5353. url = url + "/providers/";
  5354. url = url + "Microsoft.Web";
  5355. url = url + "/";
  5356. url = url + "sites";
  5357. url = url + "/";
  5358. url = url + Uri.EscapeDataString(webSiteName);
  5359. if (slotName != null)
  5360. {
  5361. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  5362. }
  5363. url = url + "/publishxml";
  5364. List<string> queryParameters = new List<string>();
  5365. queryParameters.Add("api-version=2014-06-01");
  5366. if (queryParameters.Count > 0)
  5367. {
  5368. url = url + "?" + string.Join("&", queryParameters);
  5369. }
  5370. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  5371. // Trim '/' character from the end of baseUrl and beginning of url.
  5372. if (baseUrl[baseUrl.Length - 1] == '/')
  5373. {
  5374. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  5375. }
  5376. if (url[0] == '/')
  5377. {
  5378. url = url.Substring(1);
  5379. }
  5380. url = baseUrl + "/" + url;
  5381. url = url.Replace(" ", "%20");
  5382. // Create HTTP transport objects
  5383. HttpRequestMessage httpRequest = null;
  5384. try
  5385. {
  5386. httpRequest = new HttpRequestMessage();
  5387. httpRequest.Method = HttpMethod.Post;
  5388. httpRequest.RequestUri = new Uri(url);
  5389. // Set Headers
  5390. // Set Credentials
  5391. cancellationToken.ThrowIfCancellationRequested();
  5392. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  5393. // Send Request
  5394. HttpResponseMessage httpResponse = null;
  5395. try
  5396. {
  5397. if (shouldTrace)
  5398. {
  5399. TracingAdapter.SendRequest(invocationId, httpRequest);
  5400. }
  5401. cancellationToken.ThrowIfCancellationRequested();
  5402. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  5403. if (shouldTrace)
  5404. {
  5405. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  5406. }
  5407. HttpStatusCode statusCode = httpResponse.StatusCode;
  5408. if (statusCode != HttpStatusCode.OK)
  5409. {
  5410. cancellationToken.ThrowIfCancellationRequested();
  5411. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  5412. if (shouldTrace)
  5413. {
  5414. TracingAdapter.Error(invocationId, ex);
  5415. }
  5416. throw ex;
  5417. }
  5418. // Create Result
  5419. WebSiteGetPublishProfileResponse result = null;
  5420. // Deserialize Response
  5421. if (statusCode == HttpStatusCode.OK)
  5422. {
  5423. cancellationToken.ThrowIfCancellationRequested();
  5424. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  5425. result = new WebSiteGetPublishProfileResponse();
  5426. XDocument responseDoc = XDocument.Parse(responseContent);
  5427. XElement publishDataSequenceElement = responseDoc.Element(XName.Get("publishData", ""));
  5428. if (publishDataSequenceElement != null)
  5429. {
  5430. foreach (XElement publishDataElement in publishDataSequenceElement.Elements(XName.Get("publishProfile", "")))
  5431. {
  5432. WebSiteGetPublishProfileResponse.PublishProfile publishProfileInstance = new WebSiteGetPublishProfileResponse.PublishProfile();
  5433. result.PublishProfiles.Add(publishProfileInstance);
  5434. XAttribute profileNameAttribute = publishDataElement.Attribute(XName.Get("profileName", ""));
  5435. if (profileNameAttribute != null)
  5436. {
  5437. publishProfileInstance.ProfileName = profileNameAttribute.Value;
  5438. }
  5439. XAttribute publishMethodAttribute = publishDataElement.Attribute(XName.Get("publishMethod", ""));
  5440. if (publishMethodAttribute != null)
  5441. {
  5442. publishProfileInstance.PublishMethod = publishMethodAttribute.Value;
  5443. }
  5444. XAttribute publishUrlAttribute = publishDataElement.Attribute(XName.Get("publishUrl", ""));
  5445. if (publishUrlAttribute != null)
  5446. {
  5447. publishProfileInstance.PublishUrl = publishUrlAttribute.Value;
  5448. }
  5449. XAttribute msdeploySiteAttribute = publishDataElement.Attribute(XName.Get("msdeploySite", ""));
  5450. if (msdeploySiteAttribute != null)
  5451. {
  5452. publishProfileInstance.MSDeploySite = msdeploySiteAttribute.Value;
  5453. }
  5454. XAttribute ftpPassiveModeAttribute = publishDataElement.Attribute(XName.Get("ftpPassiveMode", ""));
  5455. if (ftpPassiveModeAttribute != null)
  5456. {
  5457. publishProfileInstance.FtpPassiveMode = bool.Parse(ftpPassiveModeAttribute.Value);
  5458. }
  5459. XAttribute userNameAttribute = publishDataElement.Attribute(XName.Get("userName", ""));
  5460. if (userNameAttribute != null)
  5461. {
  5462. publishProfileInstance.UserName = userNameAttribute.Value;
  5463. }
  5464. XAttribute userPWDAttribute = publishDataElement.Attribute(XName.Get("userPWD", ""));
  5465. if (userPWDAttribute != null)
  5466. {
  5467. publishProfileInstance.UserPassword = userPWDAttribute.Value;
  5468. }
  5469. XAttribute destinationAppUrlAttribute = publishDataElement.Attribute(XName.Get("destinationAppUrl", ""));
  5470. if (destinationAppUrlAttribute != null)
  5471. {
  5472. publishProfileInstance.DestinationAppUri = TypeConversion.TryParseUri(destinationAppUrlAttribute.Value);
  5473. }
  5474. XAttribute sQLServerDBConnectionStringAttribute = publishDataElement.Attribute(XName.Get("SQLServerDBConnectionString", ""));
  5475. if (sQLServerDBConnectionStringAttribute != null)
  5476. {
  5477. publishProfileInstance.SqlServerConnectionString = sQLServerDBConnectionStringAttribute.Value;
  5478. }
  5479. XAttribute mySQLDBConnectionStringAttribute = publishDataElement.Attribute(XName.Get("mySQLDBConnectionString", ""));
  5480. if (mySQLDBConnectionStringAttribute != null)
  5481. {
  5482. publishProfileInstance.MySqlConnectionString = mySQLDBConnectionStringAttribute.Value;
  5483. }
  5484. XAttribute hostingProviderForumLinkAttribute = publishDataElement.Attribute(XName.Get("hostingProviderForumLink", ""));
  5485. if (hostingProviderForumLinkAttribute != null)
  5486. {
  5487. publishProfileInstance.HostingProviderForumUri = TypeConversion.TryParseUri(hostingProviderForumLinkAttribute.Value);
  5488. }
  5489. XAttribute controlPanelLinkAttribute = publishDataElement.Attribute(XName.Get("controlPanelLink", ""));
  5490. if (controlPanelLinkAttribute != null)
  5491. {
  5492. publishProfileInstance.ControlPanelUri = TypeConversion.TryParseUri(controlPanelLinkAttribute.Value);
  5493. }
  5494. XElement databasesSequenceElement = publishDataElement.Element(XName.Get("databases", ""));
  5495. if (databasesSequenceElement != null)
  5496. {
  5497. foreach (XElement databasesElement in databasesSequenceElement.Elements(XName.Get("add", "")))
  5498. {
  5499. WebSiteGetPublishProfileResponse.Database addInstance = new WebSiteGetPublishProfileResponse.Database();
  5500. publishProfileInstance.Databases.Add(addInstance);
  5501. XAttribute nameAttribute = databasesElement.Attribute(XName.Get("name", ""));
  5502. if (nameAttribute != null)
  5503. {
  5504. addInstance.Name = nameAttribute.Value;
  5505. }
  5506. XAttribute connectionStringAttribute = databasesElement.Attribute(XName.Get("connectionString", ""));
  5507. if (connectionStringAttribute != null)
  5508. {
  5509. addInstance.ConnectionString = connectionStringAttribute.Value;
  5510. }
  5511. XAttribute providerNameAttribute = databasesElement.Attribute(XName.Get("providerName", ""));
  5512. if (providerNameAttribute != null)
  5513. {
  5514. addInstance.ProviderName = providerNameAttribute.Value;
  5515. }
  5516. XAttribute typeAttribute = databasesElement.Attribute(XName.Get("type", ""));
  5517. if (typeAttribute != null)
  5518. {
  5519. addInstance.Type = typeAttribute.Value;
  5520. }
  5521. }
  5522. }
  5523. }
  5524. }
  5525. }
  5526. result.StatusCode = statusCode;
  5527. if (httpResponse.Headers.Contains("x-ms-request-id"))
  5528. {
  5529. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  5530. }
  5531. if (shouldTrace)
  5532. {
  5533. TracingAdapter.Exit(invocationId, result);
  5534. }
  5535. return result;
  5536. }
  5537. finally
  5538. {
  5539. if (httpResponse != null)
  5540. {
  5541. httpResponse.Dispose();
  5542. }
  5543. }
  5544. }
  5545. finally
  5546. {
  5547. if (httpRequest != null)
  5548. {
  5549. httpRequest.Dispose();
  5550. }
  5551. }
  5552. }
  5553. /// <summary>
  5554. /// A web site repository is essentially a GIT repository that you can
  5555. /// use to manage your web site content. By using GIT source control
  5556. /// tools, you can push or pull version controlled changes to your
  5557. /// site. You can create a repository for your web site by issuing an
  5558. /// HTTP POST request, or retrieve information about the repository by
  5559. /// using HTTP GET. (see
  5560. /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166967.aspx
  5561. /// for more information)
  5562. /// </summary>
  5563. /// <param name='resourceGroupName'>
  5564. /// Required. The name of the resource group.
  5565. /// </param>
  5566. /// <param name='webSiteName'>
  5567. /// Required. The name of the web site.
  5568. /// </param>
  5569. /// <param name='slotName'>
  5570. /// Optional. The name of the slot.
  5571. /// </param>
  5572. /// <param name='cancellationToken'>
  5573. /// Cancellation token.
  5574. /// </param>
  5575. /// <returns>
  5576. /// The Get Web Site Repository operation response.
  5577. /// </returns>
  5578. public async Task<WebSiteGetRepositoryResponse> GetRepositoryAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
  5579. {
  5580. // Validate
  5581. if (resourceGroupName == null)
  5582. {
  5583. throw new ArgumentNullException("resourceGroupName");
  5584. }
  5585. if (webSiteName == null)
  5586. {
  5587. throw new ArgumentNullException("webSiteName");
  5588. }
  5589. // Tracing
  5590. bool shouldTrace = TracingAdapter.IsEnabled;
  5591. string invocationId = null;
  5592. if (shouldTrace)
  5593. {
  5594. invocationId = TracingAdapter.NextInvocationId.ToString();
  5595. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  5596. tracingParameters.Add("resourceGroupName", resourceGroupName);
  5597. tracingParameters.Add("webSiteName", webSiteName);
  5598. tracingParameters.Add("slotName", slotName);
  5599. TracingAdapter.Enter(invocationId, this, "GetRepositoryAsync", tracingParameters);
  5600. }
  5601. // Construct URL
  5602. string url = "";
  5603. url = url + "/subscriptions/";
  5604. if (this.Client.Credentials.SubscriptionId != null)
  5605. {
  5606. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  5607. }
  5608. url = url + "/resourceGroups/";
  5609. url = url + Uri.EscapeDataString(resourceGroupName);
  5610. url = url + "/providers/";
  5611. url = url + "Microsoft.Web";
  5612. url = url + "/";
  5613. url = url + "sites";
  5614. url = url + "/";
  5615. url = url + Uri.EscapeDataString(webSiteName);
  5616. if (slotName != null)
  5617. {
  5618. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  5619. }
  5620. url = url + "/repository";
  5621. List<string> queryParameters = new List<string>();
  5622. queryParameters.Add("api-version=2014-06-01");
  5623. if (queryParameters.Count > 0)
  5624. {
  5625. url = url + "?" + string.Join("&", queryParameters);
  5626. }
  5627. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  5628. // Trim '/' character from the end of baseUrl and beginning of url.
  5629. if (baseUrl[baseUrl.Length - 1] == '/')
  5630. {
  5631. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  5632. }
  5633. if (url[0] == '/')
  5634. {
  5635. url = url.Substring(1);
  5636. }
  5637. url = baseUrl + "/" + url;
  5638. url = url.Replace(" ", "%20");
  5639. // Create HTTP transport objects
  5640. HttpRequestMessage httpRequest = null;
  5641. try
  5642. {
  5643. httpRequest = new HttpRequestMessage();
  5644. httpRequest.Method = HttpMethod.Get;
  5645. httpRequest.RequestUri = new Uri(url);
  5646. // Set Headers
  5647. // Set Credentials
  5648. cancellationToken.ThrowIfCancellationRequested();
  5649. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  5650. // Send Request
  5651. HttpResponseMessage httpResponse = null;
  5652. try
  5653. {
  5654. if (shouldTrace)
  5655. {
  5656. TracingAdapter.SendRequest(invocationId, httpRequest);
  5657. }
  5658. cancellationToken.ThrowIfCancellationRequested();
  5659. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  5660. if (shouldTrace)
  5661. {
  5662. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  5663. }
  5664. HttpStatusCode statusCode = httpResponse.StatusCode;
  5665. if (statusCode != HttpStatusCode.OK)
  5666. {
  5667. cancellationToken.ThrowIfCancellationRequested();
  5668. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  5669. if (shouldTrace)
  5670. {
  5671. TracingAdapter.Error(invocationId, ex);
  5672. }
  5673. throw ex;
  5674. }
  5675. // Create Result
  5676. WebSiteGetRepositoryResponse result = null;
  5677. // Deserialize Response
  5678. if (statusCode == HttpStatusCode.OK)
  5679. {
  5680. cancellationToken.ThrowIfCancellationRequested();
  5681. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  5682. result = new WebSiteGetRepositoryResponse();
  5683. JToken responseDoc = null;
  5684. if (string.IsNullOrEmpty(responseContent) == false)
  5685. {
  5686. responseDoc = JToken.Parse(responseContent);
  5687. }
  5688. if (responseDoc != null && responseDoc.Type != JTokenType.Null)
  5689. {
  5690. JToken uriValue = responseDoc["uri"];
  5691. if (uriValue != null && uriValue.Type != JTokenType.Null)
  5692. {
  5693. Uri uriInstance = TypeConversion.TryParseUri(((string)uriValue));
  5694. result.Uri = uriInstance;
  5695. }
  5696. }
  5697. }
  5698. result.StatusCode = statusCode;
  5699. if (httpResponse.Headers.Contains("x-ms-request-id"))
  5700. {
  5701. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  5702. }
  5703. if (shouldTrace)
  5704. {
  5705. TracingAdapter.Exit(invocationId, result);
  5706. }
  5707. return result;
  5708. }
  5709. finally
  5710. {
  5711. if (httpResponse != null)
  5712. {
  5713. httpResponse.Dispose();
  5714. }
  5715. }
  5716. }
  5717. finally
  5718. {
  5719. if (httpRequest != null)
  5720. {
  5721. httpRequest.Dispose();
  5722. }
  5723. }
  5724. }
  5725. /// <summary>
  5726. /// Update list of app settings and connection strings which to be slot
  5727. /// specific. E.g. settings in staging slots remain in staging after
  5728. /// swap with production.
  5729. /// </summary>
  5730. /// <param name='resourceGroupName'>
  5731. /// Required. The name of the resource group
  5732. /// </param>
  5733. /// <param name='webSiteName'>
  5734. /// Required. The name of the website
  5735. /// </param>
  5736. /// <param name='cancellationToken'>
  5737. /// Cancellation token.
  5738. /// </param>
  5739. /// <returns>
  5740. /// List of slot specific settings.
  5741. /// </returns>
  5742. public async Task<SlotConfigNamesResult> GetSlotConfigNamesAsync(string resourceGroupName, string webSiteName, CancellationToken cancellationToken)
  5743. {
  5744. // Validate
  5745. if (resourceGroupName == null)
  5746. {
  5747. throw new ArgumentNullException("resourceGroupName");
  5748. }
  5749. if (webSiteName == null)
  5750. {
  5751. throw new ArgumentNullException("webSiteName");
  5752. }
  5753. // Tracing
  5754. bool shouldTrace = TracingAdapter.IsEnabled;
  5755. string invocationId = null;
  5756. if (shouldTrace)
  5757. {
  5758. invocationId = TracingAdapter.NextInvocationId.ToString();
  5759. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  5760. tracingParameters.Add("resourceGroupName", resourceGroupName);
  5761. tracingParameters.Add("webSiteName", webSiteName);
  5762. TracingAdapter.Enter(invocationId, this, "GetSlotConfigNamesAsync", tracingParameters);
  5763. }
  5764. // Construct URL
  5765. string url = "";
  5766. url = url + "/subscriptions/";
  5767. if (this.Client.Credentials.SubscriptionId != null)
  5768. {
  5769. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  5770. }
  5771. url = url + "/resourceGroups/";
  5772. url = url + Uri.EscapeDataString(resourceGroupName);
  5773. url = url + "/providers/";
  5774. url = url + "Microsoft.Web";
  5775. url = url + "/";
  5776. url = url + "sites";
  5777. url = url + "/";
  5778. url = url + Uri.EscapeDataString(webSiteName);
  5779. url = url + "/config/slotConfigNames";
  5780. List<string> queryParameters = new List<string>();
  5781. queryParameters.Add("api-version=2014-06-01");
  5782. if (queryParameters.Count > 0)
  5783. {
  5784. url = url + "?" + string.Join("&", queryParameters);
  5785. }
  5786. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  5787. // Trim '/' character from the end of baseUrl and beginning of url.
  5788. if (baseUrl[baseUrl.Length - 1] == '/')
  5789. {
  5790. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  5791. }
  5792. if (url[0] == '/')
  5793. {
  5794. url = url.Substring(1);
  5795. }
  5796. url = baseUrl + "/" + url;
  5797. url = url.Replace(" ", "%20");
  5798. // Create HTTP transport objects
  5799. HttpRequestMessage httpRequest = null;
  5800. try
  5801. {
  5802. httpRequest = new HttpRequestMessage();
  5803. httpRequest.Method = HttpMethod.Get;
  5804. httpRequest.RequestUri = new Uri(url);
  5805. // Set Headers
  5806. httpRequest.Headers.Add("accept", "application/json");
  5807. // Set Credentials
  5808. cancellationToken.ThrowIfCancellationRequested();
  5809. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  5810. // Send Request
  5811. HttpResponseMessage httpResponse = null;
  5812. try
  5813. {
  5814. if (shouldTrace)
  5815. {
  5816. TracingAdapter.SendRequest(invocationId, httpRequest);
  5817. }
  5818. cancellationToken.ThrowIfCancellationRequested();
  5819. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  5820. if (shouldTrace)
  5821. {
  5822. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  5823. }
  5824. HttpStatusCode statusCode = httpResponse.StatusCode;
  5825. if (statusCode != HttpStatusCode.OK)
  5826. {
  5827. cancellationToken.ThrowIfCancellationRequested();
  5828. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  5829. if (shouldTrace)
  5830. {
  5831. TracingAdapter.Error(invocationId, ex);
  5832. }
  5833. throw ex;
  5834. }
  5835. // Create Result
  5836. SlotConfigNamesResult result = null;
  5837. // Deserialize Response
  5838. if (statusCode == HttpStatusCode.OK)
  5839. {
  5840. cancellationToken.ThrowIfCancellationRequested();
  5841. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  5842. result = new SlotConfigNamesResult();
  5843. JToken responseDoc = null;
  5844. if (string.IsNullOrEmpty(responseContent) == false)
  5845. {
  5846. responseDoc = JToken.Parse(responseContent);
  5847. }
  5848. if (responseDoc != null && responseDoc.Type != JTokenType.Null)
  5849. {
  5850. SlotConfigNamesEnvelope resourceInstance = new SlotConfigNamesEnvelope();
  5851. result.Resource = resourceInstance;
  5852. JToken propertiesValue = responseDoc["properties"];
  5853. if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
  5854. {
  5855. SlotConfigNames propertiesInstance = new SlotConfigNames();
  5856. resourceInstance.Properties = propertiesInstance;
  5857. JToken connectionStringNamesArray = propertiesValue["connectionStringNames"];
  5858. if (connectionStringNamesArray != null && connectionStringNamesArray.Type != JTokenType.Null)
  5859. {
  5860. foreach (JToken connectionStringNamesValue in ((JArray)connectionStringNamesArray))
  5861. {
  5862. propertiesInstance.ConnectionStringNames.Add(((string)connectionStringNamesValue));
  5863. }
  5864. }
  5865. JToken appSettingNamesArray = propertiesValue["appSettingNames"];
  5866. if (appSettingNamesArray != null && appSettingNamesArray.Type != JTokenType.Null)
  5867. {
  5868. foreach (JToken appSettingNamesValue in ((JArray)appSettingNamesArray))
  5869. {
  5870. propertiesInstance.AppSettingNames.Add(((string)appSettingNamesValue));
  5871. }
  5872. }
  5873. }
  5874. JToken idValue = responseDoc["id"];
  5875. if (idValue != null && idValue.Type != JTokenType.Null)
  5876. {
  5877. string idInstance = ((string)idValue);
  5878. resourceInstance.Id = idInstance;
  5879. }
  5880. JToken nameValue = responseDoc["name"];
  5881. if (nameValue != null && nameValue.Type != JTokenType.Null)
  5882. {
  5883. string nameInstance = ((string)nameValue);
  5884. resourceInstance.Name = nameInstance;
  5885. }
  5886. JToken locationValue = responseDoc["location"];
  5887. if (locationValue != null && locationValue.Type != JTokenType.Null)
  5888. {
  5889. string locationInstance = ((string)locationValue);
  5890. resourceInstance.Location = locationInstance;
  5891. }
  5892. JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
  5893. if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
  5894. {
  5895. foreach (JProperty property in tagsSequenceElement)
  5896. {
  5897. string tagsKey = ((string)property.Name);
  5898. string tagsValue = ((string)property.Value);
  5899. resourceInstance.Tags.Add(tagsKey, tagsValue);
  5900. }
  5901. }
  5902. JToken typeValue = responseDoc["type"];
  5903. if (typeValue != null && typeValue.Type != JTokenType.Null)
  5904. {
  5905. string typeInstance = ((string)typeValue);
  5906. resourceInstance.Type = typeInstance;
  5907. }
  5908. }
  5909. }
  5910. result.StatusCode = statusCode;
  5911. if (httpResponse.Headers.Contains("x-ms-request-id"))
  5912. {
  5913. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  5914. }
  5915. if (shouldTrace)
  5916. {
  5917. TracingAdapter.Exit(invocationId, result);
  5918. }
  5919. return result;
  5920. }
  5921. finally
  5922. {
  5923. if (httpResponse != null)
  5924. {
  5925. httpResponse.Dispose();
  5926. }
  5927. }
  5928. }
  5929. finally
  5930. {
  5931. if (httpRequest != null)
  5932. {
  5933. httpRequest.Dispose();
  5934. }
  5935. }
  5936. }
  5937. /// <summary>
  5938. /// Get a web site's current usage metrics. The metrics returned
  5939. /// include CPU Time, Data In, Data Out, Local bytes read, Local bytes
  5940. /// written, Network bytes read, Network bytes written, WP stop
  5941. /// requests, Memory Usage, CPU Time - Minute Limit, and File System
  5942. /// Storage. (see
  5943. /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166991.aspx
  5944. /// for more information)
  5945. /// </summary>
  5946. /// <param name='resourceGroupName'>
  5947. /// Required. The name of the resource group.
  5948. /// </param>
  5949. /// <param name='webSiteName'>
  5950. /// Required. The name of the web site.
  5951. /// </param>
  5952. /// <param name='slotName'>
  5953. /// Optional. The name of the slot.
  5954. /// </param>
  5955. /// <param name='cancellationToken'>
  5956. /// Cancellation token.
  5957. /// </param>
  5958. /// <returns>
  5959. /// The Get Web Site Usage Metrics operation response.
  5960. /// </returns>
  5961. public async Task<WebSiteGetUsageMetricsResponse> GetUsageMetricsAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
  5962. {
  5963. // Validate
  5964. if (resourceGroupName == null)
  5965. {
  5966. throw new ArgumentNullException("resourceGroupName");
  5967. }
  5968. if (webSiteName == null)
  5969. {
  5970. throw new ArgumentNullException("webSiteName");
  5971. }
  5972. // Tracing
  5973. bool shouldTrace = TracingAdapter.IsEnabled;
  5974. string invocationId = null;
  5975. if (shouldTrace)
  5976. {
  5977. invocationId = TracingAdapter.NextInvocationId.ToString();
  5978. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  5979. tracingParameters.Add("resourceGroupName", resourceGroupName);
  5980. tracingParameters.Add("webSiteName", webSiteName);
  5981. tracingParameters.Add("slotName", slotName);
  5982. TracingAdapter.Enter(invocationId, this, "GetUsageMetricsAsync", tracingParameters);
  5983. }
  5984. // Construct URL
  5985. string url = "";
  5986. url = url + "/subscriptions/";
  5987. if (this.Client.Credentials.SubscriptionId != null)
  5988. {
  5989. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  5990. }
  5991. url = url + "/resourceGroups/";
  5992. url = url + Uri.EscapeDataString(resourceGroupName);
  5993. url = url + "/providers/";
  5994. url = url + "Microsoft.Web";
  5995. url = url + "/";
  5996. url = url + "sites";
  5997. url = url + "/";
  5998. url = url + Uri.EscapeDataString(webSiteName);
  5999. if (slotName != null)
  6000. {
  6001. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  6002. }
  6003. url = url + "/usages";
  6004. List<string> queryParameters = new List<string>();
  6005. queryParameters.Add("api-version=2014-06-01");
  6006. if (queryParameters.Count > 0)
  6007. {
  6008. url = url + "?" + string.Join("&", queryParameters);
  6009. }
  6010. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  6011. // Trim '/' character from the end of baseUrl and beginning of url.
  6012. if (baseUrl[baseUrl.Length - 1] == '/')
  6013. {
  6014. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  6015. }
  6016. if (url[0] == '/')
  6017. {
  6018. url = url.Substring(1);
  6019. }
  6020. url = baseUrl + "/" + url;
  6021. url = url.Replace(" ", "%20");
  6022. // Create HTTP transport objects
  6023. HttpRequestMessage httpRequest = null;
  6024. try
  6025. {
  6026. httpRequest = new HttpRequestMessage();
  6027. httpRequest.Method = HttpMethod.Get;
  6028. httpRequest.RequestUri = new Uri(url);
  6029. // Set Headers
  6030. // Set Credentials
  6031. cancellationToken.ThrowIfCancellationRequested();
  6032. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  6033. // Send Request
  6034. HttpResponseMessage httpResponse = null;
  6035. try
  6036. {
  6037. if (shouldTrace)
  6038. {
  6039. TracingAdapter.SendRequest(invocationId, httpRequest);
  6040. }
  6041. cancellationToken.ThrowIfCancellationRequested();
  6042. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  6043. if (shouldTrace)
  6044. {
  6045. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  6046. }
  6047. HttpStatusCode statusCode = httpResponse.StatusCode;
  6048. if (statusCode != HttpStatusCode.OK)
  6049. {
  6050. cancellationToken.ThrowIfCancellationRequested();
  6051. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  6052. if (shouldTrace)
  6053. {
  6054. TracingAdapter.Error(invocationId, ex);
  6055. }
  6056. throw ex;
  6057. }
  6058. // Create Result
  6059. WebSiteGetUsageMetricsResponse result = null;
  6060. // Deserialize Response
  6061. if (statusCode == HttpStatusCode.OK)
  6062. {
  6063. cancellationToken.ThrowIfCancellationRequested();
  6064. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  6065. result = new WebSiteGetUsageMetricsResponse();
  6066. JToken responseDoc = null;
  6067. if (string.IsNullOrEmpty(responseContent) == false)
  6068. {
  6069. responseDoc = JToken.Parse(responseContent);
  6070. }
  6071. JToken usagesValue = responseDoc["usages"];
  6072. if (usagesValue != null && usagesValue.Type != JTokenType.Null)
  6073. {
  6074. WebSiteGetUsageMetricsResponse usagesInstance = new WebSiteGetUsageMetricsResponse();
  6075. JToken usageMetricsArray = usagesValue;
  6076. if (usageMetricsArray != null && usageMetricsArray.Type != JTokenType.Null)
  6077. {
  6078. foreach (JToken usageMetricsValue in ((JArray)usageMetricsArray))
  6079. {
  6080. WebSiteGetUsageMetricsResponse.UsageMetric usageInstance = new WebSiteGetUsageMetricsResponse.UsageMetric();
  6081. usagesInstance.UsageMetrics.Add(usageInstance);
  6082. JToken currentValueValue = usageMetricsValue["currentValue"];
  6083. if (currentValueValue != null && currentValueValue.Type != JTokenType.Null)
  6084. {
  6085. string currentValueInstance = ((string)currentValueValue);
  6086. usageInstance.CurrentValue = currentValueInstance;
  6087. }
  6088. JToken displayNameValue = usageMetricsValue["displayName"];
  6089. if (displayNameValue != null && displayNameValue.Type != JTokenType.Null)
  6090. {
  6091. string displayNameInstance = ((string)displayNameValue);
  6092. usageInstance.DisplayName = displayNameInstance;
  6093. }
  6094. JToken limitValue = usageMetricsValue["limit"];
  6095. if (limitValue != null && limitValue.Type != JTokenType.Null)
  6096. {
  6097. string limitInstance = ((string)limitValue);
  6098. usageInstance.Limit = limitInstance;
  6099. }
  6100. JToken nameValue = usageMetricsValue["name"];
  6101. if (nameValue != null && nameValue.Type != JTokenType.Null)
  6102. {
  6103. string nameInstance = ((string)nameValue);
  6104. usageInstance.Name = nameInstance;
  6105. }
  6106. JToken nextResetTimeValue = usageMetricsValue["nextResetTime"];
  6107. if (nextResetTimeValue != null && nextResetTimeValue.Type != JTokenType.Null)
  6108. {
  6109. DateTime nextResetTimeInstance = ((DateTime)nextResetTimeValue);
  6110. usageInstance.NextResetTime = nextResetTimeInstance;
  6111. }
  6112. JToken resourceNameValue = usageMetricsValue["resourceName"];
  6113. if (resourceNameValue != null && resourceNameValue.Type != JTokenType.Null)
  6114. {
  6115. string resourceNameInstance = ((string)resourceNameValue);
  6116. usageInstance.ResourceName = resourceNameInstance;
  6117. }
  6118. JToken unitValue = usageMetricsValue["unit"];
  6119. if (unitValue != null && unitValue.Type != JTokenType.Null)
  6120. {
  6121. string unitInstance = ((string)unitValue);
  6122. usageInstance.Unit = unitInstance;
  6123. }
  6124. }
  6125. }
  6126. }
  6127. }
  6128. result.StatusCode = statusCode;
  6129. if (httpResponse.Headers.Contains("x-ms-request-id"))
  6130. {
  6131. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  6132. }
  6133. if (shouldTrace)
  6134. {
  6135. TracingAdapter.Exit(invocationId, result);
  6136. }
  6137. return result;
  6138. }
  6139. finally
  6140. {
  6141. if (httpResponse != null)
  6142. {
  6143. httpResponse.Dispose();
  6144. }
  6145. }
  6146. }
  6147. finally
  6148. {
  6149. if (httpRequest != null)
  6150. {
  6151. httpRequest.Dispose();
  6152. }
  6153. }
  6154. }
  6155. /// <summary>
  6156. /// List the Web Sites in a resource group.
  6157. /// </summary>
  6158. /// <param name='resourceGroupName'>
  6159. /// Required. The name of the resource group.
  6160. /// </param>
  6161. /// <param name='webSiteName'>
  6162. /// Optional. The name of the web site.
  6163. /// </param>
  6164. /// <param name='parameters'>
  6165. /// Optional. Additional parameters.
  6166. /// </param>
  6167. /// <param name='cancellationToken'>
  6168. /// Cancellation token.
  6169. /// </param>
  6170. /// <returns>
  6171. /// The List Web Sites operation response.
  6172. /// </returns>
  6173. public async Task<WebSiteListResponse> ListAsync(string resourceGroupName, string webSiteName, WebSiteListParameters parameters, CancellationToken cancellationToken)
  6174. {
  6175. // Validate
  6176. if (resourceGroupName == null)
  6177. {
  6178. throw new ArgumentNullException("resourceGroupName");
  6179. }
  6180. // Tracing
  6181. bool shouldTrace = TracingAdapter.IsEnabled;
  6182. string invocationId = null;
  6183. if (shouldTrace)
  6184. {
  6185. invocationId = TracingAdapter.NextInvocationId.ToString();
  6186. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  6187. tracingParameters.Add("resourceGroupName", resourceGroupName);
  6188. tracingParameters.Add("webSiteName", webSiteName);
  6189. tracingParameters.Add("parameters", parameters);
  6190. TracingAdapter.Enter(invocationId, this, "ListAsync", tracingParameters);
  6191. }
  6192. // Construct URL
  6193. string url = "";
  6194. url = url + "/subscriptions/";
  6195. if (this.Client.Credentials.SubscriptionId != null)
  6196. {
  6197. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  6198. }
  6199. url = url + "/resourceGroups/";
  6200. url = url + Uri.EscapeDataString(resourceGroupName);
  6201. url = url + "/providers/";
  6202. url = url + "Microsoft.Web";
  6203. url = url + "/";
  6204. url = url + "sites";
  6205. if (webSiteName != null)
  6206. {
  6207. url = url + "/" + Uri.EscapeDataString(webSiteName) + "/slots/";
  6208. }
  6209. List<string> queryParameters = new List<string>();
  6210. queryParameters.Add("api-version=2014-06-01");
  6211. if (parameters != null && parameters.PropertiesToInclude != null && parameters.PropertiesToInclude.Count > 0)
  6212. {
  6213. queryParameters.Add("propertiesToInclude=" + Uri.EscapeDataString(string.Join(",", parameters.PropertiesToInclude)));
  6214. }
  6215. if (queryParameters.Count > 0)
  6216. {
  6217. url = url + "?" + string.Join("&", queryParameters);
  6218. }
  6219. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  6220. // Trim '/' character from the end of baseUrl and beginning of url.
  6221. if (baseUrl[baseUrl.Length - 1] == '/')
  6222. {
  6223. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  6224. }
  6225. if (url[0] == '/')
  6226. {
  6227. url = url.Substring(1);
  6228. }
  6229. url = baseUrl + "/" + url;
  6230. url = url.Replace(" ", "%20");
  6231. // Create HTTP transport objects
  6232. HttpRequestMessage httpRequest = null;
  6233. try
  6234. {
  6235. httpRequest = new HttpRequestMessage();
  6236. httpRequest.Method = HttpMethod.Get;
  6237. httpRequest.RequestUri = new Uri(url);
  6238. // Set Headers
  6239. // Set Credentials
  6240. cancellationToken.ThrowIfCancellationRequested();
  6241. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  6242. // Send Request
  6243. HttpResponseMessage httpResponse = null;
  6244. try
  6245. {
  6246. if (shouldTrace)
  6247. {
  6248. TracingAdapter.SendRequest(invocationId, httpRequest);
  6249. }
  6250. cancellationToken.ThrowIfCancellationRequested();
  6251. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  6252. if (shouldTrace)
  6253. {
  6254. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  6255. }
  6256. HttpStatusCode statusCode = httpResponse.StatusCode;
  6257. if (statusCode != HttpStatusCode.OK)
  6258. {
  6259. cancellationToken.ThrowIfCancellationRequested();
  6260. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  6261. if (shouldTrace)
  6262. {
  6263. TracingAdapter.Error(invocationId, ex);
  6264. }
  6265. throw ex;
  6266. }
  6267. // Create Result
  6268. WebSiteListResponse result = null;
  6269. // Deserialize Response
  6270. if (statusCode == HttpStatusCode.OK)
  6271. {
  6272. cancellationToken.ThrowIfCancellationRequested();
  6273. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  6274. result = new WebSiteListResponse();
  6275. JToken responseDoc = null;
  6276. if (string.IsNullOrEmpty(responseContent) == false)
  6277. {
  6278. responseDoc = JToken.Parse(responseContent);
  6279. }
  6280. if (responseDoc != null && responseDoc.Type != JTokenType.Null)
  6281. {
  6282. JToken valueArray = responseDoc["value"];
  6283. if (valueArray != null && valueArray.Type != JTokenType.Null)
  6284. {
  6285. foreach (JToken valueValue in ((JArray)valueArray))
  6286. {
  6287. WebSite webSiteInstance = new WebSite();
  6288. result.WebSites.Add(webSiteInstance);
  6289. JToken propertiesValue = valueValue["properties"];
  6290. if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
  6291. {
  6292. WebSiteProperties propertiesInstance = new WebSiteProperties();
  6293. webSiteInstance.Properties = propertiesInstance;
  6294. JToken adminEnabledValue = propertiesValue["adminEnabled"];
  6295. if (adminEnabledValue != null && adminEnabledValue.Type != JTokenType.Null)
  6296. {
  6297. bool adminEnabledInstance = ((bool)adminEnabledValue);
  6298. propertiesInstance.AdminEnabled = adminEnabledInstance;
  6299. }
  6300. JToken availabilityStateValue = propertiesValue["availabilityState"];
  6301. if (availabilityStateValue != null && availabilityStateValue.Type != JTokenType.Null)
  6302. {
  6303. WebSpaceAvailabilityState availabilityStateInstance = ((WebSpaceAvailabilityState)Enum.Parse(typeof(WebSpaceAvailabilityState), ((string)availabilityStateValue), true));
  6304. propertiesInstance.AvailabilityState = availabilityStateInstance;
  6305. }
  6306. JToken enabledValue = propertiesValue["enabled"];
  6307. if (enabledValue != null && enabledValue.Type != JTokenType.Null)
  6308. {
  6309. bool enabledInstance = ((bool)enabledValue);
  6310. propertiesInstance.Enabled = enabledInstance;
  6311. }
  6312. JToken enabledHostNamesArray = propertiesValue["enabledHostNames"];
  6313. if (enabledHostNamesArray != null && enabledHostNamesArray.Type != JTokenType.Null)
  6314. {
  6315. foreach (JToken enabledHostNamesValue in ((JArray)enabledHostNamesArray))
  6316. {
  6317. propertiesInstance.EnabledHostNames.Add(((string)enabledHostNamesValue));
  6318. }
  6319. }
  6320. JToken hostNameSslStatesArray = propertiesValue["hostNameSslStates"];
  6321. if (hostNameSslStatesArray != null && hostNameSslStatesArray.Type != JTokenType.Null)
  6322. {
  6323. foreach (JToken hostNameSslStatesValue in ((JArray)hostNameSslStatesArray))
  6324. {
  6325. WebSiteProperties.WebSiteHostNameSslState webSiteHostNameSslStateInstance = new WebSiteProperties.WebSiteHostNameSslState();
  6326. propertiesInstance.HostNameSslStates.Add(webSiteHostNameSslStateInstance);
  6327. JToken nameValue = hostNameSslStatesValue["name"];
  6328. if (nameValue != null && nameValue.Type != JTokenType.Null)
  6329. {
  6330. string nameInstance = ((string)nameValue);
  6331. webSiteHostNameSslStateInstance.Name = nameInstance;
  6332. }
  6333. JToken sslStateValue = hostNameSslStatesValue["sslState"];
  6334. if (sslStateValue != null && sslStateValue.Type != JTokenType.Null)
  6335. {
  6336. WebSiteSslState sslStateInstance = ((WebSiteSslState)Enum.Parse(typeof(WebSiteSslState), ((string)sslStateValue), true));
  6337. webSiteHostNameSslStateInstance.SslState = sslStateInstance;
  6338. }
  6339. JToken thumbprintValue = hostNameSslStatesValue["thumbprint"];
  6340. if (thumbprintValue != null && thumbprintValue.Type != JTokenType.Null)
  6341. {
  6342. string thumbprintInstance = ((string)thumbprintValue);
  6343. webSiteHostNameSslStateInstance.Thumbprint = thumbprintInstance;
  6344. }
  6345. JToken virtualIPValue = hostNameSslStatesValue["virtualIP"];
  6346. if (virtualIPValue != null && virtualIPValue.Type != JTokenType.Null)
  6347. {
  6348. string virtualIPInstance = ((string)virtualIPValue);
  6349. webSiteHostNameSslStateInstance.VirtualIP = virtualIPInstance;
  6350. }
  6351. JToken ipBasedSslResultValue = hostNameSslStatesValue["ipBasedSslResult"];
  6352. if (ipBasedSslResultValue != null && ipBasedSslResultValue.Type != JTokenType.Null)
  6353. {
  6354. string ipBasedSslResultInstance = ((string)ipBasedSslResultValue);
  6355. webSiteHostNameSslStateInstance.IpBasedSslResult = ipBasedSslResultInstance;
  6356. }
  6357. JToken toUpdateValue = hostNameSslStatesValue["toUpdate"];
  6358. if (toUpdateValue != null && toUpdateValue.Type != JTokenType.Null)
  6359. {
  6360. bool toUpdateInstance = ((bool)toUpdateValue);
  6361. webSiteHostNameSslStateInstance.ToUpdate = toUpdateInstance;
  6362. }
  6363. JToken toUpdateIpBasedSslValue = hostNameSslStatesValue["toUpdateIpBasedSsl"];
  6364. if (toUpdateIpBasedSslValue != null && toUpdateIpBasedSslValue.Type != JTokenType.Null)
  6365. {
  6366. bool toUpdateIpBasedSslInstance = ((bool)toUpdateIpBasedSslValue);
  6367. webSiteHostNameSslStateInstance.ToUpdateIpBasedSsl = toUpdateIpBasedSslInstance;
  6368. }
  6369. }
  6370. }
  6371. JToken hostNamesArray = propertiesValue["hostNames"];
  6372. if (hostNamesArray != null && hostNamesArray.Type != JTokenType.Null)
  6373. {
  6374. foreach (JToken hostNamesValue in ((JArray)hostNamesArray))
  6375. {
  6376. propertiesInstance.HostNames.Add(((string)hostNamesValue));
  6377. }
  6378. }
  6379. JToken lastModifiedTimeUtcValue = propertiesValue["lastModifiedTimeUtc"];
  6380. if (lastModifiedTimeUtcValue != null && lastModifiedTimeUtcValue.Type != JTokenType.Null)
  6381. {
  6382. DateTime lastModifiedTimeUtcInstance = ((DateTime)lastModifiedTimeUtcValue);
  6383. propertiesInstance.LastModifiedTimeUtc = lastModifiedTimeUtcInstance;
  6384. }
  6385. JToken repositorySiteNameValue = propertiesValue["repositorySiteName"];
  6386. if (repositorySiteNameValue != null && repositorySiteNameValue.Type != JTokenType.Null)
  6387. {
  6388. string repositorySiteNameInstance = ((string)repositorySiteNameValue);
  6389. propertiesInstance.RepositorySiteName = repositorySiteNameInstance;
  6390. }
  6391. JToken runtimeAvailabilityStateValue = propertiesValue["runtimeAvailabilityState"];
  6392. if (runtimeAvailabilityStateValue != null && runtimeAvailabilityStateValue.Type != JTokenType.Null)
  6393. {
  6394. WebSiteRuntimeAvailabilityState runtimeAvailabilityStateInstance = ((WebSiteRuntimeAvailabilityState)Enum.Parse(typeof(WebSiteRuntimeAvailabilityState), ((string)runtimeAvailabilityStateValue), true));
  6395. propertiesInstance.RuntimeAvailabilityState = runtimeAvailabilityStateInstance;
  6396. }
  6397. JToken trafficManagerHostNamesArray = propertiesValue["trafficManagerHostNames"];
  6398. if (trafficManagerHostNamesArray != null && trafficManagerHostNamesArray.Type != JTokenType.Null)
  6399. {
  6400. foreach (JToken trafficManagerHostNamesValue in ((JArray)trafficManagerHostNamesArray))
  6401. {
  6402. propertiesInstance.TrafficManagerHostNames.Add(((string)trafficManagerHostNamesValue));
  6403. }
  6404. }
  6405. JToken selfLinkValue = propertiesValue["selfLink"];
  6406. if (selfLinkValue != null && selfLinkValue.Type != JTokenType.Null)
  6407. {
  6408. Uri selfLinkInstance = TypeConversion.TryParseUri(((string)selfLinkValue));
  6409. propertiesInstance.Uri = selfLinkInstance;
  6410. }
  6411. JToken serverFarmValue = propertiesValue["serverFarm"];
  6412. if (serverFarmValue != null && serverFarmValue.Type != JTokenType.Null)
  6413. {
  6414. string serverFarmInstance = ((string)serverFarmValue);
  6415. propertiesInstance.ServerFarm = serverFarmInstance;
  6416. }
  6417. JToken serverFarmIdValue = propertiesValue["serverFarmId"];
  6418. if (serverFarmIdValue != null && serverFarmIdValue.Type != JTokenType.Null)
  6419. {
  6420. string serverFarmIdInstance = ((string)serverFarmIdValue);
  6421. propertiesInstance.ServerFarmId = serverFarmIdInstance;
  6422. }
  6423. JToken skuValue = propertiesValue["sku"];
  6424. if (skuValue != null && skuValue.Type != JTokenType.Null)
  6425. {
  6426. SkuOptions skuInstance = ((SkuOptions)Enum.Parse(typeof(SkuOptions), ((string)skuValue), true));
  6427. propertiesInstance.Sku = skuInstance;
  6428. }
  6429. JToken sitePropertiesValue = propertiesValue["siteProperties"];
  6430. if (sitePropertiesValue != null && sitePropertiesValue.Type != JTokenType.Null)
  6431. {
  6432. WebSiteProperties.SiteProperties sitePropertiesInstance = new WebSiteProperties.SiteProperties();
  6433. propertiesInstance.Properties = sitePropertiesInstance;
  6434. JToken appSettingsSequenceElement = ((JToken)sitePropertiesValue["appSettings"]);
  6435. if (appSettingsSequenceElement != null && appSettingsSequenceElement.Type != JTokenType.Null)
  6436. {
  6437. foreach (JProperty property in appSettingsSequenceElement)
  6438. {
  6439. string appSettingsKey = ((string)property.Name);
  6440. string appSettingsValue = ((string)property.Value);
  6441. sitePropertiesInstance.AppSettings.Add(appSettingsKey, appSettingsValue);
  6442. }
  6443. }
  6444. JToken metadataSequenceElement = ((JToken)sitePropertiesValue["metadata"]);
  6445. if (metadataSequenceElement != null && metadataSequenceElement.Type != JTokenType.Null)
  6446. {
  6447. foreach (JProperty property2 in metadataSequenceElement)
  6448. {
  6449. string metadataKey = ((string)property2.Name);
  6450. string metadataValue = ((string)property2.Value);
  6451. sitePropertiesInstance.Metadata.Add(metadataKey, metadataValue);
  6452. }
  6453. }
  6454. JToken propertiesSequenceElement = ((JToken)sitePropertiesValue["properties"]);
  6455. if (propertiesSequenceElement != null && propertiesSequenceElement.Type != JTokenType.Null)
  6456. {
  6457. foreach (JProperty property3 in propertiesSequenceElement)
  6458. {
  6459. string propertiesKey = ((string)property3.Name);
  6460. string propertiesValue2 = ((string)property3.Value);
  6461. sitePropertiesInstance.Properties.Add(propertiesKey, propertiesValue2);
  6462. }
  6463. }
  6464. }
  6465. JToken siteConfigValue = propertiesValue["siteConfig"];
  6466. if (siteConfigValue != null && siteConfigValue.Type != JTokenType.Null)
  6467. {
  6468. WebSiteConfiguration siteConfigInstance = new WebSiteConfiguration();
  6469. propertiesInstance.SiteConfig = siteConfigInstance;
  6470. JToken appSettingsSequenceElement2 = ((JToken)siteConfigValue["appSettings"]);
  6471. if (appSettingsSequenceElement2 != null && appSettingsSequenceElement2.Type != JTokenType.Null)
  6472. {
  6473. foreach (JProperty property4 in appSettingsSequenceElement2)
  6474. {
  6475. string appSettingsKey2 = ((string)property4.Name);
  6476. string appSettingsValue2 = ((string)property4.Value);
  6477. siteConfigInstance.AppSettings.Add(appSettingsKey2, appSettingsValue2);
  6478. }
  6479. }
  6480. JToken connectionStringsArray = siteConfigValue["connectionStrings"];
  6481. if (connectionStringsArray != null && connectionStringsArray.Type != JTokenType.Null)
  6482. {
  6483. foreach (JToken connectionStringsValue in ((JArray)connectionStringsArray))
  6484. {
  6485. ConnectionStringInfo connStringInfoInstance = new ConnectionStringInfo();
  6486. siteConfigInstance.ConnectionStrings.Add(connStringInfoInstance);
  6487. JToken connectionStringValue = connectionStringsValue["connectionString"];
  6488. if (connectionStringValue != null && connectionStringValue.Type != JTokenType.Null)
  6489. {
  6490. string connectionStringInstance = ((string)connectionStringValue);
  6491. connStringInfoInstance.ConnectionString = connectionStringInstance;
  6492. }
  6493. JToken nameValue2 = connectionStringsValue["name"];
  6494. if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
  6495. {
  6496. string nameInstance2 = ((string)nameValue2);
  6497. connStringInfoInstance.Name = nameInstance2;
  6498. }
  6499. JToken typeValue = connectionStringsValue["type"];
  6500. if (typeValue != null && typeValue.Type != JTokenType.Null)
  6501. {
  6502. DatabaseServerType typeInstance = ((DatabaseServerType)Enum.Parse(typeof(DatabaseServerType), ((string)typeValue), true));
  6503. connStringInfoInstance.Type = typeInstance;
  6504. }
  6505. }
  6506. }
  6507. JToken defaultDocumentsArray = siteConfigValue["defaultDocuments"];
  6508. if (defaultDocumentsArray != null && defaultDocumentsArray.Type != JTokenType.Null)
  6509. {
  6510. foreach (JToken defaultDocumentsValue in ((JArray)defaultDocumentsArray))
  6511. {
  6512. siteConfigInstance.DefaultDocuments.Add(((string)defaultDocumentsValue));
  6513. }
  6514. }
  6515. JToken detailedErrorLoggingEnabledValue = siteConfigValue["detailedErrorLoggingEnabled"];
  6516. if (detailedErrorLoggingEnabledValue != null && detailedErrorLoggingEnabledValue.Type != JTokenType.Null)
  6517. {
  6518. bool detailedErrorLoggingEnabledInstance = ((bool)detailedErrorLoggingEnabledValue);
  6519. siteConfigInstance.DetailedErrorLoggingEnabled = detailedErrorLoggingEnabledInstance;
  6520. }
  6521. JToken documentRootValue = siteConfigValue["documentRoot"];
  6522. if (documentRootValue != null && documentRootValue.Type != JTokenType.Null)
  6523. {
  6524. string documentRootInstance = ((string)documentRootValue);
  6525. siteConfigInstance.DocumentRoot = documentRootInstance;
  6526. }
  6527. JToken handlerMappingsArray = siteConfigValue["handlerMappings"];
  6528. if (handlerMappingsArray != null && handlerMappingsArray.Type != JTokenType.Null)
  6529. {
  6530. foreach (JToken handlerMappingsValue in ((JArray)handlerMappingsArray))
  6531. {
  6532. WebSiteConfiguration.HandlerMapping handlerMappingInstance = new WebSiteConfiguration.HandlerMapping();
  6533. siteConfigInstance.HandlerMappings.Add(handlerMappingInstance);
  6534. JToken argumentsValue = handlerMappingsValue["arguments"];
  6535. if (argumentsValue != null && argumentsValue.Type != JTokenType.Null)
  6536. {
  6537. string argumentsInstance = ((string)argumentsValue);
  6538. handlerMappingInstance.Arguments = argumentsInstance;
  6539. }
  6540. JToken extensionValue = handlerMappingsValue["extension"];
  6541. if (extensionValue != null && extensionValue.Type != JTokenType.Null)
  6542. {
  6543. string extensionInstance = ((string)extensionValue);
  6544. handlerMappingInstance.Extension = extensionInstance;
  6545. }
  6546. JToken scriptProcessorValue = handlerMappingsValue["scriptProcessor"];
  6547. if (scriptProcessorValue != null && scriptProcessorValue.Type != JTokenType.Null)
  6548. {
  6549. string scriptProcessorInstance = ((string)scriptProcessorValue);
  6550. handlerMappingInstance.ScriptProcessor = scriptProcessorInstance;
  6551. }
  6552. }
  6553. }
  6554. JToken httpLoggingEnabledValue = siteConfigValue["httpLoggingEnabled"];
  6555. if (httpLoggingEnabledValue != null && httpLoggingEnabledValue.Type != JTokenType.Null)
  6556. {
  6557. bool httpLoggingEnabledInstance = ((bool)httpLoggingEnabledValue);
  6558. siteConfigInstance.HttpLoggingEnabled = httpLoggingEnabledInstance;
  6559. }
  6560. JToken logsDirectorySizeLimitValue = siteConfigValue["logsDirectorySizeLimit"];
  6561. if (logsDirectorySizeLimitValue != null && logsDirectorySizeLimitValue.Type != JTokenType.Null)
  6562. {
  6563. int logsDirectorySizeLimitInstance = ((int)logsDirectorySizeLimitValue);
  6564. siteConfigInstance.LogsDirectorySizeLimit = logsDirectorySizeLimitInstance;
  6565. }
  6566. JToken managedPipelineModeValue = siteConfigValue["managedPipelineMode"];
  6567. if (managedPipelineModeValue != null && managedPipelineModeValue.Type != JTokenType.Null)
  6568. {
  6569. ManagedPipelineMode managedPipelineModeInstance = ((ManagedPipelineMode)Enum.Parse(typeof(ManagedPipelineMode), ((string)managedPipelineModeValue), true));
  6570. siteConfigInstance.ManagedPipelineMode = managedPipelineModeInstance;
  6571. }
  6572. JToken metadataSequenceElement2 = ((JToken)siteConfigValue["metadata"]);
  6573. if (metadataSequenceElement2 != null && metadataSequenceElement2.Type != JTokenType.Null)
  6574. {
  6575. foreach (JProperty property5 in metadataSequenceElement2)
  6576. {
  6577. string metadataKey2 = ((string)property5.Name);
  6578. string metadataValue2 = ((string)property5.Value);
  6579. siteConfigInstance.Metadata.Add(metadataKey2, metadataValue2);
  6580. }
  6581. }
  6582. JToken netFrameworkVersionValue = siteConfigValue["netFrameworkVersion"];
  6583. if (netFrameworkVersionValue != null && netFrameworkVersionValue.Type != JTokenType.Null)
  6584. {
  6585. string netFrameworkVersionInstance = ((string)netFrameworkVersionValue);
  6586. siteConfigInstance.NetFrameworkVersion = netFrameworkVersionInstance;
  6587. }
  6588. JToken numberOfWorkersValue = siteConfigValue["numberOfWorkers"];
  6589. if (numberOfWorkersValue != null && numberOfWorkersValue.Type != JTokenType.Null)
  6590. {
  6591. int numberOfWorkersInstance = ((int)numberOfWorkersValue);
  6592. siteConfigInstance.NumberOfWorkers = numberOfWorkersInstance;
  6593. }
  6594. JToken phpVersionValue = siteConfigValue["phpVersion"];
  6595. if (phpVersionValue != null && phpVersionValue.Type != JTokenType.Null)
  6596. {
  6597. string phpVersionInstance = ((string)phpVersionValue);
  6598. siteConfigInstance.PhpVersion = phpVersionInstance;
  6599. }
  6600. JToken pythonVersionValue = siteConfigValue["pythonVersion"];
  6601. if (pythonVersionValue != null && pythonVersionValue.Type != JTokenType.Null)
  6602. {
  6603. string pythonVersionInstance = ((string)pythonVersionValue);
  6604. siteConfigInstance.PythonVersion = pythonVersionInstance;
  6605. }
  6606. JToken publishingPasswordValue = siteConfigValue["publishingPassword"];
  6607. if (publishingPasswordValue != null && publishingPasswordValue.Type != JTokenType.Null)
  6608. {
  6609. string publishingPasswordInstance = ((string)publishingPasswordValue);
  6610. siteConfigInstance.PublishingPassword = publishingPasswordInstance;
  6611. }
  6612. JToken publishingUsernameValue = siteConfigValue["publishingUsername"];
  6613. if (publishingUsernameValue != null && publishingUsernameValue.Type != JTokenType.Null)
  6614. {
  6615. string publishingUsernameInstance = ((string)publishingUsernameValue);
  6616. siteConfigInstance.PublishingUserName = publishingUsernameInstance;
  6617. }
  6618. JToken remoteDebuggingEnabledValue = siteConfigValue["RemoteDebuggingEnabled"];
  6619. if (remoteDebuggingEnabledValue != null && remoteDebuggingEnabledValue.Type != JTokenType.Null)
  6620. {
  6621. bool remoteDebuggingEnabledInstance = ((bool)remoteDebuggingEnabledValue);
  6622. siteConfigInstance.RemoteDebuggingEnabled = remoteDebuggingEnabledInstance;
  6623. }
  6624. JToken remoteDebuggingVersionValue = siteConfigValue["remoteDebuggingVersion"];
  6625. if (remoteDebuggingVersionValue != null && remoteDebuggingVersionValue.Type != JTokenType.Null)
  6626. {
  6627. RemoteDebuggingVersion remoteDebuggingVersionInstance = ((RemoteDebuggingVersion)Enum.Parse(typeof(RemoteDebuggingVersion), ((string)remoteDebuggingVersionValue), true));
  6628. siteConfigInstance.RemoteDebuggingVersion = remoteDebuggingVersionInstance;
  6629. }
  6630. JToken requestTracingEnabledValue = siteConfigValue["requestTracingEnabled"];
  6631. if (requestTracingEnabledValue != null && requestTracingEnabledValue.Type != JTokenType.Null)
  6632. {
  6633. bool requestTracingEnabledInstance = ((bool)requestTracingEnabledValue);
  6634. siteConfigInstance.RequestTracingEnabled = requestTracingEnabledInstance;
  6635. }
  6636. JToken requestTracingExpirationTimeValue = siteConfigValue["requestTracingExpirationTime"];
  6637. if (requestTracingExpirationTimeValue != null && requestTracingExpirationTimeValue.Type != JTokenType.Null)
  6638. {
  6639. DateTime requestTracingExpirationTimeInstance = ((DateTime)requestTracingExpirationTimeValue);
  6640. siteConfigInstance.RequestTracingExpirationTime = requestTracingExpirationTimeInstance;
  6641. }
  6642. JToken scmTypeValue = siteConfigValue["scmType"];
  6643. if (scmTypeValue != null && scmTypeValue.Type != JTokenType.Null)
  6644. {
  6645. string scmTypeInstance = ((string)scmTypeValue);
  6646. siteConfigInstance.ScmType = scmTypeInstance;
  6647. }
  6648. JToken autoSwapSlotNameValue = siteConfigValue["autoSwapSlotName"];
  6649. if (autoSwapSlotNameValue != null && autoSwapSlotNameValue.Type != JTokenType.Null)
  6650. {
  6651. string autoSwapSlotNameInstance = ((string)autoSwapSlotNameValue);
  6652. siteConfigInstance.AutoSwapSlotName = autoSwapSlotNameInstance;
  6653. }
  6654. JToken use32BitWorkerProcessValue = siteConfigValue["use32BitWorkerProcess"];
  6655. if (use32BitWorkerProcessValue != null && use32BitWorkerProcessValue.Type != JTokenType.Null)
  6656. {
  6657. bool use32BitWorkerProcessInstance = ((bool)use32BitWorkerProcessValue);
  6658. siteConfigInstance.Use32BitWorkerProcess = use32BitWorkerProcessInstance;
  6659. }
  6660. JToken webSocketsEnabledValue = siteConfigValue["webSocketsEnabled"];
  6661. if (webSocketsEnabledValue != null && webSocketsEnabledValue.Type != JTokenType.Null)
  6662. {
  6663. bool webSocketsEnabledInstance = ((bool)webSocketsEnabledValue);
  6664. siteConfigInstance.WebSocketsEnabled = webSocketsEnabledInstance;
  6665. }
  6666. JToken limitsValue = siteConfigValue["limits"];
  6667. if (limitsValue != null && limitsValue.Type != JTokenType.Null)
  6668. {
  6669. SiteLimits limitsInstance = new SiteLimits();
  6670. siteConfigInstance.Limits = limitsInstance;
  6671. JToken maxPercentageCpuValue = limitsValue["maxPercentageCpu"];
  6672. if (maxPercentageCpuValue != null && maxPercentageCpuValue.Type != JTokenType.Null)
  6673. {
  6674. double maxPercentageCpuInstance = ((double)maxPercentageCpuValue);
  6675. limitsInstance.MaxPercentageCpu = maxPercentageCpuInstance;
  6676. }
  6677. JToken maxMemoryInMbValue = limitsValue["maxMemoryInMb"];
  6678. if (maxMemoryInMbValue != null && maxMemoryInMbValue.Type != JTokenType.Null)
  6679. {
  6680. long maxMemoryInMbInstance = ((long)maxMemoryInMbValue);
  6681. limitsInstance.MaxMemoryInMb = maxMemoryInMbInstance;
  6682. }
  6683. JToken maxDiskSizeInMbValue = limitsValue["maxDiskSizeInMb"];
  6684. if (maxDiskSizeInMbValue != null && maxDiskSizeInMbValue.Type != JTokenType.Null)
  6685. {
  6686. long maxDiskSizeInMbInstance = ((long)maxDiskSizeInMbValue);
  6687. limitsInstance.MaxDiskSizeInMb = maxDiskSizeInMbInstance;
  6688. }
  6689. }
  6690. }
  6691. JToken stateValue = propertiesValue["state"];
  6692. if (stateValue != null && stateValue.Type != JTokenType.Null)
  6693. {
  6694. WebSiteState stateInstance = ((WebSiteState)Enum.Parse(typeof(WebSiteState), ((string)stateValue), true));
  6695. propertiesInstance.State = stateInstance;
  6696. }
  6697. JToken usageStateValue = propertiesValue["usageState"];
  6698. if (usageStateValue != null && usageStateValue.Type != JTokenType.Null)
  6699. {
  6700. WebSiteUsageState usageStateInstance = ((WebSiteUsageState)Enum.Parse(typeof(WebSiteUsageState), ((string)usageStateValue), true));
  6701. propertiesInstance.UsageState = usageStateInstance;
  6702. }
  6703. JToken webSpaceValue = propertiesValue["webSpace"];
  6704. if (webSpaceValue != null && webSpaceValue.Type != JTokenType.Null)
  6705. {
  6706. string webSpaceInstance = ((string)webSpaceValue);
  6707. propertiesInstance.WebSpace = webSpaceInstance;
  6708. }
  6709. JToken provisioningStateValue = propertiesValue["provisioningState"];
  6710. if (provisioningStateValue != null && provisioningStateValue.Type != JTokenType.Null)
  6711. {
  6712. string provisioningStateInstance = ((string)provisioningStateValue);
  6713. propertiesInstance.ProvisioningState = provisioningStateInstance;
  6714. }
  6715. }
  6716. JToken idValue = valueValue["id"];
  6717. if (idValue != null && idValue.Type != JTokenType.Null)
  6718. {
  6719. string idInstance = ((string)idValue);
  6720. webSiteInstance.Id = idInstance;
  6721. }
  6722. JToken nameValue3 = valueValue["name"];
  6723. if (nameValue3 != null && nameValue3.Type != JTokenType.Null)
  6724. {
  6725. string nameInstance3 = ((string)nameValue3);
  6726. webSiteInstance.Name = nameInstance3;
  6727. }
  6728. JToken locationValue = valueValue["location"];
  6729. if (locationValue != null && locationValue.Type != JTokenType.Null)
  6730. {
  6731. string locationInstance = ((string)locationValue);
  6732. webSiteInstance.Location = locationInstance;
  6733. }
  6734. JToken tagsSequenceElement = ((JToken)valueValue["tags"]);
  6735. if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
  6736. {
  6737. foreach (JProperty property6 in tagsSequenceElement)
  6738. {
  6739. string tagsKey = ((string)property6.Name);
  6740. string tagsValue = ((string)property6.Value);
  6741. webSiteInstance.Tags.Add(tagsKey, tagsValue);
  6742. }
  6743. }
  6744. JToken typeValue2 = valueValue["type"];
  6745. if (typeValue2 != null && typeValue2.Type != JTokenType.Null)
  6746. {
  6747. string typeInstance2 = ((string)typeValue2);
  6748. webSiteInstance.Type = typeInstance2;
  6749. }
  6750. }
  6751. }
  6752. }
  6753. }
  6754. result.StatusCode = statusCode;
  6755. if (httpResponse.Headers.Contains("x-ms-request-id"))
  6756. {
  6757. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  6758. }
  6759. if (shouldTrace)
  6760. {
  6761. TracingAdapter.Exit(invocationId, result);
  6762. }
  6763. return result;
  6764. }
  6765. finally
  6766. {
  6767. if (httpResponse != null)
  6768. {
  6769. httpResponse.Dispose();
  6770. }
  6771. }
  6772. }
  6773. finally
  6774. {
  6775. if (httpRequest != null)
  6776. {
  6777. httpRequest.Dispose();
  6778. }
  6779. }
  6780. }
  6781. /// <summary>
  6782. /// Returns list of all backups which are tracked by the system.
  6783. /// </summary>
  6784. /// <param name='resourceGroupName'>
  6785. /// Required. The name of the resource group.
  6786. /// </param>
  6787. /// <param name='webSiteName'>
  6788. /// Required. The name of the web site.
  6789. /// </param>
  6790. /// <param name='slotName'>
  6791. /// Optional. The name of the slot.
  6792. /// </param>
  6793. /// <param name='cancellationToken'>
  6794. /// Cancellation token.
  6795. /// </param>
  6796. /// <returns>
  6797. /// List of backups for the website.
  6798. /// </returns>
  6799. public async Task<WebSiteGetBackupsResponse> ListBackupsAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
  6800. {
  6801. // Validate
  6802. if (resourceGroupName == null)
  6803. {
  6804. throw new ArgumentNullException("resourceGroupName");
  6805. }
  6806. if (webSiteName == null)
  6807. {
  6808. throw new ArgumentNullException("webSiteName");
  6809. }
  6810. // Tracing
  6811. bool shouldTrace = TracingAdapter.IsEnabled;
  6812. string invocationId = null;
  6813. if (shouldTrace)
  6814. {
  6815. invocationId = TracingAdapter.NextInvocationId.ToString();
  6816. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  6817. tracingParameters.Add("resourceGroupName", resourceGroupName);
  6818. tracingParameters.Add("webSiteName", webSiteName);
  6819. tracingParameters.Add("slotName", slotName);
  6820. TracingAdapter.Enter(invocationId, this, "ListBackupsAsync", tracingParameters);
  6821. }
  6822. // Construct URL
  6823. string url = "";
  6824. url = url + "/subscriptions/";
  6825. if (this.Client.Credentials.SubscriptionId != null)
  6826. {
  6827. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  6828. }
  6829. url = url + "/resourceGroups/";
  6830. url = url + Uri.EscapeDataString(resourceGroupName);
  6831. url = url + "/providers/";
  6832. url = url + "Microsoft.Web";
  6833. url = url + "/";
  6834. url = url + "sites";
  6835. url = url + "/";
  6836. url = url + Uri.EscapeDataString(webSiteName);
  6837. if (slotName != null)
  6838. {
  6839. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  6840. }
  6841. url = url + "/restore";
  6842. List<string> queryParameters = new List<string>();
  6843. queryParameters.Add("api-version=2014-06-01");
  6844. if (queryParameters.Count > 0)
  6845. {
  6846. url = url + "?" + string.Join("&", queryParameters);
  6847. }
  6848. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  6849. // Trim '/' character from the end of baseUrl and beginning of url.
  6850. if (baseUrl[baseUrl.Length - 1] == '/')
  6851. {
  6852. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  6853. }
  6854. if (url[0] == '/')
  6855. {
  6856. url = url.Substring(1);
  6857. }
  6858. url = baseUrl + "/" + url;
  6859. url = url.Replace(" ", "%20");
  6860. // Create HTTP transport objects
  6861. HttpRequestMessage httpRequest = null;
  6862. try
  6863. {
  6864. httpRequest = new HttpRequestMessage();
  6865. httpRequest.Method = HttpMethod.Get;
  6866. httpRequest.RequestUri = new Uri(url);
  6867. // Set Headers
  6868. httpRequest.Headers.Add("x-ms-version", "2014-06-01");
  6869. // Set Credentials
  6870. cancellationToken.ThrowIfCancellationRequested();
  6871. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  6872. // Send Request
  6873. HttpResponseMessage httpResponse = null;
  6874. try
  6875. {
  6876. if (shouldTrace)
  6877. {
  6878. TracingAdapter.SendRequest(invocationId, httpRequest);
  6879. }
  6880. cancellationToken.ThrowIfCancellationRequested();
  6881. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  6882. if (shouldTrace)
  6883. {
  6884. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  6885. }
  6886. HttpStatusCode statusCode = httpResponse.StatusCode;
  6887. if (statusCode != HttpStatusCode.OK)
  6888. {
  6889. cancellationToken.ThrowIfCancellationRequested();
  6890. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  6891. if (shouldTrace)
  6892. {
  6893. TracingAdapter.Error(invocationId, ex);
  6894. }
  6895. throw ex;
  6896. }
  6897. // Create Result
  6898. WebSiteGetBackupsResponse result = null;
  6899. // Deserialize Response
  6900. if (statusCode == HttpStatusCode.OK)
  6901. {
  6902. cancellationToken.ThrowIfCancellationRequested();
  6903. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  6904. result = new WebSiteGetBackupsResponse();
  6905. JToken responseDoc = null;
  6906. if (string.IsNullOrEmpty(responseContent) == false)
  6907. {
  6908. responseDoc = JToken.Parse(responseContent);
  6909. }
  6910. if (responseDoc != null && responseDoc.Type != JTokenType.Null)
  6911. {
  6912. BackupItemsEnvelope backupListInstance = new BackupItemsEnvelope();
  6913. result.BackupList = backupListInstance;
  6914. JToken propertiesArray = responseDoc["properties"];
  6915. if (propertiesArray != null && propertiesArray.Type != JTokenType.Null)
  6916. {
  6917. foreach (JToken propertiesValue in ((JArray)propertiesArray))
  6918. {
  6919. BackupItem backupItemInstance = new BackupItem();
  6920. backupListInstance.Properties.Add(backupItemInstance);
  6921. JToken storageAccountUrlValue = propertiesValue["storageAccountUrl"];
  6922. if (storageAccountUrlValue != null && storageAccountUrlValue.Type != JTokenType.Null)
  6923. {
  6924. string storageAccountUrlInstance = ((string)storageAccountUrlValue);
  6925. backupItemInstance.StorageAccountUrl = storageAccountUrlInstance;
  6926. }
  6927. JToken blobNameValue = propertiesValue["blobName"];
  6928. if (blobNameValue != null && blobNameValue.Type != JTokenType.Null)
  6929. {
  6930. string blobNameInstance = ((string)blobNameValue);
  6931. backupItemInstance.BlobName = blobNameInstance;
  6932. }
  6933. JToken nameValue = propertiesValue["name"];
  6934. if (nameValue != null && nameValue.Type != JTokenType.Null)
  6935. {
  6936. string nameInstance = ((string)nameValue);
  6937. backupItemInstance.Name = nameInstance;
  6938. }
  6939. JToken statusValue = propertiesValue["status"];
  6940. if (statusValue != null && statusValue.Type != JTokenType.Null)
  6941. {
  6942. BackupItemStatus statusInstance = ((BackupItemStatus)Enum.Parse(typeof(BackupItemStatus), ((string)statusValue), true));
  6943. backupItemInstance.Status = statusInstance;
  6944. }
  6945. JToken sizeInBytesValue = propertiesValue["sizeInBytes"];
  6946. if (sizeInBytesValue != null && sizeInBytesValue.Type != JTokenType.Null)
  6947. {
  6948. long sizeInBytesInstance = ((long)sizeInBytesValue);
  6949. backupItemInstance.SizeInBytes = sizeInBytesInstance;
  6950. }
  6951. JToken createdValue = propertiesValue["created"];
  6952. if (createdValue != null && createdValue.Type != JTokenType.Null)
  6953. {
  6954. DateTime createdInstance = ((DateTime)createdValue);
  6955. backupItemInstance.Created = createdInstance;
  6956. }
  6957. JToken logValue = propertiesValue["log"];
  6958. if (logValue != null && logValue.Type != JTokenType.Null)
  6959. {
  6960. string logInstance = ((string)logValue);
  6961. backupItemInstance.Log = logInstance;
  6962. }
  6963. JToken databasesArray = propertiesValue["databases"];
  6964. if (databasesArray != null && databasesArray.Type != JTokenType.Null)
  6965. {
  6966. foreach (JToken databasesValue in ((JArray)databasesArray))
  6967. {
  6968. DatabaseBackupSetting databaseBackupSettingInstance = new DatabaseBackupSetting();
  6969. backupItemInstance.Databases.Add(databaseBackupSettingInstance);
  6970. JToken connectionStringValue = databasesValue["connectionString"];
  6971. if (connectionStringValue != null && connectionStringValue.Type != JTokenType.Null)
  6972. {
  6973. string connectionStringInstance = ((string)connectionStringValue);
  6974. databaseBackupSettingInstance.ConnectionString = connectionStringInstance;
  6975. }
  6976. JToken connectionStringNameValue = databasesValue["connectionStringName"];
  6977. if (connectionStringNameValue != null && connectionStringNameValue.Type != JTokenType.Null)
  6978. {
  6979. string connectionStringNameInstance = ((string)connectionStringNameValue);
  6980. databaseBackupSettingInstance.ConnectionStringName = connectionStringNameInstance;
  6981. }
  6982. JToken databaseTypeValue = databasesValue["databaseType"];
  6983. if (databaseTypeValue != null && databaseTypeValue.Type != JTokenType.Null)
  6984. {
  6985. string databaseTypeInstance = ((string)databaseTypeValue);
  6986. databaseBackupSettingInstance.DatabaseType = databaseTypeInstance;
  6987. }
  6988. JToken nameValue2 = databasesValue["name"];
  6989. if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
  6990. {
  6991. string nameInstance2 = ((string)nameValue2);
  6992. databaseBackupSettingInstance.Name = nameInstance2;
  6993. }
  6994. }
  6995. }
  6996. JToken scheduledValue = propertiesValue["scheduled"];
  6997. if (scheduledValue != null && scheduledValue.Type != JTokenType.Null)
  6998. {
  6999. bool scheduledInstance = ((bool)scheduledValue);
  7000. backupItemInstance.Scheduled = scheduledInstance;
  7001. }
  7002. JToken lastRestoreTimeStampValue = propertiesValue["lastRestoreTimeStamp"];
  7003. if (lastRestoreTimeStampValue != null && lastRestoreTimeStampValue.Type != JTokenType.Null)
  7004. {
  7005. DateTime lastRestoreTimeStampInstance = ((DateTime)lastRestoreTimeStampValue);
  7006. backupItemInstance.LastRestoreTimeStamp = lastRestoreTimeStampInstance;
  7007. }
  7008. JToken finishedTimeStampValue = propertiesValue["finishedTimeStamp"];
  7009. if (finishedTimeStampValue != null && finishedTimeStampValue.Type != JTokenType.Null)
  7010. {
  7011. DateTime finishedTimeStampInstance = ((DateTime)finishedTimeStampValue);
  7012. backupItemInstance.FinishedTimeStamp = finishedTimeStampInstance;
  7013. }
  7014. JToken correlationIdValue = propertiesValue["correlationId"];
  7015. if (correlationIdValue != null && correlationIdValue.Type != JTokenType.Null)
  7016. {
  7017. string correlationIdInstance = ((string)correlationIdValue);
  7018. backupItemInstance.CorrelationId = correlationIdInstance;
  7019. }
  7020. }
  7021. }
  7022. JToken idValue = responseDoc["id"];
  7023. if (idValue != null && idValue.Type != JTokenType.Null)
  7024. {
  7025. string idInstance = ((string)idValue);
  7026. backupListInstance.Id = idInstance;
  7027. }
  7028. JToken nameValue3 = responseDoc["name"];
  7029. if (nameValue3 != null && nameValue3.Type != JTokenType.Null)
  7030. {
  7031. string nameInstance3 = ((string)nameValue3);
  7032. backupListInstance.Name = nameInstance3;
  7033. }
  7034. JToken locationValue = responseDoc["location"];
  7035. if (locationValue != null && locationValue.Type != JTokenType.Null)
  7036. {
  7037. string locationInstance = ((string)locationValue);
  7038. backupListInstance.Location = locationInstance;
  7039. }
  7040. JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
  7041. if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
  7042. {
  7043. foreach (JProperty property in tagsSequenceElement)
  7044. {
  7045. string tagsKey = ((string)property.Name);
  7046. string tagsValue = ((string)property.Value);
  7047. backupListInstance.Tags.Add(tagsKey, tagsValue);
  7048. }
  7049. }
  7050. JToken typeValue = responseDoc["type"];
  7051. if (typeValue != null && typeValue.Type != JTokenType.Null)
  7052. {
  7053. string typeInstance = ((string)typeValue);
  7054. backupListInstance.Type = typeInstance;
  7055. }
  7056. }
  7057. }
  7058. result.StatusCode = statusCode;
  7059. if (httpResponse.Headers.Contains("x-ms-request-id"))
  7060. {
  7061. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  7062. }
  7063. if (shouldTrace)
  7064. {
  7065. TracingAdapter.Exit(invocationId, result);
  7066. }
  7067. return result;
  7068. }
  7069. finally
  7070. {
  7071. if (httpResponse != null)
  7072. {
  7073. httpResponse.Dispose();
  7074. }
  7075. }
  7076. }
  7077. finally
  7078. {
  7079. if (httpRequest != null)
  7080. {
  7081. httpRequest.Dispose();
  7082. }
  7083. }
  7084. }
  7085. /// <summary>
  7086. /// Restart the web site.
  7087. /// </summary>
  7088. /// <param name='resourceGroupName'>
  7089. /// Required. The name of the resource group
  7090. /// </param>
  7091. /// <param name='webSiteName'>
  7092. /// Required. Name of website
  7093. /// </param>
  7094. /// <param name='slotName'>
  7095. /// Optional. The name of the slot.
  7096. /// </param>
  7097. /// <param name='cancellationToken'>
  7098. /// Cancellation token.
  7099. /// </param>
  7100. /// <returns>
  7101. /// A standard service response including an HTTP status code and
  7102. /// request ID.
  7103. /// </returns>
  7104. public async Task<AzureOperationResponse> RestartAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
  7105. {
  7106. // Validate
  7107. if (resourceGroupName == null)
  7108. {
  7109. throw new ArgumentNullException("resourceGroupName");
  7110. }
  7111. if (webSiteName == null)
  7112. {
  7113. throw new ArgumentNullException("webSiteName");
  7114. }
  7115. // Tracing
  7116. bool shouldTrace = TracingAdapter.IsEnabled;
  7117. string invocationId = null;
  7118. if (shouldTrace)
  7119. {
  7120. invocationId = TracingAdapter.NextInvocationId.ToString();
  7121. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  7122. tracingParameters.Add("resourceGroupName", resourceGroupName);
  7123. tracingParameters.Add("webSiteName", webSiteName);
  7124. tracingParameters.Add("slotName", slotName);
  7125. TracingAdapter.Enter(invocationId, this, "RestartAsync", tracingParameters);
  7126. }
  7127. // Construct URL
  7128. string url = "";
  7129. url = url + "/subscriptions/";
  7130. if (this.Client.Credentials.SubscriptionId != null)
  7131. {
  7132. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  7133. }
  7134. url = url + "/resourceGroups/";
  7135. url = url + Uri.EscapeDataString(resourceGroupName);
  7136. url = url + "/providers/";
  7137. url = url + "Microsoft.Web";
  7138. url = url + "/";
  7139. url = url + "sites";
  7140. url = url + "/";
  7141. url = url + Uri.EscapeDataString(webSiteName);
  7142. if (slotName != null)
  7143. {
  7144. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  7145. }
  7146. url = url + "/restart";
  7147. List<string> queryParameters = new List<string>();
  7148. queryParameters.Add("api-version=2014-06-01");
  7149. if (queryParameters.Count > 0)
  7150. {
  7151. url = url + "?" + string.Join("&", queryParameters);
  7152. }
  7153. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  7154. // Trim '/' character from the end of baseUrl and beginning of url.
  7155. if (baseUrl[baseUrl.Length - 1] == '/')
  7156. {
  7157. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  7158. }
  7159. if (url[0] == '/')
  7160. {
  7161. url = url.Substring(1);
  7162. }
  7163. url = baseUrl + "/" + url;
  7164. url = url.Replace(" ", "%20");
  7165. // Create HTTP transport objects
  7166. HttpRequestMessage httpRequest = null;
  7167. try
  7168. {
  7169. httpRequest = new HttpRequestMessage();
  7170. httpRequest.Method = HttpMethod.Post;
  7171. httpRequest.RequestUri = new Uri(url);
  7172. // Set Headers
  7173. // Set Credentials
  7174. cancellationToken.ThrowIfCancellationRequested();
  7175. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  7176. // Send Request
  7177. HttpResponseMessage httpResponse = null;
  7178. try
  7179. {
  7180. if (shouldTrace)
  7181. {
  7182. TracingAdapter.SendRequest(invocationId, httpRequest);
  7183. }
  7184. cancellationToken.ThrowIfCancellationRequested();
  7185. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  7186. if (shouldTrace)
  7187. {
  7188. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  7189. }
  7190. HttpStatusCode statusCode = httpResponse.StatusCode;
  7191. if (statusCode != HttpStatusCode.OK)
  7192. {
  7193. cancellationToken.ThrowIfCancellationRequested();
  7194. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  7195. if (shouldTrace)
  7196. {
  7197. TracingAdapter.Error(invocationId, ex);
  7198. }
  7199. throw ex;
  7200. }
  7201. // Create Result
  7202. AzureOperationResponse result = null;
  7203. // Deserialize Response
  7204. result = new AzureOperationResponse();
  7205. result.StatusCode = statusCode;
  7206. if (httpResponse.Headers.Contains("x-ms-request-id"))
  7207. {
  7208. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  7209. }
  7210. if (shouldTrace)
  7211. {
  7212. TracingAdapter.Exit(invocationId, result);
  7213. }
  7214. return result;
  7215. }
  7216. finally
  7217. {
  7218. if (httpResponse != null)
  7219. {
  7220. httpResponse.Dispose();
  7221. }
  7222. }
  7223. }
  7224. finally
  7225. {
  7226. if (httpRequest != null)
  7227. {
  7228. httpRequest.Dispose();
  7229. }
  7230. }
  7231. }
  7232. /// <summary>
  7233. /// Restores a site to either a new site or existing site (Overwrite
  7234. /// flag has to be set to true for that).
  7235. /// </summary>
  7236. /// <param name='resourceGroupName'>
  7237. /// Required. The name of the web space.
  7238. /// </param>
  7239. /// <param name='webSiteName'>
  7240. /// Required. The name of the web site.
  7241. /// </param>
  7242. /// <param name='slotName'>
  7243. /// Optional. The name of the slot.
  7244. /// </param>
  7245. /// <param name='restoreRequestEnvelope'>
  7246. /// Required. A restore request.
  7247. /// </param>
  7248. /// <param name='cancellationToken'>
  7249. /// Cancellation token.
  7250. /// </param>
  7251. /// <returns>
  7252. /// Restore operation information.
  7253. /// </returns>
  7254. public async Task<WebSiteRestoreResponse> RestoreAsync(string resourceGroupName, string webSiteName, string slotName, RestoreRequestEnvelope restoreRequestEnvelope, CancellationToken cancellationToken)
  7255. {
  7256. // Validate
  7257. if (resourceGroupName == null)
  7258. {
  7259. throw new ArgumentNullException("resourceGroupName");
  7260. }
  7261. if (webSiteName == null)
  7262. {
  7263. throw new ArgumentNullException("webSiteName");
  7264. }
  7265. if (restoreRequestEnvelope == null)
  7266. {
  7267. throw new ArgumentNullException("restoreRequestEnvelope");
  7268. }
  7269. if (restoreRequestEnvelope.Location == null)
  7270. {
  7271. throw new ArgumentNullException("restoreRequestEnvelope.Location");
  7272. }
  7273. // Tracing
  7274. bool shouldTrace = TracingAdapter.IsEnabled;
  7275. string invocationId = null;
  7276. if (shouldTrace)
  7277. {
  7278. invocationId = TracingAdapter.NextInvocationId.ToString();
  7279. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  7280. tracingParameters.Add("resourceGroupName", resourceGroupName);
  7281. tracingParameters.Add("webSiteName", webSiteName);
  7282. tracingParameters.Add("slotName", slotName);
  7283. tracingParameters.Add("restoreRequestEnvelope", restoreRequestEnvelope);
  7284. TracingAdapter.Enter(invocationId, this, "RestoreAsync", tracingParameters);
  7285. }
  7286. // Construct URL
  7287. string url = "";
  7288. url = url + "/subscriptions/";
  7289. if (this.Client.Credentials.SubscriptionId != null)
  7290. {
  7291. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  7292. }
  7293. url = url + "/resourceGroups/";
  7294. url = url + Uri.EscapeDataString(resourceGroupName);
  7295. url = url + "/providers/";
  7296. url = url + "Microsoft.Web";
  7297. url = url + "/";
  7298. url = url + "sites";
  7299. url = url + "/";
  7300. url = url + Uri.EscapeDataString(webSiteName);
  7301. List<string> queryParameters = new List<string>();
  7302. queryParameters.Add("api-version=2014-06-01");
  7303. queryParameters.Add("operation=restore");
  7304. if (queryParameters.Count > 0)
  7305. {
  7306. url = url + "?" + string.Join("&", queryParameters);
  7307. }
  7308. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  7309. // Trim '/' character from the end of baseUrl and beginning of url.
  7310. if (baseUrl[baseUrl.Length - 1] == '/')
  7311. {
  7312. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  7313. }
  7314. if (url[0] == '/')
  7315. {
  7316. url = url.Substring(1);
  7317. }
  7318. url = baseUrl + "/" + url;
  7319. url = url.Replace(" ", "%20");
  7320. // Create HTTP transport objects
  7321. HttpRequestMessage httpRequest = null;
  7322. try
  7323. {
  7324. httpRequest = new HttpRequestMessage();
  7325. httpRequest.Method = HttpMethod.Put;
  7326. httpRequest.RequestUri = new Uri(url);
  7327. // Set Headers
  7328. httpRequest.Headers.Add("x-ms-version", "2014-06-01");
  7329. // Set Credentials
  7330. cancellationToken.ThrowIfCancellationRequested();
  7331. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  7332. // Serialize Request
  7333. string requestContent = null;
  7334. JToken requestDoc = null;
  7335. JObject restoreRequestEnvelopeValue = new JObject();
  7336. requestDoc = restoreRequestEnvelopeValue;
  7337. if (restoreRequestEnvelope.Request != null)
  7338. {
  7339. JObject propertiesValue = new JObject();
  7340. restoreRequestEnvelopeValue["properties"] = propertiesValue;
  7341. propertiesValue["AdjustConnectionStrings"] = restoreRequestEnvelope.Request.AdjustConnectionStrings;
  7342. if (restoreRequestEnvelope.Request.BlobName != null)
  7343. {
  7344. propertiesValue["BlobName"] = restoreRequestEnvelope.Request.BlobName;
  7345. }
  7346. if (restoreRequestEnvelope.Request.Databases != null)
  7347. {
  7348. if (restoreRequestEnvelope.Request.Databases is ILazyCollection == false || ((ILazyCollection)restoreRequestEnvelope.Request.Databases).IsInitialized)
  7349. {
  7350. JArray databasesArray = new JArray();
  7351. foreach (DatabaseBackupSetting databasesItem in restoreRequestEnvelope.Request.Databases)
  7352. {
  7353. JObject databaseBackupSettingValue = new JObject();
  7354. databasesArray.Add(databaseBackupSettingValue);
  7355. if (databasesItem.ConnectionString != null)
  7356. {
  7357. databaseBackupSettingValue["connectionString"] = databasesItem.ConnectionString;
  7358. }
  7359. if (databasesItem.ConnectionStringName != null)
  7360. {
  7361. databaseBackupSettingValue["connectionStringName"] = databasesItem.ConnectionStringName;
  7362. }
  7363. if (databasesItem.DatabaseType != null)
  7364. {
  7365. databaseBackupSettingValue["databaseType"] = databasesItem.DatabaseType;
  7366. }
  7367. if (databasesItem.Name != null)
  7368. {
  7369. databaseBackupSettingValue["name"] = databasesItem.Name;
  7370. }
  7371. }
  7372. propertiesValue["Databases"] = databasesArray;
  7373. }
  7374. }
  7375. propertiesValue["IgnoreConflictingHostNames"] = restoreRequestEnvelope.Request.IgnoreConflictingHostNames;
  7376. propertiesValue["Overwrite"] = restoreRequestEnvelope.Request.Overwrite;
  7377. if (restoreRequestEnvelope.Request.StorageAccountUrl != null)
  7378. {
  7379. propertiesValue["StorageAccountUrl"] = restoreRequestEnvelope.Request.StorageAccountUrl;
  7380. }
  7381. }
  7382. if (restoreRequestEnvelope.Id != null)
  7383. {
  7384. restoreRequestEnvelopeValue["id"] = restoreRequestEnvelope.Id;
  7385. }
  7386. if (restoreRequestEnvelope.Name != null)
  7387. {
  7388. restoreRequestEnvelopeValue["name"] = restoreRequestEnvelope.Name;
  7389. }
  7390. restoreRequestEnvelopeValue["location"] = restoreRequestEnvelope.Location;
  7391. if (restoreRequestEnvelope.Tags != null)
  7392. {
  7393. JObject tagsDictionary = new JObject();
  7394. foreach (KeyValuePair<string, string> pair in restoreRequestEnvelope.Tags)
  7395. {
  7396. string tagsKey = pair.Key;
  7397. string tagsValue = pair.Value;
  7398. tagsDictionary[tagsKey] = tagsValue;
  7399. }
  7400. restoreRequestEnvelopeValue["tags"] = tagsDictionary;
  7401. }
  7402. if (restoreRequestEnvelope.Type != null)
  7403. {
  7404. restoreRequestEnvelopeValue["type"] = restoreRequestEnvelope.Type;
  7405. }
  7406. requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
  7407. httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
  7408. httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
  7409. // Send Request
  7410. HttpResponseMessage httpResponse = null;
  7411. try
  7412. {
  7413. if (shouldTrace)
  7414. {
  7415. TracingAdapter.SendRequest(invocationId, httpRequest);
  7416. }
  7417. cancellationToken.ThrowIfCancellationRequested();
  7418. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  7419. if (shouldTrace)
  7420. {
  7421. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  7422. }
  7423. HttpStatusCode statusCode = httpResponse.StatusCode;
  7424. if (statusCode != HttpStatusCode.OK)
  7425. {
  7426. cancellationToken.ThrowIfCancellationRequested();
  7427. CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  7428. if (shouldTrace)
  7429. {
  7430. TracingAdapter.Error(invocationId, ex);
  7431. }
  7432. throw ex;
  7433. }
  7434. // Create Result
  7435. WebSiteRestoreResponse result = null;
  7436. // Deserialize Response
  7437. if (statusCode == HttpStatusCode.OK)
  7438. {
  7439. cancellationToken.ThrowIfCancellationRequested();
  7440. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  7441. result = new WebSiteRestoreResponse();
  7442. JToken responseDoc = null;
  7443. if (string.IsNullOrEmpty(responseContent) == false)
  7444. {
  7445. responseDoc = JToken.Parse(responseContent);
  7446. }
  7447. JToken restoreResponseValue = responseDoc["RestoreResponse"];
  7448. if (restoreResponseValue != null && restoreResponseValue.Type != JTokenType.Null)
  7449. {
  7450. WebSiteRestoreResponse restoreResponseInstance = new WebSiteRestoreResponse();
  7451. JToken operationIdValue = restoreResponseValue["operationId"];
  7452. if (operationIdValue != null && operationIdValue.Type != JTokenType.Null)
  7453. {
  7454. string operationIdInstance = ((string)operationIdValue);
  7455. restoreResponseInstance.OperationId = operationIdInstance;
  7456. }
  7457. }
  7458. }
  7459. result.StatusCode = statusCode;
  7460. if (httpResponse.Headers.Contains("x-ms-request-id"))
  7461. {
  7462. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  7463. }
  7464. if (shouldTrace)
  7465. {
  7466. TracingAdapter.Exit(invocationId, result);
  7467. }
  7468. return result;
  7469. }
  7470. finally
  7471. {
  7472. if (httpResponse != null)
  7473. {
  7474. httpResponse.Dispose();
  7475. }
  7476. }
  7477. }
  7478. finally
  7479. {
  7480. if (httpRequest != null)
  7481. {
  7482. httpRequest.Dispose();
  7483. }
  7484. }
  7485. }
  7486. /// <summary>
  7487. /// Restart the web site.
  7488. /// </summary>
  7489. /// <param name='resourceGroupName'>
  7490. /// Required. The name of the resource group
  7491. /// </param>
  7492. /// <param name='webSiteName'>
  7493. /// Required. Name of website
  7494. /// </param>
  7495. /// <param name='slotName'>
  7496. /// Optional. The name of the slot of the website
  7497. /// </param>
  7498. /// <param name='cancellationToken'>
  7499. /// Cancellation token.
  7500. /// </param>
  7501. /// <returns>
  7502. /// A standard service response including an HTTP status code and
  7503. /// request ID.
  7504. /// </returns>
  7505. public async Task<AzureOperationResponse> StartAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
  7506. {
  7507. // Validate
  7508. if (resourceGroupName == null)
  7509. {
  7510. throw new ArgumentNullException("resourceGroupName");
  7511. }
  7512. if (webSiteName == null)
  7513. {
  7514. throw new ArgumentNullException("webSiteName");
  7515. }
  7516. // Tracing
  7517. bool shouldTrace = TracingAdapter.IsEnabled;
  7518. string invocationId = null;
  7519. if (shouldTrace)
  7520. {
  7521. invocationId = TracingAdapter.NextInvocationId.ToString();
  7522. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  7523. tracingParameters.Add("resourceGroupName", resourceGroupName);
  7524. tracingParameters.Add("webSiteName", webSiteName);
  7525. tracingParameters.Add("slotName", slotName);
  7526. TracingAdapter.Enter(invocationId, this, "StartAsync", tracingParameters);
  7527. }
  7528. // Construct URL
  7529. string url = "";
  7530. url = url + "/subscriptions/";
  7531. if (this.Client.Credentials.SubscriptionId != null)
  7532. {
  7533. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  7534. }
  7535. url = url + "/resourceGroups/";
  7536. url = url + Uri.EscapeDataString(resourceGroupName);
  7537. url = url + "/providers/";
  7538. url = url + "Microsoft.Web";
  7539. url = url + "/";
  7540. url = url + "sites";
  7541. url = url + "/";
  7542. url = url + Uri.EscapeDataString(webSiteName);
  7543. if (slotName != null)
  7544. {
  7545. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  7546. }
  7547. url = url + "/start";
  7548. List<string> queryParameters = new List<string>();
  7549. queryParameters.Add("api-version=2014-06-01");
  7550. if (queryParameters.Count > 0)
  7551. {
  7552. url = url + "?" + string.Join("&", queryParameters);
  7553. }
  7554. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  7555. // Trim '/' character from the end of baseUrl and beginning of url.
  7556. if (baseUrl[baseUrl.Length - 1] == '/')
  7557. {
  7558. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  7559. }
  7560. if (url[0] == '/')
  7561. {
  7562. url = url.Substring(1);
  7563. }
  7564. url = baseUrl + "/" + url;
  7565. url = url.Replace(" ", "%20");
  7566. // Create HTTP transport objects
  7567. HttpRequestMessage httpRequest = null;
  7568. try
  7569. {
  7570. httpRequest = new HttpRequestMessage();
  7571. httpRequest.Method = HttpMethod.Post;
  7572. httpRequest.RequestUri = new Uri(url);
  7573. // Set Headers
  7574. // Set Credentials
  7575. cancellationToken.ThrowIfCancellationRequested();
  7576. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  7577. // Send Request
  7578. HttpResponseMessage httpResponse = null;
  7579. try
  7580. {
  7581. if (shouldTrace)
  7582. {
  7583. TracingAdapter.SendRequest(invocationId, httpRequest);
  7584. }
  7585. cancellationToken.ThrowIfCancellationRequested();
  7586. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  7587. if (shouldTrace)
  7588. {
  7589. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  7590. }
  7591. HttpStatusCode statusCode = httpResponse.StatusCode;
  7592. if (statusCode != HttpStatusCode.OK)
  7593. {
  7594. cancellationToken.ThrowIfCancellationRequested();
  7595. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  7596. if (shouldTrace)
  7597. {
  7598. TracingAdapter.Error(invocationId, ex);
  7599. }
  7600. throw ex;
  7601. }
  7602. // Create Result
  7603. AzureOperationResponse result = null;
  7604. // Deserialize Response
  7605. result = new AzureOperationResponse();
  7606. result.StatusCode = statusCode;
  7607. if (httpResponse.Headers.Contains("x-ms-request-id"))
  7608. {
  7609. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  7610. }
  7611. if (shouldTrace)
  7612. {
  7613. TracingAdapter.Exit(invocationId, result);
  7614. }
  7615. return result;
  7616. }
  7617. finally
  7618. {
  7619. if (httpResponse != null)
  7620. {
  7621. httpResponse.Dispose();
  7622. }
  7623. }
  7624. }
  7625. finally
  7626. {
  7627. if (httpRequest != null)
  7628. {
  7629. httpRequest.Dispose();
  7630. }
  7631. }
  7632. }
  7633. /// <summary>
  7634. /// Restart the web site.
  7635. /// </summary>
  7636. /// <param name='resourceGroupName'>
  7637. /// Required. The name of the resource group
  7638. /// </param>
  7639. /// <param name='webSiteName'>
  7640. /// Required. Name of website
  7641. /// </param>
  7642. /// <param name='slotName'>
  7643. /// Optional. The name of the slot of the web site
  7644. /// </param>
  7645. /// <param name='cancellationToken'>
  7646. /// Cancellation token.
  7647. /// </param>
  7648. /// <returns>
  7649. /// A standard service response including an HTTP status code and
  7650. /// request ID.
  7651. /// </returns>
  7652. public async Task<AzureOperationResponse> StopAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
  7653. {
  7654. // Validate
  7655. if (resourceGroupName == null)
  7656. {
  7657. throw new ArgumentNullException("resourceGroupName");
  7658. }
  7659. if (webSiteName == null)
  7660. {
  7661. throw new ArgumentNullException("webSiteName");
  7662. }
  7663. // Tracing
  7664. bool shouldTrace = TracingAdapter.IsEnabled;
  7665. string invocationId = null;
  7666. if (shouldTrace)
  7667. {
  7668. invocationId = TracingAdapter.NextInvocationId.ToString();
  7669. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  7670. tracingParameters.Add("resourceGroupName", resourceGroupName);
  7671. tracingParameters.Add("webSiteName", webSiteName);
  7672. tracingParameters.Add("slotName", slotName);
  7673. TracingAdapter.Enter(invocationId, this, "StopAsync", tracingParameters);
  7674. }
  7675. // Construct URL
  7676. string url = "";
  7677. url = url + "/subscriptions/";
  7678. if (this.Client.Credentials.SubscriptionId != null)
  7679. {
  7680. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  7681. }
  7682. url = url + "/resourceGroups/";
  7683. url = url + Uri.EscapeDataString(resourceGroupName);
  7684. url = url + "/providers/";
  7685. url = url + "Microsoft.Web";
  7686. url = url + "/";
  7687. url = url + "sites";
  7688. url = url + "/";
  7689. url = url + Uri.EscapeDataString(webSiteName);
  7690. if (slotName != null)
  7691. {
  7692. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  7693. }
  7694. url = url + "/stop";
  7695. List<string> queryParameters = new List<string>();
  7696. queryParameters.Add("api-version=2014-06-01");
  7697. if (queryParameters.Count > 0)
  7698. {
  7699. url = url + "?" + string.Join("&", queryParameters);
  7700. }
  7701. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  7702. // Trim '/' character from the end of baseUrl and beginning of url.
  7703. if (baseUrl[baseUrl.Length - 1] == '/')
  7704. {
  7705. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  7706. }
  7707. if (url[0] == '/')
  7708. {
  7709. url = url.Substring(1);
  7710. }
  7711. url = baseUrl + "/" + url;
  7712. url = url.Replace(" ", "%20");
  7713. // Create HTTP transport objects
  7714. HttpRequestMessage httpRequest = null;
  7715. try
  7716. {
  7717. httpRequest = new HttpRequestMessage();
  7718. httpRequest.Method = HttpMethod.Post;
  7719. httpRequest.RequestUri = new Uri(url);
  7720. // Set Headers
  7721. // Set Credentials
  7722. cancellationToken.ThrowIfCancellationRequested();
  7723. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  7724. // Send Request
  7725. HttpResponseMessage httpResponse = null;
  7726. try
  7727. {
  7728. if (shouldTrace)
  7729. {
  7730. TracingAdapter.SendRequest(invocationId, httpRequest);
  7731. }
  7732. cancellationToken.ThrowIfCancellationRequested();
  7733. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  7734. if (shouldTrace)
  7735. {
  7736. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  7737. }
  7738. HttpStatusCode statusCode = httpResponse.StatusCode;
  7739. if (statusCode != HttpStatusCode.OK)
  7740. {
  7741. cancellationToken.ThrowIfCancellationRequested();
  7742. CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  7743. if (shouldTrace)
  7744. {
  7745. TracingAdapter.Error(invocationId, ex);
  7746. }
  7747. throw ex;
  7748. }
  7749. // Create Result
  7750. AzureOperationResponse result = null;
  7751. // Deserialize Response
  7752. result = new AzureOperationResponse();
  7753. result.StatusCode = statusCode;
  7754. if (httpResponse.Headers.Contains("x-ms-request-id"))
  7755. {
  7756. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  7757. }
  7758. if (shouldTrace)
  7759. {
  7760. TracingAdapter.Exit(invocationId, result);
  7761. }
  7762. return result;
  7763. }
  7764. finally
  7765. {
  7766. if (httpResponse != null)
  7767. {
  7768. httpResponse.Dispose();
  7769. }
  7770. }
  7771. }
  7772. finally
  7773. {
  7774. if (httpRequest != null)
  7775. {
  7776. httpRequest.Dispose();
  7777. }
  7778. }
  7779. }
  7780. /// <summary>
  7781. /// You can retrieve the application settings for a web site by issuing
  7782. /// an HTTP GET request, or update them by using HTTP PUT with a
  7783. /// request body that contains the settings to be updated. (see
  7784. /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166985.aspx
  7785. /// for more information)
  7786. /// </summary>
  7787. /// <param name='resourceGroupName'>
  7788. /// Required. The name of the resource group
  7789. /// </param>
  7790. /// <param name='webSiteName'>
  7791. /// Required. The name of the web site
  7792. /// </param>
  7793. /// <param name='slotName'>
  7794. /// Optional. The name of the slot of the website
  7795. /// </param>
  7796. /// <param name='parameters'>
  7797. /// Required. The Update Web Site app settings parameters
  7798. /// </param>
  7799. /// <param name='cancellationToken'>
  7800. /// Cancellation token.
  7801. /// </param>
  7802. /// <returns>
  7803. /// List of app settings for the website.
  7804. /// </returns>
  7805. public async Task<WebSiteAppSettingsResult> UpdateAppSettingsAsync(string resourceGroupName, string webSiteName, string slotName, WebSiteNameValueParameters parameters, CancellationToken cancellationToken)
  7806. {
  7807. // Validate
  7808. if (resourceGroupName == null)
  7809. {
  7810. throw new ArgumentNullException("resourceGroupName");
  7811. }
  7812. if (webSiteName == null)
  7813. {
  7814. throw new ArgumentNullException("webSiteName");
  7815. }
  7816. if (parameters == null)
  7817. {
  7818. throw new ArgumentNullException("parameters");
  7819. }
  7820. if (parameters.Location == null)
  7821. {
  7822. throw new ArgumentNullException("parameters.Location");
  7823. }
  7824. if (parameters.Properties == null)
  7825. {
  7826. throw new ArgumentNullException("parameters.Properties");
  7827. }
  7828. // Tracing
  7829. bool shouldTrace = TracingAdapter.IsEnabled;
  7830. string invocationId = null;
  7831. if (shouldTrace)
  7832. {
  7833. invocationId = TracingAdapter.NextInvocationId.ToString();
  7834. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  7835. tracingParameters.Add("resourceGroupName", resourceGroupName);
  7836. tracingParameters.Add("webSiteName", webSiteName);
  7837. tracingParameters.Add("slotName", slotName);
  7838. tracingParameters.Add("parameters", parameters);
  7839. TracingAdapter.Enter(invocationId, this, "UpdateAppSettingsAsync", tracingParameters);
  7840. }
  7841. // Construct URL
  7842. string url = "";
  7843. url = url + "/subscriptions/";
  7844. if (this.Client.Credentials.SubscriptionId != null)
  7845. {
  7846. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  7847. }
  7848. url = url + "/resourceGroups/";
  7849. url = url + Uri.EscapeDataString(resourceGroupName);
  7850. url = url + "/providers/";
  7851. url = url + "Microsoft.Web";
  7852. url = url + "/";
  7853. url = url + "sites";
  7854. url = url + "/";
  7855. url = url + Uri.EscapeDataString(webSiteName);
  7856. if (slotName != null)
  7857. {
  7858. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  7859. }
  7860. url = url + "/config/appsettings";
  7861. List<string> queryParameters = new List<string>();
  7862. queryParameters.Add("api-version=2014-06-01");
  7863. if (queryParameters.Count > 0)
  7864. {
  7865. url = url + "?" + string.Join("&", queryParameters);
  7866. }
  7867. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  7868. // Trim '/' character from the end of baseUrl and beginning of url.
  7869. if (baseUrl[baseUrl.Length - 1] == '/')
  7870. {
  7871. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  7872. }
  7873. if (url[0] == '/')
  7874. {
  7875. url = url.Substring(1);
  7876. }
  7877. url = baseUrl + "/" + url;
  7878. url = url.Replace(" ", "%20");
  7879. // Create HTTP transport objects
  7880. HttpRequestMessage httpRequest = null;
  7881. try
  7882. {
  7883. httpRequest = new HttpRequestMessage();
  7884. httpRequest.Method = HttpMethod.Put;
  7885. httpRequest.RequestUri = new Uri(url);
  7886. // Set Headers
  7887. // Set Credentials
  7888. cancellationToken.ThrowIfCancellationRequested();
  7889. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  7890. // Serialize Request
  7891. string requestContent = null;
  7892. JToken requestDoc = null;
  7893. JObject webSiteNameValueParametersValue = new JObject();
  7894. requestDoc = webSiteNameValueParametersValue;
  7895. if (parameters.Properties != null)
  7896. {
  7897. if (parameters.Properties is ILazyCollection == false || ((ILazyCollection)parameters.Properties).IsInitialized)
  7898. {
  7899. JArray propertiesArray = new JArray();
  7900. foreach (NameValuePair propertiesItem in parameters.Properties)
  7901. {
  7902. JObject nameValuePairValue = new JObject();
  7903. propertiesArray.Add(nameValuePairValue);
  7904. if (propertiesItem.Name != null)
  7905. {
  7906. nameValuePairValue["name"] = propertiesItem.Name;
  7907. }
  7908. if (propertiesItem.Value != null)
  7909. {
  7910. nameValuePairValue["value"] = propertiesItem.Value;
  7911. }
  7912. }
  7913. webSiteNameValueParametersValue["properties"] = propertiesArray;
  7914. }
  7915. }
  7916. if (parameters.Id != null)
  7917. {
  7918. webSiteNameValueParametersValue["id"] = parameters.Id;
  7919. }
  7920. if (parameters.Name != null)
  7921. {
  7922. webSiteNameValueParametersValue["name"] = parameters.Name;
  7923. }
  7924. webSiteNameValueParametersValue["location"] = parameters.Location;
  7925. if (parameters.Tags != null)
  7926. {
  7927. JObject tagsDictionary = new JObject();
  7928. foreach (KeyValuePair<string, string> pair in parameters.Tags)
  7929. {
  7930. string tagsKey = pair.Key;
  7931. string tagsValue = pair.Value;
  7932. tagsDictionary[tagsKey] = tagsValue;
  7933. }
  7934. webSiteNameValueParametersValue["tags"] = tagsDictionary;
  7935. }
  7936. if (parameters.Type != null)
  7937. {
  7938. webSiteNameValueParametersValue["type"] = parameters.Type;
  7939. }
  7940. requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
  7941. httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
  7942. httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
  7943. // Send Request
  7944. HttpResponseMessage httpResponse = null;
  7945. try
  7946. {
  7947. if (shouldTrace)
  7948. {
  7949. TracingAdapter.SendRequest(invocationId, httpRequest);
  7950. }
  7951. cancellationToken.ThrowIfCancellationRequested();
  7952. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  7953. if (shouldTrace)
  7954. {
  7955. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  7956. }
  7957. HttpStatusCode statusCode = httpResponse.StatusCode;
  7958. if (statusCode != HttpStatusCode.OK)
  7959. {
  7960. cancellationToken.ThrowIfCancellationRequested();
  7961. CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  7962. if (shouldTrace)
  7963. {
  7964. TracingAdapter.Error(invocationId, ex);
  7965. }
  7966. throw ex;
  7967. }
  7968. // Create Result
  7969. WebSiteAppSettingsResult result = null;
  7970. // Deserialize Response
  7971. if (statusCode == HttpStatusCode.OK)
  7972. {
  7973. cancellationToken.ThrowIfCancellationRequested();
  7974. string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
  7975. result = new WebSiteAppSettingsResult();
  7976. JToken responseDoc = null;
  7977. if (string.IsNullOrEmpty(responseContent) == false)
  7978. {
  7979. responseDoc = JToken.Parse(responseContent);
  7980. }
  7981. if (responseDoc != null && responseDoc.Type != JTokenType.Null)
  7982. {
  7983. WebSiteAppSettingsEnvelope resourceInstance = new WebSiteAppSettingsEnvelope();
  7984. result.Resource = resourceInstance;
  7985. JToken propertiesArray2 = responseDoc["properties"];
  7986. if (propertiesArray2 != null && propertiesArray2.Type != JTokenType.Null)
  7987. {
  7988. foreach (JToken propertiesValue in ((JArray)propertiesArray2))
  7989. {
  7990. NameValuePair nameValuePairInstance = new NameValuePair();
  7991. resourceInstance.Properties.Add(nameValuePairInstance);
  7992. JToken nameValue = propertiesValue["name"];
  7993. if (nameValue != null && nameValue.Type != JTokenType.Null)
  7994. {
  7995. string nameInstance = ((string)nameValue);
  7996. nameValuePairInstance.Name = nameInstance;
  7997. }
  7998. JToken valueValue = propertiesValue["value"];
  7999. if (valueValue != null && valueValue.Type != JTokenType.Null)
  8000. {
  8001. string valueInstance = ((string)valueValue);
  8002. nameValuePairInstance.Value = valueInstance;
  8003. }
  8004. }
  8005. }
  8006. JToken idValue = responseDoc["id"];
  8007. if (idValue != null && idValue.Type != JTokenType.Null)
  8008. {
  8009. string idInstance = ((string)idValue);
  8010. resourceInstance.Id = idInstance;
  8011. }
  8012. JToken nameValue2 = responseDoc["name"];
  8013. if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
  8014. {
  8015. string nameInstance2 = ((string)nameValue2);
  8016. resourceInstance.Name = nameInstance2;
  8017. }
  8018. JToken locationValue = responseDoc["location"];
  8019. if (locationValue != null && locationValue.Type != JTokenType.Null)
  8020. {
  8021. string locationInstance = ((string)locationValue);
  8022. resourceInstance.Location = locationInstance;
  8023. }
  8024. JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
  8025. if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
  8026. {
  8027. foreach (JProperty property in tagsSequenceElement)
  8028. {
  8029. string tagsKey2 = ((string)property.Name);
  8030. string tagsValue2 = ((string)property.Value);
  8031. resourceInstance.Tags.Add(tagsKey2, tagsValue2);
  8032. }
  8033. }
  8034. JToken typeValue = responseDoc["type"];
  8035. if (typeValue != null && typeValue.Type != JTokenType.Null)
  8036. {
  8037. string typeInstance = ((string)typeValue);
  8038. resourceInstance.Type = typeInstance;
  8039. }
  8040. }
  8041. }
  8042. result.StatusCode = statusCode;
  8043. if (httpResponse.Headers.Contains("x-ms-request-id"))
  8044. {
  8045. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  8046. }
  8047. if (shouldTrace)
  8048. {
  8049. TracingAdapter.Exit(invocationId, result);
  8050. }
  8051. return result;
  8052. }
  8053. finally
  8054. {
  8055. if (httpResponse != null)
  8056. {
  8057. httpResponse.Dispose();
  8058. }
  8059. }
  8060. }
  8061. finally
  8062. {
  8063. if (httpRequest != null)
  8064. {
  8065. httpRequest.Dispose();
  8066. }
  8067. }
  8068. }
  8069. /// <summary>
  8070. /// Updates a backup schedule for a site.
  8071. /// </summary>
  8072. /// <param name='resourceGroupName'>
  8073. /// Required. The name of the web space.
  8074. /// </param>
  8075. /// <param name='webSiteName'>
  8076. /// Required. The name of the web site.
  8077. /// </param>
  8078. /// <param name='slotName'>
  8079. /// Optional. The name of the slot.
  8080. /// </param>
  8081. /// <param name='backupRequestEnvelope'>
  8082. /// Required. A backup schedule specification.
  8083. /// </param>
  8084. /// <param name='cancellationToken'>
  8085. /// Cancellation token.
  8086. /// </param>
  8087. /// <returns>
  8088. /// A standard service response including an HTTP status code and
  8089. /// request ID.
  8090. /// </returns>
  8091. public async Task<AzureOperationResponse> UpdateBackupConfigurationAsync(string resourceGroupName, string webSiteName, string slotName, BackupRequestEnvelope backupRequestEnvelope, CancellationToken cancellationToken)
  8092. {
  8093. // Validate
  8094. if (resourceGroupName == null)
  8095. {
  8096. throw new ArgumentNullException("resourceGroupName");
  8097. }
  8098. if (webSiteName == null)
  8099. {
  8100. throw new ArgumentNullException("webSiteName");
  8101. }
  8102. if (backupRequestEnvelope == null)
  8103. {
  8104. throw new ArgumentNullException("backupRequestEnvelope");
  8105. }
  8106. if (backupRequestEnvelope.Location == null)
  8107. {
  8108. throw new ArgumentNullException("backupRequestEnvelope.Location");
  8109. }
  8110. // Tracing
  8111. bool shouldTrace = TracingAdapter.IsEnabled;
  8112. string invocationId = null;
  8113. if (shouldTrace)
  8114. {
  8115. invocationId = TracingAdapter.NextInvocationId.ToString();
  8116. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  8117. tracingParameters.Add("resourceGroupName", resourceGroupName);
  8118. tracingParameters.Add("webSiteName", webSiteName);
  8119. tracingParameters.Add("slotName", slotName);
  8120. tracingParameters.Add("backupRequestEnvelope", backupRequestEnvelope);
  8121. TracingAdapter.Enter(invocationId, this, "UpdateBackupConfigurationAsync", tracingParameters);
  8122. }
  8123. // Construct URL
  8124. string url = "";
  8125. url = url + "/subscriptions/";
  8126. if (this.Client.Credentials.SubscriptionId != null)
  8127. {
  8128. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  8129. }
  8130. url = url + "/resourceGroups/";
  8131. url = url + Uri.EscapeDataString(resourceGroupName);
  8132. url = url + "/providers/";
  8133. url = url + "Microsoft.Web";
  8134. url = url + "/";
  8135. url = url + "sites";
  8136. url = url + "/";
  8137. url = url + Uri.EscapeDataString(webSiteName);
  8138. if (slotName != null)
  8139. {
  8140. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  8141. }
  8142. url = url + "/backup/config";
  8143. List<string> queryParameters = new List<string>();
  8144. queryParameters.Add("api-version=2014-06-01");
  8145. if (queryParameters.Count > 0)
  8146. {
  8147. url = url + "?" + string.Join("&", queryParameters);
  8148. }
  8149. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  8150. // Trim '/' character from the end of baseUrl and beginning of url.
  8151. if (baseUrl[baseUrl.Length - 1] == '/')
  8152. {
  8153. baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
  8154. }
  8155. if (url[0] == '/')
  8156. {
  8157. url = url.Substring(1);
  8158. }
  8159. url = baseUrl + "/" + url;
  8160. url = url.Replace(" ", "%20");
  8161. // Create HTTP transport objects
  8162. HttpRequestMessage httpRequest = null;
  8163. try
  8164. {
  8165. httpRequest = new HttpRequestMessage();
  8166. httpRequest.Method = HttpMethod.Put;
  8167. httpRequest.RequestUri = new Uri(url);
  8168. // Set Headers
  8169. httpRequest.Headers.Add("x-ms-version", "2014-06-01");
  8170. // Set Credentials
  8171. cancellationToken.ThrowIfCancellationRequested();
  8172. await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  8173. // Serialize Request
  8174. string requestContent = null;
  8175. JToken requestDoc = null;
  8176. JObject backupRequestEnvelopeValue = new JObject();
  8177. requestDoc = backupRequestEnvelopeValue;
  8178. if (backupRequestEnvelope.Request != null)
  8179. {
  8180. JObject propertiesValue = new JObject();
  8181. backupRequestEnvelopeValue["properties"] = propertiesValue;
  8182. if (backupRequestEnvelope.Request.BackupSchedule != null)
  8183. {
  8184. JObject backupScheduleValue = new JObject();
  8185. propertiesValue["backupSchedule"] = backupScheduleValue;
  8186. backupScheduleValue["frequencyInterval"] = backupRequestEnvelope.Request.BackupSchedule.FrequencyInterval;
  8187. backupScheduleValue["frequencyUnit"] = backupRequestEnvelope.Request.BackupSchedule.FrequencyUnit.ToString();
  8188. backupScheduleValue["keepAtLeastOneBackup"] = backupRequestEnvelope.Request.BackupSchedule.KeepAtLeastOneBackup;
  8189. if (backupRequestEnvelope.Request.BackupSchedule.LastExecutionTime != null)
  8190. {
  8191. backupScheduleValue["lastExecutionTime"] = backupRequestEnvelope.Request.BackupSchedule.LastExecutionTime.Value;
  8192. }
  8193. backupScheduleValue["retentionPeriodInDays"] = backupRequestEnvelope.Request.BackupSchedule.RetentionPeriodInDays;
  8194. if (backupRequestEnvelope.Request.BackupSchedule.StartTime != null)
  8195. {
  8196. backupScheduleValue["startTime"] = backupRequestEnvelope.Request.BackupSchedule.StartTime.Value;
  8197. }
  8198. }
  8199. if (backupRequestEnvelope.Request.Databases != null)
  8200. {
  8201. if (backupRequestEnvelope.Request.Databases is ILazyCollection == false || ((ILazyCollection)backupRequestEnvelope.Request.Databases).IsInitialized)
  8202. {
  8203. JArray databasesArray = new JArray();
  8204. foreach (DatabaseBackupSetting databasesItem in backupRequestEnvelope.Request.Databases)
  8205. {
  8206. JObject databaseBackupSettingValue = new JObject();
  8207. databasesArray.Add(databaseBackupSettingValue);
  8208. if (databasesItem.ConnectionString != null)
  8209. {
  8210. databaseBackupSettingValue["connectionString"] = databasesItem.ConnectionString;
  8211. }
  8212. if (databasesItem.ConnectionStringName != null)
  8213. {
  8214. databaseBackupSettingValue["connectionStringName"] = databasesItem.ConnectionStringName;
  8215. }
  8216. if (databasesItem.DatabaseType != null)
  8217. {
  8218. databaseBackupSettingValue["databaseType"] = databasesItem.DatabaseType;
  8219. }
  8220. if (databasesItem.Name != null)
  8221. {
  8222. databaseBackupSettingValue["name"] = databasesItem.Name;
  8223. }
  8224. }
  8225. propertiesValue["databases"] = databasesArray;
  8226. }
  8227. }
  8228. if (backupRequestEnvelope.Request.Enabled != null)
  8229. {
  8230. propertiesValue["enabled"] = backupRequestEnvelope.Request.Enabled.Value;
  8231. }
  8232. if (backupRequestEnvelope.Request.Name != null)
  8233. {
  8234. propertiesValue["name"] = backupRequestEnvelope.Request.Name;
  8235. }
  8236. if (backupRequestEnvelope.Request.StorageAccountUrl != null)
  8237. {
  8238. propertiesValue["storageAccountUrl"] = backupRequestEnvelope.Request.StorageAccountUrl;
  8239. }
  8240. }
  8241. if (backupRequestEnvelope.Id != null)
  8242. {
  8243. backupRequestEnvelopeValue["id"] = backupRequestEnvelope.Id;
  8244. }
  8245. if (backupRequestEnvelope.Name != null)
  8246. {
  8247. backupRequestEnvelopeValue["name"] = backupRequestEnvelope.Name;
  8248. }
  8249. backupRequestEnvelopeValue["location"] = backupRequestEnvelope.Location;
  8250. if (backupRequestEnvelope.Tags != null)
  8251. {
  8252. JObject tagsDictionary = new JObject();
  8253. foreach (KeyValuePair<string, string> pair in backupRequestEnvelope.Tags)
  8254. {
  8255. string tagsKey = pair.Key;
  8256. string tagsValue = pair.Value;
  8257. tagsDictionary[tagsKey] = tagsValue;
  8258. }
  8259. backupRequestEnvelopeValue["tags"] = tagsDictionary;
  8260. }
  8261. if (backupRequestEnvelope.Type != null)
  8262. {
  8263. backupRequestEnvelopeValue["type"] = backupRequestEnvelope.Type;
  8264. }
  8265. requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
  8266. httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
  8267. httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
  8268. // Send Request
  8269. HttpResponseMessage httpResponse = null;
  8270. try
  8271. {
  8272. if (shouldTrace)
  8273. {
  8274. TracingAdapter.SendRequest(invocationId, httpRequest);
  8275. }
  8276. cancellationToken.ThrowIfCancellationRequested();
  8277. httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
  8278. if (shouldTrace)
  8279. {
  8280. TracingAdapter.ReceiveResponse(invocationId, httpResponse);
  8281. }
  8282. HttpStatusCode statusCode = httpResponse.StatusCode;
  8283. if (statusCode != HttpStatusCode.OK)
  8284. {
  8285. cancellationToken.ThrowIfCancellationRequested();
  8286. CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
  8287. if (shouldTrace)
  8288. {
  8289. TracingAdapter.Error(invocationId, ex);
  8290. }
  8291. throw ex;
  8292. }
  8293. // Create Result
  8294. AzureOperationResponse result = null;
  8295. // Deserialize Response
  8296. result = new AzureOperationResponse();
  8297. result.StatusCode = statusCode;
  8298. if (httpResponse.Headers.Contains("x-ms-request-id"))
  8299. {
  8300. result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
  8301. }
  8302. if (shouldTrace)
  8303. {
  8304. TracingAdapter.Exit(invocationId, result);
  8305. }
  8306. return result;
  8307. }
  8308. finally
  8309. {
  8310. if (httpResponse != null)
  8311. {
  8312. httpResponse.Dispose();
  8313. }
  8314. }
  8315. }
  8316. finally
  8317. {
  8318. if (httpRequest != null)
  8319. {
  8320. httpRequest.Dispose();
  8321. }
  8322. }
  8323. }
  8324. /// <summary>
  8325. /// You can retrieve the config settings for a web site by issuing an
  8326. /// HTTP GET request, or update them by using HTTP PUT with a request
  8327. /// body that contains the settings to be updated. (see
  8328. /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166985.aspx
  8329. /// for more information)
  8330. /// </summary>
  8331. /// <param name='resourceGroupName'>
  8332. /// Required. The name of the resource group.
  8333. /// </param>
  8334. /// <param name='webSiteName'>
  8335. /// Required. The name of the web site.
  8336. /// </param>
  8337. /// <param name='slotName'>
  8338. /// Optional. The name of the slot.
  8339. /// </param>
  8340. /// <param name='parameters'>
  8341. /// Required. The Update Web Site Configuration parameters.
  8342. /// </param>
  8343. /// <param name='cancellationToken'>
  8344. /// Cancellation token.
  8345. /// </param>
  8346. /// <returns>
  8347. /// A standard service response including an HTTP status code and
  8348. /// request ID.
  8349. /// </returns>
  8350. public async Task<AzureOperationResponse> UpdateConfigurationAsync(string resourceGroupName, string webSiteName, string slotName, WebSiteUpdateConfigurationParameters parameters, CancellationToken cancellationToken)
  8351. {
  8352. // Validate
  8353. if (resourceGroupName == null)
  8354. {
  8355. throw new ArgumentNullException("resourceGroupName");
  8356. }
  8357. if (webSiteName == null)
  8358. {
  8359. throw new ArgumentNullException("webSiteName");
  8360. }
  8361. if (parameters == null)
  8362. {
  8363. throw new ArgumentNullException("parameters");
  8364. }
  8365. if (parameters.Location == null)
  8366. {
  8367. throw new ArgumentNullException("parameters.Location");
  8368. }
  8369. if (parameters.Properties == null)
  8370. {
  8371. throw new ArgumentNullException("parameters.Properties");
  8372. }
  8373. // Tracing
  8374. bool shouldTrace = TracingAdapter.IsEnabled;
  8375. string invocationId = null;
  8376. if (shouldTrace)
  8377. {
  8378. invocationId = TracingAdapter.NextInvocationId.ToString();
  8379. Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
  8380. tracingParameters.Add("resourceGroupName", resourceGroupName);
  8381. tracingParameters.Add("webSiteName", webSiteName);
  8382. tracingParameters.Add("slotName", slotName);
  8383. tracingParameters.Add("parameters", parameters);
  8384. TracingAdapter.Enter(invocationId, this, "UpdateConfigurationAsync", tracingParameters);
  8385. }
  8386. // Construct URL
  8387. string url = "";
  8388. url = url + "/subscriptions/";
  8389. if (this.Client.Credentials.SubscriptionId != null)
  8390. {
  8391. url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
  8392. }
  8393. url = url + "/resourceGroups/";
  8394. url = url + Uri.EscapeDataString(resourceGroupName);
  8395. url = url + "/providers/";
  8396. url = url + "Microsoft.Web";
  8397. url = url + "/";
  8398. url = url + "sites";
  8399. url = url + "/";
  8400. url = url + Uri.EscapeDataString(webSiteName);
  8401. if (slotName != null)
  8402. {
  8403. url = url + "/slots/" + Uri.EscapeDataString(slotName);
  8404. }
  8405. url = url + "/config/web";
  8406. List<string> queryParameters = new List<string>();
  8407. queryParameters.Add("api-version=2014-06-01");
  8408. if (queryParameters.Count > 0)
  8409. {
  8410. url = url + "?" + string.Join("&", queryParameters);
  8411. }
  8412. string baseUrl = this.Client.BaseUri.AbsoluteUri;
  8413. // Trim '/' character fro