PageRenderTime 331ms CodeModel.GetById 10ms app.highlight 264ms RepoModel.GetById 1ms app.codeStats 3ms

/src/WebSiteManagement/Generated/WebSiteOperations.cs

https://github.com/edumunoz/azure-sdk-for-net
C# | 8390 lines | 6603 code | 761 blank | 1026 comment | 1906 complexity | 955f7dc13d603a866526bac09b8acbc8 MD5 | raw file
   1// 
   2// Copyright (c) Microsoft and contributors.  All rights reserved.
   3// 
   4// Licensed under the Apache License, Version 2.0 (the "License");
   5// you may not use this file except in compliance with the License.
   6// You may obtain a copy of the License at
   7//   http://www.apache.org/licenses/LICENSE-2.0
   8// 
   9// Unless required by applicable law or agreed to in writing, software
  10// distributed under the License is distributed on an "AS IS" BASIS,
  11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12// 
  13// See the License for the specific language governing permissions and
  14// limitations under the License.
  15// 
  16
  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.WindowsAzure.Management.WebSites;
  37using Microsoft.WindowsAzure.Management.WebSites.Models;
  38using Newtonsoft.Json.Linq;
  39
  40namespace Microsoft.WindowsAzure.Management.WebSites
  41{
  42    /// <summary>
  43    /// Operations for managing the web sites in a web space.  (see
  44    /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166981.aspx for
  45    /// more information)
  46    /// </summary>
  47    internal partial class WebSiteOperations : IServiceOperations<WebSiteManagementClient>, IWebSiteOperations
  48    {
  49        /// <summary>
  50        /// Initializes a new instance of the WebSiteOperations class.
  51        /// </summary>
  52        /// <param name='client'>
  53        /// Reference to the service client.
  54        /// </param>
  55        internal WebSiteOperations(WebSiteManagementClient client)
  56        {
  57            this._client = client;
  58        }
  59        
  60        private WebSiteManagementClient _client;
  61        
  62        /// <summary>
  63        /// Gets a reference to the
  64        /// Microsoft.WindowsAzure.Management.WebSites.WebSiteManagementClient.
  65        /// </summary>
  66        public WebSiteManagementClient Client
  67        {
  68            get { return this._client; }
  69        }
  70        
  71        /// <param name='webSpaceName'>
  72        /// Required. The name of the web space.
  73        /// </param>
  74        /// <param name='webSiteName'>
  75        /// Required. The name of the web site.
  76        /// </param>
  77        /// <param name='targetSwapSlot'>
  78        /// Required. The name of the target slot to be swapped with.
  79        /// </param>
  80        /// <param name='cancellationToken'>
  81        /// Cancellation token.
  82        /// </param>
  83        /// <returns>
  84        /// A standard service response including an HTTP status code and
  85        /// request ID.
  86        /// </returns>
  87        public async Task<AzureOperationResponse> ApplySlotConfigurationAsync(string webSpaceName, string webSiteName, string targetSwapSlot, CancellationToken cancellationToken)
  88        {
  89            // Validate
  90            if (webSpaceName == null)
  91            {
  92                throw new ArgumentNullException("webSpaceName");
  93            }
  94            if (webSiteName == null)
  95            {
  96                throw new ArgumentNullException("webSiteName");
  97            }
  98            if (targetSwapSlot == null)
  99            {
 100                throw new ArgumentNullException("targetSwapSlot");
 101            }
 102            
 103            // Tracing
 104            bool shouldTrace = TracingAdapter.IsEnabled;
 105            string invocationId = null;
 106            if (shouldTrace)
 107            {
 108                invocationId = TracingAdapter.NextInvocationId.ToString();
 109                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 110                tracingParameters.Add("webSpaceName", webSpaceName);
 111                tracingParameters.Add("webSiteName", webSiteName);
 112                tracingParameters.Add("targetSwapSlot", targetSwapSlot);
 113                TracingAdapter.Enter(invocationId, this, "ApplySlotConfigurationAsync", tracingParameters);
 114            }
 115            
 116            // Construct URL
 117            string url = "";
 118            url = url + "/";
 119            if (this.Client.Credentials.SubscriptionId != null)
 120            {
 121                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
 122            }
 123            url = url + "/services/WebSpaces/";
 124            url = url + Uri.EscapeDataString(webSpaceName);
 125            url = url + "/sites/";
 126            url = url + Uri.EscapeDataString(webSiteName);
 127            url = url + "/applySlotConfig";
 128            List<string> queryParameters = new List<string>();
 129            queryParameters.Add("targetSwapSlot=" + Uri.EscapeDataString(targetSwapSlot));
 130            if (queryParameters.Count > 0)
 131            {
 132                url = url + "?" + string.Join("&", queryParameters);
 133            }
 134            string baseUrl = this.Client.BaseUri.AbsoluteUri;
 135            // Trim '/' character from the end of baseUrl and beginning of url.
 136            if (baseUrl[baseUrl.Length - 1] == '/')
 137            {
 138                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
 139            }
 140            if (url[0] == '/')
 141            {
 142                url = url.Substring(1);
 143            }
 144            url = baseUrl + "/" + url;
 145            url = url.Replace(" ", "%20");
 146            
 147            // Create HTTP transport objects
 148            HttpRequestMessage httpRequest = null;
 149            try
 150            {
 151                httpRequest = new HttpRequestMessage();
 152                httpRequest.Method = HttpMethod.Post;
 153                httpRequest.RequestUri = new Uri(url);
 154                
 155                // Set Headers
 156                httpRequest.Headers.Add("accept", "application/json");
 157                httpRequest.Headers.Add("x-ms-version", "2014-04-01");
 158                
 159                // Set Credentials
 160                cancellationToken.ThrowIfCancellationRequested();
 161                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
 162                
 163                // Send Request
 164                HttpResponseMessage httpResponse = null;
 165                try
 166                {
 167                    if (shouldTrace)
 168                    {
 169                        TracingAdapter.SendRequest(invocationId, httpRequest);
 170                    }
 171                    cancellationToken.ThrowIfCancellationRequested();
 172                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
 173                    if (shouldTrace)
 174                    {
 175                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
 176                    }
 177                    HttpStatusCode statusCode = httpResponse.StatusCode;
 178                    if (statusCode != HttpStatusCode.OK)
 179                    {
 180                        cancellationToken.ThrowIfCancellationRequested();
 181                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
 182                        if (shouldTrace)
 183                        {
 184                            TracingAdapter.Error(invocationId, ex);
 185                        }
 186                        throw ex;
 187                    }
 188                    
 189                    // Create Result
 190                    AzureOperationResponse result = null;
 191                    // Deserialize Response
 192                    result = new AzureOperationResponse();
 193                    result.StatusCode = statusCode;
 194                    if (httpResponse.Headers.Contains("x-ms-request-id"))
 195                    {
 196                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 197                    }
 198                    
 199                    if (shouldTrace)
 200                    {
 201                        TracingAdapter.Exit(invocationId, result);
 202                    }
 203                    return result;
 204                }
 205                finally
 206                {
 207                    if (httpResponse != null)
 208                    {
 209                        httpResponse.Dispose();
 210                    }
 211                }
 212            }
 213            finally
 214            {
 215                if (httpRequest != null)
 216                {
 217                    httpRequest.Dispose();
 218                }
 219            }
 220        }
 221        
 222        /// <summary>
 223        /// Backups a site on-demand.
 224        /// </summary>
 225        /// <param name='webSpaceName'>
 226        /// Required. The name of the web space.
 227        /// </param>
 228        /// <param name='webSiteName'>
 229        /// Required. The name of the web site.
 230        /// </param>
 231        /// <param name='backupRequest'>
 232        /// Required. A backup specification.
 233        /// </param>
 234        /// <param name='cancellationToken'>
 235        /// Cancellation token.
 236        /// </param>
 237        /// <returns>
 238        /// The backup record created based on the backup request.
 239        /// </returns>
 240        public async Task<WebSiteBackupResponse> BackupAsync(string webSpaceName, string webSiteName, BackupRequest backupRequest, CancellationToken cancellationToken)
 241        {
 242            // Validate
 243            if (webSpaceName == null)
 244            {
 245                throw new ArgumentNullException("webSpaceName");
 246            }
 247            if (webSiteName == null)
 248            {
 249                throw new ArgumentNullException("webSiteName");
 250            }
 251            if (backupRequest == null)
 252            {
 253                throw new ArgumentNullException("backupRequest");
 254            }
 255            
 256            // Tracing
 257            bool shouldTrace = TracingAdapter.IsEnabled;
 258            string invocationId = null;
 259            if (shouldTrace)
 260            {
 261                invocationId = TracingAdapter.NextInvocationId.ToString();
 262                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 263                tracingParameters.Add("webSpaceName", webSpaceName);
 264                tracingParameters.Add("webSiteName", webSiteName);
 265                tracingParameters.Add("backupRequest", backupRequest);
 266                TracingAdapter.Enter(invocationId, this, "BackupAsync", tracingParameters);
 267            }
 268            
 269            // Construct URL
 270            string url = "";
 271            url = url + "/";
 272            if (this.Client.Credentials.SubscriptionId != null)
 273            {
 274                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
 275            }
 276            url = url + "/services/WebSpaces/";
 277            url = url + Uri.EscapeDataString(webSpaceName);
 278            url = url + "/sites/";
 279            url = url + Uri.EscapeDataString(webSiteName);
 280            url = url + "/backup";
 281            string baseUrl = this.Client.BaseUri.AbsoluteUri;
 282            // Trim '/' character from the end of baseUrl and beginning of url.
 283            if (baseUrl[baseUrl.Length - 1] == '/')
 284            {
 285                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
 286            }
 287            if (url[0] == '/')
 288            {
 289                url = url.Substring(1);
 290            }
 291            url = baseUrl + "/" + url;
 292            url = url.Replace(" ", "%20");
 293            
 294            // Create HTTP transport objects
 295            HttpRequestMessage httpRequest = null;
 296            try
 297            {
 298                httpRequest = new HttpRequestMessage();
 299                httpRequest.Method = HttpMethod.Put;
 300                httpRequest.RequestUri = new Uri(url);
 301                
 302                // Set Headers
 303                httpRequest.Headers.Add("x-ms-version", "2014-04-01");
 304                
 305                // Set Credentials
 306                cancellationToken.ThrowIfCancellationRequested();
 307                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
 308                
 309                // Serialize Request
 310                string requestContent = null;
 311                XDocument requestDoc = new XDocument();
 312                
 313                XElement backupRequestElement = new XElement(XName.Get("BackupRequest", "http://schemas.microsoft.com/windowsazure"));
 314                requestDoc.Add(backupRequestElement);
 315                
 316                if (backupRequest.BackupSchedule != null)
 317                {
 318                    XElement backupScheduleElement = new XElement(XName.Get("BackupSchedule", "http://schemas.microsoft.com/windowsazure"));
 319                    backupRequestElement.Add(backupScheduleElement);
 320                    
 321                    XElement frequencyIntervalElement = new XElement(XName.Get("FrequencyInterval", "http://schemas.microsoft.com/windowsazure"));
 322                    frequencyIntervalElement.Value = backupRequest.BackupSchedule.FrequencyInterval.ToString();
 323                    backupScheduleElement.Add(frequencyIntervalElement);
 324                    
 325                    XElement frequencyUnitElement = new XElement(XName.Get("FrequencyUnit", "http://schemas.microsoft.com/windowsazure"));
 326                    frequencyUnitElement.Value = backupRequest.BackupSchedule.FrequencyUnit.ToString();
 327                    backupScheduleElement.Add(frequencyUnitElement);
 328                    
 329                    XElement keepAtLeastOneBackupElement = new XElement(XName.Get("KeepAtLeastOneBackup", "http://schemas.microsoft.com/windowsazure"));
 330                    keepAtLeastOneBackupElement.Value = backupRequest.BackupSchedule.KeepAtLeastOneBackup.ToString().ToLower();
 331                    backupScheduleElement.Add(keepAtLeastOneBackupElement);
 332                    
 333                    if (backupRequest.BackupSchedule.LastExecutionTime != null)
 334                    {
 335                        XElement lastExecutionTimeElement = new XElement(XName.Get("LastExecutionTime", "http://schemas.microsoft.com/windowsazure"));
 336                        lastExecutionTimeElement.Value = string.Format(CultureInfo.InvariantCulture, "{0:O}", backupRequest.BackupSchedule.LastExecutionTime.Value.ToUniversalTime());
 337                        backupScheduleElement.Add(lastExecutionTimeElement);
 338                    }
 339                    
 340                    XElement retentionPeriodInDaysElement = new XElement(XName.Get("RetentionPeriodInDays", "http://schemas.microsoft.com/windowsazure"));
 341                    retentionPeriodInDaysElement.Value = backupRequest.BackupSchedule.RetentionPeriodInDays.ToString();
 342                    backupScheduleElement.Add(retentionPeriodInDaysElement);
 343                    
 344                    if (backupRequest.BackupSchedule.StartTime != null)
 345                    {
 346                        XElement startTimeElement = new XElement(XName.Get("StartTime", "http://schemas.microsoft.com/windowsazure"));
 347                        startTimeElement.Value = string.Format(CultureInfo.InvariantCulture, "{0:O}", backupRequest.BackupSchedule.StartTime.Value.ToUniversalTime());
 348                        backupScheduleElement.Add(startTimeElement);
 349                    }
 350                }
 351                
 352                if (backupRequest.Databases != null)
 353                {
 354                    if (backupRequest.Databases is ILazyCollection == false || ((ILazyCollection)backupRequest.Databases).IsInitialized)
 355                    {
 356                        XElement databasesSequenceElement = new XElement(XName.Get("Databases", "http://schemas.microsoft.com/windowsazure"));
 357                        foreach (DatabaseBackupSetting databasesItem in backupRequest.Databases)
 358                        {
 359                            XElement databaseBackupSettingElement = new XElement(XName.Get("DatabaseBackupSetting", "http://schemas.microsoft.com/windowsazure"));
 360                            databasesSequenceElement.Add(databaseBackupSettingElement);
 361                            
 362                            if (databasesItem.ConnectionString != null)
 363                            {
 364                                XElement connectionStringElement = new XElement(XName.Get("ConnectionString", "http://schemas.microsoft.com/windowsazure"));
 365                                connectionStringElement.Value = databasesItem.ConnectionString;
 366                                databaseBackupSettingElement.Add(connectionStringElement);
 367                            }
 368                            
 369                            if (databasesItem.ConnectionStringName != null)
 370                            {
 371                                XElement connectionStringNameElement = new XElement(XName.Get("ConnectionStringName", "http://schemas.microsoft.com/windowsazure"));
 372                                connectionStringNameElement.Value = databasesItem.ConnectionStringName;
 373                                databaseBackupSettingElement.Add(connectionStringNameElement);
 374                            }
 375                            
 376                            if (databasesItem.DatabaseType != null)
 377                            {
 378                                XElement databaseTypeElement = new XElement(XName.Get("DatabaseType", "http://schemas.microsoft.com/windowsazure"));
 379                                databaseTypeElement.Value = databasesItem.DatabaseType;
 380                                databaseBackupSettingElement.Add(databaseTypeElement);
 381                            }
 382                            
 383                            if (databasesItem.Name != null)
 384                            {
 385                                XElement nameElement = new XElement(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
 386                                nameElement.Value = databasesItem.Name;
 387                                databaseBackupSettingElement.Add(nameElement);
 388                            }
 389                        }
 390                        backupRequestElement.Add(databasesSequenceElement);
 391                    }
 392                }
 393                
 394                if (backupRequest.Enabled != null)
 395                {
 396                    XElement enabledElement = new XElement(XName.Get("Enabled", "http://schemas.microsoft.com/windowsazure"));
 397                    enabledElement.Value = backupRequest.Enabled.ToString().ToLower();
 398                    backupRequestElement.Add(enabledElement);
 399                }
 400                
 401                if (backupRequest.Name != null)
 402                {
 403                    XElement nameElement2 = new XElement(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
 404                    nameElement2.Value = backupRequest.Name;
 405                    backupRequestElement.Add(nameElement2);
 406                }
 407                
 408                if (backupRequest.StorageAccountUrl != null)
 409                {
 410                    XElement storageAccountUrlElement = new XElement(XName.Get("StorageAccountUrl", "http://schemas.microsoft.com/windowsazure"));
 411                    storageAccountUrlElement.Value = backupRequest.StorageAccountUrl;
 412                    backupRequestElement.Add(storageAccountUrlElement);
 413                }
 414                
 415                requestContent = requestDoc.ToString();
 416                httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
 417                httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/xml");
 418                
 419                // Send Request
 420                HttpResponseMessage httpResponse = null;
 421                try
 422                {
 423                    if (shouldTrace)
 424                    {
 425                        TracingAdapter.SendRequest(invocationId, httpRequest);
 426                    }
 427                    cancellationToken.ThrowIfCancellationRequested();
 428                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
 429                    if (shouldTrace)
 430                    {
 431                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
 432                    }
 433                    HttpStatusCode statusCode = httpResponse.StatusCode;
 434                    if (statusCode != HttpStatusCode.OK)
 435                    {
 436                        cancellationToken.ThrowIfCancellationRequested();
 437                        CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
 438                        if (shouldTrace)
 439                        {
 440                            TracingAdapter.Error(invocationId, ex);
 441                        }
 442                        throw ex;
 443                    }
 444                    
 445                    // Create Result
 446                    WebSiteBackupResponse result = null;
 447                    // Deserialize Response
 448                    if (statusCode == HttpStatusCode.OK)
 449                    {
 450                        cancellationToken.ThrowIfCancellationRequested();
 451                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 452                        result = new WebSiteBackupResponse();
 453                        XDocument responseDoc = XDocument.Parse(responseContent);
 454                        
 455                        XElement backupItemElement = responseDoc.Element(XName.Get("BackupItem", "http://schemas.microsoft.com/windowsazure"));
 456                        if (backupItemElement != null)
 457                        {
 458                            BackupItem backupItemInstance = new BackupItem();
 459                            result.BackupItem = backupItemInstance;
 460                            
 461                            XElement storageAccountUrlElement2 = backupItemElement.Element(XName.Get("StorageAccountUrl", "http://schemas.microsoft.com/windowsazure"));
 462                            if (storageAccountUrlElement2 != null)
 463                            {
 464                                string storageAccountUrlInstance = storageAccountUrlElement2.Value;
 465                                backupItemInstance.StorageAccountUrl = storageAccountUrlInstance;
 466                            }
 467                            
 468                            XElement blobNameElement = backupItemElement.Element(XName.Get("BlobName", "http://schemas.microsoft.com/windowsazure"));
 469                            if (blobNameElement != null)
 470                            {
 471                                string blobNameInstance = blobNameElement.Value;
 472                                backupItemInstance.BlobName = blobNameInstance;
 473                            }
 474                            
 475                            XElement nameElement3 = backupItemElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
 476                            if (nameElement3 != null)
 477                            {
 478                                string nameInstance = nameElement3.Value;
 479                                backupItemInstance.Name = nameInstance;
 480                            }
 481                            
 482                            XElement statusElement = backupItemElement.Element(XName.Get("Status", "http://schemas.microsoft.com/windowsazure"));
 483                            if (statusElement != null)
 484                            {
 485                                BackupItemStatus statusInstance = ((BackupItemStatus)Enum.Parse(typeof(BackupItemStatus), statusElement.Value, true));
 486                                backupItemInstance.Status = statusInstance;
 487                            }
 488                            
 489                            XElement sizeInBytesElement = backupItemElement.Element(XName.Get("SizeInBytes", "http://schemas.microsoft.com/windowsazure"));
 490                            if (sizeInBytesElement != null)
 491                            {
 492                                long sizeInBytesInstance = long.Parse(sizeInBytesElement.Value, CultureInfo.InvariantCulture);
 493                                backupItemInstance.SizeInBytes = sizeInBytesInstance;
 494                            }
 495                            
 496                            XElement createdElement = backupItemElement.Element(XName.Get("Created", "http://schemas.microsoft.com/windowsazure"));
 497                            if (createdElement != null && !string.IsNullOrEmpty(createdElement.Value))
 498                            {
 499                                DateTime createdInstance = DateTime.Parse(createdElement.Value, CultureInfo.InvariantCulture);
 500                                backupItemInstance.Created = createdInstance;
 501                            }
 502                            
 503                            XElement logElement = backupItemElement.Element(XName.Get("Log", "http://schemas.microsoft.com/windowsazure"));
 504                            if (logElement != null)
 505                            {
 506                                string logInstance = logElement.Value;
 507                                backupItemInstance.Log = logInstance;
 508                            }
 509                            
 510                            XElement databasesSequenceElement2 = backupItemElement.Element(XName.Get("Databases", "http://schemas.microsoft.com/windowsazure"));
 511                            if (databasesSequenceElement2 != null)
 512                            {
 513                                foreach (XElement databasesElement in databasesSequenceElement2.Elements(XName.Get("DatabaseBackupSetting", "http://schemas.microsoft.com/windowsazure")))
 514                                {
 515                                    DatabaseBackupSetting databaseBackupSettingInstance = new DatabaseBackupSetting();
 516                                    backupItemInstance.Databases.Add(databaseBackupSettingInstance);
 517                                    
 518                                    XElement connectionStringElement2 = databasesElement.Element(XName.Get("ConnectionString", "http://schemas.microsoft.com/windowsazure"));
 519                                    if (connectionStringElement2 != null)
 520                                    {
 521                                        string connectionStringInstance = connectionStringElement2.Value;
 522                                        databaseBackupSettingInstance.ConnectionString = connectionStringInstance;
 523                                    }
 524                                    
 525                                    XElement connectionStringNameElement2 = databasesElement.Element(XName.Get("ConnectionStringName", "http://schemas.microsoft.com/windowsazure"));
 526                                    if (connectionStringNameElement2 != null)
 527                                    {
 528                                        string connectionStringNameInstance = connectionStringNameElement2.Value;
 529                                        databaseBackupSettingInstance.ConnectionStringName = connectionStringNameInstance;
 530                                    }
 531                                    
 532                                    XElement databaseTypeElement2 = databasesElement.Element(XName.Get("DatabaseType", "http://schemas.microsoft.com/windowsazure"));
 533                                    if (databaseTypeElement2 != null)
 534                                    {
 535                                        string databaseTypeInstance = databaseTypeElement2.Value;
 536                                        databaseBackupSettingInstance.DatabaseType = databaseTypeInstance;
 537                                    }
 538                                    
 539                                    XElement nameElement4 = databasesElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
 540                                    if (nameElement4 != null)
 541                                    {
 542                                        string nameInstance2 = nameElement4.Value;
 543                                        databaseBackupSettingInstance.Name = nameInstance2;
 544                                    }
 545                                }
 546                            }
 547                            
 548                            XElement scheduledElement = backupItemElement.Element(XName.Get("Scheduled", "http://schemas.microsoft.com/windowsazure"));
 549                            if (scheduledElement != null)
 550                            {
 551                                bool scheduledInstance = bool.Parse(scheduledElement.Value);
 552                                backupItemInstance.Scheduled = scheduledInstance;
 553                            }
 554                            
 555                            XElement lastRestoreTimeStampElement = backupItemElement.Element(XName.Get("LastRestoreTimeStamp", "http://schemas.microsoft.com/windowsazure"));
 556                            if (lastRestoreTimeStampElement != null && !string.IsNullOrEmpty(lastRestoreTimeStampElement.Value))
 557                            {
 558                                DateTime lastRestoreTimeStampInstance = DateTime.Parse(lastRestoreTimeStampElement.Value, CultureInfo.InvariantCulture);
 559                                backupItemInstance.LastRestoreTimeStamp = lastRestoreTimeStampInstance;
 560                            }
 561                            
 562                            XElement finishedTimeStampElement = backupItemElement.Element(XName.Get("FinishedTimeStamp", "http://schemas.microsoft.com/windowsazure"));
 563                            if (finishedTimeStampElement != null && !string.IsNullOrEmpty(finishedTimeStampElement.Value))
 564                            {
 565                                DateTime finishedTimeStampInstance = DateTime.Parse(finishedTimeStampElement.Value, CultureInfo.InvariantCulture);
 566                                backupItemInstance.FinishedTimeStamp = finishedTimeStampInstance;
 567                            }
 568                            
 569                            XElement correlationIdElement = backupItemElement.Element(XName.Get("CorrelationId", "http://schemas.microsoft.com/windowsazure"));
 570                            if (correlationIdElement != null)
 571                            {
 572                                string correlationIdInstance = correlationIdElement.Value;
 573                                backupItemInstance.CorrelationId = correlationIdInstance;
 574                            }
 575                        }
 576                        
 577                    }
 578                    result.StatusCode = statusCode;
 579                    if (httpResponse.Headers.Contains("x-ms-request-id"))
 580                    {
 581                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 582                    }
 583                    
 584                    if (shouldTrace)
 585                    {
 586                        TracingAdapter.Exit(invocationId, result);
 587                    }
 588                    return result;
 589                }
 590                finally
 591                {
 592                    if (httpResponse != null)
 593                    {
 594                        httpResponse.Dispose();
 595                    }
 596                }
 597            }
 598            finally
 599            {
 600                if (httpRequest != null)
 601                {
 602                    httpRequest.Dispose();
 603                }
 604            }
 605        }
 606        
 607        /// <summary>
 608        /// You can swap a web site from one slot to another slot.
 609        /// </summary>
 610        /// <param name='webSpaceName'>
 611        /// Required. The name of the web space.
 612        /// </param>
 613        /// <param name='webSiteName'>
 614        /// Required. The name of the web site.
 615        /// </param>
 616        /// <param name='sourceSlotName'>
 617        /// Required. The name of the first web site slot to swap (source).
 618        /// </param>
 619        /// <param name='targetSlotName'>
 620        /// Required. The name of the second web site slot to swap with
 621        /// (target).
 622        /// </param>
 623        /// <param name='cancellationToken'>
 624        /// Cancellation token.
 625        /// </param>
 626        /// <returns>
 627        /// The response body contains the status of the specified long-running
 628        /// operation, indicating whether it has succeeded, is inprogress, has
 629        /// timed out, or has failed. Note that this status is distinct from
 630        /// the HTTP status code returned for the Get Operation Status
 631        /// operation itself. If the long-running operation failed, the
 632        /// response body includes error information regarding the failure.
 633        /// </returns>
 634        public async Task<WebSiteOperationStatusResponse> BeginSwappingSlotsAsync(string webSpaceName, string webSiteName, string sourceSlotName, string targetSlotName, CancellationToken cancellationToken)
 635        {
 636            // Validate
 637            if (webSpaceName == null)
 638            {
 639                throw new ArgumentNullException("webSpaceName");
 640            }
 641            if (webSiteName == null)
 642            {
 643                throw new ArgumentNullException("webSiteName");
 644            }
 645            if (sourceSlotName == null)
 646            {
 647                throw new ArgumentNullException("sourceSlotName");
 648            }
 649            if (targetSlotName == null)
 650            {
 651                throw new ArgumentNullException("targetSlotName");
 652            }
 653            
 654            // Tracing
 655            bool shouldTrace = TracingAdapter.IsEnabled;
 656            string invocationId = null;
 657            if (shouldTrace)
 658            {
 659                invocationId = TracingAdapter.NextInvocationId.ToString();
 660                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
 661                tracingParameters.Add("webSpaceName", webSpaceName);
 662                tracingParameters.Add("webSiteName", webSiteName);
 663                tracingParameters.Add("sourceSlotName", sourceSlotName);
 664                tracingParameters.Add("targetSlotName", targetSlotName);
 665                TracingAdapter.Enter(invocationId, this, "BeginSwappingSlotsAsync", tracingParameters);
 666            }
 667            
 668            // Construct URL
 669            string url = "";
 670            url = url + "/";
 671            if (this.Client.Credentials.SubscriptionId != null)
 672            {
 673                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
 674            }
 675            url = url + "/services/WebSpaces/";
 676            url = url + Uri.EscapeDataString(webSpaceName);
 677            url = url + "/sites/";
 678            url = url + Uri.EscapeDataString(webSiteName);
 679            url = url + "(";
 680            url = url + Uri.EscapeDataString(sourceSlotName);
 681            url = url + ")/slots";
 682            List<string> queryParameters = new List<string>();
 683            queryParameters.Add("Command=swap");
 684            queryParameters.Add("targetSlot=" + Uri.EscapeDataString(targetSlotName));
 685            if (queryParameters.Count > 0)
 686            {
 687                url = url + "?" + string.Join("&", queryParameters);
 688            }
 689            string baseUrl = this.Client.BaseUri.AbsoluteUri;
 690            // Trim '/' character from the end of baseUrl and beginning of url.
 691            if (baseUrl[baseUrl.Length - 1] == '/')
 692            {
 693                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
 694            }
 695            if (url[0] == '/')
 696            {
 697                url = url.Substring(1);
 698            }
 699            url = baseUrl + "/" + url;
 700            url = url.Replace(" ", "%20");
 701            
 702            // Create HTTP transport objects
 703            HttpRequestMessage httpRequest = null;
 704            try
 705            {
 706                httpRequest = new HttpRequestMessage();
 707                httpRequest.Method = HttpMethod.Post;
 708                httpRequest.RequestUri = new Uri(url);
 709                
 710                // Set Headers
 711                httpRequest.Headers.Add("x-ms-version", "2014-04-01");
 712                
 713                // Set Credentials
 714                cancellationToken.ThrowIfCancellationRequested();
 715                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
 716                
 717                // Send Request
 718                HttpResponseMessage httpResponse = null;
 719                try
 720                {
 721                    if (shouldTrace)
 722                    {
 723                        TracingAdapter.SendRequest(invocationId, httpRequest);
 724                    }
 725                    cancellationToken.ThrowIfCancellationRequested();
 726                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
 727                    if (shouldTrace)
 728                    {
 729                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
 730                    }
 731                    HttpStatusCode statusCode = httpResponse.StatusCode;
 732                    if (statusCode != HttpStatusCode.OK)
 733                    {
 734                        cancellationToken.ThrowIfCancellationRequested();
 735                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
 736                        if (shouldTrace)
 737                        {
 738                            TracingAdapter.Error(invocationId, ex);
 739                        }
 740                        throw ex;
 741                    }
 742                    
 743                    // Create Result
 744                    WebSiteOperationStatusResponse result = null;
 745                    // Deserialize Response
 746                    if (statusCode == HttpStatusCode.OK)
 747                    {
 748                        cancellationToken.ThrowIfCancellationRequested();
 749                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
 750                        result = new WebSiteOperationStatusResponse();
 751                        XDocument responseDoc = XDocument.Parse(responseContent);
 752                        
 753                        XElement operationElement = responseDoc.Element(XName.Get("Operation", "http://schemas.microsoft.com/windowsazure"));
 754                        if (operationElement != null)
 755                        {
 756                            XElement createdTimeElement = operationElement.Element(XName.Get("CreatedTime", "http://schemas.microsoft.com/windowsazure"));
 757                            if (createdTimeElement != null)
 758                            {
 759                                DateTime createdTimeInstance = DateTime.Parse(createdTimeElement.Value, CultureInfo.InvariantCulture);
 760                                result.CreatedTime = createdTimeInstance;
 761                            }
 762                            
 763                            XElement errorsSequenceElement = operationElement.Element(XName.Get("Errors", "http://schemas.microsoft.com/windowsazure"));
 764                            if (errorsSequenceElement != null)
 765                            {
 766                                bool isNil = false;
 767                                XAttribute nilAttribute = errorsSequenceElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
 768                                if (nilAttribute != null)
 769                                {
 770                                    isNil = nilAttribute.Value == "true";
 771                                }
 772                                if (isNil == false)
 773                                {
 774                                    foreach (XElement errorsElement in errorsSequenceElement.Elements(XName.Get("Error", "http://schemas.microsoft.com/windowsazure")))
 775                                    {
 776                                        WebSiteOperationStatusResponse.Error errorInstance = new WebSiteOperationStatusResponse.Error();
 777                                        result.Errors.Add(errorInstance);
 778                                        
 779                                        XElement codeElement = errorsElement.Element(XName.Get("Code", "http://schemas.microsoft.com/windowsazure"));
 780                                        if (codeElement != null)
 781                                        {
 782                                            bool isNil2 = false;
 783                                            XAttribute nilAttribute2 = codeElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
 784                                            if (nilAttribute2 != null)
 785                                            {
 786                                                isNil2 = nilAttribute2.Value == "true";
 787                                            }
 788                                            if (isNil2 == false)
 789                                            {
 790                                                string codeInstance = codeElement.Value;
 791                                                errorInstance.Code = codeInstance;
 792                                            }
 793                                        }
 794                                        
 795                                        XElement messageElement = errorsElement.Element(XName.Get("Message", "http://schemas.microsoft.com/windowsazure"));
 796                                        if (messageElement != null)
 797                                        {
 798                                            bool isNil3 = false;
 799                                            XAttribute nilAttribute3 = messageElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
 800                                            if (nilAttribute3 != null)
 801                                            {
 802                                                isNil3 = nilAttribute3.Value == "true";
 803                                            }
 804                                            if (isNil3 == false)
 805                                            {
 806                                                string messageInstance = messageElement.Value;
 807                                                errorInstance.Message = messageInstance;
 808                                            }
 809                                        }
 810                                        
 811                                        XElement extendedCodeElement = errorsElement.Element(XName.Get("ExtendedCode", "http://schemas.microsoft.com/windowsazure"));
 812                                        if (extendedCodeElement != null)
 813                                        {
 814                                            bool isNil4 = false;
 815                                            XAttribute nilAttribute4 = extendedCodeElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
 816                                            if (nilAttribute4 != null)
 817                                            {
 818                                                isNil4 = nilAttribute4.Value == "true";
 819                                            }
 820                                            if (isNil4 == false)
 821                                            {
 822                                                string extendedCodeInstance = extendedCodeElement.Value;
 823                                                errorInstance.ExtendedCode = extendedCodeInstance;
 824                                            }
 825                                        }
 826                                        
 827                                        XElement messageTemplateElement = errorsElement.Element(XName.Get("MessageTemplate", "http://schemas.microsoft.com/windowsazure"));
 828                                        if (messageTemplateElement != null)
 829                                        {
 830                                            bool isNil5 = false;
 831                                            XAttribute nilAttribute5 = messageTemplateElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
 832                                            if (nilAttribute5 != null)
 833                                            {
 834                                                isNil5 = nilAttribute5.Value == "true";
 835                                            }
 836                                            if (isNil5 == false)
 837                                            {
 838                                                string messageTemplateInstance = messageTemplateElement.Value;
 839                                                errorInstance.MessageTemplate = messageTemplateInstance;
 840                                            }
 841                                        }
 842                                        
 843                                        XElement parametersSequenceElement = errorsElement.Element(XName.Get("Parameters", "http://schemas.microsoft.com/windowsazure"));
 844                                        if (parametersSequenceElement != null)
 845                                        {
 846                                            bool isNil6 = false;
 847                                            XAttribute nilAttribute6 = parametersSequenceElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
 848                                            if (nilAttribute6 != null)
 849                                            {
 850                                                isNil6 = nilAttribute6.Value == "true";
 851                                            }
 852                                            if (isNil6 == false)
 853                                            {
 854                                                foreach (XElement parametersElement in parametersSequenceElement.Elements(XName.Get("string", "http://schemas.microsoft.com/2003/10/Serialization/Arrays")))
 855                                                {
 856                                                    errorInstance.Parameters.Add(parametersElement.Value);
 857                                                }
 858                                            }
 859                                            else
 860                                            {
 861                                                errorInstance.Parameters = null;
 862                                            }
 863                                        }
 864                                        
 865                                        XElement innerErrorsElement = errorsElement.Element(XName.Get("InnerErrors", "http://schemas.microsoft.com/windowsazure"));
 866                                        if (innerErrorsElement != null)
 867                                        {
 868                                            bool isNil7 = false;
 869                                            XAttribute nilAttribute7 = innerErrorsElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
 870                                            if (nilAttribute7 != null)
 871                                            {
 872                                                isNil7 = nilAttribute7.Value == "true";
 873                                            }
 874                                            if (isNil7 == false)
 875                                            {
 876                                                string innerErrorsInstance = innerErrorsElement.Value;
 877                                                errorInstance.InnerErrors = innerErrorsInstance;
 878                                            }
 879                                        }
 880                                    }
 881                                }
 882                                else
 883                                {
 884                                    result.Errors = null;
 885                                }
 886                            }
 887                            
 888                            XElement expirationTimeElement = operationElement.Element(XName.Get("ExpirationTime", "http://schemas.microsoft.com/windowsazure"));
 889                            if (expirationTimeElement != null)
 890                            {
 891                                DateTime expirationTimeInstance = DateTime.Parse(expirationTimeElement.Value, CultureInfo.InvariantCulture);
 892                                result.ExpirationTime = expirationTimeInstance;
 893                            }
 894                            
 895                            XElement geoMasterOperationIdElement = operationElement.Element(XName.Get("GeoMasterOperationId", "http://schemas.microsoft.com/windowsazure"));
 896                            if (geoMasterOperationIdElement != null)
 897                            {
 898                                bool isNil8 = false;
 899                                XAttribute nilAttribute8 = geoMasterOperationIdElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
 900                                if (nilAttribute8 != null)
 901                                {
 902                                    isNil8 = nilAttribute8.Value == "true";
 903                                }
 904                                if (isNil8 == false)
 905                                {
 906                                    string geoMasterOperationIdInstance = geoMasterOperationIdElement.Value;
 907                                    result.GeoMasterOperationId = geoMasterOperationIdInstance;
 908                                }
 909                            }
 910                            
 911                            XElement idElement = operationElement.Element(XName.Get("Id", "http://schemas.microsoft.com/windowsazure"));
 912                            if (idElement != null)
 913                            {
 914                                bool isNil9 = false;
 915                                XAttribute nilAttribute9 = idElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
 916                                if (nilAttribute9 != null)
 917                                {
 918                                    isNil9 = nilAttribute9.Value == "true";
 919                                }
 920                                if (isNil9 == false)
 921                                {
 922                                    string idInstance = idElement.Value;
 923                                    result.OperationId = idInstance;
 924                                }
 925                            }
 926                            
 927                            XElement modifiedTimeElement = operationElement.Element(XName.Get("ModifiedTime", "http://schemas.microsoft.com/windowsazure"));
 928                            if (modifiedTimeElement != null)
 929                            {
 930                                DateTime modifiedTimeInstance = DateTime.Parse(modifiedTimeElement.Value, CultureInfo.InvariantCulture);
 931                                result.ModifiedTime = modifiedTimeInstance;
 932                            }
 933                            
 934                            XElement nameElement = operationElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
 935                            if (nameElement != null)
 936                            {
 937                                bool isNil10 = false;
 938                                XAttribute nilAttribute10 = nameElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
 939                                if (nilAttribute10 != null)
 940                                {
 941                                    isNil10 = nilAttribute10.Value == "true";
 942                                }
 943                                if (isNil10 == false)
 944                                {
 945                                    string nameInstance = nameElement.Value;
 946                                    result.Name = nameInstance;
 947                                }
 948                            }
 949                            
 950                            XElement statusElement = operationElement.Element(XName.Get("Status", "http://schemas.microsoft.com/windowsazure"));
 951                            if (statusElement != null)
 952                            {
 953                                WebSiteOperationStatus statusInstance = ((WebSiteOperationStatus)Enum.Parse(typeof(WebSiteOperationStatus), statusElement.Value, true));
 954                                result.Status = statusInstance;
 955                            }
 956                        }
 957                        
 958                    }
 959                    result.StatusCode = statusCode;
 960                    if (httpResponse.Headers.Contains("x-ms-request-id"))
 961                    {
 962                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
 963                    }
 964                    
 965                    if (shouldTrace)
 966                    {
 967                        TracingAdapter.Exit(invocationId, result);
 968                    }
 969                    return result;
 970                }
 971                finally
 972                {
 973                    if (httpResponse != null)
 974                    {
 975                        httpResponse.Dispose();
 976                    }
 977                }
 978            }
 979            finally
 980            {
 981                if (httpRequest != null)
 982                {
 983                    httpRequest.Dispose();
 984                }
 985            }
 986        }
 987        
 988        /// <summary>
 989        /// You can create a web site by using a POST request that includes the
 990        /// name of the web site and other information in the request body.
 991        /// (see
 992        /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166986.aspx
 993        /// for more information)
 994        /// </summary>
 995        /// <param name='webSpaceName'>
 996        /// Required. The name of the web space.
 997        /// </param>
 998        /// <param name='parameters'>
 999        /// Required. Parameters supplied to the Create Web Site operation.
1000        /// </param>
1001        /// <param name='cancellationToken'>
1002        /// Cancellation token.
1003        /// </param>
1004        /// <returns>
1005        /// The Create Web Site operation response.
1006        /// </returns>
1007        public async Task<WebSiteCreateResponse> CreateAsync(string webSpaceName, WebSiteCreateParameters parameters, CancellationToken cancellationToken)
1008        {
1009            // Validate
1010            if (webSpaceName == null)
1011            {
1012                throw new ArgumentNullException("webSpaceName");
1013            }
1014            if (parameters == null)
1015            {
1016                throw new ArgumentNullException("parameters");
1017            }
1018            if (parameters.Name == null)
1019            {
1020                throw new ArgumentNullException("parameters.Name");
1021            }
1022            if (parameters.ServerFarm == null)
1023            {
1024                throw new ArgumentNullException("parameters.ServerFarm");
1025            }
1026            if (parameters.WebSpace != null)
1027            {
1028                if (parameters.WebSpace.GeoRegion == null)
1029                {
1030                    throw new ArgumentNullException("parameters.WebSpace.GeoRegion");
1031                }
1032                if (parameters.WebSpace.Name == null)
1033                {
1034                    throw new ArgumentNullException("parameters.WebSpace.Name");
1035                }
1036                if (parameters.WebSpace.Plan == null)
1037                {
1038                    throw new ArgumentNullException("parameters.WebSpace.Plan");
1039                }
1040            }
1041            
1042            // Tracing
1043            bool shouldTrace = TracingAdapter.IsEnabled;
1044            string invocationId = null;
1045            if (shouldTrace)
1046            {
1047                invocationId = TracingAdapter.NextInvocationId.ToString();
1048                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
1049                tracingParameters.Add("webSpaceName", webSpaceName);
1050                tracingParameters.Add("parameters", parameters);
1051                TracingAdapter.Enter(invocationId, this, "CreateAsync", tracingParameters);
1052            }
1053            
1054            // Construct URL
1055            string url = "";
1056            url = url + "/";
1057            if (this.Client.Credentials.SubscriptionId != null)
1058            {
1059                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
1060            }
1061            url = url + "/services/WebSpaces/";
1062            url = url + Uri.EscapeDataString(webSpaceName);
1063            url = url + "/sites";
1064            string baseUrl = this.Client.BaseUri.AbsoluteUri;
1065            // Trim '/' character from the end of baseUrl and beginning of url.
1066            if (baseUrl[baseUrl.Length - 1] == '/')
1067            {
1068                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
1069            }
1070            if (url[0] == '/')
1071            {
1072                url = url.Substring(1);
1073            }
1074            url = baseUrl + "/" + url;
1075            url = url.Replace(" ", "%20");
1076            
1077            // Create HTTP transport objects
1078            HttpRequestMessage httpRequest = null;
1079            try
1080            {
1081                httpRequest = new HttpRequestMessage();
1082                httpRequest.Method = HttpMethod.Post;
1083                httpRequest.RequestUri = new Uri(url);
1084                
1085                // Set Headers
1086                httpRequest.Headers.Add("x-ms-version", "2014-04-01");
1087                
1088                // Set Credentials
1089                cancellationToken.ThrowIfCancellationRequested();
1090                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
1091                
1092                // Serialize Request
1093                string requestContent = null;
1094                XDocument requestDoc = new XDocument();
1095                
1096                XElement siteElement = new XElement(XName.Get("Site", "http://schemas.microsoft.com/windowsazure"));
1097                requestDoc.Add(siteElement);
1098                
1099                XElement nameElement = new XElement(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
1100                nameElement.Value = parameters.Name;
1101                siteElement.Add(nameElement);
1102                
1103                XElement serverFarmElement = new XElement(XName.Get("ServerFarm", "http://schemas.microsoft.com/windowsazure"));
1104                serverFarmElement.Value = parameters.ServerFarm;
1105                siteElement.Add(serverFarmElement);
1106                
1107                if (parameters.WebSpace != null)
1108                {
1109                    XElement webSpaceToCreateElement = new XElement(XName.Get("WebSpaceToCreate", "http://schemas.microsoft.com/windowsazure"));
1110                    siteElement.Add(webSpaceToCreateElement);
1111                    
1112                    XElement geoRegionElement = new XElement(XName.Get("GeoRegion", "http://schemas.microsoft.com/windowsazure"));
1113                    geoRegionElement.Value = parameters.WebSpace.GeoRegion;
1114                    webSpaceToCreateElement.Add(geoRegionElement);
1115                    
1116                    XElement nameElement2 = new XElement(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
1117                    nameElement2.Value = parameters.WebSpace.Name;
1118                    webSpaceToCreateElement.Add(nameElement2);
1119                    
1120                    XElement planElement = new XElement(XName.Get("Plan", "http://schemas.microsoft.com/windowsazure"));
1121                    planElement.Value = parameters.WebSpace.Plan;
1122                    webSpaceToCreateElement.Add(planElement);
1123                }
1124                
1125                requestContent = requestDoc.ToString();
1126                httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
1127                httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/xml");
1128                
1129                // Send Request
1130                HttpResponseMessage httpResponse = null;
1131                try
1132                {
1133                    if (shouldTrace)
1134                    {
1135                        TracingAdapter.SendRequest(invocationId, httpRequest);
1136                    }
1137                    cancellationToken.ThrowIfCancellationRequested();
1138                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
1139                    if (shouldTrace)
1140                    {
1141                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
1142                    }
1143                    HttpStatusCode statusCode = httpResponse.StatusCode;
1144                    if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.Created)
1145                    {
1146                        cancellationToken.ThrowIfCancellationRequested();
1147                        CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
1148                        if (shouldTrace)
1149                        {
1150                            TracingAdapter.Error(invocationId, ex);
1151                        }
1152                        throw ex;
1153                    }
1154                    
1155                    // Create Result
1156                    WebSiteCreateResponse result = null;
1157                    // Deserialize Response
1158                    if (statusCode == HttpStatusCode.OK || statusCode == HttpStatusCode.Created)
1159                    {
1160                        cancellationToken.ThrowIfCancellationRequested();
1161                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
1162                        result = new WebSiteCreateResponse();
1163                        XDocument responseDoc = XDocument.Parse(responseContent);
1164                        
1165                        XElement siteElement2 = responseDoc.Element(XName.Get("Site", "http://schemas.microsoft.com/windowsazure"));
1166                        if (siteElement2 != null)
1167                        {
1168                            WebSite webSiteInstance = new WebSite();
1169                            result.WebSite = webSiteInstance;
1170                            
1171                            XElement adminEnabledElement = siteElement2.Element(XName.Get("AdminEnabled", "http://schemas.microsoft.com/windowsazure"));
1172                            if (adminEnabledElement != null && !string.IsNullOrEmpty(adminEnabledElement.Value))
1173                            {
1174                                bool adminEnabledInstance = bool.Parse(adminEnabledElement.Value);
1175                                webSiteInstance.AdminEnabled = adminEnabledInstance;
1176                            }
1177                            
1178                            XElement availabilityStateElement = siteElement2.Element(XName.Get("AvailabilityState", "http://schemas.microsoft.com/windowsazure"));
1179                            if (availabilityStateElement != null && !string.IsNullOrEmpty(availabilityStateElement.Value))
1180                            {
1181                                WebSpaceAvailabilityState availabilityStateInstance = ((WebSpaceAvailabilityState)Enum.Parse(typeof(WebSpaceAvailabilityState), availabilityStateElement.Value, true));
1182                                webSiteInstance.AvailabilityState = availabilityStateInstance;
1183                            }
1184                            
1185                            XElement sKUElement = siteElement2.Element(XName.Get("SKU", "http://schemas.microsoft.com/windowsazure"));
1186                            if (sKUElement != null)
1187                            {
1188                                SkuOptions sKUInstance = ((SkuOptions)Enum.Parse(typeof(SkuOptions), sKUElement.Value, true));
1189                                webSiteInstance.Sku = sKUInstance;
1190                            }
1191                            
1192                            XElement enabledElement = siteElement2.Element(XName.Get("Enabled", "http://schemas.microsoft.com/windowsazure"));
1193                            if (enabledElement != null && !string.IsNullOrEmpty(enabledElement.Value))
1194                            {
1195                                bool enabledInstance = bool.Parse(enabledElement.Value);
1196                                webSiteInstance.Enabled = enabledInstance;
1197                            }
1198                            
1199                            XElement enabledHostNamesSequenceElement = siteElement2.Element(XName.Get("EnabledHostNames", "http://schemas.microsoft.com/windowsazure"));
1200                            if (enabledHostNamesSequenceElement != null)
1201                            {
1202                                foreach (XElement enabledHostNamesElement in enabledHostNamesSequenceElement.Elements(XName.Get("string", "http://schemas.microsoft.com/2003/10/Serialization/Arrays")))
1203                                {
1204                                    webSiteInstance.EnabledHostNames.Add(enabledHostNamesElement.Value);
1205                                }
1206                            }
1207                            
1208                            XElement hostNameSslStatesSequenceElement = siteElement2.Element(XName.Get("HostNameSslStates", "http://schemas.microsoft.com/windowsazure"));
1209                            if (hostNameSslStatesSequenceElement != null)
1210                            {
1211                                foreach (XElement hostNameSslStatesElement in hostNameSslStatesSequenceElement.Elements(XName.Get("HostNameSslState", "http://schemas.microsoft.com/windowsazure")))
1212                                {
1213                                    WebSite.WebSiteHostNameSslState hostNameSslStateInstance = new WebSite.WebSiteHostNameSslState();
1214                                    webSiteInstance.HostNameSslStates.Add(hostNameSslStateInstance);
1215                                    
1216                                    XElement nameElement3 = hostNameSslStatesElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
1217                                    if (nameElement3 != null)
1218                                    {
1219                                        string nameInstance = nameElement3.Value;
1220                                        hostNameSslStateInstance.Name = nameInstance;
1221                                    }
1222                                    
1223                                    XElement sslStateElement = hostNameSslStatesElement.Element(XName.Get("SslState", "http://schemas.microsoft.com/windowsazure"));
1224                                    if (sslStateElement != null && !string.IsNullOrEmpty(sslStateElement.Value))
1225                                    {
1226                                        WebSiteSslState sslStateInstance = ((WebSiteSslState)Enum.Parse(typeof(WebSiteSslState), sslStateElement.Value, true));
1227                                        hostNameSslStateInstance.SslState = sslStateInstance;
1228                                    }
1229                                    
1230                                    XElement thumbprintElement = hostNameSslStatesElement.Element(XName.Get("Thumbprint", "http://schemas.microsoft.com/windowsazure"));
1231                                    if (thumbprintElement != null)
1232                                    {
1233                                        bool isNil = false;
1234                                        XAttribute nilAttribute = thumbprintElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
1235                                        if (nilAttribute != null)
1236                                        {
1237                                            isNil = nilAttribute.Value == "true";
1238                                        }
1239                                        if (isNil == false)
1240                                        {
1241                                            string thumbprintInstance = thumbprintElement.Value;
1242                                            hostNameSslStateInstance.Thumbprint = thumbprintInstance;
1243                                        }
1244                                    }
1245                                    
1246                                    XElement virtualIPElement = hostNameSslStatesElement.Element(XName.Get("VirtualIP", "http://schemas.microsoft.com/windowsazure"));
1247                                    if (virtualIPElement != null)
1248                                    {
1249                                        bool isNil2 = false;
1250                                        XAttribute nilAttribute2 = virtualIPElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
1251                                        if (nilAttribute2 != null)
1252                                        {
1253                                            isNil2 = nilAttribute2.Value == "true";
1254                                        }
1255                                        if (isNil2 == false)
1256                                        {
1257                                            string virtualIPInstance = virtualIPElement.Value;
1258                                            hostNameSslStateInstance.VirtualIP = virtualIPInstance;
1259                                        }
1260                                    }
1261                                }
1262                            }
1263                            
1264                            XElement hostNamesSequenceElement = siteElement2.Element(XName.Get("HostNames", "http://schemas.microsoft.com/windowsazure"));
1265                            if (hostNamesSequenceElement != null)
1266                            {
1267                                foreach (XElement hostNamesElement in hostNamesSequenceElement.Elements(XName.Get("string", "http://schemas.microsoft.com/2003/10/Serialization/Arrays")))
1268                                {
1269                                    webSiteInstance.HostNames.Add(hostNamesElement.Value);
1270                                }
1271                            }
1272                            
1273                            XElement lastModifiedTimeUtcElement = siteElement2.Element(XName.Get("LastModifiedTimeUtc", "http://schemas.microsoft.com/windowsazure"));
1274                            if (lastModifiedTimeUtcElement != null && !string.IsNullOrEmpty(lastModifiedTimeUtcElement.Value))
1275                            {
1276                                DateTime lastModifiedTimeUtcInstance = DateTime.Parse(lastModifiedTimeUtcElement.Value, CultureInfo.InvariantCulture);
1277                                webSiteInstance.LastModifiedTimeUtc = lastModifiedTimeUtcInstance;
1278                            }
1279                            
1280                            XElement nameElement4 = siteElement2.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
1281                            if (nameElement4 != null)
1282                            {
1283                                string nameInstance2 = nameElement4.Value;
1284                                webSiteInstance.Name = nameInstance2;
1285                            }
1286                            
1287                            XElement repositorySiteNameElement = siteElement2.Element(XName.Get("RepositorySiteName", "http://schemas.microsoft.com/windowsazure"));
1288                            if (repositorySiteNameElement != null)
1289                            {
1290                                string repositorySiteNameInstance = repositorySiteNameElement.Value;
1291                                webSiteInstance.RepositorySiteName = repositorySiteNameInstance;
1292                            }
1293                            
1294                            XElement runtimeAvailabilityStateElement = siteElement2.Element(XName.Get("RuntimeAvailabilityState", "http://schemas.microsoft.com/windowsazure"));
1295                            if (runtimeAvailabilityStateElement != null && !string.IsNullOrEmpty(runtimeAvailabilityStateElement.Value))
1296                            {
1297                                WebSiteRuntimeAvailabilityState runtimeAvailabilityStateInstance = ((WebSiteRuntimeAvailabilityState)Enum.Parse(typeof(WebSiteRuntimeAvailabilityState), runtimeAvailabilityStateElement.Value, true));
1298                                webSiteInstance.RuntimeAvailabilityState = runtimeAvailabilityStateInstance;
1299                            }
1300                            
1301                            XElement selfLinkElement = siteElement2.Element(XName.Get("SelfLink", "http://schemas.microsoft.com/windowsazure"));
1302                            if (selfLinkElement != null)
1303                            {
1304                                Uri selfLinkInstance = TypeConversion.TryParseUri(selfLinkElement.Value);
1305                                webSiteInstance.Uri = selfLinkInstance;
1306                            }
1307                            
1308                            XElement serverFarmElement2 = siteElement2.Element(XName.Get("ServerFarm", "http://schemas.microsoft.com/windowsazure"));
1309                            if (serverFarmElement2 != null)
1310                            {
1311                                string serverFarmInstance = serverFarmElement2.Value;
1312                                webSiteInstance.ServerFarm = serverFarmInstance;
1313                            }
1314                            
1315                            XElement sitePropertiesElement = siteElement2.Element(XName.Get("SiteProperties", "http://schemas.microsoft.com/windowsazure"));
1316                            if (sitePropertiesElement != null)
1317                            {
1318                                WebSite.WebSiteProperties sitePropertiesInstance = new WebSite.WebSiteProperties();
1319                                webSiteInstance.SiteProperties = sitePropertiesInstance;
1320                                
1321                                XElement appSettingsSequenceElement = sitePropertiesElement.Element(XName.Get("AppSettings", "http://schemas.microsoft.com/windowsazure"));
1322                                if (appSettingsSequenceElement != null)
1323                                {
1324                                    foreach (XElement appSettingsElement in appSettingsSequenceElement.Elements(XName.Get("NameValuePair", "http://schemas.microsoft.com/windowsazure")))
1325                                    {
1326                                        string appSettingsKey = appSettingsElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure")).Value;
1327                                        string appSettingsValue = appSettingsElement.Element(XName.Get("Value", "http://schemas.microsoft.com/windowsazure")).Value;
1328                                        sitePropertiesInstance.AppSettings.Add(appSettingsKey, appSettingsValue);
1329                                    }
1330                                }
1331                                
1332                                XElement metadataSequenceElement = sitePropertiesElement.Element(XName.Get("Metadata", "http://schemas.microsoft.com/windowsazure"));
1333                                if (metadataSequenceElement != null)
1334                                {
1335                                    foreach (XElement metadataElement in metadataSequenceElement.Elements(XName.Get("NameValuePair", "http://schemas.microsoft.com/windowsazure")))
1336                                    {
1337                                        string metadataKey = metadataElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure")).Value;
1338                                        string metadataValue = metadataElement.Element(XName.Get("Value", "http://schemas.microsoft.com/windowsazure")).Value;
1339                                        sitePropertiesInstance.Metadata.Add(metadataKey, metadataValue);
1340                                    }
1341                                }
1342                                
1343                                XElement propertiesSequenceElement = sitePropertiesElement.Element(XName.Get("Properties", "http://schemas.microsoft.com/windowsazure"));
1344                                if (propertiesSequenceElement != null)
1345                                {
1346                                    foreach (XElement propertiesElement in propertiesSequenceElement.Elements(XName.Get("NameValuePair", "http://schemas.microsoft.com/windowsazure")))
1347                                    {
1348                                        string propertiesKey = propertiesElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure")).Value;
1349                                        string propertiesValue = propertiesElement.Element(XName.Get("Value", "http://schemas.microsoft.com/windowsazure")).Value;
1350                                        sitePropertiesInstance.Properties.Add(propertiesKey, propertiesValue);
1351                                    }
1352                                }
1353                            }
1354                            
1355                            XElement stateElement = siteElement2.Element(XName.Get("State", "http://schemas.microsoft.com/windowsazure"));
1356                            if (stateElement != null)
1357                            {
1358                                string stateInstance = stateElement.Value;
1359                                webSiteInstance.State = stateInstance;
1360                            }
1361                            
1362                            XElement usageStateElement = siteElement2.Element(XName.Get("UsageState", "http://schemas.microsoft.com/windowsazure"));
1363                            if (usageStateElement != null && !string.IsNullOrEmpty(usageStateElement.Value))
1364                            {
1365                                WebSiteUsageState usageStateInstance = ((WebSiteUsageState)Enum.Parse(typeof(WebSiteUsageState), usageStateElement.Value, true));
1366                                webSiteInstance.UsageState = usageStateInstance;
1367                            }
1368                            
1369                            XElement webSpaceElement = siteElement2.Element(XName.Get("WebSpace", "http://schemas.microsoft.com/windowsazure"));
1370                            if (webSpaceElement != null)
1371                            {
1372                                string webSpaceInstance = webSpaceElement.Value;
1373                                webSiteInstance.WebSpace = webSpaceInstance;
1374                            }
1375                        }
1376                        
1377                    }
1378                    result.StatusCode = statusCode;
1379                    if (httpResponse.Headers.Contains("x-ms-request-id"))
1380                    {
1381                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
1382                    }
1383                    
1384                    if (shouldTrace)
1385                    {
1386                        TracingAdapter.Exit(invocationId, result);
1387                    }
1388                    return result;
1389                }
1390                finally
1391                {
1392                    if (httpResponse != null)
1393                    {
1394                        httpResponse.Dispose();
1395                    }
1396                }
1397            }
1398            finally
1399            {
1400                if (httpRequest != null)
1401                {
1402                    httpRequest.Dispose();
1403                }
1404            }
1405        }
1406        
1407        /// <summary>
1408        /// Creates an association to a hybrid connection for a web site.
1409        /// </summary>
1410        /// <param name='webSpaceName'>
1411        /// Required. The name of the web space.
1412        /// </param>
1413        /// <param name='siteName'>
1414        /// Required. The name of the web site.
1415        /// </param>
1416        /// <param name='parameters'>
1417        /// Required. Parameters supplied to the Create Hybrid Connection
1418        /// operation.
1419        /// </param>
1420        /// <param name='cancellationToken'>
1421        /// Cancellation token.
1422        /// </param>
1423        /// <returns>
1424        /// The Create Hybrid Connection operation response.
1425        /// </returns>
1426        public async Task<HybridConnectionCreateResponse> CreateHybridConnectionAsync(string webSpaceName, string siteName, HybridConnectionCreateParameters parameters, CancellationToken cancellationToken)
1427        {
1428            // Validate
1429            if (webSpaceName == null)
1430            {
1431                throw new ArgumentNullException("webSpaceName");
1432            }
1433            if (siteName == null)
1434            {
1435                throw new ArgumentNullException("siteName");
1436            }
1437            if (parameters == null)
1438            {
1439                throw new ArgumentNullException("parameters");
1440            }
1441            if (parameters.BiztalkUri == null)
1442            {
1443                throw new ArgumentNullException("parameters.BiztalkUri");
1444            }
1445            if (parameters.EntityConnectionString == null)
1446            {
1447                throw new ArgumentNullException("parameters.EntityConnectionString");
1448            }
1449            if (parameters.EntityName == null)
1450            {
1451                throw new ArgumentNullException("parameters.EntityName");
1452            }
1453            if (parameters.Hostname == null)
1454            {
1455                throw new ArgumentNullException("parameters.Hostname");
1456            }
1457            if (parameters.ResourceConnectionString == null)
1458            {
1459                throw new ArgumentNullException("parameters.ResourceConnectionString");
1460            }
1461            if (parameters.ResourceType == null)
1462            {
1463                throw new ArgumentNullException("parameters.ResourceType");
1464            }
1465            
1466            // Tracing
1467            bool shouldTrace = TracingAdapter.IsEnabled;
1468            string invocationId = null;
1469            if (shouldTrace)
1470            {
1471                invocationId = TracingAdapter.NextInvocationId.ToString();
1472                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
1473                tracingParameters.Add("webSpaceName", webSpaceName);
1474                tracingParameters.Add("siteName", siteName);
1475                tracingParameters.Add("parameters", parameters);
1476                TracingAdapter.Enter(invocationId, this, "CreateHybridConnectionAsync", tracingParameters);
1477            }
1478            
1479            // Construct URL
1480            string url = "";
1481            url = url + "/";
1482            if (this.Client.Credentials.SubscriptionId != null)
1483            {
1484                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
1485            }
1486            url = url + "/services/WebSpaces/";
1487            url = url + Uri.EscapeDataString(webSpaceName);
1488            url = url + "/sites/";
1489            url = url + Uri.EscapeDataString(siteName);
1490            url = url + "/hybridconnection";
1491            string baseUrl = this.Client.BaseUri.AbsoluteUri;
1492            // Trim '/' character from the end of baseUrl and beginning of url.
1493            if (baseUrl[baseUrl.Length - 1] == '/')
1494            {
1495                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
1496            }
1497            if (url[0] == '/')
1498            {
1499                url = url.Substring(1);
1500            }
1501            url = baseUrl + "/" + url;
1502            url = url.Replace(" ", "%20");
1503            
1504            // Create HTTP transport objects
1505            HttpRequestMessage httpRequest = null;
1506            try
1507            {
1508                httpRequest = new HttpRequestMessage();
1509                httpRequest.Method = HttpMethod.Post;
1510                httpRequest.RequestUri = new Uri(url);
1511                
1512                // Set Headers
1513                httpRequest.Headers.Add("x-ms-version", "2014-04-01");
1514                
1515                // Set Credentials
1516                cancellationToken.ThrowIfCancellationRequested();
1517                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
1518                
1519                // Serialize Request
1520                string requestContent = null;
1521                XDocument requestDoc = new XDocument();
1522                
1523                XElement relayServiceConnectionEntityElement = new XElement(XName.Get("RelayServiceConnectionEntity", "http://schemas.microsoft.com/windowsazure"));
1524                requestDoc.Add(relayServiceConnectionEntityElement);
1525                
1526                XElement biztalkUriElement = new XElement(XName.Get("BiztalkUri", "http://schemas.microsoft.com/windowsazure"));
1527                biztalkUriElement.Value = parameters.BiztalkUri;
1528                relayServiceConnectionEntityElement.Add(biztalkUriElement);
1529                
1530                XElement entityConnectionStringElement = new XElement(XName.Get("EntityConnectionString", "http://schemas.microsoft.com/windowsazure"));
1531                entityConnectionStringElement.Value = parameters.EntityConnectionString;
1532                relayServiceConnectionEntityElement.Add(entityConnectionStringElement);
1533                
1534                XElement entityNameElement = new XElement(XName.Get("EntityName", "http://schemas.microsoft.com/windowsazure"));
1535                entityNameElement.Value = parameters.EntityName;
1536                relayServiceConnectionEntityElement.Add(entityNameElement);
1537                
1538                XElement hostnameElement = new XElement(XName.Get("Hostname", "http://schemas.microsoft.com/windowsazure"));
1539                hostnameElement.Value = parameters.Hostname;
1540                relayServiceConnectionEntityElement.Add(hostnameElement);
1541                
1542                XElement portElement = new XElement(XName.Get("Port", "http://schemas.microsoft.com/windowsazure"));
1543                portElement.Value = parameters.Port.ToString();
1544                relayServiceConnectionEntityElement.Add(portElement);
1545                
1546                XElement resourceConnectionStringElement = new XElement(XName.Get("ResourceConnectionString", "http://schemas.microsoft.com/windowsazure"));
1547                resourceConnectionStringElement.Value = parameters.ResourceConnectionString;
1548                relayServiceConnectionEntityElement.Add(resourceConnectionStringElement);
1549                
1550                XElement resourceTypeElement = new XElement(XName.Get("ResourceType", "http://schemas.microsoft.com/windowsazure"));
1551                resourceTypeElement.Value = parameters.ResourceType;
1552                relayServiceConnectionEntityElement.Add(resourceTypeElement);
1553                
1554                requestContent = requestDoc.ToString();
1555                httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
1556                httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/xml");
1557                
1558                // Send Request
1559                HttpResponseMessage httpResponse = null;
1560                try
1561                {
1562                    if (shouldTrace)
1563                    {
1564                        TracingAdapter.SendRequest(invocationId, httpRequest);
1565                    }
1566                    cancellationToken.ThrowIfCancellationRequested();
1567                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
1568                    if (shouldTrace)
1569                    {
1570                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
1571                    }
1572                    HttpStatusCode statusCode = httpResponse.StatusCode;
1573                    if (statusCode != HttpStatusCode.OK)
1574                    {
1575                        cancellationToken.ThrowIfCancellationRequested();
1576                        CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
1577                        if (shouldTrace)
1578                        {
1579                            TracingAdapter.Error(invocationId, ex);
1580                        }
1581                        throw ex;
1582                    }
1583                    
1584                    // Create Result
1585                    HybridConnectionCreateResponse result = null;
1586                    // Deserialize Response
1587                    if (statusCode == HttpStatusCode.OK)
1588                    {
1589                        cancellationToken.ThrowIfCancellationRequested();
1590                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
1591                        result = new HybridConnectionCreateResponse();
1592                        XDocument responseDoc = XDocument.Parse(responseContent);
1593                        
1594                        XElement relayServiceConnectionEntityElement2 = responseDoc.Element(XName.Get("RelayServiceConnectionEntity", "http://schemas.microsoft.com/windowsazure"));
1595                        if (relayServiceConnectionEntityElement2 != null)
1596                        {
1597                            HybridConnection hybridConnectionInstance = new HybridConnection();
1598                            result.HybridConnection = hybridConnectionInstance;
1599                            
1600                            XElement entityNameElement2 = relayServiceConnectionEntityElement2.Element(XName.Get("EntityName", "http://schemas.microsoft.com/windowsazure"));
1601                            if (entityNameElement2 != null)
1602                            {
1603                                string entityNameInstance = entityNameElement2.Value;
1604                                hybridConnectionInstance.EntityName = entityNameInstance;
1605                            }
1606                            
1607                            XElement entityConnectionStringElement2 = relayServiceConnectionEntityElement2.Element(XName.Get("EntityConnectionString", "http://schemas.microsoft.com/windowsazure"));
1608                            if (entityConnectionStringElement2 != null)
1609                            {
1610                                string entityConnectionStringInstance = entityConnectionStringElement2.Value;
1611                                hybridConnectionInstance.EntityConnectionString = entityConnectionStringInstance;
1612                            }
1613                            
1614                            XElement resourceTypeElement2 = relayServiceConnectionEntityElement2.Element(XName.Get("ResourceType", "http://schemas.microsoft.com/windowsazure"));
1615                            if (resourceTypeElement2 != null)
1616                            {
1617                                string resourceTypeInstance = resourceTypeElement2.Value;
1618                                hybridConnectionInstance.ResourceType = resourceTypeInstance;
1619                            }
1620                            
1621                            XElement resourceConnectionStringElement2 = relayServiceConnectionEntityElement2.Element(XName.Get("ResourceConnectionString", "http://schemas.microsoft.com/windowsazure"));
1622                            if (resourceConnectionStringElement2 != null)
1623                            {
1624                                string resourceConnectionStringInstance = resourceConnectionStringElement2.Value;
1625                                hybridConnectionInstance.ResourceConnectionString = resourceConnectionStringInstance;
1626                            }
1627                            
1628                            XElement hostnameElement2 = relayServiceConnectionEntityElement2.Element(XName.Get("Hostname", "http://schemas.microsoft.com/windowsazure"));
1629                            if (hostnameElement2 != null)
1630                            {
1631                                string hostnameInstance = hostnameElement2.Value;
1632                                hybridConnectionInstance.Hostname = hostnameInstance;
1633                            }
1634                            
1635                            XElement portElement2 = relayServiceConnectionEntityElement2.Element(XName.Get("Port", "http://schemas.microsoft.com/windowsazure"));
1636                            if (portElement2 != null)
1637                            {
1638                                int portInstance = int.Parse(portElement2.Value, CultureInfo.InvariantCulture);
1639                                hybridConnectionInstance.Port = portInstance;
1640                            }
1641                            
1642                            XElement biztalkUriElement2 = relayServiceConnectionEntityElement2.Element(XName.Get("BiztalkUri", "http://schemas.microsoft.com/windowsazure"));
1643                            if (biztalkUriElement2 != null)
1644                            {
1645                                string biztalkUriInstance = biztalkUriElement2.Value;
1646                                hybridConnectionInstance.BiztalkUri = biztalkUriInstance;
1647                            }
1648                        }
1649                        
1650                    }
1651                    result.StatusCode = statusCode;
1652                    if (httpResponse.Headers.Contains("x-ms-request-id"))
1653                    {
1654                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
1655                    }
1656                    
1657                    if (shouldTrace)
1658                    {
1659                        TracingAdapter.Exit(invocationId, result);
1660                    }
1661                    return result;
1662                }
1663                finally
1664                {
1665                    if (httpResponse != null)
1666                    {
1667                        httpResponse.Dispose();
1668                    }
1669                }
1670            }
1671            finally
1672            {
1673                if (httpRequest != null)
1674                {
1675                    httpRequest.Dispose();
1676                }
1677            }
1678        }
1679        
1680        /// <summary>
1681        /// A web site repository is essentially a Git repository that you can
1682        /// use to manage your web site content. By using Git source control
1683        /// tools, you can push or pull version-controlled changes to your
1684        /// site. This API executes a repository create operation.  (see
1685        /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166967.aspx
1686        /// for more information)
1687        /// </summary>
1688        /// <param name='webSpaceName'>
1689        /// Required. The name of the web space.
1690        /// </param>
1691        /// <param name='webSiteName'>
1692        /// Required. The name of the web site.
1693        /// </param>
1694        /// <param name='cancellationToken'>
1695        /// Cancellation token.
1696        /// </param>
1697        /// <returns>
1698        /// A standard service response including an HTTP status code and
1699        /// request ID.
1700        /// </returns>
1701        public async Task<AzureOperationResponse> CreateRepositoryAsync(string webSpaceName, string webSiteName, CancellationToken cancellationToken)
1702        {
1703            // Validate
1704            if (webSpaceName == null)
1705            {
1706                throw new ArgumentNullException("webSpaceName");
1707            }
1708            if (webSiteName == null)
1709            {
1710                throw new ArgumentNullException("webSiteName");
1711            }
1712            
1713            // Tracing
1714            bool shouldTrace = TracingAdapter.IsEnabled;
1715            string invocationId = null;
1716            if (shouldTrace)
1717            {
1718                invocationId = TracingAdapter.NextInvocationId.ToString();
1719                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
1720                tracingParameters.Add("webSpaceName", webSpaceName);
1721                tracingParameters.Add("webSiteName", webSiteName);
1722                TracingAdapter.Enter(invocationId, this, "CreateRepositoryAsync", tracingParameters);
1723            }
1724            
1725            // Construct URL
1726            string url = "";
1727            url = url + "/";
1728            if (this.Client.Credentials.SubscriptionId != null)
1729            {
1730                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
1731            }
1732            url = url + "/services/WebSpaces/";
1733            url = url + Uri.EscapeDataString(webSpaceName);
1734            url = url + "/sites/";
1735            url = url + Uri.EscapeDataString(webSiteName);
1736            url = url + "/repository";
1737            string baseUrl = this.Client.BaseUri.AbsoluteUri;
1738            // Trim '/' character from the end of baseUrl and beginning of url.
1739            if (baseUrl[baseUrl.Length - 1] == '/')
1740            {
1741                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
1742            }
1743            if (url[0] == '/')
1744            {
1745                url = url.Substring(1);
1746            }
1747            url = baseUrl + "/" + url;
1748            url = url.Replace(" ", "%20");
1749            
1750            // Create HTTP transport objects
1751            HttpRequestMessage httpRequest = null;
1752            try
1753            {
1754                httpRequest = new HttpRequestMessage();
1755                httpRequest.Method = HttpMethod.Post;
1756                httpRequest.RequestUri = new Uri(url);
1757                
1758                // Set Headers
1759                httpRequest.Headers.Add("x-ms-version", "2014-04-01");
1760                
1761                // Set Credentials
1762                cancellationToken.ThrowIfCancellationRequested();
1763                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
1764                
1765                // Send Request
1766                HttpResponseMessage httpResponse = null;
1767                try
1768                {
1769                    if (shouldTrace)
1770                    {
1771                        TracingAdapter.SendRequest(invocationId, httpRequest);
1772                    }
1773                    cancellationToken.ThrowIfCancellationRequested();
1774                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
1775                    if (shouldTrace)
1776                    {
1777                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
1778                    }
1779                    HttpStatusCode statusCode = httpResponse.StatusCode;
1780                    if (statusCode != HttpStatusCode.OK)
1781                    {
1782                        cancellationToken.ThrowIfCancellationRequested();
1783                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
1784                        if (shouldTrace)
1785                        {
1786                            TracingAdapter.Error(invocationId, ex);
1787                        }
1788                        throw ex;
1789                    }
1790                    
1791                    // Create Result
1792                    AzureOperationResponse result = null;
1793                    // Deserialize Response
1794                    result = new AzureOperationResponse();
1795                    result.StatusCode = statusCode;
1796                    if (httpResponse.Headers.Contains("x-ms-request-id"))
1797                    {
1798                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
1799                    }
1800                    
1801                    if (shouldTrace)
1802                    {
1803                        TracingAdapter.Exit(invocationId, result);
1804                    }
1805                    return result;
1806                }
1807                finally
1808                {
1809                    if (httpResponse != null)
1810                    {
1811                        httpResponse.Dispose();
1812                    }
1813                }
1814            }
1815            finally
1816            {
1817                if (httpRequest != null)
1818                {
1819                    httpRequest.Dispose();
1820                }
1821            }
1822        }
1823        
1824        /// <summary>
1825        /// You can delete a web site by issuing an HTTP DELETE request. If the
1826        /// web site being deleted is the only site remaining in a server
1827        /// farm, you can optionally delete the server farm as well by using
1828        /// the deleteEmptyServerFarm parameter.  (see
1829        /// http://msdn.microsoft.com/en-us/library/windowsazure/dn236430.aspx
1830        /// for more information)
1831        /// </summary>
1832        /// <param name='webSpaceName'>
1833        /// Required. The name of the web space.
1834        /// </param>
1835        /// <param name='webSiteName'>
1836        /// Required. The name of the web site.
1837        /// </param>
1838        /// <param name='parameters'>
1839        /// Required. Parameters supplied to the Delete Web Site operation.
1840        /// </param>
1841        /// <param name='cancellationToken'>
1842        /// Cancellation token.
1843        /// </param>
1844        /// <returns>
1845        /// A standard service response including an HTTP status code and
1846        /// request ID.
1847        /// </returns>
1848        public async Task<AzureOperationResponse> DeleteAsync(string webSpaceName, string webSiteName, WebSiteDeleteParameters parameters, CancellationToken cancellationToken)
1849        {
1850            // Validate
1851            if (webSpaceName == null)
1852            {
1853                throw new ArgumentNullException("webSpaceName");
1854            }
1855            if (webSiteName == null)
1856            {
1857                throw new ArgumentNullException("webSiteName");
1858            }
1859            if (parameters == null)
1860            {
1861                throw new ArgumentNullException("parameters");
1862            }
1863            
1864            // Tracing
1865            bool shouldTrace = TracingAdapter.IsEnabled;
1866            string invocationId = null;
1867            if (shouldTrace)
1868            {
1869                invocationId = TracingAdapter.NextInvocationId.ToString();
1870                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
1871                tracingParameters.Add("webSpaceName", webSpaceName);
1872                tracingParameters.Add("webSiteName", webSiteName);
1873                tracingParameters.Add("parameters", parameters);
1874                TracingAdapter.Enter(invocationId, this, "DeleteAsync", tracingParameters);
1875            }
1876            
1877            // Construct URL
1878            string url = "";
1879            url = url + "/";
1880            if (this.Client.Credentials.SubscriptionId != null)
1881            {
1882                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
1883            }
1884            url = url + "/services/WebSpaces/";
1885            url = url + Uri.EscapeDataString(webSpaceName);
1886            url = url + "/sites/";
1887            url = url + Uri.EscapeDataString(webSiteName);
1888            List<string> queryParameters = new List<string>();
1889            queryParameters.Add("deleteEmptyServerFarm=" + Uri.EscapeDataString(parameters.DeleteEmptyServerFarm.ToString().ToLower()));
1890            queryParameters.Add("deleteMetrics=" + Uri.EscapeDataString(parameters.DeleteMetrics.ToString().ToLower()));
1891            queryParameters.Add("deleteAllSlots=" + Uri.EscapeDataString(parameters.DeleteAllSlots.ToString().ToLower()));
1892            if (queryParameters.Count > 0)
1893            {
1894                url = url + "?" + string.Join("&", queryParameters);
1895            }
1896            string baseUrl = this.Client.BaseUri.AbsoluteUri;
1897            // Trim '/' character from the end of baseUrl and beginning of url.
1898            if (baseUrl[baseUrl.Length - 1] == '/')
1899            {
1900                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
1901            }
1902            if (url[0] == '/')
1903            {
1904                url = url.Substring(1);
1905            }
1906            url = baseUrl + "/" + url;
1907            url = url.Replace(" ", "%20");
1908            
1909            // Create HTTP transport objects
1910            HttpRequestMessage httpRequest = null;
1911            try
1912            {
1913                httpRequest = new HttpRequestMessage();
1914                httpRequest.Method = HttpMethod.Delete;
1915                httpRequest.RequestUri = new Uri(url);
1916                
1917                // Set Headers
1918                httpRequest.Headers.Add("x-ms-version", "2014-04-01");
1919                
1920                // Set Credentials
1921                cancellationToken.ThrowIfCancellationRequested();
1922                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
1923                
1924                // Send Request
1925                HttpResponseMessage httpResponse = null;
1926                try
1927                {
1928                    if (shouldTrace)
1929                    {
1930                        TracingAdapter.SendRequest(invocationId, httpRequest);
1931                    }
1932                    cancellationToken.ThrowIfCancellationRequested();
1933                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
1934                    if (shouldTrace)
1935                    {
1936                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
1937                    }
1938                    HttpStatusCode statusCode = httpResponse.StatusCode;
1939                    if (statusCode != HttpStatusCode.OK)
1940                    {
1941                        cancellationToken.ThrowIfCancellationRequested();
1942                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
1943                        if (shouldTrace)
1944                        {
1945                            TracingAdapter.Error(invocationId, ex);
1946                        }
1947                        throw ex;
1948                    }
1949                    
1950                    // Create Result
1951                    AzureOperationResponse result = null;
1952                    // Deserialize Response
1953                    result = new AzureOperationResponse();
1954                    result.StatusCode = statusCode;
1955                    if (httpResponse.Headers.Contains("x-ms-request-id"))
1956                    {
1957                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
1958                    }
1959                    
1960                    if (shouldTrace)
1961                    {
1962                        TracingAdapter.Exit(invocationId, result);
1963                    }
1964                    return result;
1965                }
1966                finally
1967                {
1968                    if (httpResponse != null)
1969                    {
1970                        httpResponse.Dispose();
1971                    }
1972                }
1973            }
1974            finally
1975            {
1976                if (httpRequest != null)
1977                {
1978                    httpRequest.Dispose();
1979                }
1980            }
1981        }
1982        
1983        /// <summary>
1984        /// Deletes a hybrid connection on a specific site.
1985        /// </summary>
1986        /// <param name='webSpaceName'>
1987        /// Required. The name of the web space.
1988        /// </param>
1989        /// <param name='webSiteName'>
1990        /// Required. The name of the web site.
1991        /// </param>
1992        /// <param name='hybridConnectionName'>
1993        /// Required. The name of the hybrid connection entity
1994        /// </param>
1995        /// <param name='cancellationToken'>
1996        /// Cancellation token.
1997        /// </param>
1998        /// <returns>
1999        /// A standard service response including an HTTP status code and
2000        /// request ID.
2001        /// </returns>
2002        public async Task<AzureOperationResponse> DeleteHybridConnectionAsync(string webSpaceName, string webSiteName, string hybridConnectionName, CancellationToken cancellationToken)
2003        {
2004            // Validate
2005            if (webSpaceName == null)
2006            {
2007                throw new ArgumentNullException("webSpaceName");
2008            }
2009            if (webSiteName == null)
2010            {
2011                throw new ArgumentNullException("webSiteName");
2012            }
2013            if (hybridConnectionName == null)
2014            {
2015                throw new ArgumentNullException("hybridConnectionName");
2016            }
2017            
2018            // Tracing
2019            bool shouldTrace = TracingAdapter.IsEnabled;
2020            string invocationId = null;
2021            if (shouldTrace)
2022            {
2023                invocationId = TracingAdapter.NextInvocationId.ToString();
2024                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
2025                tracingParameters.Add("webSpaceName", webSpaceName);
2026                tracingParameters.Add("webSiteName", webSiteName);
2027                tracingParameters.Add("hybridConnectionName", hybridConnectionName);
2028                TracingAdapter.Enter(invocationId, this, "DeleteHybridConnectionAsync", tracingParameters);
2029            }
2030            
2031            // Construct URL
2032            string url = "";
2033            url = url + "/";
2034            if (this.Client.Credentials.SubscriptionId != null)
2035            {
2036                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
2037            }
2038            url = url + "/services/WebSpaces/";
2039            url = url + Uri.EscapeDataString(webSpaceName);
2040            url = url + "/sites/";
2041            url = url + Uri.EscapeDataString(webSiteName);
2042            url = url + "/hybridconnection/";
2043            url = url + Uri.EscapeDataString(hybridConnectionName);
2044            string baseUrl = this.Client.BaseUri.AbsoluteUri;
2045            // Trim '/' character from the end of baseUrl and beginning of url.
2046            if (baseUrl[baseUrl.Length - 1] == '/')
2047            {
2048                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
2049            }
2050            if (url[0] == '/')
2051            {
2052                url = url.Substring(1);
2053            }
2054            url = baseUrl + "/" + url;
2055            url = url.Replace(" ", "%20");
2056            
2057            // Create HTTP transport objects
2058            HttpRequestMessage httpRequest = null;
2059            try
2060            {
2061                httpRequest = new HttpRequestMessage();
2062                httpRequest.Method = HttpMethod.Delete;
2063                httpRequest.RequestUri = new Uri(url);
2064                
2065                // Set Headers
2066                httpRequest.Headers.Add("x-ms-version", "2014-04-01");
2067                
2068                // Set Credentials
2069                cancellationToken.ThrowIfCancellationRequested();
2070                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
2071                
2072                // Send Request
2073                HttpResponseMessage httpResponse = null;
2074                try
2075                {
2076                    if (shouldTrace)
2077                    {
2078                        TracingAdapter.SendRequest(invocationId, httpRequest);
2079                    }
2080                    cancellationToken.ThrowIfCancellationRequested();
2081                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
2082                    if (shouldTrace)
2083                    {
2084                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
2085                    }
2086                    HttpStatusCode statusCode = httpResponse.StatusCode;
2087                    if (statusCode != HttpStatusCode.OK)
2088                    {
2089                        cancellationToken.ThrowIfCancellationRequested();
2090                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
2091                        if (shouldTrace)
2092                        {
2093                            TracingAdapter.Error(invocationId, ex);
2094                        }
2095                        throw ex;
2096                    }
2097                    
2098                    // Create Result
2099                    AzureOperationResponse result = null;
2100                    // Deserialize Response
2101                    result = new AzureOperationResponse();
2102                    result.StatusCode = statusCode;
2103                    if (httpResponse.Headers.Contains("x-ms-request-id"))
2104                    {
2105                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
2106                    }
2107                    
2108                    if (shouldTrace)
2109                    {
2110                        TracingAdapter.Exit(invocationId, result);
2111                    }
2112                    return result;
2113                }
2114                finally
2115                {
2116                    if (httpResponse != null)
2117                    {
2118                        httpResponse.Dispose();
2119                    }
2120                }
2121            }
2122            finally
2123            {
2124                if (httpRequest != null)
2125                {
2126                    httpRequest.Dispose();
2127                }
2128            }
2129        }
2130        
2131        /// <summary>
2132        /// A web site repository is essentially a Git repository that you can
2133        /// use to manage your web site content. By using Git source control
2134        /// tools, you can push or pull version-controlled changes to your
2135        /// site. This API executes a repository delete operation.  (see
2136        /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166967.aspx
2137        /// for more information)
2138        /// </summary>
2139        /// <param name='webSpaceName'>
2140        /// Required. The name of the web space.
2141        /// </param>
2142        /// <param name='webSiteName'>
2143        /// Required. The name of the web site.
2144        /// </param>
2145        /// <param name='cancellationToken'>
2146        /// Cancellation token.
2147        /// </param>
2148        /// <returns>
2149        /// The Delete Repository Web Site operation response.
2150        /// </returns>
2151        public async Task<WebSiteDeleteRepositoryResponse> DeleteRepositoryAsync(string webSpaceName, string webSiteName, CancellationToken cancellationToken)
2152        {
2153            // Validate
2154            if (webSpaceName == null)
2155            {
2156                throw new ArgumentNullException("webSpaceName");
2157            }
2158            if (webSiteName == null)
2159            {
2160                throw new ArgumentNullException("webSiteName");
2161            }
2162            
2163            // Tracing
2164            bool shouldTrace = TracingAdapter.IsEnabled;
2165            string invocationId = null;
2166            if (shouldTrace)
2167            {
2168                invocationId = TracingAdapter.NextInvocationId.ToString();
2169                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
2170                tracingParameters.Add("webSpaceName", webSpaceName);
2171                tracingParameters.Add("webSiteName", webSiteName);
2172                TracingAdapter.Enter(invocationId, this, "DeleteRepositoryAsync", tracingParameters);
2173            }
2174            
2175            // Construct URL
2176            string url = "";
2177            url = url + "/";
2178            if (this.Client.Credentials.SubscriptionId != null)
2179            {
2180                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
2181            }
2182            url = url + "/services/WebSpaces/";
2183            url = url + Uri.EscapeDataString(webSpaceName);
2184            url = url + "/sites/";
2185            url = url + Uri.EscapeDataString(webSiteName);
2186            url = url + "/repository";
2187            string baseUrl = this.Client.BaseUri.AbsoluteUri;
2188            // Trim '/' character from the end of baseUrl and beginning of url.
2189            if (baseUrl[baseUrl.Length - 1] == '/')
2190            {
2191                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
2192            }
2193            if (url[0] == '/')
2194            {
2195                url = url.Substring(1);
2196            }
2197            url = baseUrl + "/" + url;
2198            url = url.Replace(" ", "%20");
2199            
2200            // Create HTTP transport objects
2201            HttpRequestMessage httpRequest = null;
2202            try
2203            {
2204                httpRequest = new HttpRequestMessage();
2205                httpRequest.Method = HttpMethod.Delete;
2206                httpRequest.RequestUri = new Uri(url);
2207                
2208                // Set Headers
2209                httpRequest.Headers.Add("x-ms-version", "2014-04-01");
2210                
2211                // Set Credentials
2212                cancellationToken.ThrowIfCancellationRequested();
2213                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
2214                
2215                // Send Request
2216                HttpResponseMessage httpResponse = null;
2217                try
2218                {
2219                    if (shouldTrace)
2220                    {
2221                        TracingAdapter.SendRequest(invocationId, httpRequest);
2222                    }
2223                    cancellationToken.ThrowIfCancellationRequested();
2224                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
2225                    if (shouldTrace)
2226                    {
2227                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
2228                    }
2229                    HttpStatusCode statusCode = httpResponse.StatusCode;
2230                    if (statusCode != HttpStatusCode.OK)
2231                    {
2232                        cancellationToken.ThrowIfCancellationRequested();
2233                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
2234                        if (shouldTrace)
2235                        {
2236                            TracingAdapter.Error(invocationId, ex);
2237                        }
2238                        throw ex;
2239                    }
2240                    
2241                    // Create Result
2242                    WebSiteDeleteRepositoryResponse result = null;
2243                    // Deserialize Response
2244                    if (statusCode == HttpStatusCode.OK)
2245                    {
2246                        cancellationToken.ThrowIfCancellationRequested();
2247                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
2248                        result = new WebSiteDeleteRepositoryResponse();
2249                        XDocument responseDoc = XDocument.Parse(responseContent);
2250                        
2251                        XElement anyURIElement = responseDoc.Element(XName.Get("anyURI", "http://schemas.microsoft.com/2003/10/Serialization/"));
2252                        if (anyURIElement != null)
2253                        {
2254                            result.Uri = TypeConversion.TryParseUri(anyURIElement.Value);
2255                        }
2256                        
2257                    }
2258                    result.StatusCode = statusCode;
2259                    if (httpResponse.Headers.Contains("x-ms-request-id"))
2260                    {
2261                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
2262                    }
2263                    
2264                    if (shouldTrace)
2265                    {
2266                        TracingAdapter.Exit(invocationId, result);
2267                    }
2268                    return result;
2269                }
2270                finally
2271                {
2272                    if (httpResponse != null)
2273                    {
2274                        httpResponse.Dispose();
2275                    }
2276                }
2277            }
2278            finally
2279            {
2280                if (httpRequest != null)
2281                {
2282                    httpRequest.Dispose();
2283                }
2284            }
2285        }
2286        
2287        /// <summary>
2288        /// Scans a backup in a storage account and returns database
2289        /// information etc. Should be called before calling Restore to
2290        /// discover what parameters are needed for the restore operation.
2291        /// </summary>
2292        /// <param name='webSpaceName'>
2293        /// Required. The name of the web space.
2294        /// </param>
2295        /// <param name='webSiteName'>
2296        /// Required. The name of the web site.
2297        /// </param>
2298        /// <param name='restoreRequest'>
2299        /// Required. A restore request.
2300        /// </param>
2301        /// <param name='cancellationToken'>
2302        /// Cancellation token.
2303        /// </param>
2304        /// <returns>
2305        /// The information gathered about a backup storaged in a storage
2306        /// account.
2307        /// </returns>
2308        public async Task<WebSiteRestoreDiscoverResponse> DiscoverAsync(string webSpaceName, string webSiteName, RestoreRequest restoreRequest, CancellationToken cancellationToken)
2309        {
2310            // Validate
2311            if (webSpaceName == null)
2312            {
2313                throw new ArgumentNullException("webSpaceName");
2314            }
2315            if (webSiteName == null)
2316            {
2317                throw new ArgumentNullException("webSiteName");
2318            }
2319            if (restoreRequest == null)
2320            {
2321                throw new ArgumentNullException("restoreRequest");
2322            }
2323            
2324            // Tracing
2325            bool shouldTrace = TracingAdapter.IsEnabled;
2326            string invocationId = null;
2327            if (shouldTrace)
2328            {
2329                invocationId = TracingAdapter.NextInvocationId.ToString();
2330                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
2331                tracingParameters.Add("webSpaceName", webSpaceName);
2332                tracingParameters.Add("webSiteName", webSiteName);
2333                tracingParameters.Add("restoreRequest", restoreRequest);
2334                TracingAdapter.Enter(invocationId, this, "DiscoverAsync", tracingParameters);
2335            }
2336            
2337            // Construct URL
2338            string url = "";
2339            url = url + "/";
2340            if (this.Client.Credentials.SubscriptionId != null)
2341            {
2342                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
2343            }
2344            url = url + "/services/WebSpaces/";
2345            url = url + Uri.EscapeDataString(webSpaceName);
2346            url = url + "/sites/";
2347            url = url + Uri.EscapeDataString(webSiteName);
2348            url = url + "/restore/discover";
2349            string baseUrl = this.Client.BaseUri.AbsoluteUri;
2350            // Trim '/' character from the end of baseUrl and beginning of url.
2351            if (baseUrl[baseUrl.Length - 1] == '/')
2352            {
2353                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
2354            }
2355            if (url[0] == '/')
2356            {
2357                url = url.Substring(1);
2358            }
2359            url = baseUrl + "/" + url;
2360            url = url.Replace(" ", "%20");
2361            
2362            // Create HTTP transport objects
2363            HttpRequestMessage httpRequest = null;
2364            try
2365            {
2366                httpRequest = new HttpRequestMessage();
2367                httpRequest.Method = HttpMethod.Put;
2368                httpRequest.RequestUri = new Uri(url);
2369                
2370                // Set Headers
2371                httpRequest.Headers.Add("x-ms-version", "2014-04-01");
2372                
2373                // Set Credentials
2374                cancellationToken.ThrowIfCancellationRequested();
2375                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
2376                
2377                // Serialize Request
2378                string requestContent = null;
2379                XDocument requestDoc = new XDocument();
2380                
2381                XElement restoreRequestElement = new XElement(XName.Get("RestoreRequest", "http://schemas.microsoft.com/windowsazure"));
2382                requestDoc.Add(restoreRequestElement);
2383                
2384                XElement adjustConnectionStringsElement = new XElement(XName.Get("AdjustConnectionStrings", "http://schemas.microsoft.com/windowsazure"));
2385                adjustConnectionStringsElement.Value = restoreRequest.AdjustConnectionStrings.ToString().ToLower();
2386                restoreRequestElement.Add(adjustConnectionStringsElement);
2387                
2388                if (restoreRequest.BlobName != null)
2389                {
2390                    XElement blobNameElement = new XElement(XName.Get("BlobName", "http://schemas.microsoft.com/windowsazure"));
2391                    blobNameElement.Value = restoreRequest.BlobName;
2392                    restoreRequestElement.Add(blobNameElement);
2393                }
2394                
2395                if (restoreRequest.Databases != null)
2396                {
2397                    if (restoreRequest.Databases is ILazyCollection == false || ((ILazyCollection)restoreRequest.Databases).IsInitialized)
2398                    {
2399                        XElement databasesSequenceElement = new XElement(XName.Get("Databases", "http://schemas.microsoft.com/windowsazure"));
2400                        foreach (DatabaseBackupSetting databasesItem in restoreRequest.Databases)
2401                        {
2402                            XElement databaseBackupSettingElement = new XElement(XName.Get("DatabaseBackupSetting", "http://schemas.microsoft.com/windowsazure"));
2403                            databasesSequenceElement.Add(databaseBackupSettingElement);
2404                            
2405                            if (databasesItem.ConnectionString != null)
2406                            {
2407                                XElement connectionStringElement = new XElement(XName.Get("ConnectionString", "http://schemas.microsoft.com/windowsazure"));
2408                                connectionStringElement.Value = databasesItem.ConnectionString;
2409                                databaseBackupSettingElement.Add(connectionStringElement);
2410                            }
2411                            
2412                            if (databasesItem.ConnectionStringName != null)
2413                            {
2414                                XElement connectionStringNameElement = new XElement(XName.Get("ConnectionStringName", "http://schemas.microsoft.com/windowsazure"));
2415                                connectionStringNameElement.Value = databasesItem.ConnectionStringName;
2416                                databaseBackupSettingElement.Add(connectionStringNameElement);
2417                            }
2418                            
2419                            if (databasesItem.DatabaseType != null)
2420                            {
2421                                XElement databaseTypeElement = new XElement(XName.Get("DatabaseType", "http://schemas.microsoft.com/windowsazure"));
2422                                databaseTypeElement.Value = databasesItem.DatabaseType;
2423                                databaseBackupSettingElement.Add(databaseTypeElement);
2424                            }
2425                            
2426                            if (databasesItem.Name != null)
2427                            {
2428                                XElement nameElement = new XElement(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
2429                                nameElement.Value = databasesItem.Name;
2430                                databaseBackupSettingElement.Add(nameElement);
2431                            }
2432                        }
2433                        restoreRequestElement.Add(databasesSequenceElement);
2434                    }
2435                }
2436                
2437                XElement ignoreConflictingHostNamesElement = new XElement(XName.Get("IgnoreConflictingHostNames", "http://schemas.microsoft.com/windowsazure"));
2438                ignoreConflictingHostNamesElement.Value = restoreRequest.IgnoreConflictingHostNames.ToString().ToLower();
2439                restoreRequestElement.Add(ignoreConflictingHostNamesElement);
2440                
2441                XElement overwriteElement = new XElement(XName.Get("Overwrite", "http://schemas.microsoft.com/windowsazure"));
2442                overwriteElement.Value = restoreRequest.Overwrite.ToString().ToLower();
2443                restoreRequestElement.Add(overwriteElement);
2444                
2445                if (restoreRequest.StorageAccountUrl != null)
2446                {
2447                    XElement storageAccountUrlElement = new XElement(XName.Get("StorageAccountUrl", "http://schemas.microsoft.com/windowsazure"));
2448                    storageAccountUrlElement.Value = restoreRequest.StorageAccountUrl;
2449                    restoreRequestElement.Add(storageAccountUrlElement);
2450                }
2451                
2452                requestContent = requestDoc.ToString();
2453                httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
2454                httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/xml");
2455                
2456                // Send Request
2457                HttpResponseMessage httpResponse = null;
2458                try
2459                {
2460                    if (shouldTrace)
2461                    {
2462                        TracingAdapter.SendRequest(invocationId, httpRequest);
2463                    }
2464                    cancellationToken.ThrowIfCancellationRequested();
2465                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
2466                    if (shouldTrace)
2467                    {
2468                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
2469                    }
2470                    HttpStatusCode statusCode = httpResponse.StatusCode;
2471                    if (statusCode != HttpStatusCode.OK)
2472                    {
2473                        cancellationToken.ThrowIfCancellationRequested();
2474                        CloudException ex = CloudException.Create(httpRequest, requestContent, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
2475                        if (shouldTrace)
2476                        {
2477                            TracingAdapter.Error(invocationId, ex);
2478                        }
2479                        throw ex;
2480                    }
2481                    
2482                    // Create Result
2483                    WebSiteRestoreDiscoverResponse result = null;
2484                    // Deserialize Response
2485                    if (statusCode == HttpStatusCode.OK)
2486                    {
2487                        cancellationToken.ThrowIfCancellationRequested();
2488                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
2489                        result = new WebSiteRestoreDiscoverResponse();
2490                        XDocument responseDoc = XDocument.Parse(responseContent);
2491                        
2492                        XElement restoreRequestElement2 = responseDoc.Element(XName.Get("RestoreRequest", "http://schemas.microsoft.com/windowsazure"));
2493                        if (restoreRequestElement2 != null)
2494                        {
2495                            XElement storageAccountUrlElement2 = restoreRequestElement2.Element(XName.Get("StorageAccountUrl", "http://schemas.microsoft.com/windowsazure"));
2496                            if (storageAccountUrlElement2 != null)
2497                            {
2498                                string storageAccountUrlInstance = storageAccountUrlElement2.Value;
2499                                result.StorageAccountUrl = storageAccountUrlInstance;
2500                            }
2501                            
2502                            XElement blobNameElement2 = restoreRequestElement2.Element(XName.Get("BlobName", "http://schemas.microsoft.com/windowsazure"));
2503                            if (blobNameElement2 != null)
2504                            {
2505                                string blobNameInstance = blobNameElement2.Value;
2506                                result.BlobName = blobNameInstance;
2507                            }
2508                            
2509                            XElement overwriteElement2 = restoreRequestElement2.Element(XName.Get("Overwrite", "http://schemas.microsoft.com/windowsazure"));
2510                            if (overwriteElement2 != null)
2511                            {
2512                                bool overwriteInstance = bool.Parse(overwriteElement2.Value);
2513                                result.Overwrite = overwriteInstance;
2514                            }
2515                            
2516                            XElement databasesSequenceElement2 = restoreRequestElement2.Element(XName.Get("Databases", "http://schemas.microsoft.com/windowsazure"));
2517                            if (databasesSequenceElement2 != null)
2518                            {
2519                                foreach (XElement databasesElement in databasesSequenceElement2.Elements(XName.Get("DatabaseBackupSetting", "http://schemas.microsoft.com/windowsazure")))
2520                                {
2521                                    DatabaseBackupSetting databaseBackupSettingInstance = new DatabaseBackupSetting();
2522                                    result.Databases.Add(databaseBackupSettingInstance);
2523                                    
2524                                    XElement connectionStringElement2 = databasesElement.Element(XName.Get("ConnectionString", "http://schemas.microsoft.com/windowsazure"));
2525                                    if (connectionStringElement2 != null)
2526                                    {
2527                                        string connectionStringInstance = connectionStringElement2.Value;
2528                                        databaseBackupSettingInstance.ConnectionString = connectionStringInstance;
2529                                    }
2530                                    
2531                                    XElement connectionStringNameElement2 = databasesElement.Element(XName.Get("ConnectionStringName", "http://schemas.microsoft.com/windowsazure"));
2532                                    if (connectionStringNameElement2 != null)
2533                                    {
2534                                        string connectionStringNameInstance = connectionStringNameElement2.Value;
2535                                        databaseBackupSettingInstance.ConnectionStringName = connectionStringNameInstance;
2536                                    }
2537                                    
2538                                    XElement databaseTypeElement2 = databasesElement.Element(XName.Get("DatabaseType", "http://schemas.microsoft.com/windowsazure"));
2539                                    if (databaseTypeElement2 != null)
2540                                    {
2541                                        string databaseTypeInstance = databaseTypeElement2.Value;
2542                                        databaseBackupSettingInstance.DatabaseType = databaseTypeInstance;
2543                                    }
2544                                    
2545                                    XElement nameElement2 = databasesElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
2546                                    if (nameElement2 != null)
2547                                    {
2548                                        string nameInstance = nameElement2.Value;
2549                                        databaseBackupSettingInstance.Name = nameInstance;
2550                                    }
2551                                }
2552                            }
2553                            
2554                            XElement ignoreConflictingHostNamesElement2 = restoreRequestElement2.Element(XName.Get("IgnoreConflictingHostNames", "http://schemas.microsoft.com/windowsazure"));
2555                            if (ignoreConflictingHostNamesElement2 != null)
2556                            {
2557                                bool ignoreConflictingHostNamesInstance = bool.Parse(ignoreConflictingHostNamesElement2.Value);
2558                                result.IgnoreConflictingHostNames = ignoreConflictingHostNamesInstance;
2559                            }
2560                            
2561                            XElement adjustConnectionStringsElement2 = restoreRequestElement2.Element(XName.Get("AdjustConnectionStrings", "http://schemas.microsoft.com/windowsazure"));
2562                            if (adjustConnectionStringsElement2 != null)
2563                            {
2564                                bool adjustConnectionStringsInstance = bool.Parse(adjustConnectionStringsElement2.Value);
2565                                result.AdjustConnectionStrings = adjustConnectionStringsInstance;
2566                            }
2567                        }
2568                        
2569                    }
2570                    result.StatusCode = statusCode;
2571                    if (httpResponse.Headers.Contains("x-ms-request-id"))
2572                    {
2573                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
2574                    }
2575                    
2576                    if (shouldTrace)
2577                    {
2578                        TracingAdapter.Exit(invocationId, result);
2579                    }
2580                    return result;
2581                }
2582                finally
2583                {
2584                    if (httpResponse != null)
2585                    {
2586                        httpResponse.Dispose();
2587                    }
2588                }
2589            }
2590            finally
2591            {
2592                if (httpRequest != null)
2593                {
2594                    httpRequest.Dispose();
2595                }
2596            }
2597        }
2598        
2599        /// <summary>
2600        /// You can generate a new random password for publishing a site by
2601        /// issuing an HTTP POST request. Tip: If you want to verify that the
2602        /// publish password has changed, issue an HTTP GET on /publishxml
2603        /// before calling /newpassword. In the publish XML, note the hash
2604        /// value in the userPWD attribute. After calling /newpassword, call
2605        /// /publishxml again. You can then compare the new value of userPWD
2606        /// in the Publish XML with the one you noted earlier.  (see
2607        /// http://msdn.microsoft.com/en-us/library/windowsazure/dn236428.aspx
2608        /// for more information)
2609        /// </summary>
2610        /// <param name='webSpaceName'>
2611        /// Required. The name of the web space.
2612        /// </param>
2613        /// <param name='webSiteName'>
2614        /// Required. The name of the web site.
2615        /// </param>
2616        /// <param name='cancellationToken'>
2617        /// Cancellation token.
2618        /// </param>
2619        /// <returns>
2620        /// A standard service response including an HTTP status code and
2621        /// request ID.
2622        /// </returns>
2623        public async Task<AzureOperationResponse> GeneratePasswordAsync(string webSpaceName, string webSiteName, CancellationToken cancellationToken)
2624        {
2625            // Validate
2626            if (webSpaceName == null)
2627            {
2628                throw new ArgumentNullException("webSpaceName");
2629            }
2630            if (webSiteName == null)
2631            {
2632                throw new ArgumentNullException("webSiteName");
2633            }
2634            
2635            // Tracing
2636            bool shouldTrace = TracingAdapter.IsEnabled;
2637            string invocationId = null;
2638            if (shouldTrace)
2639            {
2640                invocationId = TracingAdapter.NextInvocationId.ToString();
2641                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
2642                tracingParameters.Add("webSpaceName", webSpaceName);
2643                tracingParameters.Add("webSiteName", webSiteName);
2644                TracingAdapter.Enter(invocationId, this, "GeneratePasswordAsync", tracingParameters);
2645            }
2646            
2647            // Construct URL
2648            string url = "";
2649            url = url + "/";
2650            if (this.Client.Credentials.SubscriptionId != null)
2651            {
2652                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
2653            }
2654            url = url + "/services/WebSpaces/";
2655            url = url + Uri.EscapeDataString(webSpaceName);
2656            url = url + "/sites/";
2657            url = url + Uri.EscapeDataString(webSiteName);
2658            url = url + "/newpassword";
2659            string baseUrl = this.Client.BaseUri.AbsoluteUri;
2660            // Trim '/' character from the end of baseUrl and beginning of url.
2661            if (baseUrl[baseUrl.Length - 1] == '/')
2662            {
2663                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
2664            }
2665            if (url[0] == '/')
2666            {
2667                url = url.Substring(1);
2668            }
2669            url = baseUrl + "/" + url;
2670            url = url.Replace(" ", "%20");
2671            
2672            // Create HTTP transport objects
2673            HttpRequestMessage httpRequest = null;
2674            try
2675            {
2676                httpRequest = new HttpRequestMessage();
2677                httpRequest.Method = HttpMethod.Post;
2678                httpRequest.RequestUri = new Uri(url);
2679                
2680                // Set Headers
2681                httpRequest.Headers.Add("x-ms-version", "2014-04-01");
2682                
2683                // Set Credentials
2684                cancellationToken.ThrowIfCancellationRequested();
2685                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
2686                
2687                // Send Request
2688                HttpResponseMessage httpResponse = null;
2689                try
2690                {
2691                    if (shouldTrace)
2692                    {
2693                        TracingAdapter.SendRequest(invocationId, httpRequest);
2694                    }
2695                    cancellationToken.ThrowIfCancellationRequested();
2696                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
2697                    if (shouldTrace)
2698                    {
2699                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
2700                    }
2701                    HttpStatusCode statusCode = httpResponse.StatusCode;
2702                    if (statusCode != HttpStatusCode.OK)
2703                    {
2704                        cancellationToken.ThrowIfCancellationRequested();
2705                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
2706                        if (shouldTrace)
2707                        {
2708                            TracingAdapter.Error(invocationId, ex);
2709                        }
2710                        throw ex;
2711                    }
2712                    
2713                    // Create Result
2714                    AzureOperationResponse result = null;
2715                    // Deserialize Response
2716                    result = new AzureOperationResponse();
2717                    result.StatusCode = statusCode;
2718                    if (httpResponse.Headers.Contains("x-ms-request-id"))
2719                    {
2720                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
2721                    }
2722                    
2723                    if (shouldTrace)
2724                    {
2725                        TracingAdapter.Exit(invocationId, result);
2726                    }
2727                    return result;
2728                }
2729                finally
2730                {
2731                    if (httpResponse != null)
2732                    {
2733                        httpResponse.Dispose();
2734                    }
2735                }
2736            }
2737            finally
2738            {
2739                if (httpRequest != null)
2740                {
2741                    httpRequest.Dispose();
2742                }
2743            }
2744        }
2745        
2746        /// <summary>
2747        /// You can retrieve details for a web site by issuing an HTTP GET
2748        /// request.  (see
2749        /// http://msdn.microsoft.com/en-us/library/windowsazure/dn167007.aspx
2750        /// for more information)
2751        /// </summary>
2752        /// <param name='webSpaceName'>
2753        /// Required. The name of the web space.
2754        /// </param>
2755        /// <param name='webSiteName'>
2756        /// Required. The name of the web site.
2757        /// </param>
2758        /// <param name='parameters'>
2759        /// Optional. Parameters supplied to the Get Web Site Operation.
2760        /// </param>
2761        /// <param name='cancellationToken'>
2762        /// Cancellation token.
2763        /// </param>
2764        /// <returns>
2765        /// The Get Web Site operation response.
2766        /// </returns>
2767        public async Task<WebSiteGetResponse> GetAsync(string webSpaceName, string webSiteName, WebSiteGetParameters parameters, CancellationToken cancellationToken)
2768        {
2769            // Validate
2770            if (webSpaceName == null)
2771            {
2772                throw new ArgumentNullException("webSpaceName");
2773            }
2774            if (webSiteName == null)
2775            {
2776                throw new ArgumentNullException("webSiteName");
2777            }
2778            
2779            // Tracing
2780            bool shouldTrace = TracingAdapter.IsEnabled;
2781            string invocationId = null;
2782            if (shouldTrace)
2783            {
2784                invocationId = TracingAdapter.NextInvocationId.ToString();
2785                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
2786                tracingParameters.Add("webSpaceName", webSpaceName);
2787                tracingParameters.Add("webSiteName", webSiteName);
2788                tracingParameters.Add("parameters", parameters);
2789                TracingAdapter.Enter(invocationId, this, "GetAsync", tracingParameters);
2790            }
2791            
2792            // Construct URL
2793            string url = "";
2794            url = url + "/";
2795            if (this.Client.Credentials.SubscriptionId != null)
2796            {
2797                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
2798            }
2799            url = url + "/services/WebSpaces/";
2800            url = url + Uri.EscapeDataString(webSpaceName);
2801            url = url + "/sites/";
2802            url = url + Uri.EscapeDataString(webSiteName);
2803            List<string> queryParameters = new List<string>();
2804            if (parameters != null && parameters.PropertiesToInclude != null && parameters.PropertiesToInclude.Count > 0)
2805            {
2806                queryParameters.Add("propertiesToInclude=" + Uri.EscapeDataString(string.Join(",", parameters.PropertiesToInclude)));
2807            }
2808            if (queryParameters.Count > 0)
2809            {
2810                url = url + "?" + string.Join("&", queryParameters);
2811            }
2812            string baseUrl = this.Client.BaseUri.AbsoluteUri;
2813            // Trim '/' character from the end of baseUrl and beginning of url.
2814            if (baseUrl[baseUrl.Length - 1] == '/')
2815            {
2816                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
2817            }
2818            if (url[0] == '/')
2819            {
2820                url = url.Substring(1);
2821            }
2822            url = baseUrl + "/" + url;
2823            url = url.Replace(" ", "%20");
2824            
2825            // Create HTTP transport objects
2826            HttpRequestMessage httpRequest = null;
2827            try
2828            {
2829                httpRequest = new HttpRequestMessage();
2830                httpRequest.Method = HttpMethod.Get;
2831                httpRequest.RequestUri = new Uri(url);
2832                
2833                // Set Headers
2834                httpRequest.Headers.Add("x-ms-version", "2014-04-01");
2835                
2836                // Set Credentials
2837                cancellationToken.ThrowIfCancellationRequested();
2838                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
2839                
2840                // Send Request
2841                HttpResponseMessage httpResponse = null;
2842                try
2843                {
2844                    if (shouldTrace)
2845                    {
2846                        TracingAdapter.SendRequest(invocationId, httpRequest);
2847                    }
2848                    cancellationToken.ThrowIfCancellationRequested();
2849                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
2850                    if (shouldTrace)
2851                    {
2852                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
2853                    }
2854                    HttpStatusCode statusCode = httpResponse.StatusCode;
2855                    if (statusCode != HttpStatusCode.OK)
2856                    {
2857                        cancellationToken.ThrowIfCancellationRequested();
2858                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
2859                        if (shouldTrace)
2860                        {
2861                            TracingAdapter.Error(invocationId, ex);
2862                        }
2863                        throw ex;
2864                    }
2865                    
2866                    // Create Result
2867                    WebSiteGetResponse result = null;
2868                    // Deserialize Response
2869                    if (statusCode == HttpStatusCode.OK)
2870                    {
2871                        cancellationToken.ThrowIfCancellationRequested();
2872                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
2873                        result = new WebSiteGetResponse();
2874                        XDocument responseDoc = XDocument.Parse(responseContent);
2875                        
2876                        XElement siteElement = responseDoc.Element(XName.Get("Site", "http://schemas.microsoft.com/windowsazure"));
2877                        if (siteElement != null)
2878                        {
2879                            WebSite webSiteInstance = new WebSite();
2880                            result.WebSite = webSiteInstance;
2881                            
2882                            XElement adminEnabledElement = siteElement.Element(XName.Get("AdminEnabled", "http://schemas.microsoft.com/windowsazure"));
2883                            if (adminEnabledElement != null && !string.IsNullOrEmpty(adminEnabledElement.Value))
2884                            {
2885                                bool adminEnabledInstance = bool.Parse(adminEnabledElement.Value);
2886                                webSiteInstance.AdminEnabled = adminEnabledInstance;
2887                            }
2888                            
2889                            XElement availabilityStateElement = siteElement.Element(XName.Get("AvailabilityState", "http://schemas.microsoft.com/windowsazure"));
2890                            if (availabilityStateElement != null && !string.IsNullOrEmpty(availabilityStateElement.Value))
2891                            {
2892                                WebSpaceAvailabilityState availabilityStateInstance = ((WebSpaceAvailabilityState)Enum.Parse(typeof(WebSpaceAvailabilityState), availabilityStateElement.Value, true));
2893                                webSiteInstance.AvailabilityState = availabilityStateInstance;
2894                            }
2895                            
2896                            XElement sKUElement = siteElement.Element(XName.Get("SKU", "http://schemas.microsoft.com/windowsazure"));
2897                            if (sKUElement != null)
2898                            {
2899                                SkuOptions sKUInstance = ((SkuOptions)Enum.Parse(typeof(SkuOptions), sKUElement.Value, true));
2900                                webSiteInstance.Sku = sKUInstance;
2901                            }
2902                            
2903                            XElement enabledElement = siteElement.Element(XName.Get("Enabled", "http://schemas.microsoft.com/windowsazure"));
2904                            if (enabledElement != null && !string.IsNullOrEmpty(enabledElement.Value))
2905                            {
2906                                bool enabledInstance = bool.Parse(enabledElement.Value);
2907                                webSiteInstance.Enabled = enabledInstance;
2908                            }
2909                            
2910                            XElement enabledHostNamesSequenceElement = siteElement.Element(XName.Get("EnabledHostNames", "http://schemas.microsoft.com/windowsazure"));
2911                            if (enabledHostNamesSequenceElement != null)
2912                            {
2913                                foreach (XElement enabledHostNamesElement in enabledHostNamesSequenceElement.Elements(XName.Get("string", "http://schemas.microsoft.com/2003/10/Serialization/Arrays")))
2914                                {
2915                                    webSiteInstance.EnabledHostNames.Add(enabledHostNamesElement.Value);
2916                                }
2917                            }
2918                            
2919                            XElement hostNameSslStatesSequenceElement = siteElement.Element(XName.Get("HostNameSslStates", "http://schemas.microsoft.com/windowsazure"));
2920                            if (hostNameSslStatesSequenceElement != null)
2921                            {
2922                                foreach (XElement hostNameSslStatesElement in hostNameSslStatesSequenceElement.Elements(XName.Get("HostNameSslState", "http://schemas.microsoft.com/windowsazure")))
2923                                {
2924                                    WebSite.WebSiteHostNameSslState hostNameSslStateInstance = new WebSite.WebSiteHostNameSslState();
2925                                    webSiteInstance.HostNameSslStates.Add(hostNameSslStateInstance);
2926                                    
2927                                    XElement nameElement = hostNameSslStatesElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
2928                                    if (nameElement != null)
2929                                    {
2930                                        string nameInstance = nameElement.Value;
2931                                        hostNameSslStateInstance.Name = nameInstance;
2932                                    }
2933                                    
2934                                    XElement sslStateElement = hostNameSslStatesElement.Element(XName.Get("SslState", "http://schemas.microsoft.com/windowsazure"));
2935                                    if (sslStateElement != null && !string.IsNullOrEmpty(sslStateElement.Value))
2936                                    {
2937                                        WebSiteSslState sslStateInstance = ((WebSiteSslState)Enum.Parse(typeof(WebSiteSslState), sslStateElement.Value, true));
2938                                        hostNameSslStateInstance.SslState = sslStateInstance;
2939                                    }
2940                                    
2941                                    XElement thumbprintElement = hostNameSslStatesElement.Element(XName.Get("Thumbprint", "http://schemas.microsoft.com/windowsazure"));
2942                                    if (thumbprintElement != null)
2943                                    {
2944                                        bool isNil = false;
2945                                        XAttribute nilAttribute = thumbprintElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
2946                                        if (nilAttribute != null)
2947                                        {
2948                                            isNil = nilAttribute.Value == "true";
2949                                        }
2950                                        if (isNil == false)
2951                                        {
2952                                            string thumbprintInstance = thumbprintElement.Value;
2953                                            hostNameSslStateInstance.Thumbprint = thumbprintInstance;
2954                                        }
2955                                    }
2956                                    
2957                                    XElement virtualIPElement = hostNameSslStatesElement.Element(XName.Get("VirtualIP", "http://schemas.microsoft.com/windowsazure"));
2958                                    if (virtualIPElement != null)
2959                                    {
2960                                        bool isNil2 = false;
2961                                        XAttribute nilAttribute2 = virtualIPElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
2962                                        if (nilAttribute2 != null)
2963                                        {
2964                                            isNil2 = nilAttribute2.Value == "true";
2965                                        }
2966                                        if (isNil2 == false)
2967                                        {
2968                                            string virtualIPInstance = virtualIPElement.Value;
2969                                            hostNameSslStateInstance.VirtualIP = virtualIPInstance;
2970                                        }
2971                                    }
2972                                }
2973                            }
2974                            
2975                            XElement hostNamesSequenceElement = siteElement.Element(XName.Get("HostNames", "http://schemas.microsoft.com/windowsazure"));
2976                            if (hostNamesSequenceElement != null)
2977                            {
2978                                foreach (XElement hostNamesElement in hostNamesSequenceElement.Elements(XName.Get("string", "http://schemas.microsoft.com/2003/10/Serialization/Arrays")))
2979                                {
2980                                    webSiteInstance.HostNames.Add(hostNamesElement.Value);
2981                                }
2982                            }
2983                            
2984                            XElement lastModifiedTimeUtcElement = siteElement.Element(XName.Get("LastModifiedTimeUtc", "http://schemas.microsoft.com/windowsazure"));
2985                            if (lastModifiedTimeUtcElement != null && !string.IsNullOrEmpty(lastModifiedTimeUtcElement.Value))
2986                            {
2987                                DateTime lastModifiedTimeUtcInstance = DateTime.Parse(lastModifiedTimeUtcElement.Value, CultureInfo.InvariantCulture);
2988                                webSiteInstance.LastModifiedTimeUtc = lastModifiedTimeUtcInstance;
2989                            }
2990                            
2991                            XElement nameElement2 = siteElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
2992                            if (nameElement2 != null)
2993                            {
2994                                string nameInstance2 = nameElement2.Value;
2995                                webSiteInstance.Name = nameInstance2;
2996                            }
2997                            
2998                            XElement repositorySiteNameElement = siteElement.Element(XName.Get("RepositorySiteName", "http://schemas.microsoft.com/windowsazure"));
2999                            if (repositorySiteNameElement != null)
3000                            {
3001                                string repositorySiteNameInstance = repositorySiteNameElement.Value;
3002                                webSiteInstance.RepositorySiteName = repositorySiteNameInstance;
3003                            }
3004                            
3005                            XElement runtimeAvailabilityStateElement = siteElement.Element(XName.Get("RuntimeAvailabilityState", "http://schemas.microsoft.com/windowsazure"));
3006                            if (runtimeAvailabilityStateElement != null && !string.IsNullOrEmpty(runtimeAvailabilityStateElement.Value))
3007                            {
3008                                WebSiteRuntimeAvailabilityState runtimeAvailabilityStateInstance = ((WebSiteRuntimeAvailabilityState)Enum.Parse(typeof(WebSiteRuntimeAvailabilityState), runtimeAvailabilityStateElement.Value, true));
3009                                webSiteInstance.RuntimeAvailabilityState = runtimeAvailabilityStateInstance;
3010                            }
3011                            
3012                            XElement selfLinkElement = siteElement.Element(XName.Get("SelfLink", "http://schemas.microsoft.com/windowsazure"));
3013                            if (selfLinkElement != null)
3014                            {
3015                                Uri selfLinkInstance = TypeConversion.TryParseUri(selfLinkElement.Value);
3016                                webSiteInstance.Uri = selfLinkInstance;
3017                            }
3018                            
3019                            XElement serverFarmElement = siteElement.Element(XName.Get("ServerFarm", "http://schemas.microsoft.com/windowsazure"));
3020                            if (serverFarmElement != null)
3021                            {
3022                                string serverFarmInstance = serverFarmElement.Value;
3023                                webSiteInstance.ServerFarm = serverFarmInstance;
3024                            }
3025                            
3026                            XElement sitePropertiesElement = siteElement.Element(XName.Get("SiteProperties", "http://schemas.microsoft.com/windowsazure"));
3027                            if (sitePropertiesElement != null)
3028                            {
3029                                WebSite.WebSiteProperties sitePropertiesInstance = new WebSite.WebSiteProperties();
3030                                webSiteInstance.SiteProperties = sitePropertiesInstance;
3031                                
3032                                XElement appSettingsSequenceElement = sitePropertiesElement.Element(XName.Get("AppSettings", "http://schemas.microsoft.com/windowsazure"));
3033                                if (appSettingsSequenceElement != null)
3034                                {
3035                                    foreach (XElement appSettingsElement in appSettingsSequenceElement.Elements(XName.Get("NameValuePair", "http://schemas.microsoft.com/windowsazure")))
3036                                    {
3037                                        string appSettingsKey = appSettingsElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure")).Value;
3038                                        string appSettingsValue = appSettingsElement.Element(XName.Get("Value", "http://schemas.microsoft.com/windowsazure")).Value;
3039                                        sitePropertiesInstance.AppSettings.Add(appSettingsKey, appSettingsValue);
3040                                    }
3041                                }
3042                                
3043                                XElement metadataSequenceElement = sitePropertiesElement.Element(XName.Get("Metadata", "http://schemas.microsoft.com/windowsazure"));
3044                                if (metadataSequenceElement != null)
3045                                {
3046                                    foreach (XElement metadataElement in metadataSequenceElement.Elements(XName.Get("NameValuePair", "http://schemas.microsoft.com/windowsazure")))
3047                                    {
3048                                        string metadataKey = metadataElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure")).Value;
3049                                        string metadataValue = metadataElement.Element(XName.Get("Value", "http://schemas.microsoft.com/windowsazure")).Value;
3050                                        sitePropertiesInstance.Metadata.Add(metadataKey, metadataValue);
3051                                    }
3052                                }
3053                                
3054                                XElement propertiesSequenceElement = sitePropertiesElement.Element(XName.Get("Properties", "http://schemas.microsoft.com/windowsazure"));
3055                                if (propertiesSequenceElement != null)
3056                                {
3057                                    foreach (XElement propertiesElement in propertiesSequenceElement.Elements(XName.Get("NameValuePair", "http://schemas.microsoft.com/windowsazure")))
3058                                    {
3059                                        string propertiesKey = propertiesElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure")).Value;
3060                                        string propertiesValue = propertiesElement.Element(XName.Get("Value", "http://schemas.microsoft.com/windowsazure")).Value;
3061                                        sitePropertiesInstance.Properties.Add(propertiesKey, propertiesValue);
3062                                    }
3063                                }
3064                            }
3065                            
3066                            XElement stateElement = siteElement.Element(XName.Get("State", "http://schemas.microsoft.com/windowsazure"));
3067                            if (stateElement != null)
3068                            {
3069                                string stateInstance = stateElement.Value;
3070                                webSiteInstance.State = stateInstance;
3071                            }
3072                            
3073                            XElement usageStateElement = siteElement.Element(XName.Get("UsageState", "http://schemas.microsoft.com/windowsazure"));
3074                            if (usageStateElement != null && !string.IsNullOrEmpty(usageStateElement.Value))
3075                            {
3076                                WebSiteUsageState usageStateInstance = ((WebSiteUsageState)Enum.Parse(typeof(WebSiteUsageState), usageStateElement.Value, true));
3077                                webSiteInstance.UsageState = usageStateInstance;
3078                            }
3079                            
3080                            XElement webSpaceElement = siteElement.Element(XName.Get("WebSpace", "http://schemas.microsoft.com/windowsazure"));
3081                            if (webSpaceElement != null)
3082                            {
3083                                string webSpaceInstance = webSpaceElement.Value;
3084                                webSiteInstance.WebSpace = webSpaceInstance;
3085                            }
3086                        }
3087                        
3088                    }
3089                    result.StatusCode = statusCode;
3090                    if (httpResponse.Headers.Contains("x-ms-request-id"))
3091                    {
3092                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
3093                    }
3094                    
3095                    if (shouldTrace)
3096                    {
3097                        TracingAdapter.Exit(invocationId, result);
3098                    }
3099                    return result;
3100                }
3101                finally
3102                {
3103                    if (httpResponse != null)
3104                    {
3105                        httpResponse.Dispose();
3106                    }
3107                }
3108            }
3109            finally
3110            {
3111                if (httpRequest != null)
3112                {
3113                    httpRequest.Dispose();
3114                }
3115            }
3116        }
3117        
3118        /// <summary>
3119        /// Gets a schedule configuration for site backups.
3120        /// </summary>
3121        /// <param name='webSpaceName'>
3122        /// Required. The name of the web space.
3123        /// </param>
3124        /// <param name='webSiteName'>
3125        /// Required. The name of the web site.
3126        /// </param>
3127        /// <param name='cancellationToken'>
3128        /// Cancellation token.
3129        /// </param>
3130        /// <returns>
3131        /// Scheduled backup definition.
3132        /// </returns>
3133        public async Task<WebSiteGetBackupConfigurationResponse> GetBackupConfigurationAsync(string webSpaceName, string webSiteName, CancellationToken cancellationToken)
3134        {
3135            // Validate
3136            if (webSpaceName == null)
3137            {
3138                throw new ArgumentNullException("webSpaceName");
3139            }
3140            if (webSiteName == null)
3141            {
3142                throw new ArgumentNullException("webSiteName");
3143            }
3144            
3145            // Tracing
3146            bool shouldTrace = TracingAdapter.IsEnabled;
3147            string invocationId = null;
3148            if (shouldTrace)
3149            {
3150                invocationId = TracingAdapter.NextInvocationId.ToString();
3151                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
3152                tracingParameters.Add("webSpaceName", webSpaceName);
3153                tracingParameters.Add("webSiteName", webSiteName);
3154                TracingAdapter.Enter(invocationId, this, "GetBackupConfigurationAsync", tracingParameters);
3155            }
3156            
3157            // Construct URL
3158            string url = "";
3159            url = url + "/";
3160            if (this.Client.Credentials.SubscriptionId != null)
3161            {
3162                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
3163            }
3164            url = url + "/services/WebSpaces/";
3165            url = url + Uri.EscapeDataString(webSpaceName);
3166            url = url + "/sites/";
3167            url = url + Uri.EscapeDataString(webSiteName);
3168            url = url + "/backup/config";
3169            string baseUrl = this.Client.BaseUri.AbsoluteUri;
3170            // Trim '/' character from the end of baseUrl and beginning of url.
3171            if (baseUrl[baseUrl.Length - 1] == '/')
3172            {
3173                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
3174            }
3175            if (url[0] == '/')
3176            {
3177                url = url.Substring(1);
3178            }
3179            url = baseUrl + "/" + url;
3180            url = url.Replace(" ", "%20");
3181            
3182            // Create HTTP transport objects
3183            HttpRequestMessage httpRequest = null;
3184            try
3185            {
3186                httpRequest = new HttpRequestMessage();
3187                httpRequest.Method = HttpMethod.Get;
3188                httpRequest.RequestUri = new Uri(url);
3189                
3190                // Set Headers
3191                httpRequest.Headers.Add("x-ms-version", "2014-04-01");
3192                
3193                // Set Credentials
3194                cancellationToken.ThrowIfCancellationRequested();
3195                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
3196                
3197                // Send Request
3198                HttpResponseMessage httpResponse = null;
3199                try
3200                {
3201                    if (shouldTrace)
3202                    {
3203                        TracingAdapter.SendRequest(invocationId, httpRequest);
3204                    }
3205                    cancellationToken.ThrowIfCancellationRequested();
3206                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
3207                    if (shouldTrace)
3208                    {
3209                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
3210                    }
3211                    HttpStatusCode statusCode = httpResponse.StatusCode;
3212                    if (statusCode != HttpStatusCode.OK)
3213                    {
3214                        cancellationToken.ThrowIfCancellationRequested();
3215                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
3216                        if (shouldTrace)
3217                        {
3218                            TracingAdapter.Error(invocationId, ex);
3219                        }
3220                        throw ex;
3221                    }
3222                    
3223                    // Create Result
3224                    WebSiteGetBackupConfigurationResponse result = null;
3225                    // Deserialize Response
3226                    if (statusCode == HttpStatusCode.OK)
3227                    {
3228                        cancellationToken.ThrowIfCancellationRequested();
3229                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
3230                        result = new WebSiteGetBackupConfigurationResponse();
3231                        XDocument responseDoc = XDocument.Parse(responseContent);
3232                        
3233                        XElement backupRequestElement = responseDoc.Element(XName.Get("BackupRequest", "http://schemas.microsoft.com/windowsazure"));
3234                        if (backupRequestElement != null)
3235                        {
3236                            XElement enabledElement = backupRequestElement.Element(XName.Get("Enabled", "http://schemas.microsoft.com/windowsazure"));
3237                            if (enabledElement != null && !string.IsNullOrEmpty(enabledElement.Value))
3238                            {
3239                                bool enabledInstance = bool.Parse(enabledElement.Value);
3240                                result.Enabled = enabledInstance;
3241                            }
3242                            
3243                            XElement nameElement = backupRequestElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
3244                            if (nameElement != null)
3245                            {
3246                                string nameInstance = nameElement.Value;
3247                                result.Name = nameInstance;
3248                            }
3249                            
3250                            XElement backupScheduleElement = backupRequestElement.Element(XName.Get("BackupSchedule", "http://schemas.microsoft.com/windowsazure"));
3251                            if (backupScheduleElement != null)
3252                            {
3253                                BackupSchedule backupScheduleInstance = new BackupSchedule();
3254                                result.BackupSchedule = backupScheduleInstance;
3255                                
3256                                XElement frequencyIntervalElement = backupScheduleElement.Element(XName.Get("FrequencyInterval", "http://schemas.microsoft.com/windowsazure"));
3257                                if (frequencyIntervalElement != null)
3258                                {
3259                                    int frequencyIntervalInstance = int.Parse(frequencyIntervalElement.Value, CultureInfo.InvariantCulture);
3260                                    backupScheduleInstance.FrequencyInterval = frequencyIntervalInstance;
3261                                }
3262                                
3263                                XElement frequencyUnitElement = backupScheduleElement.Element(XName.Get("FrequencyUnit", "http://schemas.microsoft.com/windowsazure"));
3264                                if (frequencyUnitElement != null)
3265                                {
3266                                    FrequencyUnit frequencyUnitInstance = ((FrequencyUnit)Enum.Parse(typeof(FrequencyUnit), frequencyUnitElement.Value, true));
3267                                    backupScheduleInstance.FrequencyUnit = frequencyUnitInstance;
3268                                }
3269                                
3270                                XElement keepAtLeastOneBackupElement = backupScheduleElement.Element(XName.Get("KeepAtLeastOneBackup", "http://schemas.microsoft.com/windowsazure"));
3271                                if (keepAtLeastOneBackupElement != null)
3272                                {
3273                                    bool keepAtLeastOneBackupInstance = bool.Parse(keepAtLeastOneBackupElement.Value);
3274                                    backupScheduleInstance.KeepAtLeastOneBackup = keepAtLeastOneBackupInstance;
3275                                }
3276                                
3277                                XElement lastExecutionTimeElement = backupScheduleElement.Element(XName.Get("LastExecutionTime", "http://schemas.microsoft.com/windowsazure"));
3278                                if (lastExecutionTimeElement != null && !string.IsNullOrEmpty(lastExecutionTimeElement.Value))
3279                                {
3280                                    DateTime lastExecutionTimeInstance = DateTime.Parse(lastExecutionTimeElement.Value, CultureInfo.InvariantCulture);
3281                                    backupScheduleInstance.LastExecutionTime = lastExecutionTimeInstance;
3282                                }
3283                                
3284                                XElement retentionPeriodInDaysElement = backupScheduleElement.Element(XName.Get("RetentionPeriodInDays", "http://schemas.microsoft.com/windowsazure"));
3285                                if (retentionPeriodInDaysElement != null)
3286                                {
3287                                    int retentionPeriodInDaysInstance = int.Parse(retentionPeriodInDaysElement.Value, CultureInfo.InvariantCulture);
3288                                    backupScheduleInstance.RetentionPeriodInDays = retentionPeriodInDaysInstance;
3289                                }
3290                                
3291                                XElement startTimeElement = backupScheduleElement.Element(XName.Get("StartTime", "http://schemas.microsoft.com/windowsazure"));
3292                                if (startTimeElement != null && !string.IsNullOrEmpty(startTimeElement.Value))
3293                                {
3294                                    DateTime startTimeInstance = DateTime.Parse(startTimeElement.Value, CultureInfo.InvariantCulture);
3295                                    backupScheduleInstance.StartTime = startTimeInstance;
3296                                }
3297                            }
3298                            
3299                            XElement databasesSequenceElement = backupRequestElement.Element(XName.Get("Databases", "http://schemas.microsoft.com/windowsazure"));
3300                            if (databasesSequenceElement != null)
3301                            {
3302                                foreach (XElement databasesElement in databasesSequenceElement.Elements(XName.Get("DatabaseBackupSetting", "http://schemas.microsoft.com/windowsazure")))
3303                                {
3304                                    DatabaseBackupSetting databaseBackupSettingInstance = new DatabaseBackupSetting();
3305                                    result.Databases.Add(databaseBackupSettingInstance);
3306                                    
3307                                    XElement connectionStringElement = databasesElement.Element(XName.Get("ConnectionString", "http://schemas.microsoft.com/windowsazure"));
3308                                    if (connectionStringElement != null)
3309                                    {
3310                                        string connectionStringInstance = connectionStringElement.Value;
3311                                        databaseBackupSettingInstance.ConnectionString = connectionStringInstance;
3312                                    }
3313                                    
3314                                    XElement connectionStringNameElement = databasesElement.Element(XName.Get("ConnectionStringName", "http://schemas.microsoft.com/windowsazure"));
3315                                    if (connectionStringNameElement != null)
3316                                    {
3317                                        string connectionStringNameInstance = connectionStringNameElement.Value;
3318                                        databaseBackupSettingInstance.ConnectionStringName = connectionStringNameInstance;
3319                                    }
3320                                    
3321                                    XElement databaseTypeElement = databasesElement.Element(XName.Get("DatabaseType", "http://schemas.microsoft.com/windowsazure"));
3322                                    if (databaseTypeElement != null)
3323                                    {
3324                                        string databaseTypeInstance = databaseTypeElement.Value;
3325                                        databaseBackupSettingInstance.DatabaseType = databaseTypeInstance;
3326                                    }
3327                                    
3328                                    XElement nameElement2 = databasesElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
3329                                    if (nameElement2 != null)
3330                                    {
3331                                        string nameInstance2 = nameElement2.Value;
3332                                        databaseBackupSettingInstance.Name = nameInstance2;
3333                                    }
3334                                }
3335                            }
3336                            
3337                            XElement storageAccountUrlElement = backupRequestElement.Element(XName.Get("StorageAccountUrl", "http://schemas.microsoft.com/windowsazure"));
3338                            if (storageAccountUrlElement != null)
3339                            {
3340                                string storageAccountUrlInstance = storageAccountUrlElement.Value;
3341                                result.StorageAccountUrl = storageAccountUrlInstance;
3342                            }
3343                        }
3344                        
3345                    }
3346                    result.StatusCode = statusCode;
3347                    if (httpResponse.Headers.Contains("x-ms-request-id"))
3348                    {
3349                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
3350                    }
3351                    
3352                    if (shouldTrace)
3353                    {
3354                        TracingAdapter.Exit(invocationId, result);
3355                    }
3356                    return result;
3357                }
3358                finally
3359                {
3360                    if (httpResponse != null)
3361                    {
3362                        httpResponse.Dispose();
3363                    }
3364                }
3365            }
3366            finally
3367            {
3368                if (httpRequest != null)
3369                {
3370                    httpRequest.Dispose();
3371                }
3372            }
3373        }
3374        
3375        /// <summary>
3376        /// You can retrieve the config settings for a web site by issuing an
3377        /// HTTP GET request.  (see
3378        /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166985.aspx
3379        /// for more information)
3380        /// </summary>
3381        /// <param name='webSpaceName'>
3382        /// Required. The name of the web space.
3383        /// </param>
3384        /// <param name='webSiteName'>
3385        /// Required. The name of the web site.
3386        /// </param>
3387        /// <param name='cancellationToken'>
3388        /// Cancellation token.
3389        /// </param>
3390        /// <returns>
3391        /// The Get Configuration Web Site operation response.
3392        /// </returns>
3393        public async Task<WebSiteGetConfigurationResponse> GetConfigurationAsync(string webSpaceName, string webSiteName, CancellationToken cancellationToken)
3394        {
3395            // Validate
3396            if (webSpaceName == null)
3397            {
3398                throw new ArgumentNullException("webSpaceName");
3399            }
3400            if (webSiteName == null)
3401            {
3402                throw new ArgumentNullException("webSiteName");
3403            }
3404            
3405            // Tracing
3406            bool shouldTrace = TracingAdapter.IsEnabled;
3407            string invocationId = null;
3408            if (shouldTrace)
3409            {
3410                invocationId = TracingAdapter.NextInvocationId.ToString();
3411                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
3412                tracingParameters.Add("webSpaceName", webSpaceName);
3413                tracingParameters.Add("webSiteName", webSiteName);
3414                TracingAdapter.Enter(invocationId, this, "GetConfigurationAsync", tracingParameters);
3415            }
3416            
3417            // Construct URL
3418            string url = "";
3419            url = url + "/";
3420            if (this.Client.Credentials.SubscriptionId != null)
3421            {
3422                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
3423            }
3424            url = url + "/services/WebSpaces/";
3425            url = url + Uri.EscapeDataString(webSpaceName);
3426            url = url + "/sites/";
3427            url = url + Uri.EscapeDataString(webSiteName);
3428            url = url + "/config";
3429            string baseUrl = this.Client.BaseUri.AbsoluteUri;
3430            // Trim '/' character from the end of baseUrl and beginning of url.
3431            if (baseUrl[baseUrl.Length - 1] == '/')
3432            {
3433                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
3434            }
3435            if (url[0] == '/')
3436            {
3437                url = url.Substring(1);
3438            }
3439            url = baseUrl + "/" + url;
3440            url = url.Replace(" ", "%20");
3441            
3442            // Create HTTP transport objects
3443            HttpRequestMessage httpRequest = null;
3444            try
3445            {
3446                httpRequest = new HttpRequestMessage();
3447                httpRequest.Method = HttpMethod.Get;
3448                httpRequest.RequestUri = new Uri(url);
3449                
3450                // Set Headers
3451                httpRequest.Headers.Add("accept", "application/json");
3452                httpRequest.Headers.Add("x-ms-version", "2014-04-01");
3453                
3454                // Set Credentials
3455                cancellationToken.ThrowIfCancellationRequested();
3456                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
3457                
3458                // Send Request
3459                HttpResponseMessage httpResponse = null;
3460                try
3461                {
3462                    if (shouldTrace)
3463                    {
3464                        TracingAdapter.SendRequest(invocationId, httpRequest);
3465                    }
3466                    cancellationToken.ThrowIfCancellationRequested();
3467                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
3468                    if (shouldTrace)
3469                    {
3470                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
3471                    }
3472                    HttpStatusCode statusCode = httpResponse.StatusCode;
3473                    if (statusCode != HttpStatusCode.OK)
3474                    {
3475                        cancellationToken.ThrowIfCancellationRequested();
3476                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
3477                        if (shouldTrace)
3478                        {
3479                            TracingAdapter.Error(invocationId, ex);
3480                        }
3481                        throw ex;
3482                    }
3483                    
3484                    // Create Result
3485                    WebSiteGetConfigurationResponse result = null;
3486                    // Deserialize Response
3487                    if (statusCode == HttpStatusCode.OK)
3488                    {
3489                        cancellationToken.ThrowIfCancellationRequested();
3490                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
3491                        result = new WebSiteGetConfigurationResponse();
3492                        JToken responseDoc = null;
3493                        if (string.IsNullOrEmpty(responseContent) == false)
3494                        {
3495                            responseDoc = JToken.Parse(responseContent);
3496                        }
3497                        
3498                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
3499                        {
3500                            JToken appSettingsSequenceElement = ((JToken)responseDoc["AppSettings"]);
3501                            if (appSettingsSequenceElement != null && appSettingsSequenceElement.Type != JTokenType.Null)
3502                            {
3503                                foreach (JToken appSettingsElement in ((JArray)appSettingsSequenceElement))
3504                                {
3505                                    string appSettingsKey = ((string)appSettingsElement["Name"]);
3506                                    string appSettingsValue = ((string)appSettingsElement["Value"]);
3507                                    result.AppSettings.Add(appSettingsKey, appSettingsValue);
3508                                }
3509                            }
3510                            
3511                            JToken connectionStringsArray = responseDoc["ConnectionStrings"];
3512                            if (connectionStringsArray != null && connectionStringsArray.Type != JTokenType.Null)
3513                            {
3514                                foreach (JToken connectionStringsValue in ((JArray)connectionStringsArray))
3515                                {
3516                                    WebSiteGetConfigurationResponse.ConnectionStringInfo connectionStringInfoInstance = new WebSiteGetConfigurationResponse.ConnectionStringInfo();
3517                                    result.ConnectionStrings.Add(connectionStringInfoInstance);
3518                                    
3519                                    JToken connectionStringValue = connectionStringsValue["ConnectionString"];
3520                                    if (connectionStringValue != null && connectionStringValue.Type != JTokenType.Null)
3521                                    {
3522                                        string connectionStringInstance = ((string)connectionStringValue);
3523                                        connectionStringInfoInstance.ConnectionString = connectionStringInstance;
3524                                    }
3525                                    
3526                                    JToken nameValue = connectionStringsValue["Name"];
3527                                    if (nameValue != null && nameValue.Type != JTokenType.Null)
3528                                    {
3529                                        string nameInstance = ((string)nameValue);
3530                                        connectionStringInfoInstance.Name = nameInstance;
3531                                    }
3532                                    
3533                                    JToken typeValue = connectionStringsValue["Type"];
3534                                    if (typeValue != null && typeValue.Type != JTokenType.Null)
3535                                    {
3536                                        ConnectionStringType typeInstance = ((ConnectionStringType)(((int)typeValue)));
3537                                        connectionStringInfoInstance.Type = typeInstance;
3538                                    }
3539                                }
3540                            }
3541                            
3542                            JToken defaultDocumentsArray = responseDoc["DefaultDocuments"];
3543                            if (defaultDocumentsArray != null && defaultDocumentsArray.Type != JTokenType.Null)
3544                            {
3545                                foreach (JToken defaultDocumentsValue in ((JArray)defaultDocumentsArray))
3546                                {
3547                                    result.DefaultDocuments.Add(((string)defaultDocumentsValue));
3548                                }
3549                            }
3550                            
3551                            JToken detailedErrorLoggingEnabledValue = responseDoc["DetailedErrorLoggingEnabled"];
3552                            if (detailedErrorLoggingEnabledValue != null && detailedErrorLoggingEnabledValue.Type != JTokenType.Null)
3553                            {
3554                                bool detailedErrorLoggingEnabledInstance = ((bool)detailedErrorLoggingEnabledValue);
3555                                result.DetailedErrorLoggingEnabled = detailedErrorLoggingEnabledInstance;
3556                            }
3557                            
3558                            JToken documentRootValue = responseDoc["DocumentRoot"];
3559                            if (documentRootValue != null && documentRootValue.Type != JTokenType.Null)
3560                            {
3561                                string documentRootInstance = ((string)documentRootValue);
3562                                result.DocumentRoot = documentRootInstance;
3563                            }
3564                            
3565                            JToken handlerMappingsArray = responseDoc["HandlerMappings"];
3566                            if (handlerMappingsArray != null && handlerMappingsArray.Type != JTokenType.Null)
3567                            {
3568                                foreach (JToken handlerMappingsValue in ((JArray)handlerMappingsArray))
3569                                {
3570                                    WebSiteGetConfigurationResponse.HandlerMapping handlerMappingInstance = new WebSiteGetConfigurationResponse.HandlerMapping();
3571                                    result.HandlerMappings.Add(handlerMappingInstance);
3572                                    
3573                                    JToken argumentsValue = handlerMappingsValue["Arguments"];
3574                                    if (argumentsValue != null && argumentsValue.Type != JTokenType.Null)
3575                                    {
3576                                        string argumentsInstance = ((string)argumentsValue);
3577                                        handlerMappingInstance.Arguments = argumentsInstance;
3578                                    }
3579                                    
3580                                    JToken extensionValue = handlerMappingsValue["Extension"];
3581                                    if (extensionValue != null && extensionValue.Type != JTokenType.Null)
3582                                    {
3583                                        string extensionInstance = ((string)extensionValue);
3584                                        handlerMappingInstance.Extension = extensionInstance;
3585                                    }
3586                                    
3587                                    JToken scriptProcessorValue = handlerMappingsValue["ScriptProcessor"];
3588                                    if (scriptProcessorValue != null && scriptProcessorValue.Type != JTokenType.Null)
3589                                    {
3590                                        string scriptProcessorInstance = ((string)scriptProcessorValue);
3591                                        handlerMappingInstance.ScriptProcessor = scriptProcessorInstance;
3592                                    }
3593                                }
3594                            }
3595                            
3596                            JToken httpLoggingEnabledValue = responseDoc["HttpLoggingEnabled"];
3597                            if (httpLoggingEnabledValue != null && httpLoggingEnabledValue.Type != JTokenType.Null)
3598                            {
3599                                bool httpLoggingEnabledInstance = ((bool)httpLoggingEnabledValue);
3600                                result.HttpLoggingEnabled = httpLoggingEnabledInstance;
3601                            }
3602                            
3603                            JToken logsDirectorySizeLimitValue = responseDoc["LogsDirectorySizeLimit"];
3604                            if (logsDirectorySizeLimitValue != null && logsDirectorySizeLimitValue.Type != JTokenType.Null)
3605                            {
3606                                int logsDirectorySizeLimitInstance = ((int)logsDirectorySizeLimitValue);
3607                                result.LogsDirectorySizeLimit = logsDirectorySizeLimitInstance;
3608                            }
3609                            
3610                            JToken managedPipelineModeValue = responseDoc["ManagedPipelineMode"];
3611                            if (managedPipelineModeValue != null && managedPipelineModeValue.Type != JTokenType.Null)
3612                            {
3613                                ManagedPipelineMode managedPipelineModeInstance = ((ManagedPipelineMode)(((int)managedPipelineModeValue)));
3614                                result.ManagedPipelineMode = managedPipelineModeInstance;
3615                            }
3616                            
3617                            JToken metadataSequenceElement = ((JToken)responseDoc["Metadata"]);
3618                            if (metadataSequenceElement != null && metadataSequenceElement.Type != JTokenType.Null)
3619                            {
3620                                foreach (JToken metadataElement in ((JArray)metadataSequenceElement))
3621                                {
3622                                    string metadataKey = ((string)metadataElement["Name"]);
3623                                    string metadataValue = ((string)metadataElement["Value"]);
3624                                    result.Metadata.Add(metadataKey, metadataValue);
3625                                }
3626                            }
3627                            
3628                            JToken netFrameworkVersionValue = responseDoc["NetFrameworkVersion"];
3629                            if (netFrameworkVersionValue != null && netFrameworkVersionValue.Type != JTokenType.Null)
3630                            {
3631                                string netFrameworkVersionInstance = ((string)netFrameworkVersionValue);
3632                                result.NetFrameworkVersion = netFrameworkVersionInstance;
3633                            }
3634                            
3635                            JToken numberOfWorkersValue = responseDoc["NumberOfWorkers"];
3636                            if (numberOfWorkersValue != null && numberOfWorkersValue.Type != JTokenType.Null)
3637                            {
3638                                int numberOfWorkersInstance = ((int)numberOfWorkersValue);
3639                                result.NumberOfWorkers = numberOfWorkersInstance;
3640                            }
3641                            
3642                            JToken phpVersionValue = responseDoc["PhpVersion"];
3643                            if (phpVersionValue != null && phpVersionValue.Type != JTokenType.Null)
3644                            {
3645                                string phpVersionInstance = ((string)phpVersionValue);
3646                                result.PhpVersion = phpVersionInstance;
3647                            }
3648                            
3649                            JToken publishingPasswordValue = responseDoc["PublishingPassword"];
3650                            if (publishingPasswordValue != null && publishingPasswordValue.Type != JTokenType.Null)
3651                            {
3652                                string publishingPasswordInstance = ((string)publishingPasswordValue);
3653                                result.PublishingPassword = publishingPasswordInstance;
3654                            }
3655                            
3656                            JToken publishingUsernameValue = responseDoc["PublishingUsername"];
3657                            if (publishingUsernameValue != null && publishingUsernameValue.Type != JTokenType.Null)
3658                            {
3659                                string publishingUsernameInstance = ((string)publishingUsernameValue);
3660                                result.PublishingUserName = publishingUsernameInstance;
3661                            }
3662                            
3663                            JToken remoteDebuggingEnabledValue = responseDoc["RemoteDebuggingEnabled"];
3664                            if (remoteDebuggingEnabledValue != null && remoteDebuggingEnabledValue.Type != JTokenType.Null)
3665                            {
3666                                bool remoteDebuggingEnabledInstance = ((bool)remoteDebuggingEnabledValue);
3667                                result.RemoteDebuggingEnabled = remoteDebuggingEnabledInstance;
3668                            }
3669                            
3670                            JToken remoteDebuggingVersionValue = responseDoc["RemoteDebuggingVersion"];
3671                            if (remoteDebuggingVersionValue != null && remoteDebuggingVersionValue.Type != JTokenType.Null)
3672                            {
3673                                RemoteDebuggingVersion remoteDebuggingVersionInstance = ((RemoteDebuggingVersion)Enum.Parse(typeof(RemoteDebuggingVersion), ((string)remoteDebuggingVersionValue), true));
3674                                result.RemoteDebuggingVersion = remoteDebuggingVersionInstance;
3675                            }
3676                            
3677                            JToken requestTracingEnabledValue = responseDoc["RequestTracingEnabled"];
3678                            if (requestTracingEnabledValue != null && requestTracingEnabledValue.Type != JTokenType.Null)
3679                            {
3680                                bool requestTracingEnabledInstance = ((bool)requestTracingEnabledValue);
3681                                result.RequestTracingEnabled = requestTracingEnabledInstance;
3682                            }
3683                            
3684                            JToken requestTracingExpirationTimeValue = responseDoc["RequestTracingExpirationTime"];
3685                            if (requestTracingExpirationTimeValue != null && requestTracingExpirationTimeValue.Type != JTokenType.Null)
3686                            {
3687                                DateTime requestTracingExpirationTimeInstance = ((DateTime)requestTracingExpirationTimeValue);
3688                                result.RequestTracingExpirationTime = requestTracingExpirationTimeInstance;
3689                            }
3690                            
3691                            JToken scmTypeValue = responseDoc["ScmType"];
3692                            if (scmTypeValue != null && scmTypeValue.Type != JTokenType.Null)
3693                            {
3694                                string scmTypeInstance = ((string)scmTypeValue);
3695                                result.ScmType = scmTypeInstance;
3696                            }
3697                            
3698                            JToken use32BitWorkerProcessValue = responseDoc["Use32BitWorkerProcess"];
3699                            if (use32BitWorkerProcessValue != null && use32BitWorkerProcessValue.Type != JTokenType.Null)
3700                            {
3701                                bool use32BitWorkerProcessInstance = ((bool)use32BitWorkerProcessValue);
3702                                result.Use32BitWorkerProcess = use32BitWorkerProcessInstance;
3703                            }
3704                            
3705                            JToken webSocketsEnabledValue = responseDoc["WebSocketsEnabled"];
3706                            if (webSocketsEnabledValue != null && webSocketsEnabledValue.Type != JTokenType.Null)
3707                            {
3708                                bool webSocketsEnabledInstance = ((bool)webSocketsEnabledValue);
3709                                result.WebSocketsEnabled = webSocketsEnabledInstance;
3710                            }
3711                            
3712                            JToken alwaysOnValue = responseDoc["AlwaysOn"];
3713                            if (alwaysOnValue != null && alwaysOnValue.Type != JTokenType.Null)
3714                            {
3715                                bool alwaysOnInstance = ((bool)alwaysOnValue);
3716                                result.AlwaysOn = alwaysOnInstance;
3717                            }
3718                            
3719                            JToken routingRulesArray = responseDoc["RoutingRules"];
3720                            if (routingRulesArray != null && routingRulesArray.Type != JTokenType.Null)
3721                            {
3722                                foreach (JToken routingRulesValue in ((JArray)routingRulesArray))
3723                                {
3724                                    string typeName = ((string)routingRulesValue["__type"]);
3725                                    if (typeName == "RampUpRule:http://schemas.microsoft.com/windowsazure")
3726                                    {
3727                                        RampUpRule rampUpRuleInstance = new RampUpRule();
3728                                        
3729                                        JToken actionHostNameValue = routingRulesValue["ActionHostName"];
3730                                        if (actionHostNameValue != null && actionHostNameValue.Type != JTokenType.Null)
3731                                        {
3732                                            string actionHostNameInstance = ((string)actionHostNameValue);
3733                                            rampUpRuleInstance.ActionHostName = actionHostNameInstance;
3734                                        }
3735                                        
3736                                        JToken reroutePercentageValue = routingRulesValue["ReroutePercentage"];
3737                                        if (reroutePercentageValue != null && reroutePercentageValue.Type != JTokenType.Null)
3738                                        {
3739                                            double reroutePercentageInstance = ((double)reroutePercentageValue);
3740                                            rampUpRuleInstance.ReroutePercentage = reroutePercentageInstance;
3741                                        }
3742                                        
3743                                        JToken changeStepValue = routingRulesValue["ChangeStep"];
3744                                        if (changeStepValue != null && changeStepValue.Type != JTokenType.Null)
3745                                        {
3746                                            double changeStepInstance = ((double)changeStepValue);
3747                                            rampUpRuleInstance.ChangeStep = changeStepInstance;
3748                                        }
3749                                        
3750                                        JToken changeIntervalInMinutesValue = routingRulesValue["ChangeIntervalInMinutes"];
3751                                        if (changeIntervalInMinutesValue != null && changeIntervalInMinutesValue.Type != JTokenType.Null)
3752                                        {
3753                                            int changeIntervalInMinutesInstance = ((int)changeIntervalInMinutesValue);
3754                                            rampUpRuleInstance.ChangeIntervalInMinutes = changeIntervalInMinutesInstance;
3755                                        }
3756                                        
3757                                        JToken minReroutePercentageValue = routingRulesValue["MinReroutePercentage"];
3758                                        if (minReroutePercentageValue != null && minReroutePercentageValue.Type != JTokenType.Null)
3759                                        {
3760                                            double minReroutePercentageInstance = ((double)minReroutePercentageValue);
3761                                            rampUpRuleInstance.MinReroutePercentage = minReroutePercentageInstance;
3762                                        }
3763                                        
3764                                        JToken maxReroutePercentageValue = routingRulesValue["MaxReroutePercentage"];
3765                                        if (maxReroutePercentageValue != null && maxReroutePercentageValue.Type != JTokenType.Null)
3766                                        {
3767                                            double maxReroutePercentageInstance = ((double)maxReroutePercentageValue);
3768                                            rampUpRuleInstance.MaxReroutePercentage = maxReroutePercentageInstance;
3769                                        }
3770                                        
3771                                        JToken changeDecisionCallbackUrlValue = routingRulesValue["ChangeDecisionCallbackUrl"];
3772                                        if (changeDecisionCallbackUrlValue != null && changeDecisionCallbackUrlValue.Type != JTokenType.Null)
3773                                        {
3774                                            string changeDecisionCallbackUrlInstance = ((string)changeDecisionCallbackUrlValue);
3775                                            rampUpRuleInstance.ChangeDecisionCallbackUrl = changeDecisionCallbackUrlInstance;
3776                                        }
3777                                        
3778                                        JToken nameValue2 = routingRulesValue["Name"];
3779                                        if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
3780                                        {
3781                                            string nameInstance2 = ((string)nameValue2);
3782                                            rampUpRuleInstance.Name = nameInstance2;
3783                                        }
3784                                        result.RoutingRules.Add(rampUpRuleInstance);
3785                                    }
3786                                }
3787                            }
3788                            
3789                            JToken javaVersionValue = responseDoc["JavaVersion"];
3790                            if (javaVersionValue != null && javaVersionValue.Type != JTokenType.Null)
3791                            {
3792                                string javaVersionInstance = ((string)javaVersionValue);
3793                                result.JavaVersion = javaVersionInstance;
3794                            }
3795                            
3796                            JToken javaContainerValue = responseDoc["JavaContainer"];
3797                            if (javaContainerValue != null && javaContainerValue.Type != JTokenType.Null)
3798                            {
3799                                string javaContainerInstance = ((string)javaContainerValue);
3800                                result.JavaContainer = javaContainerInstance;
3801                            }
3802                            
3803                            JToken javaContainerVersionValue = responseDoc["JavaContainerVersion"];
3804                            if (javaContainerVersionValue != null && javaContainerVersionValue.Type != JTokenType.Null)
3805                            {
3806                                string javaContainerVersionInstance = ((string)javaContainerVersionValue);
3807                                result.JavaContainerVersion = javaContainerVersionInstance;
3808                            }
3809                            
3810                            JToken autoSwapSlotNameValue = responseDoc["AutoSwapSlotName"];
3811                            if (autoSwapSlotNameValue != null && autoSwapSlotNameValue.Type != JTokenType.Null)
3812                            {
3813                                string autoSwapSlotNameInstance = ((string)autoSwapSlotNameValue);
3814                                result.AutoSwapSlotName = autoSwapSlotNameInstance;
3815                            }
3816                            
3817                            JToken siteAuthEnabledValue = responseDoc["SiteAuthEnabled"];
3818                            if (siteAuthEnabledValue != null && siteAuthEnabledValue.Type != JTokenType.Null)
3819                            {
3820                                bool siteAuthEnabledInstance = ((bool)siteAuthEnabledValue);
3821                                result.SiteAuthEnabled = siteAuthEnabledInstance;
3822                            }
3823                            
3824                            JToken siteAuthSettingsValue = responseDoc["SiteAuthSettings"];
3825                            if (siteAuthSettingsValue != null && siteAuthSettingsValue.Type != JTokenType.Null)
3826                            {
3827                                SiteAuthSettings siteAuthSettingsInstance = new SiteAuthSettings();
3828                                result.SiteAuthSettings = siteAuthSettingsInstance;
3829                                
3830                                JToken aADClientIdValue = siteAuthSettingsValue["AADClientId"];
3831                                if (aADClientIdValue != null && aADClientIdValue.Type != JTokenType.Null)
3832                                {
3833                                    string aADClientIdInstance = ((string)aADClientIdValue);
3834                                    siteAuthSettingsInstance.AADClientId = aADClientIdInstance;
3835                                }
3836                                
3837                                JToken openIdIssuerValue = siteAuthSettingsValue["OpenIdIssuer"];
3838                                if (openIdIssuerValue != null && openIdIssuerValue.Type != JTokenType.Null)
3839                                {
3840                                    string openIdIssuerInstance = ((string)openIdIssuerValue);
3841                                    siteAuthSettingsInstance.OpenIdIssuer = openIdIssuerInstance;
3842                                }
3843                            }
3844                            
3845                            JToken limitsValue = responseDoc["limits"];
3846                            if (limitsValue != null && limitsValue.Type != JTokenType.Null)
3847                            {
3848                                WebSiteGetConfigurationResponse.SiteLimits limitsInstance = new WebSiteGetConfigurationResponse.SiteLimits();
3849                                result.Limits = limitsInstance;
3850                                
3851                                JToken maxPercentageCpuValue = limitsValue["maxPercentageCpu"];
3852                                if (maxPercentageCpuValue != null && maxPercentageCpuValue.Type != JTokenType.Null)
3853                                {
3854                                    double maxPercentageCpuInstance = ((double)maxPercentageCpuValue);
3855                                    limitsInstance.MaxPercentageCpu = maxPercentageCpuInstance;
3856                                }
3857                                
3858                                JToken maxMemoryInMbValue = limitsValue["maxMemoryInMb"];
3859                                if (maxMemoryInMbValue != null && maxMemoryInMbValue.Type != JTokenType.Null)
3860                                {
3861                                    long maxMemoryInMbInstance = ((long)maxMemoryInMbValue);
3862                                    limitsInstance.MaxMemoryInMb = maxMemoryInMbInstance;
3863                                }
3864                                
3865                                JToken maxDiskSizeInMbValue = limitsValue["maxDiskSizeInMb"];
3866                                if (maxDiskSizeInMbValue != null && maxDiskSizeInMbValue.Type != JTokenType.Null)
3867                                {
3868                                    long maxDiskSizeInMbInstance = ((long)maxDiskSizeInMbValue);
3869                                    limitsInstance.MaxDiskSizeInMb = maxDiskSizeInMbInstance;
3870                                }
3871                            }
3872                        }
3873                        
3874                    }
3875                    result.StatusCode = statusCode;
3876                    if (httpResponse.Headers.Contains("x-ms-request-id"))
3877                    {
3878                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
3879                    }
3880                    
3881                    if (shouldTrace)
3882                    {
3883                        TracingAdapter.Exit(invocationId, result);
3884                    }
3885                    return result;
3886                }
3887                finally
3888                {
3889                    if (httpResponse != null)
3890                    {
3891                        httpResponse.Dispose();
3892                    }
3893                }
3894            }
3895            finally
3896            {
3897                if (httpRequest != null)
3898                {
3899                    httpRequest.Dispose();
3900                }
3901            }
3902        }
3903        
3904        /// <summary>
3905        /// You can retrieve historical usage metrics for a site by issuing an
3906        /// HTTP GET request.  (see
3907        /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166964.aspx
3908        /// for more information)
3909        /// </summary>
3910        /// <param name='webSpaceName'>
3911        /// Required. The name of the web space.
3912        /// </param>
3913        /// <param name='webSiteName'>
3914        /// Required. The name of the web site.
3915        /// </param>
3916        /// <param name='parameters'>
3917        /// Required. Parameters supplied to the Get Historical Usage Metrics
3918        /// Web Site operation.
3919        /// </param>
3920        /// <param name='cancellationToken'>
3921        /// Cancellation token.
3922        /// </param>
3923        /// <returns>
3924        /// The Get Historical Usage Metrics Web Site operation response.
3925        /// </returns>
3926        public async Task<WebSiteGetHistoricalUsageMetricsResponse> GetHistoricalUsageMetricsAsync(string webSpaceName, string webSiteName, WebSiteGetHistoricalUsageMetricsParameters parameters, CancellationToken cancellationToken)
3927        {
3928            // Validate
3929            if (webSpaceName == null)
3930            {
3931                throw new ArgumentNullException("webSpaceName");
3932            }
3933            if (webSiteName == null)
3934            {
3935                throw new ArgumentNullException("webSiteName");
3936            }
3937            if (parameters == null)
3938            {
3939                throw new ArgumentNullException("parameters");
3940            }
3941            
3942            // Tracing
3943            bool shouldTrace = TracingAdapter.IsEnabled;
3944            string invocationId = null;
3945            if (shouldTrace)
3946            {
3947                invocationId = TracingAdapter.NextInvocationId.ToString();
3948                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
3949                tracingParameters.Add("webSpaceName", webSpaceName);
3950                tracingParameters.Add("webSiteName", webSiteName);
3951                tracingParameters.Add("parameters", parameters);
3952                TracingAdapter.Enter(invocationId, this, "GetHistoricalUsageMetricsAsync", tracingParameters);
3953            }
3954            
3955            // Construct URL
3956            string url = "";
3957            url = url + "/";
3958            if (this.Client.Credentials.SubscriptionId != null)
3959            {
3960                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
3961            }
3962            url = url + "/services/WebSpaces/";
3963            url = url + Uri.EscapeDataString(webSpaceName);
3964            url = url + "/sites/";
3965            url = url + Uri.EscapeDataString(webSiteName);
3966            url = url + "/metrics";
3967            List<string> queryParameters = new List<string>();
3968            if (parameters.MetricNames != null && parameters.MetricNames.Count > 0)
3969            {
3970                queryParameters.Add("names=" + Uri.EscapeDataString(string.Join(",", parameters.MetricNames)));
3971            }
3972            if (parameters.StartTime != null)
3973            {
3974                queryParameters.Add("StartTime=" + Uri.EscapeDataString(string.Format(CultureInfo.InvariantCulture, "{0:O}", parameters.StartTime.Value.ToUniversalTime())));
3975            }
3976            if (parameters.EndTime != null)
3977            {
3978                queryParameters.Add("EndTime=" + Uri.EscapeDataString(string.Format(CultureInfo.InvariantCulture, "{0:O}", parameters.EndTime.Value.ToUniversalTime())));
3979            }
3980            if (parameters.TimeGrain != null)
3981            {
3982                queryParameters.Add("timeGrain=" + Uri.EscapeDataString(parameters.TimeGrain));
3983            }
3984            queryParameters.Add("details=" + Uri.EscapeDataString(parameters.IncludeInstanceBreakdown.ToString().ToLower()));
3985            queryParameters.Add("slotView=" + Uri.EscapeDataString(parameters.SlotView.ToString().ToLower()));
3986            if (queryParameters.Count > 0)
3987            {
3988                url = url + "?" + string.Join("&", queryParameters);
3989            }
3990            string baseUrl = this.Client.BaseUri.AbsoluteUri;
3991            // Trim '/' character from the end of baseUrl and beginning of url.
3992            if (baseUrl[baseUrl.Length - 1] == '/')
3993            {
3994                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
3995            }
3996            if (url[0] == '/')
3997            {
3998                url = url.Substring(1);
3999            }
4000            url = baseUrl + "/" + url;
4001            url = url.Replace(" ", "%20");
4002            
4003            // Create HTTP transport objects
4004            HttpRequestMessage httpRequest = null;
4005            try
4006            {
4007                httpRequest = new HttpRequestMessage();
4008                httpRequest.Method = HttpMethod.Get;
4009                httpRequest.RequestUri = new Uri(url);
4010                
4011                // Set Headers
4012                httpRequest.Headers.Add("x-ms-version", "2014-04-01");
4013                
4014                // Set Credentials
4015                cancellationToken.ThrowIfCancellationRequested();
4016                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
4017                
4018                // Send Request
4019                HttpResponseMessage httpResponse = null;
4020                try
4021                {
4022                    if (shouldTrace)
4023                    {
4024                        TracingAdapter.SendRequest(invocationId, httpRequest);
4025                    }
4026                    cancellationToken.ThrowIfCancellationRequested();
4027                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
4028                    if (shouldTrace)
4029                    {
4030                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
4031                    }
4032                    HttpStatusCode statusCode = httpResponse.StatusCode;
4033                    if (statusCode != HttpStatusCode.OK)
4034                    {
4035                        cancellationToken.ThrowIfCancellationRequested();
4036                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
4037                        if (shouldTrace)
4038                        {
4039                            TracingAdapter.Error(invocationId, ex);
4040                        }
4041                        throw ex;
4042                    }
4043                    
4044                    // Create Result
4045                    WebSiteGetHistoricalUsageMetricsResponse result = null;
4046                    // Deserialize Response
4047                    if (statusCode == HttpStatusCode.OK)
4048                    {
4049                        cancellationToken.ThrowIfCancellationRequested();
4050                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
4051                        result = new WebSiteGetHistoricalUsageMetricsResponse();
4052                        XDocument responseDoc = XDocument.Parse(responseContent);
4053                        
4054                        XElement metricResponsesElement = responseDoc.Element(XName.Get("MetricResponses", "http://schemas.microsoft.com/windowsazure"));
4055                        if (metricResponsesElement != null)
4056                        {
4057                            if (metricResponsesElement != null)
4058                            {
4059                                foreach (XElement usageMetricsElement in metricResponsesElement.Elements(XName.Get("MetricResponse", "http://schemas.microsoft.com/windowsazure")))
4060                                {
4061                                    HistoricalUsageMetric metricResponseInstance = new HistoricalUsageMetric();
4062                                    result.UsageMetrics.Add(metricResponseInstance);
4063                                    
4064                                    XElement codeElement = usageMetricsElement.Element(XName.Get("Code", "http://schemas.microsoft.com/windowsazure"));
4065                                    if (codeElement != null)
4066                                    {
4067                                        string codeInstance = codeElement.Value;
4068                                        metricResponseInstance.Code = codeInstance;
4069                                    }
4070                                    
4071                                    XElement dataElement = usageMetricsElement.Element(XName.Get("Data", "http://schemas.microsoft.com/windowsazure"));
4072                                    if (dataElement != null)
4073                                    {
4074                                        HistoricalUsageMetricData dataInstance = new HistoricalUsageMetricData();
4075                                        metricResponseInstance.Data = dataInstance;
4076                                        
4077                                        XElement displayNameElement = dataElement.Element(XName.Get("DisplayName", "http://schemas.microsoft.com/windowsazure"));
4078                                        if (displayNameElement != null)
4079                                        {
4080                                            string displayNameInstance = displayNameElement.Value;
4081                                            dataInstance.DisplayName = displayNameInstance;
4082                                        }
4083                                        
4084                                        XElement endTimeElement = dataElement.Element(XName.Get("EndTime", "http://schemas.microsoft.com/windowsazure"));
4085                                        if (endTimeElement != null)
4086                                        {
4087                                            DateTime endTimeInstance = DateTime.Parse(endTimeElement.Value, CultureInfo.InvariantCulture);
4088                                            dataInstance.EndTime = endTimeInstance;
4089                                        }
4090                                        
4091                                        XElement nameElement = dataElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
4092                                        if (nameElement != null)
4093                                        {
4094                                            string nameInstance = nameElement.Value;
4095                                            dataInstance.Name = nameInstance;
4096                                        }
4097                                        
4098                                        XElement primaryAggregationTypeElement = dataElement.Element(XName.Get("PrimaryAggregationType", "http://schemas.microsoft.com/windowsazure"));
4099                                        if (primaryAggregationTypeElement != null)
4100                                        {
4101                                            string primaryAggregationTypeInstance = primaryAggregationTypeElement.Value;
4102                                            dataInstance.PrimaryAggregationType = primaryAggregationTypeInstance;
4103                                        }
4104                                        
4105                                        XElement startTimeElement = dataElement.Element(XName.Get("StartTime", "http://schemas.microsoft.com/windowsazure"));
4106                                        if (startTimeElement != null)
4107                                        {
4108                                            DateTime startTimeInstance = DateTime.Parse(startTimeElement.Value, CultureInfo.InvariantCulture);
4109                                            dataInstance.StartTime = startTimeInstance;
4110                                        }
4111                                        
4112                                        XElement timeGrainElement = dataElement.Element(XName.Get("TimeGrain", "http://schemas.microsoft.com/windowsazure"));
4113                                        if (timeGrainElement != null)
4114                                        {
4115                                            string timeGrainInstance = timeGrainElement.Value;
4116                                            dataInstance.TimeGrain = timeGrainInstance;
4117                                        }
4118                                        
4119                                        XElement unitElement = dataElement.Element(XName.Get("Unit", "http://schemas.microsoft.com/windowsazure"));
4120                                        if (unitElement != null)
4121                                        {
4122                                            string unitInstance = unitElement.Value;
4123                                            dataInstance.Unit = unitInstance;
4124                                        }
4125                                        
4126                                        XElement valuesSequenceElement = dataElement.Element(XName.Get("Values", "http://schemas.microsoft.com/windowsazure"));
4127                                        if (valuesSequenceElement != null)
4128                                        {
4129                                            foreach (XElement valuesElement in valuesSequenceElement.Elements(XName.Get("MetricSample", "http://schemas.microsoft.com/windowsazure")))
4130                                            {
4131                                                HistoricalUsageMetricSample metricSampleInstance = new HistoricalUsageMetricSample();
4132                                                dataInstance.Values.Add(metricSampleInstance);
4133                                                
4134                                                XElement countElement = valuesElement.Element(XName.Get("Count", "http://schemas.microsoft.com/windowsazure"));
4135                                                if (countElement != null)
4136                                                {
4137                                                    int countInstance = int.Parse(countElement.Value, CultureInfo.InvariantCulture);
4138                                                    metricSampleInstance.Count = countInstance;
4139                                                }
4140                                                
4141                                                XElement maximumElement = valuesElement.Element(XName.Get("Maximum", "http://schemas.microsoft.com/windowsazure"));
4142                                                if (maximumElement != null)
4143                                                {
4144                                                    bool isNil = false;
4145                                                    XAttribute nilAttribute = maximumElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
4146                                                    if (nilAttribute != null)
4147                                                    {
4148                                                        isNil = nilAttribute.Value == "true";
4149                                                    }
4150                                                    if (isNil == false)
4151                                                    {
4152                                                        string maximumInstance = maximumElement.Value;
4153                                                        metricSampleInstance.Maximum = maximumInstance;
4154                                                    }
4155                                                }
4156                                                
4157                                                XElement minimumElement = valuesElement.Element(XName.Get("Minimum", "http://schemas.microsoft.com/windowsazure"));
4158                                                if (minimumElement != null)
4159                                                {
4160                                                    bool isNil2 = false;
4161                                                    XAttribute nilAttribute2 = minimumElement.Attribute(XName.Get("nil", "http://www.w3.org/2001/XMLSchema-instance"));
4162                                                    if (nilAttribute2 != null)
4163                                                    {
4164                                                        isNil2 = nilAttribute2.Value == "true";
4165                                                    }
4166                                                    if (isNil2 == false)
4167                                                    {
4168                                                        string minimumInstance = minimumElement.Value;
4169                                                        metricSampleInstance.Minimum = minimumInstance;
4170                                                    }
4171                                                }
4172                                                
4173                                                XElement timeCreatedElement = valuesElement.Element(XName.Get("TimeCreated", "http://schemas.microsoft.com/windowsazure"));
4174                                                if (timeCreatedElement != null)
4175                                                {
4176                                                    DateTime timeCreatedInstance = DateTime.Parse(timeCreatedElement.Value, CultureInfo.InvariantCulture);
4177                                                    metricSampleInstance.TimeCreated = timeCreatedInstance;
4178                                                }
4179                                                
4180                                                XElement totalElement = valuesElement.Element(XName.Get("Total", "http://schemas.microsoft.com/windowsazure"));
4181                                                if (totalElement != null)
4182                                                {
4183                                                    string totalInstance = totalElement.Value;
4184                                                    metricSampleInstance.Total = totalInstance;
4185                                                }
4186                                                
4187                                                XElement instanceNameElement = valuesElement.Element(XName.Get("InstanceName", "http://schemas.microsoft.com/windowsazure"));
4188                                                if (instanceNameElement != null)
4189                                                {
4190                                                    string instanceNameInstance = instanceNameElement.Value;
4191                                                    metricSampleInstance.InstanceName = instanceNameInstance;
4192                                                }
4193                                            }
4194                                        }
4195                                    }
4196                                    
4197                                    XElement messageElement = usageMetricsElement.Element(XName.Get("Message", "http://schemas.microsoft.com/windowsazure"));
4198                                    if (messageElement != null)
4199                                    {
4200                                        string messageInstance = messageElement.Value;
4201                                        metricResponseInstance.Message = messageInstance;
4202                                    }
4203                                }
4204                            }
4205                        }
4206                        
4207                    }
4208                    result.StatusCode = statusCode;
4209                    if (httpResponse.Headers.Contains("x-ms-request-id"))
4210                    {
4211                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
4212                    }
4213                    
4214                    if (shouldTrace)
4215                    {
4216                        TracingAdapter.Exit(invocationId, result);
4217                    }
4218                    return result;
4219                }
4220                finally
4221                {
4222                    if (httpResponse != null)
4223                    {
4224                        httpResponse.Dispose();
4225                    }
4226                }
4227            }
4228            finally
4229            {
4230                if (httpRequest != null)
4231                {
4232                    httpRequest.Dispose();
4233                }
4234            }
4235        }
4236        
4237        /// <summary>
4238        /// Retrieves a particular hybrid connection that belongs to a specific
4239        /// site.
4240        /// </summary>
4241        /// <param name='webSpaceName'>
4242        /// Required. The name of the web space.
4243        /// </param>
4244        /// <param name='webSiteName'>
4245        /// Required. The name of the web site.
4246        /// </param>
4247        /// <param name='hybridConnectionName'>
4248        /// Required. The name of the hybrid connection entity
4249        /// </param>
4250        /// <param name='cancellationToken'>
4251        /// Cancellation token.
4252        /// </param>
4253        /// <returns>
4254        /// The Get Hybrid Connection operation response.
4255        /// </returns>
4256        public async Task<HybridConnectionGetResponse> GetHybridConnectionAsync(string webSpaceName, string webSiteName, string hybridConnectionName, CancellationToken cancellationToken)
4257        {
4258            // Validate
4259            if (webSpaceName == null)
4260            {
4261                throw new ArgumentNullException("webSpaceName");
4262            }
4263            if (webSiteName == null)
4264            {
4265                throw new ArgumentNullException("webSiteName");
4266            }
4267            if (hybridConnectionName == null)
4268            {
4269                throw new ArgumentNullException("hybridConnectionName");
4270            }
4271            
4272            // Tracing
4273            bool shouldTrace = TracingAdapter.IsEnabled;
4274            string invocationId = null;
4275            if (shouldTrace)
4276            {
4277                invocationId = TracingAdapter.NextInvocationId.ToString();
4278                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
4279                tracingParameters.Add("webSpaceName", webSpaceName);
4280                tracingParameters.Add("webSiteName", webSiteName);
4281                tracingParameters.Add("hybridConnectionName", hybridConnectionName);
4282                TracingAdapter.Enter(invocationId, this, "GetHybridConnectionAsync", tracingParameters);
4283            }
4284            
4285            // Construct URL
4286            string url = "";
4287            url = url + "/";
4288            if (this.Client.Credentials.SubscriptionId != null)
4289            {
4290                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
4291            }
4292            url = url + "/services/WebSpaces/";
4293            url = url + Uri.EscapeDataString(webSpaceName);
4294            url = url + "/sites/";
4295            url = url + Uri.EscapeDataString(webSiteName);
4296            url = url + "/hybridconnection/";
4297            url = url + Uri.EscapeDataString(hybridConnectionName);
4298            string baseUrl = this.Client.BaseUri.AbsoluteUri;
4299            // Trim '/' character from the end of baseUrl and beginning of url.
4300            if (baseUrl[baseUrl.Length - 1] == '/')
4301            {
4302                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
4303            }
4304            if (url[0] == '/')
4305            {
4306                url = url.Substring(1);
4307            }
4308            url = baseUrl + "/" + url;
4309            url = url.Replace(" ", "%20");
4310            
4311            // Create HTTP transport objects
4312            HttpRequestMessage httpRequest = null;
4313            try
4314            {
4315                httpRequest = new HttpRequestMessage();
4316                httpRequest.Method = HttpMethod.Get;
4317                httpRequest.RequestUri = new Uri(url);
4318                
4319                // Set Headers
4320                httpRequest.Headers.Add("x-ms-version", "2014-04-01");
4321                
4322                // Set Credentials
4323                cancellationToken.ThrowIfCancellationRequested();
4324                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
4325                
4326                // Send Request
4327                HttpResponseMessage httpResponse = null;
4328                try
4329                {
4330                    if (shouldTrace)
4331                    {
4332                        TracingAdapter.SendRequest(invocationId, httpRequest);
4333                    }
4334                    cancellationToken.ThrowIfCancellationRequested();
4335                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
4336                    if (shouldTrace)
4337                    {
4338                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
4339                    }
4340                    HttpStatusCode statusCode = httpResponse.StatusCode;
4341                    if (statusCode != HttpStatusCode.OK)
4342                    {
4343                        cancellationToken.ThrowIfCancellationRequested();
4344                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
4345                        if (shouldTrace)
4346                        {
4347                            TracingAdapter.Error(invocationId, ex);
4348                        }
4349                        throw ex;
4350                    }
4351                    
4352                    // Create Result
4353                    HybridConnectionGetResponse result = null;
4354                    // Deserialize Response
4355                    if (statusCode == HttpStatusCode.OK)
4356                    {
4357                        cancellationToken.ThrowIfCancellationRequested();
4358                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
4359                        result = new HybridConnectionGetResponse();
4360                        XDocument responseDoc = XDocument.Parse(responseContent);
4361                        
4362                        XElement relayServiceConnectionEntityElement = responseDoc.Element(XName.Get("RelayServiceConnectionEntity", "http://schemas.microsoft.com/windowsazure"));
4363                        if (relayServiceConnectionEntityElement != null)
4364                        {
4365                            HybridConnection hybridConnectionInstance = new HybridConnection();
4366                            result.HybridConnection = hybridConnectionInstance;
4367                            
4368                            XElement entityNameElement = relayServiceConnectionEntityElement.Element(XName.Get("EntityName", "http://schemas.microsoft.com/windowsazure"));
4369                            if (entityNameElement != null)
4370                            {
4371                                string entityNameInstance = entityNameElement.Value;
4372                                hybridConnectionInstance.EntityName = entityNameInstance;
4373                            }
4374                            
4375                            XElement entityConnectionStringElement = relayServiceConnectionEntityElement.Element(XName.Get("EntityConnectionString", "http://schemas.microsoft.com/windowsazure"));
4376                            if (entityConnectionStringElement != null)
4377                            {
4378                                string entityConnectionStringInstance = entityConnectionStringElement.Value;
4379                                hybridConnectionInstance.EntityConnectionString = entityConnectionStringInstance;
4380                            }
4381                            
4382                            XElement resourceTypeElement = relayServiceConnectionEntityElement.Element(XName.Get("ResourceType", "http://schemas.microsoft.com/windowsazure"));
4383                            if (resourceTypeElement != null)
4384                            {
4385                                string resourceTypeInstance = resourceTypeElement.Value;
4386                                hybridConnectionInstance.ResourceType = resourceTypeInstance;
4387                            }
4388                            
4389                            XElement resourceConnectionStringElement = relayServiceConnectionEntityElement.Element(XName.Get("ResourceConnectionString", "http://schemas.microsoft.com/windowsazure"));
4390                            if (resourceConnectionStringElement != null)
4391                            {
4392                                string resourceConnectionStringInstance = resourceConnectionStringElement.Value;
4393                                hybridConnectionInstance.ResourceConnectionString = resourceConnectionStringInstance;
4394                            }
4395                            
4396                            XElement hostnameElement = relayServiceConnectionEntityElement.Element(XName.Get("Hostname", "http://schemas.microsoft.com/windowsazure"));
4397                            if (hostnameElement != null)
4398                            {
4399                                string hostnameInstance = hostnameElement.Value;
4400                                hybridConnectionInstance.Hostname = hostnameInstance;
4401                            }
4402                            
4403                            XElement portElement = relayServiceConnectionEntityElement.Element(XName.Get("Port", "http://schemas.microsoft.com/windowsazure"));
4404                            if (portElement != null)
4405                            {
4406                                int portInstance = int.Parse(portElement.Value, CultureInfo.InvariantCulture);
4407                                hybridConnectionInstance.Port = portInstance;
4408                            }
4409                            
4410                            XElement biztalkUriElement = relayServiceConnectionEntityElement.Element(XName.Get("BiztalkUri", "http://schemas.microsoft.com/windowsazure"));
4411                            if (biztalkUriElement != null)
4412                            {
4413                                string biztalkUriInstance = biztalkUriElement.Value;
4414                                hybridConnectionInstance.BiztalkUri = biztalkUriInstance;
4415                            }
4416                        }
4417                        
4418                    }
4419                    result.StatusCode = statusCode;
4420                    if (httpResponse.Headers.Contains("x-ms-request-id"))
4421                    {
4422                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
4423                    }
4424                    
4425                    if (shouldTrace)
4426                    {
4427                        TracingAdapter.Exit(invocationId, result);
4428                    }
4429                    return result;
4430                }
4431                finally
4432                {
4433                    if (httpResponse != null)
4434                    {
4435                        httpResponse.Dispose();
4436                    }
4437                }
4438            }
4439            finally
4440            {
4441                if (httpRequest != null)
4442                {
4443                    httpRequest.Dispose();
4444                }
4445            }
4446        }
4447        
4448        /// <summary>
4449        /// You can retrieve the list of active instances by ids for a web site
4450        /// by issuing an HTTP GET request.  (see
4451        /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166981.aspx
4452        /// for more information)
4453        /// </summary>
4454        /// <param name='webSpaceName'>
4455        /// Required. The name of the web space.
4456        /// </param>
4457        /// <param name='webSiteName'>
4458        /// Required. The name of the web site.
4459        /// </param>
4460        /// <param name='cancellationToken'>
4461        /// Cancellation token.
4462        /// </param>
4463        /// <returns>
4464        /// The web site instance ids response.
4465        /// </returns>
4466        public async Task<WebSiteInstanceIdsResponse> GetInstanceIdsAsync(string webSpaceName, string webSiteName, CancellationToken cancellationToken)
4467        {
4468            // Validate
4469            if (webSpaceName == null)
4470            {
4471                throw new ArgumentNullException("webSpaceName");
4472            }
4473            if (webSiteName == null)
4474            {
4475                throw new ArgumentNullException("webSiteName");
4476            }
4477            
4478            // Tracing
4479            bool shouldTrace = TracingAdapter.IsEnabled;
4480            string invocationId = null;
4481            if (shouldTrace)
4482            {
4483                invocationId = TracingAdapter.NextInvocationId.ToString();
4484                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
4485                tracingParameters.Add("webSpaceName", webSpaceName);
4486                tracingParameters.Add("webSiteName", webSiteName);
4487                TracingAdapter.Enter(invocationId, this, "GetInstanceIdsAsync", tracingParameters);
4488            }
4489            
4490            // Construct URL
4491            string url = "";
4492            url = url + "/";
4493            if (this.Client.Credentials.SubscriptionId != null)
4494            {
4495                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
4496            }
4497            url = url + "/services/WebSpaces/";
4498            url = url + Uri.EscapeDataString(webSpaceName);
4499            url = url + "/sites/";
4500            url = url + Uri.EscapeDataString(webSiteName);
4501            url = url + "/instanceids";
4502            string baseUrl = this.Client.BaseUri.AbsoluteUri;
4503            // Trim '/' character from the end of baseUrl and beginning of url.
4504            if (baseUrl[baseUrl.Length - 1] == '/')
4505            {
4506                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
4507            }
4508            if (url[0] == '/')
4509            {
4510                url = url.Substring(1);
4511            }
4512            url = baseUrl + "/" + url;
4513            url = url.Replace(" ", "%20");
4514            
4515            // Create HTTP transport objects
4516            HttpRequestMessage httpRequest = null;
4517            try
4518            {
4519                httpRequest = new HttpRequestMessage();
4520                httpRequest.Method = HttpMethod.Get;
4521                httpRequest.RequestUri = new Uri(url);
4522                
4523                // Set Headers
4524                httpRequest.Headers.Add("x-ms-version", "2014-04-01");
4525                
4526                // Set Credentials
4527                cancellationToken.ThrowIfCancellationRequested();
4528                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
4529                
4530                // Send Request
4531                HttpResponseMessage httpResponse = null;
4532                try
4533                {
4534                    if (shouldTrace)
4535                    {
4536                        TracingAdapter.SendRequest(invocationId, httpRequest);
4537                    }
4538                    cancellationToken.ThrowIfCancellationRequested();
4539                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
4540                    if (shouldTrace)
4541                    {
4542                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
4543                    }
4544                    HttpStatusCode statusCode = httpResponse.StatusCode;
4545                    if (statusCode != HttpStatusCode.OK)
4546                    {
4547                        cancellationToken.ThrowIfCancellationRequested();
4548                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
4549                        if (shouldTrace)
4550                        {
4551                            TracingAdapter.Error(invocationId, ex);
4552                        }
4553                        throw ex;
4554                    }
4555                    
4556                    // Create Result
4557                    WebSiteInstanceIdsResponse result = null;
4558                    // Deserialize Response
4559                    if (statusCode == HttpStatusCode.OK)
4560                    {
4561                        cancellationToken.ThrowIfCancellationRequested();
4562                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
4563                        result = new WebSiteInstanceIdsResponse();
4564                        XDocument responseDoc = XDocument.Parse(responseContent);
4565                        
4566                        XElement arrayOfstringSequenceElement = responseDoc.Element(XName.Get("ArrayOfstring", "http://schemas.microsoft.com/2003/10/Serialization/Arrays"));
4567                        if (arrayOfstringSequenceElement != null)
4568                        {
4569                            foreach (XElement arrayOfstringElement in arrayOfstringSequenceElement.Elements(XName.Get("string", "http://schemas.microsoft.com/2003/10/Serialization/Arrays")))
4570                            {
4571                                result.InstanceIds.Add(arrayOfstringElement.Value);
4572                            }
4573                        }
4574                        
4575                    }
4576                    result.StatusCode = statusCode;
4577                    if (httpResponse.Headers.Contains("x-ms-request-id"))
4578                    {
4579                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
4580                    }
4581                    
4582                    if (shouldTrace)
4583                    {
4584                        TracingAdapter.Exit(invocationId, result);
4585                    }
4586                    return result;
4587                }
4588                finally
4589                {
4590                    if (httpResponse != null)
4591                    {
4592                        httpResponse.Dispose();
4593                    }
4594                }
4595            }
4596            finally
4597            {
4598                if (httpRequest != null)
4599                {
4600                    httpRequest.Dispose();
4601                }
4602            }
4603        }
4604        
4605        /// <summary>
4606        /// You can retrieve the publish settings information for a web site by
4607        /// issuing an HTTP GET request.  (see
4608        /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166996.aspx
4609        /// for more information)
4610        /// </summary>
4611        /// <param name='webSpaceName'>
4612        /// Required. The name of the web space.
4613        /// </param>
4614        /// <param name='webSiteName'>
4615        /// Required. The name of the web site.
4616        /// </param>
4617        /// <param name='cancellationToken'>
4618        /// Cancellation token.
4619        /// </param>
4620        /// <returns>
4621        /// The Get Publish Profile Web Site operation response.
4622        /// </returns>
4623        public async Task<WebSiteGetPublishProfileResponse> GetPublishProfileAsync(string webSpaceName, string webSiteName, CancellationToken cancellationToken)
4624        {
4625            // Validate
4626            if (webSpaceName == null)
4627            {
4628                throw new ArgumentNullException("webSpaceName");
4629            }
4630            if (webSiteName == null)
4631            {
4632                throw new ArgumentNullException("webSiteName");
4633            }
4634            
4635            // Tracing
4636            bool shouldTrace = TracingAdapter.IsEnabled;
4637            string invocationId = null;
4638            if (shouldTrace)
4639            {
4640                invocationId = TracingAdapter.NextInvocationId.ToString();
4641                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
4642                tracingParameters.Add("webSpaceName", webSpaceName);
4643                tracingParameters.Add("webSiteName", webSiteName);
4644                TracingAdapter.Enter(invocationId, this, "GetPublishProfileAsync", tracingParameters);
4645            }
4646            
4647            // Construct URL
4648            string url = "";
4649            url = url + "/";
4650            if (this.Client.Credentials.SubscriptionId != null)
4651            {
4652                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
4653            }
4654            url = url + "/services/WebSpaces/";
4655            url = url + Uri.EscapeDataString(webSpaceName);
4656            url = url + "/sites/";
4657            url = url + Uri.EscapeDataString(webSiteName);
4658            url = url + "/publishxml";
4659            string baseUrl = this.Client.BaseUri.AbsoluteUri;
4660            // Trim '/' character from the end of baseUrl and beginning of url.
4661            if (baseUrl[baseUrl.Length - 1] == '/')
4662            {
4663                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
4664            }
4665            if (url[0] == '/')
4666            {
4667                url = url.Substring(1);
4668            }
4669            url = baseUrl + "/" + url;
4670            url = url.Replace(" ", "%20");
4671            
4672            // Create HTTP transport objects
4673            HttpRequestMessage httpRequest = null;
4674            try
4675            {
4676                httpRequest = new HttpRequestMessage();
4677                httpRequest.Method = HttpMethod.Get;
4678                httpRequest.RequestUri = new Uri(url);
4679                
4680                // Set Headers
4681                httpRequest.Headers.Add("x-ms-version", "2014-04-01");
4682                
4683                // Set Credentials
4684                cancellationToken.ThrowIfCancellationRequested();
4685                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
4686                
4687                // Send Request
4688                HttpResponseMessage httpResponse = null;
4689                try
4690                {
4691                    if (shouldTrace)
4692                    {
4693                        TracingAdapter.SendRequest(invocationId, httpRequest);
4694                    }
4695                    cancellationToken.ThrowIfCancellationRequested();
4696                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
4697                    if (shouldTrace)
4698                    {
4699                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
4700                    }
4701                    HttpStatusCode statusCode = httpResponse.StatusCode;
4702                    if (statusCode != HttpStatusCode.OK)
4703                    {
4704                        cancellationToken.ThrowIfCancellationRequested();
4705                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
4706                        if (shouldTrace)
4707                        {
4708                            TracingAdapter.Error(invocationId, ex);
4709                        }
4710                        throw ex;
4711                    }
4712                    
4713                    // Create Result
4714                    WebSiteGetPublishProfileResponse result = null;
4715                    // Deserialize Response
4716                    if (statusCode == HttpStatusCode.OK)
4717                    {
4718                        cancellationToken.ThrowIfCancellationRequested();
4719                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
4720                        result = new WebSiteGetPublishProfileResponse();
4721                        XDocument responseDoc = XDocument.Parse(responseContent);
4722                        
4723                        XElement publishDataElement = responseDoc.Element(XName.Get("publishData", ""));
4724                        if (publishDataElement != null)
4725                        {
4726                            if (publishDataElement != null)
4727                            {
4728                                foreach (XElement publishProfilesElement in publishDataElement.Elements(XName.Get("publishProfile", "")))
4729                                {
4730                                    WebSiteGetPublishProfileResponse.PublishProfile publishProfileInstance = new WebSiteGetPublishProfileResponse.PublishProfile();
4731                                    result.PublishProfiles.Add(publishProfileInstance);
4732                                    
4733                                    XAttribute profileNameAttribute = publishProfilesElement.Attribute(XName.Get("profileName", ""));
4734                                    if (profileNameAttribute != null)
4735                                    {
4736                                        publishProfileInstance.ProfileName = profileNameAttribute.Value;
4737                                    }
4738                                    
4739                                    XAttribute publishMethodAttribute = publishProfilesElement.Attribute(XName.Get("publishMethod", ""));
4740                                    if (publishMethodAttribute != null)
4741                                    {
4742                                        publishProfileInstance.PublishMethod = publishMethodAttribute.Value;
4743                                    }
4744                                    
4745                                    XAttribute publishUrlAttribute = publishProfilesElement.Attribute(XName.Get("publishUrl", ""));
4746                                    if (publishUrlAttribute != null)
4747                                    {
4748                                        publishProfileInstance.PublishUrl = publishUrlAttribute.Value;
4749                                    }
4750                                    
4751                                    XAttribute msdeploySiteAttribute = publishProfilesElement.Attribute(XName.Get("msdeploySite", ""));
4752                                    if (msdeploySiteAttribute != null)
4753                                    {
4754                                        publishProfileInstance.MSDeploySite = msdeploySiteAttribute.Value;
4755                                    }
4756                                    
4757                                    XAttribute ftpPassiveModeAttribute = publishProfilesElement.Attribute(XName.Get("ftpPassiveMode", ""));
4758                                    if (ftpPassiveModeAttribute != null)
4759                                    {
4760                                        publishProfileInstance.FtpPassiveMode = bool.Parse(ftpPassiveModeAttribute.Value);
4761                                    }
4762                                    
4763                                    XAttribute userNameAttribute = publishProfilesElement.Attribute(XName.Get("userName", ""));
4764                                    if (userNameAttribute != null)
4765                                    {
4766                                        publishProfileInstance.UserName = userNameAttribute.Value;
4767                                    }
4768                                    
4769                                    XAttribute userPWDAttribute = publishProfilesElement.Attribute(XName.Get("userPWD", ""));
4770                                    if (userPWDAttribute != null)
4771                                    {
4772                                        publishProfileInstance.UserPassword = userPWDAttribute.Value;
4773                                    }
4774                                    
4775                                    XAttribute destinationAppUrlAttribute = publishProfilesElement.Attribute(XName.Get("destinationAppUrl", ""));
4776                                    if (destinationAppUrlAttribute != null)
4777                                    {
4778                                        publishProfileInstance.DestinationAppUri = TypeConversion.TryParseUri(destinationAppUrlAttribute.Value);
4779                                    }
4780                                    
4781                                    XAttribute sQLServerDBConnectionStringAttribute = publishProfilesElement.Attribute(XName.Get("SQLServerDBConnectionString", ""));
4782                                    if (sQLServerDBConnectionStringAttribute != null)
4783                                    {
4784                                        publishProfileInstance.SqlServerConnectionString = sQLServerDBConnectionStringAttribute.Value;
4785                                    }
4786                                    
4787                                    XAttribute mySQLDBConnectionStringAttribute = publishProfilesElement.Attribute(XName.Get("mySQLDBConnectionString", ""));
4788                                    if (mySQLDBConnectionStringAttribute != null)
4789                                    {
4790                                        publishProfileInstance.MySqlConnectionString = mySQLDBConnectionStringAttribute.Value;
4791                                    }
4792                                    
4793                                    XAttribute hostingProviderForumLinkAttribute = publishProfilesElement.Attribute(XName.Get("hostingProviderForumLink", ""));
4794                                    if (hostingProviderForumLinkAttribute != null)
4795                                    {
4796                                        publishProfileInstance.HostingProviderForumUri = TypeConversion.TryParseUri(hostingProviderForumLinkAttribute.Value);
4797                                    }
4798                                    
4799                                    XAttribute controlPanelLinkAttribute = publishProfilesElement.Attribute(XName.Get("controlPanelLink", ""));
4800                                    if (controlPanelLinkAttribute != null)
4801                                    {
4802                                        publishProfileInstance.ControlPanelUri = TypeConversion.TryParseUri(controlPanelLinkAttribute.Value);
4803                                    }
4804                                    
4805                                    XElement databasesSequenceElement = publishProfilesElement.Element(XName.Get("databases", ""));
4806                                    if (databasesSequenceElement != null)
4807                                    {
4808                                        foreach (XElement databasesElement in databasesSequenceElement.Elements(XName.Get("add", "")))
4809                                        {
4810                                            WebSiteGetPublishProfileResponse.Database addInstance = new WebSiteGetPublishProfileResponse.Database();
4811                                            publishProfileInstance.Databases.Add(addInstance);
4812                                            
4813                                            XAttribute nameAttribute = databasesElement.Attribute(XName.Get("name", ""));
4814                                            if (nameAttribute != null)
4815                                            {
4816                                                addInstance.Name = nameAttribute.Value;
4817                                            }
4818                                            
4819                                            XAttribute connectionStringAttribute = databasesElement.Attribute(XName.Get("connectionString", ""));
4820                                            if (connectionStringAttribute != null)
4821                                            {
4822                                                addInstance.ConnectionString = connectionStringAttribute.Value;
4823                                            }
4824                                            
4825                                            XAttribute providerNameAttribute = databasesElement.Attribute(XName.Get("providerName", ""));
4826                                            if (providerNameAttribute != null)
4827                                            {
4828                                                addInstance.ProviderName = providerNameAttribute.Value;
4829                                            }
4830                                            
4831                                            XAttribute typeAttribute = databasesElement.Attribute(XName.Get("type", ""));
4832                                            if (typeAttribute != null)
4833                                            {
4834                                                addInstance.Type = typeAttribute.Value;
4835                                            }
4836                                        }
4837                                    }
4838                                }
4839                            }
4840                        }
4841                        
4842                    }
4843                    result.StatusCode = statusCode;
4844                    if (httpResponse.Headers.Contains("x-ms-request-id"))
4845                    {
4846                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
4847                    }
4848                    
4849                    if (shouldTrace)
4850                    {
4851                        TracingAdapter.Exit(invocationId, result);
4852                    }
4853                    return result;
4854                }
4855                finally
4856                {
4857                    if (httpResponse != null)
4858                    {
4859                        httpResponse.Dispose();
4860                    }
4861                }
4862            }
4863            finally
4864            {
4865                if (httpRequest != null)
4866                {
4867                    httpRequest.Dispose();
4868                }
4869            }
4870        }
4871        
4872        /// <summary>
4873        /// A web site repository is essentially a Git repository that you can
4874        /// use to manage your web site content. By using Git source control
4875        /// tools, you can push or pull version-controlled changes to your
4876        /// site. This API executes a repository get operation.  (see
4877        /// http://msdn.microsoft.com/en-us/library/windowsazure/dn166967.aspx
4878        /// for more information)
4879        /// </summary>
4880        /// <param name='webSpaceName'>
4881        /// Required. The name of the web space.
4882        /// </param>
4883        /// <param name='webSiteName'>
4884        /// Required. The name of the web site.
4885        /// </param>
4886        /// <param name='cancellationToken'>
4887        /// Cancellation token.
4888        /// </param>
4889        /// <returns>
4890        /// The Get Repository Web Site operation response.
4891        /// </returns>
4892        public async Task<WebSiteGetRepositoryResponse> GetRepositoryAsync(string webSpaceName, string webSiteName, CancellationToken cancellationToken)
4893        {
4894            // Validate
4895            if (webSpaceName == null)
4896            {
4897                throw new ArgumentNullException("webSpaceName");
4898            }
4899            if (webSiteName == null)
4900            {
4901                throw new ArgumentNullException("webSiteName");
4902            }
4903            
4904            // Tracing
4905            bool shouldTrace = TracingAdapter.IsEnabled;
4906            string invocationId = null;
4907            if (shouldTrace)
4908            {
4909                invocationId = TracingAdapter.NextInvocationId.ToString();
4910                Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
4911                tracingParameters.Add("webSpaceName", webSpaceName);
4912                tracingParameters.Add("webSiteName", webSiteName);
4913                TracingAdapter.Enter(invocationId, this, "GetRepositoryAsync", tracingParameters);
4914            }
4915            
4916            // Construct URL
4917            string url = "";
4918            url = url + "/";
4919            if (this.Client.Credentials.SubscriptionId != null)
4920            {
4921                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
4922            }
4923            url = url + "/services/WebSpaces/";
4924            url = url + Uri.EscapeDataString(webSpaceName);
4925            url = url + "/sites/";
4926            url = url + Uri.EscapeDataString(webSiteName);
4927            url = url + "/repository";
4928            string baseUrl = this.Client.BaseUri.AbsoluteUri;
4929            // Trim '/' character from the end of baseUrl and beginning of url.
4930            if (baseUrl[baseUrl.Length - 1] == '/')
4931            {
4932                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
4933            }
4934            if (url[0] == '/')
4935            {
4936                url = url.Substring(1);
4937            }
4938            url = baseUrl + "/" + url;
4939            url = url.Replace(" ", "%20");
4940            
4941            // Create HTTP transport objects
4942            HttpRequestMessage httpRequest = null;
4943            try
4944            {
4945                httpRequest = new HttpRequestMessage();
4946                httpRequest.Method = HttpMethod.Get;
4947                httpRequest.RequestUri = new Uri(url);
4948                
4949                // Set Headers
4950                httpRequest.Headers.Add("x-ms-version", "2014-04-01");
4951                
4952                // Set Credentials
4953                cancellationToken.ThrowIfCancellationRequested();
4954                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
4955                
4956                // Send Request
4957                HttpResponseMessage httpResponse = null;
4958                try
4959                {
4960                    if (shouldTrace)
4961                    {
4962                        TracingAdapter.SendRequest(invocationId, httpRequest);
4963                    }
4964                    cancellationToken.ThrowIfCancellationRequested();
4965                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
4966                    if (shouldTrace)
4967                    {
4968                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
4969                    }
4970                    HttpStatusCode statusCode = httpResponse.StatusCode;
4971                    if (statusCode != HttpStatusCode.OK)
4972                    {
4973                        cancellationToken.ThrowIfCancellationRequested();
4974                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content