Skip to content
Snippets Groups Projects
Commit c218ade5 authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Make CheckFreeDiskSpace static and move to ATXCommon.SystemChecks.

parent 479f8edc
No related branches found
No related tags found
No related merge requests found
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Management; using System.Management;
...@@ -66,6 +67,24 @@ namespace ATXCommon ...@@ -66,6 +67,24 @@ namespace ATXCommon
return 0; 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> /// <summary>
/// Check if a user is currently logged into Windows. /// Check if a user is currently logged into Windows.
/// ///
......
...@@ -485,7 +485,7 @@ namespace AutoTx ...@@ -485,7 +485,7 @@ namespace AutoTx
/// </summary> /// </summary>
public void RunMainTasks() { public void RunMainTasks() {
// mandatory tasks, run on every call: // mandatory tasks, run on every call:
CheckFreeDiskSpace(); SendLowSpaceMail(SystemChecks.CheckFreeDiskSpace(_config.SpaceMonitoring));
UpdateServiceState(); UpdateServiceState();
var delta = (int)(DateTime.Now - _lastUserDirCheck).TotalSeconds; var delta = (int)(DateTime.Now - _lastUserDirCheck).TotalSeconds;
......
...@@ -106,6 +106,9 @@ namespace AutoTx ...@@ -106,6 +106,9 @@ namespace AutoTx
/// </summary> /// </summary>
/// <param name="spaceDetails">String describing the drives being low on space.</param> /// <param name="spaceDetails">String describing the drives being low on space.</param>
public void SendLowSpaceMail(string spaceDetails) { public void SendLowSpaceMail(string spaceDetails) {
if (string.IsNullOrWhiteSpace(spaceDetails))
return;
var delta = (int)(DateTime.Now - _status.LastStorageNotification).TotalMinutes; var delta = (int)(DateTime.Now - _status.LastStorageNotification).TotalMinutes;
if (delta < _config.StorageNotificationDelta) if (delta < _config.StorageNotificationDelta)
return; return;
......
...@@ -6,24 +6,6 @@ namespace AutoTx ...@@ -6,24 +6,6 @@ namespace AutoTx
{ {
public partial class 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> /// <summary>
/// Compares all processes against the ProcessNames in the BlacklistedProcesses list. /// Compares all processes against the ProcessNames in the BlacklistedProcesses list.
/// </summary> /// </summary>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment