From bedbfc6c9217ddea2282da0ab7da7675f42787e7 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Fri, 26 Jul 2013 17:56:49 -0700 Subject: [PATCH] fixed GetProcessByName in mono. --- NzbDrone.Common/ProcessProvider.cs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/NzbDrone.Common/ProcessProvider.cs b/NzbDrone.Common/ProcessProvider.cs index 4409d1ba4..14486f421 100644 --- a/NzbDrone.Common/ProcessProvider.cs +++ b/NzbDrone.Common/ProcessProvider.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.Linq; using NLog; +using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Model; namespace NzbDrone.Common @@ -50,6 +51,14 @@ public ProcessInfo GetProcessById(int id) public IEnumerable GetProcessByName(string name) { + if (OsInfo.IsMono) + { + var mono = Process.GetProcessesByName("mono"); + + return mono.Where(process => process.Modules.Cast().Any(module => module.ModuleName.ToLower() == name + ".exe")) + .Select(ConvertToProcessInfo); + } + return Process.GetProcessesByName(name).Select(ConvertToProcessInfo).Where(p => p != null); } @@ -91,6 +100,17 @@ public void SetPriority(int processId, ProcessPriorityClass priority) process.PriorityClass = priority; } + public void KillAll(string processName) + { + var processToKill = GetProcessByName(processName); + + foreach (var processInfo in processToKill) + { + Kill(processInfo.Id); + } + } + + private static ProcessInfo ConvertToProcessInfo(Process process) { if (process == null || process.Id <= 0 || process.HasExited) return null; @@ -104,15 +124,7 @@ private static ProcessInfo ConvertToProcessInfo(Process process) }; } - public void KillAll(string processName) - { - var processToKill = GetProcessByName(processName); - foreach (var processInfo in processToKill) - { - Kill(processInfo.Id); - } - } private void Kill(int processId) {