public static IList<AzureRMBackupRetentionPolicy> ConvertCSMRetentionPolicyListToPowershell(CSMLongTermRetentionPolicy LTRRetentionPolicy) { IList<AzureRMBackupRetentionPolicy> retentionPolicyList = new List<AzureRMBackupRetentionPolicy>(); AzureBackupDailyRetentionPolicy dailyRetentionPolicy = ConvertToPowershellDailyRetentionObject(LTRRetentionPolicy.DailySchedule); AzureBackupWeeklyRetentionPolicy weeklyRetentionPolicy = ConvertToPowershellWeeklyRetentionObject(LTRRetentionPolicy.WeeklySchedule); AzureBackupMonthlyRetentionPolicy monthlyRetentionPolicy = ConvertToPowershellMonthlyRetentionObject(LTRRetentionPolicy.MonthlySchedule); AzureBackupYearlyRetentionPolicy yearlyRetentionPolicy = ConvertToPowershellYearlyRetentionObject(LTRRetentionPolicy.YearlySchedule); if (dailyRetentionPolicy != null) { retentionPolicyList.Add(dailyRetentionPolicy); } if (weeklyRetentionPolicy != null) { retentionPolicyList.Add(weeklyRetentionPolicy); } if (monthlyRetentionPolicy != null) { retentionPolicyList.Add(monthlyRetentionPolicy); } if (yearlyRetentionPolicy != null) { retentionPolicyList.Add(yearlyRetentionPolicy); } return retentionPolicyList; }
public static CSMLongTermRetentionPolicy ConvertToCSMRetentionPolicyObject(IList<AzureRMBackupRetentionPolicy> retentionPolicyList, CSMBackupSchedule backupSchedule) { CSMLongTermRetentionPolicy csmLongTermRetentionPolicy = new CSMLongTermRetentionPolicy(); foreach (AzureRMBackupRetentionPolicy retentionPolicy in retentionPolicyList) { if (retentionPolicy.RetentionType == "Daily") { csmLongTermRetentionPolicy.DailySchedule = ConvertToCSMDailyRetentionObject((AzureBackupDailyRetentionPolicy)retentionPolicy, backupSchedule.ScheduleRunTimes); } if (retentionPolicy.RetentionType == "Weekly") { csmLongTermRetentionPolicy.WeeklySchedule = ConvertToCSMWeeklyRetentionObject((AzureBackupWeeklyRetentionPolicy)retentionPolicy, backupSchedule.ScheduleRunTimes); } if (retentionPolicy.RetentionType == "Monthly") { csmLongTermRetentionPolicy.MonthlySchedule = ConvertToGetCSMMonthlyRetentionObject((AzureBackupMonthlyRetentionPolicy)retentionPolicy, backupSchedule.ScheduleRunTimes); } if (retentionPolicy.RetentionType == "Yearly") { csmLongTermRetentionPolicy.YearlySchedule = ConvertToCSMYearlyRetentionObject((AzureBackupYearlyRetentionPolicy)retentionPolicy, backupSchedule.ScheduleRunTimes); } } return csmLongTermRetentionPolicy; }
private CSMLongTermRetentionPolicy GetRetentionPolicy(IList<DateTime> RetentionTimes) { CSMRetentionDuration cmsDailyRetentionDuration = new CSMRetentionDuration(); cmsDailyRetentionDuration.Count = Convert.ToInt32(ConfigurationManager.AppSettings["DailyRetentionCount"]); cmsDailyRetentionDuration.DurationType = RetentionDurationType.Days; CSMRetentionDuration cmsWeeklyRetentionDuration = new CSMRetentionDuration(); cmsWeeklyRetentionDuration.Count = Convert.ToInt32(ConfigurationManager.AppSettings["WeeklyRetentionCount"]); cmsWeeklyRetentionDuration.DurationType = RetentionDurationType.Weeks; IList<DayOfWeek> dayofWeekList = new List<DayOfWeek>(); dayofWeekList.Add(DayOfWeek.Monday); var retentionPolicy = new CSMLongTermRetentionPolicy { DailySchedule = new CSMDailyRetentionSchedule(), WeeklySchedule = new CSMWeeklyRetentionSchedule() }; retentionPolicy.DailySchedule.CSMRetentionDuration = cmsDailyRetentionDuration; retentionPolicy.DailySchedule.RetentionTimes = RetentionTimes; retentionPolicy.WeeklySchedule.CSMRetentionDuration = cmsWeeklyRetentionDuration; retentionPolicy.WeeklySchedule.RetentionTimes = RetentionTimes; retentionPolicy.WeeklySchedule.DaysOfTheWeek = dayofWeekList; return retentionPolicy; }