PageRenderTime 140ms CodeModel.GetById 8ms app.highlight 73ms RepoModel.GetById 5ms app.codeStats 8ms

/src/WebSiteManagement2/Generated/WebSiteOperations.cs

https://github.com/edumunoz/azure-sdk-for-net
C# | 9288 lines | 7390 code | 875 blank | 1023 comment | 2881 complexity | 19364238039f91d3ea332dc8a6ac8162 MD5 | raw file

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

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

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