本文整理汇总了C#中PowerShell.InvokeWithDebugger方法的典型用法代码示例。如果您正苦于以下问题:C# PowerShell.InvokeWithDebugger方法的具体用法?C# PowerShell.InvokeWithDebugger怎么用?C# PowerShell.InvokeWithDebugger使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PowerShell
的用法示例。
在下文中一共展示了PowerShell.InvokeWithDebugger方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessCommand
/// <summary>
/// ProcessCommand
/// </summary>
/// <param name="command">PowerShell command</param>
/// <param name="output">Output</param>
/// <returns>DebuggerCommandResults</returns>
public override DebuggerCommandResults ProcessCommand(PSCommand command, PSDataCollection<PSObject> output)
{
if (command == null)
{
throw new PSArgumentNullException("command");
}
if (output == null)
{
throw new PSArgumentNullException("output");
}
if (!DebuggerStopped)
{
throw new PSInvalidOperationException(
DebuggerStrings.CannotProcessDebuggerCommandNotStopped,
null,
Debugger.CannotProcessCommandNotStopped,
ErrorCategory.InvalidOperation,
null);
}
//
// Allow an active pushed debugger to process commands
//
DebuggerCommandResults results = ProcessCommandForActiveDebugger(command, output);
if (results != null)
{
return results;
}
//
// Otherwise let root script debugger handle it.
//
LocalRunspace localRunspace = _context.CurrentRunspace as LocalRunspace;
if (localRunspace == null)
{
throw new PSInvalidOperationException(
DebuggerStrings.CannotProcessDebuggerCommandNotStopped,
null,
Debugger.CannotProcessCommandNotStopped,
ErrorCategory.InvalidOperation,
null);
}
try
{
using (_psDebuggerCommand = PowerShell.Create())
{
if (localRunspace.GetCurrentlyRunningPipeline() != null)
{
_psDebuggerCommand.SetIsNested(true);
}
_psDebuggerCommand.Runspace = localRunspace;
_psDebuggerCommand.Commands = command;
foreach (var cmd in _psDebuggerCommand.Commands.Commands)
{
cmd.MergeMyResults(PipelineResultTypes.All, PipelineResultTypes.Output);
}
PSDataCollection<PSObject> internalOutput = new PSDataCollection<PSObject>();
internalOutput.DataAdded += (sender, args) =>
{
foreach (var item in internalOutput.ReadAll())
{
if (item == null) { continue; }
DebuggerCommand dbgCmd = item.BaseObject as DebuggerCommand;
if (dbgCmd != null)
{
bool executedByDebugger = (dbgCmd.ResumeAction != null || dbgCmd.ExecutedByDebugger);
results = new DebuggerCommandResults(dbgCmd.ResumeAction, executedByDebugger);
}
else
{
output.Add(item);
}
}
};
// Allow any exceptions to propagate.
_psDebuggerCommand.InvokeWithDebugger(null, internalOutput, null, false);
}
}
finally
{
_psDebuggerCommand = null;
}
return results ?? new DebuggerCommandResults(null, false);
}