From a6d00d788c220f71cf932d57bcf39a1892a8421c Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch> Date: Thu, 18 Jan 2018 15:27:42 +0100 Subject: [PATCH] Move CheckForBlacklistedProcesses to SystemChecks. --- ATXCommon/SystemChecks.cs | 23 ++++++++++++++++++++++- AutoTx/ATXProject.csproj | 3 --- AutoTx/AutoTx.cs | 3 ++- AutoTx/SystemChecks.cs | 29 ----------------------------- 4 files changed, 24 insertions(+), 34 deletions(-) delete mode 100644 AutoTx/SystemChecks.cs diff --git a/ATXCommon/SystemChecks.cs b/ATXCommon/SystemChecks.cs index 73e63a4..29abc61 100644 --- a/ATXCommon/SystemChecks.cs +++ b/ATXCommon/SystemChecks.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Management; @@ -74,7 +75,7 @@ namespace ATXCommon public static string CheckFreeDiskSpace(List<Serializables.DriveToCheck> drives) { var msg = ""; foreach (var driveToCheck in drives) { - var freeSpace = SystemChecks.GetFreeDriveSpace(driveToCheck.DriveName); + var freeSpace = GetFreeDriveSpace(driveToCheck.DriveName); if (freeSpace >= driveToCheck.SpaceThreshold) continue; @@ -85,6 +86,26 @@ namespace ATXCommon return msg; } + /// <summary> + /// Compares all processes against the ProcessNames in the BlacklistedProcesses list. + /// </summary> + /// <returns>Returns the name of the first matching process, an empty string otherwise.</returns> + public static string CheckForBlacklistedProcesses(List<string> processNames) { + foreach (var running in Process.GetProcesses()) { + try { + foreach (var blacklisted in processNames) { + if (running.ProcessName.ToLower().Equals(blacklisted)) { + return blacklisted; + } + } + } + catch (Exception ex) { + Log.Warn("Error in checkProcesses(): {0}", ex.Message); + } + } + return ""; + } + /// <summary> /// Check if a user is currently logged into Windows. /// diff --git a/AutoTx/ATXProject.csproj b/AutoTx/ATXProject.csproj index 9612115..aa53c59 100644 --- a/AutoTx/ATXProject.csproj +++ b/AutoTx/ATXProject.csproj @@ -103,9 +103,6 @@ <Compile Include="RoboCommand.cs"> <SubType>Component</SubType> </Compile> - <Compile Include="SystemChecks.cs"> - <SubType>Component</SubType> - </Compile> </ItemGroup> <ItemGroup> <None Include="App.config" /> diff --git a/AutoTx/AutoTx.cs b/AutoTx/AutoTx.cs index 374b38c..f5b722b 100644 --- a/AutoTx/AutoTx.cs +++ b/AutoTx/AutoTx.cs @@ -446,7 +446,8 @@ namespace AutoTx else if (SystemChecks.GetFreeMemory() < _config.MinAvailableMemory) limitReason = "RAM usage"; else { - var blacklistedProcess = CheckForBlacklistedProcesses(); + var blacklistedProcess = SystemChecks.CheckForBlacklistedProcesses( + _config.BlacklistedProcesses); if (blacklistedProcess != "") { limitReason = "blacklisted process '" + blacklistedProcess + "'"; } diff --git a/AutoTx/SystemChecks.cs b/AutoTx/SystemChecks.cs deleted file mode 100644 index 64e7446..0000000 --- a/AutoTx/SystemChecks.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Diagnostics; -using ATXCommon; - -namespace AutoTx -{ - public partial class AutoTx - { - /// <summary> - /// Compares all processes against the ProcessNames in the BlacklistedProcesses list. - /// </summary> - /// <returns>Returns the name of the first matching process, an empty string otherwise.</returns> - public string CheckForBlacklistedProcesses() { - foreach (var running in Process.GetProcesses()) { - try { - foreach (var blacklisted in _config.BlacklistedProcesses) { - if (running.ProcessName.ToLower().Equals(blacklisted)) { - return blacklisted; - } - } - } - catch (Exception ex) { - Log.Warn("Error in checkProcesses(): {0}", ex.Message); - } - } - return ""; - } - } -} \ No newline at end of file -- GitLab