diff --git a/ATXCommon/SystemChecks.cs b/ATXCommon/SystemChecks.cs index f7f42358977753af5f361fb0c185654433c33d1f..73e63a44301223b2bae39ba228b583e4b8c2f65a 100644 --- a/ATXCommon/SystemChecks.cs +++ b/ATXCommon/SystemChecks.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Management; @@ -66,6 +67,24 @@ namespace ATXCommon return 0; } + /// <summary> + /// Check all configured disks for their free space and send a notification + /// if necessary (depending on the configured delta time). + /// </summary> + public static string CheckFreeDiskSpace(List<Serializables.DriveToCheck> drives) { + var msg = ""; + foreach (var driveToCheck in drives) { + var freeSpace = SystemChecks.GetFreeDriveSpace(driveToCheck.DriveName); + if (freeSpace >= driveToCheck.SpaceThreshold) + continue; + + msg += "Drive '" + driveToCheck.DriveName + + "' - free space: " + freeSpace + + " (threshold: " + driveToCheck.SpaceThreshold + ")\n"; + } + return msg; + } + /// <summary> /// Check if a user is currently logged into Windows. /// diff --git a/AutoTx/AutoTx.cs b/AutoTx/AutoTx.cs index 2c87db6dc5be5727d4d9cf8be161aa4c7954e7c4..ae91a53e688e0ee7d7392678224e7ef438d19087 100644 --- a/AutoTx/AutoTx.cs +++ b/AutoTx/AutoTx.cs @@ -485,7 +485,7 @@ namespace AutoTx /// </summary> public void RunMainTasks() { // mandatory tasks, run on every call: - CheckFreeDiskSpace(); + SendLowSpaceMail(SystemChecks.CheckFreeDiskSpace(_config.SpaceMonitoring)); UpdateServiceState(); var delta = (int)(DateTime.Now - _lastUserDirCheck).TotalSeconds; diff --git a/AutoTx/Email.cs b/AutoTx/Email.cs index eefb9b28de853da62d23164b58fe41f744691df5..584d54605cfb474044a7fb70dd3c5b66e751bc01 100644 --- a/AutoTx/Email.cs +++ b/AutoTx/Email.cs @@ -106,6 +106,9 @@ namespace AutoTx /// </summary> /// <param name="spaceDetails">String describing the drives being low on space.</param> public void SendLowSpaceMail(string spaceDetails) { + if (string.IsNullOrWhiteSpace(spaceDetails)) + return; + var delta = (int)(DateTime.Now - _status.LastStorageNotification).TotalMinutes; if (delta < _config.StorageNotificationDelta) return; diff --git a/AutoTx/SystemChecks.cs b/AutoTx/SystemChecks.cs index 2364680f51d72df3d93d4a9a14c417fb6139646a..64e744656058ce9beb3065e722aa97be7a169a0b 100644 --- a/AutoTx/SystemChecks.cs +++ b/AutoTx/SystemChecks.cs @@ -6,24 +6,6 @@ namespace AutoTx { public partial class AutoTx { - /// <summary> - /// Check all configured disks for their free space and send a notification - /// if necessary (depending on the configured delta time). - /// </summary> - public void CheckFreeDiskSpace() { - var msg = ""; - foreach (var driveToCheck in _config.SpaceMonitoring) { - var freeSpace = SystemChecks.GetFreeDriveSpace(driveToCheck.DriveName); - if (freeSpace >= driveToCheck.SpaceThreshold) continue; - - msg += "Drive '" + driveToCheck.DriveName + - "' - free space: " + freeSpace + - " (threshold: " + driveToCheck.SpaceThreshold + ")\n"; - } - if (msg != "") - SendLowSpaceMail(msg); - } - /// <summary> /// Compares all processes against the ProcessNames in the BlacklistedProcesses list. /// </summary>