Add project files.
This commit is contained in:
33
LeagueAPI/Utils/ProcessInfo.cs
Normal file
33
LeagueAPI/Utils/ProcessInfo.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user