private void GetRecoveryPlanFile(RecoveryPlan recoveryPlan)
        {
            recoveryPlan = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(recoveryPlan.Name).RecoveryPlan;

            if (string.IsNullOrEmpty(this.Path) || !Directory.Exists(System.IO.Path.GetDirectoryName(this.Path)))
            {
                throw new DirectoryNotFoundException(string.Format(Properties.Resources.DirectoryNotFound, System.IO.Path.GetDirectoryName(this.Path)));
            }

            string fullFileName = this.Path; 
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@fullFileName, false))
            {
                string json = JsonConvert.SerializeObject(recoveryPlan, Formatting.Indented);
                file.WriteLine(json);
            }
        }
 /// <summary>
 /// Write Recovery Plan.
 /// </summary>
 /// <param name="recoveryPlan">Recovery Plan object</param>
 private void WriteRecoveryPlan(RecoveryPlan recoveryPlan)
 {
     var replicationProtectedItemListResponse = RecoveryServicesClient.GetAzureSiteRecoveryReplicationProtectedItemInRP(recoveryPlan.Name);
     this.WriteObject(new ASRRecoveryPlan(recoveryPlan, replicationProtectedItemListResponse.ReplicationProtectedItems));
 }
        private static void ValidateCreateInput2(
            RecoveryPlan rp,
            string fabricId,
            string vmId)
        {
            Assert.True(rp.Properties.PrimaryFabricId == fabricId);
            Assert.True(rp.Properties.RecoveryFabricId == fabricId);

            Assert.True(rp.Properties.Groups.Count == 2);
            Assert.True(rp.Properties.Groups[0].GroupType == "Shutdown");
            Assert.True(rp.Properties.Groups[0].ReplicationProtectedItems.Count == 0);

            Assert.True(rp.Properties.Groups[1].GroupType == "Failover");
            Assert.True(rp.Properties.Groups[1].ReplicationProtectedItems.Count == 0);

            Assert.True(rp.Properties.Groups[0].StartGroupActions.Count == 2);
            Assert.True(rp.Properties.Groups[0].StartGroupActions[0].ActionName == "S2");
            Assert.True(rp.Properties.Groups[0].StartGroupActions[0].FailoverTypes.Count == 1);
            Assert.True(rp.Properties.Groups[0].StartGroupActions[0].FailoverTypes[0] == "PlannedFailover");
            Assert.True(rp.Properties.Groups[0].StartGroupActions[0].FailoverDirections.Count == 1);
            Assert.True(rp.Properties.Groups[0].StartGroupActions[0].FailoverDirections[0] == "PrimaryToRecovery");
            Assert.True(rp.Properties.Groups[0].StartGroupActions[0].CustomDetails.InstanceType == "ScriptActionDetails");

            Assert.True(rp.Properties.Groups[0].StartGroupActions[1].ActionName == "M2");
            Assert.True(rp.Properties.Groups[0].StartGroupActions[1].FailoverTypes.Count == 1);
            Assert.True(rp.Properties.Groups[0].StartGroupActions[1].FailoverTypes[0] == "UnplannedFailover");
            Assert.True(rp.Properties.Groups[0].StartGroupActions[1].FailoverDirections.Count == 1);
            Assert.True(rp.Properties.Groups[0].StartGroupActions[1].FailoverDirections[0] == "RecoveryToPrimary");
            Assert.True(rp.Properties.Groups[0].StartGroupActions[1].CustomDetails.InstanceType == "ManualActionDetails");

            RecoveryPlanScriptActionDetails scriptAction =
                rp.Properties.Groups[0].StartGroupActions[0].CustomDetails as RecoveryPlanScriptActionDetails;
            Assert.True(scriptAction.Path == "path2");
            Assert.True(scriptAction.FabricLocation == "Primary");

            RecoveryPlanManualActionDetails manualAction =
                rp.Properties.Groups[0].StartGroupActions[1].CustomDetails as RecoveryPlanManualActionDetails;
            Assert.True(manualAction.Description == "desc2");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ASRRecoveryPlan" /> class with required
        /// parameters.
        /// </summary>
        /// <param name="recoveryPlan">Recovery plan object</param>
        public ASRRecoveryPlan(RecoveryPlan recoveryPlan, IList<ReplicationProtectedItem> replicationProtectedItems)
        {
            this.Name = recoveryPlan.Name;
            this.FriendlyName = recoveryPlan.Properties.FriendlyName;
            this.ServerId = recoveryPlan.Properties.PrimaryFabricId;
            this.TargetServerId = recoveryPlan.Properties.RecoveryFabricId;
            this.FailoverDeploymentModel = recoveryPlan.Properties.FailoverDeploymentModel;
            this.Groups = new List<ASRRecoveryPlanGroup>();
            int groupCount = 0;
            string groupName = null;

            foreach (RecoveryPlanGroup recoveryPlanGroup in recoveryPlan.Properties.Groups)
            {
                switch(recoveryPlanGroup.GroupType)
                {
                    case Constants.Boot:
                        groupCount++;
                        groupName = "Group " + groupCount.ToString();
                        break;
                    case Constants.Failover:
                        groupName = Constants.Failover;
                        break;
                    case Constants.Shutdown:
                        groupName = Constants.Shutdown;
                        break;
                }
                this.Groups.Add(new ASRRecoveryPlanGroup(groupName, recoveryPlanGroup, replicationProtectedItems));
            }

            this.ReplicationProvider = recoveryPlan.Properties.ReplicationProviders;
        }
        /// <summary>
        /// Update Recovery Plan: By Service object
        /// </summary>
        private void UpdateRecoveryPlan(RecoveryPlan recoveryPlan)
        {
            UpdateRecoveryPlanInputProperties updateRecoveryPlanInputProperties = new UpdateRecoveryPlanInputProperties()
            {
                Groups = recoveryPlan.Properties.Groups,
            };

            UpdateRecoveryPlanInput updateRecoveryPlanInput = new UpdateRecoveryPlanInput()
            {
                Properties = updateRecoveryPlanInputProperties
            };

            UpdateRecoveryPlan(recoveryPlan.Name, updateRecoveryPlanInput);
        }
        /// <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>
        /// ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            switch (this.ParameterSetName)
            {
                case ASRParameterSets.EnterpriseToEnterpriseLegacy:
                    this.WriteWarningWithTimestamp(Properties.Resources.ParameterSetWillBeDeprecatedSoon);
                    failoverDeploymentModel = Constants.NotApplicable;
                    this.primaryserver = RecoveryServicesClient.GetAzureSiteRecoveryFabric(Utilities.GetValueFromArmId(this.PrimaryServer.ID, ARMResourceTypeConstants.ReplicationFabrics)).Fabric.Id;
                    this.recoveryserver = RecoveryServicesClient.GetAzureSiteRecoveryFabric(Utilities.GetValueFromArmId(this.RecoveryServer.ID, ARMResourceTypeConstants.ReplicationFabrics)).Fabric.Id;
                    break;
                case ASRParameterSets.EnterpriseToAzureLegacy:
                    this.WriteWarningWithTimestamp(Properties.Resources.ParameterSetWillBeDeprecatedSoon);
                    failoverDeploymentModel = this.FailoverDeploymentModel;
                    this.primaryserver = RecoveryServicesClient.GetAzureSiteRecoveryFabric(Utilities.GetValueFromArmId(this.PrimaryServer.ID, ARMResourceTypeConstants.ReplicationFabrics)).Fabric.Id;
                    this.recoveryserver = Constants.AzureContainer;
                    break;
                case ASRParameterSets.HyperVSiteToAzureLegacy:
                    this.WriteWarningWithTimestamp(Properties.Resources.ParameterSetWillBeDeprecatedSoon);
                    failoverDeploymentModel = this.FailoverDeploymentModel;
                    this.primaryserver = this.PrimarySite.ID;
                    this.recoveryserver = Constants.AzureContainer;
                    break;
                case ASRParameterSets.EnterpriseToEnterprise:
                    failoverDeploymentModel = Constants.NotApplicable;
                    this.primaryserver = this.PrimaryFabric.ID;
                    this.recoveryserver = this.RecoveryFabric.ID;
                    break;
                case ASRParameterSets.EnterpriseToAzure:
                    failoverDeploymentModel = this.FailoverDeploymentModel;
                    this.primaryserver = this.PrimaryFabric.ID;
                    this.recoveryserver = Constants.AzureContainer;
                    break;
                case ASRParameterSets.ByRPFile:

                    if (!File.Exists(this.Path))
                    {
                        throw new FileNotFoundException(string.Format(Properties.Resources.FileNotFound, this.Path)); ;
                    }

                    string filePath = this.Path;

                    using (System.IO.StreamReader file = new System.IO.StreamReader(filePath))
                    {
                        recoveryPlan = JsonConvert.DeserializeObject<RecoveryPlan>(file.ReadToEnd(), new RecoveryPlanActionDetailsConverter());
                    }

                    break;

            }

            if (string.Compare(this.ParameterSetName, ASRParameterSets.ByRPFile, StringComparison.OrdinalIgnoreCase) == 0)
            {
                CreateRecoveryPlan(recoveryPlan);
            }
            else if(string.Compare(this.ParameterSetName, ASRParameterSets.EnterpriseToEnterpriseLegacy, StringComparison.OrdinalIgnoreCase) == 0 ||
                string.Compare(this.ParameterSetName, ASRParameterSets.EnterpriseToAzureLegacy, StringComparison.OrdinalIgnoreCase) == 0 ||
                string.Compare(this.ParameterSetName, ASRParameterSets.HyperVSiteToAzureLegacy, StringComparison.OrdinalIgnoreCase) == 0)
            {
                CreateRecoveryPlanLegacy();
            }
            else
            {
                this.CreateRecoveryPlan();
            }
        }