public void DeleteVariable() { var test = @" 0:0 when the script starts, 5:100 set variable %hi to {hi}. 5:107 delete variable %hi. 1:100 and variable %hi is defined, 5:102 print {@var %hi does exist} to the console. 1:101 and variable %hi is not defined, 5:102 print {@var %hi does not exist} to the console. "; var engine = new Monkeyspeak.MonkeyspeakEngine { Options = { TriggerLimit = int.MaxValue, Debug = true } }; var page = engine.LoadFromString(test); page.AddTriggerHandler(TriggerCategory.Cause, 0, UnitTest1.HandleScriptStartCause); page.LoadAllLibraries(); page.Execute(); foreach (var var in page.Scope) { Logger.Debug(var); } Console.WriteLine("Page Trigger Count: " + page.Size); }
public void TestParallelExecute() { var ioTestString = @" (0:0) when the script starts, (5:100) set variable %file to {test.txt}. (1:200) and the file {%file} exist, (5:202) delete file {%file}. (5:203) create file {%file}. (0:0) when the script starts, (5:102) print {%file} to the console. (5:150) take variable %increment and add 1 to it. (5:102) print {Execution increment %increment} to the console. (0:0) when the script starts, (1:200) and the file {%file} exists, (1:203) and the file {%file} can be written to, (5:200) append {Hello World from Monkeyspeak %VERSION!} to file {%file}. (0:0) when the script starts, (5:150) take variable %test and add 2 to it. (5:102) print {%test} to the console. "; var engine = new Monkeyspeak.MonkeyspeakEngine { Options = { TriggerLimit = int.MaxValue } }; engine.Options.Debug = false; var page = engine.LoadFromString(UnitTest1.tableScript); page.AddTriggerHandler(TriggerCategory.Cause, 0, UnitTest1.HandleScriptStartCause); page.LoadAllLibraries(); var tasks = new Task[5]; for (int i = 0; i <= tasks.Length - 1; i++) { tasks[i] = Task.Run(async() => await page.ExecuteAsync(0)); } Console.WriteLine("Page Trigger Count: " + page.Size); Task.WaitAll(tasks); foreach (var variable in page.Scope) { Console.WriteLine(variable.ToString()); } }