PageRenderTime 7ms CodeModel.GetById 55ms app.highlight 34ms RepoModel.GetById 1ms app.codeStats 6ms

/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

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

  1// 
  2// Copyright (c) Microsoft and contributors.  All rights reserved.
  3// 
  4// Licensed under the Apache License, Version 2.0 (the "License");
  5// you may not use this file except in compliance with the License.
  6// You may obtain a copy of the License at
  7//   http://www.apache.org/licenses/LICENSE-2.0
  8// 
  9// Unless required by applicable law or agreed to in writing, software
 10// distributed under the License is distributed on an "AS IS" BASIS,
 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12// 
 13// See the License for the specific language governing permissions and
 14// limitations under the License.
 15// 
 16
 17// Warning: This code was generated by a tool.
 18// 
 19// Changes to this file may cause incorrect behavior and will be lost if the
 20// code is regenerated.
 21
 22using System;
 23using System.Collections.Generic;
 24using System.Globalization;
 25using System.Linq;
 26using System.Net;
 27using System.Net.Http;
 28using System.Net.Http.Headers;
 29using System.Text;
 30using System.Threading;
 31using System.Threading.Tasks;
 32using System.Xml.Linq;
 33using Hyak.Common;
 34using Hyak.Common.Internals;
 35using Microsoft.Azure;
 36using Microsoft.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.Attribut

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