Beispiel #1
0
        static void Main(string[] args)
        {
            const string on    = "On";
            const string off   = "Off";
            const char   space = ' ';

            // Instantiate a new state machine in the 'off' state
            var onOffSwitch = new StateMachine <string, char>(off);

            // Configure state machine with the Configure method, supplying the state to be configured as a parameter
            onOffSwitch.Configure(off).Permit(space, on);
            onOffSwitch.Configure(on).Permit(space, off);

            Console.WriteLine(UmlDotGraph.Format(onOffSwitch.GetInfo()));

            Console.WriteLine("Press <space> to toggle the switch. Any other key will exit the program.");

            while (true)
            {
                Console.WriteLine("Switch is in state: " + onOffSwitch.State);
                var pressed = Console.ReadKey(true).KeyChar;

                // Check if user wants to exit
                if (pressed != space)
                {
                    break;
                }

                // Use the Fire method with the trigger as payload to supply the state machine with an event.
                // The state machine will react according to its configuration.
                onOffSwitch.Fire(pressed);
            }
        }
Beispiel #2
0
        public void OnEntryWithTriggerParameter()
        {
            var expected = prefix(Style.UML) + box(Style.UML, "A", new List <string> {
                "OnEntry"
            })
                           + box(Style.UML, "B") + box(Style.UML, "C")
                           + line("A", "B", "X / BX")
                           + line("A", "C", "Y / TestEntryActionString [IsTriggerY]")
                           + line("A", "B", "Z [IsTriggerZ]")
                           + suffix;

            Func <bool> anonymousGuard = () => true;
            var         sm             = new StateMachine <State, Trigger>(State.A);
            var         parmTrig       = sm.SetTriggerParameters <string>(Trigger.Y);

            sm.Configure(State.A)
            .OnEntry(() => { }, "OnEntry")
            .Permit(Trigger.X, State.B)
            .PermitIf(Trigger.Y, State.C, anonymousGuard, "IsTriggerY")
            .PermitIf(Trigger.Z, State.B, anonymousGuard, "IsTriggerZ");

            sm.Configure(State.B)
            .OnEntryFrom(Trigger.X, TestEntryAction, "BX");

            sm.Configure(State.C)
            .OnEntryFrom(parmTrig, TestEntryActionString);

            string dotGraph = UmlDotGraph.Format(sm.GetInfo());

#if WRITE_DOTS_TO_FOLDER
            System.IO.File.WriteAllText(DestinationFolder + "OnEntryWithTriggerParameter.dot", dotGraph);
#endif

            Assert.Equal(expected, dotGraph);
        }
Beispiel #3
0
        private StateMachine <OrderStatus, OrderTrigger> Configure()
        {
            stateMachine = new StateMachine <OrderStatus, OrderTrigger>(order.Status);

            stateMachine.Configure(OrderStatus.New)
            .Permit(OrderTrigger.Approve, OrderStatus.Approved)
            .Permit(OrderTrigger.Cancel, OrderStatus.Canceled);

            stateMachine.Configure(OrderStatus.Approved)
            .Permit(OrderTrigger.Delivery, OrderStatus.Delivered)
            .Permit(OrderTrigger.Cancel, OrderStatus.Canceled);

            stateMachine.Configure(OrderStatus.Approved)
            .OnEntryAsync(ApproveOrderAsync);

            stateMachine.Configure(OrderStatus.Delivered)
            .OnEntryAsync(DeliveryOrderAsync);

            stateMachine.Configure(OrderStatus.Canceled)
            .OnEntryAsync(CancelOrderAsync);

            var graph = UmlDotGraph.Format(stateMachine.GetInfo());

            return(stateMachine);
        }
