Esempio n. 1
0
        public static void ExpandSectionParams_5()
        {
            EngineState s = EngineTests.CreateEngineState();

            EngineTests.PushDepthInfo(s, 2);

            s.Variables.SetValue(VarsType.Local, "B", "C#");
            Variables.SetVariable(s, "#2", "WPF");

            string[] srcs =
            {
                "A_%A%",
                "B_%B%",
                "C_#1",
                "D_#2"
            };
            List <string> dests = StringEscaper.ExpandSectionParams(s, srcs);

            string[] comps =
            {
                "A_%A%",
                "B_%B%",
                "C_",
                "D_WPF"
            };

            for (int i = 0; i < dests.Count; i++)
            {
                Assert.IsTrue(dests[i].Equals(comps[i], StringComparison.Ordinal));
            }
        }
Esempio n. 2
0
        public void ExpandSectionParams_7()
        {
            EngineState s = EngineTests.CreateEngineState();

            s.SectionReturnValue = "TEST";

            const string src  = "##1 ##a ##r #r";
            string       dest = StringEscaper.ExpandSectionParams(s, src);
            const string comp = "##1 ##a ##r TEST";

            Assert.IsTrue(dest.Equals(comp, StringComparison.Ordinal));
        }
Esempio n. 3
0
        public void ExpandSectionParams_3()
        {
            EngineState s = EngineTests.CreateEngineState();

            s.Variables.SetValue(VarsType.Local, "A", "Hello");

            const string src  = "%A% #1";
            string       dest = StringEscaper.ExpandSectionParams(s, src);
            const string comp = "%A% ##1";

            Assert.IsTrue(dest.Equals(comp, StringComparison.Ordinal));
        }
Esempio n. 4
0
        public void ExpandSectionParams_2()
        {
            EngineState s = EngineTests.CreateEngineState();

            Variables.SetVariable(s, "#1", "World");

            const string src  = "%A% ##2 #1";
            string       dest = StringEscaper.ExpandSectionParams(s, src);
            const string comp = "%A% ##2 World";

            Assert.IsTrue(dest.Equals(comp, StringComparison.Ordinal));
        }
Esempio n. 5
0
        public static void Macro(EngineState s, CodeCommand cmd)
        {
            CodeInfo_Macro info = cmd.Info.Cast <CodeInfo_Macro>();

            bool        isGlobal;
            CodeCommand macroCmd;

            if (s.Macro.GlobalDict.ContainsKey(info.MacroType))
            {
                macroCmd         = s.Macro.GlobalDict[info.MacroType];
                macroCmd.RawCode = cmd.RawCode;
                isGlobal         = true;
            }
            else if (s.Macro.LocalDict.ContainsKey(info.MacroType))
            {
                macroCmd         = s.Macro.LocalDict[info.MacroType];
                macroCmd.RawCode = cmd.RawCode;
                isGlobal         = false;
            }
            else
            {
                s.Logger.BuildWrite(s, new LogInfo(LogState.Error, $"Invalid Command [{info.MacroType}]", cmd, s.CurDepth));
                return;
            }

            Dictionary <int, string> paramDict = new Dictionary <int, string>();

            for (int i = 0; i < info.Args.Count; i++)
            {
                paramDict[i + 1] = StringEscaper.ExpandSectionParams(s, info.Args[i]);
            }

            s.CurSectionInParams = paramDict;
            s.Logger.BuildWrite(s, new LogInfo(LogState.Info, $"Executing Command [{info.MacroType}]", cmd, s.CurDepth));

            // Backup and set EngineState values
            int realScriptIdBackup = s.RefScriptId;

            if (isGlobal)
            {
                s.RefScriptId = s.Logger.BuildRefScriptWrite(s, macroCmd.Section.Script);
            }
            s.InMacro = true;

            CommandBranch.RunExec(s, macroCmd, true);

            // Restore and reset EngineState values
            s.RefScriptId = realScriptIdBackup;
            s.InMacro     = false;
        }
Esempio n. 6
0
        public static void Macro(EngineState s, CodeCommand cmd)
        {
            CodeInfo_Macro info = cmd.Info.Cast <CodeInfo_Macro>();

            CodeCommand macroCmd;

            if (s.Macro.GlobalDict.ContainsKey(info.MacroType))
            {
                macroCmd = s.Macro.GlobalDict[info.MacroType];
            }
            else if (s.Macro.LocalDict.ContainsKey(info.MacroType))
            {
                macroCmd = s.Macro.LocalDict[info.MacroType];
            }
            else
            {
                throw new ExecuteException($"Invalid command [{info.MacroType}]");
            }

            Dictionary <int, string> paramDict = new Dictionary <int, string>();

            for (int i = 0; i < info.Args.Count; i++)
            {
                paramDict[i + 1] = StringEscaper.ExpandSectionParams(s, info.Args[i]);
            }

            s.CurSectionInParams = paramDict;
            s.Logger.BuildWrite(s, new LogInfo(LogState.Info, $"Executing command [{info.MacroType}]", cmd, s.PeekDepth));

            if (macroCmd.Type == CodeType.Run || macroCmd.Type == CodeType.RunEx || macroCmd.Type == CodeType.Exec)
            {
                CommandBranch.RunExec(s, macroCmd, new CommandBranch.RunExecOptions
                {
                    PreserveCurrentParams = true,
                    IsMacro = true,
                });
            }
            else
            {
                s.PushLocalState(true, s.Logger.BuildRefScriptWrite(s, macroCmd.Section.Script, true));
                Engine.ExecuteCommand(s, macroCmd);
                s.PopLocalState();
            }
        }