Пример #1
0
        //
        // Summary:
        //     Initializes a new instance of the RecoveryPlanAction class.
        public static RecoveryPlanAction GetSrsRecoveryPlanAction(ASRRecoveryPlanAction asrRecoveryPlanAction)
        {
            var recoveryPlanAction = new RecoveryPlanAction();

            recoveryPlanAction.ActionName         = asrRecoveryPlanAction.ActionName;
            recoveryPlanAction.FailoverDirections = asrRecoveryPlanAction.FailoverDirections;

            if (asrRecoveryPlanAction.CustomDetails is ASRRecoveryPlanAutomationRunbookActionDetails)
            {
                recoveryPlanAction.CustomDetails = ASRRecoveryPlanAutomationRunbookActionDetails.getSrsRecoveryPlanAutomationRunbookActionDetails(
                    (ASRRecoveryPlanAutomationRunbookActionDetails)asrRecoveryPlanAction.CustomDetails);
            }
            else if (asrRecoveryPlanAction.CustomDetails is ASRRecoveryPlanManualActionDetails)
            {
                recoveryPlanAction.CustomDetails = ASRRecoveryPlanManualActionDetails.getSrsRecoveryPlanAutomationRunbookActionDetails(
                    (ASRRecoveryPlanManualActionDetails)asrRecoveryPlanAction.CustomDetails);
            }
            else if (asrRecoveryPlanAction.CustomDetails is ASRRecoveryPlanScriptActionDetails)
            {
                recoveryPlanAction.CustomDetails = ASRRecoveryPlanScriptActionDetails.getRecoveryPlanScriptActionDetails(
                    (ASRRecoveryPlanScriptActionDetails)asrRecoveryPlanAction.CustomDetails);
            }

            return(recoveryPlanAction);
        }
        /// <summary>
        ///     Update Recovery Plan: By powerShell Recovery Plan object
        /// </summary>
        private void UpdateRecoveryPlan(
            ASRRecoveryPlan asrRecoveryPlan)
        {
            var updateRecoveryPlanInputProperties =
                new UpdateRecoveryPlanInputProperties {
                Groups = new List <RecoveryPlanGroup>()
            };

            foreach (var asrRecoveryPlanGroup in asrRecoveryPlan.Groups)
            {
                var recoveryPlanGroup = new RecoveryPlanGroup
                {
                    GroupType = asrRecoveryPlanGroup.GroupType,

                    // Initialize ReplicationProtectedItems with empty List if asrRecoveryPlanGroup.ReplicationProtectedItems is null
                    // otherwise assign respective values
                    ReplicationProtectedItems =
                        asrRecoveryPlanGroup.ReplicationProtectedItems == null
                            ? new List <RecoveryPlanProtectedItem>() : asrRecoveryPlanGroup
                        .ReplicationProtectedItems.Select(
                            item =>
                    {
                        var newItem = new RecoveryPlanProtectedItem(item.ID);

                        string VmId = null;

                        if (item.ProviderSpecificDetails.GetType() ==
                            typeof(ASRHyperVReplicaAzureSpecificRPIDetails))
                        {
                            VmId = ((ASRHyperVReplicaAzureSpecificRPIDetails)item.ProviderSpecificDetails).VmId;
                        }
                        else if (item.ProviderSpecificDetails.GetType() == typeof(ASRHyperVReplicaRPIDetails))
                        {
                            VmId = ((ASRHyperVReplicaRPIDetails)item.ProviderSpecificDetails).VmId;
                        }
                        else if (item.ProviderSpecificDetails.GetType() == typeof(ASRHyperVReplicaBlueRPIDetails))
                        {
                            VmId = ((ASRHyperVReplicaBlueRPIDetails)item.ProviderSpecificDetails).VmId;
                        }
                        else if (item.ProviderSpecificDetails.GetType() == typeof(ASRInMageSpecificRPIDetails))
                        {
                            VmId = ((ASRInMageSpecificRPIDetails)item.ProviderSpecificDetails).VmId;
                        }
                        else if (item.ProviderSpecificDetails.GetType() == typeof(ASRInMageSpecificRPIDetails))
                        {
                            VmId = ((ASRInMageSpecificRPIDetails)item.ProviderSpecificDetails).VmId;
                        }

                        newItem.VirtualMachineId = VmId;

                        return(newItem);
                    })
                        .ToList(),
                    StartGroupActions = asrRecoveryPlanGroup.StartGroupActions == null ?
                                        null : asrRecoveryPlanGroup.StartGroupActions.ToList().ConvertAll(
                        action => ASRRecoveryPlanAction.GetSrsRecoveryPlanAction(action)),
                    EndGroupActions = asrRecoveryPlanGroup.EndGroupActions == null ?
                                      null : asrRecoveryPlanGroup.EndGroupActions.ToList().ConvertAll(
                        action => ASRRecoveryPlanAction.GetSrsRecoveryPlanAction(action)),
                };

                updateRecoveryPlanInputProperties.Groups.Add(recoveryPlanGroup);
            }

            var updateRecoveryPlanInput =
                new UpdateRecoveryPlanInput {
                Properties = updateRecoveryPlanInputProperties
            };

            this.UpdateRecoveryPlan(
                asrRecoveryPlan.Name,
                updateRecoveryPlanInput);
        }