Example #1
0
 ExecutionVisitor CloneSub(bool writeSideEffectsToPipeline)
 {
     var subContext = this.ExecutionContext.CreateNestedContext();
     var subRuntime = new PipelineCommandRuntime(this._pipelineCommandRuntime.PipelineProcessor);
     subRuntime.ExecutionContext = subContext;
     return new ExecutionVisitor(
         subContext,
         subRuntime,
         writeSideEffectsToPipeline
         );
 }
Example #2
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());
         }
     }
 }
Example #3
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;
        }
Example #4
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);
            }
        }
Example #5
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;
        }
Example #6
0
 public ExecutionVisitor(ExecutionContext context, PipelineCommandRuntime pipelineCommandRuntime, bool writeSideEffectsToPipeline = false)
 {
     this._context = context;
     this._pipelineCommandRuntime = pipelineCommandRuntime;
     this._writeSideEffectsToPipeline = writeSideEffectsToPipeline;
 }
Example #7
0
 internal CommandInvocationIntrinsics(ExecutionContext executionContext, PipelineCommandRuntime commandRuntime)
 {
     this.executionContext = executionContext;
     this.commandRuntime   = commandRuntime;
 }
 internal CommandInvocationIntrinsics(ExecutionContext executionContext, PipelineCommandRuntime commandRuntime)
 {
     this.executionContext = executionContext;
     this.commandRuntime = commandRuntime;
 }
Example #9
0
 public ExecutionVisitor(ExecutionContext context, PipelineCommandRuntime pipelineCommandRuntime)
 {
     this._context = context;
     this._pipelineCommandRuntime = pipelineCommandRuntime;
 }
Example #10
0
 internal CommandProcessorBase(CommandInfo cmdInfo)
 {
     CommandInfo = cmdInfo;
     Parameters = new CommandParameterCollection();
     CommandRuntime = new PipelineCommandRuntime(null);
 }
Example #11
0
 public FileRedirectionVisitor(ExecutionVisitor visitor, PipelineCommandRuntime runtime)
 {
     _visitor = visitor;
     _runtime = runtime;
 }