SetSuccessVariable() private method

private SetSuccessVariable ( bool success ) : void
success bool
return void
Ejemplo n.º 1
0
        private Collection <PSObject> ExecuteScriptInSessionState(string path, SessionState sessionState)
        {
            var scriptBlock     = new ExternalScriptInfo(path, ScopeUsages.CurrentScope).ScriptBlock;
            var originalContext = _executionContext;
            var scopedContext   = _executionContext.Clone(sessionState, ScopeUsages.CurrentScope);

            try
            {
                // actually change the scope by changing the execution context
                // there should definitely be a nicer way for this #ExecutionContextChange
                _executionContext = scopedContext;
                _executionContext.CurrentRunspace.ExecutionContext = scopedContext;
                return(scriptBlock.Invoke()); // TODO: pass parameters if set
            }
            catch (ExitException e)
            {
                var exitCode = LanguagePrimitives.ConvertTo <int>(e.Argument);
                _executionContext.SetLastExitCodeVariable(exitCode);
                _executionContext.SetSuccessVariable(exitCode == 0);
                return(new Collection <PSObject>()
                {
                    PSObject.AsPSObject(e.Argument)
                });
            }
            finally
            {
                // restore original context / scope
                _executionContext.CurrentRunspace.ExecutionContext = originalContext;
                _executionContext = originalContext;
            }
        }
Ejemplo n.º 2
0
        private void ProcessExited(object sender, System.EventArgs e)
        {
            ExecutionContext.SetLastExitCodeVariable(_process.ExitCode);
            ExecutionContext.SetSuccessVariable(_process.ExitCode == 0); // PS also just compares against null

            _process.Dispose();
            _process = null;
        }
Ejemplo n.º 3
0
 public override void EndProcessing()
 {
     // TODO: process end clause. remember to switch scope
     ExecutionContext.SetSuccessVariable(_exitCode == null || _exitCode == 0);
 }
Ejemplo n.º 4
0
 private Collection<PSObject> ExecuteScriptInSessionState(string path, SessionState sessionState)
 {
     var scriptBlock = new ExternalScriptInfo(path, ScopeUsages.CurrentScope).ScriptBlock;
     var originalContext = _executionContext;
     var scopedContext = _executionContext.Clone(sessionState, ScopeUsages.CurrentScope);
     try
     {
         // actually change the scope by changing the execution context
         // there should definitely be a nicer way for this #ExecutionContextChange
         _executionContext = scopedContext;
         _executionContext.CurrentRunspace.ExecutionContext = scopedContext;
         return scriptBlock.Invoke(); // TODO: pass parameters if set
     }
     catch (ExitException e)
     {
         var exitCode = LanguagePrimitives.ConvertTo<int>(e.Argument);
         _executionContext.SetLastExitCodeVariable(exitCode);
         _executionContext.SetSuccessVariable(exitCode == 0);
         return new Collection<PSObject>() { PSObject.AsPSObject(e.Argument) };
     }
     finally
     {
         // restore original context / scope
         _executionContext.CurrentRunspace.ExecutionContext = originalContext;
         _executionContext = originalContext;
     }
 }
Ejemplo n.º 5
0
        public override Collection <PSObject> Invoke(IEnumerable input)
        {
            // TODO: run the pipeline on another thread and wait for the completion
            // TODO: nested pipelines: make sure we are running in the same thread as another pipeline, because
            // nested pipelines aren't allowed to run in their own thread. This ensures that there is a "parent" pipeline

            Input.Write(input, true);

            // in a pipeline, the first command enters *always* the ProcessRecord phase, the following commands only
            // if the previous command generated output. To make sure the first command enters that phase, add null
            // if nothing else is in the input stream
            if (_inputStream.Count == 0)
            {
                Input.Write(null);
            }

            ExecutionContext context = _runspace.ExecutionContext.Clone();

            RerouteExecutionContext(context);
            try
            {
                if (!_pipelineStateInfo.State.Equals(PipelineState.NotStarted))
                {
                    throw new InvalidPipelineStateException("Pipeline cannot be started",
                                                            _pipelineStateInfo.State, PipelineState.NotStarted);
                }

                var pipelineProcessor = BuildPipelineProcessor(context);

                _runspace.AddRunningPipeline(this);
                SetPipelineState(PipelineState.Running);

                pipelineProcessor.Execute(context);
                SetPipelineState(PipelineState.Completed);
            }
            catch (FlowControlException ex)
            {
                if (IsNested)
                {
                    throw; // propagate to parent levels
                }
                if (ex is ExitException)
                {
                    // exit code must be an int. otherwise it's 0
                    int exitCode = 0;
                    LanguagePrimitives.TryConvertTo <int>(((ExitException)ex).Argument, out exitCode);
                    _runspace.PSHost.SetShouldExit(exitCode);
                }
                // at this point we are in the toplevel pipeline and we got a "return", "break", or "continue".
                // The behavior for this is that the pipeline stops (that's why we're here), but nothing else
            }
            catch (Exception ex)
            {
                // in case of throw statement, parse error, or "ThrowTerminatingError"
                // just add to error variable, the error stream and rethrow that thing
                context.AddToErrorVariable(ex);
                context.SetSuccessVariable(false); // last command was definitely not successfull
                throw;
            }
            _runspace.RemoveRunningPipeline(this);
            return(Output.NonBlockingRead());
        }