/src/WebSiteManagement2/Generated/WebSiteOperations.cs
C# | 9288 lines | 7390 code | 875 blank | 1023 comment | 2881 complexity | 19364238039f91d3ea332dc8a6ac8162 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- //
- // 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();
- …
Large files files are truncated, but you can click here to view the full file