예제 #1
0
 public override AstVisitAction VisitCommand(CommandAst commandAst)  //confirmed
 {
     if (commandAst.ToString().Contains(symbolRef.ScriptRegion.Text))
     {
         ValidateExtend(symbolRef.ScriptRegion.Text, commandAst.GetCommandName(), commandAst);
     }
     return(base.VisitCommand(commandAst));
 }
예제 #2
0
        public override AstVisitAction VisitCommand(CommandAst commandAst)
        {
            if (commandAst.InvocationOperator == TokenKind.Dot)
            {
                throw new NotImplementedException(commandAst.ToString());
            }

            Pipeline pipeline = this._context.CurrentRunspace.CreateNestedPipeline();

            pipeline.Input.Write(this._context.inputStreamReader.ReadToEnd(), true);

            var command = GetCommand(commandAst);
            List <CommandParameter> commandParameters = new List <CommandParameter>();

            // the first CommandElements is the command itself. The rest are parameters/arguments
            foreach (var commandElement in commandAst.CommandElements.Skip(1))
            {
                var commandParameterAst         = commandElement as CommandParameterAst;
                var stringConstantExpressionAst = commandElement as StringConstantExpressionAst;

                if (commandParameterAst != null)
                {
                    commandParameters.Add(new CommandParameter(commandParameterAst.ParameterName, commandParameterAst.Argument));
                }

                else if (stringConstantExpressionAst != null)
                {
                    commandParameters.Add(new CommandParameter(null, stringConstantExpressionAst.Value));
                }
            }

            commandParameters.ForEach(commandParameter => command.Parameters.Add(commandParameter));
            pipeline.Commands.Add(command);

            this._context.PushPipeline(pipeline);
            try
            {
                // TODO: develop a rational model for null/singleton/collection
                var result = pipeline.Invoke();
                if (result.Any())
                {
                    this._pipelineCommandRuntime.WriteObject(result, true);
                }
            }
            finally
            {
                this._context.PopPipeline();
            }

            return(AstVisitAction.SkipChildren);
        }
예제 #3
0
        public override AstVisitAction VisitCommand(CommandAst commandAst)
        {
            if (commandAst.InvocationOperator == TokenKind.Dot)
            {
                throw new NotImplementedException(commandAst.ToString());
            }

            // Pipeline uses global execution context, so we should set its WriteSideEffects flag, and restore it to previous value after.
            var  pipeLineContext  = _context.CurrentRunspace.ExecutionContext;
            bool writeSideEffects = pipeLineContext.WriteSideEffectsToPipeline;

            try
            {
                pipeLineContext.WriteSideEffectsToPipeline = _writeSideEffectsToPipeline;
                var pipeline = _context.CurrentRunspace.CreateNestedPipeline();

                pipeline.Input.Write(_context.inputStreamReader.ReadToEnd(), true);

                var command = GetCommand(commandAst);

                commandAst.CommandElements
                // the first CommandElements is the command itself. The rest are parameters/arguments
                .Skip(1)
                .Select(ConvertCommandElementToCommandParameter)
                .ForEach(command.Parameters.Add);

                pipeline.Commands.Add(command);

                _context.PushPipeline(pipeline);
                try
                {
                    // TODO: develop a rational model for null/singleton/collection
                    var result = pipeline.Invoke();
                    if (result.Any())
                    {
                        _pipelineCommandRuntime.WriteObject(result, true);
                    }
                }
                finally
                {
                    _context.PopPipeline();
                }
            }
            finally
            {
                pipeLineContext.WriteSideEffectsToPipeline = writeSideEffects;
            }

            return(AstVisitAction.SkipChildren);
        }
예제 #4
0
 public override AstVisitAction VisitCommand(CommandAst commandAst)
 {
     Console.WriteLine("Visited an CommandAst.");
     Console.WriteLine("    " + commandAst.ToString().Replace(Environment.NewLine, Environment.NewLine + "    "));
     return(AstVisitAction.Continue);
 }