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

            NSFTraceLog.PrimaryTraceLog.Enabled = true;

            WorkHardPlayHard workHardPlayHardExample = new WorkHardPlayHard("WorkHardPlayHardExample");

            workHardPlayHardExample.startStateMachine();

            NSFDebugUtility.PrimaryDebugUtility.writeLineToConsole("WorkHardPlayHardExample - Review trace file to see results.");

            // Illustrate transitions and history
            // Work for a while, then play for a while, then take a break, then back to playing via history, then back to work
            Thread.Sleep(100);
            workHardPlayHardExample.milestoneMet();
            Thread.Sleep(100);
            workHardPlayHardExample.takeBreak();
            Thread.Sleep(100);
            workHardPlayHardExample.breakOver();
            Thread.Sleep(100);
            workHardPlayHardExample.backToWork();
            Thread.Sleep(100);

            // Save trace log
            NSFTraceLog.PrimaryTraceLog.saveLog("CommandProcessorExampleTrace.xml");

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

            NSFEnvironment.terminate();
        }
Ejemplo n.º 2
0
        static void Main(String[] args)
        {
            NSFExceptionHandler.ExceptionActions += globalExceptionAction;

            NSFTraceLog.PrimaryTraceLog.Enabled = true;

            Combat combatExample = new Combat("CombatExample");

            combatExample.startStateMachine();

            NSFDebugUtility.PrimaryDebugUtility.writeLineToConsole("CombatExample - Review trace file to see results.");

            // Illustrate transitions taken as distance to enemy changes
            combatExample.sendScoutTeam();
            Thread.Sleep(100);
            combatExample.DistanceToEnemy = combatExample.NearDistance - 1;
            combatExample.sendScoutTeam();
            Thread.Sleep(100);
            combatExample.DistanceToEnemy = combatExample.InRangeDistance - 1;
            combatExample.sendScoutTeam();
            Thread.Sleep(100);

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

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

            NSFEnvironment.terminate();
        }
        static void Main(String[] args)
        {
            NSFExceptionHandler.ExceptionActions += globalExceptionAction;

            NSFTraceLog.PrimaryTraceLog.Enabled = true;

            CycleAB cycleABExample = new CycleAB("CycleABExample");

            cycleABExample.startStateMachine();

            NSFDebugUtility.PrimaryDebugUtility.writeLineToConsole("CycleABExample - Review trace file to see results.");

            // Illustrate a cycle
            // Wait until ready to cycle, cycle, wait until ready again
            while (!cycleABExample.isReadyToCycle())
            {
                Thread.Sleep(100);
            }
            cycleABExample.startCycle();
            while (!cycleABExample.isReadyToCycle())
            {
                Thread.Sleep(100);
            }

            // Save trace log
            NSFTraceLog.PrimaryTraceLog.saveLog("CycleABExampleTrace.xml");

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

            NSFEnvironment.terminate();
        }
Ejemplo n.º 4
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)
        {
            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime;

            // Create Test
            List <ITestInterface> tests = new List <ITestInterface>();

            if ((args.Length >= 1) && (args[0] == "/c"))
            {
                tests.Add(new ContinuouslyRunningTest("Continuously Running Test", 100));
            }
            else
            {
                tests.Add(new TimerResolutionTest("Timer Resolution Test"));
                tests.Add(new TimerAccuracyTest("Timer Accuracy Test"));
                tests.Add(new TimerGetTimeTest("Timer Get Time Test"));
                tests.Add(new ContextSwitchTest("Context Switch Test"));
                tests.Add(new BasicStateMachineTest("Basic State Machine Test"));
                tests.Add(new ShallowHistoryTest("Shallow History Test"));
                tests.Add(new DeepHistoryTest("Deep History Test"));
                tests.Add(new BasicForkJoinTest("Basic Fork Join Test"));
                tests.Add(new DeepHistoryReEntryTest("Deep History Re-entry Test"));
                tests.Add(new StateMachineRestartTest("State Machine Restart Test"));
                tests.Add(new ForkJoinToForkJoinTransitionTest("Fork Join to Fork Join Transition Test"));
                tests.Add(new MultipleTriggersOnTransitionTest("Multiple Triggers on Transition Test"));
                tests.Add(new ExtendedRunTest("Extended Run Test"));
                tests.Add(new ExceptionHandlingTest("Exception Handling Test"));
                tests.Add(new StrategyTest("Strategy Test"));
                tests.Add(new TransitionOrderTest("Transition Order Test"));
                tests.Add(new ChoiceStateTest("Choice State Test"));
                tests.Add(new DocumentNavigationTest("Document Test Load", "ValidTest.xml"));
                tests.Add(new DocumentLoadTest("Invalid Document Test Load", "InvalidTest.xml"));
                tests.Add(new StateMachineDeleteTest("State Machine Delete Test"));
                tests.Add(new TraceAddTest("Trace Add Test", 10000));
                tests.Add(new TimerObservedTimeGapTest("Timer Observed Time Gap Test"));
                tests.Add(new MultipleStateMachineStressTest("Multiple State Machine Stress Test", 100, 100));
                tests.Add(new TimerObservedTimeGapTest("Timer Observed Time Gap Test"));
            }
            // Set up global exception handler
            NSFExceptionHandler.ExceptionActions += globalExceptionAction;

            // Run Test
            bool allTestPassed = true;

            NSFTraceLog.PrimaryTraceLog.addTrace(NSFTraceTags.InformationalTag, "Test", "Start");

            foreach (ITestInterface test in tests)
            {
                string errorMessage = string.Empty;
                if (test.runTest(ref errorMessage))
                {
                    NSFDebugUtility.PrimaryDebugUtility.writeLineToConsole("Passed - " + test.Name);
                }
                else
                {
                    allTestPassed = false;
                    NSFDebugUtility.PrimaryDebugUtility.writeLineToConsole("Failed - " + test.Name);
                    NSFDebugUtility.PrimaryDebugUtility.writeLineToConsole(errorMessage);
                    NSFTraceLog.PrimaryTraceLog.addTrace(NSFTraceTags.InformationalTag, "Test", errorMessage);
                    NSFTraceLog.PrimaryTraceLog.addTrace(NSFTraceTags.InformationalTag, "Test", "End");
                    NSFTraceLog.PrimaryTraceLog.saveLog("TraceFile_" + test.Name + "_Failed.xml");
                }
            }

            if (allTestPassed)
            {
                NSFDebugUtility.PrimaryDebugUtility.writeLineToConsole("All tests passed");
                NSFTraceLog.PrimaryTraceLog.addTrace(NSFTraceTags.InformationalTag, "Test", "All tests passed");
                NSFTraceLog.PrimaryTraceLog.addTrace(NSFTraceTags.InformationalTag, "Test", "End");
                NSFTraceLog.PrimaryTraceLog.saveLog("TraceFile_AllPassed.xml");
            }
            else
            {
                NSFDebugUtility.PrimaryDebugUtility.writeLineToConsole("Some test failed");
            }

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

            NSFEnvironment.terminate();
        }