Beispiel #1
0
        private object GetCommandName(
            out bool createScope,
            out int index,
            out SessionStateInternal commandSessionState,
            out bool forceSessionState,
            ExecutionContext context)
        {
            createScope         = true;
            index               = 0;
            forceSessionState   = false;
            commandSessionState = context.EngineSessionState;
            if (this._elements.Count == 0)
            {
                return((object)null);
            }
            Token element = (Token)this._elements[index++];

            if (element.Is(TokenId.DotToken))
            {
                createScope = false;
            }
            else if (!element.Is(TokenId.AmpersandToken))
            {
                return((object)element.TokenText);
            }
            for (int index1 = 0; index1 < 2; ++index1)
            {
                ParseTreeNode parseTreeNode = (ParseTreeNode)null;
                if (index < this._elements.Count)
                {
                    parseTreeNode = this._elements[index++] as ParseTreeNode;
                }
                object obj = parseTreeNode != null?PSObject.Base(parseTreeNode.Execute(context)) : throw InterpreterError.NewInterpreterException((object)null, typeof(RuntimeException), element, "MissingExpression", (object)element.TokenText);

                if (!(obj is PSModuleInfo psModuleInfo))
                {
                    return(obj);
                }
                if (psModuleInfo.ModuleType == ModuleType.Binary && psModuleInfo.SessionState == null)
                {
                    throw InterpreterError.NewInterpreterException((object)null, typeof(RuntimeException), element, "CantInvokeInBinaryModule", (object)psModuleInfo.Name);
                }
                commandSessionState = psModuleInfo.SessionState.Internal;
                forceSessionState   = true;
            }
            return((object)null);
        }
        internal object Execute(ParseTreeNode ptn, Array input)
        {
            object obj = (object)AutomationNull.Value;
            ActivationRecordBuilder activationRecordBuilder = new ActivationRecordBuilder();

            ptn.Accept((ParseTreeVisitor)activationRecordBuilder);
            ActivationRecord activationRecord = this._context.EngineSessionState.CurrentActivationRecord;

            try
            {
                this._context.EngineSessionState.CurrentActivationRecord = new ActivationRecord(activationRecordBuilder.PipelineSlots, activationRecordBuilder.VariableSlots, this._context.EngineSessionState.CurrentScope);
                obj = ptn.Execute(input, this._context);
            }
            catch (FlowControlException ex)
            {
            }
            finally
            {
                this._context.EngineSessionState.CurrentActivationRecord = activationRecord;
            }
            return(obj);
        }
Beispiel #3
0
 internal override object Execute(Array input, Pipe outputPipe, ExecutionContext context)
 {
     this.CheckForInterrupts(context);
     if (this._expressions == null || this._expressions.Count == 0)
     {
         return((object)new object[0]);
     }
     object[] objArray = new object[this._expressions.Count];
     for (int index = 0; index < this._expressions.Count; ++index)
     {
         ParseTreeNode expression = this._expressions[index];
         objArray[index] = expression == null ? (object)this._expressions[index] : expression.Execute(input, (Pipe)null, context);
         if (objArray[index] == AutomationNull.Value)
         {
             objArray[index] = (object)null;
         }
     }
     return((object)objArray);
 }
        private void ExecuteStatement(
            ParseTreeNode statement,
            Array input,
            Pipe outputPipe,
            ref ArrayList resultList,
            ExecutionContext context)
        {
            ScriptTrace.TraceLine(context, statement);
            Exception e = (Exception)null;

            try
            {
                try
                {
                    if (statement.IsVoidable)
                    {
                        statement.Execute(input, (Pipe)null, context);
                    }
                    else
                    {
                        statement.Execute(input, outputPipe, ref resultList, context);
                    }
                    ParseTreeNode parseTreeNode = statement;
                    while (parseTreeNode is AssignmentStatementNode assignmentStatementNode)
                    {
                        parseTreeNode = assignmentStatementNode.RightHandSide;
                    }
                    if (parseTreeNode.IsExpression)
                    {
                        context.QuestionMarkVariableValue = true;
                    }
                    else if (parseTreeNode is PipelineNode pipelineNode)
                    {
                        context.QuestionMarkVariableValue = !pipelineNode.ExecutionFailed(context);
                    }
                }
                catch (COMException ex)
                {
                    throw InterpreterError.NewInterpreterExceptionWithInnerException((object)null, typeof(RuntimeException), statement.NodeToken, "COMException", (Exception)ex, (object)ex.Message);
                }
                catch (InvalidComObjectException ex)
                {
                    throw InterpreterError.NewInterpreterExceptionWithInnerException((object)null, typeof(RuntimeException), statement.NodeToken, "InvalidComObjectException", (Exception)ex, (object)ex.Message);
                }
            }
            catch (ReturnException ex)
            {
                if (resultList == null || resultList.Count == 0)
                {
                    e = (Exception)ex;
                }
                else
                {
                    ParseTreeNode.AppendResult(context, ex.Argument, (Pipe)null, ref resultList);
                    ex.SetArgument((object)resultList.ToArray());
                    resultList = (ArrayList)null;
                    e          = (Exception)ex;
                }
            }
            catch (RuntimeException ex)
            {
                e = this.HandleException(statement.NodeToken, ex, outputPipe, ref resultList, context);
            }
            if (e != null)
            {
                RuntimeException.LockStackTrace(e);
                throw e;
            }
        }
Beispiel #5
0
        private object ExecuteWithCatch(ParseTreeNode ptn, Array inputToProcess)
        {
            object        newValue    = (object)null;
            CommandOrigin scopeOrigin = this.Context.EngineSessionState.currentScope.ScopeOrigin;

            if (string.IsNullOrEmpty(this.CommandInfo.Name))
            {
                if (!this._fromPipeline)
                {
                    goto label_3;
                }
            }
            newValue = this.Context.GetVariable("MyInvocation");
            this.Context.SetVariable("MyInvocation", (object)this.Command.MyInvocation);
label_3:
            try
            {
                if (this._dontUseScopeCommandOrigin)
                {
                    this.Context.EngineSessionState.currentScope.ScopeOrigin = CommandOrigin.Internal;
                }
                else
                {
                    this.Context.EngineSessionState.currentScope.ScopeOrigin = this.Command.CommandOrigin;
                }
                return(ptn.Execute(inputToProcess, this.commandRuntime.OutputPipe, this.Context));
            }
            catch (ExitException ex)
            {
                if (!this.FromScriptFile || this._rethrowExitException)
                {
                    throw;
                }
                else
                {
                    this._exitWasCalled = true;
                    int num = (int)ex.Argument;
                    this.Command.Context.SetVariable("global:LASTEXITCODE", (object)num);
                    if (num != 0)
                    {
                        this.commandRuntime.PipelineProcessor.ExecutionFailed = true;
                    }
                    return((object)AutomationNull.Value);
                }
            }
            catch (TerminateException ex)
            {
                throw;
            }
            catch (ReturnException ex)
            {
                return(ex.Argument);
            }
            catch (RuntimeException ex)
            {
                this.ManageScriptException(ex);
                throw;
            }
            catch (Exception ex)
            {
                CommandProcessorBase.CheckForSevereException(ex);
                ScriptCommandProcessor.tracer.TraceException(ex);
                throw this.ManageInvocationException(ex);
            }
            finally
            {
                this.Context.EngineSessionState.currentScope.ScopeOrigin = scopeOrigin;
                if (!string.IsNullOrEmpty(this.CommandInfo.Name) || this._fromPipeline)
                {
                    this.Context.SetVariable("MyInvocation", newValue);
                }
            }
        }