コード例 #1
0
ファイル: PipelineCommandRuntime.cs プロジェクト: mauve/Pash
 // TODO: hook the runtime to the Host for Debug and Error output
 internal PipelineCommandRuntime(PipelineProcessor pipelineProcessor)
 {
     PipelineProcessor = pipelineProcessor;
     MergeErrorToOutput = false;
     MergeUnclaimedPreviousErrors = false;
     OutputStream = new ObjectStream(this);
     ErrorStream = new ObjectStream(this);
     InputStream = new ObjectStream(this);
 }
コード例 #2
0
        public void When_processing_succeeds_processed_event_is_fired()
        {
            bool eventFired = false;
            var pipelineProcessor = new PipelineProcessor(new SucceedingEventProcessor());
            pipelineProcessor.EventProcessed += (s, e) => eventFired = true;
            
            pipelineProcessor.ProcessNext(_element);

            Assert.IsTrue(eventFired);
        }
コード例 #3
0
        public void When_processing_fails_processed_event_is_not_fired()
        {
            bool eventFired = false;
            var pipelineProcessor = new PipelineProcessor(new FailingEventProcessor());
            pipelineProcessor.EventProcessed += (s, e) => eventFired = true;

            pipelineProcessor.ProcessNext(_element);

            Assert.IsFalse(eventFired);
        }
コード例 #4
0
ファイル: BaseCommand.cs プロジェクト: theathos/synity-Shell
        private void DelayedInternalInitialize()
        {
            _pp = new PipelineProcessor();

            CmdletInfo cmdletInfo = new CmdletInfo(_commandName, _commandType, null, null, _context);

            CommandProcessor cp = new CommandProcessor(cmdletInfo, _context);

            foreach (CommandParameterInternal par in _commandParameterList)
            {
                cp.AddParameter(par);
            }

            _pp.Add(cp);
        }
コード例 #5
0
 internal void Push(PipelineProcessor item)
 {
     if (item == null)
     {
         throw PSTraceSource.NewArgumentNullException("item");
     }
     lock (this._syncRoot)
     {
         if (this._stopping)
         {
             PipelineStoppedException exception = new PipelineStoppedException();
             throw exception;
         }
         this._stack.Push(item);
     }
     item.LocalPipeline = this._localPipeline;
 }
コード例 #6
0
        public async Task BeginProcessingMessageAsyncSingleDoNotProcess()
        {
            var pipeline = new PipelineProcessor(new OnMessageOptions());
            var message  = new BrokeredMessage();
            var token    = new CancellationTokenSource();
            var entered  = false;

            pipeline.Add(async(ctx, next, cancel) =>
            {
                entered = true;
                await Task.Delay(0);
            });

            var result = await pipeline.BeginProcessingMessageAsync(message, token.Token);

            Assert.IsFalse(result);
            Assert.IsTrue(entered);
        }
コード例 #7
0
 internal void Pop(bool fromSteppablePipeline)
 {
     lock (this._syncRoot)
     {
         if (!this._stopping && (this._stack.Count > 0))
         {
             PipelineProcessor processor = this._stack.Pop();
             if ((fromSteppablePipeline && processor.ExecutionFailed) && (this._stack.Count > 0))
             {
                 this._stack.Peek().ExecutionFailed = true;
             }
             if ((this._stack.Count == 1) && (this._localPipeline != null))
             {
                 this._localPipeline.SetHadErrors(processor.ExecutionFailed);
             }
         }
     }
 }
コード例 #8
0
        private PipelineProcessor CreatePipelineProcessor()
        {
            CommandCollection commands = this.Commands;

            if (commands == null || commands.Count == 0)
            {
                throw LocalPipeline._trace.NewInvalidOperationException("Runspace", "NoCommandInPipeline");
            }
            PipelineProcessor pipelineProcessor = new PipelineProcessor();

            pipelineProcessor.TopLevel = true;
            bool flag = false;

            try
            {
                foreach (Command command in (Collection <Command>)commands)
                {
                    CommandProcessorBase commandProcessor = command.CreateCommandProcessor(this.LocalRunspace.ExecutionContext, this.LocalRunspace.CommandFactory, this.AddToHistory);
                    commandProcessor.RedirectShellErrorOutputPipe = this.RedirectShellErrorOutputPipe;
                    pipelineProcessor.Add(commandProcessor);
                }
                return(pipelineProcessor);
            }
            catch (RuntimeException ex)
            {
                flag = true;
                throw;
            }
            catch (Exception ex)
            {
                flag = true;
                CommandProcessorBase.CheckForSevereException(ex);
                throw new RuntimeException(ResourceManagerCache.GetResourceString("Pipeline", "CannotCreatePipeline"), ex);
            }
            finally
            {
                if (flag)
                {
                    pipelineProcessor.Dispose();
                }
            }
        }
