Пример #1
0
 static void PrintState(EventFeedStateMachine stateMachine) =>
 Console.WriteLine($"Current state: {stateMachine.State.ToString()}");
Пример #2
0
 static void PrintExceptionsReceived(EventFeedStateMachine stateMachine) =>
 Console.WriteLine($"Exceptions received: {stateMachine.ExceptionsReceived}");
Пример #3
0
        static void Main(string[] args)
        {
            var stateMachine = new EventFeedStateMachine(threshold: 3);

            /* Current state: Normal */
            PrintState(stateMachine);

            Console.WriteLine();

            /*
             * Exception occurred
             * Exceptions received: 1
             * Current state: Exception
             */
            PrintExceptionOccurred();
            stateMachine.ExceptionOccurred(new Exception());
            PrintExceptionsReceived(stateMachine);
            PrintState(stateMachine);

            Console.WriteLine();

            /*
             * Exception occurred
             * Exceptions received: 2
             * Current state: Exception
             */
            PrintExceptionOccurred();
            stateMachine.ExceptionOccurred(new Exception());
            PrintExceptionsReceived(stateMachine);
            PrintState(stateMachine);

            Console.WriteLine();

            /*
             * Exception occurred
             * Exceptions received: 2
             * Current state: Exception
             */
            PrintExceptionOccurred();
            stateMachine.ExceptionOccurred(new Exception());
            PrintExceptionsReceived(stateMachine);
            PrintState(stateMachine);

            Console.WriteLine();

            /*
             * Successful dispatch
             * Current state: Normal
             */
            PrintSuccessfulDispatch();
            stateMachine.SuccessfulDispatch();
            PrintState(stateMachine);

            Console.WriteLine();

            /*
             * Exception occurred
             * Exceptions received: 1
             * Current state: Exception
             */
            PrintExceptionOccurred();
            stateMachine.ExceptionOccurred(new Exception());
            PrintExceptionsReceived(stateMachine);
            PrintState(stateMachine);

            Console.WriteLine();

            /*
             * Successful dispatch
             * Current state: Normal
             */
            PrintSuccessfulDispatch();
            stateMachine.SuccessfulDispatch();
            PrintState(stateMachine);

            Console.ReadLine();
        }