/// <summary>
        /// Queries by name.
        /// </summary>
        private void GetByName()
        {
            ProtectionContainerListResponse protectionContainerListResponse =
                RecoveryServicesClient.GetAzureSiteRecoveryProtectionContainer();

            bool found = false;

            foreach (
                ProtectionContainer protectionContainer in
                protectionContainerListResponse.ProtectionContainers)
            {
                if (0 == string.Compare(this.Name, protectionContainer.Name, true))
                {
                    this.WriteProtectionContainer(protectionContainer);
                    found = true;
                }
            }

            if (!found)
            {
                throw new InvalidOperationException(
                          string.Format(
                              Properties.Resources.ProtectionContainerNotFound,
                              this.Name,
                              PSRecoveryServicesClient.asrVaultCreds.ResourceName));
            }
        }
Пример #2
0
        public void ListContainersTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"];

                var client = GetServiceClient <RecoveryServicesBackupManagementClient>(resourceNamespace);

                ProtectionContainerListQueryParams queryParams = new ProtectionContainerListQueryParams();
                queryParams.BackupManagementType = CommonTestHelper.GetSetting(TestConstants.ProviderTypeAzureIaasVM);

                ContainerTestHelper             containerTestHelper = new ContainerTestHelper(client);
                ProtectionContainerListResponse response            = containerTestHelper.ListContainers(queryParams);

                string containerName = ConfigurationManager.AppSettings["RsVaultIaasV1ContainerUniqueName"];;
                Assert.True(
                    response.ItemList.ProtectionContainers.Any(
                        protectionContainer =>
                {
                    return(protectionContainer.Properties.GetType().IsSubclassOf(typeof(AzureIaaSVMProtectionContainer)) &&
                           protectionContainer.Name.Contains(containerName));
                }),
                    "Retrieved list of containers doesn't contain AzureIaaSClassicComputeVMProtectionContainer test container");
            }
        }
        /// <summary>
        /// Queries all, by default.
        /// </summary>
        private void GetByDefault()
        {
            ProtectionContainerListResponse protectionContainerListResponse =
                RecoveryServicesClient.GetAzureSiteRecoveryProtectionContainer();

            this.WriteProtectionContainers(protectionContainerListResponse.ProtectionContainers);
        }
        public ProtectionContainerListResponse ListContainers(string rsVaultRgName, string rsVaultName, ProtectionContainerListQueryParams queryParams)
        {
            ProtectionContainerListResponse response = Client.Containers.List(rsVaultRgName, rsVaultName, queryParams, CommonTestHelper.GetCustomRequestHeaders());

            Assert.NotNull(response);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.NotNull(response.ItemList);
            return(response);
        }
Пример #5
0
        public void ListContainersTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"];
                string resourceGroupName = ConfigurationManager.AppSettings["RsVaultRgNameRP"];
                string resourceName      = ConfigurationManager.AppSettings["RsVaultNameRP"];
                string location          = ConfigurationManager.AppSettings["vaultLocationRP"];
                // TODO: Create VM instead of taking these parameters from config
                string containerUniqueName = ConfigurationManager.AppSettings["RsVaultIaasVMContainerUniqueNameRP"];
                string itemUniqueName      = ConfigurationManager.AppSettings["RsVaultIaasVMItemUniqueNameRP"];
                string containeType        = ConfigurationManager.AppSettings["IaaSVMContainerType"];
                string itemType            = ConfigurationManager.AppSettings["IaaSVMItemType"];
                string containerUri        = containeType + ";" + containerUniqueName;
                string itemUri             = itemType + ";" + itemUniqueName;

                var client = GetServiceClient <RecoveryServicesBackupManagementClient>(resourceNamespace);

                // 1. Create vault
                VaultTestHelpers vaultTestHelper = new VaultTestHelpers(client);
                vaultTestHelper.CreateVault(resourceGroupName, resourceName, location);

                // 2. Get default policy
                PolicyTestHelpers policyTestHelper = new PolicyTestHelpers(client);
                string            policyId         = policyTestHelper.GetDefaultPolicyId(resourceGroupName, resourceName);

                // 3. Enable protection
                ProtectedItemTestHelpers protectedItemTestHelper = new ProtectedItemTestHelpers(client);
                protectedItemTestHelper.EnableProtection(resourceGroupName, resourceName, policyId, containerUri, itemUri);

                // ACTION: List containers
                ProtectionContainerListQueryParams queryParams = new ProtectionContainerListQueryParams();
                queryParams.BackupManagementType = CommonTestHelper.GetSetting(TestConstants.ProviderTypeAzureIaasVM);
                ContainerTestHelper             containerTestHelper = new ContainerTestHelper(client);
                ProtectionContainerListResponse response            = containerTestHelper.ListContainers(resourceGroupName, resourceName, queryParams);

                // VALIDATION: VM should be found in the list
                Assert.True(response.ItemList.ProtectionContainers.Any(
                                protectionContainer =>
                {
                    return(protectionContainer.Properties.GetType().IsSubclassOf(typeof(AzureIaaSVMProtectionContainer)) &&
                           protectionContainer.Name.Contains(containerUniqueName));
                }),
                            "Retrieved list of containers doesn't contain AzureIaaSVMProtectionContainer test container");
            }
        }