コード例 #9
0
        internal Pipe GetRedirectionPipe(ExecutionContext context)
        {
            if (this._location == null)
            {
                return((Pipe)null);
            }
            string stringParser = PSObject.ToStringParser(context, this._location.Execute(context));

            if (string.IsNullOrEmpty(stringParser))
            {
                return new Pipe()
                       {
                           NullPipe = true
                       }
            }
            ;
            PipelineProcessor outputPipeline = this.BuildRedirectionPipeline(stringParser, context);

            return(new Pipe(context, outputPipeline));
        }
        /// <summary>
        /// 1. parse command line
        /// 2. execute command or error
        ///     A. internal command (modules)
        ///     B. underlying shell command
        ///     C. unknown command
        /// </summary>
        /// <param name="expr">expression to be evaluated</param>
        /// <returns>return code</returns>
        public ExpressionEvaluationResult Eval(
            CommandEvaluationContext context,
            string expr,
            int outputX)
        {
            var  pipelineParseResults = Parse(context, _syntaxAnalyzer, expr);
            bool allValid             = true;
            var  evalParses           = new List <ExpressionEvaluationResult>();

            foreach (var pipelineParseResult in pipelineParseResults)
            {
                allValid &= pipelineParseResult.ParseResult.ParseResultType == ParseResultType.Valid;
                var evalRes = EvalParse(context, expr, outputX, pipelineParseResult.ParseResult);
                evalParses.Add(evalRes);
            }
            if (!allValid)
            {
                return(evalParses.FirstOrDefault());
            }
            return(PipelineProcessor.RunPipeline(context, pipelineParseResults.FirstOrDefault()));
        }
コード例 #11
0
        public void ShouldCreateAndProcessOneStepPipeline()
        {
            PipelineProcessor        processor         = new PipelineProcessor();
            TestProcessor            testProcessor     = new TestProcessor();
            TestProcessor            receiverProcessor = new TestProcessor();
            ICollection <IProcessor> processors        = new List <IProcessor>();

            processors.Add(testProcessor);
            processor.RegisterProcessor(receiverProcessor);
            processor.Processors = processors;

            processor.ProcessMessage(new Message("foo"));

            testProcessor.AutoEvent.WaitOne();
            receiverProcessor.AutoEvent.WaitOne();

            Assert.IsNotNull(testProcessor.ProcessedMessage);
            Assert.AreEqual("foo", testProcessor.ProcessedMessage.Payload);
            Assert.IsNotNull(receiverProcessor.ProcessedMessage);
            Assert.AreEqual("foo", receiverProcessor.ProcessedMessage.Payload);
        }
コード例 #12
0
        /// <summary>
        /// Gets the PSTraceSource instances that match the names specified.
        /// </summary>
        protected override void BeginProcessing()
        {
            Collection <PSTraceSource> preconfiguredSources = null;

            _matchingSources = ConfigureTraceSource(base.NameInternal, false, out preconfiguredSources);

            TurnOnTracing(_matchingSources, false);
            TurnOnTracing(preconfiguredSources, true);

            // Now that tracing has been configured, move all the sources into a
            // single collection

            foreach (PSTraceSource preconfiguredSource in preconfiguredSources)
            {
                _matchingSources.Add(preconfiguredSource);
            }

            if (ParameterSetName == "commandSet")
            {
                // Create the CommandProcessor and add it to a pipeline

                CommandProcessorBase commandProcessor =
                    this.Context.CommandDiscovery.LookupCommandProcessor(Command, CommandOrigin.Runspace, false);

                // Add the parameters that were specified

                ParameterBinderController.AddArgumentsToCommandProcessor(commandProcessor, ArgumentList);

                _pipeline = new PipelineProcessor();
                _pipeline.Add(commandProcessor);

                // Hook up the success and error pipelines to this cmdlet's WriteObject and
                // WriteError methods

                _pipeline.ExternalErrorOutput   = new TracePipelineWriter(this, true, _matchingSources);
                _pipeline.ExternalSuccessOutput = new TracePipelineWriter(this, false, _matchingSources);
            }

            ResetTracing(_matchingSources);
        }
