34 lines
884 B
C#
34 lines
884 B
C#
using System.Diagnostics;
|
|
|
|
namespace LeagueAPI.Utils;
|
|
|
|
public class ProcessInfo
|
|
{
|
|
private static readonly List<IPortTokenBehavior> Behaviors =
|
|
[
|
|
new PortTokenWithLockfile(),
|
|
new PortTokenWithProcessList(),
|
|
];
|
|
|
|
public int AppPort { get; }
|
|
public string RemotingAuthToken { get; }
|
|
|
|
internal ProcessInfo(Process process)
|
|
{
|
|
List<Exception> exceptions = [];
|
|
foreach (IPortTokenBehavior behavior in Behaviors)
|
|
{
|
|
if (behavior.TryGet(process, out string remotingAuthToken, out int appPort, out Exception? exception))
|
|
{
|
|
RemotingAuthToken = remotingAuthToken;
|
|
AppPort = appPort;
|
|
return;
|
|
}
|
|
|
|
exceptions.Add(exception);
|
|
}
|
|
|
|
throw new AggregateException("Unable to obtain process information.", exceptions);
|
|
}
|
|
}
|