1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

fixed GetProcessByName in mono.

This commit is contained in:
Keivan Beigi 2013-07-26 17:56:49 -07:00
parent 5a52de7ba9
commit bedbfc6c92

View File

@ -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<ProcessInfo> GetProcessByName(string name)
{
if (OsInfo.IsMono)
{
var mono = Process.GetProcessesByName("mono");
return mono.Where(process => process.Modules.Cast<ProcessModule>().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)
{