コード例 #13
0
        public async Task ExceptionInDoublePipePostTrigger2()
        {
            var pipeline   = new PipelineProcessor(new OnMessageOptions());
            var message    = new BrokeredMessage();
            var token      = new CancellationTokenSource();
            var funcresult = new FunctionResult(true);
            var pre1       = false;
            var pre2       = false;
            var post       = false;
            var result     = false;

            pipeline.Add(async(ctx, next, cancel) =>
            {
                pre1 = true;
                await next();
                throw new DivideByZeroException();
            });
            pipeline.Add(async(ctx, next, cancel) =>
            {
                pre2 = true;
                await next();
                post = true;
            });

            try
            {
                result = await pipeline.BeginProcessingMessageAsync(message, token.Token);

                await pipeline.CompleteProcessingMessageAsync(message, funcresult, token.Token);
            }
            catch
            {
                Assert.IsTrue(pre1);
                Assert.IsTrue(pre2);
                Assert.IsTrue(post);
                Assert.IsTrue(result);
                throw;
            }
        }
コード例 #14
0
        protected override void BeginProcessing()
        {
            Collection <PSTraceSource> preconfiguredSources = null;

            this.matchingSources = base.ConfigureTraceSource(base.NameInternal, false, out preconfiguredSources);
            base.TurnOnTracing(this.matchingSources, false);
            base.TurnOnTracing(preconfiguredSources, true);
            foreach (PSTraceSource source in preconfiguredSources)
            {
                this.matchingSources.Add(source);
            }
            if (base.ParameterSetName == "commandSet")
            {
                CommandProcessorBase commandProcessor = base.Context.CommandDiscovery.LookupCommandProcessor(this.command, CommandOrigin.Runspace, false);
                ParameterBinderController.AddArgumentsToCommandProcessor(commandProcessor, this.ArgumentList);
                this.pipeline = new PipelineProcessor();
                this.pipeline.Add(commandProcessor);
                this.pipeline.ExternalErrorOutput   = new TracePipelineWriter(this, true, this.matchingSources);
                this.pipeline.ExternalSuccessOutput = new TracePipelineWriter(this, false, this.matchingSources);
            }
            base.ResetTracing(this.matchingSources);
        }
        public ServiceBusPipelineProcessor(OnMessageOptions messageOptions, List <object> stages)
            : base(messageOptions)
        {
            if (stages == null)
            {
                throw new ArgumentNullException(nameof(stages));
            }

            _processor = new PipelineProcessor(messageOptions);

            foreach (var stage in stages)
            {
                if (stage is Type)
                {
                    _processor.Add(stage as Type);
                }
                else
                {
                    _processor.Add(stage as Func <IPipelineContext, Func <Task>, CancellationToken, Task>);
                }
            }
        }
コード例 #16
0
ファイル: CommandNode.cs プロジェクト: mmoenfly/GitCook2021
 private void BindRedirectionPipes(
     CommandProcessorBase commandProcessor,
     PipelineProcessor pipeline,
     ExecutionContext context)
 {
     if (this._outputRedirection != null)
     {
         commandProcessor.CommandRuntime.OutputPipe = this._outputRedirection.GetRedirectionPipe(context);
         if (commandProcessor.CommandRuntime.OutputPipe != null && commandProcessor.CommandRuntime.OutputPipe.PipelineProcessor != null)
         {
             pipeline.AddRedirectionPipe(commandProcessor.CommandRuntime.OutputPipe.PipelineProcessor);
         }
     }
     if (this._errorRedirection != null)
     {
         if (this._errorRedirection.Merging)
         {
             commandProcessor.CommandRuntime.MergeMyErrorOutputWithSuccess = true;
         }
         else
         {
             commandProcessor.CommandRuntime.ErrorOutputPipe = this._errorRedirection.GetRedirectionPipe(context);
             if (commandProcessor.CommandRuntime.ErrorOutputPipe == null || commandProcessor.CommandRuntime.ErrorOutputPipe.PipelineProcessor == null)
             {
                 return;
             }
             pipeline.AddRedirectionPipe(commandProcessor.CommandRuntime.ErrorOutputPipe.PipelineProcessor);
         }
     }
     else if (context.ShellFunctionErrorOutputPipe != null)
     {
         commandProcessor.CommandRuntime.ErrorOutputPipe = context.ShellFunctionErrorOutputPipe;
     }
     else
     {
         commandProcessor.CommandRuntime.ErrorOutputPipe.ExternalWriter = context.ExternalErrorOutput;
     }
 }
