static void Main(String[] args)
        {
            NSFTraceLog.PrimaryTraceLog.Enabled = true;

            CommandProcessor commandProcessor = new CommandProcessor("CommandProcessor");
            #pragma warning disable 0219
            CommandProcessorObserver commandProcessorObserver = new CommandProcessorObserver(commandProcessor);
            #pragma warning restore 0219

            commandProcessor.startStateMachine();

            // Simple example of polling for state
            int i = 0;
            while (true)
            {
                Thread.Sleep(500);

                if (commandProcessor.isInState(commandProcessor.WaitForCommandState))
                {
                    NSFDebugUtility.PrimaryDebugUtility.writeLineToConsole("Press Enter key to inject a command");
                    Console.ReadKey();
                    commandProcessor.addCommand("TestCommand");
                }
                else if (commandProcessor.isInState(commandProcessor.WaitForResponseState))
                {
                    // Only send two responses
                    if (++i <= 2)
                    {
                        commandProcessor.addResponse("TestResponse");
                    }
                }
                else if (commandProcessor.isInState(commandProcessor.ErrorState))
                {
                    break;
                }
            }

            NSFTraceLog.PrimaryTraceLog.saveLog("CommandProcessorExampleTrace.xml");

            NSFDebugUtility.PrimaryDebugUtility.writeLineToConsole("Press Enter key to continue");
            Console.ReadKey();

            NSFEnvironment.terminate();
        }
        public CommandProcessorObserver(CommandProcessor commandProcessor)
        {
            // Register handleStateChange to be called on state entry.
            commandProcessor.WaitForCommandState.EntryActions += handleStateEntered;
            commandProcessor.WaitForResponseState.EntryActions += handleStateEntered;
            commandProcessor.ErrorState.EntryActions += handleStateEntered;
            commandProcessor.ResetState.EntryActions += handleStateEntered;

            // Register handleStateChange to be called on state exit.
            commandProcessor.WaitForCommandState.ExitActions += handleStateExited;
            commandProcessor.WaitForResponseState.ExitActions += handleStateExited;
            commandProcessor.ErrorState.ExitActions += handleStateExited;
            commandProcessor.ResetState.ExitActions += handleStateExited;

            // Register transition actions to be called on transition from one state to another.
            commandProcessor.WaitForCommandToWaitForResponseTransition.Actions += handleTransition;
            commandProcessor.WaitForResponseToWaitForCommandTransition.Actions += handleTransition;
            commandProcessor.WaitForResponseToErrorTransition.Actions += handleTransition;
            commandProcessor.ErrorToResetTransition.Actions += handleTransition;
            commandProcessor.ResetToWaitForCommandTransition.Actions += handleTransition;
        }