public override int EnumPorts(out IEnumDebugPorts2 ppEnum) { ThreadHelper.ThrowIfNotOnUIThread(); if (_distros == null) { IVsUIShell shell = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell; try { WSLCommandLine.EnsureInitialized(); _distros = WSLCommandLine.GetInstalledDistros(); } catch (Exception ex) { shell.SetErrorInfo(ex.HResult, ex.Message, 0, null, null); shell.ReportErrorInfo(ex.HResult); ppEnum = null; return(VSConstants.E_ABORT); } } WSLPort[] ports = _distros.Select(name => new WSLPort(this, name, isInAddPort: false)).ToArray(); ppEnum = new AD7PortEnum(ports); return(HR.S_OK); }
/// <inheritdoc/> public override void BeginExecuteAsyncCommand(string commandText, bool runInShell, IDebugUnixShellCommandCallback callback, out IDebugUnixShellAsyncCommand asyncCommand) { if (IsClosed) { throw new ObjectDisposedException(nameof(WSLConnection)); } string args = WSLCommandLine.GetExecCommandLineArgs(this.Name, commandText); ICommandRunner commandRunner = LocalCommandRunner.CreateInstance(handleRawOutput: runInShell == false, WSLCommandLine.ExePath, args); asyncCommand = new PipeAsyncCommand(commandRunner, callback); }
/// <inheritdoc/> public override int ExecuteCommand(string commandText, int timeout, out string commandOutput, out string errorMessage) { using (var cancellationTokenSource = new CancellationTokenSource()) { Task <ProcessResult> task = LocalProcessAsyncRunner.ExecuteProcessAsync(WSLCommandLine.GetExecStartInfo(this.Name, commandText), cancellationTokenSource.Token); #pragma warning disable VSTHRD002 // Avoid problematic synchronous waits if (!task.Wait(timeout)) { cancellationTokenSource.Cancel(); throw new TimeoutException(); } ProcessResult result = task.Result; #pragma warning restore VSTHRD002 // Avoid problematic synchronous waits commandOutput = string.Join("\n", result.StdOut); errorMessage = string.Join("\n", result.StdErr); return(result.ExitCode); } }