From c218ade5254b3756a3cdecf33a334672e129ed3f Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Thu, 18 Jan 2018 00:44:23 +0100
Subject: [PATCH] Make CheckFreeDiskSpace static and move to
 ATXCommon.SystemChecks.

---
 ATXCommon/SystemChecks.cs | 19 +++++++++++++++++++
 AutoTx/AutoTx.cs          |  2 +-
 AutoTx/Email.cs           |  3 +++
 AutoTx/SystemChecks.cs    | 18 ------------------
 4 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/ATXCommon/SystemChecks.cs b/ATXCommon/SystemChecks.cs
index f7f4235..73e63a4 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 2c87db6..ae91a53 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 eefb9b2..584d546 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 2364680..64e7446 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>
-- 
GitLab