Пример #6
0
        public void ListContainersTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"];

                var client = GetServiceClient <RecoveryServicesBackupManagementClient>(resourceNamespace);
                ProtectionContainerListQueryParams queryParams = new ProtectionContainerListQueryParams();
                queryParams.BackupManagementType = BackupManagementType.MAB.ToString();

                ContainerTestHelper             containerTestHelper = new ContainerTestHelper(client);
                ProtectionContainerListResponse response            = containerTestHelper.ListMABContainers(queryParams);

                string containerUniqueName       = CommonTestHelper.GetSetting(TestConstants.RsVaultMabContainerUniqueName);
                MabProtectionContainer container = response.ItemList.ProtectionContainers[0].Properties as MabProtectionContainer;
                Assert.NotNull(container);
                Assert.Equal(containerUniqueName, container.FriendlyName);
            }
        }
        public void ListContainersTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"];
                string rsVaultRgName     = CommonTestHelper.GetSetting(TestConstants.RsVaultRgName);
                string rsVaultName       = CommonTestHelper.GetSetting(TestConstants.RsVaultName);

                var client = GetServiceClient <RecoveryServicesBackupManagementClient>(resourceNamespace);
                ProtectionContainerListQueryParams queryParams = new ProtectionContainerListQueryParams();
                queryParams.BackupManagementType = BackupManagementType.AzureSql.ToString();

                ContainerTestHelper             containerTestHelper = new ContainerTestHelper(client);
                ProtectionContainerListResponse response            = containerTestHelper.ListContainers(rsVaultRgName, rsVaultName, queryParams);

                string containerUniqueName = ConfigurationManager.AppSettings["ContainerTypeAzureSql"] + ";" + ConfigurationManager.AppSettings["AzureSqlContainerName"];
                var    container           = response.ItemList.ProtectionContainers[0];
                Assert.NotNull(container);
                Assert.Equal(containerUniqueName, container.Name);
            }
        }