Beispiel #4
0
        public void UmlWithDynamic()
        {
            var expected = prefix(Style.UML)
                           + box(Style.UML, "A")
                           + box(Style.UML, "B")
                           + box(Style.UML, "C")
                           + decision(Style.UML, "Decision1", "DestinationSelector")
                           + line("A", "Decision1", "X")
                           + line("Decision1", "B", "X [ChoseB]")
                           + line("Decision1", "C", "X [ChoseC]")
                           + suffix;

            var sm = new StateMachine <State, Trigger>(State.A);

            sm.Configure(State.A)
            .PermitDynamic(Trigger.X, DestinationSelector, null, new DynamicStateInfos {
                { State.B, "ChoseB" }, { State.C, "ChoseC" }
            });

            sm.Configure(State.B);
            sm.Configure(State.C);

            string dotGraph = UmlDotGraph.Format(sm.GetInfo());

#if WRITE_DOTS_TO_FOLDER
            System.IO.File.WriteAllText(DestinationFolder + "UmlWithDynamic.dot", dotGraph);
#endif

            Assert.Equal(expected, dotGraph);
        }
Beispiel #5
0
        public void TransitionWithIgnoreAndEntry()
        {
            var expected = prefix(Style.UML)
                           + box(Style.UML, "A", new List <string> {
                "DoEntry"
            })
                           + box(Style.UML, "B", new List <string> {
                "DoThisEntry"
            })
                           + line("A", "B", "X")
                           + line("A", "A", "Y")
                           + line("B", "B", "Z / DoThisEntry")
                           + suffix;

            var sm = new StateMachine <State, Trigger>(State.A);

            sm.Configure(State.A)
            .OnEntry(TestEntryAction, "DoEntry")
            .Ignore(Trigger.Y)
            .Permit(Trigger.X, State.B);

            sm.Configure(State.B)
            .OnEntry(TestEntryAction, "DoThisEntry")
            .PermitReentry(Trigger.Z);

            string dotGraph = UmlDotGraph.Format(sm.GetInfo());

#if WRITE_DOTS_TO_FOLDER
            System.IO.File.WriteAllText(DestinationFolder + "TransitionWithIgnoreAndEntry.dot", dotGraph);
#endif

            Assert.Equal(expected, dotGraph);
        }
Beispiel #6
0
        public static void Test1()
        {
            var stateMachine = new StateMachine <OrderItemStatus, EventType>(OrderItemStatus.Enquired);

            stateMachine.Configure(OrderItemStatus.Enquired)
            .Permit(EventType.SupplierConfirm, OrderItemStatus.SupplierConfirmed)
            .Permit(EventType.Cancel, OrderItemStatus.Cancelled);

            stateMachine.Configure(OrderItemStatus.SupplierConfirmed)
            .OnEntry(() => { Console.WriteLine("Supplier Confirmed Entry"); })
            .OnExit(() => { Console.WriteLine("Supplier Confirmed Exit"); })
            .Permit(EventType.Confirm, OrderItemStatus.Confirmed)
            .Permit(EventType.Cancel, OrderItemStatus.Cancelled);

            Console.WriteLine(stateMachine.State);

            stateMachine.Fire(EventType.SupplierConfirm);
            Console.WriteLine(stateMachine.State);

            var validate1 = stateMachine.IsInState(OrderItemStatus.SupplierConfirmed);

            stateMachine.Fire(EventType.Cancel);
            Console.WriteLine(stateMachine.State);

            string graph = UmlDotGraph.Format(stateMachine.GetInfo());

            Console.ReadLine();
        }
Beispiel #7
0
        public void PrintUmlDotGraph()
        {
            string graph = UmlDotGraph.Format(_machine.GetInfo());

            Console.WriteLine("UmlDotGraph:");
            Console.WriteLine(graph);
        }
Beispiel #8
0
        public (string diagram, string contentType) Diagram()
        {
            Rules(Machine);
            var d = UmlDotGraph.Format(Machine.GetInfo());

            return(d, "text/vnd.graphviz");
        }
