/// <summary>
        /// Creates Replication Plan Legacy.
        /// </summary>
        private void CreateRecoveryPlanLegacy()
        {
            CreateRecoveryPlanInputProperties createRecoveryPlanInputProperties = new CreateRecoveryPlanInputProperties()
            {
                FailoverDeploymentModel = failoverDeploymentModel,
                Groups           = new List <RecoveryPlanGroup>(),
                PrimaryFabricId  = this.primaryserver,
                RecoveryFabricId = this.recoveryserver
            };

            RecoveryPlanGroup recoveryPlanGroup = new RecoveryPlanGroup()
            {
                GroupType = Constants.Boot,
                ReplicationProtectedItems = new List <RecoveryPlanProtectedItem>(),
                StartGroupActions         = new List <RecoveryPlanAction>(),
                EndGroupActions           = new List <RecoveryPlanAction>()
            };

            foreach (ASRProtectionEntity pe in ProtectionEntityList)
            {
                string fabricName = Utilities.GetValueFromArmId(pe.ID, ARMResourceTypeConstants.ReplicationFabrics);
                // fetch the latest PE object
                ProtectableItemResponse protectableItemResponse =
                    RecoveryServicesClient.GetAzureSiteRecoveryProtectableItem(fabricName,
                                                                               pe.ProtectionContainerId, pe.Name);

                ReplicationProtectedItemResponse replicationProtectedItemResponse =
                    RecoveryServicesClient.GetAzureSiteRecoveryReplicationProtectedItem(fabricName,
                                                                                        pe.ProtectionContainerId, Utilities.GetValueFromArmId(protectableItemResponse.ProtectableItem.Properties.ReplicationProtectedItemId, ARMResourceTypeConstants.ReplicationProtectedItems));

                string VmId = null;

                if (replicationProtectedItemResponse.ReplicationProtectedItem.Properties.ProviderSpecificDetails.GetType() == typeof(HyperVReplicaAzureReplicationDetails))
                {
                    VmId = ((HyperVReplicaAzureReplicationDetails)replicationProtectedItemResponse.ReplicationProtectedItem.Properties.ProviderSpecificDetails).VmId;
                }
                else if (replicationProtectedItemResponse.ReplicationProtectedItem.Properties.ProviderSpecificDetails.GetType() == typeof(HyperVReplica2012ReplicationDetails))
                {
                    VmId = ((HyperVReplica2012ReplicationDetails)replicationProtectedItemResponse.ReplicationProtectedItem.Properties.ProviderSpecificDetails).VmId;
                }

                RecoveryPlanProtectedItem recoveryPlanProtectedItem = new RecoveryPlanProtectedItem();
                recoveryPlanProtectedItem.Id = replicationProtectedItemResponse.ReplicationProtectedItem.Id;
                recoveryPlanProtectedItem.VirtualMachineId = VmId;
                recoveryPlanGroup.ReplicationProtectedItems.Add(recoveryPlanProtectedItem);
            }

            createRecoveryPlanInputProperties.Groups.Add(recoveryPlanGroup);

            CreateRecoveryPlanInput createRecoveryPlanInput = new CreateRecoveryPlanInput()
            {
                Properties = createRecoveryPlanInputProperties
            };

            CreateRecoveryPlan(this.Name, createRecoveryPlanInput);
        }
        /// <summary>
        /// Create Recovery Plan: By Service object
        /// </summary>
        private void CreateRecoveryPlan(RecoveryPlan recoveryPlan)
        {
            CreateRecoveryPlanInputProperties createRecoveryPlanInputProperties = new CreateRecoveryPlanInputProperties()
            {
                FailoverDeploymentModel = recoveryPlan.Properties.FailoverDeploymentModel,
                Groups           = recoveryPlan.Properties.Groups,
                PrimaryFabricId  = recoveryPlan.Properties.PrimaryFabricId,
                RecoveryFabricId = recoveryPlan.Properties.RecoveryFabricId
            };

            CreateRecoveryPlanInput createRecoveryPlanInput = new CreateRecoveryPlanInput()
            {
                Properties = createRecoveryPlanInputProperties
            };

            CreateRecoveryPlan(recoveryPlan.Name, createRecoveryPlanInput);
        }
        /// <summary>
        ///     Create Recovery Plan: By Service object
        /// </summary>
        private void CreateRecoveryPlan(
            RecoveryPlan recoveryPlan)
        {
            var createRecoveryPlanInputProperties = new CreateRecoveryPlanInputProperties
            {
                FailoverDeploymentModel = recoveryPlan.Properties.FailoverDeploymentModel,
                Groups           = recoveryPlan.Properties.Groups,
                PrimaryFabricId  = recoveryPlan.Properties.PrimaryFabricId,
                RecoveryFabricId = recoveryPlan.Properties.RecoveryFabricId
            };

            if (recoveryPlan.Properties.ProviderSpecificDetails != null &&
                recoveryPlan.Properties.ProviderSpecificDetails.Count > 0)
            {
                createRecoveryPlanInputProperties.ProviderSpecificInput =
                    new List <RecoveryPlanProviderSpecificInput>();
                foreach (var providerSpecificDetails in recoveryPlan.Properties.ProviderSpecificDetails)
                {
                    if (providerSpecificDetails is RecoveryPlanA2ADetails)
                    {
                        var a2aProviderDetails = (RecoveryPlanA2ADetails)providerSpecificDetails;
                        var psd = new RecoveryPlanA2AInput
                        {
                            RecoveryZone = a2aProviderDetails.RecoveryZone,
                            PrimaryZone  = a2aProviderDetails.PrimaryZone
                        };

                        createRecoveryPlanInputProperties.ProviderSpecificInput.Add(psd);
                    }
                }
            }

            var createRecoveryPlanInput =
                new CreateRecoveryPlanInput {
                Properties = createRecoveryPlanInputProperties
            };

            this.CreateRecoveryPlan(
                recoveryPlan.Name,
                createRecoveryPlanInput);
        }
        /// <summary>
        ///     Create Recovery Plan: By Service object
        /// </summary>
        private void CreateRecoveryPlan(
            RecoveryPlan recoveryPlan)
        {
            var createRecoveryPlanInputProperties = new CreateRecoveryPlanInputProperties
            {
                FailoverDeploymentModel = (FailoverDeploymentModel)Enum.Parse(
                    typeof(FailoverDeploymentModel),
                    recoveryPlan.Properties.FailoverDeploymentModel),
                Groups           = recoveryPlan.Properties.Groups,
                PrimaryFabricId  = recoveryPlan.Properties.PrimaryFabricId,
                RecoveryFabricId = recoveryPlan.Properties.RecoveryFabricId
            };

            var createRecoveryPlanInput =
                new CreateRecoveryPlanInput {
                Properties = createRecoveryPlanInputProperties
            };

            this.CreateRecoveryPlan(
                recoveryPlan.Name,
                createRecoveryPlanInput);
        }
        /// <summary>
        ///     Creates Replication Plan
        /// </summary>
        private void CreateRecoveryPlan()
        {
            var createRecoveryPlanInputProperties = new CreateRecoveryPlanInputProperties
            {
                FailoverDeploymentModel = (FailoverDeploymentModel)Enum.Parse(
                    typeof(FailoverDeploymentModel),
                    this.failoverDeploymentModel),
                Groups           = new List <RecoveryPlanGroup>(),
                PrimaryFabricId  = this.primaryserver,
                RecoveryFabricId = this.recoveryserver
            };

            var recoveryPlanGroup = new RecoveryPlanGroup
            {
                GroupType = RecoveryPlanGroupType.Boot,
                ReplicationProtectedItems = new List <RecoveryPlanProtectedItem>(),
                StartGroupActions         = new List <RecoveryPlanAction>(),
                EndGroupActions           = new List <RecoveryPlanAction>()
            };

            foreach (var rpi in this.ReplicationProtectedItem)
            {
                var fabricName = Utilities.GetValueFromArmId(
                    rpi.ID,
                    ARMResourceTypeConstants.ReplicationFabrics);

                var replicationProtectedItemResponse = this.RecoveryServicesClient
                                                       .GetAzureSiteRecoveryReplicationProtectedItem(
                    fabricName,
                    Utilities.GetValueFromArmId(
                        rpi.ID,
                        ARMResourceTypeConstants.ReplicationProtectionContainers),
                    rpi.Name);

                string VmId = null;

                if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails.GetType() ==
                    typeof(HyperVReplicaAzureReplicationDetails))
                {
                    VmId = ((HyperVReplicaAzureReplicationDetails)replicationProtectedItemResponse
                            .Properties.ProviderSpecificDetails).VmId;
                }
                else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails
                         .GetType() ==
                         typeof(HyperVReplicaReplicationDetails))
                {
                    VmId = ((HyperVReplicaReplicationDetails)replicationProtectedItemResponse
                            .Properties.ProviderSpecificDetails).VmId;
                }
                else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails
                         .GetType() ==
                         typeof(HyperVReplicaBlueReplicationDetails))
                {
                    VmId = ((HyperVReplicaBlueReplicationDetails)replicationProtectedItemResponse
                            .Properties.ProviderSpecificDetails).VmId;
                }
                else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails
                         .GetType() ==
                         typeof(InMageAzureV2ReplicationDetails))
                {
                    VmId = ((InMageAzureV2ReplicationDetails)replicationProtectedItemResponse
                            .Properties.ProviderSpecificDetails).VmId;
                }
                else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails
                         .GetType() ==
                         typeof(InMageReplicationDetails))
                {
                    VmId = ((InMageReplicationDetails)replicationProtectedItemResponse
                            .Properties.ProviderSpecificDetails).VmId;
                }
                else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails.GetType() == typeof(A2AReplicationDetails))
                {
                    A2AReplicationDetails a2aReplicationDetails =
                        ((A2AReplicationDetails)replicationProtectedItemResponse
                         .Properties
                         .ProviderSpecificDetails);
                    if (a2aReplicationDetails.FabricObjectId.IndexOf(
                            Constants.ClassicCompute,
                            StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        createRecoveryPlanInputProperties.FailoverDeploymentModel =
                            Management.RecoveryServices.SiteRecovery.Models.FailoverDeploymentModel.Classic;
                    }
                    else if (a2aReplicationDetails.FabricObjectId.IndexOf(
                                 Constants.Compute,
                                 StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        createRecoveryPlanInputProperties.FailoverDeploymentModel =
                            Management.RecoveryServices.SiteRecovery.Models.FailoverDeploymentModel.ResourceManager;
                    }
                }

                var recoveryPlanProtectedItem = new RecoveryPlanProtectedItem();
                recoveryPlanProtectedItem.Id = replicationProtectedItemResponse.Id;
                recoveryPlanProtectedItem.VirtualMachineId = VmId;
                recoveryPlanGroup.ReplicationProtectedItems.Add(recoveryPlanProtectedItem);
            }

            createRecoveryPlanInputProperties.Groups.Add(recoveryPlanGroup);

            var createRecoveryPlanInput =
                new CreateRecoveryPlanInput {
                Properties = createRecoveryPlanInputProperties
            };

            this.CreateRecoveryPlan(
                this.Name,
                createRecoveryPlanInput);
        }
        /// <summary>
        ///     Creates Replication Plan
        /// </summary>
        private void CreateRecoveryPlan()
        {
            var createRecoveryPlanInputProperties = new CreateRecoveryPlanInputProperties
            {
                FailoverDeploymentModel = this.failoverDeploymentModel,
                Groups           = new List <RecoveryPlanGroup>(),
                PrimaryFabricId  = this.primaryserver,
                RecoveryFabricId = this.recoveryserver
            };

            var recoveryPlanGroup = new RecoveryPlanGroup
            {
                GroupType = RecoveryPlanGroupType.Boot,
                ReplicationProtectedItems = new List <RecoveryPlanProtectedItem>(),
                StartGroupActions         = new List <RecoveryPlanAction>(),
                EndGroupActions           = new List <RecoveryPlanAction>()
            };

            foreach (var rpi in this.ReplicationProtectedItem)
            {
                var fabricName = Utilities.GetValueFromArmId(
                    rpi.ID,
                    ARMResourceTypeConstants.ReplicationFabrics);

                var replicationProtectedItemResponse = this.RecoveryServicesClient
                                                       .GetAzureSiteRecoveryReplicationProtectedItem(
                    fabricName,
                    Utilities.GetValueFromArmId(
                        rpi.ID,
                        ARMResourceTypeConstants.ReplicationProtectionContainers),
                    rpi.Name);

                string VmId = null;

                if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails.GetType() ==
                    typeof(HyperVReplicaAzureReplicationDetails))
                {
                    VmId = ((HyperVReplicaAzureReplicationDetails)replicationProtectedItemResponse
                            .Properties.ProviderSpecificDetails).VmId;
                }
                else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails
                         .GetType() ==
                         typeof(HyperVReplicaReplicationDetails))
                {
                    VmId = ((HyperVReplicaReplicationDetails)replicationProtectedItemResponse
                            .Properties.ProviderSpecificDetails).VmId;
                }
                else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails
                         .GetType() ==
                         typeof(HyperVReplicaBlueReplicationDetails))
                {
                    VmId = ((HyperVReplicaBlueReplicationDetails)replicationProtectedItemResponse
                            .Properties.ProviderSpecificDetails).VmId;
                }
                else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails
                         .GetType() ==
                         typeof(InMageAzureV2ReplicationDetails))
                {
                    VmId = ((InMageAzureV2ReplicationDetails)replicationProtectedItemResponse
                            .Properties.ProviderSpecificDetails).VmId;
                }
                else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails
                         .GetType() ==
                         typeof(InMageReplicationDetails))
                {
                    VmId = ((InMageReplicationDetails)replicationProtectedItemResponse
                            .Properties.ProviderSpecificDetails).VmId;
                }
                else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails.GetType() == typeof(A2AReplicationDetails))
                {
                    A2AReplicationDetails a2aReplicationDetails =
                        ((A2AReplicationDetails)replicationProtectedItemResponse
                         .Properties
                         .ProviderSpecificDetails);
                    if (a2aReplicationDetails.FabricObjectId.IndexOf(
                            Constants.ClassicCompute,
                            StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        createRecoveryPlanInputProperties.FailoverDeploymentModel =
                            Management.RecoveryServices.SiteRecovery.Models.FailoverDeploymentModel.Classic;
                    }
                    else if (a2aReplicationDetails.FabricObjectId.IndexOf(
                                 Constants.Compute,
                                 StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        createRecoveryPlanInputProperties.FailoverDeploymentModel =
                            Management.RecoveryServices.SiteRecovery.Models.FailoverDeploymentModel.ResourceManager;
                    }
                }
                else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails
                         .GetType() ==
                         typeof(InMageRcmReplicationDetails))
                {
                    VmId = ((InMageRcmReplicationDetails)replicationProtectedItemResponse
                            .Properties.ProviderSpecificDetails).InternalIdentifier;
                    createRecoveryPlanInputProperties.FailoverDeploymentModel =
                        Management.RecoveryServices.SiteRecovery.Models.FailoverDeploymentModel.ResourceManager;
                }
                else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails
                         .GetType() ==
                         typeof(InMageRcmFailbackReplicationDetails))
                {
                    VmId = ((InMageRcmFailbackReplicationDetails)replicationProtectedItemResponse
                            .Properties.ProviderSpecificDetails).InternalIdentifier;
                    createRecoveryPlanInputProperties.FailoverDeploymentModel =
                        Management.RecoveryServices.SiteRecovery.Models.FailoverDeploymentModel.ResourceManager;
                }

                var recoveryPlanProtectedItem = new RecoveryPlanProtectedItem();
                recoveryPlanProtectedItem.Id = replicationProtectedItemResponse.Id;
                recoveryPlanProtectedItem.VirtualMachineId = VmId;
                recoveryPlanGroup.ReplicationProtectedItems.Add(recoveryPlanProtectedItem);
            }

            createRecoveryPlanInputProperties.Groups.Add(recoveryPlanGroup);

            // Add zone to zone details.
            if (this.ParameterSetName == ASRParameterSets.AzureZoneToZone)
            {
                var recoveryPlanA2AInput = new RecoveryPlanA2AInput
                {
                    PrimaryZone             = this.PrimaryZone,
                    RecoveryZone            = this.RecoveryZone,
                    PrimaryExtendedLocation = this.IsParameterBound(c => c.PrimaryEdgeZone) ? new ExtendedLocation
                    {
                        Name = this.PrimaryEdgeZone
                    } : null,
                    RecoveryExtendedLocation = this.IsParameterBound(c => c.RecoveryEdgeZone) ? new ExtendedLocation
                    {
                        Name = this.RecoveryEdgeZone
                    } : null
                };

                createRecoveryPlanInputProperties.ProviderSpecificInput = new List <RecoveryPlanProviderSpecificInput>();
                createRecoveryPlanInputProperties.ProviderSpecificInput.Add(recoveryPlanA2AInput);
            }


            var createRecoveryPlanInput =
                new CreateRecoveryPlanInput {
                Properties = createRecoveryPlanInputProperties
            };

            this.CreateRecoveryPlan(
                this.Name,
                createRecoveryPlanInput);
        }