コード例 #17
0
        public async Task ContextsDontMixMessages2()
        {
            var pipeline = new PipelineProcessor(new OnMessageOptions());
            var id1      = Guid.NewGuid().ToString();
            var id2      = Guid.NewGuid().ToString();
            var message1 = new BrokeredMessage()
            {
                MessageId = id1
            };
            var message2 = new BrokeredMessage()
            {
                MessageId = id2
            };
            var token1     = new CancellationTokenSource();
            var token2     = new CancellationTokenSource();
            var funcresult = new FunctionResult(true);

            pipeline.Add(async(ctx, next, cancel) =>
            {
                ctx.Enviorment["id"] = ctx.Message.MessageId;
                await next();
                ctx.Message.MessageId = ctx.Enviorment["id"] as string;
            });

            var result1 = await pipeline.BeginProcessingMessageAsync(message1, token1.Token);

            var result2 = await pipeline.BeginProcessingMessageAsync(message2, token1.Token);

            await pipeline.CompleteProcessingMessageAsync(message2, funcresult, token2.Token);

            await pipeline.CompleteProcessingMessageAsync(message1, funcresult, token1.Token);

            Assert.IsTrue(result1);
            Assert.IsTrue(result2);
            Assert.AreEqual(id1, message1.MessageId);
            Assert.AreEqual(id2, message2.MessageId);
        }
コード例 #18
0
        internal override void Bind(PipelineProcessor pipelineProcessor, CommandProcessorBase commandProcessor, ExecutionContext context)
        {
            Pipe outputPipe = commandProcessor.CommandRuntime.OutputPipe;

            switch (base.FromStream)
            {
            case RedirectionStream.All:
                commandProcessor.CommandRuntime.ErrorMergeTo      = MshCommandRuntime.MergeDataStream.Output;
                commandProcessor.CommandRuntime.WarningOutputPipe = outputPipe;
                commandProcessor.CommandRuntime.VerboseOutputPipe = outputPipe;
                commandProcessor.CommandRuntime.DebugOutputPipe   = outputPipe;
                return;

            case RedirectionStream.Output:
            case RedirectionStream.Host:
                break;

            case RedirectionStream.Error:
                commandProcessor.CommandRuntime.ErrorMergeTo = MshCommandRuntime.MergeDataStream.Output;
                return;

            case RedirectionStream.Warning:
                commandProcessor.CommandRuntime.WarningOutputPipe = outputPipe;
                return;

            case RedirectionStream.Verbose:
                commandProcessor.CommandRuntime.VerboseOutputPipe = outputPipe;
                return;

            case RedirectionStream.Debug:
                commandProcessor.CommandRuntime.DebugOutputPipe = outputPipe;
                break;

            default:
                return;
            }
        }
コード例 #19
0
 public void Dispose()
 {
     if (!this.disposed)
     {
         this.disposed = true;
         base.ResetTracing(this.matchingSources);
         base.ClearStoredState();
         this.matchingSources = null;
         if (this.pipeline != null)
         {
             this.pipeline.Dispose();
             this.pipeline = null;
         }
         if (base.FileStreams != null)
         {
             foreach (FileStream stream in base.FileStreams)
             {
                 stream.Flush();
                 stream.Close();
             }
         }
         GC.SuppressFinalize(this);
     }
 }
コード例 #20
0
ファイル: LocalPipeline.cs プロジェクト: modulexcite/pash-1
        private PipelineProcessor CreatePipelineProcessor()
        {
            PipelineProcessor processor2;
            CommandCollection commands = base.Commands;

            if ((commands == null) || (commands.Count == 0))
            {
                throw PSTraceSource.NewInvalidOperationException("RunspaceStrings", "NoCommandInPipeline", new object[0]);
            }
            PipelineProcessor processor = new PipelineProcessor {
                TopLevel = true
            };
            bool flag = false;

            try
            {
                foreach (Command command in commands)
                {
                    CommandProcessorBase base2;
                    if (command.CommandInfo == null)
                    {
                        base2 = command.CreateCommandProcessor(this.LocalRunspace.ExecutionContext, this.LocalRunspace.CommandFactory, base.AddToHistory, this.IsNested ? CommandOrigin.Internal : CommandOrigin.Runspace);
                    }
                    else
                    {
                        CmdletInfo commandInfo = (CmdletInfo)command.CommandInfo;
                        base2 = new CommandProcessor(commandInfo, this.LocalRunspace.ExecutionContext);
                        PSSQMAPI.IncrementData(commandInfo.CommandType);
                        base2.Command.CommandOriginInternal       = CommandOrigin.Internal;
                        base2.Command.MyInvocation.InvocationName = commandInfo.Name;
                        if (command.Parameters != null)
                        {
                            foreach (CommandParameter parameter in command.Parameters)
                            {
                                CommandParameterInternal internal2 = CommandParameter.ToCommandParameterInternal(parameter, false);
                                base2.AddParameter(internal2);
                            }
                        }
                    }
                    base2.RedirectShellErrorOutputPipe = base.RedirectShellErrorOutputPipe;
                    processor.Add(base2);
                }
                processor2 = processor;
            }
            catch (RuntimeException)
            {
                flag = true;
                throw;
            }
            catch (Exception exception)
            {
                flag = true;
                CommandProcessorBase.CheckForSevereException(exception);
                throw new RuntimeException(PipelineStrings.CannotCreatePipeline, exception);
            }
            finally
            {
                if (flag)
                {
                    base.SetHadErrors(true);
                    processor.Dispose();
                }
            }
            return(processor2);
        }