Beispiel #9
0
        private void ConfigureStatemachine()
        {
            _sm = new StateMachine <State, Trigger>(State.Starting);

            // Instantiate a new trigger with a parameter.
            _joinTrigger = _sm.SetTriggerParameters <RunWorkerCompletedEventArgs>(Trigger.Join);

            // always starts in Paused state, to be able to load the state before running, or set breakpoints
            _sm.Configure(State.Starting)
            .Permit(Trigger.Start, State.Paused);

            _sm.Configure(State.Started)
            .OnEntry(sm_OnEntry_Started);

            _sm.Configure(State.Paused)
            .SubstateOf(State.Started)
            .OnEntryFrom(_joinTrigger, sm_OnEntry_Paused)
            .OnExit(sm_OnExit_Paused)
            .Ignore(Trigger.Pause)
            .Permit(Trigger.Unpause, State.Running)
            .Permit(Trigger.Terminate, State.Terminated);

            _sm.Configure(State.Running)
            .SubstateOf(State.Started)
            .OnEntry(sm_OnEntry_Running)
            .Permit(Trigger.Join, State.Paused)
            .Permit(Trigger.Suspend, State.Suspended)
            .Permit(Trigger.Pause, State.Pausing)
            .Ignore(Trigger.Unpause)
            .Permit(Trigger.Terminate, State.Terminating);

            _sm.Configure(State.Suspended)
            .SubstateOf(State.Running)
            .Permit(Trigger.Resume, State.Running)
            .OnEntry(sm_OnEntry_Suspended)
            .OnExit(sm_OnExit_Suspended);

            _sm.Configure(State.Pausing)
            .SubstateOf(State.Running)
            .OnEntry(sm_OnStopping)
            .Permit(Trigger.Join, State.Paused);

            _sm.Configure(State.Terminating)
            .SubstateOf(State.Running)
            .OnEntry(sm_OnStopping)
            .Permit(Trigger.Join, State.Terminated);

            _sm.Configure(State.Terminated)
            .OnEntryFrom(_joinTrigger, sm_OnEntry_Terminated);

            _sm.OnTransitioned(t => WriteMessage($"OnTransitioned: {t.Source} -> {t.Destination} via {t.Trigger}({string.Join( ", ", t.Parameters )})"));

            string dotGraph = UmlDotGraph.Format(_sm.GetInfo());

            System.IO.File.WriteAllText(@"s:\source\repos\Robotron_2084\VirtuRoC\tmp\MachineOperator.dot", dotGraph);
        }
Beispiel #10
0
        private StateMachine <State, Trigger> CreateStateMachine()
        {
            var stateMachine = new StateMachine <State, Trigger>(State.Aus);

            stateMachine.Configure(State.Aus)
            .InternalTransition(Trigger.Aktualisieren, _ => _stateAus.Doing())
            .Permit(Trigger.Hochfahren, State.Hochfahren)
            .Permit(Trigger.Reset, State.Reset);

            stateMachine.Configure(State.Hochfahren)
            .InternalTransition(Trigger.Aktualisieren, _ => _stateHochfahren.Doing())
            .Permit(Trigger.Synchronisieren, State.Synchronisieren)
            .Permit(Trigger.MaschineTot, State.MaschineTot)
            .Permit(Trigger.VentilGeschlossen, State.Aus)
            .Permit(Trigger.Reset, State.Reset);

            stateMachine.Configure(State.Synchronisieren)
            .OnEntry(() => _stateSynchronisieren.OnEntry())
            .Permit(Trigger.MaschineTot, State.MaschineTot)
            .Permit(Trigger.Belasten, State.Belasten)
            .Permit(Trigger.Reset, State.Reset);

            stateMachine.Configure(State.MaschineTot)
            .OnEntry(() => _stateMaschineTot.OnEntry())
            .Permit(Trigger.Reset, State.Reset);

            stateMachine.Configure(State.Belasten)
            .OnEntry(() => _stateBelasten.OnEntry())
            .InternalTransition(Trigger.Aktualisieren, _ => _stateBelasten.Doing())
            .Permit(Trigger.MaschineTot, State.MaschineTot)
            .Permit(Trigger.LeistungsschalterAus, State.LeistungsschalterAus)
            .Permit(Trigger.Reset, State.Reset);

            stateMachine.Configure(State.LeistungsschalterAus)
            .InternalTransition(Trigger.Aktualisieren, _ => _stateLeistungsschalterAus.Doing())
            .Permit(Trigger.MaschineTot, State.MaschineTot)
            .Permit(Trigger.VentilGeschlossen, State.Aus)
            .Permit(Trigger.Reset, State.Reset);

            stateMachine.Configure(State.Reset)
            .OnEntry(() => _stateReset.OnEntry())
            .Permit(Trigger.Neustart, State.Aus);

            stateMachine.OnUnhandledTrigger((_, _) =>
            {
                Console.WriteLine("Unhandled:");
            });

            var graph = UmlDotGraph.Format(stateMachine.GetInfo());

            Console.Write("\n \n" + graph + "\n \n");

            return(stateMachine);
        }
