Exemplo n.º 1
0
        static void Main(String[] args)
        {
            NSFExceptionHandler.ExceptionActions += globalExceptionAction;

            NSFTraceLog.PrimaryTraceLog.Enabled = true;

            CommandProcessorWithRetry commandProcessor = new CommandProcessorWithRetry("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))
                {
                    // Should see the retry attempt followed by an error
                    break;
                }
            }

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

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

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

            CommandProcessorWithRetry commandProcessor = new CommandProcessorWithRetry("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))
                {
                    // Should see the retry attempt followed by an error
                    break;
                }
            }

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

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

            NSFEnvironment.terminate();
        }