コード例 #1
0
ファイル: TimePeriod.cs プロジェクト: slimnate/ValheimBackup
        /// <summary>
        /// Calculates a <see cref="DateTime"/> object by subtracting the
        /// supplied <see cref="CleanupFrequency"/>'s time from the current time.
        /// Used to determine when files should be cleaned up.
        /// <br/><br/>
        /// Throws an <see cref="Exception"/> if the CleanupFrequency is not
        /// valid (because <see cref="CleanupPeriod.Copies"/> is selected, or
        /// some other invalid value was supplied.)
        /// </summary>
        /// <param name="frequency">frequency to calculate from</param>
        /// <returns>
        /// The date/time that was exactly one <paramref name="frequency"/>
        /// period before the current date/time.
        /// </returns>
        /// <exception cref="Exception"></exception>
        public static DateTime TimeAgo(CleanupFrequency frequency)
        {
            TimeSpan span = TimeSpan.FromSeconds(0);

            switch (frequency.Period)
            {
            case CleanupPeriod.Minutes:
                span = TimeSpan.FromMinutes(frequency.Amount);
                break;

            case CleanupPeriod.Hours:
                span = TimeSpan.FromHours(frequency.Amount);
                break;

            case CleanupPeriod.Days:
                span = TimeSpan.FromHours(frequency.Amount);
                break;

            case CleanupPeriod.Weeks:
                span = TimeSpan.FromHours(frequency.Amount);
                break;

            default:
                throw new Exception("Can't get TimeAgo - Invalid CleanupPeriod - could be CleanupPeriod.Copies, or an invalid value");
            }

            return(DateTime.Now.Subtract(span));
        }
コード例 #2
0
ファイル: TimePeriod.cs プロジェクト: slimnate/ValheimBackup
 /// <summary>
 /// Convert a <see cref="CleanupFrequency"/> object to it's period value
 /// in milliseconds.
 /// <br/><br/>
 /// Throws an <see cref="ArgumentException"/> if the cleanup period
 /// is <see cref="CleanupPeriod.Copies"/>
 /// </summary>
 /// <param name="frequency">cleanup frequency to convert</param>
 /// <returns>the frequency's period in milliseconds.</returns>
 /// <exception cref="ArgumentException"></exception>
 public static double ToMilliseconds(CleanupFrequency frequency)
 {
     if (frequency.Period == CleanupPeriod.Copies)
     {
         throw new ArgumentException("frequency period is CleanupPeriod.Copies, cannot convert copies to seconds.");
     }
     return(frequency.Amount * Multiplier(frequency.Period));
 }
コード例 #3
0
 /// <summary>
 /// Create a new BackupDataCleaner with specified params
 /// </summary>
 /// <param name="server">The server that is currently being processed.</param>
 /// <param name="backups">The list of backups that currently exist for that server.</param>
 public BackupDataCleaner(Server server, List <Backup> backups)
 {
     this.serverId  = server.Id;
     this.frequency = server.BackupSettings.CleanupSchedule;
     this.backups   = backups;
 }