コード例 #21
0
        public void ShouldCreatePipelineProcessor()
        {
            PipelineProcessor processor = new PipelineProcessor();

            Assert.IsNotNull(processor);
        }
コード例 #22
0
        private static CommandProcessorBase AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, System.Management.Automation.ExecutionContext context)
        {
            object               parameterText;
            IScriptExtent        parameterExtent;
            CommandProcessorBase base2;
            InternalCommand      command;
            string               str3;
            HelpCategory         category;
            CommandAst           ast          = commandBaseAst as CommandAst;
            TokenKind            kind         = (ast != null) ? ast.InvocationOperator : TokenKind.Unknown;
            bool dotSource                    = kind == TokenKind.Dot;
            SessionStateInternal sessionState = null;
            int          index                = 0;
            PSModuleInfo info                 = PSObject.Base(commandElements[0].ArgumentValue) as PSModuleInfo;

            if (info != null)
            {
                if ((info.ModuleType == ModuleType.Binary) && (info.SessionState == null))
                {
                    throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException), null, "CantInvokeInBinaryModule", ParserStrings.CantInvokeInBinaryModule, new object[] { info.Name });
                }
                if (info.SessionState == null)
                {
                    throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException), null, "CantInvokeInNonImportedModule", ParserStrings.CantInvokeInNonImportedModule, new object[] { info.Name });
                }
                sessionState = info.SessionState.Internal;
                index++;
            }
            CommandParameterInternal internal3 = commandElements[index];

            if (internal3.ParameterNameSpecified)
            {
                parameterText   = internal3.ParameterText;
                parameterExtent = internal3.ParameterExtent;
                if (!internal3.ArgumentSpecified)
                {
                }
            }
            else
            {
                parameterText   = PSObject.Base(internal3.ArgumentValue);
                parameterExtent = internal3.ArgumentExtent;
            }
            string      str         = dotSource ? "." : ((kind == TokenKind.Ampersand) ? "&" : null);
            ScriptBlock scriptblock = parameterText as ScriptBlock;

            if (scriptblock != null)
            {
                base2 = CommandDiscovery.CreateCommandProcessorForScript(scriptblock, context, !dotSource, sessionState);
            }
            else
            {
                CommandInfo commandInfo = parameterText as CommandInfo;
                if (commandInfo != null)
                {
                    base2 = context.CommandDiscovery.LookupCommandProcessor(commandInfo, context.EngineSessionState.CurrentScope.ScopeOrigin, new bool?(!dotSource), sessionState);
                }
                else
                {
                    string str2 = (parameterText as string) ?? PSObject.ToStringParser(context, parameterText);
                    str = str ?? str2;
                    if (string.IsNullOrEmpty(str2))
                    {
                        throw InterpreterError.NewInterpreterException(parameterText, typeof(RuntimeException), parameterExtent, "BadExpression", ParserStrings.BadExpression, new object[] { dotSource ? "." : "&" });
                    }
                    try
                    {
                        if (sessionState != null)
                        {
                            SessionStateInternal engineSessionState = context.EngineSessionState;
                            try
                            {
                                context.EngineSessionState = sessionState;
                                base2 = context.CreateCommand(str2, dotSource);
                                goto Label_025D;
                            }
                            finally
                            {
                                context.EngineSessionState = engineSessionState;
                            }
                        }
                        base2 = context.CreateCommand(str2, dotSource);
                    }

                    catch (RuntimeException exception)
                    {
                        if (exception.ErrorRecord.InvocationInfo == null)
                        {
                            InvocationInfo invocationInfo = new InvocationInfo(null, parameterExtent, context)
                            {
                                InvocationName = str
                            };
                            exception.ErrorRecord.SetInvocationInfo(invocationInfo);
                        }
                        throw;
                    }
                }
            }