Beispiel #11
0
        public void OnExitWithAnonymousActionAndDescription()
        {
            var expected = prefix(Style.UML) + box(Style.UML, "A", null, new List <string> {
                "exitA"
            }) + suffix;

            var sm = new StateMachine <State, Trigger>(State.A);

            sm.Configure(State.A)
            .OnExit(() => { }, "exitA");

            Assert.Equal(expected, UmlDotGraph.Format(sm.GetInfo()));
        }
Beispiel #12
0
        public void OnEntryWithNamedDelegateActionAndDescription()
        {
            var expected = prefix(Style.UML) + box(Style.UML, "A", new List <string> {
                "enteredA"
            }) + suffix;

            var sm = new StateMachine <State, Trigger>(State.A);

            sm.Configure(State.A)
            .OnEntry(OnEntry, "enteredA");

            Assert.Equal(expected, UmlDotGraph.Format(sm.GetInfo()));
        }
Beispiel #13
0
        public void WhenDiscriminatedByNamedDelegateWithDescription()
        {
            var expected = prefix(Style.UML)
                           + box(Style.UML, "A") + box(Style.UML, "B")
                           + line("A", "B", "X [description]")
                           + suffix;

            var sm = new StateMachine <State, Trigger>(State.A);

            sm.Configure(State.A)
            .PermitIf(Trigger.X, State.B, IsTrue, "description");
            sm.Configure(State.B);
            Assert.Equal(expected, UmlDotGraph.Format(sm.GetInfo()));
        }
Beispiel #14
0
        public void WhenDiscriminatedByNamedDelegate()
        {
            var expected = Prefix(Style.UML)
                           + Box(Style.UML, "A") + Box(Style.UML, "B")
                           + Line("A", "B", "X [IsTrue]")
                           + suffix;

            var sm = new StateMachine <State, Trigger>(State.A);

            sm.Configure(State.A)
            .PermitIf(Trigger.X, State.B, IsTrue);

            Assert.Equal(expected, UmlDotGraph.Format(sm.GetInfo()));
        }
Beispiel #15
0
        public void WhenDiscriminatedByAnonymousGuard()
        {
            Func <bool> anonymousGuard = () => true;

            var expected = prefix(Style.UML) + box(Style.UML, "A") + box(Style.UML, "B")
                           + line("A", "B", "X [" + InvocationInfo.DefaultFunctionDescription + "]")
                           + suffix;
            var sm = new StateMachine <State, Trigger>(State.A);

            sm.Configure(State.A)
            .PermitIf(Trigger.X, State.B, anonymousGuard);
            sm.Configure(State.B);

            Assert.Equal(expected, UmlDotGraph.Format(sm.GetInfo()));
        }
