예제 #1
0
        internal void EnterNestedPrompt(InternalCommand callingCommand)
        {
            LocalRunspace localRunspace = (LocalRunspace)null;

            try
            {
                localRunspace = this.Runspace as LocalRunspace;
            }
            catch (PSNotImplementedException ex)
            {
            }
            if (localRunspace != null)
            {
                Pipeline currentlyRunningPipeline = this.Runspace.GetCurrentlyRunningPipeline();
                if (currentlyRunningPipeline != null && currentlyRunningPipeline == localRunspace.PulsePipeline)
                {
                    throw new InvalidOperationException();
                }
            }
            if (this.nestedPromptCount < 0)
            {
                throw InternalHost.tracer.NewInvalidOperationException("InternalHostStrings", "EnterExitNestedPromptOutOfSync");
            }
            ++this.nestedPromptCount;
            this.executionContext.SetVariable("global:NestedPromptLevel", (object)this.nestedPromptCount);
            InternalHost.PromptContextData promptContextData = new InternalHost.PromptContextData();
            promptContextData.SavedContextData = this.executionContext.SaveContextData();
            promptContextData.SavedCurrentlyExecutingCommandVarValue = this.executionContext.GetVariable("CurrentlyExecutingCommand");
            promptContextData.SavedPSBoundParametersVarValue         = this.executionContext.GetVariable("PSBoundParameters");
            promptContextData.RunspaceAvailability = this.Context.CurrentRunspace.RunspaceAvailability;
            if (callingCommand != null)
            {
                PSObject psObject = PSObject.AsPSObject((object)callingCommand);
                psObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("CommandInfo", (object)callingCommand.CommandInfo));
                psObject.Properties.Add((PSPropertyInfo) new PSNoteProperty("StackTrace", (object)new StackTrace()));
                this.executionContext.SetVariable("CurrentlyExecutingCommand", (object)psObject);
            }
            this.contextStack.Push(promptContextData);
            this.executionContext.StepScript = false;
            this.executionContext.PSDebug    = 0;
            this.executionContext.ResetShellFunctionErrorOutputPipe();
            this.Context.CurrentRunspace.UpdateRunspaceAvailability(RunspaceAvailability.AvailableForNestedCommand, true);
            try
            {
                this.externalHostRef.Value.EnterNestedPrompt();
            }
            catch
            {
                this.ExitNestedPromptHelper();
                throw;
            }
        }
예제 #2
0
 private void ExitNestedPromptHelper()
 {
     --this.nestedPromptCount;
     this.executionContext.SetVariable("global:NestedPromptLevel", (object)this.nestedPromptCount);
     if (this.contextStack.Count <= 0)
     {
         return;
     }
     InternalHost.PromptContextData promptContextData = this.contextStack.Pop();
     promptContextData.SavedContextData.RestoreContextData(this.executionContext);
     this.executionContext.SetVariable("CurrentlyExecutingCommand", promptContextData.SavedCurrentlyExecutingCommandVarValue);
     this.executionContext.SetVariable("PSBoundParameters", promptContextData.SavedPSBoundParametersVarValue);
     this.Context.CurrentRunspace.UpdateRunspaceAvailability(promptContextData.RunspaceAvailability, true);
 }