Label_025D:
            command             = base2.Command;
            base2.UseLocalScope = !dotSource && ((command is ScriptCommand) || (command is PSScriptCmdlet));
            bool flag2 = base2 is NativeCommandProcessor;

            for (int i = index + 1; i < commandElements.Length; i++)
            {
                CommandParameterInternal parameter = commandElements[i];
                if ((!parameter.ParameterNameSpecified || !parameter.ParameterName.Equals("-", StringComparison.OrdinalIgnoreCase)) || flag2)
                {
                    if (parameter.ArgumentSplatted)
                    {
                        foreach (CommandParameterInternal internal6 in Splat(parameter.ArgumentValue, parameter.ArgumentExtent))
                        {
                            base2.AddParameter(internal6);
                        }
                    }
                    else
                    {
                        base2.AddParameter(parameter);
                    }
                }
            }
            if (base2.IsHelpRequested(out str3, out category))
            {
                base2 = CommandProcessorBase.CreateGetHelpCommandProcessor(context, str3, category);
            }
            base2.Command.InvocationExtent            = commandBaseAst.Extent;
            base2.Command.MyInvocation.ScriptPosition = commandBaseAst.Extent;
            base2.Command.MyInvocation.InvocationName = str;
            pipe.Add(base2);
            bool flag3 = false;
            bool flag4 = false;
            bool flag5 = false;
            bool flag6 = false;

            if (redirections != null)
            {
                foreach (CommandRedirection redirection in redirections)
                {
                    redirection.Bind(pipe, base2, context);
                    switch (redirection.FromStream)
                    {
                    case RedirectionStream.All:
                        flag3 = true;
                        flag4 = true;
                        flag5 = true;
                        flag6 = true;
                        break;

                    case RedirectionStream.Error:
                        flag3 = true;
                        break;

                    case RedirectionStream.Warning:
                        flag4 = true;
                        break;

                    case RedirectionStream.Verbose:
                        flag5 = true;
                        break;

                    case RedirectionStream.Debug:
                        flag6 = true;
                        break;
                    }
                }
            }
            if (!flag3)
            {
                if (context.ShellFunctionErrorOutputPipe != null)
                {
                    base2.CommandRuntime.ErrorOutputPipe = context.ShellFunctionErrorOutputPipe;
                }
                else
                {
                    base2.CommandRuntime.ErrorOutputPipe.ExternalWriter = context.ExternalErrorOutput;
                }
            }
            if (!flag4 && (context.ExpressionWarningOutputPipe != null))
            {
                base2.CommandRuntime.WarningOutputPipe = context.ExpressionWarningOutputPipe;
                flag4 = true;
            }
            if (!flag5 && (context.ExpressionVerboseOutputPipe != null))
            {
                base2.CommandRuntime.VerboseOutputPipe = context.ExpressionVerboseOutputPipe;
                flag5 = true;
            }
            if (!flag6 && (context.ExpressionDebugOutputPipe != null))
            {
                base2.CommandRuntime.DebugOutputPipe = context.ExpressionDebugOutputPipe;
                flag6 = true;
            }
            if ((context.CurrentCommandProcessor != null) && (context.CurrentCommandProcessor.CommandRuntime != null))
            {
                if (!flag4 && (context.CurrentCommandProcessor.CommandRuntime.WarningOutputPipe != null))
                {
                    base2.CommandRuntime.WarningOutputPipe = context.CurrentCommandProcessor.CommandRuntime.WarningOutputPipe;
                }
                if (!flag5 && (context.CurrentCommandProcessor.CommandRuntime.VerboseOutputPipe != null))
                {
                    base2.CommandRuntime.VerboseOutputPipe = context.CurrentCommandProcessor.CommandRuntime.VerboseOutputPipe;
                }
                if (!flag6 && (context.CurrentCommandProcessor.CommandRuntime.DebugOutputPipe != null))
                {
                    base2.CommandRuntime.DebugOutputPipe = context.CurrentCommandProcessor.CommandRuntime.DebugOutputPipe;
                }
            }
            return(base2);
        }
