static Script BuildScriptTree(List <IScriptCommand> commands) { Stack <List <IScriptCommand> > context = new Stack <List <IScriptCommand> >(); foreach (IScriptCommand command in commands) { if (context.Count() == 0) { context.Push(new List <IScriptCommand>()); } ; if (command.Type.Equals("basic") && command.GetType() != typeof(LoopStartCommand) && command.GetType() != typeof(LoopEndCommand)) { context.Peek().Add(command); } if (command.GetType() == typeof(LoopStartCommand)) { List <IScriptCommand> newContext = new List <IScriptCommand>(); newContext.Add(command); context.Push(newContext); } if (command.GetType() == typeof(LoopEndCommand)) { List <IScriptCommand> currentContext = context.Pop(); LoopStartCommand loopStart = (LoopStartCommand)currentContext[0]; currentContext.RemoveAt(0); LoopCommand loop = new LoopCommand(loopStart, currentContext, (LoopEndCommand)command); context.Peek().Add(loop); } } return(new Script(context.Pop())); }
private static IScriptCommand BuildComplexCommand(string CommandName, params object[] args) { switch (CommandName) { case "loop": LoopStartCommand start = (LoopStartCommand)args[0]; List <IScriptCommand> commands = (List <IScriptCommand>)args[1]; LoopEndCommand end = (LoopEndCommand)args[2]; return(new LoopCommand(start, commands, end)); case "script": List <IScriptCommand> scriptsCommands = (List <IScriptCommand>)args[0]; return(new CompositeCommand(scriptsCommands)); case "composite": List <IScriptCommand> compositeCommands = (List <IScriptCommand>)args[0]; return(new CompositeCommand(compositeCommands)); } return(null); }
public void VisitLoopStart(LoopStartCommand Start) { System.Console.WriteLine("loop-start " + Start.Loops); }
public LoopCommand(LoopStartCommand start, List <IScriptCommand> commands, LoopEndCommand end) : base(commands) { Start = start; End = end; }
private void SerializeIf(LoopStartCommand cmd) { sb.AppendFormat("loop_start_if {0}\n", cmd.LoopCount); }