Beispiel #16
0
        public DefineRulesVM(IProcessingRuleDataService processingRuleDataService, IEntryDataService entryDataService,
                             IPeriodDataService periodDataService, ITransactionDataService transactionDataService, ILogFile logFile)
        {
            mProcessingRuleDataService = processingRuleDataService;
            mEntryDataService          = entryDataService;
            mPeriodDataService         = periodDataService;
            mTransactionDataService    = transactionDataService;
            mLogFile = logFile;

            MatchingTransactions = new ObservableCollection <Transaction>();

            InitializeStateMachine();

            mLogFile.Debug($"DefineRulesVM.MainStm: {UmlDotGraph.Format(mMainStm.GetInfo())}");
        }
Beispiel #17
0
        public void TwoSimpleTransitions()
        {
            var expected = prefix(Style.UML) + box(Style.UML, "A") + box(Style.UML, "B") + box(Style.UML, "C")
                           + line("A", "B", "X")
                           + line("A", "C", "Y")
                           + suffix;

            var sm = new StateMachine <State, Trigger>(State.A);

            sm.Configure(State.A)
            .Permit(Trigger.X, State.B)
            .Permit(Trigger.Y, State.C);

            Assert.Equal(expected, UmlDotGraph.Format(sm.GetInfo()));
        }
Beispiel #18
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, world!");
            State CurrentState = State.OFF;

            sm1 = new StateMachine <State, Trigger>(() => CurrentState, s => CurrentState = s);
            sm1.Configure(State.ON).Permit(Trigger.TOGGLE, State.OFF);

            sm1.Configure(State.OFF).PermitIf(Trigger.TOGGLE, State.ON, () => IsLightNeeded(), "Toggle allowed")
            .PermitReentryIf(Trigger.TOGGLE, () => !IsLightNeeded(), "Toggle not allowed");

            sm1.Fire(Trigger.TOGGLE);
            string graph = UmlDotGraph.Format(sm1.GetInfo());

            Console.WriteLine(graph);
        }
Beispiel #19
0
        public void SpacedUmlWithSubstate()
        {
            string StateA   = "State A";
            string StateB   = "State B";
            string StateC   = "State C";
            string StateD   = "State D";
            string TriggerX = "Trigger X";
            string TriggerY = "Trigger Y";

            var expected = Prefix(Style.UML)
                           + Subgraph(Style.UML, StateD, $"{StateD}\\n----------\\nentry / Enter D",
                                      Box(Style.UML, StateB)
                                      + Box(Style.UML, StateC))
                           + Box(Style.UML, StateA, new List <string> {
                "Enter A"
            }, new List <string> {
                "Exit A"
            })
                           + Line(StateA, StateB, TriggerX) + Line(StateA, StateC, TriggerY)
                           + Environment.NewLine
                           + $" init [label=\"\", shape=point];" + Environment.NewLine
                           + $" init -> \"{StateA}\"[style = \"solid\"]" + Environment.NewLine
                           + "}";

            var sm = new StateMachine <string, string>("State A");

            sm.Configure(StateA)
            .Permit(TriggerX, StateB)
            .Permit(TriggerY, StateC)
            .OnEntry(TestEntryAction, "Enter A")
            .OnExit(TestEntryAction, "Exit A");

            sm.Configure(StateB)
            .SubstateOf(StateD);
            sm.Configure(StateC)
            .SubstateOf(StateD);
            sm.Configure(StateD)
            .OnEntry(TestEntryAction, "Enter D");

            string dotGraph = UmlDotGraph.Format(sm.GetInfo());

#if WRITE_DOTS_TO_FOLDER
            System.IO.File.WriteAllText(DestinationFolder + "UmlWithSubstate.dot", dotGraph);
#endif

            Assert.Equal(expected, dotGraph);
        }
