From dc935361625c1d1b24042c33da8f723941e052e6 Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch> Date: Tue, 9 Jan 2018 13:37:52 +0100 Subject: [PATCH] Fix calculations of time span values. --- AutoTx/AutoTx.cs | 6 +++--- AutoTx/Email.cs | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/AutoTx/AutoTx.cs b/AutoTx/AutoTx.cs index c069730..b633804 100644 --- a/AutoTx/AutoTx.cs +++ b/AutoTx/AutoTx.cs @@ -399,8 +399,8 @@ namespace AutoTx CheckFreeDiskSpace(); UpdateServiceState(); - var delta = DateTime.Now - _lastUserDirCheck; - if (delta.Seconds >= 120) + var delta = (int)(DateTime.Now - _lastUserDirCheck).TotalSeconds; + if (delta >= 120) CreateIncomingDirectories(); // tasks depending on the service state: @@ -970,7 +970,7 @@ namespace AutoTx private Dictionary<string, List<Tuple<DirectoryInfo, long, int>>> ExpiredDirs(int thresh) { var collection = new Dictionary<string, List<Tuple<DirectoryInfo, long, int>>>(); var graceDir = new DirectoryInfo(Path.Combine(_managedPath, "DONE")); - var now = DateTime.UtcNow; + var now = DateTime.Now; foreach (var userdir in graceDir.GetDirectories()) { var expired = new List<Tuple<DirectoryInfo, long, int>>(); foreach (var subdir in userdir.GetDirectories()) { diff --git a/AutoTx/Email.cs b/AutoTx/Email.cs index c068a2b..8cee0dd 100644 --- a/AutoTx/Email.cs +++ b/AutoTx/Email.cs @@ -80,9 +80,12 @@ namespace AutoTx if (_config.SendAdminNotification == false) return; - var delta = DateTime.Now - _status.LastAdminNotification; - if (delta.Minutes < _config.AdminNotificationDelta) + var delta = (int)(DateTime.Now - _status.LastAdminNotification).TotalMinutes; + if (delta < _config.AdminNotificationDelta) { + writeLogDebug("Suppressed admin email, interval too short (" + delta + " vs. " + + _config.AdminNotificationDelta + "):\n\n" + subject + "\n" + body); return; + } if (subject == "") { subject = ServiceName + @@ -103,8 +106,8 @@ namespace AutoTx /// </summary> /// <param name="spaceDetails">String describing the drives being low on space.</param> public void SendLowSpaceMail(string spaceDetails) { - var delta = DateTime.Now - _status.LastStorageNotification; - if (delta.Minutes < _config.StorageNotificationDelta) + var delta = (int)(DateTime.Now - _status.LastStorageNotification).TotalMinutes; + if (delta < _config.StorageNotificationDelta) return; writeLog("WARNING: " + spaceDetails); -- GitLab