本文整理汇总了C#中PowerShell.SetIsNested方法的典型用法代码示例。如果您正苦于以下问题:C# PowerShell.SetIsNested方法的具体用法?C# PowerShell.SetIsNested怎么用?C# PowerShell.SetIsNested使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PowerShell
的用法示例。
在下文中一共展示了PowerShell.SetIsNested方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNewCompletionResults
private CommandCompletion GetNewCompletionResults(string input)
{
try
{
var runspace = _parent.Runspace;
var debugger = runspace.Debugger;
if ((debugger != null) && debugger.InBreakpoint)
{
// If in debug stop mode do command completion though debugger process command.
try
{
return CommandCompletion.CompleteInputInDebugger(input, input.Length, null, debugger);
}
catch (PSInvalidOperationException)
{ }
}
if (runspace is LocalRunspace &&
runspace.ExecutionContext.EngineHostInterface.NestedPromptCount > 0)
{
_commandCompletionPowerShell = PowerShell.Create(RunspaceMode.CurrentRunspace);
}
else
{
_commandCompletionPowerShell = PowerShell.Create();
_commandCompletionPowerShell.SetIsNested(_parent.IsNested);
_commandCompletionPowerShell.Runspace = runspace;
}
return CommandCompletion.CompleteInput(input, input.Length, null, _commandCompletionPowerShell);
}
finally
{
_commandCompletionPowerShell = null;
}
}
示例2: RemotePipeline
/// <summary>
/// Constructs a remote pipeline for the specified runspace and
/// specified command
/// </summary>
/// <param name="runspace">runspace in which to create the pipeline</param>
/// <param name="command">command as a string, to be used in pipeline creation</param>
/// <param name="addToHistory">whether to add the command to the runspaces history</param>
/// <param name="isNested">whether this pipeline is nested</param>
internal RemotePipeline(RemoteRunspace runspace, string command, bool addToHistory, bool isNested)
: this(runspace, addToHistory, isNested)
{
if (command != null)
{
_commands.Add(new Command(command, true));
}
// initialize the underlying powershell object
_powershell = new PowerShell(_inputStream, _outputStream, _errorStream,
((RemoteRunspace)_runspace).RunspacePool);
_powershell.SetIsNested(isNested);
_powershell.InvocationStateChanged +=
new EventHandler<PSInvocationStateChangedEventArgs>(HandleInvocationStateChanged);
}
示例3: StartPowerShellCommand
internal void StartPowerShellCommand(
PowerShell powershell,
Guid powershellId,
Guid runspacePoolId,
ServerRunspacePoolDriver runspacePoolDriver,
#if !CORECLR // No ApartmentState In CoreCLR
ApartmentState apartmentState,
#endif
ServerRemoteHost remoteHost,
HostInfo hostInfo,
RemoteStreamOptions streamOptions,
bool addToHistory)
{
// For nested debugger command processing, invoke command on new local runspace since
// the root script debugger runspace is unavailable (it is running a PS script or a
// workflow function script).
Runspace runspace = (remoteHost != null) ?
RunspaceFactory.CreateRunspace(remoteHost) : RunspaceFactory.CreateRunspace();
runspace.Open();
try
{
powershell.InvocationStateChanged += HandlePowerShellInvocationStateChanged;
powershell.SetIsNested(false);
string script = @"
param ($Debugger, $Commands, $output)
trap { throw $_ }
$Debugger.ProcessCommand($Commands, $output)
";
PSDataCollection<PSObject> output = new PSDataCollection<PSObject>();
PSCommand Commands = new PSCommand(powershell.Commands);
powershell.Commands.Clear();
powershell.AddScript(script).AddParameter("Debugger", this).AddParameter("Commands", Commands).AddParameter("output", output);
ServerPowerShellDriver driver = new ServerPowerShellDriver(
powershell,
null,
true,
powershellId,
runspacePoolId,
runspacePoolDriver,
#if !CORECLR // No ApartmentState In CoreCLR
apartmentState,
#endif
hostInfo,
streamOptions,
addToHistory,
runspace,
output);
driver.Start();
}
catch (Exception e)
{
CommandProcessorBase.CheckForSevereException(e);
runspace.Close();
runspace.Dispose();
}
}
示例4: 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);
}