Ejemplo n.º 1
0
        public void LoadInterruptionHandlingProgram(string[] commands, string interruptName)
        {
            Timer.Stop();

            LogText(interruptName, LogLevel.Interrupt);
            Commands.Push(commands);
            CurrentIndices.Push(0);
            State = ExecutorState.Normal;

            Timer.Start();
        }
Ejemplo n.º 2
0
 public Executor(string[] commands, TimeSpan interval, ILogger logger, MainWindow _main)
 {
     Commands.Push((string[])commands.Clone());
     CurrentIndices.Push(0);
     Logger = logger;
     main   = _main;
     Timer  = new DispatcherTimer
     {
         Interval = interval
     };
     Timer.Tick += Timer_Tick;
 }
Ejemplo n.º 3
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            if (State == ExecutorState.Normal)
            {
                var index = CurrentIndices.Peek();
                if (CurrentIndices.Peek() < Commands.Peek().Length)
                {
                    ProcessCommand(Commands.Peek()[index]);
                    CurrentIndices.Pop();
                    CurrentIndices.Push(index + 1);
                }
                else
                {
                    LogText("Program finished");
                    Timer.Stop();
                }
            }
            else if (State == ExecutorState.Reverse)
            {
                string command = "";
                do
                {
                    var index = CurrentIndices.Peek() - 1;

                    if (index < 0)
                    {
                        CurrentIndices.Pop();
                        Commands.Pop();
                        LogText("State recovered");

                        if (CurrentIndices.Count == 1)
                        {
                            State = ExecutorState.Normal;
                            LogText("Resuming execution");
                            return; //goto timer_tick
                        }
                    }
                    else
                    {
                        command = InvertCommand(Commands.Peek()[index]);
                        CurrentIndices.Pop();
                        CurrentIndices.Push(index);
                    }
                } while (command == "");

                ProcessCommand(command);
            }
        }