diff --git a/src/Artemis.Core/Plugins/Modules/ActivationRequirements/ProcessActivationRequirement.cs b/src/Artemis.Core/Plugins/Modules/ActivationRequirements/ProcessActivationRequirement.cs
index b9b4329c0..aa553ba4a 100644
--- a/src/Artemis.Core/Plugins/Modules/ActivationRequirements/ProcessActivationRequirement.cs
+++ b/src/Artemis.Core/Plugins/Modules/ActivationRequirements/ProcessActivationRequirement.cs
@@ -38,16 +38,7 @@ public class ProcessActivationRequirement : IModuleActivationRequirement
///
public bool Evaluate()
{
- if (!ProcessMonitor.IsStarted || (ProcessName == null && Location == null))
- return false;
-
- IEnumerable processes = ProcessMonitor.Processes;
- if (ProcessName != null)
- processes = processes.Where(p => string.Equals(p.ProcessName, ProcessName, StringComparison.InvariantCultureIgnoreCase));
- if (Location != null)
- processes = processes.Where(p => string.Equals(Path.GetDirectoryName(p.Executable), Location, StringComparison.InvariantCultureIgnoreCase));
-
- return processes.Any();
+ return ProcessMonitor.IsProcessRunning(ProcessName, Location);
}
///
diff --git a/src/Artemis.Core/Services/ProcessMonitoring/ProcessMonitor.cs b/src/Artemis.Core/Services/ProcessMonitoring/ProcessMonitor.cs
index ee265e90d..743e70416 100644
--- a/src/Artemis.Core/Services/ProcessMonitoring/ProcessMonitor.cs
+++ b/src/Artemis.Core/Services/ProcessMonitoring/ProcessMonitor.cs
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
+using System.IO;
using System.Linq;
+using System.Numerics;
using System.Threading;
namespace Artemis.Core.Services;
@@ -99,6 +101,23 @@ public static partial class ProcessMonitor
FreeBuffer();
}
}
+
+ ///
+ /// Returns whether the specified process is running
+ ///
+ /// The name of the process to check
+ /// The location of where the process must be running from (optional)
+ ///
+ public static bool IsProcessRunning(string? processName = null, string? processLocation = null)
+ {
+ if (!IsStarted || (processName == null && processLocation == null))
+ return false;
+
+ lock (LOCK)
+ {
+ return _processes.Values.Any(x => Match(x, processName, processLocation));
+ }
+ }
// ReSharper disable once SuggestBaseTypeForParameter
private static void HandleStoppedProcesses(HashSet currentProcessIds)
@@ -112,6 +131,21 @@ public static partial class ProcessMonitor
OnProcessStopped(info);
}
}
+
+ private static bool Match(ProcessInfo info, string? processName, string? processLocation)
+ {
+ if (processName != null && processLocation != null)
+ return string.Equals(info.ProcessName, processName, StringComparison.InvariantCultureIgnoreCase) &&
+ string.Equals(Path.GetDirectoryName(info.Executable), processLocation, StringComparison.InvariantCultureIgnoreCase);
+
+ if (processName != null)
+ return string.Equals(info.ProcessName, processName, StringComparison.InvariantCultureIgnoreCase);
+
+ if (processLocation != null)
+ return string.Equals(Path.GetDirectoryName(info.Executable), processLocation, StringComparison.InvariantCultureIgnoreCase);
+
+ return false;
+ }
private static void OnProcessStarted(ProcessInfo processInfo)
{