Exemplo n.º 1
0
 private object EvaluateLambdaExpression(LambdaExpression lambdaExpression, CodeContext codeContext)
 {
     ExecuteScriptInstruction esi = new ExecuteScriptInstruction(codeContext, lambdaExpression.Body.GetText());
     return esi;
 }
Exemplo n.º 2
0
        public void TestAnonymousMethods()
        {
            CodeContext context = new CodeContext(mElementRuntime);
            ExecuteScriptInstruction instruction = new ExecuteScriptInstruction(context, "this.X = 64;");

            instruction.Execute();
            ScriptParsingPlugin.Self.CallUpdate();
            if (mElementRuntime.X != 64)
            {
                throw new Exception("ExecuteScriptInstruction is not positioning properly");
            }

            object result = mExpressionParser.EvaluateExpression("() => this.X = 3 ", context);

            if (result as ExecuteScriptInstruction == null)
            {
                throw new Exception("ExecuteScriptInstruction is not returning a script instruction");
            }

            result = mExpressionParser.EvaluateExpression("() => {this.X = 3;} ", context);

            if (result as ExecuteScriptInstruction == null)
            {
                throw new Exception("ExecuteScriptInstruction is not returning a script instruction");
            }

            string line = "this.Call( () => this.X = -32 ).After(0);";
            string[] lines = new string[] { line };
            mPlugin.ApplyLinesInternal(lines, 0, 1, mElementRuntime.AssociatedIElement, new CodeContext(mElementRuntime));
            if (mElementRuntime.Instructions.Count == 0)
            {
                throw new Exception("Instructions are not being added properly to elements when using the Call method");
            }

            // Forces the instructions to execute
            mElementRuntime.ExecuteInstructions(TimeManager.CurrentTime + 1);
            ScriptParsingPlugin.Self.CallUpdate();

            if (mElementRuntime.Instructions.Count != 0)
            {
                throw new Exception("The instructions are not executing properly");
            }

            if (mElementRuntime.X != -32)
            {
                throw new Exception("The instruction set earlier is not properly being applied");
            }

            // Test just like above, but multi-line
            lines = new string[] {
                "this.Call( ",
                "() => this.X = -128 ).After(0);"
            };

            mPlugin.ApplyLinesInternal(lines, 0, lines.Length, mElementRuntime.AssociatedIElement, new CodeContext(mElementRuntime));
            if (mElementRuntime.Instructions.Count == 0)
            {
                throw new Exception("Instructions are not being added properly to elements when using the Call method");
            }
            // Forces the instructions to execute
            mElementRuntime.ExecuteInstructions(TimeManager.CurrentTime + 1);
            ScriptParsingPlugin.Self.CallUpdate();
            if (mElementRuntime.X != -128)
            {
                throw new Exception("ExecuteScriptInstruction is not positioning properly");
            }

            // Let's test multiline with semicolons
            lines = new string[] {
            "this.Call(",
            "    () => ",
            "    { ",
            "        this.X = 256; ",
            "    }",
            "    ).After(0);"};

            int numberOfLinesInStatement = ScriptParsingPlugin.Self.GetNumberOfLinesInRegularStatement(lines, 0);

            if (numberOfLinesInStatement != 6)
            {
                throw new Exception("The number of lines should be 6, not " + numberOfLinesInStatement);
            }

            mPlugin.ApplyLinesInternal(lines, 0, lines.Length, mElementRuntime.AssociatedIElement, new CodeContext(mElementRuntime));
            if (mElementRuntime.Instructions.Count == 0)
            {
                throw new Exception("Instructions are not being added properly to elements when using the Call method");
            }
            // Forces the instructions to execute
            mElementRuntime.ExecuteInstructions(TimeManager.CurrentTime + 1);
            ScriptParsingPlugin.Self.CallUpdate();
            if (mElementRuntime.X != 256)
            {
                throw new Exception("ExecuteScriptInstruction is not positioning properly");
            }



            lines = new string[] {
            "this.Set(\"X\").To(3.2f).After(1);"};

            
            mPlugin.ApplyLinesInternal(lines, 0, lines.Length, mElementRuntime.AssociatedIElement, new CodeContext(mElementRuntime));
            if (mElementRuntime.Instructions.Count == 0)
            {
                throw new Exception("Instructions are not being added properly to elements when using the Call method");
            }
            // Forces the instructions to execute
            mElementRuntime.ExecuteInstructions(TimeManager.CurrentTime + 3);
            ScriptParsingPlugin.Self.CallUpdate();
            if (mElementRuntime.X != 3.2f)
            {
                throw new Exception("ExecuteScriptInstruction is not positioning properly");
            }
        }