/src/WebSiteManagement2/Generated/WebSiteOperations.cs
C# | 9288 lines | 7390 code | 875 blank | 1023 comment | 2881 complexity | 19364238039f91d3ea332dc8a6ac8162 MD5 | raw file
- //
- // Copyright (c) Microsoft and contributors. All rights reserved.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- //
- // See the License for the specific language governing permissions and
- // limitations under the License.
- //
- // Warning: This code was generated by a tool.
- //
- // Changes to this file may cause incorrect behavior and will be lost if the
- // code is regenerated.
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Net.Http.Headers;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Xml.Linq;
- using Hyak.Common;
- using Hyak.Common.Internals;
- using Microsoft.Azure;
- using Microsoft.Azure.Management.WebSites;
- using Microsoft.Azure.Management.WebSites.Models;
- using Newtonsoft.Json.Linq;
- namespace Microsoft.Azure.Management.WebSites
- {
- /// <summary>
- /// Operations for managing the web sites in a web space.
- /// </summary>
- internal partial class WebSiteOperations : IServiceOperations<WebSiteManagementClient>, IWebSiteOperations
- {
- /// <summary>
- /// Initializes a new instance of the WebSiteOperations class.
- /// </summary>
- /// <param name='client'>
- /// Reference to the service client.
- /// </param>
- internal WebSiteOperations(WebSiteManagementClient client)
- {
- this._client = client;
- }
-
- private WebSiteManagementClient _client;
-
- /// <summary>
- /// Gets a reference to the
- /// Microsoft.Azure.Management.WebSites.WebSiteManagementClient.
- /// </summary>
- public WebSiteManagementClient Client
- {
- get { return this._client; }
- }
-
- /// <summary>
- /// Backups a site on-demand.
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the web space.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='backupRequestEnvelope'>
- /// Required. A backup specification.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// The backup record created based on the backup request.
- /// </returns>
- public async Task<WebSiteBackupResponse> BackupAsync(string resourceGroupName, string webSiteName, string slotName, BackupRequestEnvelope backupRequestEnvelope, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
- if (backupRequestEnvelope == null)
- {
- throw new ArgumentNullException("backupRequestEnvelope");
- }
- if (backupRequestEnvelope.Location == null)
- {
- throw new ArgumentNullException("backupRequestEnvelope.Location");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- tracingParameters.Add("backupRequestEnvelope", backupRequestEnvelope);
- TracingAdapter.Enter(invocationId, this, "BackupAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/backup";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Put;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
- httpRequest.Headers.Add("x-ms-version", "2014-06-01");
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Serialize Request
- string requestContent = null;
- JToken requestDoc = null;
-
- JObject backupRequestEnvelopeValue = new JObject();
- requestDoc = backupRequestEnvelopeValue;
-
- if (backupRequestEnvelope.Request != null)
- {
- JObject propertiesValue = new JObject();
- backupRequestEnvelopeValue["properties"] = propertiesValue;
-
- if (backupRequestEnvelope.Request.BackupSchedule != null)
- {
- JObject backupScheduleValue = new JObject();
- propertiesValue["backupSchedule"] = backupScheduleValue;
-
- backupScheduleValue["frequencyInterval"] = backupRequestEnvelope.Request.BackupSchedule.FrequencyInterval;
-
- backupScheduleValue["frequencyUnit"] = backupRequestEnvelope.Request.BackupSchedule.FrequencyUnit.ToString();
-
- backupScheduleValue["keepAtLeastOneBackup"] = backupRequestEnvelope.Request.BackupSchedule.KeepAtLeastOneBackup;
-
- if (backupRequestEnvelope.Request.BackupSchedule.LastExecutionTime != null)
- {
- backupScheduleValue["lastExecutionTime"] = backupRequestEnvelope.Request.BackupSchedule.LastExecutionTime.Value;
- }
-
- backupScheduleValue["retentionPeriodInDays"] = backupRequestEnvelope.Request.BackupSchedule.RetentionPeriodInDays;
-
- if (backupRequestEnvelope.Request.BackupSchedule.StartTime != null)
- {
- backupScheduleValue["startTime"] = backupRequestEnvelope.Request.BackupSchedule.StartTime.Value;
- }
- }
-
- if (backupRequestEnvelope.Request.Databases != null)
- {
- if (backupRequestEnvelope.Request.Databases is ILazyCollection == false || ((ILazyCollection)backupRequestEnvelope.Request.Databases).IsInitialized)
- {
- JArray databasesArray = new JArray();
- foreach (DatabaseBackupSetting databasesItem in backupRequestEnvelope.Request.Databases)
- {
- JObject databaseBackupSettingValue = new JObject();
- databasesArray.Add(databaseBackupSettingValue);
-
- if (databasesItem.ConnectionString != null)
- {
- databaseBackupSettingValue["connectionString"] = databasesItem.ConnectionString;
- }
-
- if (databasesItem.ConnectionStringName != null)
- {
- databaseBackupSettingValue["connectionStringName"] = databasesItem.ConnectionStringName;
- }
-
- if (databasesItem.DatabaseType != null)
- {
- databaseBackupSettingValue["databaseType"] = databasesItem.DatabaseType;
- }
-
- if (databasesItem.Name != null)
- {
- databaseBackupSettingValue["name"] = databasesItem.Name;
- }
- }
- propertiesValue["databases"] = databasesArray;
- }
- }
-
- if (backupRequestEnvelope.Request.Enabled != null)
- {
- propertiesValue["enabled"] = backupRequestEnvelope.Request.Enabled.Value;
- }
-
- if (backupRequestEnvelope.Request.Name != null)
- {
- propertiesValue["name"] = backupRequestEnvelope.Request.Name;
- }
-
- if (backupRequestEnvelope.Request.StorageAccountUrl != null)
- {
- propertiesValue["storageAccountUrl"] = backupRequestEnvelope.Request.StorageAccountUrl;
- }
- }
-
- if (backupRequestEnvelope.Id != null)
- {
- backupRequestEnvelopeValue["id"] = backupRequestEnvelope.Id;
- }
-
- if (backupRequestEnvelope.Name != null)
- {
- backupRequestEnvelopeValue["name"] = backupRequestEnvelope.Name;
- }
-
- backupRequestEnvelopeValue["location"] = backupRequestEnvelope.Location;
-
- if (backupRequestEnvelope.Tags != null)
- {
- JObject tagsDictionary = new JObject();
- foreach (KeyValuePair<string, string> pair in backupRequestEnvelope.Tags)
- {
- string tagsKey = pair.Key;
- string tagsValue = pair.Value;
- tagsDictionary[tagsKey] = tagsValue;
- }
- backupRequestEnvelopeValue["tags"] = tagsDictionary;
- }
-
- if (backupRequestEnvelope.Type != null)
- {
- backupRequestEnvelopeValue["type"] = backupRequestEnvelope.Type;
- }
-
- requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
- httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
- httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteBackupResponse result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteBackupResponse();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- if (responseDoc != null && responseDoc.Type != JTokenType.Null)
- {
- BackupItemEnvelope backupItemInstance = new BackupItemEnvelope();
- result.BackupItem = backupItemInstance;
-
- JToken propertiesValue2 = responseDoc["properties"];
- if (propertiesValue2 != null && propertiesValue2.Type != JTokenType.Null)
- {
- BackupItem propertiesInstance = new BackupItem();
- backupItemInstance.Properties = propertiesInstance;
-
- JToken storageAccountUrlValue = propertiesValue2["storageAccountUrl"];
- if (storageAccountUrlValue != null && storageAccountUrlValue.Type != JTokenType.Null)
- {
- string storageAccountUrlInstance = ((string)storageAccountUrlValue);
- propertiesInstance.StorageAccountUrl = storageAccountUrlInstance;
- }
-
- JToken blobNameValue = propertiesValue2["blobName"];
- if (blobNameValue != null && blobNameValue.Type != JTokenType.Null)
- {
- string blobNameInstance = ((string)blobNameValue);
- propertiesInstance.BlobName = blobNameInstance;
- }
-
- JToken nameValue = propertiesValue2["name"];
- if (nameValue != null && nameValue.Type != JTokenType.Null)
- {
- string nameInstance = ((string)nameValue);
- propertiesInstance.Name = nameInstance;
- }
-
- JToken statusValue = propertiesValue2["status"];
- if (statusValue != null && statusValue.Type != JTokenType.Null)
- {
- BackupItemStatus statusInstance = ((BackupItemStatus)Enum.Parse(typeof(BackupItemStatus), ((string)statusValue), true));
- propertiesInstance.Status = statusInstance;
- }
-
- JToken sizeInBytesValue = propertiesValue2["sizeInBytes"];
- if (sizeInBytesValue != null && sizeInBytesValue.Type != JTokenType.Null)
- {
- long sizeInBytesInstance = ((long)sizeInBytesValue);
- propertiesInstance.SizeInBytes = sizeInBytesInstance;
- }
-
- JToken createdValue = propertiesValue2["created"];
- if (createdValue != null && createdValue.Type != JTokenType.Null)
- {
- DateTime createdInstance = ((DateTime)createdValue);
- propertiesInstance.Created = createdInstance;
- }
-
- JToken logValue = propertiesValue2["log"];
- if (logValue != null && logValue.Type != JTokenType.Null)
- {
- string logInstance = ((string)logValue);
- propertiesInstance.Log = logInstance;
- }
-
- JToken databasesArray2 = propertiesValue2["databases"];
- if (databasesArray2 != null && databasesArray2.Type != JTokenType.Null)
- {
- foreach (JToken databasesValue in ((JArray)databasesArray2))
- {
- DatabaseBackupSetting databaseBackupSettingInstance = new DatabaseBackupSetting();
- propertiesInstance.Databases.Add(databaseBackupSettingInstance);
-
- JToken connectionStringValue = databasesValue["connectionString"];
- if (connectionStringValue != null && connectionStringValue.Type != JTokenType.Null)
- {
- string connectionStringInstance = ((string)connectionStringValue);
- databaseBackupSettingInstance.ConnectionString = connectionStringInstance;
- }
-
- JToken connectionStringNameValue = databasesValue["connectionStringName"];
- if (connectionStringNameValue != null && connectionStringNameValue.Type != JTokenType.Null)
- {
- string connectionStringNameInstance = ((string)connectionStringNameValue);
- databaseBackupSettingInstance.ConnectionStringName = connectionStringNameInstance;
- }
-
- JToken databaseTypeValue = databasesValue["databaseType"];
- if (databaseTypeValue != null && databaseTypeValue.Type != JTokenType.Null)
- {
- string databaseTypeInstance = ((string)databaseTypeValue);
- databaseBackupSettingInstance.DatabaseType = databaseTypeInstance;
- }
-
- JToken nameValue2 = databasesValue["name"];
- if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
- {
- string nameInstance2 = ((string)nameValue2);
- databaseBackupSettingInstance.Name = nameInstance2;
- }
- }
- }
-
- JToken scheduledValue = propertiesValue2["scheduled"];
- if (scheduledValue != null && scheduledValue.Type != JTokenType.Null)
- {
- bool scheduledInstance = ((bool)scheduledValue);
- propertiesInstance.Scheduled = scheduledInstance;
- }
-
- JToken lastRestoreTimeStampValue = propertiesValue2["lastRestoreTimeStamp"];
- if (lastRestoreTimeStampValue != null && lastRestoreTimeStampValue.Type != JTokenType.Null)
- {
- DateTime lastRestoreTimeStampInstance = ((DateTime)lastRestoreTimeStampValue);
- propertiesInstance.LastRestoreTimeStamp = lastRestoreTimeStampInstance;
- }
-
- JToken finishedTimeStampValue = propertiesValue2["finishedTimeStamp"];
- if (finishedTimeStampValue != null && finishedTimeStampValue.Type != JTokenType.Null)
- {
- DateTime finishedTimeStampInstance = ((DateTime)finishedTimeStampValue);
- propertiesInstance.FinishedTimeStamp = finishedTimeStampInstance;
- }
-
- JToken correlationIdValue = propertiesValue2["correlationId"];
- if (correlationIdValue != null && correlationIdValue.Type != JTokenType.Null)
- {
- string correlationIdInstance = ((string)correlationIdValue);
- propertiesInstance.CorrelationId = correlationIdInstance;
- }
- }
-
- JToken idValue = responseDoc["id"];
- if (idValue != null && idValue.Type != JTokenType.Null)
- {
- string idInstance = ((string)idValue);
- backupItemInstance.Id = idInstance;
- }
-
- JToken nameValue3 = responseDoc["name"];
- if (nameValue3 != null && nameValue3.Type != JTokenType.Null)
- {
- string nameInstance3 = ((string)nameValue3);
- backupItemInstance.Name = nameInstance3;
- }
-
- JToken locationValue = responseDoc["location"];
- if (locationValue != null && locationValue.Type != JTokenType.Null)
- {
- string locationInstance = ((string)locationValue);
- backupItemInstance.Location = locationInstance;
- }
-
- JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
- if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property in tagsSequenceElement)
- {
- string tagsKey2 = ((string)property.Name);
- string tagsValue2 = ((string)property.Value);
- backupItemInstance.Tags.Add(tagsKey2, tagsValue2);
- }
- }
-
- JToken typeValue = responseDoc["type"];
- if (typeValue != null && typeValue.Type != JTokenType.Null)
- {
- string typeInstance = ((string)typeValue);
- backupItemInstance.Type = typeInstance;
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// You can clone a web site by using a PUT request that includes the
- /// name of the web site and other information in the request body.
- /// (see
- /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166986.aspx
- /// for more information)
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='parameters'>
- /// Required. Parameters supplied to the clone Web Site operation.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// The website operation response.
- /// </returns>
- public async Task<WebSiteAsyncOperationResponse> CloneAsync(string resourceGroupName, string webSiteName, string slotName, WebSiteCloneParameters parameters, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
- if (parameters == null)
- {
- throw new ArgumentNullException("parameters");
- }
- if (parameters.WebSiteClone == null)
- {
- throw new ArgumentNullException("parameters.WebSiteClone");
- }
- if (parameters.WebSiteClone.Location == null)
- {
- throw new ArgumentNullException("parameters.WebSiteClone.Location");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- tracingParameters.Add("parameters", parameters);
- TracingAdapter.Enter(invocationId, this, "CloneAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Put;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Serialize Request
- string requestContent = null;
- JToken requestDoc = null;
-
- JObject webSiteCloneParametersValue = new JObject();
- requestDoc = webSiteCloneParametersValue;
-
- if (parameters.WebSiteClone.Properties != null)
- {
- JObject propertiesValue = new JObject();
- webSiteCloneParametersValue["properties"] = propertiesValue;
-
- if (parameters.WebSiteClone.Properties.ServerFarm != null)
- {
- propertiesValue["ServerFarm"] = parameters.WebSiteClone.Properties.ServerFarm;
- }
-
- if (parameters.WebSiteClone.Properties.CloningInfo != null)
- {
- JObject cloningInfoValue = new JObject();
- propertiesValue["cloningInfo"] = cloningInfoValue;
-
- cloningInfoValue["CorrelationId"] = parameters.WebSiteClone.Properties.CloningInfo.CorrelationId.ToString();
-
- cloningInfoValue["Overwrite"] = parameters.WebSiteClone.Properties.CloningInfo.Overwrite;
-
- cloningInfoValue["CloneCustomHostNames"] = parameters.WebSiteClone.Properties.CloningInfo.CloneCustomHostNames;
-
- if (parameters.WebSiteClone.Properties.CloningInfo.Source != null)
- {
- JObject sourceValue = new JObject();
- cloningInfoValue["Source"] = sourceValue;
-
- if (parameters.WebSiteClone.Properties.CloningInfo.Source.Name != null)
- {
- sourceValue["Name"] = parameters.WebSiteClone.Properties.CloningInfo.Source.Name;
- }
-
- if (parameters.WebSiteClone.Properties.CloningInfo.Source.Location != null)
- {
- sourceValue["Location"] = parameters.WebSiteClone.Properties.CloningInfo.Source.Location;
- }
-
- if (parameters.WebSiteClone.Properties.CloningInfo.Source.ResourceGroupName != null)
- {
- sourceValue["ResourceGroupName"] = parameters.WebSiteClone.Properties.CloningInfo.Source.ResourceGroupName;
- }
-
- if (parameters.WebSiteClone.Properties.CloningInfo.Source.SubscriptionId != null)
- {
- sourceValue["SubscriptionId"] = parameters.WebSiteClone.Properties.CloningInfo.Source.SubscriptionId;
- }
-
- if (parameters.WebSiteClone.Properties.CloningInfo.Source.Slot != null)
- {
- sourceValue["Slot"] = parameters.WebSiteClone.Properties.CloningInfo.Source.Slot;
- }
- }
-
- if (parameters.WebSiteClone.Properties.CloningInfo.HostingEnvironment != null)
- {
- cloningInfoValue["HostingEnvironment"] = parameters.WebSiteClone.Properties.CloningInfo.HostingEnvironment;
- }
- }
- }
-
- if (parameters.WebSiteClone.Id != null)
- {
- webSiteCloneParametersValue["id"] = parameters.WebSiteClone.Id;
- }
-
- if (parameters.WebSiteClone.Name != null)
- {
- webSiteCloneParametersValue["name"] = parameters.WebSiteClone.Name;
- }
-
- webSiteCloneParametersValue["location"] = parameters.WebSiteClone.Location;
-
- if (parameters.WebSiteClone.Tags != null)
- {
- JObject tagsDictionary = new JObject();
- foreach (KeyValuePair<string, string> pair in parameters.WebSiteClone.Tags)
- {
- string tagsKey = pair.Key;
- string tagsValue = pair.Value;
- tagsDictionary[tagsKey] = tagsValue;
- }
- webSiteCloneParametersValue["tags"] = tagsDictionary;
- }
-
- if (parameters.WebSiteClone.Type != null)
- {
- webSiteCloneParametersValue["type"] = parameters.WebSiteClone.Type;
- }
-
- requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
- httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
- httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.Accepted)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteAsyncOperationResponse result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.Accepted)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteAsyncOperationResponse();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- if (responseDoc != null && responseDoc.Type != JTokenType.Null)
- {
- JToken locationValue = responseDoc["location"];
- if (locationValue != null && locationValue.Type != JTokenType.Null)
- {
- string locationInstance = ((string)locationValue);
- result.Location = locationInstance;
- }
-
- JToken retryAfterValue = responseDoc["retry-after"];
- if (retryAfterValue != null && retryAfterValue.Type != JTokenType.Null)
- {
- string retryAfterInstance = ((string)retryAfterValue);
- result.RetryAfter = retryAfterInstance;
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("location"))
- {
- result.Location = httpResponse.Headers.GetValues("location").FirstOrDefault();
- }
- if (httpResponse.Headers.Contains("retry-after"))
- {
- result.RetryAfter = httpResponse.Headers.GetValues("retry-after").FirstOrDefault();
- }
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// You can create a web site by using a POST request that includes the
- /// name of the web site and other information in the request body.
- /// (see
- /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166986.aspx
- /// for more information)
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='parameters'>
- /// Required. Parameters supplied to the Create Web Site operation.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// The Create Web Space operation response.
- /// </returns>
- public async Task<WebSiteCreateResponse> CreateOrUpdateAsync(string resourceGroupName, string webSiteName, string slotName, WebSiteCreateOrUpdateParameters parameters, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
- if (parameters == null)
- {
- throw new ArgumentNullException("parameters");
- }
- if (parameters.WebSite == null)
- {
- throw new ArgumentNullException("parameters.WebSite");
- }
- if (parameters.WebSite.Location == null)
- {
- throw new ArgumentNullException("parameters.WebSite.Location");
- }
- if (parameters.WebSite.Properties != null)
- {
- if (parameters.WebSite.Properties.ServerFarm == null)
- {
- throw new ArgumentNullException("parameters.WebSite.Properties.ServerFarm");
- }
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- tracingParameters.Add("parameters", parameters);
- TracingAdapter.Enter(invocationId, this, "CreateOrUpdateAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Put;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Serialize Request
- string requestContent = null;
- JToken requestDoc = null;
-
- JObject webSiteCreateOrUpdateParametersValue = new JObject();
- requestDoc = webSiteCreateOrUpdateParametersValue;
-
- if (parameters.WebSite.Properties != null)
- {
- JObject propertiesValue = new JObject();
- webSiteCreateOrUpdateParametersValue["properties"] = propertiesValue;
-
- propertiesValue["ServerFarm"] = parameters.WebSite.Properties.ServerFarm;
- }
-
- if (parameters.WebSite.Id != null)
- {
- webSiteCreateOrUpdateParametersValue["id"] = parameters.WebSite.Id;
- }
-
- if (parameters.WebSite.Name != null)
- {
- webSiteCreateOrUpdateParametersValue["name"] = parameters.WebSite.Name;
- }
-
- webSiteCreateOrUpdateParametersValue["location"] = parameters.WebSite.Location;
-
- if (parameters.WebSite.Tags != null)
- {
- JObject tagsDictionary = new JObject();
- foreach (KeyValuePair<string, string> pair in parameters.WebSite.Tags)
- {
- string tagsKey = pair.Key;
- string tagsValue = pair.Value;
- tagsDictionary[tagsKey] = tagsValue;
- }
- webSiteCreateOrUpdateParametersValue["tags"] = tagsDictionary;
- }
-
- if (parameters.WebSite.Type != null)
- {
- webSiteCreateOrUpdateParametersValue["type"] = parameters.WebSite.Type;
- }
-
- requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
- httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
- httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteCreateResponse result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteCreateResponse();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- if (responseDoc != null && responseDoc.Type != JTokenType.Null)
- {
- WebSite webSiteInstance = new WebSite();
- result.WebSite = webSiteInstance;
-
- JToken propertiesValue2 = responseDoc["properties"];
- if (propertiesValue2 != null && propertiesValue2.Type != JTokenType.Null)
- {
- WebSiteProperties propertiesInstance = new WebSiteProperties();
- webSiteInstance.Properties = propertiesInstance;
-
- JToken adminEnabledValue = propertiesValue2["adminEnabled"];
- if (adminEnabledValue != null && adminEnabledValue.Type != JTokenType.Null)
- {
- bool adminEnabledInstance = ((bool)adminEnabledValue);
- propertiesInstance.AdminEnabled = adminEnabledInstance;
- }
-
- JToken availabilityStateValue = propertiesValue2["availabilityState"];
- if (availabilityStateValue != null && availabilityStateValue.Type != JTokenType.Null)
- {
- WebSpaceAvailabilityState availabilityStateInstance = ((WebSpaceAvailabilityState)Enum.Parse(typeof(WebSpaceAvailabilityState), ((string)availabilityStateValue), true));
- propertiesInstance.AvailabilityState = availabilityStateInstance;
- }
-
- JToken enabledValue = propertiesValue2["enabled"];
- if (enabledValue != null && enabledValue.Type != JTokenType.Null)
- {
- bool enabledInstance = ((bool)enabledValue);
- propertiesInstance.Enabled = enabledInstance;
- }
-
- JToken enabledHostNamesArray = propertiesValue2["enabledHostNames"];
- if (enabledHostNamesArray != null && enabledHostNamesArray.Type != JTokenType.Null)
- {
- foreach (JToken enabledHostNamesValue in ((JArray)enabledHostNamesArray))
- {
- propertiesInstance.EnabledHostNames.Add(((string)enabledHostNamesValue));
- }
- }
-
- JToken hostNameSslStatesArray = propertiesValue2["hostNameSslStates"];
- if (hostNameSslStatesArray != null && hostNameSslStatesArray.Type != JTokenType.Null)
- {
- foreach (JToken hostNameSslStatesValue in ((JArray)hostNameSslStatesArray))
- {
- WebSiteProperties.WebSiteHostNameSslState webSiteHostNameSslStateInstance = new WebSiteProperties.WebSiteHostNameSslState();
- propertiesInstance.HostNameSslStates.Add(webSiteHostNameSslStateInstance);
-
- JToken nameValue = hostNameSslStatesValue["name"];
- if (nameValue != null && nameValue.Type != JTokenType.Null)
- {
- string nameInstance = ((string)nameValue);
- webSiteHostNameSslStateInstance.Name = nameInstance;
- }
-
- JToken sslStateValue = hostNameSslStatesValue["sslState"];
- if (sslStateValue != null && sslStateValue.Type != JTokenType.Null)
- {
- WebSiteSslState sslStateInstance = ((WebSiteSslState)Enum.Parse(typeof(WebSiteSslState), ((string)sslStateValue), true));
- webSiteHostNameSslStateInstance.SslState = sslStateInstance;
- }
-
- JToken thumbprintValue = hostNameSslStatesValue["thumbprint"];
- if (thumbprintValue != null && thumbprintValue.Type != JTokenType.Null)
- {
- string thumbprintInstance = ((string)thumbprintValue);
- webSiteHostNameSslStateInstance.Thumbprint = thumbprintInstance;
- }
-
- JToken virtualIPValue = hostNameSslStatesValue["virtualIP"];
- if (virtualIPValue != null && virtualIPValue.Type != JTokenType.Null)
- {
- string virtualIPInstance = ((string)virtualIPValue);
- webSiteHostNameSslStateInstance.VirtualIP = virtualIPInstance;
- }
-
- JToken ipBasedSslResultValue = hostNameSslStatesValue["ipBasedSslResult"];
- if (ipBasedSslResultValue != null && ipBasedSslResultValue.Type != JTokenType.Null)
- {
- string ipBasedSslResultInstance = ((string)ipBasedSslResultValue);
- webSiteHostNameSslStateInstance.IpBasedSslResult = ipBasedSslResultInstance;
- }
-
- JToken toUpdateValue = hostNameSslStatesValue["toUpdate"];
- if (toUpdateValue != null && toUpdateValue.Type != JTokenType.Null)
- {
- bool toUpdateInstance = ((bool)toUpdateValue);
- webSiteHostNameSslStateInstance.ToUpdate = toUpdateInstance;
- }
-
- JToken toUpdateIpBasedSslValue = hostNameSslStatesValue["toUpdateIpBasedSsl"];
- if (toUpdateIpBasedSslValue != null && toUpdateIpBasedSslValue.Type != JTokenType.Null)
- {
- bool toUpdateIpBasedSslInstance = ((bool)toUpdateIpBasedSslValue);
- webSiteHostNameSslStateInstance.ToUpdateIpBasedSsl = toUpdateIpBasedSslInstance;
- }
- }
- }
-
- JToken hostNamesArray = propertiesValue2["hostNames"];
- if (hostNamesArray != null && hostNamesArray.Type != JTokenType.Null)
- {
- foreach (JToken hostNamesValue in ((JArray)hostNamesArray))
- {
- propertiesInstance.HostNames.Add(((string)hostNamesValue));
- }
- }
-
- JToken lastModifiedTimeUtcValue = propertiesValue2["lastModifiedTimeUtc"];
- if (lastModifiedTimeUtcValue != null && lastModifiedTimeUtcValue.Type != JTokenType.Null)
- {
- DateTime lastModifiedTimeUtcInstance = ((DateTime)lastModifiedTimeUtcValue);
- propertiesInstance.LastModifiedTimeUtc = lastModifiedTimeUtcInstance;
- }
-
- JToken repositorySiteNameValue = propertiesValue2["repositorySiteName"];
- if (repositorySiteNameValue != null && repositorySiteNameValue.Type != JTokenType.Null)
- {
- string repositorySiteNameInstance = ((string)repositorySiteNameValue);
- propertiesInstance.RepositorySiteName = repositorySiteNameInstance;
- }
-
- JToken runtimeAvailabilityStateValue = propertiesValue2["runtimeAvailabilityState"];
- if (runtimeAvailabilityStateValue != null && runtimeAvailabilityStateValue.Type != JTokenType.Null)
- {
- WebSiteRuntimeAvailabilityState runtimeAvailabilityStateInstance = ((WebSiteRuntimeAvailabilityState)Enum.Parse(typeof(WebSiteRuntimeAvailabilityState), ((string)runtimeAvailabilityStateValue), true));
- propertiesInstance.RuntimeAvailabilityState = runtimeAvailabilityStateInstance;
- }
-
- JToken trafficManagerHostNamesArray = propertiesValue2["trafficManagerHostNames"];
- if (trafficManagerHostNamesArray != null && trafficManagerHostNamesArray.Type != JTokenType.Null)
- {
- foreach (JToken trafficManagerHostNamesValue in ((JArray)trafficManagerHostNamesArray))
- {
- propertiesInstance.TrafficManagerHostNames.Add(((string)trafficManagerHostNamesValue));
- }
- }
-
- JToken selfLinkValue = propertiesValue2["selfLink"];
- if (selfLinkValue != null && selfLinkValue.Type != JTokenType.Null)
- {
- Uri selfLinkInstance = TypeConversion.TryParseUri(((string)selfLinkValue));
- propertiesInstance.Uri = selfLinkInstance;
- }
-
- JToken serverFarmValue = propertiesValue2["serverFarm"];
- if (serverFarmValue != null && serverFarmValue.Type != JTokenType.Null)
- {
- string serverFarmInstance = ((string)serverFarmValue);
- propertiesInstance.ServerFarm = serverFarmInstance;
- }
-
- JToken serverFarmIdValue = propertiesValue2["serverFarmId"];
- if (serverFarmIdValue != null && serverFarmIdValue.Type != JTokenType.Null)
- {
- string serverFarmIdInstance = ((string)serverFarmIdValue);
- propertiesInstance.ServerFarmId = serverFarmIdInstance;
- }
-
- JToken skuValue = propertiesValue2["sku"];
- if (skuValue != null && skuValue.Type != JTokenType.Null)
- {
- SkuOptions skuInstance = ((SkuOptions)Enum.Parse(typeof(SkuOptions), ((string)skuValue), true));
- propertiesInstance.Sku = skuInstance;
- }
-
- JToken sitePropertiesValue = propertiesValue2["siteProperties"];
- if (sitePropertiesValue != null && sitePropertiesValue.Type != JTokenType.Null)
- {
- WebSiteProperties.SiteProperties sitePropertiesInstance = new WebSiteProperties.SiteProperties();
- propertiesInstance.Properties = sitePropertiesInstance;
-
- JToken appSettingsSequenceElement = ((JToken)sitePropertiesValue["appSettings"]);
- if (appSettingsSequenceElement != null && appSettingsSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property in appSettingsSequenceElement)
- {
- string appSettingsKey = ((string)property.Name);
- string appSettingsValue = ((string)property.Value);
- sitePropertiesInstance.AppSettings.Add(appSettingsKey, appSettingsValue);
- }
- }
-
- JToken metadataSequenceElement = ((JToken)sitePropertiesValue["metadata"]);
- if (metadataSequenceElement != null && metadataSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property2 in metadataSequenceElement)
- {
- string metadataKey = ((string)property2.Name);
- string metadataValue = ((string)property2.Value);
- sitePropertiesInstance.Metadata.Add(metadataKey, metadataValue);
- }
- }
-
- JToken propertiesSequenceElement = ((JToken)sitePropertiesValue["properties"]);
- if (propertiesSequenceElement != null && propertiesSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property3 in propertiesSequenceElement)
- {
- string propertiesKey = ((string)property3.Name);
- string propertiesValue3 = ((string)property3.Value);
- sitePropertiesInstance.Properties.Add(propertiesKey, propertiesValue3);
- }
- }
- }
-
- JToken siteConfigValue = propertiesValue2["siteConfig"];
- if (siteConfigValue != null && siteConfigValue.Type != JTokenType.Null)
- {
- WebSiteConfiguration siteConfigInstance = new WebSiteConfiguration();
- propertiesInstance.SiteConfig = siteConfigInstance;
-
- JToken appSettingsSequenceElement2 = ((JToken)siteConfigValue["appSettings"]);
- if (appSettingsSequenceElement2 != null && appSettingsSequenceElement2.Type != JTokenType.Null)
- {
- foreach (JProperty property4 in appSettingsSequenceElement2)
- {
- string appSettingsKey2 = ((string)property4.Name);
- string appSettingsValue2 = ((string)property4.Value);
- siteConfigInstance.AppSettings.Add(appSettingsKey2, appSettingsValue2);
- }
- }
-
- JToken connectionStringsArray = siteConfigValue["connectionStrings"];
- if (connectionStringsArray != null && connectionStringsArray.Type != JTokenType.Null)
- {
- foreach (JToken connectionStringsValue in ((JArray)connectionStringsArray))
- {
- ConnectionStringInfo connStringInfoInstance = new ConnectionStringInfo();
- siteConfigInstance.ConnectionStrings.Add(connStringInfoInstance);
-
- JToken connectionStringValue = connectionStringsValue["connectionString"];
- if (connectionStringValue != null && connectionStringValue.Type != JTokenType.Null)
- {
- string connectionStringInstance = ((string)connectionStringValue);
- connStringInfoInstance.ConnectionString = connectionStringInstance;
- }
-
- JToken nameValue2 = connectionStringsValue["name"];
- if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
- {
- string nameInstance2 = ((string)nameValue2);
- connStringInfoInstance.Name = nameInstance2;
- }
-
- JToken typeValue = connectionStringsValue["type"];
- if (typeValue != null && typeValue.Type != JTokenType.Null)
- {
- DatabaseServerType typeInstance = ((DatabaseServerType)Enum.Parse(typeof(DatabaseServerType), ((string)typeValue), true));
- connStringInfoInstance.Type = typeInstance;
- }
- }
- }
-
- JToken defaultDocumentsArray = siteConfigValue["defaultDocuments"];
- if (defaultDocumentsArray != null && defaultDocumentsArray.Type != JTokenType.Null)
- {
- foreach (JToken defaultDocumentsValue in ((JArray)defaultDocumentsArray))
- {
- siteConfigInstance.DefaultDocuments.Add(((string)defaultDocumentsValue));
- }
- }
-
- JToken detailedErrorLoggingEnabledValue = siteConfigValue["detailedErrorLoggingEnabled"];
- if (detailedErrorLoggingEnabledValue != null && detailedErrorLoggingEnabledValue.Type != JTokenType.Null)
- {
- bool detailedErrorLoggingEnabledInstance = ((bool)detailedErrorLoggingEnabledValue);
- siteConfigInstance.DetailedErrorLoggingEnabled = detailedErrorLoggingEnabledInstance;
- }
-
- JToken documentRootValue = siteConfigValue["documentRoot"];
- if (documentRootValue != null && documentRootValue.Type != JTokenType.Null)
- {
- string documentRootInstance = ((string)documentRootValue);
- siteConfigInstance.DocumentRoot = documentRootInstance;
- }
-
- JToken handlerMappingsArray = siteConfigValue["handlerMappings"];
- if (handlerMappingsArray != null && handlerMappingsArray.Type != JTokenType.Null)
- {
- foreach (JToken handlerMappingsValue in ((JArray)handlerMappingsArray))
- {
- WebSiteConfiguration.HandlerMapping handlerMappingInstance = new WebSiteConfiguration.HandlerMapping();
- siteConfigInstance.HandlerMappings.Add(handlerMappingInstance);
-
- JToken argumentsValue = handlerMappingsValue["arguments"];
- if (argumentsValue != null && argumentsValue.Type != JTokenType.Null)
- {
- string argumentsInstance = ((string)argumentsValue);
- handlerMappingInstance.Arguments = argumentsInstance;
- }
-
- JToken extensionValue = handlerMappingsValue["extension"];
- if (extensionValue != null && extensionValue.Type != JTokenType.Null)
- {
- string extensionInstance = ((string)extensionValue);
- handlerMappingInstance.Extension = extensionInstance;
- }
-
- JToken scriptProcessorValue = handlerMappingsValue["scriptProcessor"];
- if (scriptProcessorValue != null && scriptProcessorValue.Type != JTokenType.Null)
- {
- string scriptProcessorInstance = ((string)scriptProcessorValue);
- handlerMappingInstance.ScriptProcessor = scriptProcessorInstance;
- }
- }
- }
-
- JToken httpLoggingEnabledValue = siteConfigValue["httpLoggingEnabled"];
- if (httpLoggingEnabledValue != null && httpLoggingEnabledValue.Type != JTokenType.Null)
- {
- bool httpLoggingEnabledInstance = ((bool)httpLoggingEnabledValue);
- siteConfigInstance.HttpLoggingEnabled = httpLoggingEnabledInstance;
- }
-
- JToken logsDirectorySizeLimitValue = siteConfigValue["logsDirectorySizeLimit"];
- if (logsDirectorySizeLimitValue != null && logsDirectorySizeLimitValue.Type != JTokenType.Null)
- {
- int logsDirectorySizeLimitInstance = ((int)logsDirectorySizeLimitValue);
- siteConfigInstance.LogsDirectorySizeLimit = logsDirectorySizeLimitInstance;
- }
-
- JToken managedPipelineModeValue = siteConfigValue["managedPipelineMode"];
- if (managedPipelineModeValue != null && managedPipelineModeValue.Type != JTokenType.Null)
- {
- ManagedPipelineMode managedPipelineModeInstance = ((ManagedPipelineMode)Enum.Parse(typeof(ManagedPipelineMode), ((string)managedPipelineModeValue), true));
- siteConfigInstance.ManagedPipelineMode = managedPipelineModeInstance;
- }
-
- JToken metadataSequenceElement2 = ((JToken)siteConfigValue["metadata"]);
- if (metadataSequenceElement2 != null && metadataSequenceElement2.Type != JTokenType.Null)
- {
- foreach (JProperty property5 in metadataSequenceElement2)
- {
- string metadataKey2 = ((string)property5.Name);
- string metadataValue2 = ((string)property5.Value);
- siteConfigInstance.Metadata.Add(metadataKey2, metadataValue2);
- }
- }
-
- JToken netFrameworkVersionValue = siteConfigValue["netFrameworkVersion"];
- if (netFrameworkVersionValue != null && netFrameworkVersionValue.Type != JTokenType.Null)
- {
- string netFrameworkVersionInstance = ((string)netFrameworkVersionValue);
- siteConfigInstance.NetFrameworkVersion = netFrameworkVersionInstance;
- }
-
- JToken numberOfWorkersValue = siteConfigValue["numberOfWorkers"];
- if (numberOfWorkersValue != null && numberOfWorkersValue.Type != JTokenType.Null)
- {
- int numberOfWorkersInstance = ((int)numberOfWorkersValue);
- siteConfigInstance.NumberOfWorkers = numberOfWorkersInstance;
- }
-
- JToken phpVersionValue = siteConfigValue["phpVersion"];
- if (phpVersionValue != null && phpVersionValue.Type != JTokenType.Null)
- {
- string phpVersionInstance = ((string)phpVersionValue);
- siteConfigInstance.PhpVersion = phpVersionInstance;
- }
-
- JToken pythonVersionValue = siteConfigValue["pythonVersion"];
- if (pythonVersionValue != null && pythonVersionValue.Type != JTokenType.Null)
- {
- string pythonVersionInstance = ((string)pythonVersionValue);
- siteConfigInstance.PythonVersion = pythonVersionInstance;
- }
-
- JToken publishingPasswordValue = siteConfigValue["publishingPassword"];
- if (publishingPasswordValue != null && publishingPasswordValue.Type != JTokenType.Null)
- {
- string publishingPasswordInstance = ((string)publishingPasswordValue);
- siteConfigInstance.PublishingPassword = publishingPasswordInstance;
- }
-
- JToken publishingUsernameValue = siteConfigValue["publishingUsername"];
- if (publishingUsernameValue != null && publishingUsernameValue.Type != JTokenType.Null)
- {
- string publishingUsernameInstance = ((string)publishingUsernameValue);
- siteConfigInstance.PublishingUserName = publishingUsernameInstance;
- }
-
- JToken remoteDebuggingEnabledValue = siteConfigValue["RemoteDebuggingEnabled"];
- if (remoteDebuggingEnabledValue != null && remoteDebuggingEnabledValue.Type != JTokenType.Null)
- {
- bool remoteDebuggingEnabledInstance = ((bool)remoteDebuggingEnabledValue);
- siteConfigInstance.RemoteDebuggingEnabled = remoteDebuggingEnabledInstance;
- }
-
- JToken remoteDebuggingVersionValue = siteConfigValue["remoteDebuggingVersion"];
- if (remoteDebuggingVersionValue != null && remoteDebuggingVersionValue.Type != JTokenType.Null)
- {
- RemoteDebuggingVersion remoteDebuggingVersionInstance = ((RemoteDebuggingVersion)Enum.Parse(typeof(RemoteDebuggingVersion), ((string)remoteDebuggingVersionValue), true));
- siteConfigInstance.RemoteDebuggingVersion = remoteDebuggingVersionInstance;
- }
-
- JToken requestTracingEnabledValue = siteConfigValue["requestTracingEnabled"];
- if (requestTracingEnabledValue != null && requestTracingEnabledValue.Type != JTokenType.Null)
- {
- bool requestTracingEnabledInstance = ((bool)requestTracingEnabledValue);
- siteConfigInstance.RequestTracingEnabled = requestTracingEnabledInstance;
- }
-
- JToken requestTracingExpirationTimeValue = siteConfigValue["requestTracingExpirationTime"];
- if (requestTracingExpirationTimeValue != null && requestTracingExpirationTimeValue.Type != JTokenType.Null)
- {
- DateTime requestTracingExpirationTimeInstance = ((DateTime)requestTracingExpirationTimeValue);
- siteConfigInstance.RequestTracingExpirationTime = requestTracingExpirationTimeInstance;
- }
-
- JToken scmTypeValue = siteConfigValue["scmType"];
- if (scmTypeValue != null && scmTypeValue.Type != JTokenType.Null)
- {
- string scmTypeInstance = ((string)scmTypeValue);
- siteConfigInstance.ScmType = scmTypeInstance;
- }
-
- JToken autoSwapSlotNameValue = siteConfigValue["autoSwapSlotName"];
- if (autoSwapSlotNameValue != null && autoSwapSlotNameValue.Type != JTokenType.Null)
- {
- string autoSwapSlotNameInstance = ((string)autoSwapSlotNameValue);
- siteConfigInstance.AutoSwapSlotName = autoSwapSlotNameInstance;
- }
-
- JToken use32BitWorkerProcessValue = siteConfigValue["use32BitWorkerProcess"];
- if (use32BitWorkerProcessValue != null && use32BitWorkerProcessValue.Type != JTokenType.Null)
- {
- bool use32BitWorkerProcessInstance = ((bool)use32BitWorkerProcessValue);
- siteConfigInstance.Use32BitWorkerProcess = use32BitWorkerProcessInstance;
- }
-
- JToken webSocketsEnabledValue = siteConfigValue["webSocketsEnabled"];
- if (webSocketsEnabledValue != null && webSocketsEnabledValue.Type != JTokenType.Null)
- {
- bool webSocketsEnabledInstance = ((bool)webSocketsEnabledValue);
- siteConfigInstance.WebSocketsEnabled = webSocketsEnabledInstance;
- }
-
- JToken limitsValue = siteConfigValue["limits"];
- if (limitsValue != null && limitsValue.Type != JTokenType.Null)
- {
- SiteLimits limitsInstance = new SiteLimits();
- siteConfigInstance.Limits = limitsInstance;
-
- JToken maxPercentageCpuValue = limitsValue["maxPercentageCpu"];
- if (maxPercentageCpuValue != null && maxPercentageCpuValue.Type != JTokenType.Null)
- {
- double maxPercentageCpuInstance = ((double)maxPercentageCpuValue);
- limitsInstance.MaxPercentageCpu = maxPercentageCpuInstance;
- }
-
- JToken maxMemoryInMbValue = limitsValue["maxMemoryInMb"];
- if (maxMemoryInMbValue != null && maxMemoryInMbValue.Type != JTokenType.Null)
- {
- long maxMemoryInMbInstance = ((long)maxMemoryInMbValue);
- limitsInstance.MaxMemoryInMb = maxMemoryInMbInstance;
- }
-
- JToken maxDiskSizeInMbValue = limitsValue["maxDiskSizeInMb"];
- if (maxDiskSizeInMbValue != null && maxDiskSizeInMbValue.Type != JTokenType.Null)
- {
- long maxDiskSizeInMbInstance = ((long)maxDiskSizeInMbValue);
- limitsInstance.MaxDiskSizeInMb = maxDiskSizeInMbInstance;
- }
- }
- }
-
- JToken stateValue = propertiesValue2["state"];
- if (stateValue != null && stateValue.Type != JTokenType.Null)
- {
- WebSiteState stateInstance = ((WebSiteState)Enum.Parse(typeof(WebSiteState), ((string)stateValue), true));
- propertiesInstance.State = stateInstance;
- }
-
- JToken usageStateValue = propertiesValue2["usageState"];
- if (usageStateValue != null && usageStateValue.Type != JTokenType.Null)
- {
- WebSiteUsageState usageStateInstance = ((WebSiteUsageState)Enum.Parse(typeof(WebSiteUsageState), ((string)usageStateValue), true));
- propertiesInstance.UsageState = usageStateInstance;
- }
-
- JToken webSpaceValue = propertiesValue2["webSpace"];
- if (webSpaceValue != null && webSpaceValue.Type != JTokenType.Null)
- {
- string webSpaceInstance = ((string)webSpaceValue);
- propertiesInstance.WebSpace = webSpaceInstance;
- }
-
- JToken provisioningStateValue = propertiesValue2["provisioningState"];
- if (provisioningStateValue != null && provisioningStateValue.Type != JTokenType.Null)
- {
- string provisioningStateInstance = ((string)provisioningStateValue);
- propertiesInstance.ProvisioningState = provisioningStateInstance;
- }
- }
-
- JToken idValue = responseDoc["id"];
- if (idValue != null && idValue.Type != JTokenType.Null)
- {
- string idInstance = ((string)idValue);
- webSiteInstance.Id = idInstance;
- }
-
- JToken nameValue3 = responseDoc["name"];
- if (nameValue3 != null && nameValue3.Type != JTokenType.Null)
- {
- string nameInstance3 = ((string)nameValue3);
- webSiteInstance.Name = nameInstance3;
- }
-
- JToken locationValue = responseDoc["location"];
- if (locationValue != null && locationValue.Type != JTokenType.Null)
- {
- string locationInstance = ((string)locationValue);
- webSiteInstance.Location = locationInstance;
- }
-
- JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
- if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property6 in tagsSequenceElement)
- {
- string tagsKey2 = ((string)property6.Name);
- string tagsValue2 = ((string)property6.Value);
- webSiteInstance.Tags.Add(tagsKey2, tagsValue2);
- }
- }
-
- JToken typeValue2 = responseDoc["type"];
- if (typeValue2 != null && typeValue2.Type != JTokenType.Null)
- {
- string typeInstance2 = ((string)typeValue2);
- webSiteInstance.Type = typeInstance2;
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// A web site repository is essentially a GIT repository that you can
- /// use to manage your web site content. By using GIT source control
- /// tools, you can push or pull version controlled changes to your
- /// site. You can create a repository for your web site by issuing an
- /// HTTP POST request, or retrieve information about the repository by
- /// using HTTP GET. (see
- /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166967.aspx
- /// for more information)
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// A standard service response including an HTTP status code and
- /// request ID.
- /// </returns>
- public async Task<AzureOperationResponse> CreateRepositoryAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- TracingAdapter.Enter(invocationId, this, "CreateRepositoryAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/repository";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Post;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- AzureOperationResponse result = null;
- // Deserialize Response
- result = new AzureOperationResponse();
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// Deletes the web site.
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group..
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the Web Site resource.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='parameters'>
- /// Required. The parameters to delete a web site.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// A standard service response including an HTTP status code and
- /// request ID.
- /// </returns>
- public async Task<AzureOperationResponse> DeleteAsync(string resourceGroupName, string webSiteName, string slotName, WebSiteDeleteParameters parameters, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
- if (parameters == null)
- {
- throw new ArgumentNullException("parameters");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- tracingParameters.Add("parameters", parameters);
- TracingAdapter.Enter(invocationId, this, "DeleteAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- queryParameters.Add("deleteEmptyServerFarm=" + Uri.EscapeDataString(parameters.DeleteEmptyServerFarm.ToString().ToLower()));
- queryParameters.Add("deleteMetrics=" + Uri.EscapeDataString(parameters.DeleteMetrics.ToString().ToLower()));
- queryParameters.Add("deleteAllSlots=" + Uri.EscapeDataString(parameters.DeleteAllSlots.ToString().ToLower()));
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Delete;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- AzureOperationResponse result = null;
- // Deserialize Response
- result = new AzureOperationResponse();
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// A web site repository is essentially a GIT repository that you can
- /// use to manage your web site content. By using GIT source control
- /// tools, you can push or pull version controlled changes to your
- /// site. You can create a repository for your web site by issuing an
- /// HTTP POST request, or retrieve information about the repository by
- /// using HTTP GET. (see
- /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166967.aspx
- /// for more information)
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// The Delete Web Site Repository operation response.
- /// </returns>
- public async Task<WebSiteDeleteRepositoryResponse> DeleteRepositoryAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- TracingAdapter.Enter(invocationId, this, "DeleteRepositoryAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/repository";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Delete;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteDeleteRepositoryResponse result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteDeleteRepositoryResponse();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- if (responseDoc != null && responseDoc.Type != JTokenType.Null)
- {
- JToken uriValue = responseDoc["uri"];
- if (uriValue != null && uriValue.Type != JTokenType.Null)
- {
- Uri uriInstance = TypeConversion.TryParseUri(((string)uriValue));
- result.Uri = uriInstance;
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// Unlink source control from website
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='repoUrl'>
- /// Required. The repository url.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// A standard service response including an HTTP status code and
- /// request ID.
- /// </returns>
- public async Task<AzureOperationResponse> DeleteSiteSourceControlAsync(string resourceGroupName, string webSiteName, string slotName, string repoUrl, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
- if (repoUrl == null)
- {
- throw new ArgumentNullException("repoUrl");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- tracingParameters.Add("repoUrl", repoUrl);
- TracingAdapter.Enter(invocationId, this, "DeleteSiteSourceControlAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/sourcecontrols/web";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Delete;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- AzureOperationResponse result = null;
- // Deserialize Response
- result = new AzureOperationResponse();
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// Scans a backup in a storage account and returns database
- /// information etc. Should be called before calling Restore to
- /// discover what parameters are needed for the restore operation.
- /// KNOWN BUG: This has to be called against an exisingsite, otherwise
- /// will hit an error about non-existing resource.
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the web space.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='restoreRequestEnvelope'>
- /// Required. A restore request.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// The information gathered about a backup storaged in a storage
- /// account.
- /// </returns>
- public async Task<WebSiteRestoreDiscoverResponse> DiscoverAsync(string resourceGroupName, string webSiteName, string slotName, RestoreRequestEnvelope restoreRequestEnvelope, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
- if (restoreRequestEnvelope == null)
- {
- throw new ArgumentNullException("restoreRequestEnvelope");
- }
- if (restoreRequestEnvelope.Location == null)
- {
- throw new ArgumentNullException("restoreRequestEnvelope.Location");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- tracingParameters.Add("restoreRequestEnvelope", restoreRequestEnvelope);
- TracingAdapter.Enter(invocationId, this, "DiscoverAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/restore/discover";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Put;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
- httpRequest.Headers.Add("x-ms-version", "2014-06-01");
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Serialize Request
- string requestContent = null;
- JToken requestDoc = null;
-
- JObject restoreRequestEnvelopeValue = new JObject();
- requestDoc = restoreRequestEnvelopeValue;
-
- if (restoreRequestEnvelope.Request != null)
- {
- JObject propertiesValue = new JObject();
- restoreRequestEnvelopeValue["properties"] = propertiesValue;
-
- propertiesValue["AdjustConnectionStrings"] = restoreRequestEnvelope.Request.AdjustConnectionStrings;
-
- if (restoreRequestEnvelope.Request.BlobName != null)
- {
- propertiesValue["BlobName"] = restoreRequestEnvelope.Request.BlobName;
- }
-
- if (restoreRequestEnvelope.Request.Databases != null)
- {
- if (restoreRequestEnvelope.Request.Databases is ILazyCollection == false || ((ILazyCollection)restoreRequestEnvelope.Request.Databases).IsInitialized)
- {
- JArray databasesArray = new JArray();
- foreach (DatabaseBackupSetting databasesItem in restoreRequestEnvelope.Request.Databases)
- {
- JObject databaseBackupSettingValue = new JObject();
- databasesArray.Add(databaseBackupSettingValue);
-
- if (databasesItem.ConnectionString != null)
- {
- databaseBackupSettingValue["connectionString"] = databasesItem.ConnectionString;
- }
-
- if (databasesItem.ConnectionStringName != null)
- {
- databaseBackupSettingValue["connectionStringName"] = databasesItem.ConnectionStringName;
- }
-
- if (databasesItem.DatabaseType != null)
- {
- databaseBackupSettingValue["databaseType"] = databasesItem.DatabaseType;
- }
-
- if (databasesItem.Name != null)
- {
- databaseBackupSettingValue["name"] = databasesItem.Name;
- }
- }
- propertiesValue["Databases"] = databasesArray;
- }
- }
-
- propertiesValue["IgnoreConflictingHostNames"] = restoreRequestEnvelope.Request.IgnoreConflictingHostNames;
-
- propertiesValue["Overwrite"] = restoreRequestEnvelope.Request.Overwrite;
-
- if (restoreRequestEnvelope.Request.StorageAccountUrl != null)
- {
- propertiesValue["StorageAccountUrl"] = restoreRequestEnvelope.Request.StorageAccountUrl;
- }
- }
-
- if (restoreRequestEnvelope.Id != null)
- {
- restoreRequestEnvelopeValue["id"] = restoreRequestEnvelope.Id;
- }
-
- if (restoreRequestEnvelope.Name != null)
- {
- restoreRequestEnvelopeValue["name"] = restoreRequestEnvelope.Name;
- }
-
- restoreRequestEnvelopeValue["location"] = restoreRequestEnvelope.Location;
-
- if (restoreRequestEnvelope.Tags != null)
- {
- JObject tagsDictionary = new JObject();
- foreach (KeyValuePair<string, string> pair in restoreRequestEnvelope.Tags)
- {
- string tagsKey = pair.Key;
- string tagsValue = pair.Value;
- tagsDictionary[tagsKey] = tagsValue;
- }
- restoreRequestEnvelopeValue["tags"] = tagsDictionary;
- }
-
- if (restoreRequestEnvelope.Type != null)
- {
- restoreRequestEnvelopeValue["type"] = restoreRequestEnvelope.Type;
- }
-
- requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
- httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
- httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteRestoreDiscoverResponse result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteRestoreDiscoverResponse();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- if (responseDoc != null && responseDoc.Type != JTokenType.Null)
- {
- WebSiteRestoreDiscover envelopeInstance = new WebSiteRestoreDiscover();
- result.Envelope = envelopeInstance;
-
- JToken propertiesValue2 = responseDoc["properties"];
- if (propertiesValue2 != null && propertiesValue2.Type != JTokenType.Null)
- {
- WebSiteRestoreDiscoverProperties propertiesInstance = new WebSiteRestoreDiscoverProperties();
- envelopeInstance.Properties = propertiesInstance;
-
- JToken storageAccountUrlValue = propertiesValue2["storageAccountUrl"];
- if (storageAccountUrlValue != null && storageAccountUrlValue.Type != JTokenType.Null)
- {
- string storageAccountUrlInstance = ((string)storageAccountUrlValue);
- propertiesInstance.StorageAccountUrl = storageAccountUrlInstance;
- }
-
- JToken blobNameValue = propertiesValue2["blobName"];
- if (blobNameValue != null && blobNameValue.Type != JTokenType.Null)
- {
- string blobNameInstance = ((string)blobNameValue);
- propertiesInstance.BlobName = blobNameInstance;
- }
-
- JToken overwriteValue = propertiesValue2["overwrite"];
- if (overwriteValue != null && overwriteValue.Type != JTokenType.Null)
- {
- bool overwriteInstance = ((bool)overwriteValue);
- propertiesInstance.Overwrite = overwriteInstance;
- }
-
- JToken databasesArray2 = propertiesValue2["databases"];
- if (databasesArray2 != null && databasesArray2.Type != JTokenType.Null)
- {
- foreach (JToken databasesValue in ((JArray)databasesArray2))
- {
- DatabaseBackupSetting databaseBackupSettingInstance = new DatabaseBackupSetting();
- propertiesInstance.Databases.Add(databaseBackupSettingInstance);
-
- JToken connectionStringValue = databasesValue["connectionString"];
- if (connectionStringValue != null && connectionStringValue.Type != JTokenType.Null)
- {
- string connectionStringInstance = ((string)connectionStringValue);
- databaseBackupSettingInstance.ConnectionString = connectionStringInstance;
- }
-
- JToken connectionStringNameValue = databasesValue["connectionStringName"];
- if (connectionStringNameValue != null && connectionStringNameValue.Type != JTokenType.Null)
- {
- string connectionStringNameInstance = ((string)connectionStringNameValue);
- databaseBackupSettingInstance.ConnectionStringName = connectionStringNameInstance;
- }
-
- JToken databaseTypeValue = databasesValue["databaseType"];
- if (databaseTypeValue != null && databaseTypeValue.Type != JTokenType.Null)
- {
- string databaseTypeInstance = ((string)databaseTypeValue);
- databaseBackupSettingInstance.DatabaseType = databaseTypeInstance;
- }
-
- JToken nameValue = databasesValue["name"];
- if (nameValue != null && nameValue.Type != JTokenType.Null)
- {
- string nameInstance = ((string)nameValue);
- databaseBackupSettingInstance.Name = nameInstance;
- }
- }
- }
-
- JToken ignoreConflictingHostNamesValue = propertiesValue2["ignoreConflictingHostNames"];
- if (ignoreConflictingHostNamesValue != null && ignoreConflictingHostNamesValue.Type != JTokenType.Null)
- {
- bool ignoreConflictingHostNamesInstance = ((bool)ignoreConflictingHostNamesValue);
- propertiesInstance.IgnoreConflictingHostNames = ignoreConflictingHostNamesInstance;
- }
-
- JToken adjustConnectionStringsValue = propertiesValue2["adjustConnectionStrings"];
- if (adjustConnectionStringsValue != null && adjustConnectionStringsValue.Type != JTokenType.Null)
- {
- bool adjustConnectionStringsInstance = ((bool)adjustConnectionStringsValue);
- propertiesInstance.AdjustConnectionStrings = adjustConnectionStringsInstance;
- }
- }
-
- JToken idValue = responseDoc["id"];
- if (idValue != null && idValue.Type != JTokenType.Null)
- {
- string idInstance = ((string)idValue);
- envelopeInstance.Id = idInstance;
- }
-
- JToken nameValue2 = responseDoc["name"];
- if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
- {
- string nameInstance2 = ((string)nameValue2);
- envelopeInstance.Name = nameInstance2;
- }
-
- JToken locationValue = responseDoc["location"];
- if (locationValue != null && locationValue.Type != JTokenType.Null)
- {
- string locationInstance = ((string)locationValue);
- envelopeInstance.Location = locationInstance;
- }
-
- JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
- if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property in tagsSequenceElement)
- {
- string tagsKey2 = ((string)property.Name);
- string tagsValue2 = ((string)property.Value);
- envelopeInstance.Tags.Add(tagsKey2, tagsValue2);
- }
- }
-
- JToken typeValue = responseDoc["type"];
- if (typeValue != null && typeValue.Type != JTokenType.Null)
- {
- string typeInstance = ((string)typeValue);
- envelopeInstance.Type = typeInstance;
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// You can generate a new random password for publishing a site by
- /// issuing an HTTP POST request. Tip: If you want to verify that the
- /// publish password has changed, call HTTP GET on /publishxml before
- /// calling /newpassword. In the publish XML, note the hash value in
- /// the userPWD attribute. After calling /newpassword, call
- /// /publishxml again. You can then compare the new value of userPWD
- /// in the Publish XML with the one you noted earlier. (see
- /// http://msdn.microsoft.com/en-us/library/windowsazure/dn236428.aspx
- /// for more information)
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// A standard service response including an HTTP status code and
- /// request ID.
- /// </returns>
- public async Task<AzureOperationResponse> GeneratePasswordAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- TracingAdapter.Enter(invocationId, this, "GeneratePasswordAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/newPassword";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Post;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- AzureOperationResponse result = null;
- // Deserialize Response
- result = new AzureOperationResponse();
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// You can retrieve details for a web site by issuing an HTTP GET
- /// request. (see
- /// http://msdn.microsoft.com/en-us/library/windowsazure/dn167007.aspx
- /// for more information)
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='parameters'>
- /// Optional. Additional parameters.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// The Get Web Site Details operation response.
- /// </returns>
- public async Task<WebSiteGetResponse> GetAsync(string resourceGroupName, string webSiteName, string slotName, WebSiteGetParameters parameters, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- tracingParameters.Add("parameters", parameters);
- TracingAdapter.Enter(invocationId, this, "GetAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (parameters != null && parameters.PropertiesToInclude != null && parameters.PropertiesToInclude.Count > 0)
- {
- queryParameters.Add("propertiesToInclude=" + Uri.EscapeDataString(string.Join(",", parameters.PropertiesToInclude)));
- }
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Get;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteGetResponse result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteGetResponse();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- if (responseDoc != null && responseDoc.Type != JTokenType.Null)
- {
- WebSite webSiteInstance = new WebSite();
- result.WebSite = webSiteInstance;
-
- JToken propertiesValue = responseDoc["properties"];
- if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
- {
- WebSiteProperties propertiesInstance = new WebSiteProperties();
- webSiteInstance.Properties = propertiesInstance;
-
- JToken adminEnabledValue = propertiesValue["adminEnabled"];
- if (adminEnabledValue != null && adminEnabledValue.Type != JTokenType.Null)
- {
- bool adminEnabledInstance = ((bool)adminEnabledValue);
- propertiesInstance.AdminEnabled = adminEnabledInstance;
- }
-
- JToken availabilityStateValue = propertiesValue["availabilityState"];
- if (availabilityStateValue != null && availabilityStateValue.Type != JTokenType.Null)
- {
- WebSpaceAvailabilityState availabilityStateInstance = ((WebSpaceAvailabilityState)Enum.Parse(typeof(WebSpaceAvailabilityState), ((string)availabilityStateValue), true));
- propertiesInstance.AvailabilityState = availabilityStateInstance;
- }
-
- JToken enabledValue = propertiesValue["enabled"];
- if (enabledValue != null && enabledValue.Type != JTokenType.Null)
- {
- bool enabledInstance = ((bool)enabledValue);
- propertiesInstance.Enabled = enabledInstance;
- }
-
- JToken enabledHostNamesArray = propertiesValue["enabledHostNames"];
- if (enabledHostNamesArray != null && enabledHostNamesArray.Type != JTokenType.Null)
- {
- foreach (JToken enabledHostNamesValue in ((JArray)enabledHostNamesArray))
- {
- propertiesInstance.EnabledHostNames.Add(((string)enabledHostNamesValue));
- }
- }
-
- JToken hostNameSslStatesArray = propertiesValue["hostNameSslStates"];
- if (hostNameSslStatesArray != null && hostNameSslStatesArray.Type != JTokenType.Null)
- {
- foreach (JToken hostNameSslStatesValue in ((JArray)hostNameSslStatesArray))
- {
- WebSiteProperties.WebSiteHostNameSslState webSiteHostNameSslStateInstance = new WebSiteProperties.WebSiteHostNameSslState();
- propertiesInstance.HostNameSslStates.Add(webSiteHostNameSslStateInstance);
-
- JToken nameValue = hostNameSslStatesValue["name"];
- if (nameValue != null && nameValue.Type != JTokenType.Null)
- {
- string nameInstance = ((string)nameValue);
- webSiteHostNameSslStateInstance.Name = nameInstance;
- }
-
- JToken sslStateValue = hostNameSslStatesValue["sslState"];
- if (sslStateValue != null && sslStateValue.Type != JTokenType.Null)
- {
- WebSiteSslState sslStateInstance = ((WebSiteSslState)Enum.Parse(typeof(WebSiteSslState), ((string)sslStateValue), true));
- webSiteHostNameSslStateInstance.SslState = sslStateInstance;
- }
-
- JToken thumbprintValue = hostNameSslStatesValue["thumbprint"];
- if (thumbprintValue != null && thumbprintValue.Type != JTokenType.Null)
- {
- string thumbprintInstance = ((string)thumbprintValue);
- webSiteHostNameSslStateInstance.Thumbprint = thumbprintInstance;
- }
-
- JToken virtualIPValue = hostNameSslStatesValue["virtualIP"];
- if (virtualIPValue != null && virtualIPValue.Type != JTokenType.Null)
- {
- string virtualIPInstance = ((string)virtualIPValue);
- webSiteHostNameSslStateInstance.VirtualIP = virtualIPInstance;
- }
-
- JToken ipBasedSslResultValue = hostNameSslStatesValue["ipBasedSslResult"];
- if (ipBasedSslResultValue != null && ipBasedSslResultValue.Type != JTokenType.Null)
- {
- string ipBasedSslResultInstance = ((string)ipBasedSslResultValue);
- webSiteHostNameSslStateInstance.IpBasedSslResult = ipBasedSslResultInstance;
- }
-
- JToken toUpdateValue = hostNameSslStatesValue["toUpdate"];
- if (toUpdateValue != null && toUpdateValue.Type != JTokenType.Null)
- {
- bool toUpdateInstance = ((bool)toUpdateValue);
- webSiteHostNameSslStateInstance.ToUpdate = toUpdateInstance;
- }
-
- JToken toUpdateIpBasedSslValue = hostNameSslStatesValue["toUpdateIpBasedSsl"];
- if (toUpdateIpBasedSslValue != null && toUpdateIpBasedSslValue.Type != JTokenType.Null)
- {
- bool toUpdateIpBasedSslInstance = ((bool)toUpdateIpBasedSslValue);
- webSiteHostNameSslStateInstance.ToUpdateIpBasedSsl = toUpdateIpBasedSslInstance;
- }
- }
- }
-
- JToken hostNamesArray = propertiesValue["hostNames"];
- if (hostNamesArray != null && hostNamesArray.Type != JTokenType.Null)
- {
- foreach (JToken hostNamesValue in ((JArray)hostNamesArray))
- {
- propertiesInstance.HostNames.Add(((string)hostNamesValue));
- }
- }
-
- JToken lastModifiedTimeUtcValue = propertiesValue["lastModifiedTimeUtc"];
- if (lastModifiedTimeUtcValue != null && lastModifiedTimeUtcValue.Type != JTokenType.Null)
- {
- DateTime lastModifiedTimeUtcInstance = ((DateTime)lastModifiedTimeUtcValue);
- propertiesInstance.LastModifiedTimeUtc = lastModifiedTimeUtcInstance;
- }
-
- JToken repositorySiteNameValue = propertiesValue["repositorySiteName"];
- if (repositorySiteNameValue != null && repositorySiteNameValue.Type != JTokenType.Null)
- {
- string repositorySiteNameInstance = ((string)repositorySiteNameValue);
- propertiesInstance.RepositorySiteName = repositorySiteNameInstance;
- }
-
- JToken runtimeAvailabilityStateValue = propertiesValue["runtimeAvailabilityState"];
- if (runtimeAvailabilityStateValue != null && runtimeAvailabilityStateValue.Type != JTokenType.Null)
- {
- WebSiteRuntimeAvailabilityState runtimeAvailabilityStateInstance = ((WebSiteRuntimeAvailabilityState)Enum.Parse(typeof(WebSiteRuntimeAvailabilityState), ((string)runtimeAvailabilityStateValue), true));
- propertiesInstance.RuntimeAvailabilityState = runtimeAvailabilityStateInstance;
- }
-
- JToken trafficManagerHostNamesArray = propertiesValue["trafficManagerHostNames"];
- if (trafficManagerHostNamesArray != null && trafficManagerHostNamesArray.Type != JTokenType.Null)
- {
- foreach (JToken trafficManagerHostNamesValue in ((JArray)trafficManagerHostNamesArray))
- {
- propertiesInstance.TrafficManagerHostNames.Add(((string)trafficManagerHostNamesValue));
- }
- }
-
- JToken selfLinkValue = propertiesValue["selfLink"];
- if (selfLinkValue != null && selfLinkValue.Type != JTokenType.Null)
- {
- Uri selfLinkInstance = TypeConversion.TryParseUri(((string)selfLinkValue));
- propertiesInstance.Uri = selfLinkInstance;
- }
-
- JToken serverFarmValue = propertiesValue["serverFarm"];
- if (serverFarmValue != null && serverFarmValue.Type != JTokenType.Null)
- {
- string serverFarmInstance = ((string)serverFarmValue);
- propertiesInstance.ServerFarm = serverFarmInstance;
- }
-
- JToken serverFarmIdValue = propertiesValue["serverFarmId"];
- if (serverFarmIdValue != null && serverFarmIdValue.Type != JTokenType.Null)
- {
- string serverFarmIdInstance = ((string)serverFarmIdValue);
- propertiesInstance.ServerFarmId = serverFarmIdInstance;
- }
-
- JToken skuValue = propertiesValue["sku"];
- if (skuValue != null && skuValue.Type != JTokenType.Null)
- {
- SkuOptions skuInstance = ((SkuOptions)Enum.Parse(typeof(SkuOptions), ((string)skuValue), true));
- propertiesInstance.Sku = skuInstance;
- }
-
- JToken sitePropertiesValue = propertiesValue["siteProperties"];
- if (sitePropertiesValue != null && sitePropertiesValue.Type != JTokenType.Null)
- {
- WebSiteProperties.SiteProperties sitePropertiesInstance = new WebSiteProperties.SiteProperties();
- propertiesInstance.Properties = sitePropertiesInstance;
-
- JToken appSettingsSequenceElement = ((JToken)sitePropertiesValue["appSettings"]);
- if (appSettingsSequenceElement != null && appSettingsSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property in appSettingsSequenceElement)
- {
- string appSettingsKey = ((string)property.Name);
- string appSettingsValue = ((string)property.Value);
- sitePropertiesInstance.AppSettings.Add(appSettingsKey, appSettingsValue);
- }
- }
-
- JToken metadataSequenceElement = ((JToken)sitePropertiesValue["metadata"]);
- if (metadataSequenceElement != null && metadataSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property2 in metadataSequenceElement)
- {
- string metadataKey = ((string)property2.Name);
- string metadataValue = ((string)property2.Value);
- sitePropertiesInstance.Metadata.Add(metadataKey, metadataValue);
- }
- }
-
- JToken propertiesSequenceElement = ((JToken)sitePropertiesValue["properties"]);
- if (propertiesSequenceElement != null && propertiesSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property3 in propertiesSequenceElement)
- {
- string propertiesKey = ((string)property3.Name);
- string propertiesValue2 = ((string)property3.Value);
- sitePropertiesInstance.Properties.Add(propertiesKey, propertiesValue2);
- }
- }
- }
-
- JToken siteConfigValue = propertiesValue["siteConfig"];
- if (siteConfigValue != null && siteConfigValue.Type != JTokenType.Null)
- {
- WebSiteConfiguration siteConfigInstance = new WebSiteConfiguration();
- propertiesInstance.SiteConfig = siteConfigInstance;
-
- JToken appSettingsSequenceElement2 = ((JToken)siteConfigValue["appSettings"]);
- if (appSettingsSequenceElement2 != null && appSettingsSequenceElement2.Type != JTokenType.Null)
- {
- foreach (JProperty property4 in appSettingsSequenceElement2)
- {
- string appSettingsKey2 = ((string)property4.Name);
- string appSettingsValue2 = ((string)property4.Value);
- siteConfigInstance.AppSettings.Add(appSettingsKey2, appSettingsValue2);
- }
- }
-
- JToken connectionStringsArray = siteConfigValue["connectionStrings"];
- if (connectionStringsArray != null && connectionStringsArray.Type != JTokenType.Null)
- {
- foreach (JToken connectionStringsValue in ((JArray)connectionStringsArray))
- {
- ConnectionStringInfo connStringInfoInstance = new ConnectionStringInfo();
- siteConfigInstance.ConnectionStrings.Add(connStringInfoInstance);
-
- JToken connectionStringValue = connectionStringsValue["connectionString"];
- if (connectionStringValue != null && connectionStringValue.Type != JTokenType.Null)
- {
- string connectionStringInstance = ((string)connectionStringValue);
- connStringInfoInstance.ConnectionString = connectionStringInstance;
- }
-
- JToken nameValue2 = connectionStringsValue["name"];
- if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
- {
- string nameInstance2 = ((string)nameValue2);
- connStringInfoInstance.Name = nameInstance2;
- }
-
- JToken typeValue = connectionStringsValue["type"];
- if (typeValue != null && typeValue.Type != JTokenType.Null)
- {
- DatabaseServerType typeInstance = ((DatabaseServerType)Enum.Parse(typeof(DatabaseServerType), ((string)typeValue), true));
- connStringInfoInstance.Type = typeInstance;
- }
- }
- }
-
- JToken defaultDocumentsArray = siteConfigValue["defaultDocuments"];
- if (defaultDocumentsArray != null && defaultDocumentsArray.Type != JTokenType.Null)
- {
- foreach (JToken defaultDocumentsValue in ((JArray)defaultDocumentsArray))
- {
- siteConfigInstance.DefaultDocuments.Add(((string)defaultDocumentsValue));
- }
- }
-
- JToken detailedErrorLoggingEnabledValue = siteConfigValue["detailedErrorLoggingEnabled"];
- if (detailedErrorLoggingEnabledValue != null && detailedErrorLoggingEnabledValue.Type != JTokenType.Null)
- {
- bool detailedErrorLoggingEnabledInstance = ((bool)detailedErrorLoggingEnabledValue);
- siteConfigInstance.DetailedErrorLoggingEnabled = detailedErrorLoggingEnabledInstance;
- }
-
- JToken documentRootValue = siteConfigValue["documentRoot"];
- if (documentRootValue != null && documentRootValue.Type != JTokenType.Null)
- {
- string documentRootInstance = ((string)documentRootValue);
- siteConfigInstance.DocumentRoot = documentRootInstance;
- }
-
- JToken handlerMappingsArray = siteConfigValue["handlerMappings"];
- if (handlerMappingsArray != null && handlerMappingsArray.Type != JTokenType.Null)
- {
- foreach (JToken handlerMappingsValue in ((JArray)handlerMappingsArray))
- {
- WebSiteConfiguration.HandlerMapping handlerMappingInstance = new WebSiteConfiguration.HandlerMapping();
- siteConfigInstance.HandlerMappings.Add(handlerMappingInstance);
-
- JToken argumentsValue = handlerMappingsValue["arguments"];
- if (argumentsValue != null && argumentsValue.Type != JTokenType.Null)
- {
- string argumentsInstance = ((string)argumentsValue);
- handlerMappingInstance.Arguments = argumentsInstance;
- }
-
- JToken extensionValue = handlerMappingsValue["extension"];
- if (extensionValue != null && extensionValue.Type != JTokenType.Null)
- {
- string extensionInstance = ((string)extensionValue);
- handlerMappingInstance.Extension = extensionInstance;
- }
-
- JToken scriptProcessorValue = handlerMappingsValue["scriptProcessor"];
- if (scriptProcessorValue != null && scriptProcessorValue.Type != JTokenType.Null)
- {
- string scriptProcessorInstance = ((string)scriptProcessorValue);
- handlerMappingInstance.ScriptProcessor = scriptProcessorInstance;
- }
- }
- }
-
- JToken httpLoggingEnabledValue = siteConfigValue["httpLoggingEnabled"];
- if (httpLoggingEnabledValue != null && httpLoggingEnabledValue.Type != JTokenType.Null)
- {
- bool httpLoggingEnabledInstance = ((bool)httpLoggingEnabledValue);
- siteConfigInstance.HttpLoggingEnabled = httpLoggingEnabledInstance;
- }
-
- JToken logsDirectorySizeLimitValue = siteConfigValue["logsDirectorySizeLimit"];
- if (logsDirectorySizeLimitValue != null && logsDirectorySizeLimitValue.Type != JTokenType.Null)
- {
- int logsDirectorySizeLimitInstance = ((int)logsDirectorySizeLimitValue);
- siteConfigInstance.LogsDirectorySizeLimit = logsDirectorySizeLimitInstance;
- }
-
- JToken managedPipelineModeValue = siteConfigValue["managedPipelineMode"];
- if (managedPipelineModeValue != null && managedPipelineModeValue.Type != JTokenType.Null)
- {
- ManagedPipelineMode managedPipelineModeInstance = ((ManagedPipelineMode)Enum.Parse(typeof(ManagedPipelineMode), ((string)managedPipelineModeValue), true));
- siteConfigInstance.ManagedPipelineMode = managedPipelineModeInstance;
- }
-
- JToken metadataSequenceElement2 = ((JToken)siteConfigValue["metadata"]);
- if (metadataSequenceElement2 != null && metadataSequenceElement2.Type != JTokenType.Null)
- {
- foreach (JProperty property5 in metadataSequenceElement2)
- {
- string metadataKey2 = ((string)property5.Name);
- string metadataValue2 = ((string)property5.Value);
- siteConfigInstance.Metadata.Add(metadataKey2, metadataValue2);
- }
- }
-
- JToken netFrameworkVersionValue = siteConfigValue["netFrameworkVersion"];
- if (netFrameworkVersionValue != null && netFrameworkVersionValue.Type != JTokenType.Null)
- {
- string netFrameworkVersionInstance = ((string)netFrameworkVersionValue);
- siteConfigInstance.NetFrameworkVersion = netFrameworkVersionInstance;
- }
-
- JToken numberOfWorkersValue = siteConfigValue["numberOfWorkers"];
- if (numberOfWorkersValue != null && numberOfWorkersValue.Type != JTokenType.Null)
- {
- int numberOfWorkersInstance = ((int)numberOfWorkersValue);
- siteConfigInstance.NumberOfWorkers = numberOfWorkersInstance;
- }
-
- JToken phpVersionValue = siteConfigValue["phpVersion"];
- if (phpVersionValue != null && phpVersionValue.Type != JTokenType.Null)
- {
- string phpVersionInstance = ((string)phpVersionValue);
- siteConfigInstance.PhpVersion = phpVersionInstance;
- }
-
- JToken pythonVersionValue = siteConfigValue["pythonVersion"];
- if (pythonVersionValue != null && pythonVersionValue.Type != JTokenType.Null)
- {
- string pythonVersionInstance = ((string)pythonVersionValue);
- siteConfigInstance.PythonVersion = pythonVersionInstance;
- }
-
- JToken publishingPasswordValue = siteConfigValue["publishingPassword"];
- if (publishingPasswordValue != null && publishingPasswordValue.Type != JTokenType.Null)
- {
- string publishingPasswordInstance = ((string)publishingPasswordValue);
- siteConfigInstance.PublishingPassword = publishingPasswordInstance;
- }
-
- JToken publishingUsernameValue = siteConfigValue["publishingUsername"];
- if (publishingUsernameValue != null && publishingUsernameValue.Type != JTokenType.Null)
- {
- string publishingUsernameInstance = ((string)publishingUsernameValue);
- siteConfigInstance.PublishingUserName = publishingUsernameInstance;
- }
-
- JToken remoteDebuggingEnabledValue = siteConfigValue["RemoteDebuggingEnabled"];
- if (remoteDebuggingEnabledValue != null && remoteDebuggingEnabledValue.Type != JTokenType.Null)
- {
- bool remoteDebuggingEnabledInstance = ((bool)remoteDebuggingEnabledValue);
- siteConfigInstance.RemoteDebuggingEnabled = remoteDebuggingEnabledInstance;
- }
-
- JToken remoteDebuggingVersionValue = siteConfigValue["remoteDebuggingVersion"];
- if (remoteDebuggingVersionValue != null && remoteDebuggingVersionValue.Type != JTokenType.Null)
- {
- RemoteDebuggingVersion remoteDebuggingVersionInstance = ((RemoteDebuggingVersion)Enum.Parse(typeof(RemoteDebuggingVersion), ((string)remoteDebuggingVersionValue), true));
- siteConfigInstance.RemoteDebuggingVersion = remoteDebuggingVersionInstance;
- }
-
- JToken requestTracingEnabledValue = siteConfigValue["requestTracingEnabled"];
- if (requestTracingEnabledValue != null && requestTracingEnabledValue.Type != JTokenType.Null)
- {
- bool requestTracingEnabledInstance = ((bool)requestTracingEnabledValue);
- siteConfigInstance.RequestTracingEnabled = requestTracingEnabledInstance;
- }
-
- JToken requestTracingExpirationTimeValue = siteConfigValue["requestTracingExpirationTime"];
- if (requestTracingExpirationTimeValue != null && requestTracingExpirationTimeValue.Type != JTokenType.Null)
- {
- DateTime requestTracingExpirationTimeInstance = ((DateTime)requestTracingExpirationTimeValue);
- siteConfigInstance.RequestTracingExpirationTime = requestTracingExpirationTimeInstance;
- }
-
- JToken scmTypeValue = siteConfigValue["scmType"];
- if (scmTypeValue != null && scmTypeValue.Type != JTokenType.Null)
- {
- string scmTypeInstance = ((string)scmTypeValue);
- siteConfigInstance.ScmType = scmTypeInstance;
- }
-
- JToken autoSwapSlotNameValue = siteConfigValue["autoSwapSlotName"];
- if (autoSwapSlotNameValue != null && autoSwapSlotNameValue.Type != JTokenType.Null)
- {
- string autoSwapSlotNameInstance = ((string)autoSwapSlotNameValue);
- siteConfigInstance.AutoSwapSlotName = autoSwapSlotNameInstance;
- }
-
- JToken use32BitWorkerProcessValue = siteConfigValue["use32BitWorkerProcess"];
- if (use32BitWorkerProcessValue != null && use32BitWorkerProcessValue.Type != JTokenType.Null)
- {
- bool use32BitWorkerProcessInstance = ((bool)use32BitWorkerProcessValue);
- siteConfigInstance.Use32BitWorkerProcess = use32BitWorkerProcessInstance;
- }
-
- JToken webSocketsEnabledValue = siteConfigValue["webSocketsEnabled"];
- if (webSocketsEnabledValue != null && webSocketsEnabledValue.Type != JTokenType.Null)
- {
- bool webSocketsEnabledInstance = ((bool)webSocketsEnabledValue);
- siteConfigInstance.WebSocketsEnabled = webSocketsEnabledInstance;
- }
-
- JToken limitsValue = siteConfigValue["limits"];
- if (limitsValue != null && limitsValue.Type != JTokenType.Null)
- {
- SiteLimits limitsInstance = new SiteLimits();
- siteConfigInstance.Limits = limitsInstance;
-
- JToken maxPercentageCpuValue = limitsValue["maxPercentageCpu"];
- if (maxPercentageCpuValue != null && maxPercentageCpuValue.Type != JTokenType.Null)
- {
- double maxPercentageCpuInstance = ((double)maxPercentageCpuValue);
- limitsInstance.MaxPercentageCpu = maxPercentageCpuInstance;
- }
-
- JToken maxMemoryInMbValue = limitsValue["maxMemoryInMb"];
- if (maxMemoryInMbValue != null && maxMemoryInMbValue.Type != JTokenType.Null)
- {
- long maxMemoryInMbInstance = ((long)maxMemoryInMbValue);
- limitsInstance.MaxMemoryInMb = maxMemoryInMbInstance;
- }
-
- JToken maxDiskSizeInMbValue = limitsValue["maxDiskSizeInMb"];
- if (maxDiskSizeInMbValue != null && maxDiskSizeInMbValue.Type != JTokenType.Null)
- {
- long maxDiskSizeInMbInstance = ((long)maxDiskSizeInMbValue);
- limitsInstance.MaxDiskSizeInMb = maxDiskSizeInMbInstance;
- }
- }
- }
-
- JToken stateValue = propertiesValue["state"];
- if (stateValue != null && stateValue.Type != JTokenType.Null)
- {
- WebSiteState stateInstance = ((WebSiteState)Enum.Parse(typeof(WebSiteState), ((string)stateValue), true));
- propertiesInstance.State = stateInstance;
- }
-
- JToken usageStateValue = propertiesValue["usageState"];
- if (usageStateValue != null && usageStateValue.Type != JTokenType.Null)
- {
- WebSiteUsageState usageStateInstance = ((WebSiteUsageState)Enum.Parse(typeof(WebSiteUsageState), ((string)usageStateValue), true));
- propertiesInstance.UsageState = usageStateInstance;
- }
-
- JToken webSpaceValue = propertiesValue["webSpace"];
- if (webSpaceValue != null && webSpaceValue.Type != JTokenType.Null)
- {
- string webSpaceInstance = ((string)webSpaceValue);
- propertiesInstance.WebSpace = webSpaceInstance;
- }
-
- JToken provisioningStateValue = propertiesValue["provisioningState"];
- if (provisioningStateValue != null && provisioningStateValue.Type != JTokenType.Null)
- {
- string provisioningStateInstance = ((string)provisioningStateValue);
- propertiesInstance.ProvisioningState = provisioningStateInstance;
- }
- }
-
- JToken idValue = responseDoc["id"];
- if (idValue != null && idValue.Type != JTokenType.Null)
- {
- string idInstance = ((string)idValue);
- webSiteInstance.Id = idInstance;
- }
-
- JToken nameValue3 = responseDoc["name"];
- if (nameValue3 != null && nameValue3.Type != JTokenType.Null)
- {
- string nameInstance3 = ((string)nameValue3);
- webSiteInstance.Name = nameInstance3;
- }
-
- JToken locationValue = responseDoc["location"];
- if (locationValue != null && locationValue.Type != JTokenType.Null)
- {
- string locationInstance = ((string)locationValue);
- webSiteInstance.Location = locationInstance;
- }
-
- JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
- if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property6 in tagsSequenceElement)
- {
- string tagsKey = ((string)property6.Name);
- string tagsValue = ((string)property6.Value);
- webSiteInstance.Tags.Add(tagsKey, tagsValue);
- }
- }
-
- JToken typeValue2 = responseDoc["type"];
- if (typeValue2 != null && typeValue2.Type != JTokenType.Null)
- {
- string typeInstance2 = ((string)typeValue2);
- webSiteInstance.Type = typeInstance2;
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// Restart the web site.
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group
- /// </param>
- /// <param name='webSiteName'>
- /// Required. Name of website
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot of the website
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// List of app settings for the website.
- /// </returns>
- public async Task<WebSiteAppSettingsResult> GetAppSettingsAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- TracingAdapter.Enter(invocationId, this, "GetAppSettingsAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/config/appsettings/list";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Post;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteAppSettingsResult result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteAppSettingsResult();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- if (responseDoc != null && responseDoc.Type != JTokenType.Null)
- {
- WebSiteAppSettingsEnvelope resourceInstance = new WebSiteAppSettingsEnvelope();
- result.Resource = resourceInstance;
-
- JToken propertiesArray = responseDoc["properties"];
- if (propertiesArray != null && propertiesArray.Type != JTokenType.Null)
- {
- foreach (JToken propertiesValue in ((JArray)propertiesArray))
- {
- NameValuePair nameValuePairInstance = new NameValuePair();
- resourceInstance.Properties.Add(nameValuePairInstance);
-
- JToken nameValue = propertiesValue["name"];
- if (nameValue != null && nameValue.Type != JTokenType.Null)
- {
- string nameInstance = ((string)nameValue);
- nameValuePairInstance.Name = nameInstance;
- }
-
- JToken valueValue = propertiesValue["value"];
- if (valueValue != null && valueValue.Type != JTokenType.Null)
- {
- string valueInstance = ((string)valueValue);
- nameValuePairInstance.Value = valueInstance;
- }
- }
- }
-
- JToken idValue = responseDoc["id"];
- if (idValue != null && idValue.Type != JTokenType.Null)
- {
- string idInstance = ((string)idValue);
- resourceInstance.Id = idInstance;
- }
-
- JToken nameValue2 = responseDoc["name"];
- if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
- {
- string nameInstance2 = ((string)nameValue2);
- resourceInstance.Name = nameInstance2;
- }
-
- JToken locationValue = responseDoc["location"];
- if (locationValue != null && locationValue.Type != JTokenType.Null)
- {
- string locationInstance = ((string)locationValue);
- resourceInstance.Location = locationInstance;
- }
-
- JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
- if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property in tagsSequenceElement)
- {
- string tagsKey = ((string)property.Name);
- string tagsValue = ((string)property.Value);
- resourceInstance.Tags.Add(tagsKey, tagsValue);
- }
- }
-
- JToken typeValue = responseDoc["type"];
- if (typeValue != null && typeValue.Type != JTokenType.Null)
- {
- string typeInstance = ((string)typeValue);
- resourceInstance.Type = typeInstance;
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// Gets a schedule configuration for site backups.
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the web space.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// Scheduled backup definition.
- /// </returns>
- public async Task<WebSiteGetBackupConfigurationResponse> GetBackupConfigurationAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- TracingAdapter.Enter(invocationId, this, "GetBackupConfigurationAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/backup/config";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Get;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
- httpRequest.Headers.Add("x-ms-version", "2014-06-01");
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteGetBackupConfigurationResponse result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteGetBackupConfigurationResponse();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- if (responseDoc != null && responseDoc.Type != JTokenType.Null)
- {
- BackupScheduleRequestEnvelope backupScheduleInstance = new BackupScheduleRequestEnvelope();
- result.BackupSchedule = backupScheduleInstance;
-
- JToken propertiesValue = responseDoc["properties"];
- if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
- {
- BackupScheduleRequestResponse propertiesInstance = new BackupScheduleRequestResponse();
- backupScheduleInstance.Properties = propertiesInstance;
-
- JToken enabledValue = propertiesValue["enabled"];
- if (enabledValue != null && enabledValue.Type != JTokenType.Null)
- {
- bool enabledInstance = ((bool)enabledValue);
- propertiesInstance.Enabled = enabledInstance;
- }
-
- JToken nameValue = propertiesValue["name"];
- if (nameValue != null && nameValue.Type != JTokenType.Null)
- {
- string nameInstance = ((string)nameValue);
- propertiesInstance.Name = nameInstance;
- }
-
- JToken storageAccountUrlValue = propertiesValue["storageAccountUrl"];
- if (storageAccountUrlValue != null && storageAccountUrlValue.Type != JTokenType.Null)
- {
- string storageAccountUrlInstance = ((string)storageAccountUrlValue);
- propertiesInstance.StorageAccountUrl = storageAccountUrlInstance;
- }
-
- JToken backupScheduleValue = propertiesValue["backupSchedule"];
- if (backupScheduleValue != null && backupScheduleValue.Type != JTokenType.Null)
- {
- BackupSchedule backupScheduleInstance2 = new BackupSchedule();
- propertiesInstance.BackupSchedule = backupScheduleInstance2;
-
- JToken frequencyIntervalValue = backupScheduleValue["frequencyInterval"];
- if (frequencyIntervalValue != null && frequencyIntervalValue.Type != JTokenType.Null)
- {
- int frequencyIntervalInstance = ((int)frequencyIntervalValue);
- backupScheduleInstance2.FrequencyInterval = frequencyIntervalInstance;
- }
-
- JToken frequencyUnitValue = backupScheduleValue["frequencyUnit"];
- if (frequencyUnitValue != null && frequencyUnitValue.Type != JTokenType.Null)
- {
- FrequencyUnit frequencyUnitInstance = ((FrequencyUnit)Enum.Parse(typeof(FrequencyUnit), ((string)frequencyUnitValue), true));
- backupScheduleInstance2.FrequencyUnit = frequencyUnitInstance;
- }
-
- JToken keepAtLeastOneBackupValue = backupScheduleValue["keepAtLeastOneBackup"];
- if (keepAtLeastOneBackupValue != null && keepAtLeastOneBackupValue.Type != JTokenType.Null)
- {
- bool keepAtLeastOneBackupInstance = ((bool)keepAtLeastOneBackupValue);
- backupScheduleInstance2.KeepAtLeastOneBackup = keepAtLeastOneBackupInstance;
- }
-
- JToken lastExecutionTimeValue = backupScheduleValue["lastExecutionTime"];
- if (lastExecutionTimeValue != null && lastExecutionTimeValue.Type != JTokenType.Null)
- {
- DateTime lastExecutionTimeInstance = ((DateTime)lastExecutionTimeValue);
- backupScheduleInstance2.LastExecutionTime = lastExecutionTimeInstance;
- }
-
- JToken retentionPeriodInDaysValue = backupScheduleValue["retentionPeriodInDays"];
- if (retentionPeriodInDaysValue != null && retentionPeriodInDaysValue.Type != JTokenType.Null)
- {
- int retentionPeriodInDaysInstance = ((int)retentionPeriodInDaysValue);
- backupScheduleInstance2.RetentionPeriodInDays = retentionPeriodInDaysInstance;
- }
-
- JToken startTimeValue = backupScheduleValue["startTime"];
- if (startTimeValue != null && startTimeValue.Type != JTokenType.Null)
- {
- DateTime startTimeInstance = ((DateTime)startTimeValue);
- backupScheduleInstance2.StartTime = startTimeInstance;
- }
- }
-
- JToken databasesArray = propertiesValue["databases"];
- if (databasesArray != null && databasesArray.Type != JTokenType.Null)
- {
- foreach (JToken databasesValue in ((JArray)databasesArray))
- {
- DatabaseBackupSetting databaseBackupSettingInstance = new DatabaseBackupSetting();
- propertiesInstance.Databases.Add(databaseBackupSettingInstance);
-
- JToken connectionStringValue = databasesValue["connectionString"];
- if (connectionStringValue != null && connectionStringValue.Type != JTokenType.Null)
- {
- string connectionStringInstance = ((string)connectionStringValue);
- databaseBackupSettingInstance.ConnectionString = connectionStringInstance;
- }
-
- JToken connectionStringNameValue = databasesValue["connectionStringName"];
- if (connectionStringNameValue != null && connectionStringNameValue.Type != JTokenType.Null)
- {
- string connectionStringNameInstance = ((string)connectionStringNameValue);
- databaseBackupSettingInstance.ConnectionStringName = connectionStringNameInstance;
- }
-
- JToken databaseTypeValue = databasesValue["databaseType"];
- if (databaseTypeValue != null && databaseTypeValue.Type != JTokenType.Null)
- {
- string databaseTypeInstance = ((string)databaseTypeValue);
- databaseBackupSettingInstance.DatabaseType = databaseTypeInstance;
- }
-
- JToken nameValue2 = databasesValue["name"];
- if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
- {
- string nameInstance2 = ((string)nameValue2);
- databaseBackupSettingInstance.Name = nameInstance2;
- }
- }
- }
- }
-
- JToken idValue = responseDoc["id"];
- if (idValue != null && idValue.Type != JTokenType.Null)
- {
- string idInstance = ((string)idValue);
- backupScheduleInstance.Id = idInstance;
- }
-
- JToken nameValue3 = responseDoc["name"];
- if (nameValue3 != null && nameValue3.Type != JTokenType.Null)
- {
- string nameInstance3 = ((string)nameValue3);
- backupScheduleInstance.Name = nameInstance3;
- }
-
- JToken locationValue = responseDoc["location"];
- if (locationValue != null && locationValue.Type != JTokenType.Null)
- {
- string locationInstance = ((string)locationValue);
- backupScheduleInstance.Location = locationInstance;
- }
-
- JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
- if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property in tagsSequenceElement)
- {
- string tagsKey = ((string)property.Name);
- string tagsValue = ((string)property.Value);
- backupScheduleInstance.Tags.Add(tagsKey, tagsValue);
- }
- }
-
- JToken typeValue = responseDoc["type"];
- if (typeValue != null && typeValue.Type != JTokenType.Null)
- {
- string typeInstance = ((string)typeValue);
- backupScheduleInstance.Type = typeInstance;
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// You can retrieve the config settings for a web site by issuing an
- /// HTTP GET request, or update them by using HTTP PUT with a request
- /// body that contains the settings to be updated. (see
- /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166985.aspx
- /// for more information)
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='parameters'>
- /// Optional. Additional parameters.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// Config for the website.
- /// </returns>
- public async Task<WebSiteGetConfigurationResult> GetConfigurationAsync(string resourceGroupName, string webSiteName, string slotName, WebSiteGetConfigurationParameters parameters, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- tracingParameters.Add("parameters", parameters);
- TracingAdapter.Enter(invocationId, this, "GetConfigurationAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/config/web";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (parameters != null && parameters.PropertiesToInclude != null && parameters.PropertiesToInclude.Count > 0)
- {
- queryParameters.Add("propertiesToInclude=" + Uri.EscapeDataString(string.Join(",", parameters.PropertiesToInclude)));
- }
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Get;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteGetConfigurationResult result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteGetConfigurationResult();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- if (responseDoc != null && responseDoc.Type != JTokenType.Null)
- {
- WebSiteConfigurationEnvelope resourceInstance = new WebSiteConfigurationEnvelope();
- result.Resource = resourceInstance;
-
- JToken propertiesValue = responseDoc["properties"];
- if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
- {
- WebSiteConfiguration propertiesInstance = new WebSiteConfiguration();
- resourceInstance.Properties = propertiesInstance;
-
- JToken appSettingsSequenceElement = ((JToken)propertiesValue["appSettings"]);
- if (appSettingsSequenceElement != null && appSettingsSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property in appSettingsSequenceElement)
- {
- string appSettingsKey = ((string)property.Name);
- string appSettingsValue = ((string)property.Value);
- propertiesInstance.AppSettings.Add(appSettingsKey, appSettingsValue);
- }
- }
-
- JToken connectionStringsArray = propertiesValue["connectionStrings"];
- if (connectionStringsArray != null && connectionStringsArray.Type != JTokenType.Null)
- {
- foreach (JToken connectionStringsValue in ((JArray)connectionStringsArray))
- {
- ConnectionStringInfo connStringInfoInstance = new ConnectionStringInfo();
- propertiesInstance.ConnectionStrings.Add(connStringInfoInstance);
-
- JToken connectionStringValue = connectionStringsValue["connectionString"];
- if (connectionStringValue != null && connectionStringValue.Type != JTokenType.Null)
- {
- string connectionStringInstance = ((string)connectionStringValue);
- connStringInfoInstance.ConnectionString = connectionStringInstance;
- }
-
- JToken nameValue = connectionStringsValue["name"];
- if (nameValue != null && nameValue.Type != JTokenType.Null)
- {
- string nameInstance = ((string)nameValue);
- connStringInfoInstance.Name = nameInstance;
- }
-
- JToken typeValue = connectionStringsValue["type"];
- if (typeValue != null && typeValue.Type != JTokenType.Null)
- {
- DatabaseServerType typeInstance = ((DatabaseServerType)Enum.Parse(typeof(DatabaseServerType), ((string)typeValue), true));
- connStringInfoInstance.Type = typeInstance;
- }
- }
- }
-
- JToken defaultDocumentsArray = propertiesValue["defaultDocuments"];
- if (defaultDocumentsArray != null && defaultDocumentsArray.Type != JTokenType.Null)
- {
- foreach (JToken defaultDocumentsValue in ((JArray)defaultDocumentsArray))
- {
- propertiesInstance.DefaultDocuments.Add(((string)defaultDocumentsValue));
- }
- }
-
- JToken detailedErrorLoggingEnabledValue = propertiesValue["detailedErrorLoggingEnabled"];
- if (detailedErrorLoggingEnabledValue != null && detailedErrorLoggingEnabledValue.Type != JTokenType.Null)
- {
- bool detailedErrorLoggingEnabledInstance = ((bool)detailedErrorLoggingEnabledValue);
- propertiesInstance.DetailedErrorLoggingEnabled = detailedErrorLoggingEnabledInstance;
- }
-
- JToken documentRootValue = propertiesValue["documentRoot"];
- if (documentRootValue != null && documentRootValue.Type != JTokenType.Null)
- {
- string documentRootInstance = ((string)documentRootValue);
- propertiesInstance.DocumentRoot = documentRootInstance;
- }
-
- JToken handlerMappingsArray = propertiesValue["handlerMappings"];
- if (handlerMappingsArray != null && handlerMappingsArray.Type != JTokenType.Null)
- {
- foreach (JToken handlerMappingsValue in ((JArray)handlerMappingsArray))
- {
- WebSiteConfiguration.HandlerMapping handlerMappingInstance = new WebSiteConfiguration.HandlerMapping();
- propertiesInstance.HandlerMappings.Add(handlerMappingInstance);
-
- JToken argumentsValue = handlerMappingsValue["arguments"];
- if (argumentsValue != null && argumentsValue.Type != JTokenType.Null)
- {
- string argumentsInstance = ((string)argumentsValue);
- handlerMappingInstance.Arguments = argumentsInstance;
- }
-
- JToken extensionValue = handlerMappingsValue["extension"];
- if (extensionValue != null && extensionValue.Type != JTokenType.Null)
- {
- string extensionInstance = ((string)extensionValue);
- handlerMappingInstance.Extension = extensionInstance;
- }
-
- JToken scriptProcessorValue = handlerMappingsValue["scriptProcessor"];
- if (scriptProcessorValue != null && scriptProcessorValue.Type != JTokenType.Null)
- {
- string scriptProcessorInstance = ((string)scriptProcessorValue);
- handlerMappingInstance.ScriptProcessor = scriptProcessorInstance;
- }
- }
- }
-
- JToken httpLoggingEnabledValue = propertiesValue["httpLoggingEnabled"];
- if (httpLoggingEnabledValue != null && httpLoggingEnabledValue.Type != JTokenType.Null)
- {
- bool httpLoggingEnabledInstance = ((bool)httpLoggingEnabledValue);
- propertiesInstance.HttpLoggingEnabled = httpLoggingEnabledInstance;
- }
-
- JToken logsDirectorySizeLimitValue = propertiesValue["logsDirectorySizeLimit"];
- if (logsDirectorySizeLimitValue != null && logsDirectorySizeLimitValue.Type != JTokenType.Null)
- {
- int logsDirectorySizeLimitInstance = ((int)logsDirectorySizeLimitValue);
- propertiesInstance.LogsDirectorySizeLimit = logsDirectorySizeLimitInstance;
- }
-
- JToken managedPipelineModeValue = propertiesValue["managedPipelineMode"];
- if (managedPipelineModeValue != null && managedPipelineModeValue.Type != JTokenType.Null)
- {
- ManagedPipelineMode managedPipelineModeInstance = ((ManagedPipelineMode)Enum.Parse(typeof(ManagedPipelineMode), ((string)managedPipelineModeValue), true));
- propertiesInstance.ManagedPipelineMode = managedPipelineModeInstance;
- }
-
- JToken metadataSequenceElement = ((JToken)propertiesValue["metadata"]);
- if (metadataSequenceElement != null && metadataSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property2 in metadataSequenceElement)
- {
- string metadataKey = ((string)property2.Name);
- string metadataValue = ((string)property2.Value);
- propertiesInstance.Metadata.Add(metadataKey, metadataValue);
- }
- }
-
- JToken netFrameworkVersionValue = propertiesValue["netFrameworkVersion"];
- if (netFrameworkVersionValue != null && netFrameworkVersionValue.Type != JTokenType.Null)
- {
- string netFrameworkVersionInstance = ((string)netFrameworkVersionValue);
- propertiesInstance.NetFrameworkVersion = netFrameworkVersionInstance;
- }
-
- JToken numberOfWorkersValue = propertiesValue["numberOfWorkers"];
- if (numberOfWorkersValue != null && numberOfWorkersValue.Type != JTokenType.Null)
- {
- int numberOfWorkersInstance = ((int)numberOfWorkersValue);
- propertiesInstance.NumberOfWorkers = numberOfWorkersInstance;
- }
-
- JToken phpVersionValue = propertiesValue["phpVersion"];
- if (phpVersionValue != null && phpVersionValue.Type != JTokenType.Null)
- {
- string phpVersionInstance = ((string)phpVersionValue);
- propertiesInstance.PhpVersion = phpVersionInstance;
- }
-
- JToken pythonVersionValue = propertiesValue["pythonVersion"];
- if (pythonVersionValue != null && pythonVersionValue.Type != JTokenType.Null)
- {
- string pythonVersionInstance = ((string)pythonVersionValue);
- propertiesInstance.PythonVersion = pythonVersionInstance;
- }
-
- JToken publishingPasswordValue = propertiesValue["publishingPassword"];
- if (publishingPasswordValue != null && publishingPasswordValue.Type != JTokenType.Null)
- {
- string publishingPasswordInstance = ((string)publishingPasswordValue);
- propertiesInstance.PublishingPassword = publishingPasswordInstance;
- }
-
- JToken publishingUsernameValue = propertiesValue["publishingUsername"];
- if (publishingUsernameValue != null && publishingUsernameValue.Type != JTokenType.Null)
- {
- string publishingUsernameInstance = ((string)publishingUsernameValue);
- propertiesInstance.PublishingUserName = publishingUsernameInstance;
- }
-
- JToken remoteDebuggingEnabledValue = propertiesValue["RemoteDebuggingEnabled"];
- if (remoteDebuggingEnabledValue != null && remoteDebuggingEnabledValue.Type != JTokenType.Null)
- {
- bool remoteDebuggingEnabledInstance = ((bool)remoteDebuggingEnabledValue);
- propertiesInstance.RemoteDebuggingEnabled = remoteDebuggingEnabledInstance;
- }
-
- JToken remoteDebuggingVersionValue = propertiesValue["remoteDebuggingVersion"];
- if (remoteDebuggingVersionValue != null && remoteDebuggingVersionValue.Type != JTokenType.Null)
- {
- RemoteDebuggingVersion remoteDebuggingVersionInstance = ((RemoteDebuggingVersion)Enum.Parse(typeof(RemoteDebuggingVersion), ((string)remoteDebuggingVersionValue), true));
- propertiesInstance.RemoteDebuggingVersion = remoteDebuggingVersionInstance;
- }
-
- JToken requestTracingEnabledValue = propertiesValue["requestTracingEnabled"];
- if (requestTracingEnabledValue != null && requestTracingEnabledValue.Type != JTokenType.Null)
- {
- bool requestTracingEnabledInstance = ((bool)requestTracingEnabledValue);
- propertiesInstance.RequestTracingEnabled = requestTracingEnabledInstance;
- }
-
- JToken requestTracingExpirationTimeValue = propertiesValue["requestTracingExpirationTime"];
- if (requestTracingExpirationTimeValue != null && requestTracingExpirationTimeValue.Type != JTokenType.Null)
- {
- DateTime requestTracingExpirationTimeInstance = ((DateTime)requestTracingExpirationTimeValue);
- propertiesInstance.RequestTracingExpirationTime = requestTracingExpirationTimeInstance;
- }
-
- JToken scmTypeValue = propertiesValue["scmType"];
- if (scmTypeValue != null && scmTypeValue.Type != JTokenType.Null)
- {
- string scmTypeInstance = ((string)scmTypeValue);
- propertiesInstance.ScmType = scmTypeInstance;
- }
-
- JToken autoSwapSlotNameValue = propertiesValue["autoSwapSlotName"];
- if (autoSwapSlotNameValue != null && autoSwapSlotNameValue.Type != JTokenType.Null)
- {
- string autoSwapSlotNameInstance = ((string)autoSwapSlotNameValue);
- propertiesInstance.AutoSwapSlotName = autoSwapSlotNameInstance;
- }
-
- JToken use32BitWorkerProcessValue = propertiesValue["use32BitWorkerProcess"];
- if (use32BitWorkerProcessValue != null && use32BitWorkerProcessValue.Type != JTokenType.Null)
- {
- bool use32BitWorkerProcessInstance = ((bool)use32BitWorkerProcessValue);
- propertiesInstance.Use32BitWorkerProcess = use32BitWorkerProcessInstance;
- }
-
- JToken webSocketsEnabledValue = propertiesValue["webSocketsEnabled"];
- if (webSocketsEnabledValue != null && webSocketsEnabledValue.Type != JTokenType.Null)
- {
- bool webSocketsEnabledInstance = ((bool)webSocketsEnabledValue);
- propertiesInstance.WebSocketsEnabled = webSocketsEnabledInstance;
- }
-
- JToken limitsValue = propertiesValue["limits"];
- if (limitsValue != null && limitsValue.Type != JTokenType.Null)
- {
- SiteLimits limitsInstance = new SiteLimits();
- propertiesInstance.Limits = limitsInstance;
-
- JToken maxPercentageCpuValue = limitsValue["maxPercentageCpu"];
- if (maxPercentageCpuValue != null && maxPercentageCpuValue.Type != JTokenType.Null)
- {
- double maxPercentageCpuInstance = ((double)maxPercentageCpuValue);
- limitsInstance.MaxPercentageCpu = maxPercentageCpuInstance;
- }
-
- JToken maxMemoryInMbValue = limitsValue["maxMemoryInMb"];
- if (maxMemoryInMbValue != null && maxMemoryInMbValue.Type != JTokenType.Null)
- {
- long maxMemoryInMbInstance = ((long)maxMemoryInMbValue);
- limitsInstance.MaxMemoryInMb = maxMemoryInMbInstance;
- }
-
- JToken maxDiskSizeInMbValue = limitsValue["maxDiskSizeInMb"];
- if (maxDiskSizeInMbValue != null && maxDiskSizeInMbValue.Type != JTokenType.Null)
- {
- long maxDiskSizeInMbInstance = ((long)maxDiskSizeInMbValue);
- limitsInstance.MaxDiskSizeInMb = maxDiskSizeInMbInstance;
- }
- }
- }
-
- JToken idValue = responseDoc["id"];
- if (idValue != null && idValue.Type != JTokenType.Null)
- {
- string idInstance = ((string)idValue);
- resourceInstance.Id = idInstance;
- }
-
- JToken nameValue2 = responseDoc["name"];
- if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
- {
- string nameInstance2 = ((string)nameValue2);
- resourceInstance.Name = nameInstance2;
- }
-
- JToken locationValue = responseDoc["location"];
- if (locationValue != null && locationValue.Type != JTokenType.Null)
- {
- string locationInstance = ((string)locationValue);
- resourceInstance.Location = locationInstance;
- }
-
- JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
- if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property3 in tagsSequenceElement)
- {
- string tagsKey = ((string)property3.Name);
- string tagsValue = ((string)property3.Value);
- resourceInstance.Tags.Add(tagsKey, tagsValue);
- }
- }
-
- JToken typeValue2 = responseDoc["type"];
- if (typeValue2 != null && typeValue2.Type != JTokenType.Null)
- {
- string typeInstance2 = ((string)typeValue2);
- resourceInstance.Type = typeInstance2;
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// Restart the web site.
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group
- /// </param>
- /// <param name='webSiteName'>
- /// Required. Name of website
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot of the web site
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// List of connection strings for the website.
- /// </returns>
- public async Task<WebSiteConnectionStringsResult> GetConnectionStringsAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- TracingAdapter.Enter(invocationId, this, "GetConnectionStringsAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/config/connectionstrings/list";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Post;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteConnectionStringsResult result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteConnectionStringsResult();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- if (responseDoc != null && responseDoc.Type != JTokenType.Null)
- {
- WebSiteConnectionStringsEnvelope resourceInstance = new WebSiteConnectionStringsEnvelope();
- result.Resource = resourceInstance;
-
- JToken propertiesArray = responseDoc["properties"];
- if (propertiesArray != null && propertiesArray.Type != JTokenType.Null)
- {
- foreach (JToken propertiesValue in ((JArray)propertiesArray))
- {
- ConnectionStringInfo connStringInfoInstance = new ConnectionStringInfo();
- resourceInstance.Properties.Add(connStringInfoInstance);
-
- JToken connectionStringValue = propertiesValue["connectionString"];
- if (connectionStringValue != null && connectionStringValue.Type != JTokenType.Null)
- {
- string connectionStringInstance = ((string)connectionStringValue);
- connStringInfoInstance.ConnectionString = connectionStringInstance;
- }
-
- JToken nameValue = propertiesValue["name"];
- if (nameValue != null && nameValue.Type != JTokenType.Null)
- {
- string nameInstance = ((string)nameValue);
- connStringInfoInstance.Name = nameInstance;
- }
-
- JToken typeValue = propertiesValue["type"];
- if (typeValue != null && typeValue.Type != JTokenType.Null)
- {
- DatabaseServerType typeInstance = ((DatabaseServerType)Enum.Parse(typeof(DatabaseServerType), ((string)typeValue), true));
- connStringInfoInstance.Type = typeInstance;
- }
- }
- }
-
- JToken idValue = responseDoc["id"];
- if (idValue != null && idValue.Type != JTokenType.Null)
- {
- string idInstance = ((string)idValue);
- resourceInstance.Id = idInstance;
- }
-
- JToken nameValue2 = responseDoc["name"];
- if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
- {
- string nameInstance2 = ((string)nameValue2);
- resourceInstance.Name = nameInstance2;
- }
-
- JToken locationValue = responseDoc["location"];
- if (locationValue != null && locationValue.Type != JTokenType.Null)
- {
- string locationInstance = ((string)locationValue);
- resourceInstance.Location = locationInstance;
- }
-
- JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
- if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property in tagsSequenceElement)
- {
- string tagsKey = ((string)property.Name);
- string tagsValue = ((string)property.Value);
- resourceInstance.Tags.Add(tagsKey, tagsValue);
- }
- }
-
- JToken typeValue2 = responseDoc["type"];
- if (typeValue2 != null && typeValue2.Type != JTokenType.Null)
- {
- string typeInstance2 = ((string)typeValue2);
- resourceInstance.Type = typeInstance2;
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// You can retrieve historical usage metrics for a site by issuing an
- /// HTTP GET request. (see
- /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166964.aspx
- /// for more information)
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='parameters'>
- /// Required. The Get Web Site Historical Usage Metrics parameters.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// The Get Web Site Historical Usage Metrics operation response.
- /// </returns>
- public async Task<WebSiteGetHistoricalUsageMetricsResponse> GetHistoricalUsageMetricsAsync(string resourceGroupName, string webSiteName, string slotName, WebSiteGetHistoricalUsageMetricsParameters parameters, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
- if (parameters == null)
- {
- throw new ArgumentNullException("parameters");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- tracingParameters.Add("parameters", parameters);
- TracingAdapter.Enter(invocationId, this, "GetHistoricalUsageMetricsAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/metrics";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (parameters.MetricNames != null && parameters.MetricNames.Count > 0)
- {
- queryParameters.Add("names=" + Uri.EscapeDataString(string.Join(",", parameters.MetricNames)));
- }
- if (parameters.StartTime != null)
- {
- queryParameters.Add("StartTime=" + Uri.EscapeDataString(string.Format(CultureInfo.InvariantCulture, "{0:O}", parameters.StartTime.Value.ToUniversalTime())));
- }
- if (parameters.EndTime != null)
- {
- queryParameters.Add("EndTime=" + Uri.EscapeDataString(string.Format(CultureInfo.InvariantCulture, "{0:O}", parameters.EndTime.Value.ToUniversalTime())));
- }
- if (parameters.TimeGrain != null)
- {
- queryParameters.Add("timeGrain=" + Uri.EscapeDataString(parameters.TimeGrain));
- }
- queryParameters.Add("details=" + Uri.EscapeDataString(parameters.IncludeInstanceBreakdown.ToString().ToLower()));
- queryParameters.Add("slotView=" + Uri.EscapeDataString(parameters.SlotView.ToString().ToLower()));
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Get;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteGetHistoricalUsageMetricsResponse result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteGetHistoricalUsageMetricsResponse();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- if (responseDoc != null && responseDoc.Type != JTokenType.Null)
- {
- JToken propertiesArray = responseDoc["properties"];
- if (propertiesArray != null && propertiesArray.Type != JTokenType.Null)
- {
- foreach (JToken propertiesValue in ((JArray)propertiesArray))
- {
- HistoricalUsageMetric historicalUsageMetricInstance = new HistoricalUsageMetric();
- result.UsageMetrics.Add(historicalUsageMetricInstance);
-
- JToken codeValue = propertiesValue["code"];
- if (codeValue != null && codeValue.Type != JTokenType.Null)
- {
- string codeInstance = ((string)codeValue);
- historicalUsageMetricInstance.Code = codeInstance;
- }
-
- JToken dataValue = propertiesValue["data"];
- if (dataValue != null && dataValue.Type != JTokenType.Null)
- {
- HistoricalUsageMetricData dataInstance = new HistoricalUsageMetricData();
- historicalUsageMetricInstance.Data = dataInstance;
-
- JToken displayNameValue = dataValue["displayName"];
- if (displayNameValue != null && displayNameValue.Type != JTokenType.Null)
- {
- string displayNameInstance = ((string)displayNameValue);
- dataInstance.DisplayName = displayNameInstance;
- }
-
- JToken endTimeValue = dataValue["EndTime"];
- if (endTimeValue != null && endTimeValue.Type != JTokenType.Null)
- {
- DateTime endTimeInstance = ((DateTime)endTimeValue);
- dataInstance.EndTime = endTimeInstance;
- }
-
- JToken nameValue = dataValue["name"];
- if (nameValue != null && nameValue.Type != JTokenType.Null)
- {
- string nameInstance = ((string)nameValue);
- dataInstance.Name = nameInstance;
- }
-
- JToken primaryAggregationTypeValue = dataValue["primaryAggregationType"];
- if (primaryAggregationTypeValue != null && primaryAggregationTypeValue.Type != JTokenType.Null)
- {
- string primaryAggregationTypeInstance = ((string)primaryAggregationTypeValue);
- dataInstance.PrimaryAggregationType = primaryAggregationTypeInstance;
- }
-
- JToken startTimeValue = dataValue["startTime"];
- if (startTimeValue != null && startTimeValue.Type != JTokenType.Null)
- {
- DateTime startTimeInstance = ((DateTime)startTimeValue);
- dataInstance.StartTime = startTimeInstance;
- }
-
- JToken timeGrainValue = dataValue["timeGrain"];
- if (timeGrainValue != null && timeGrainValue.Type != JTokenType.Null)
- {
- string timeGrainInstance = ((string)timeGrainValue);
- dataInstance.TimeGrain = timeGrainInstance;
- }
-
- JToken unitValue = dataValue["unit"];
- if (unitValue != null && unitValue.Type != JTokenType.Null)
- {
- string unitInstance = ((string)unitValue);
- dataInstance.Unit = unitInstance;
- }
-
- JToken valuesArray = dataValue["values"];
- if (valuesArray != null && valuesArray.Type != JTokenType.Null)
- {
- foreach (JToken valuesValue in ((JArray)valuesArray))
- {
- HistoricalUsageMetricSample metricSampleInstance = new HistoricalUsageMetricSample();
- dataInstance.Values.Add(metricSampleInstance);
-
- JToken countValue = valuesValue["count"];
- if (countValue != null && countValue.Type != JTokenType.Null)
- {
- int countInstance = ((int)countValue);
- metricSampleInstance.Count = countInstance;
- }
-
- JToken maximumValue = valuesValue["maximum"];
- if (maximumValue != null && maximumValue.Type != JTokenType.Null)
- {
- string maximumInstance = ((string)maximumValue);
- metricSampleInstance.Maximum = maximumInstance;
- }
-
- JToken minimumValue = valuesValue["minimum"];
- if (minimumValue != null && minimumValue.Type != JTokenType.Null)
- {
- string minimumInstance = ((string)minimumValue);
- metricSampleInstance.Minimum = minimumInstance;
- }
-
- JToken timeCreatedValue = valuesValue["timeCreated"];
- if (timeCreatedValue != null && timeCreatedValue.Type != JTokenType.Null)
- {
- DateTime timeCreatedInstance = ((DateTime)timeCreatedValue);
- metricSampleInstance.TimeCreated = timeCreatedInstance;
- }
-
- JToken totalValue = valuesValue["total"];
- if (totalValue != null && totalValue.Type != JTokenType.Null)
- {
- string totalInstance = ((string)totalValue);
- metricSampleInstance.Total = totalInstance;
- }
-
- JToken instanceNameValue = valuesValue["instanceName"];
- if (instanceNameValue != null && instanceNameValue.Type != JTokenType.Null)
- {
- string instanceNameInstance = ((string)instanceNameValue);
- metricSampleInstance.InstanceName = instanceNameInstance;
- }
- }
- }
- }
-
- JToken messageValue = propertiesValue["message"];
- if (messageValue != null && messageValue.Type != JTokenType.Null)
- {
- string messageInstance = ((string)messageValue);
- historicalUsageMetricInstance.Message = messageInstance;
- }
- }
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// Restart the web site.
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group
- /// </param>
- /// <param name='webSiteName'>
- /// Required. Name of website
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot of the web site
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// List of metadata for the website.
- /// </returns>
- public async Task<WebSiteMetadataResult> GetMetadataAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- TracingAdapter.Enter(invocationId, this, "GetMetadataAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/config/metadata/list";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Post;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteMetadataResult result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteMetadataResult();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- if (responseDoc != null && responseDoc.Type != JTokenType.Null)
- {
- WebSiteMetadataEnvelope resourceInstance = new WebSiteMetadataEnvelope();
- result.Resource = resourceInstance;
-
- JToken propertiesArray = responseDoc["properties"];
- if (propertiesArray != null && propertiesArray.Type != JTokenType.Null)
- {
- foreach (JToken propertiesValue in ((JArray)propertiesArray))
- {
- NameValuePair nameValuePairInstance = new NameValuePair();
- resourceInstance.Properties.Add(nameValuePairInstance);
-
- JToken nameValue = propertiesValue["name"];
- if (nameValue != null && nameValue.Type != JTokenType.Null)
- {
- string nameInstance = ((string)nameValue);
- nameValuePairInstance.Name = nameInstance;
- }
-
- JToken valueValue = propertiesValue["value"];
- if (valueValue != null && valueValue.Type != JTokenType.Null)
- {
- string valueInstance = ((string)valueValue);
- nameValuePairInstance.Value = valueInstance;
- }
- }
- }
-
- JToken idValue = responseDoc["id"];
- if (idValue != null && idValue.Type != JTokenType.Null)
- {
- string idInstance = ((string)idValue);
- resourceInstance.Id = idInstance;
- }
-
- JToken nameValue2 = responseDoc["name"];
- if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
- {
- string nameInstance2 = ((string)nameValue2);
- resourceInstance.Name = nameInstance2;
- }
-
- JToken locationValue = responseDoc["location"];
- if (locationValue != null && locationValue.Type != JTokenType.Null)
- {
- string locationInstance = ((string)locationValue);
- resourceInstance.Location = locationInstance;
- }
-
- JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
- if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property in tagsSequenceElement)
- {
- string tagsKey = ((string)property.Name);
- string tagsValue = ((string)property.Value);
- resourceInstance.Tags.Add(tagsKey, tagsValue);
- }
- }
-
- JToken typeValue = responseDoc["type"];
- if (typeValue != null && typeValue.Type != JTokenType.Null)
- {
- string typeInstance = ((string)typeValue);
- resourceInstance.Type = typeInstance;
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// You can retrieve details for a web site by issuing an HTTP GET
- /// request. (see
- /// http://msdn.microsoft.com/en-us/library/windowsazure/dn167007.aspx
- /// for more information)
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='operationId'>
- /// Required. Additional parameters.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// The website operation response.
- /// </returns>
- public async Task<WebSiteAsyncOperationResponse> GetOperationAsync(string resourceGroupName, string webSiteName, string slotName, Guid operationId, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- tracingParameters.Add("operationId", operationId);
- TracingAdapter.Enter(invocationId, this, "GetOperationAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/operations/";
- url = url + Uri.EscapeDataString(operationId.ToString());
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Get;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.Created && statusCode != HttpStatusCode.Accepted)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteAsyncOperationResponse result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK || statusCode == HttpStatusCode.Created || statusCode == HttpStatusCode.Accepted)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteAsyncOperationResponse();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- if (responseDoc != null && responseDoc.Type != JTokenType.Null)
- {
- JToken locationValue = responseDoc["location"];
- if (locationValue != null && locationValue.Type != JTokenType.Null)
- {
- string locationInstance = ((string)locationValue);
- result.Location = locationInstance;
- }
-
- JToken retryAfterValue = responseDoc["retry-after"];
- if (retryAfterValue != null && retryAfterValue.Type != JTokenType.Null)
- {
- string retryAfterInstance = ((string)retryAfterValue);
- result.RetryAfter = retryAfterInstance;
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("location"))
- {
- result.Location = httpResponse.Headers.GetValues("location").FirstOrDefault();
- }
- if (httpResponse.Headers.Contains("retry-after"))
- {
- result.RetryAfter = httpResponse.Headers.GetValues("retry-after").FirstOrDefault();
- }
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// Get publishing credentials for the web site.
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. Name of website
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot of the web site.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// Publishing credentials for the website.
- /// </returns>
- public async Task<WebSitePublishingCredentialsResult> GetPublishingCredentialsAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- TracingAdapter.Enter(invocationId, this, "GetPublishingCredentialsAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/config/publishingcredentials/list";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Post;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSitePublishingCredentialsResult result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSitePublishingCredentialsResult();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- if (responseDoc != null && responseDoc.Type != JTokenType.Null)
- {
- WebSitePublishingCredentialsEnvelope resourceInstance = new WebSitePublishingCredentialsEnvelope();
- result.Resource = resourceInstance;
-
- JToken propertiesValue = responseDoc["properties"];
- if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
- {
- PublishingCredentials propertiesInstance = new PublishingCredentials();
- resourceInstance.Properties = propertiesInstance;
-
- JToken publishingPasswordValue = propertiesValue["publishingPassword"];
- if (publishingPasswordValue != null && publishingPasswordValue.Type != JTokenType.Null)
- {
- string publishingPasswordInstance = ((string)publishingPasswordValue);
- propertiesInstance.PublishingPassword = publishingPasswordInstance;
- }
-
- JToken publishingUserNameValue = propertiesValue["publishingUserName"];
- if (publishingUserNameValue != null && publishingUserNameValue.Type != JTokenType.Null)
- {
- string publishingUserNameInstance = ((string)publishingUserNameValue);
- propertiesInstance.PublishingUserName = publishingUserNameInstance;
- }
- }
-
- JToken idValue = responseDoc["id"];
- if (idValue != null && idValue.Type != JTokenType.Null)
- {
- string idInstance = ((string)idValue);
- resourceInstance.Id = idInstance;
- }
-
- JToken nameValue = responseDoc["name"];
- if (nameValue != null && nameValue.Type != JTokenType.Null)
- {
- string nameInstance = ((string)nameValue);
- resourceInstance.Name = nameInstance;
- }
-
- JToken locationValue = responseDoc["location"];
- if (locationValue != null && locationValue.Type != JTokenType.Null)
- {
- string locationInstance = ((string)locationValue);
- resourceInstance.Location = locationInstance;
- }
-
- JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
- if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property in tagsSequenceElement)
- {
- string tagsKey = ((string)property.Name);
- string tagsValue = ((string)property.Value);
- resourceInstance.Tags.Add(tagsKey, tagsValue);
- }
- }
-
- JToken typeValue = responseDoc["type"];
- if (typeValue != null && typeValue.Type != JTokenType.Null)
- {
- string typeInstance = ((string)typeValue);
- resourceInstance.Type = typeInstance;
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// Retrieve the publish settings information for a web site. (see
- /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166996.aspx
- /// for more information)
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// The Get Web Site Publish Profile operation response.
- /// </returns>
- public async Task<WebSiteGetPublishProfileResponse> GetPublishProfileAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- TracingAdapter.Enter(invocationId, this, "GetPublishProfileAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/publishxml";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Post;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteGetPublishProfileResponse result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteGetPublishProfileResponse();
- XDocument responseDoc = XDocument.Parse(responseContent);
-
- XElement publishDataSequenceElement = responseDoc.Element(XName.Get("publishData", ""));
- if (publishDataSequenceElement != null)
- {
- foreach (XElement publishDataElement in publishDataSequenceElement.Elements(XName.Get("publishProfile", "")))
- {
- WebSiteGetPublishProfileResponse.PublishProfile publishProfileInstance = new WebSiteGetPublishProfileResponse.PublishProfile();
- result.PublishProfiles.Add(publishProfileInstance);
-
- XAttribute profileNameAttribute = publishDataElement.Attribute(XName.Get("profileName", ""));
- if (profileNameAttribute != null)
- {
- publishProfileInstance.ProfileName = profileNameAttribute.Value;
- }
-
- XAttribute publishMethodAttribute = publishDataElement.Attribute(XName.Get("publishMethod", ""));
- if (publishMethodAttribute != null)
- {
- publishProfileInstance.PublishMethod = publishMethodAttribute.Value;
- }
-
- XAttribute publishUrlAttribute = publishDataElement.Attribute(XName.Get("publishUrl", ""));
- if (publishUrlAttribute != null)
- {
- publishProfileInstance.PublishUrl = publishUrlAttribute.Value;
- }
-
- XAttribute msdeploySiteAttribute = publishDataElement.Attribute(XName.Get("msdeploySite", ""));
- if (msdeploySiteAttribute != null)
- {
- publishProfileInstance.MSDeploySite = msdeploySiteAttribute.Value;
- }
-
- XAttribute ftpPassiveModeAttribute = publishDataElement.Attribute(XName.Get("ftpPassiveMode", ""));
- if (ftpPassiveModeAttribute != null)
- {
- publishProfileInstance.FtpPassiveMode = bool.Parse(ftpPassiveModeAttribute.Value);
- }
-
- XAttribute userNameAttribute = publishDataElement.Attribute(XName.Get("userName", ""));
- if (userNameAttribute != null)
- {
- publishProfileInstance.UserName = userNameAttribute.Value;
- }
-
- XAttribute userPWDAttribute = publishDataElement.Attribute(XName.Get("userPWD", ""));
- if (userPWDAttribute != null)
- {
- publishProfileInstance.UserPassword = userPWDAttribute.Value;
- }
-
- XAttribute destinationAppUrlAttribute = publishDataElement.Attribute(XName.Get("destinationAppUrl", ""));
- if (destinationAppUrlAttribute != null)
- {
- publishProfileInstance.DestinationAppUri = TypeConversion.TryParseUri(destinationAppUrlAttribute.Value);
- }
-
- XAttribute sQLServerDBConnectionStringAttribute = publishDataElement.Attribute(XName.Get("SQLServerDBConnectionString", ""));
- if (sQLServerDBConnectionStringAttribute != null)
- {
- publishProfileInstance.SqlServerConnectionString = sQLServerDBConnectionStringAttribute.Value;
- }
-
- XAttribute mySQLDBConnectionStringAttribute = publishDataElement.Attribute(XName.Get("mySQLDBConnectionString", ""));
- if (mySQLDBConnectionStringAttribute != null)
- {
- publishProfileInstance.MySqlConnectionString = mySQLDBConnectionStringAttribute.Value;
- }
-
- XAttribute hostingProviderForumLinkAttribute = publishDataElement.Attribute(XName.Get("hostingProviderForumLink", ""));
- if (hostingProviderForumLinkAttribute != null)
- {
- publishProfileInstance.HostingProviderForumUri = TypeConversion.TryParseUri(hostingProviderForumLinkAttribute.Value);
- }
-
- XAttribute controlPanelLinkAttribute = publishDataElement.Attribute(XName.Get("controlPanelLink", ""));
- if (controlPanelLinkAttribute != null)
- {
- publishProfileInstance.ControlPanelUri = TypeConversion.TryParseUri(controlPanelLinkAttribute.Value);
- }
-
- XElement databasesSequenceElement = publishDataElement.Element(XName.Get("databases", ""));
- if (databasesSequenceElement != null)
- {
- foreach (XElement databasesElement in databasesSequenceElement.Elements(XName.Get("add", "")))
- {
- WebSiteGetPublishProfileResponse.Database addInstance = new WebSiteGetPublishProfileResponse.Database();
- publishProfileInstance.Databases.Add(addInstance);
-
- XAttribute nameAttribute = databasesElement.Attribute(XName.Get("name", ""));
- if (nameAttribute != null)
- {
- addInstance.Name = nameAttribute.Value;
- }
-
- XAttribute connectionStringAttribute = databasesElement.Attribute(XName.Get("connectionString", ""));
- if (connectionStringAttribute != null)
- {
- addInstance.ConnectionString = connectionStringAttribute.Value;
- }
-
- XAttribute providerNameAttribute = databasesElement.Attribute(XName.Get("providerName", ""));
- if (providerNameAttribute != null)
- {
- addInstance.ProviderName = providerNameAttribute.Value;
- }
-
- XAttribute typeAttribute = databasesElement.Attribute(XName.Get("type", ""));
- if (typeAttribute != null)
- {
- addInstance.Type = typeAttribute.Value;
- }
- }
- }
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// A web site repository is essentially a GIT repository that you can
- /// use to manage your web site content. By using GIT source control
- /// tools, you can push or pull version controlled changes to your
- /// site. You can create a repository for your web site by issuing an
- /// HTTP POST request, or retrieve information about the repository by
- /// using HTTP GET. (see
- /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166967.aspx
- /// for more information)
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// The Get Web Site Repository operation response.
- /// </returns>
- public async Task<WebSiteGetRepositoryResponse> GetRepositoryAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- TracingAdapter.Enter(invocationId, this, "GetRepositoryAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/repository";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Get;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteGetRepositoryResponse result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteGetRepositoryResponse();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- if (responseDoc != null && responseDoc.Type != JTokenType.Null)
- {
- JToken uriValue = responseDoc["uri"];
- if (uriValue != null && uriValue.Type != JTokenType.Null)
- {
- Uri uriInstance = TypeConversion.TryParseUri(((string)uriValue));
- result.Uri = uriInstance;
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// Update list of app settings and connection strings which to be slot
- /// specific. E.g. settings in staging slots remain in staging after
- /// swap with production.
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the website
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// List of slot specific settings.
- /// </returns>
- public async Task<SlotConfigNamesResult> GetSlotConfigNamesAsync(string resourceGroupName, string webSiteName, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- TracingAdapter.Enter(invocationId, this, "GetSlotConfigNamesAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- url = url + "/config/slotConfigNames";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Get;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
- httpRequest.Headers.Add("accept", "application/json");
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- SlotConfigNamesResult result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new SlotConfigNamesResult();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- if (responseDoc != null && responseDoc.Type != JTokenType.Null)
- {
- SlotConfigNamesEnvelope resourceInstance = new SlotConfigNamesEnvelope();
- result.Resource = resourceInstance;
-
- JToken propertiesValue = responseDoc["properties"];
- if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
- {
- SlotConfigNames propertiesInstance = new SlotConfigNames();
- resourceInstance.Properties = propertiesInstance;
-
- JToken connectionStringNamesArray = propertiesValue["connectionStringNames"];
- if (connectionStringNamesArray != null && connectionStringNamesArray.Type != JTokenType.Null)
- {
- foreach (JToken connectionStringNamesValue in ((JArray)connectionStringNamesArray))
- {
- propertiesInstance.ConnectionStringNames.Add(((string)connectionStringNamesValue));
- }
- }
-
- JToken appSettingNamesArray = propertiesValue["appSettingNames"];
- if (appSettingNamesArray != null && appSettingNamesArray.Type != JTokenType.Null)
- {
- foreach (JToken appSettingNamesValue in ((JArray)appSettingNamesArray))
- {
- propertiesInstance.AppSettingNames.Add(((string)appSettingNamesValue));
- }
- }
- }
-
- JToken idValue = responseDoc["id"];
- if (idValue != null && idValue.Type != JTokenType.Null)
- {
- string idInstance = ((string)idValue);
- resourceInstance.Id = idInstance;
- }
-
- JToken nameValue = responseDoc["name"];
- if (nameValue != null && nameValue.Type != JTokenType.Null)
- {
- string nameInstance = ((string)nameValue);
- resourceInstance.Name = nameInstance;
- }
-
- JToken locationValue = responseDoc["location"];
- if (locationValue != null && locationValue.Type != JTokenType.Null)
- {
- string locationInstance = ((string)locationValue);
- resourceInstance.Location = locationInstance;
- }
-
- JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
- if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property in tagsSequenceElement)
- {
- string tagsKey = ((string)property.Name);
- string tagsValue = ((string)property.Value);
- resourceInstance.Tags.Add(tagsKey, tagsValue);
- }
- }
-
- JToken typeValue = responseDoc["type"];
- if (typeValue != null && typeValue.Type != JTokenType.Null)
- {
- string typeInstance = ((string)typeValue);
- resourceInstance.Type = typeInstance;
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// Get a web site's current usage metrics. The metrics returned
- /// include CPU Time, Data In, Data Out, Local bytes read, Local bytes
- /// written, Network bytes read, Network bytes written, WP stop
- /// requests, Memory Usage, CPU Time - Minute Limit, and File System
- /// Storage. (see
- /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166991.aspx
- /// for more information)
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// The Get Web Site Usage Metrics operation response.
- /// </returns>
- public async Task<WebSiteGetUsageMetricsResponse> GetUsageMetricsAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- TracingAdapter.Enter(invocationId, this, "GetUsageMetricsAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/usages";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Get;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteGetUsageMetricsResponse result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteGetUsageMetricsResponse();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- JToken usagesValue = responseDoc["usages"];
- if (usagesValue != null && usagesValue.Type != JTokenType.Null)
- {
- WebSiteGetUsageMetricsResponse usagesInstance = new WebSiteGetUsageMetricsResponse();
-
- JToken usageMetricsArray = usagesValue;
- if (usageMetricsArray != null && usageMetricsArray.Type != JTokenType.Null)
- {
- foreach (JToken usageMetricsValue in ((JArray)usageMetricsArray))
- {
- WebSiteGetUsageMetricsResponse.UsageMetric usageInstance = new WebSiteGetUsageMetricsResponse.UsageMetric();
- usagesInstance.UsageMetrics.Add(usageInstance);
-
- JToken currentValueValue = usageMetricsValue["currentValue"];
- if (currentValueValue != null && currentValueValue.Type != JTokenType.Null)
- {
- string currentValueInstance = ((string)currentValueValue);
- usageInstance.CurrentValue = currentValueInstance;
- }
-
- JToken displayNameValue = usageMetricsValue["displayName"];
- if (displayNameValue != null && displayNameValue.Type != JTokenType.Null)
- {
- string displayNameInstance = ((string)displayNameValue);
- usageInstance.DisplayName = displayNameInstance;
- }
-
- JToken limitValue = usageMetricsValue["limit"];
- if (limitValue != null && limitValue.Type != JTokenType.Null)
- {
- string limitInstance = ((string)limitValue);
- usageInstance.Limit = limitInstance;
- }
-
- JToken nameValue = usageMetricsValue["name"];
- if (nameValue != null && nameValue.Type != JTokenType.Null)
- {
- string nameInstance = ((string)nameValue);
- usageInstance.Name = nameInstance;
- }
-
- JToken nextResetTimeValue = usageMetricsValue["nextResetTime"];
- if (nextResetTimeValue != null && nextResetTimeValue.Type != JTokenType.Null)
- {
- DateTime nextResetTimeInstance = ((DateTime)nextResetTimeValue);
- usageInstance.NextResetTime = nextResetTimeInstance;
- }
-
- JToken resourceNameValue = usageMetricsValue["resourceName"];
- if (resourceNameValue != null && resourceNameValue.Type != JTokenType.Null)
- {
- string resourceNameInstance = ((string)resourceNameValue);
- usageInstance.ResourceName = resourceNameInstance;
- }
-
- JToken unitValue = usageMetricsValue["unit"];
- if (unitValue != null && unitValue.Type != JTokenType.Null)
- {
- string unitInstance = ((string)unitValue);
- usageInstance.Unit = unitInstance;
- }
- }
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// List the Web Sites in a resource group.
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group.
- /// </param>
- /// <param name='webSiteName'>
- /// Optional. The name of the web site.
- /// </param>
- /// <param name='parameters'>
- /// Optional. Additional parameters.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// The List Web Sites operation response.
- /// </returns>
- public async Task<WebSiteListResponse> ListAsync(string resourceGroupName, string webSiteName, WebSiteListParameters parameters, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("parameters", parameters);
- TracingAdapter.Enter(invocationId, this, "ListAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- if (webSiteName != null)
- {
- url = url + "/" + Uri.EscapeDataString(webSiteName) + "/slots/";
- }
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (parameters != null && parameters.PropertiesToInclude != null && parameters.PropertiesToInclude.Count > 0)
- {
- queryParameters.Add("propertiesToInclude=" + Uri.EscapeDataString(string.Join(",", parameters.PropertiesToInclude)));
- }
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Get;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteListResponse result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteListResponse();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- if (responseDoc != null && responseDoc.Type != JTokenType.Null)
- {
- JToken valueArray = responseDoc["value"];
- if (valueArray != null && valueArray.Type != JTokenType.Null)
- {
- foreach (JToken valueValue in ((JArray)valueArray))
- {
- WebSite webSiteInstance = new WebSite();
- result.WebSites.Add(webSiteInstance);
-
- JToken propertiesValue = valueValue["properties"];
- if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
- {
- WebSiteProperties propertiesInstance = new WebSiteProperties();
- webSiteInstance.Properties = propertiesInstance;
-
- JToken adminEnabledValue = propertiesValue["adminEnabled"];
- if (adminEnabledValue != null && adminEnabledValue.Type != JTokenType.Null)
- {
- bool adminEnabledInstance = ((bool)adminEnabledValue);
- propertiesInstance.AdminEnabled = adminEnabledInstance;
- }
-
- JToken availabilityStateValue = propertiesValue["availabilityState"];
- if (availabilityStateValue != null && availabilityStateValue.Type != JTokenType.Null)
- {
- WebSpaceAvailabilityState availabilityStateInstance = ((WebSpaceAvailabilityState)Enum.Parse(typeof(WebSpaceAvailabilityState), ((string)availabilityStateValue), true));
- propertiesInstance.AvailabilityState = availabilityStateInstance;
- }
-
- JToken enabledValue = propertiesValue["enabled"];
- if (enabledValue != null && enabledValue.Type != JTokenType.Null)
- {
- bool enabledInstance = ((bool)enabledValue);
- propertiesInstance.Enabled = enabledInstance;
- }
-
- JToken enabledHostNamesArray = propertiesValue["enabledHostNames"];
- if (enabledHostNamesArray != null && enabledHostNamesArray.Type != JTokenType.Null)
- {
- foreach (JToken enabledHostNamesValue in ((JArray)enabledHostNamesArray))
- {
- propertiesInstance.EnabledHostNames.Add(((string)enabledHostNamesValue));
- }
- }
-
- JToken hostNameSslStatesArray = propertiesValue["hostNameSslStates"];
- if (hostNameSslStatesArray != null && hostNameSslStatesArray.Type != JTokenType.Null)
- {
- foreach (JToken hostNameSslStatesValue in ((JArray)hostNameSslStatesArray))
- {
- WebSiteProperties.WebSiteHostNameSslState webSiteHostNameSslStateInstance = new WebSiteProperties.WebSiteHostNameSslState();
- propertiesInstance.HostNameSslStates.Add(webSiteHostNameSslStateInstance);
-
- JToken nameValue = hostNameSslStatesValue["name"];
- if (nameValue != null && nameValue.Type != JTokenType.Null)
- {
- string nameInstance = ((string)nameValue);
- webSiteHostNameSslStateInstance.Name = nameInstance;
- }
-
- JToken sslStateValue = hostNameSslStatesValue["sslState"];
- if (sslStateValue != null && sslStateValue.Type != JTokenType.Null)
- {
- WebSiteSslState sslStateInstance = ((WebSiteSslState)Enum.Parse(typeof(WebSiteSslState), ((string)sslStateValue), true));
- webSiteHostNameSslStateInstance.SslState = sslStateInstance;
- }
-
- JToken thumbprintValue = hostNameSslStatesValue["thumbprint"];
- if (thumbprintValue != null && thumbprintValue.Type != JTokenType.Null)
- {
- string thumbprintInstance = ((string)thumbprintValue);
- webSiteHostNameSslStateInstance.Thumbprint = thumbprintInstance;
- }
-
- JToken virtualIPValue = hostNameSslStatesValue["virtualIP"];
- if (virtualIPValue != null && virtualIPValue.Type != JTokenType.Null)
- {
- string virtualIPInstance = ((string)virtualIPValue);
- webSiteHostNameSslStateInstance.VirtualIP = virtualIPInstance;
- }
-
- JToken ipBasedSslResultValue = hostNameSslStatesValue["ipBasedSslResult"];
- if (ipBasedSslResultValue != null && ipBasedSslResultValue.Type != JTokenType.Null)
- {
- string ipBasedSslResultInstance = ((string)ipBasedSslResultValue);
- webSiteHostNameSslStateInstance.IpBasedSslResult = ipBasedSslResultInstance;
- }
-
- JToken toUpdateValue = hostNameSslStatesValue["toUpdate"];
- if (toUpdateValue != null && toUpdateValue.Type != JTokenType.Null)
- {
- bool toUpdateInstance = ((bool)toUpdateValue);
- webSiteHostNameSslStateInstance.ToUpdate = toUpdateInstance;
- }
-
- JToken toUpdateIpBasedSslValue = hostNameSslStatesValue["toUpdateIpBasedSsl"];
- if (toUpdateIpBasedSslValue != null && toUpdateIpBasedSslValue.Type != JTokenType.Null)
- {
- bool toUpdateIpBasedSslInstance = ((bool)toUpdateIpBasedSslValue);
- webSiteHostNameSslStateInstance.ToUpdateIpBasedSsl = toUpdateIpBasedSslInstance;
- }
- }
- }
-
- JToken hostNamesArray = propertiesValue["hostNames"];
- if (hostNamesArray != null && hostNamesArray.Type != JTokenType.Null)
- {
- foreach (JToken hostNamesValue in ((JArray)hostNamesArray))
- {
- propertiesInstance.HostNames.Add(((string)hostNamesValue));
- }
- }
-
- JToken lastModifiedTimeUtcValue = propertiesValue["lastModifiedTimeUtc"];
- if (lastModifiedTimeUtcValue != null && lastModifiedTimeUtcValue.Type != JTokenType.Null)
- {
- DateTime lastModifiedTimeUtcInstance = ((DateTime)lastModifiedTimeUtcValue);
- propertiesInstance.LastModifiedTimeUtc = lastModifiedTimeUtcInstance;
- }
-
- JToken repositorySiteNameValue = propertiesValue["repositorySiteName"];
- if (repositorySiteNameValue != null && repositorySiteNameValue.Type != JTokenType.Null)
- {
- string repositorySiteNameInstance = ((string)repositorySiteNameValue);
- propertiesInstance.RepositorySiteName = repositorySiteNameInstance;
- }
-
- JToken runtimeAvailabilityStateValue = propertiesValue["runtimeAvailabilityState"];
- if (runtimeAvailabilityStateValue != null && runtimeAvailabilityStateValue.Type != JTokenType.Null)
- {
- WebSiteRuntimeAvailabilityState runtimeAvailabilityStateInstance = ((WebSiteRuntimeAvailabilityState)Enum.Parse(typeof(WebSiteRuntimeAvailabilityState), ((string)runtimeAvailabilityStateValue), true));
- propertiesInstance.RuntimeAvailabilityState = runtimeAvailabilityStateInstance;
- }
-
- JToken trafficManagerHostNamesArray = propertiesValue["trafficManagerHostNames"];
- if (trafficManagerHostNamesArray != null && trafficManagerHostNamesArray.Type != JTokenType.Null)
- {
- foreach (JToken trafficManagerHostNamesValue in ((JArray)trafficManagerHostNamesArray))
- {
- propertiesInstance.TrafficManagerHostNames.Add(((string)trafficManagerHostNamesValue));
- }
- }
-
- JToken selfLinkValue = propertiesValue["selfLink"];
- if (selfLinkValue != null && selfLinkValue.Type != JTokenType.Null)
- {
- Uri selfLinkInstance = TypeConversion.TryParseUri(((string)selfLinkValue));
- propertiesInstance.Uri = selfLinkInstance;
- }
-
- JToken serverFarmValue = propertiesValue["serverFarm"];
- if (serverFarmValue != null && serverFarmValue.Type != JTokenType.Null)
- {
- string serverFarmInstance = ((string)serverFarmValue);
- propertiesInstance.ServerFarm = serverFarmInstance;
- }
-
- JToken serverFarmIdValue = propertiesValue["serverFarmId"];
- if (serverFarmIdValue != null && serverFarmIdValue.Type != JTokenType.Null)
- {
- string serverFarmIdInstance = ((string)serverFarmIdValue);
- propertiesInstance.ServerFarmId = serverFarmIdInstance;
- }
-
- JToken skuValue = propertiesValue["sku"];
- if (skuValue != null && skuValue.Type != JTokenType.Null)
- {
- SkuOptions skuInstance = ((SkuOptions)Enum.Parse(typeof(SkuOptions), ((string)skuValue), true));
- propertiesInstance.Sku = skuInstance;
- }
-
- JToken sitePropertiesValue = propertiesValue["siteProperties"];
- if (sitePropertiesValue != null && sitePropertiesValue.Type != JTokenType.Null)
- {
- WebSiteProperties.SiteProperties sitePropertiesInstance = new WebSiteProperties.SiteProperties();
- propertiesInstance.Properties = sitePropertiesInstance;
-
- JToken appSettingsSequenceElement = ((JToken)sitePropertiesValue["appSettings"]);
- if (appSettingsSequenceElement != null && appSettingsSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property in appSettingsSequenceElement)
- {
- string appSettingsKey = ((string)property.Name);
- string appSettingsValue = ((string)property.Value);
- sitePropertiesInstance.AppSettings.Add(appSettingsKey, appSettingsValue);
- }
- }
-
- JToken metadataSequenceElement = ((JToken)sitePropertiesValue["metadata"]);
- if (metadataSequenceElement != null && metadataSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property2 in metadataSequenceElement)
- {
- string metadataKey = ((string)property2.Name);
- string metadataValue = ((string)property2.Value);
- sitePropertiesInstance.Metadata.Add(metadataKey, metadataValue);
- }
- }
-
- JToken propertiesSequenceElement = ((JToken)sitePropertiesValue["properties"]);
- if (propertiesSequenceElement != null && propertiesSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property3 in propertiesSequenceElement)
- {
- string propertiesKey = ((string)property3.Name);
- string propertiesValue2 = ((string)property3.Value);
- sitePropertiesInstance.Properties.Add(propertiesKey, propertiesValue2);
- }
- }
- }
-
- JToken siteConfigValue = propertiesValue["siteConfig"];
- if (siteConfigValue != null && siteConfigValue.Type != JTokenType.Null)
- {
- WebSiteConfiguration siteConfigInstance = new WebSiteConfiguration();
- propertiesInstance.SiteConfig = siteConfigInstance;
-
- JToken appSettingsSequenceElement2 = ((JToken)siteConfigValue["appSettings"]);
- if (appSettingsSequenceElement2 != null && appSettingsSequenceElement2.Type != JTokenType.Null)
- {
- foreach (JProperty property4 in appSettingsSequenceElement2)
- {
- string appSettingsKey2 = ((string)property4.Name);
- string appSettingsValue2 = ((string)property4.Value);
- siteConfigInstance.AppSettings.Add(appSettingsKey2, appSettingsValue2);
- }
- }
-
- JToken connectionStringsArray = siteConfigValue["connectionStrings"];
- if (connectionStringsArray != null && connectionStringsArray.Type != JTokenType.Null)
- {
- foreach (JToken connectionStringsValue in ((JArray)connectionStringsArray))
- {
- ConnectionStringInfo connStringInfoInstance = new ConnectionStringInfo();
- siteConfigInstance.ConnectionStrings.Add(connStringInfoInstance);
-
- JToken connectionStringValue = connectionStringsValue["connectionString"];
- if (connectionStringValue != null && connectionStringValue.Type != JTokenType.Null)
- {
- string connectionStringInstance = ((string)connectionStringValue);
- connStringInfoInstance.ConnectionString = connectionStringInstance;
- }
-
- JToken nameValue2 = connectionStringsValue["name"];
- if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
- {
- string nameInstance2 = ((string)nameValue2);
- connStringInfoInstance.Name = nameInstance2;
- }
-
- JToken typeValue = connectionStringsValue["type"];
- if (typeValue != null && typeValue.Type != JTokenType.Null)
- {
- DatabaseServerType typeInstance = ((DatabaseServerType)Enum.Parse(typeof(DatabaseServerType), ((string)typeValue), true));
- connStringInfoInstance.Type = typeInstance;
- }
- }
- }
-
- JToken defaultDocumentsArray = siteConfigValue["defaultDocuments"];
- if (defaultDocumentsArray != null && defaultDocumentsArray.Type != JTokenType.Null)
- {
- foreach (JToken defaultDocumentsValue in ((JArray)defaultDocumentsArray))
- {
- siteConfigInstance.DefaultDocuments.Add(((string)defaultDocumentsValue));
- }
- }
-
- JToken detailedErrorLoggingEnabledValue = siteConfigValue["detailedErrorLoggingEnabled"];
- if (detailedErrorLoggingEnabledValue != null && detailedErrorLoggingEnabledValue.Type != JTokenType.Null)
- {
- bool detailedErrorLoggingEnabledInstance = ((bool)detailedErrorLoggingEnabledValue);
- siteConfigInstance.DetailedErrorLoggingEnabled = detailedErrorLoggingEnabledInstance;
- }
-
- JToken documentRootValue = siteConfigValue["documentRoot"];
- if (documentRootValue != null && documentRootValue.Type != JTokenType.Null)
- {
- string documentRootInstance = ((string)documentRootValue);
- siteConfigInstance.DocumentRoot = documentRootInstance;
- }
-
- JToken handlerMappingsArray = siteConfigValue["handlerMappings"];
- if (handlerMappingsArray != null && handlerMappingsArray.Type != JTokenType.Null)
- {
- foreach (JToken handlerMappingsValue in ((JArray)handlerMappingsArray))
- {
- WebSiteConfiguration.HandlerMapping handlerMappingInstance = new WebSiteConfiguration.HandlerMapping();
- siteConfigInstance.HandlerMappings.Add(handlerMappingInstance);
-
- JToken argumentsValue = handlerMappingsValue["arguments"];
- if (argumentsValue != null && argumentsValue.Type != JTokenType.Null)
- {
- string argumentsInstance = ((string)argumentsValue);
- handlerMappingInstance.Arguments = argumentsInstance;
- }
-
- JToken extensionValue = handlerMappingsValue["extension"];
- if (extensionValue != null && extensionValue.Type != JTokenType.Null)
- {
- string extensionInstance = ((string)extensionValue);
- handlerMappingInstance.Extension = extensionInstance;
- }
-
- JToken scriptProcessorValue = handlerMappingsValue["scriptProcessor"];
- if (scriptProcessorValue != null && scriptProcessorValue.Type != JTokenType.Null)
- {
- string scriptProcessorInstance = ((string)scriptProcessorValue);
- handlerMappingInstance.ScriptProcessor = scriptProcessorInstance;
- }
- }
- }
-
- JToken httpLoggingEnabledValue = siteConfigValue["httpLoggingEnabled"];
- if (httpLoggingEnabledValue != null && httpLoggingEnabledValue.Type != JTokenType.Null)
- {
- bool httpLoggingEnabledInstance = ((bool)httpLoggingEnabledValue);
- siteConfigInstance.HttpLoggingEnabled = httpLoggingEnabledInstance;
- }
-
- JToken logsDirectorySizeLimitValue = siteConfigValue["logsDirectorySizeLimit"];
- if (logsDirectorySizeLimitValue != null && logsDirectorySizeLimitValue.Type != JTokenType.Null)
- {
- int logsDirectorySizeLimitInstance = ((int)logsDirectorySizeLimitValue);
- siteConfigInstance.LogsDirectorySizeLimit = logsDirectorySizeLimitInstance;
- }
-
- JToken managedPipelineModeValue = siteConfigValue["managedPipelineMode"];
- if (managedPipelineModeValue != null && managedPipelineModeValue.Type != JTokenType.Null)
- {
- ManagedPipelineMode managedPipelineModeInstance = ((ManagedPipelineMode)Enum.Parse(typeof(ManagedPipelineMode), ((string)managedPipelineModeValue), true));
- siteConfigInstance.ManagedPipelineMode = managedPipelineModeInstance;
- }
-
- JToken metadataSequenceElement2 = ((JToken)siteConfigValue["metadata"]);
- if (metadataSequenceElement2 != null && metadataSequenceElement2.Type != JTokenType.Null)
- {
- foreach (JProperty property5 in metadataSequenceElement2)
- {
- string metadataKey2 = ((string)property5.Name);
- string metadataValue2 = ((string)property5.Value);
- siteConfigInstance.Metadata.Add(metadataKey2, metadataValue2);
- }
- }
-
- JToken netFrameworkVersionValue = siteConfigValue["netFrameworkVersion"];
- if (netFrameworkVersionValue != null && netFrameworkVersionValue.Type != JTokenType.Null)
- {
- string netFrameworkVersionInstance = ((string)netFrameworkVersionValue);
- siteConfigInstance.NetFrameworkVersion = netFrameworkVersionInstance;
- }
-
- JToken numberOfWorkersValue = siteConfigValue["numberOfWorkers"];
- if (numberOfWorkersValue != null && numberOfWorkersValue.Type != JTokenType.Null)
- {
- int numberOfWorkersInstance = ((int)numberOfWorkersValue);
- siteConfigInstance.NumberOfWorkers = numberOfWorkersInstance;
- }
-
- JToken phpVersionValue = siteConfigValue["phpVersion"];
- if (phpVersionValue != null && phpVersionValue.Type != JTokenType.Null)
- {
- string phpVersionInstance = ((string)phpVersionValue);
- siteConfigInstance.PhpVersion = phpVersionInstance;
- }
-
- JToken pythonVersionValue = siteConfigValue["pythonVersion"];
- if (pythonVersionValue != null && pythonVersionValue.Type != JTokenType.Null)
- {
- string pythonVersionInstance = ((string)pythonVersionValue);
- siteConfigInstance.PythonVersion = pythonVersionInstance;
- }
-
- JToken publishingPasswordValue = siteConfigValue["publishingPassword"];
- if (publishingPasswordValue != null && publishingPasswordValue.Type != JTokenType.Null)
- {
- string publishingPasswordInstance = ((string)publishingPasswordValue);
- siteConfigInstance.PublishingPassword = publishingPasswordInstance;
- }
-
- JToken publishingUsernameValue = siteConfigValue["publishingUsername"];
- if (publishingUsernameValue != null && publishingUsernameValue.Type != JTokenType.Null)
- {
- string publishingUsernameInstance = ((string)publishingUsernameValue);
- siteConfigInstance.PublishingUserName = publishingUsernameInstance;
- }
-
- JToken remoteDebuggingEnabledValue = siteConfigValue["RemoteDebuggingEnabled"];
- if (remoteDebuggingEnabledValue != null && remoteDebuggingEnabledValue.Type != JTokenType.Null)
- {
- bool remoteDebuggingEnabledInstance = ((bool)remoteDebuggingEnabledValue);
- siteConfigInstance.RemoteDebuggingEnabled = remoteDebuggingEnabledInstance;
- }
-
- JToken remoteDebuggingVersionValue = siteConfigValue["remoteDebuggingVersion"];
- if (remoteDebuggingVersionValue != null && remoteDebuggingVersionValue.Type != JTokenType.Null)
- {
- RemoteDebuggingVersion remoteDebuggingVersionInstance = ((RemoteDebuggingVersion)Enum.Parse(typeof(RemoteDebuggingVersion), ((string)remoteDebuggingVersionValue), true));
- siteConfigInstance.RemoteDebuggingVersion = remoteDebuggingVersionInstance;
- }
-
- JToken requestTracingEnabledValue = siteConfigValue["requestTracingEnabled"];
- if (requestTracingEnabledValue != null && requestTracingEnabledValue.Type != JTokenType.Null)
- {
- bool requestTracingEnabledInstance = ((bool)requestTracingEnabledValue);
- siteConfigInstance.RequestTracingEnabled = requestTracingEnabledInstance;
- }
-
- JToken requestTracingExpirationTimeValue = siteConfigValue["requestTracingExpirationTime"];
- if (requestTracingExpirationTimeValue != null && requestTracingExpirationTimeValue.Type != JTokenType.Null)
- {
- DateTime requestTracingExpirationTimeInstance = ((DateTime)requestTracingExpirationTimeValue);
- siteConfigInstance.RequestTracingExpirationTime = requestTracingExpirationTimeInstance;
- }
-
- JToken scmTypeValue = siteConfigValue["scmType"];
- if (scmTypeValue != null && scmTypeValue.Type != JTokenType.Null)
- {
- string scmTypeInstance = ((string)scmTypeValue);
- siteConfigInstance.ScmType = scmTypeInstance;
- }
-
- JToken autoSwapSlotNameValue = siteConfigValue["autoSwapSlotName"];
- if (autoSwapSlotNameValue != null && autoSwapSlotNameValue.Type != JTokenType.Null)
- {
- string autoSwapSlotNameInstance = ((string)autoSwapSlotNameValue);
- siteConfigInstance.AutoSwapSlotName = autoSwapSlotNameInstance;
- }
-
- JToken use32BitWorkerProcessValue = siteConfigValue["use32BitWorkerProcess"];
- if (use32BitWorkerProcessValue != null && use32BitWorkerProcessValue.Type != JTokenType.Null)
- {
- bool use32BitWorkerProcessInstance = ((bool)use32BitWorkerProcessValue);
- siteConfigInstance.Use32BitWorkerProcess = use32BitWorkerProcessInstance;
- }
-
- JToken webSocketsEnabledValue = siteConfigValue["webSocketsEnabled"];
- if (webSocketsEnabledValue != null && webSocketsEnabledValue.Type != JTokenType.Null)
- {
- bool webSocketsEnabledInstance = ((bool)webSocketsEnabledValue);
- siteConfigInstance.WebSocketsEnabled = webSocketsEnabledInstance;
- }
-
- JToken limitsValue = siteConfigValue["limits"];
- if (limitsValue != null && limitsValue.Type != JTokenType.Null)
- {
- SiteLimits limitsInstance = new SiteLimits();
- siteConfigInstance.Limits = limitsInstance;
-
- JToken maxPercentageCpuValue = limitsValue["maxPercentageCpu"];
- if (maxPercentageCpuValue != null && maxPercentageCpuValue.Type != JTokenType.Null)
- {
- double maxPercentageCpuInstance = ((double)maxPercentageCpuValue);
- limitsInstance.MaxPercentageCpu = maxPercentageCpuInstance;
- }
-
- JToken maxMemoryInMbValue = limitsValue["maxMemoryInMb"];
- if (maxMemoryInMbValue != null && maxMemoryInMbValue.Type != JTokenType.Null)
- {
- long maxMemoryInMbInstance = ((long)maxMemoryInMbValue);
- limitsInstance.MaxMemoryInMb = maxMemoryInMbInstance;
- }
-
- JToken maxDiskSizeInMbValue = limitsValue["maxDiskSizeInMb"];
- if (maxDiskSizeInMbValue != null && maxDiskSizeInMbValue.Type != JTokenType.Null)
- {
- long maxDiskSizeInMbInstance = ((long)maxDiskSizeInMbValue);
- limitsInstance.MaxDiskSizeInMb = maxDiskSizeInMbInstance;
- }
- }
- }
-
- JToken stateValue = propertiesValue["state"];
- if (stateValue != null && stateValue.Type != JTokenType.Null)
- {
- WebSiteState stateInstance = ((WebSiteState)Enum.Parse(typeof(WebSiteState), ((string)stateValue), true));
- propertiesInstance.State = stateInstance;
- }
-
- JToken usageStateValue = propertiesValue["usageState"];
- if (usageStateValue != null && usageStateValue.Type != JTokenType.Null)
- {
- WebSiteUsageState usageStateInstance = ((WebSiteUsageState)Enum.Parse(typeof(WebSiteUsageState), ((string)usageStateValue), true));
- propertiesInstance.UsageState = usageStateInstance;
- }
-
- JToken webSpaceValue = propertiesValue["webSpace"];
- if (webSpaceValue != null && webSpaceValue.Type != JTokenType.Null)
- {
- string webSpaceInstance = ((string)webSpaceValue);
- propertiesInstance.WebSpace = webSpaceInstance;
- }
-
- JToken provisioningStateValue = propertiesValue["provisioningState"];
- if (provisioningStateValue != null && provisioningStateValue.Type != JTokenType.Null)
- {
- string provisioningStateInstance = ((string)provisioningStateValue);
- propertiesInstance.ProvisioningState = provisioningStateInstance;
- }
- }
-
- JToken idValue = valueValue["id"];
- if (idValue != null && idValue.Type != JTokenType.Null)
- {
- string idInstance = ((string)idValue);
- webSiteInstance.Id = idInstance;
- }
-
- JToken nameValue3 = valueValue["name"];
- if (nameValue3 != null && nameValue3.Type != JTokenType.Null)
- {
- string nameInstance3 = ((string)nameValue3);
- webSiteInstance.Name = nameInstance3;
- }
-
- JToken locationValue = valueValue["location"];
- if (locationValue != null && locationValue.Type != JTokenType.Null)
- {
- string locationInstance = ((string)locationValue);
- webSiteInstance.Location = locationInstance;
- }
-
- JToken tagsSequenceElement = ((JToken)valueValue["tags"]);
- if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property6 in tagsSequenceElement)
- {
- string tagsKey = ((string)property6.Name);
- string tagsValue = ((string)property6.Value);
- webSiteInstance.Tags.Add(tagsKey, tagsValue);
- }
- }
-
- JToken typeValue2 = valueValue["type"];
- if (typeValue2 != null && typeValue2.Type != JTokenType.Null)
- {
- string typeInstance2 = ((string)typeValue2);
- webSiteInstance.Type = typeInstance2;
- }
- }
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// Returns list of all backups which are tracked by the system.
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// List of backups for the website.
- /// </returns>
- public async Task<WebSiteGetBackupsResponse> ListBackupsAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- TracingAdapter.Enter(invocationId, this, "ListBackupsAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/restore";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Get;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
- httpRequest.Headers.Add("x-ms-version", "2014-06-01");
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteGetBackupsResponse result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteGetBackupsResponse();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- if (responseDoc != null && responseDoc.Type != JTokenType.Null)
- {
- BackupItemsEnvelope backupListInstance = new BackupItemsEnvelope();
- result.BackupList = backupListInstance;
-
- JToken propertiesArray = responseDoc["properties"];
- if (propertiesArray != null && propertiesArray.Type != JTokenType.Null)
- {
- foreach (JToken propertiesValue in ((JArray)propertiesArray))
- {
- BackupItem backupItemInstance = new BackupItem();
- backupListInstance.Properties.Add(backupItemInstance);
-
- JToken storageAccountUrlValue = propertiesValue["storageAccountUrl"];
- if (storageAccountUrlValue != null && storageAccountUrlValue.Type != JTokenType.Null)
- {
- string storageAccountUrlInstance = ((string)storageAccountUrlValue);
- backupItemInstance.StorageAccountUrl = storageAccountUrlInstance;
- }
-
- JToken blobNameValue = propertiesValue["blobName"];
- if (blobNameValue != null && blobNameValue.Type != JTokenType.Null)
- {
- string blobNameInstance = ((string)blobNameValue);
- backupItemInstance.BlobName = blobNameInstance;
- }
-
- JToken nameValue = propertiesValue["name"];
- if (nameValue != null && nameValue.Type != JTokenType.Null)
- {
- string nameInstance = ((string)nameValue);
- backupItemInstance.Name = nameInstance;
- }
-
- JToken statusValue = propertiesValue["status"];
- if (statusValue != null && statusValue.Type != JTokenType.Null)
- {
- BackupItemStatus statusInstance = ((BackupItemStatus)Enum.Parse(typeof(BackupItemStatus), ((string)statusValue), true));
- backupItemInstance.Status = statusInstance;
- }
-
- JToken sizeInBytesValue = propertiesValue["sizeInBytes"];
- if (sizeInBytesValue != null && sizeInBytesValue.Type != JTokenType.Null)
- {
- long sizeInBytesInstance = ((long)sizeInBytesValue);
- backupItemInstance.SizeInBytes = sizeInBytesInstance;
- }
-
- JToken createdValue = propertiesValue["created"];
- if (createdValue != null && createdValue.Type != JTokenType.Null)
- {
- DateTime createdInstance = ((DateTime)createdValue);
- backupItemInstance.Created = createdInstance;
- }
-
- JToken logValue = propertiesValue["log"];
- if (logValue != null && logValue.Type != JTokenType.Null)
- {
- string logInstance = ((string)logValue);
- backupItemInstance.Log = logInstance;
- }
-
- JToken databasesArray = propertiesValue["databases"];
- if (databasesArray != null && databasesArray.Type != JTokenType.Null)
- {
- foreach (JToken databasesValue in ((JArray)databasesArray))
- {
- DatabaseBackupSetting databaseBackupSettingInstance = new DatabaseBackupSetting();
- backupItemInstance.Databases.Add(databaseBackupSettingInstance);
-
- JToken connectionStringValue = databasesValue["connectionString"];
- if (connectionStringValue != null && connectionStringValue.Type != JTokenType.Null)
- {
- string connectionStringInstance = ((string)connectionStringValue);
- databaseBackupSettingInstance.ConnectionString = connectionStringInstance;
- }
-
- JToken connectionStringNameValue = databasesValue["connectionStringName"];
- if (connectionStringNameValue != null && connectionStringNameValue.Type != JTokenType.Null)
- {
- string connectionStringNameInstance = ((string)connectionStringNameValue);
- databaseBackupSettingInstance.ConnectionStringName = connectionStringNameInstance;
- }
-
- JToken databaseTypeValue = databasesValue["databaseType"];
- if (databaseTypeValue != null && databaseTypeValue.Type != JTokenType.Null)
- {
- string databaseTypeInstance = ((string)databaseTypeValue);
- databaseBackupSettingInstance.DatabaseType = databaseTypeInstance;
- }
-
- JToken nameValue2 = databasesValue["name"];
- if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
- {
- string nameInstance2 = ((string)nameValue2);
- databaseBackupSettingInstance.Name = nameInstance2;
- }
- }
- }
-
- JToken scheduledValue = propertiesValue["scheduled"];
- if (scheduledValue != null && scheduledValue.Type != JTokenType.Null)
- {
- bool scheduledInstance = ((bool)scheduledValue);
- backupItemInstance.Scheduled = scheduledInstance;
- }
-
- JToken lastRestoreTimeStampValue = propertiesValue["lastRestoreTimeStamp"];
- if (lastRestoreTimeStampValue != null && lastRestoreTimeStampValue.Type != JTokenType.Null)
- {
- DateTime lastRestoreTimeStampInstance = ((DateTime)lastRestoreTimeStampValue);
- backupItemInstance.LastRestoreTimeStamp = lastRestoreTimeStampInstance;
- }
-
- JToken finishedTimeStampValue = propertiesValue["finishedTimeStamp"];
- if (finishedTimeStampValue != null && finishedTimeStampValue.Type != JTokenType.Null)
- {
- DateTime finishedTimeStampInstance = ((DateTime)finishedTimeStampValue);
- backupItemInstance.FinishedTimeStamp = finishedTimeStampInstance;
- }
-
- JToken correlationIdValue = propertiesValue["correlationId"];
- if (correlationIdValue != null && correlationIdValue.Type != JTokenType.Null)
- {
- string correlationIdInstance = ((string)correlationIdValue);
- backupItemInstance.CorrelationId = correlationIdInstance;
- }
- }
- }
-
- JToken idValue = responseDoc["id"];
- if (idValue != null && idValue.Type != JTokenType.Null)
- {
- string idInstance = ((string)idValue);
- backupListInstance.Id = idInstance;
- }
-
- JToken nameValue3 = responseDoc["name"];
- if (nameValue3 != null && nameValue3.Type != JTokenType.Null)
- {
- string nameInstance3 = ((string)nameValue3);
- backupListInstance.Name = nameInstance3;
- }
-
- JToken locationValue = responseDoc["location"];
- if (locationValue != null && locationValue.Type != JTokenType.Null)
- {
- string locationInstance = ((string)locationValue);
- backupListInstance.Location = locationInstance;
- }
-
- JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
- if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property in tagsSequenceElement)
- {
- string tagsKey = ((string)property.Name);
- string tagsValue = ((string)property.Value);
- backupListInstance.Tags.Add(tagsKey, tagsValue);
- }
- }
-
- JToken typeValue = responseDoc["type"];
- if (typeValue != null && typeValue.Type != JTokenType.Null)
- {
- string typeInstance = ((string)typeValue);
- backupListInstance.Type = typeInstance;
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// Restart the web site.
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group
- /// </param>
- /// <param name='webSiteName'>
- /// Required. Name of website
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// A standard service response including an HTTP status code and
- /// request ID.
- /// </returns>
- public async Task<AzureOperationResponse> RestartAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- TracingAdapter.Enter(invocationId, this, "RestartAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/restart";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Post;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- AzureOperationResponse result = null;
- // Deserialize Response
- result = new AzureOperationResponse();
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// Restores a site to either a new site or existing site (Overwrite
- /// flag has to be set to true for that).
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the web space.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='restoreRequestEnvelope'>
- /// Required. A restore request.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// Restore operation information.
- /// </returns>
- public async Task<WebSiteRestoreResponse> RestoreAsync(string resourceGroupName, string webSiteName, string slotName, RestoreRequestEnvelope restoreRequestEnvelope, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
- if (restoreRequestEnvelope == null)
- {
- throw new ArgumentNullException("restoreRequestEnvelope");
- }
- if (restoreRequestEnvelope.Location == null)
- {
- throw new ArgumentNullException("restoreRequestEnvelope.Location");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- tracingParameters.Add("restoreRequestEnvelope", restoreRequestEnvelope);
- TracingAdapter.Enter(invocationId, this, "RestoreAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- queryParameters.Add("operation=restore");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Put;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
- httpRequest.Headers.Add("x-ms-version", "2014-06-01");
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Serialize Request
- string requestContent = null;
- JToken requestDoc = null;
-
- JObject restoreRequestEnvelopeValue = new JObject();
- requestDoc = restoreRequestEnvelopeValue;
-
- if (restoreRequestEnvelope.Request != null)
- {
- JObject propertiesValue = new JObject();
- restoreRequestEnvelopeValue["properties"] = propertiesValue;
-
- propertiesValue["AdjustConnectionStrings"] = restoreRequestEnvelope.Request.AdjustConnectionStrings;
-
- if (restoreRequestEnvelope.Request.BlobName != null)
- {
- propertiesValue["BlobName"] = restoreRequestEnvelope.Request.BlobName;
- }
-
- if (restoreRequestEnvelope.Request.Databases != null)
- {
- if (restoreRequestEnvelope.Request.Databases is ILazyCollection == false || ((ILazyCollection)restoreRequestEnvelope.Request.Databases).IsInitialized)
- {
- JArray databasesArray = new JArray();
- foreach (DatabaseBackupSetting databasesItem in restoreRequestEnvelope.Request.Databases)
- {
- JObject databaseBackupSettingValue = new JObject();
- databasesArray.Add(databaseBackupSettingValue);
-
- if (databasesItem.ConnectionString != null)
- {
- databaseBackupSettingValue["connectionString"] = databasesItem.ConnectionString;
- }
-
- if (databasesItem.ConnectionStringName != null)
- {
- databaseBackupSettingValue["connectionStringName"] = databasesItem.ConnectionStringName;
- }
-
- if (databasesItem.DatabaseType != null)
- {
- databaseBackupSettingValue["databaseType"] = databasesItem.DatabaseType;
- }
-
- if (databasesItem.Name != null)
- {
- databaseBackupSettingValue["name"] = databasesItem.Name;
- }
- }
- propertiesValue["Databases"] = databasesArray;
- }
- }
-
- propertiesValue["IgnoreConflictingHostNames"] = restoreRequestEnvelope.Request.IgnoreConflictingHostNames;
-
- propertiesValue["Overwrite"] = restoreRequestEnvelope.Request.Overwrite;
-
- if (restoreRequestEnvelope.Request.StorageAccountUrl != null)
- {
- propertiesValue["StorageAccountUrl"] = restoreRequestEnvelope.Request.StorageAccountUrl;
- }
- }
-
- if (restoreRequestEnvelope.Id != null)
- {
- restoreRequestEnvelopeValue["id"] = restoreRequestEnvelope.Id;
- }
-
- if (restoreRequestEnvelope.Name != null)
- {
- restoreRequestEnvelopeValue["name"] = restoreRequestEnvelope.Name;
- }
-
- restoreRequestEnvelopeValue["location"] = restoreRequestEnvelope.Location;
-
- if (restoreRequestEnvelope.Tags != null)
- {
- JObject tagsDictionary = new JObject();
- foreach (KeyValuePair<string, string> pair in restoreRequestEnvelope.Tags)
- {
- string tagsKey = pair.Key;
- string tagsValue = pair.Value;
- tagsDictionary[tagsKey] = tagsValue;
- }
- restoreRequestEnvelopeValue["tags"] = tagsDictionary;
- }
-
- if (restoreRequestEnvelope.Type != null)
- {
- restoreRequestEnvelopeValue["type"] = restoreRequestEnvelope.Type;
- }
-
- requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
- httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
- httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteRestoreResponse result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteRestoreResponse();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- JToken restoreResponseValue = responseDoc["RestoreResponse"];
- if (restoreResponseValue != null && restoreResponseValue.Type != JTokenType.Null)
- {
- WebSiteRestoreResponse restoreResponseInstance = new WebSiteRestoreResponse();
-
- JToken operationIdValue = restoreResponseValue["operationId"];
- if (operationIdValue != null && operationIdValue.Type != JTokenType.Null)
- {
- string operationIdInstance = ((string)operationIdValue);
- restoreResponseInstance.OperationId = operationIdInstance;
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// Restart the web site.
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group
- /// </param>
- /// <param name='webSiteName'>
- /// Required. Name of website
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot of the website
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// A standard service response including an HTTP status code and
- /// request ID.
- /// </returns>
- public async Task<AzureOperationResponse> StartAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- TracingAdapter.Enter(invocationId, this, "StartAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/start";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Post;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- AzureOperationResponse result = null;
- // Deserialize Response
- result = new AzureOperationResponse();
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// Restart the web site.
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group
- /// </param>
- /// <param name='webSiteName'>
- /// Required. Name of website
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot of the web site
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// A standard service response including an HTTP status code and
- /// request ID.
- /// </returns>
- public async Task<AzureOperationResponse> StopAsync(string resourceGroupName, string webSiteName, string slotName, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- TracingAdapter.Enter(invocationId, this, "StopAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/stop";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Post;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- AzureOperationResponse result = null;
- // Deserialize Response
- result = new AzureOperationResponse();
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// You can retrieve the application settings for a web site by issuing
- /// an HTTP GET request, or update them by using HTTP PUT with a
- /// request body that contains the settings to be updated. (see
- /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166985.aspx
- /// for more information)
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot of the website
- /// </param>
- /// <param name='parameters'>
- /// Required. The Update Web Site app settings parameters
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// List of app settings for the website.
- /// </returns>
- public async Task<WebSiteAppSettingsResult> UpdateAppSettingsAsync(string resourceGroupName, string webSiteName, string slotName, WebSiteNameValueParameters parameters, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
- if (parameters == null)
- {
- throw new ArgumentNullException("parameters");
- }
- if (parameters.Location == null)
- {
- throw new ArgumentNullException("parameters.Location");
- }
- if (parameters.Properties == null)
- {
- throw new ArgumentNullException("parameters.Properties");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- tracingParameters.Add("parameters", parameters);
- TracingAdapter.Enter(invocationId, this, "UpdateAppSettingsAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/config/appsettings";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Put;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Serialize Request
- string requestContent = null;
- JToken requestDoc = null;
-
- JObject webSiteNameValueParametersValue = new JObject();
- requestDoc = webSiteNameValueParametersValue;
-
- if (parameters.Properties != null)
- {
- if (parameters.Properties is ILazyCollection == false || ((ILazyCollection)parameters.Properties).IsInitialized)
- {
- JArray propertiesArray = new JArray();
- foreach (NameValuePair propertiesItem in parameters.Properties)
- {
- JObject nameValuePairValue = new JObject();
- propertiesArray.Add(nameValuePairValue);
-
- if (propertiesItem.Name != null)
- {
- nameValuePairValue["name"] = propertiesItem.Name;
- }
-
- if (propertiesItem.Value != null)
- {
- nameValuePairValue["value"] = propertiesItem.Value;
- }
- }
- webSiteNameValueParametersValue["properties"] = propertiesArray;
- }
- }
-
- if (parameters.Id != null)
- {
- webSiteNameValueParametersValue["id"] = parameters.Id;
- }
-
- if (parameters.Name != null)
- {
- webSiteNameValueParametersValue["name"] = parameters.Name;
- }
-
- webSiteNameValueParametersValue["location"] = parameters.Location;
-
- if (parameters.Tags != null)
- {
- JObject tagsDictionary = new JObject();
- foreach (KeyValuePair<string, string> pair in parameters.Tags)
- {
- string tagsKey = pair.Key;
- string tagsValue = pair.Value;
- tagsDictionary[tagsKey] = tagsValue;
- }
- webSiteNameValueParametersValue["tags"] = tagsDictionary;
- }
-
- if (parameters.Type != null)
- {
- webSiteNameValueParametersValue["type"] = parameters.Type;
- }
-
- requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
- httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
- httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- WebSiteAppSettingsResult result = null;
- // Deserialize Response
- if (statusCode == HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
- result = new WebSiteAppSettingsResult();
- JToken responseDoc = null;
- if (string.IsNullOrEmpty(responseContent) == false)
- {
- responseDoc = JToken.Parse(responseContent);
- }
-
- if (responseDoc != null && responseDoc.Type != JTokenType.Null)
- {
- WebSiteAppSettingsEnvelope resourceInstance = new WebSiteAppSettingsEnvelope();
- result.Resource = resourceInstance;
-
- JToken propertiesArray2 = responseDoc["properties"];
- if (propertiesArray2 != null && propertiesArray2.Type != JTokenType.Null)
- {
- foreach (JToken propertiesValue in ((JArray)propertiesArray2))
- {
- NameValuePair nameValuePairInstance = new NameValuePair();
- resourceInstance.Properties.Add(nameValuePairInstance);
-
- JToken nameValue = propertiesValue["name"];
- if (nameValue != null && nameValue.Type != JTokenType.Null)
- {
- string nameInstance = ((string)nameValue);
- nameValuePairInstance.Name = nameInstance;
- }
-
- JToken valueValue = propertiesValue["value"];
- if (valueValue != null && valueValue.Type != JTokenType.Null)
- {
- string valueInstance = ((string)valueValue);
- nameValuePairInstance.Value = valueInstance;
- }
- }
- }
-
- JToken idValue = responseDoc["id"];
- if (idValue != null && idValue.Type != JTokenType.Null)
- {
- string idInstance = ((string)idValue);
- resourceInstance.Id = idInstance;
- }
-
- JToken nameValue2 = responseDoc["name"];
- if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
- {
- string nameInstance2 = ((string)nameValue2);
- resourceInstance.Name = nameInstance2;
- }
-
- JToken locationValue = responseDoc["location"];
- if (locationValue != null && locationValue.Type != JTokenType.Null)
- {
- string locationInstance = ((string)locationValue);
- resourceInstance.Location = locationInstance;
- }
-
- JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
- if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
- {
- foreach (JProperty property in tagsSequenceElement)
- {
- string tagsKey2 = ((string)property.Name);
- string tagsValue2 = ((string)property.Value);
- resourceInstance.Tags.Add(tagsKey2, tagsValue2);
- }
- }
-
- JToken typeValue = responseDoc["type"];
- if (typeValue != null && typeValue.Type != JTokenType.Null)
- {
- string typeInstance = ((string)typeValue);
- resourceInstance.Type = typeInstance;
- }
- }
-
- }
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// Updates a backup schedule for a site.
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the web space.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='backupRequestEnvelope'>
- /// Required. A backup schedule specification.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// A standard service response including an HTTP status code and
- /// request ID.
- /// </returns>
- public async Task<AzureOperationResponse> UpdateBackupConfigurationAsync(string resourceGroupName, string webSiteName, string slotName, BackupRequestEnvelope backupRequestEnvelope, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
- if (backupRequestEnvelope == null)
- {
- throw new ArgumentNullException("backupRequestEnvelope");
- }
- if (backupRequestEnvelope.Location == null)
- {
- throw new ArgumentNullException("backupRequestEnvelope.Location");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- tracingParameters.Add("backupRequestEnvelope", backupRequestEnvelope);
- TracingAdapter.Enter(invocationId, this, "UpdateBackupConfigurationAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/backup/config";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character from the end of baseUrl and beginning of url.
- if (baseUrl[baseUrl.Length - 1] == '/')
- {
- baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
- }
- if (url[0] == '/')
- {
- url = url.Substring(1);
- }
- url = baseUrl + "/" + url;
- url = url.Replace(" ", "%20");
-
- // Create HTTP transport objects
- HttpRequestMessage httpRequest = null;
- try
- {
- httpRequest = new HttpRequestMessage();
- httpRequest.Method = HttpMethod.Put;
- httpRequest.RequestUri = new Uri(url);
-
- // Set Headers
- httpRequest.Headers.Add("x-ms-version", "2014-06-01");
-
- // Set Credentials
- cancellationToken.ThrowIfCancellationRequested();
- await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
-
- // Serialize Request
- string requestContent = null;
- JToken requestDoc = null;
-
- JObject backupRequestEnvelopeValue = new JObject();
- requestDoc = backupRequestEnvelopeValue;
-
- if (backupRequestEnvelope.Request != null)
- {
- JObject propertiesValue = new JObject();
- backupRequestEnvelopeValue["properties"] = propertiesValue;
-
- if (backupRequestEnvelope.Request.BackupSchedule != null)
- {
- JObject backupScheduleValue = new JObject();
- propertiesValue["backupSchedule"] = backupScheduleValue;
-
- backupScheduleValue["frequencyInterval"] = backupRequestEnvelope.Request.BackupSchedule.FrequencyInterval;
-
- backupScheduleValue["frequencyUnit"] = backupRequestEnvelope.Request.BackupSchedule.FrequencyUnit.ToString();
-
- backupScheduleValue["keepAtLeastOneBackup"] = backupRequestEnvelope.Request.BackupSchedule.KeepAtLeastOneBackup;
-
- if (backupRequestEnvelope.Request.BackupSchedule.LastExecutionTime != null)
- {
- backupScheduleValue["lastExecutionTime"] = backupRequestEnvelope.Request.BackupSchedule.LastExecutionTime.Value;
- }
-
- backupScheduleValue["retentionPeriodInDays"] = backupRequestEnvelope.Request.BackupSchedule.RetentionPeriodInDays;
-
- if (backupRequestEnvelope.Request.BackupSchedule.StartTime != null)
- {
- backupScheduleValue["startTime"] = backupRequestEnvelope.Request.BackupSchedule.StartTime.Value;
- }
- }
-
- if (backupRequestEnvelope.Request.Databases != null)
- {
- if (backupRequestEnvelope.Request.Databases is ILazyCollection == false || ((ILazyCollection)backupRequestEnvelope.Request.Databases).IsInitialized)
- {
- JArray databasesArray = new JArray();
- foreach (DatabaseBackupSetting databasesItem in backupRequestEnvelope.Request.Databases)
- {
- JObject databaseBackupSettingValue = new JObject();
- databasesArray.Add(databaseBackupSettingValue);
-
- if (databasesItem.ConnectionString != null)
- {
- databaseBackupSettingValue["connectionString"] = databasesItem.ConnectionString;
- }
-
- if (databasesItem.ConnectionStringName != null)
- {
- databaseBackupSettingValue["connectionStringName"] = databasesItem.ConnectionStringName;
- }
-
- if (databasesItem.DatabaseType != null)
- {
- databaseBackupSettingValue["databaseType"] = databasesItem.DatabaseType;
- }
-
- if (databasesItem.Name != null)
- {
- databaseBackupSettingValue["name"] = databasesItem.Name;
- }
- }
- propertiesValue["databases"] = databasesArray;
- }
- }
-
- if (backupRequestEnvelope.Request.Enabled != null)
- {
- propertiesValue["enabled"] = backupRequestEnvelope.Request.Enabled.Value;
- }
-
- if (backupRequestEnvelope.Request.Name != null)
- {
- propertiesValue["name"] = backupRequestEnvelope.Request.Name;
- }
-
- if (backupRequestEnvelope.Request.StorageAccountUrl != null)
- {
- propertiesValue["storageAccountUrl"] = backupRequestEnvelope.Request.StorageAccountUrl;
- }
- }
-
- if (backupRequestEnvelope.Id != null)
- {
- backupRequestEnvelopeValue["id"] = backupRequestEnvelope.Id;
- }
-
- if (backupRequestEnvelope.Name != null)
- {
- backupRequestEnvelopeValue["name"] = backupRequestEnvelope.Name;
- }
-
- backupRequestEnvelopeValue["location"] = backupRequestEnvelope.Location;
-
- if (backupRequestEnvelope.Tags != null)
- {
- JObject tagsDictionary = new JObject();
- foreach (KeyValuePair<string, string> pair in backupRequestEnvelope.Tags)
- {
- string tagsKey = pair.Key;
- string tagsValue = pair.Value;
- tagsDictionary[tagsKey] = tagsValue;
- }
- backupRequestEnvelopeValue["tags"] = tagsDictionary;
- }
-
- if (backupRequestEnvelope.Type != null)
- {
- backupRequestEnvelopeValue["type"] = backupRequestEnvelope.Type;
- }
-
- requestContent = requestDoc.ToString(Newtonsoft.Json.Formatting.Indented);
- httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
- httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
-
- // Send Request
- HttpResponseMessage httpResponse = null;
- try
- {
- if (shouldTrace)
- {
- TracingAdapter.SendRequest(invocationId, httpRequest);
- }
- cancellationToken.ThrowIfCancellationRequested();
- httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
- if (shouldTrace)
- {
- TracingAdapter.ReceiveResponse(invocationId, httpResponse);
- }
- HttpStatusCode statusCode = httpResponse.StatusCode;
- if (statusCode != HttpStatusCode.OK)
- {
- cancellationToken.ThrowIfCancellationRequested();
- CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
- if (shouldTrace)
- {
- TracingAdapter.Error(invocationId, ex);
- }
- throw ex;
- }
-
- // Create Result
- AzureOperationResponse result = null;
- // Deserialize Response
- result = new AzureOperationResponse();
- result.StatusCode = statusCode;
- if (httpResponse.Headers.Contains("x-ms-request-id"))
- {
- result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
- }
-
- if (shouldTrace)
- {
- TracingAdapter.Exit(invocationId, result);
- }
- return result;
- }
- finally
- {
- if (httpResponse != null)
- {
- httpResponse.Dispose();
- }
- }
- }
- finally
- {
- if (httpRequest != null)
- {
- httpRequest.Dispose();
- }
- }
- }
-
- /// <summary>
- /// You can retrieve the config settings for a web site by issuing an
- /// HTTP GET request, or update them by using HTTP PUT with a request
- /// body that contains the settings to be updated. (see
- /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166985.aspx
- /// for more information)
- /// </summary>
- /// <param name='resourceGroupName'>
- /// Required. The name of the resource group.
- /// </param>
- /// <param name='webSiteName'>
- /// Required. The name of the web site.
- /// </param>
- /// <param name='slotName'>
- /// Optional. The name of the slot.
- /// </param>
- /// <param name='parameters'>
- /// Required. The Update Web Site Configuration parameters.
- /// </param>
- /// <param name='cancellationToken'>
- /// Cancellation token.
- /// </param>
- /// <returns>
- /// A standard service response including an HTTP status code and
- /// request ID.
- /// </returns>
- public async Task<AzureOperationResponse> UpdateConfigurationAsync(string resourceGroupName, string webSiteName, string slotName, WebSiteUpdateConfigurationParameters parameters, CancellationToken cancellationToken)
- {
- // Validate
- if (resourceGroupName == null)
- {
- throw new ArgumentNullException("resourceGroupName");
- }
- if (webSiteName == null)
- {
- throw new ArgumentNullException("webSiteName");
- }
- if (parameters == null)
- {
- throw new ArgumentNullException("parameters");
- }
- if (parameters.Location == null)
- {
- throw new ArgumentNullException("parameters.Location");
- }
- if (parameters.Properties == null)
- {
- throw new ArgumentNullException("parameters.Properties");
- }
-
- // Tracing
- bool shouldTrace = TracingAdapter.IsEnabled;
- string invocationId = null;
- if (shouldTrace)
- {
- invocationId = TracingAdapter.NextInvocationId.ToString();
- Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
- tracingParameters.Add("resourceGroupName", resourceGroupName);
- tracingParameters.Add("webSiteName", webSiteName);
- tracingParameters.Add("slotName", slotName);
- tracingParameters.Add("parameters", parameters);
- TracingAdapter.Enter(invocationId, this, "UpdateConfigurationAsync", tracingParameters);
- }
-
- // Construct URL
- string url = "";
- url = url + "/subscriptions/";
- if (this.Client.Credentials.SubscriptionId != null)
- {
- url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
- }
- url = url + "/resourceGroups/";
- url = url + Uri.EscapeDataString(resourceGroupName);
- url = url + "/providers/";
- url = url + "Microsoft.Web";
- url = url + "/";
- url = url + "sites";
- url = url + "/";
- url = url + Uri.EscapeDataString(webSiteName);
- if (slotName != null)
- {
- url = url + "/slots/" + Uri.EscapeDataString(slotName);
- }
- url = url + "/config/web";
- List<string> queryParameters = new List<string>();
- queryParameters.Add("api-version=2014-06-01");
- if (queryParameters.Count > 0)
- {
- url = url + "?" + string.Join("&", queryParameters);
- }
- string baseUrl = this.Client.BaseUri.AbsoluteUri;
- // Trim '/' character fro