Beispiel #20
0
        public void SimpleTransitionUML()
        {
            var expected = prefix(Style.UML) + box(Style.UML, "A") + box(Style.UML, "B") + line("A", "B", "X") + suffix;

            var sm = new StateMachine <State, Trigger>(State.A);

            sm.Configure(State.A)
            .Permit(Trigger.X, State.B);

            string dotGraph = UmlDotGraph.Format(sm.GetInfo());

#if WRITE_DOTS_TO_FOLDER
            System.IO.File.WriteAllText(DestinationFolder + "SimpleTransitionUML.dot", dotGraph);
#endif

            Assert.Equal(expected, dotGraph);
        }
Beispiel #21
0
        public void TransitionWithIgnore()
        {
            // Ignored triggers do not appear in the graph
            var expected = prefix(Style.UML)
                           + box(Style.UML, "A") + box(Style.UML, "B")
                           + line("A", "B", "X")
                           + line("A", "A", "Y")
                           + suffix;

            var sm = new StateMachine <State, Trigger>(State.A);

            sm.Configure(State.A)
            .Ignore(Trigger.Y)
            .Permit(Trigger.X, State.B);

            Assert.Equal(expected, UmlDotGraph.Format(sm.GetInfo()));
        }
Beispiel #22
0
        public void OnExitWithNamedDelegateActionAndDescription()
        {
            var sm = new StateMachine <State, Trigger>(State.A);

            sm.Configure(State.A)
            .OnExit(OnExit, "exitA");

            var expected = Prefix(Style.UML) + Box(Style.UML, "A", null, new List <string> {
                "exitA"
            }) + suffix;

            Assert.Equal(expected, UmlDotGraph.Format(sm.GetInfo()));
            expected = Prefix(Style.UML) + Box(Style.UML, "A", null, new List <string> {
                "exitA"
            }) + suffix;
            Assert.Equal(expected, UmlDotGraph.Format(sm.GetInfo()));
        }
Beispiel #23
0
        public Lamp()
        {
            machine = new StateMachine <LampState, Trigger>(LampState.Off);

            machine.Configure(LampState.Off)
            .Permit(Trigger.Switch, LampState.On);

            machine.Configure(LampState.On)
            .Permit(Trigger.Switch, LampState.Blink)
            .Permit(Trigger.Stop, LampState.Off)
            .OnEntry(() => Console.WriteLine("wlaczono"), "wyslij powitanie")
            .OnExit(() => Console.WriteLine("THX"), "wyslij pozegnanie");
            ;

            machine.Configure(LampState.Blink)
            .Permit(Trigger.Switch, LampState.Off);

            string graph = UmlDotGraph.Format(machine.GetInfo());
        }
Beispiel #24
0
        public void OnEntryWithAnonymousActionAndDescription()
        {
            var expected = prefix(Style.UML) + box(Style.UML, "A", new List <string> {
                "enteredA"
            }) + suffix;

            var sm = new StateMachine <State, Trigger>(State.A);

            sm.Configure(State.A)
            .OnEntry(() => { }, "enteredA");

            string dotGraph = UmlDotGraph.Format(sm.GetInfo());

#if WRITE_DOTS_TO_FOLDER
            System.IO.File.WriteAllText(DestinationFolder + "OnEntryWithAnonymousActionAndDescription.dot", dotGraph);
#endif

            Assert.Equal(expected, dotGraph);
        }
Beispiel #25
0
        public void DestinationStateIsCalculatedBasedOnTriggerParameters()
        {
            var expected = prefix(Style.UML)
                           + box(Style.UML, "A")
                           + decision(Style.UML, "Decision1", "Function")
                           + line("A", "Decision1", "X") + suffix;

            var sm      = new StateMachine <State, Trigger>(State.A);
            var trigger = sm.SetTriggerParameters <int>(Trigger.X);

            sm.Configure(State.A)
            .PermitDynamic(trigger, i => i == 1 ? State.B : State.C);

            string dotGraph = UmlDotGraph.Format(sm.GetInfo());

#if WRITE_DOTS_TO_FOLDER
            System.IO.File.WriteAllText(DestinationFolder + "DestinationStateIsCalculatedBasedOnTriggerParameters.dot", dotGraph);
#endif
            Assert.Equal(expected, dotGraph);
        }