Пример #8
0
        /// <summary>
        /// Queries all Protection Containers under given Fabric.
        /// </summary>
        private void GetByFabric()
        {
            ProtectionContainerListResponse protectionContainerListResponse = RecoveryServicesClient.GetAzureSiteRecoveryProtectionContainer(this.Fabric.Name);

            this.WriteProtectionContainers(protectionContainerListResponse.ProtectionContainers);
        }
        /// <summary>
        /// Get the list of all ProtectionContainers for the given server.
        /// </summary>
        /// <param name='customRequestHeaders'>
        /// Optional. Request header parameters.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The response model for the list ProtectionContainers operation.
        /// </returns>
        public async System.Threading.Tasks.Task <Microsoft.WindowsAzure.Management.SiteRecovery.Models.ProtectionContainerListResponse> ListAsync(CustomRequestHeaders customRequestHeaders, CancellationToken cancellationToken)
        {
            // Validate

            // Tracing
            bool   shouldTrace  = CloudContext.Configuration.Tracing.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = Tracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("customRequestHeaders", customRequestHeaders);
                Tracing.Enter(invocationId, this, "ListAsync", tracingParameters);
            }

            // Construct URL
            string url = (this.Client.Credentials.SubscriptionId != null ? this.Client.Credentials.SubscriptionId.Trim() : "") + "/cloudservices/" + this.Client.CloudServiceName.Trim() + "/resources/WAHyperVRecoveryManager/~/HyperVRecoveryManagerVault/" + this.Client.ResourceName.Trim() + "/ProtectionContainers?";

            url = url + "api-version=2014-10-27";
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Get;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("Accept", "application/xml");
                httpRequest.Headers.Add("x-ms-client-request-id", customRequestHeaders.ClientRequestId);
                httpRequest.Headers.Add("x-ms-version", "2013-03-01");

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        Tracing.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        Tracing.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            Tracing.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    ProtectionContainerListResponse result = null;
                    // Deserialize Response
                    cancellationToken.ThrowIfCancellationRequested();
                    string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                    result = new ProtectionContainerListResponse();
                    XDocument responseDoc = XDocument.Parse(responseContent);

                    XElement arrayOfServiceResourceSequenceElement = responseDoc.Element(XName.Get("ArrayOfServiceResource", "http://schemas.microsoft.com/windowsazure"));
                    if (arrayOfServiceResourceSequenceElement != null)
                    {
                        foreach (XElement arrayOfServiceResourceElement in arrayOfServiceResourceSequenceElement.Elements(XName.Get("ServiceResource", "http://schemas.microsoft.com/windowsazure")))
                        {
                            ProtectionContainer serviceResourceInstance = new ProtectionContainer();
                            result.ProtectionContainers.Add(serviceResourceInstance);

                            XElement serverIdElement = arrayOfServiceResourceElement.Element(XName.Get("ServerId", "http://schemas.microsoft.com/windowsazure"));
                            if (serverIdElement != null)
                            {
                                string serverIdInstance = serverIdElement.Value;
                                serviceResourceInstance.ServerId = serverIdInstance;
                            }

                            XElement fabricObjectIdElement = arrayOfServiceResourceElement.Element(XName.Get("FabricObjectId", "http://schemas.microsoft.com/windowsazure"));
                            if (fabricObjectIdElement != null)
                            {
                                string fabricObjectIdInstance = fabricObjectIdElement.Value;
                                serviceResourceInstance.FabricObjectId = fabricObjectIdInstance;
                            }

                            XElement configurationStatusElement = arrayOfServiceResourceElement.Element(XName.Get("ConfigurationStatus", "http://schemas.microsoft.com/windowsazure"));
                            if (configurationStatusElement != null)
                            {
                                string configurationStatusInstance = configurationStatusElement.Value;
                                serviceResourceInstance.ConfigurationStatus = configurationStatusInstance;
                            }

                            XElement pairedToElement = arrayOfServiceResourceElement.Element(XName.Get("PairedTo", "http://schemas.microsoft.com/windowsazure"));
                            if (pairedToElement != null)
                            {
                                string pairedToInstance = pairedToElement.Value;
                                serviceResourceInstance.PairedTo = pairedToInstance;
                            }

                            XElement roleElement = arrayOfServiceResourceElement.Element(XName.Get("Role", "http://schemas.microsoft.com/windowsazure"));
                            if (roleElement != null)
                            {
                                string roleInstance = roleElement.Value;
                                serviceResourceInstance.Role = roleInstance;
                            }

                            XElement nameElement = arrayOfServiceResourceElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
                            if (nameElement != null)
                            {
                                string nameInstance = nameElement.Value;
                                serviceResourceInstance.Name = nameInstance;
                            }

                            XElement idElement = arrayOfServiceResourceElement.Element(XName.Get("ID", "http://schemas.microsoft.com/windowsazure"));
                            if (idElement != null)
                            {
                                string idInstance = idElement.Value;
                                serviceResourceInstance.ID = idInstance;
                            }
                        }
                    }

                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        Tracing.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Get the list of all ProtectionContainers for the given server.
        /// </summary>
        /// <param name='customRequestHeaders'>
        /// Optional. Request header parameters.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The response model for the list ProtectionContainers operation.
        /// </returns>
        public async Task <ProtectionContainerListResponse> ListAsync(CustomRequestHeaders customRequestHeaders, CancellationToken cancellationToken)
        {
            // Validate

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("customRequestHeaders", customRequestHeaders);
                TracingAdapter.Enter(invocationId, this, "ListAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            if (this.Client.Credentials.SubscriptionId != null)
            {
                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
            }
            url = url + "/cloudservices/";
            url = url + Uri.EscapeDataString(this.Client.CloudServiceName);
            url = url + "/resources/";
            url = url + "WAHyperVRecoveryManager";
            url = url + "/~/";
            url = url + "HyperVRecoveryManagerVault";
            url = url + "/";
            url = url + Uri.EscapeDataString(this.Client.ResourceName);
            url = url + "/ProtectionContainers";
            List <string> queryParameters = new List <string>();

            queryParameters.Add("api-version=2015-04-10");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Get;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("Accept", "application/xml");
                httpRequest.Headers.Add("x-ms-client-request-id", customRequestHeaders.ClientRequestId);
                httpRequest.Headers.Add("x-ms-version", "2013-03-01");

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        TracingAdapter.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    ProtectionContainerListResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new ProtectionContainerListResponse();
                        XDocument responseDoc = XDocument.Parse(responseContent);

                        XElement arrayOfProtectionContainerSequenceElement = responseDoc.Element(XName.Get("ArrayOfProtectionContainer", "http://schemas.microsoft.com/windowsazure"));
                        if (arrayOfProtectionContainerSequenceElement != null)
                        {
                            foreach (XElement arrayOfProtectionContainerElement in arrayOfProtectionContainerSequenceElement.Elements(XName.Get("ProtectionContainer", "http://schemas.microsoft.com/windowsazure")))
                            {
                                ProtectionContainer protectionContainerInstance = new ProtectionContainer();
                                result.ProtectionContainers.Add(protectionContainerInstance);

                                XElement serverIdElement = arrayOfProtectionContainerElement.Element(XName.Get("ServerId", "http://schemas.microsoft.com/windowsazure"));
                                if (serverIdElement != null)
                                {
                                    string serverIdInstance = serverIdElement.Value;
                                    protectionContainerInstance.ServerId = serverIdInstance;
                                }

                                XElement fabricObjectIdElement = arrayOfProtectionContainerElement.Element(XName.Get("FabricObjectId", "http://schemas.microsoft.com/windowsazure"));
                                if (fabricObjectIdElement != null)
                                {
                                    string fabricObjectIdInstance = fabricObjectIdElement.Value;
                                    protectionContainerInstance.FabricObjectId = fabricObjectIdInstance;
                                }

                                XElement roleElement = arrayOfProtectionContainerElement.Element(XName.Get("Role", "http://schemas.microsoft.com/windowsazure"));
                                if (roleElement != null)
                                {
                                    string roleInstance = roleElement.Value;
                                    protectionContainerInstance.Role = roleInstance;
                                }

                                XElement fabricTypeElement = arrayOfProtectionContainerElement.Element(XName.Get("FabricType", "http://schemas.microsoft.com/windowsazure"));
                                if (fabricTypeElement != null)
                                {
                                    string fabricTypeInstance = fabricTypeElement.Value;
                                    protectionContainerInstance.FabricType = fabricTypeInstance;
                                }

                                XElement typeElement = arrayOfProtectionContainerElement.Element(XName.Get("Type", "http://schemas.microsoft.com/windowsazure"));
                                if (typeElement != null)
                                {
                                    string typeInstance = typeElement.Value;
                                    protectionContainerInstance.Type = typeInstance;
                                }

                                XElement availableProtectionProfilesSequenceElement = arrayOfProtectionContainerElement.Element(XName.Get("AvailableProtectionProfiles", "http://schemas.microsoft.com/windowsazure"));
                                if (availableProtectionProfilesSequenceElement != null)
                                {
                                    foreach (XElement availableProtectionProfilesElement in availableProtectionProfilesSequenceElement.Elements(XName.Get("ProtectionProfile", "http://schemas.microsoft.com/windowsazure")))
                                    {
                                        ProtectionProfile protectionProfileInstance = new ProtectionProfile();
                                        protectionContainerInstance.AvailableProtectionProfiles.Add(protectionProfileInstance);

                                        XElement protectedEntityCountElement = availableProtectionProfilesElement.Element(XName.Get("ProtectedEntityCount", "http://schemas.microsoft.com/windowsazure"));
                                        if (protectedEntityCountElement != null)
                                        {
                                            int protectedEntityCountInstance = int.Parse(protectedEntityCountElement.Value, CultureInfo.InvariantCulture);
                                            protectionProfileInstance.ProtectedEntityCount = protectedEntityCountInstance;
                                        }

                                        XElement replicationProviderElement = availableProtectionProfilesElement.Element(XName.Get("ReplicationProvider", "http://schemas.microsoft.com/windowsazure"));
                                        if (replicationProviderElement != null)
                                        {
                                            string replicationProviderInstance = replicationProviderElement.Value;
                                            protectionProfileInstance.ReplicationProvider = replicationProviderInstance;
                                        }

                                        XElement replicationProviderSettingElement = availableProtectionProfilesElement.Element(XName.Get("ReplicationProviderSetting", "http://schemas.microsoft.com/windowsazure"));
                                        if (replicationProviderSettingElement != null)
                                        {
                                            string replicationProviderSettingInstance = replicationProviderSettingElement.Value;
                                            protectionProfileInstance.ReplicationProviderSetting = replicationProviderSettingInstance;
                                        }

                                        XElement canDissociateElement = availableProtectionProfilesElement.Element(XName.Get("CanDissociate", "http://schemas.microsoft.com/windowsazure"));
                                        if (canDissociateElement != null)
                                        {
                                            bool canDissociateInstance = bool.Parse(canDissociateElement.Value);
                                            protectionProfileInstance.CanDissociate = canDissociateInstance;
                                        }

                                        XElement associationDetailSequenceElement = availableProtectionProfilesElement.Element(XName.Get("AssociationDetail", "http://schemas.microsoft.com/windowsazure"));
                                        if (associationDetailSequenceElement != null)
                                        {
                                            foreach (XElement associationDetailElement in associationDetailSequenceElement.Elements(XName.Get("ProtectionProfileAssociationDetails", "http://schemas.microsoft.com/windowsazure")))
                                            {
                                                ProtectionProfileAssociationDetails protectionProfileAssociationDetailsInstance = new ProtectionProfileAssociationDetails();
                                                protectionProfileInstance.AssociationDetail.Add(protectionProfileAssociationDetailsInstance);

                                                XElement primaryProtectionContainerIdElement = associationDetailElement.Element(XName.Get("PrimaryProtectionContainerId", "http://schemas.microsoft.com/windowsazure"));
                                                if (primaryProtectionContainerIdElement != null)
                                                {
                                                    string primaryProtectionContainerIdInstance = primaryProtectionContainerIdElement.Value;
                                                    protectionProfileAssociationDetailsInstance.PrimaryProtectionContainerId = primaryProtectionContainerIdInstance;
                                                }

                                                XElement recoveryProtectionContainerIdElement = associationDetailElement.Element(XName.Get("RecoveryProtectionContainerId", "http://schemas.microsoft.com/windowsazure"));
                                                if (recoveryProtectionContainerIdElement != null)
                                                {
                                                    string recoveryProtectionContainerIdInstance = recoveryProtectionContainerIdElement.Value;
                                                    protectionProfileAssociationDetailsInstance.RecoveryProtectionContainerId = recoveryProtectionContainerIdInstance;
                                                }

                                                XElement associationStatusElement = associationDetailElement.Element(XName.Get("AssociationStatus", "http://schemas.microsoft.com/windowsazure"));
                                                if (associationStatusElement != null)
                                                {
                                                    string associationStatusInstance = associationStatusElement.Value;
                                                    protectionProfileAssociationDetailsInstance.AssociationStatus = associationStatusInstance;
                                                }
                                            }
                                        }

                                        XElement nameElement = availableProtectionProfilesElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
                                        if (nameElement != null)
                                        {
                                            string nameInstance = nameElement.Value;
                                            protectionProfileInstance.Name = nameInstance;
                                        }

                                        XElement idElement = availableProtectionProfilesElement.Element(XName.Get("ID", "http://schemas.microsoft.com/windowsazure"));
                                        if (idElement != null)
                                        {
                                            string idInstance = idElement.Value;
                                            protectionProfileInstance.ID = idInstance;
                                        }
                                    }
                                }

                                XElement nameElement2 = arrayOfProtectionContainerElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure"));
                                if (nameElement2 != null)
                                {
                                    string nameInstance2 = nameElement2.Value;
                                    protectionContainerInstance.Name = nameInstance2;
                                }

                                XElement idElement2 = arrayOfProtectionContainerElement.Element(XName.Get("ID", "http://schemas.microsoft.com/windowsazure"));
                                if (idElement2 != null)
                                {
                                    string idInstance2 = idElement2.Value;
                                    protectionContainerInstance.ID = idInstance2;
                                }
                            }
                        }
                    }
                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }