public IEnumerable <TResult> ExecuteCommandInDebugger <TResult>( PowerShellContext powerShellContext, Runspace currentRunspace, PSCommand psCommand, bool sendOutputToHost) { PSDataCollection <PSObject> outputCollection = new PSDataCollection <PSObject>(); #if !PowerShellv3 if (sendOutputToHost) { outputCollection.DataAdded += (obj, e) => { for (int i = e.Index; i < outputCollection.Count; i++) { powerShellContext.WriteOutput( outputCollection[i].ToString(), true); } }; } DebuggerCommandResults commandResults = currentRunspace.Debugger.ProcessCommand( psCommand, outputCollection); #endif return (outputCollection .Select(pso => pso.BaseObject) .Cast <TResult>()); }
public IEnumerable <TResult> ExecuteCommandInDebugger <TResult>( PowerShellContext powerShellContext, Runspace currentRunspace, PSCommand psCommand, bool sendOutputToHost) { IEnumerable <TResult> executionResult = null; using (var nestedPipeline = currentRunspace.CreateNestedPipeline()) { foreach (var command in psCommand.Commands) { nestedPipeline.Commands.Add(command); } executionResult = nestedPipeline .Invoke() .Select(pso => pso.BaseObject) .Cast <TResult>(); } // Write the output to the host if necessary if (sendOutputToHost) { foreach (var line in executionResult) { powerShellContext.WriteOutput(line.ToString(), true); } } return(executionResult); }
public IEnumerable <TResult> ExecuteCommandInDebugger <TResult>( PowerShellContext powerShellContext, Runspace currentRunspace, PSCommand psCommand, bool sendOutputToHost, out DebuggerResumeAction?debuggerResumeAction) { debuggerResumeAction = null; PSDataCollection <PSObject> outputCollection = new PSDataCollection <PSObject>(); #if !PowerShellv3 if (sendOutputToHost) { outputCollection.DataAdded += (obj, e) => { for (int i = e.Index; i < outputCollection.Count; i++) { powerShellContext.WriteOutput( outputCollection[i].ToString(), true); } }; } DebuggerCommandResults commandResults = currentRunspace.Debugger.ProcessCommand( psCommand, outputCollection); // Pass along the debugger's resume action if the user's // command caused one to be returned debuggerResumeAction = commandResults.ResumeAction; #endif IEnumerable <TResult> results = null; if (typeof(TResult) != typeof(PSObject)) { results = outputCollection .Select(pso => pso.BaseObject) .Cast <TResult>(); } else { results = outputCollection.Cast <TResult>(); } return(results); }