Exemplo n.º 1
0
        internal override void Execute(ExecutionContext context, ICommandRuntime commandRuntime)
        {
            // TODO: rewrite this - it should expand the commands in the original pipe

            PipelineCommandRuntime subRuntime = null;

            foreach (ASTNode node in Pipeline)
            {
                ExecutionContext subContext = context.CreateNestedContext();

                if (subRuntime == null)
                {
                    subContext.inputStreamReader = context.inputStreamReader;
                }
                else
                {
                    subContext.inputStreamReader = new PSObjectPipelineReader(subRuntime.outputResults);
                }

                subRuntime = new PipelineCommandRuntime(((PipelineCommandRuntime)commandRuntime).pipelineProcessor);
                subContext.inputStreamReader = subContext.inputStreamReader;

                node.Execute(subContext, subRuntime);
            }
        }
Exemplo n.º 2
0
        public override AstVisitAction VisitPipeline(PipelineAst pipelineAst)
        {
            // TODO: rewrite this - it should expand the commands in the original pipe

            PipelineCommandRuntime subRuntime = null;

            foreach (var pipelineElement in pipelineAst.PipelineElements)
            {
                ExecutionContext subContext = this._context.CreateNestedContext();

                if (subRuntime == null)
                {
                    subContext.inputStreamReader = this._context.inputStreamReader;
                }
                else
                {
                    subContext.inputStreamReader = new PSObjectPipelineReader(subRuntime.outputResults);
                }

                subRuntime = new PipelineCommandRuntime(this._pipelineCommandRuntime.pipelineProcessor);
                subContext.inputStreamReader = subContext.inputStreamReader;

                pipelineElement.Visit(new ExecutionVisitor(subContext, subRuntime, this._writeSideEffectsToPipeline));
            }

            this._pipelineCommandRuntime.WriteObject(subRuntime.outputResults.Read(), true);

            return(AstVisitAction.SkipChildren);
        }
Exemplo n.º 3
0
        internal override void ProcessRecord()
        {
            ExecutionContext context = ExecutionContext.Clone();

            PipelineCommandRuntime pipelineCommandRuntime = (PipelineCommandRuntime)CommandRuntime;

            this._scriptInfo.ScriptBlock.Ast.Visit(new ExecutionVisitor(context, pipelineCommandRuntime, false));
        }
Exemplo n.º 4
0
        public Array Execute(ExecutionContext context)
        {
            PSObject psObjectCurrent             = context.inputStreamReader.Read();
            Collection <PSObject> dataCollection = new Collection <PSObject>()
            {
                psObjectCurrent
            };

            do
            {
                foreach (CommandProcessorBase commandProcessor in commandsToExecute)
                {
                    PipelineCommandRuntime commandRuntime = new PipelineCommandRuntime(this);

                    foreach (PSObject psObject in dataCollection)
                    {
                        // TODO: protect the execution context
                        commandProcessor.ExecutionContext = context;

                        // TODO: replace the Command default runtime to execute callbacks on the pipeline when the object is written to the pipeline and then execute the next cmdlet

                        // TODO: provide a proper command initialization (for parameters and pipeline objects)
                        commandProcessor.CommandRuntime = commandRuntime;

                        commandProcessor.BindArguments(psObject);

                        // TODO: for each entry in pipe
                        // Execute the cmdlet at least once (even if there were nothing in the pipe
                        commandProcessor.ProcessRecord();
                    }
                    commandProcessor.Complete();

                    // TODO: process Error stream

                    dataCollection = new PSObjectPipelineReader(commandRuntime.outputResults).ReadToEnd();
                }
            } while ((psObjectCurrent = context.inputStreamReader.Read()) != null);

            // Write the final result to the output pipeline
            context.outputStreamWriter.Write(dataCollection, true);

            object[] dataResult = new object[dataCollection.Count];
            int      index      = 0;

            foreach (PSObject obj in dataCollection)
            {
                dataResult[index++] = obj;
            }

            return(dataResult);
        }
Exemplo n.º 5
0
 public void Visit(PipelineCommandRuntime runtime)
 {
     foreach (RedirectionAst redirectionAst in _redirections)
     {
         var fileRedirectionAst = redirectionAst as FileRedirectionAst;
         if (fileRedirectionAst != null)
         {
             var redirectionVisitor = new FileRedirectionVisitor(_visitor, runtime);
             redirectionVisitor.Visit(fileRedirectionAst);
         }
         else
         {
             throw new NotImplementedException(redirectionAst.ToString());
         }
     }
 }
Exemplo n.º 6
0
 public ExecutionVisitor(ExecutionContext context, PipelineCommandRuntime pipelineCommandRuntime, bool writeSideEffectsToPipeline = false)
 {
     this._context = context;
     this._pipelineCommandRuntime     = pipelineCommandRuntime;
     this._writeSideEffectsToPipeline = writeSideEffectsToPipeline;
 }
Exemplo n.º 7
0
 internal CommandProcessorBase(CommandInfo cmdInfo)
 {
     CommandInfo    = cmdInfo;
     Parameters     = new CommandParameterCollection();
     CommandRuntime = new PipelineCommandRuntime(null);
 }
Exemplo n.º 8
0
 public ExecutionVisitor(ExecutionContext context, PipelineCommandRuntime pipelineCommandRuntime)
 {
     this._context = context;
     this._pipelineCommandRuntime = pipelineCommandRuntime;
 }
Exemplo n.º 9
0
 public FileRedirectionVisitor(ExecutionVisitor visitor, PipelineCommandRuntime runtime)
 {
     _visitor = visitor;
     _runtime = runtime;
 }