コード例 #23
0
 private PipelineProcessor CreateProcessor()
 {
     var pipelineProcessor = new PipelineProcessor(new FailingEventProcessor());
     pipelineProcessor.EventProcessed += (s, e) => _eventStore.MarkLastProcessedElement(e.ProcessedElement);
     return pipelineProcessor;
 }
コード例 #24
0
 internal abstract void Bind(PipelineProcessor pipelineProcessor, CommandProcessorBase commandProcessor, ExecutionContext context);
コード例 #25
0
        private void InvokeHelper()
        {
            PipelineProcessor pipelineProcessor = (PipelineProcessor)null;

            try
            {
                this.RaisePipelineStateEvents();
                this.RecordPipelineStartTime();
                try
                {
                    pipelineProcessor = this.CreatePipelineProcessor();
                }
                catch (Exception ex)
                {
                    if (this.SetPipelineSessionState)
                    {
                        this.Runspace.ExecutionContext.AppendDollarError((object)ex);
                    }
                    throw;
                }
                if (this.useExternalInput)
                {
                    pipelineProcessor.ExternalInput = this.InputStream.ObjectReader;
                }
                pipelineProcessor.ExternalSuccessOutput = this.OutputStream.ObjectWriter;
                pipelineProcessor.ExternalErrorOutput   = this.ErrorStream.ObjectWriter;
                this.LocalRunspace.ExecutionContext.InternalHost.InternalUI.SetInformationalMessageBuffers(this.InformationalBuffers);
                bool flag = true;
                bool enclosingStatementBlock = this.LocalRunspace.ExecutionContext.ExceptionHandlerInEnclosingStatementBlock;
                this.LocalRunspace.ExecutionContext.ExceptionHandlerInEnclosingStatementBlock = false;
                try
                {
                    this._stopper.Push(pipelineProcessor);
                    if (!this.AddToHistory)
                    {
                        flag = this.LocalRunspace.ExecutionContext.QuestionMarkVariableValue;
                        this.LocalRunspace.ExecutionContext.IgnoreScriptDebug = true;
                    }
                    else
                    {
                        this.LocalRunspace.ExecutionContext.IgnoreScriptDebug = false;
                    }
                    if (!this.IsNested)
                    {
                        this.LocalRunspace.ExecutionContext.ResetScopeDepth();
                    }
                    this.LocalRunspace.ExecutionContext.ResetRedirection();
                    try
                    {
                        pipelineProcessor.Execute();
                    }
                    catch (ExitException ex1)
                    {
                        int exitCode = 1;
                        if (this.IsNested)
                        {
                            try
                            {
                                this.LocalRunspace.ExecutionContext.SetVariable("global:LASTEXITCODE", (object)(int)ex1.Argument);
                            }
                            finally
                            {
                                try
                                {
                                    LocalPipeline._trace.WriteLine("exiting nested prompt at top level from exit statement", new object[0]);
                                    this.LocalRunspace.ExecutionContext.EngineHostInterface.ExitNestedPrompt();
                                }
                                catch (ExitNestedPromptException ex2)
                                {
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                exitCode = (int)ex1.Argument;
                            }
                            finally
                            {
                                this.LocalRunspace.ExecutionContext.EngineHostInterface.SetShouldExit(exitCode);
                            }
                        }
                    }
                    catch (ExitNestedPromptException ex)
                    {
                        LocalPipeline._trace.WriteLine("exiting nested prompt at top level from direct method call", new object[0]);
                    }
                    catch (FlowControlException ex)
                    {
                    }
                }
                finally
                {
                    if (this.LocalRunspace.Events is PSLocalEventManager events)
                    {
                        events.ProcessPendingActions();
                    }
                    this.LocalRunspace.ExecutionContext.ExceptionHandlerInEnclosingStatementBlock = enclosingStatementBlock;
                    this.LocalRunspace.ExecutionContext.InternalHost.InternalUI.SetInformationalMessageBuffers((PSInformationalBuffers)null);
                    if (!this.AddToHistory)
                    {
                        this.LocalRunspace.ExecutionContext.QuestionMarkVariableValue = flag;
                    }
                    this._stopper.Pop();
                }
            }
            finally
            {
                pipelineProcessor?.Dispose();
            }
        }
コード例 #26
0
 // TODO: hook the runtime to the Host for Debug and Error output
 internal PipelineCommandRuntime(PipelineProcessor pipelineProcessor)
 {
     this.pipelineProcessor = pipelineProcessor;
     this.outputResults     = new ObjectStream();
     this.errorResults      = new ObjectStream();
 }
コード例 #27
0
ファイル: LocalPipeline.cs プロジェクト: modulexcite/pash-1
        private void InvokeHelper()
        {
            PipelineProcessor item = null;

            try
            {
                base.RaisePipelineStateEvents();
                this.RecordPipelineStartTime();
                try
                {
                    item = this.CreatePipelineProcessor();
                }
                catch (Exception exception)
                {
                    if (base.SetPipelineSessionState)
                    {
                        base.SetHadErrors(true);
                        this.Runspace.ExecutionContext.AppendDollarError(exception);
                    }
                    throw;
                }
                if (this.useExternalInput)
                {
                    item.ExternalInput = base.InputStream.ObjectReader;
                }
                item.ExternalSuccessOutput = base.OutputStream.ObjectWriter;
                item.ExternalErrorOutput   = base.ErrorStream.ObjectWriter;
                if (!this.IsChild)
                {
                    this.LocalRunspace.ExecutionContext.InternalHost.InternalUI.SetInformationalMessageBuffers(base.InformationalBuffers);
                }
                bool questionMarkVariableValue = true;
                bool exceptionHandlerInEnclosingStatementBlock = this.LocalRunspace.ExecutionContext.ExceptionHandlerInEnclosingStatementBlock;
                this.LocalRunspace.ExecutionContext.ExceptionHandlerInEnclosingStatementBlock = false;
                try
                {
                    this._stopper.Push(item);
                    if (!base.AddToHistory)
                    {
                        questionMarkVariableValue = this.LocalRunspace.ExecutionContext.QuestionMarkVariableValue;
                        this.LocalRunspace.ExecutionContext.IgnoreScriptDebug = true;
                    }
                    else
                    {
                        this.LocalRunspace.ExecutionContext.IgnoreScriptDebug = false;
                    }
                    if (!this.IsNested && !base.IsPulsePipeline)
                    {
                        this.LocalRunspace.ExecutionContext.ResetRedirection();
                    }
                    try
                    {
                        item.Execute();
                        base.SetHadErrors(item.ExecutionFailed);
                    }
                    catch (ExitException exception2)
                    {
                        base.SetHadErrors(item.ExecutionFailed);
                        int newValue = 1;
                        if (this.IsNested)
                        {
                            try
                            {
                                newValue = (int)exception2.Argument;
                                this.LocalRunspace.ExecutionContext.SetVariable(SpecialVariables.LastExitCodeVarPath, newValue);
                                return;
                            }
                            finally
                            {
                                try
                                {
                                    this.LocalRunspace.ExecutionContext.EngineHostInterface.ExitNestedPrompt();
                                }
                                catch (ExitNestedPromptException)
                                {
                                }
                            }
                        }
                        try
                        {
                            newValue = (int)exception2.Argument;
                        }
                        finally
                        {
                            this.LocalRunspace.ExecutionContext.EngineHostInterface.SetShouldExit(newValue);
                        }
                    }
                    catch (ExitNestedPromptException)
                    {
                    }
                    catch (FlowControlException)
                    {
                    }
                    catch (Exception)
                    {
                        base.SetHadErrors(true);
                        throw;
                    }
                }
                finally
                {
                    if ((item != null) && (item.Commands != null))
                    {
                        for (int i = 0; i < item.Commands.Count; i++)
                        {
                            CommandProcessorBase base2 = item.Commands[i];
                            EtwActivity.SetActivityId(base2.PipelineActivityId);
                            MshLog.LogCommandLifecycleEvent(base2.Context, CommandState.Terminated, base2.Command.MyInvocation);
                        }
                    }
                    PSLocalEventManager events = this.LocalRunspace.Events as PSLocalEventManager;
                    if (events != null)
                    {
                        events.ProcessPendingActions();
                    }
                    this.LocalRunspace.ExecutionContext.ExceptionHandlerInEnclosingStatementBlock = exceptionHandlerInEnclosingStatementBlock;
                    if (!this.IsChild)
                    {
                        this.LocalRunspace.ExecutionContext.InternalHost.InternalUI.SetInformationalMessageBuffers(null);
                    }
                    this._stopper.Pop(false);
                    if (!base.AddToHistory)
                    {
                        this.LocalRunspace.ExecutionContext.QuestionMarkVariableValue = questionMarkVariableValue;
                    }
                }
            }
            catch (FlowControlException)
            {
            }
            finally
            {
                if (item != null)
                {
                    item.Dispose();
                    item = null;
                }
            }
        }