Beispiel #26
0
        public void DestinationStateIsDynamic()
        {
            var expected = prefix(Style.UML)
                           + box(Style.UML, "A")
                           + decision(Style.UML, "Decision1", "Function")
                           + line("A", "Decision1", "X") + suffix;

            var sm = new StateMachine <State, Trigger>(State.A);

            sm.Configure(State.A)
            .PermitDynamic(Trigger.X, () => State.B);

            string dotGraph = UmlDotGraph.Format(sm.GetInfo());

#if WRITE_DOTS_TO_FOLDER
            System.IO.File.WriteAllText(DestinationFolder + "DestinationStateIsDynamic.dot", dotGraph);
#endif

            Assert.Equal(expected, dotGraph);
        }
Beispiel #27
0
        public Order()
        {
            Details = new List <OrderDetail>();

            CreateDate = DateTime.Now;

            machine = new StateMachine <OrderStatus, OrderTrigger>(OrderStatus.Created);

            machine.Configure(OrderStatus.Created)
            .Permit(OrderTrigger.Complete, OrderStatus.Completing)
            .OnEntry(() => Console.WriteLine("Trwa kompletacja"));

            machine.Configure(OrderStatus.Completing)
            .Permit(OrderTrigger.Send, OrderStatus.Sent)
            .Permit(OrderTrigger.Cancel, OrderStatus.Canceled)
            ;

            string graph = UmlDotGraph.Format(machine.GetInfo());

            Trace.WriteLine(graph);
        }
        public Lamp()
        {
            _machine =
                new Stateless.StateMachine <LampState, LampTrigger>(LampState.Off);

            _machine.Configure(LampState.Off)
            .OnEntry(() => Console.WriteLine("Dziękuję za wyłączenie światła."), "Send SMS")
            .Permit(LampTrigger.Down, LampState.On)
            //   .PermitReentry(LampTrigger.Up)
            ;

            _machine.Configure(LampState.On)
            .OnEntry(() => Console.WriteLine("Pamiętaj o wyłączeniu światła!"), "Send SMS")
            .Permit(LampTrigger.Up, LampState.Off)
            .PermitReentry(LampTrigger.Down)
            ;

            string graph = UmlDotGraph.Format(_machine.GetInfo());

            Console.WriteLine(graph);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var stateMachine = new StateMachine <State, Input>(State.Locked);

            stateMachine.Configure(State.Locked)
            .Permit(Input.Coin, State.UnLocked)
            .PermitReentry(Input.Push);

            stateMachine.Configure(State.UnLocked)
            .Permit(Input.Push, State.Locked)
            .PermitReentry(Input.Coin);

            stateMachine.Fire(Input.Coin);
            Console.WriteLine(stateMachine.State);

            string graph = UmlDotGraph.Format(stateMachine.GetInfo());

            Console.WriteLine(graph);
        }
Beispiel #30
0
        public void WhenDiscriminatedByAnonymousGuardWithDescription()
        {
            Func <bool> anonymousGuard = () => true;

            var expected = prefix(Style.UML)
                           + box(Style.UML, "A") + box(Style.UML, "B")
                           + line("A", "B", "X [description]")
                           + suffix;

            var sm = new StateMachine <State, Trigger>(State.A);

            sm.Configure(State.A)
            .PermitIf(Trigger.X, State.B, anonymousGuard, "description");

            string dotGraph = UmlDotGraph.Format(sm.GetInfo());

#if WRITE_DOTS_TO_FOLDER
            System.IO.File.WriteAllText(DestinationFolder + "WhenDiscriminatedByAnonymousGuardWithDescription.dot", dotGraph);
#endif

            Assert.Equal(expected, dotGraph);
        }