Instead of providing delegates to a ScriptClient singleton, script execution now relies on dependency injection for debugging. This can be handled by registering an implementation of IScriptDebugger. Multiple script debuggers are supported. These changes required the creation of a PowerShellScriptFactory to handle DI of the service provider to the script. In the case of LANCommander, "debugging" scripts really just gives an opportunity for the application to break after a script's execution and provide a poor-man's pty. This could be expanded upon in the future to hook directly into PowerShell's debugging functionality, but would require a substantial refactor to script execution.
32 lines
No EOL
997 B
C#
32 lines
No EOL
997 B
C#
using LANCommander.SDK.PowerShell;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace LANCommander.Launcher.Services.PowerShell;
|
|
|
|
public class ScriptDebugger : IScriptDebugger
|
|
{
|
|
public Func<System.Management.Automation.PowerShell, Task> OnDebugStart;
|
|
public Func<System.Management.Automation.PowerShell, Task> OnDebugBreak;
|
|
public Func<System.Management.Automation.PowerShell, Task> OnDebugEnd;
|
|
public Func<LogLevel, string, Task> OnOutput;
|
|
|
|
public async Task StartAsync(System.Management.Automation.PowerShell ps)
|
|
{
|
|
await OnDebugStart?.Invoke(ps)!;
|
|
}
|
|
|
|
public async Task EndAsync(System.Management.Automation.PowerShell ps)
|
|
{
|
|
await OnDebugEnd?.Invoke(ps)!;
|
|
}
|
|
|
|
public async Task BreakAsync(System.Management.Automation.PowerShell ps)
|
|
{
|
|
await OnDebugBreak?.Invoke(ps)!;
|
|
}
|
|
|
|
public async Task OutputAsync(LogLevel level, string message, params object[] args)
|
|
{
|
|
await OnOutput?.Invoke(level, message)!;
|
|
}
|
|
} |