public static CSMBackupSchedule FillCSMBackupSchedule(string scheduleType, DateTime scheduleStartTime,
            string[] scheduleRunDays)
        {
            var backupSchedule = new CSMBackupSchedule();

            backupSchedule.BackupType = BackupType.Full.ToString();
            
            scheduleType = FillScheduleType(scheduleType, scheduleRunDays);
            backupSchedule.ScheduleRun = scheduleType;

            if (string.Compare(scheduleType, ScheduleType.Weekly.ToString(), true) == 0)
            {
                backupSchedule.ScheduleRunDays = ParseScheduleRunDays(scheduleRunDays);
            }

            DateTime scheduleRunTime = ParseScheduleRunTime(scheduleStartTime);

            backupSchedule.ScheduleRunTimes = new List<DateTime> { scheduleRunTime };

            return backupSchedule;
        }
        public static void ValidateRetentionPolicy(IList<AzureRMBackupRetentionPolicy> retentionPolicyList, CSMBackupSchedule backupSchedule = null)
        {
            bool validateDailyRetention = false;
            bool validateWeeklyRetention = false;
            int dailyRetentionPolicyCount = 0;
            int weeklyRetentionPolicyCount = 0;
            int monthlyRetentionPolicyCount = 0;
            int yearlyRetentionPolicyCount = 0;

            if(retentionPolicyList.Count == 0 )
            {
                var exception = new ArgumentException(Resources.RetentionPolicyCountException);
                throw exception;
            }

            foreach (AzureRMBackupRetentionPolicy retentionPolicy in retentionPolicyList)
            {
                if(retentionPolicy.RetentionType == RetentionType.Daily.ToString())
                {
                    ValidateDailyRetention((AzureBackupDailyRetentionPolicy)retentionPolicy);
                    validateDailyRetention = true;
                    dailyRetentionPolicyCount = dailyRetentionPolicyCount + 1;
                }
                else if (retentionPolicy.RetentionType == RetentionType.Weekly.ToString())
                {
                    ValidateWeeklyRetention((AzureBackupWeeklyRetentionPolicy)retentionPolicy);
                    validateWeeklyRetention = true;
                    if (backupSchedule != null)
                    {
                        var weeklyRetention = (AzureBackupWeeklyRetentionPolicy)retentionPolicy;
                        ValidateForWeeklyBackupScheduleDaysOfWeek(backupSchedule.ScheduleRun, backupSchedule.ScheduleRunDays, weeklyRetention.DaysOfWeek);
                    }
                    weeklyRetentionPolicyCount = weeklyRetentionPolicyCount + 1;
                }
                else if (retentionPolicy.RetentionType == RetentionType.Monthly.ToString())
                {
                    ValidateMonthlyRetention((AzureBackupMonthlyRetentionPolicy)retentionPolicy);
                    if (backupSchedule != null)
                    {
                        var monthlyRetention = (AzureBackupMonthlyRetentionPolicy)retentionPolicy;
                        ValidateForWeeklyBackupSchedule(monthlyRetention.RetentionFormat, backupSchedule.ScheduleRun, backupSchedule.ScheduleRunDays, monthlyRetention.DaysOfWeek);
                    }
                    monthlyRetentionPolicyCount = monthlyRetentionPolicyCount + 1;
                }
                else if (retentionPolicy.RetentionType == RetentionType.Yearly.ToString())
                {
                    ValidateYearlyRetention((AzureBackupYearlyRetentionPolicy)retentionPolicy);
                    if (backupSchedule != null)
                    {
                        var yearlyRetention = (AzureBackupYearlyRetentionPolicy)retentionPolicy;
                        ValidateForWeeklyBackupSchedule(yearlyRetention.RetentionFormat, backupSchedule.ScheduleRun, backupSchedule.ScheduleRunDays, yearlyRetention.DaysOfWeek);
                    }
                    yearlyRetentionPolicyCount = yearlyRetentionPolicyCount + 1;
                }
            }

            ValidateRetentionPolicyCount(dailyRetentionPolicyCount, weeklyRetentionPolicyCount, monthlyRetentionPolicyCount,
                                          yearlyRetentionPolicyCount);

            if (backupSchedule != null)
                {
                    string scheduleType = backupSchedule.ScheduleRun;
                    if (scheduleType == ScheduleType.Daily.ToString() && validateDailyRetention == false)
                    {
                        var exception = new ArgumentException(Resources.DailyScheduleException);
                        throw exception;
                    }

                    if (scheduleType == ScheduleType.Weekly.ToString() && validateWeeklyRetention == false)
                    {
                        var exception = new ArgumentException(Resources.WeeklyScheduleException);
                        throw exception;
                    }

                    if (scheduleType == ScheduleType.Weekly.ToString() && validateDailyRetention == true)
                    {
                        var exception = new ArgumentException(Resources.WeeklyScheduleWithDailyException);
                        throw exception;
                    }
               }
        }
        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 CSMBackupSchedule GetBackupSchedule()
 {
     var backupSchedule = new CSMBackupSchedule();
     var scheduleRunTime = ConfigurationManager.AppSettings["ScheduleRunTime"];
     backupSchedule.BackupType = ConfigurationManager.AppSettings["BackupType"];
     backupSchedule.ScheduleRun = ConfigurationManager.AppSettings["ScheduleType"];
     backupSchedule.ScheduleRunTimes = new List<DateTime> { DateTime.Parse(scheduleRunTime) };
     return backupSchedule;
 }