CreateNestedContext() public method

public CreateNestedContext ( ) : ExecutionContext
return ExecutionContext
Exemplo n.º 1
0
        internal override void Execute(ExecutionContext context, ICommandRuntime commandRuntime)
        {
            ExecutionContext nestedContext = context.CreateNestedContext();

            if (lValue is VariableNode)
            {
                VariableNode varNode = (VariableNode)lValue;

                if (! (context.CurrentRunspace is LocalRunspace))
                    throw new InvalidOperationException("Invalid context");

                // MUST: fix this with the commandRuntime
                Pipeline pipeline = context.CurrentRunspace.CreateNestedPipeline();
                context.PushPipeline(pipeline);

                try
                {
                    Command cmd = new Command("Set-Variable");
                    cmd.Parameters.Add("Name", new string[] { varNode.Text });
                    cmd.Parameters.Add("Value", rValue.GetValue(context));
                    // TODO: implement command invoke
                    pipeline.Commands.Add(cmd);
                    pipeline.Invoke();
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    context.PopPipeline();
                }
            }
        }
Exemplo n.º 2
0
        internal override void Execute(Pash.Implementation.ExecutionContext context, ICommandRuntime commandRuntime)
        {
            ExecutionContext nestedContext = context.CreateNestedContext();

            if (!(context.CurrentRunspace is LocalRunspace))
            {
                throw new InvalidOperationException("Invalid context");
            }

            // MUST: fix this with the commandRuntime
            Pipeline pipeline = context.CurrentRunspace.CreateNestedPipeline();

            context.PushPipeline(pipeline);

            try
            {
                Command cmd = new Command("Get-Variable");
                cmd.Parameters.Add("Name", new string[] { Text });
                // TODO: implement command invoke
                pipeline.Commands.Add(cmd);

                commandRuntime.WriteObject(pipeline.Invoke(), true);
                //context.outputStreamWriter.Write(pipeline.Invoke(), true);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                context.PopPipeline();
            }
        }
Exemplo n.º 3
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);
            }
        }