/// <summary> /// Enabled the scheduler to do auto backups using the given settings /// </summary> /// <param name="backupPeriodAmount"></param> /// <param name="selectedBackupPeriod"></param> public void Enable(int backupPeriodAmount, BackupPeriod selectedBackupPeriod) { m_currentPeriodAmount = backupPeriodAmount; m_currentPeriodType = selectedBackupPeriod; DestroyTimer(); double interval = 0.0; switch (selectedBackupPeriod) { case BackupPeriod.Days: interval = DaysToMillis(backupPeriodAmount); break; case BackupPeriod.Hours: interval = HoursToMillis(backupPeriodAmount); //Hours to milliseconds break; case BackupPeriod.Minutes: interval = MinutesToMillis(backupPeriodAmount); //Seconds to milliseconds break; default: throw new NotImplementedException(); } m_scheduleTimer = new Timer(interval); m_scheduleTimer.Elapsed += OnRunScheduledBackup; m_scheduleTimer.Start(); IsEnabled = true; NextScheduledBackupTime = DateTime.Now.Add(TimeSpan.FromMilliseconds(interval)); }
/// <summary> /// Get's the numeric multiplier needed to convert a frequency's amount /// from the specified <paramref name="period"/> to milliseconds. /// <br/><br/> /// Throws an <see cref="Exception"/> if the <paramref name="period"/> /// is not valid. /// </summary> /// <param name="period">period to get multiplier for</param> /// <returns>amount multiplier for period</returns> /// <exception cref="Exception"></exception> public static double Multiplier(BackupPeriod period) { switch (period) { case BackupPeriod.Minutes: return(MINUTES); case BackupPeriod.Hours: return(HOURS); case BackupPeriod.Days: return(DAYS); case BackupPeriod.Weeks: return(WEEKS); default: throw new Exception("Can't get multiplier - Invalid BackupPeriod - this should NEVER happen"); } }