public void Loading( StateMachineSaver <State> saver, StateMachineLoader <State> loader, FakeExtension extension, State sourceState, State targetState) { "establish a saved state machine with history".x(() => { var machine = new PassiveStateMachine <State, Event>(); DefineMachine(machine); machine.Initialize(State.A); machine.Start(); machine.Fire(Event.S2); // set history of super state S machine.Fire(Event.B); // set current state to B saver = new StateMachineSaver <State>(); loader = new StateMachineLoader <State>(); machine.Save(saver); }); "when state machine is loaded".x(() => { loader.SetCurrentState(saver.CurrentStateId); loader.SetHistoryStates(saver.HistoryStates); extension = new FakeExtension(); var loadedMachine = new PassiveStateMachine <State, Event>(); loadedMachine.AddExtension(extension); DefineMachine(loadedMachine); loadedMachine.Load(loader); loadedMachine.TransitionCompleted += (sender, args) => { sourceState = args.StateId; targetState = args.NewStateId; }; loadedMachine.Start(); loadedMachine.Fire(Event.S); }); "it should reset current state".x(() => sourceState.Should().Be(State.B)); "it should reset all history states of super states".x(() => targetState.Should().Be(State.S2)); "it should notify extensions".x(() => extension.LoadedCurrentState .Should().BeEquivalentTo(State.B)); }
public void LogStateTransition() { _stateMachine.Initialize(States.Off); _stateMachine.Start(); _loggerMock.Setup(logger => logger.Debug("StateMachine Test fires event TurnOn")); _loggerMock.Setup(logger => logger.Debug("StateMachine Test switched from Off to On")); _stateMachine.Fire(Events.TurnOn); _loggerMock.VerifyAll(); }
public void SimpleTransition() { fsm = new PassiveStateMachine <SM.ProcessState, SM.Command>(); fsm.Initialize(SM.ProcessState.Initial); fsm.Fire(SM.Command.OnOpenBattleFront); fsm.Start(); fsm.Fire(SM.Command.OnOuterDoorDown); Assert.IsTrue(fsm.IsRunning); }
public void OtherwiseGuard( PassiveStateMachine <int, int> machine, CurrentStateExtension currentStateExtension) { "establish a state machine with otherwise guard and no matching other guard".x(() => { var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <int, int>(); stateMachineDefinitionBuilder .In(SourceState) .On(Event) .If(() => false).Goto(ErrorState) .Otherwise().Goto(DestinationState); machine = stateMachineDefinitionBuilder .WithInitialState(SourceState) .Build() .CreatePassiveStateMachine(); currentStateExtension = new CurrentStateExtension(); machine.AddExtension(currentStateExtension); machine.Start(); }); "when an event is fired".x(() => machine.Fire(Event)); "it should_take_transition_guarded_with_otherwise".x(() => currentStateExtension.CurrentState.Should().Be(DestinationState)); }
public void ExitActionException(PassiveStateMachine <int, int> machine) { "establish an exit action throwing an exception".x(() => { var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <int, int>(); stateMachineDefinitionBuilder .In(Values.Source) .ExecuteOnExit(() => throw Values.Exception) .On(Values.Event) .Goto(Values.Destination); machine = stateMachineDefinitionBuilder .WithInitialState(Values.Source) .Build() .CreatePassiveStateMachine(); machine.TransitionExceptionThrown += (s, e) => this.receivedTransitionExceptionEventArgs = e; }); "when executing the transition".x(() => { machine.Start(); machine.Fire(Values.Event, Values.Parameter); }); this.ItShouldHandleTransitionException(); }
public void NoExceptionHandlerRegistered( PassiveStateMachine <int, int> machine, Exception catchedException) { "establish an exception throwing state machine without a registered exception handler".x(() => { var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <int, int>(); stateMachineDefinitionBuilder .In(Values.Source) .On(Values.Event) .Execute(() => throw Values.Exception); machine = stateMachineDefinitionBuilder .WithInitialState(Values.Source) .Build() .CreatePassiveStateMachine(); machine.Start(); }); "when an exception occurs".x(() => catchedException = Catch.Exception(() => machine.Fire(Values.Event))); "should (re-)throw exception".x(() => catchedException.InnerException .Should().BeSameAs(Values.Exception)); }
public void MultipleExitActions( PassiveStateMachine <int, int> machine, bool exitAction1Executed, bool exitAction2Executed) { "establish a state machine with several exit actions on a state".x(() => { var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <int, int>(); stateMachineDefinitionBuilder .In(State) .ExecuteOnExit(() => exitAction1Executed = true) .ExecuteOnExit(() => exitAction2Executed = true) .On(Event).Goto(AnotherState); machine = stateMachineDefinitionBuilder .WithInitialState(State) .Build() .CreatePassiveStateMachine(); }); "when leaving the state".x(() => { machine.Start(); machine.Fire(Event); }); "It should execute all exit actions".x(() => { exitAction1Executed .Should().BeTrue("first action should be executed"); exitAction2Executed .Should().BeTrue("second action should be executed"); }); }
public void ExitActionWithParameter( PassiveStateMachine <int, int> machine, string parameter) { const string Parameter = "parameter"; "establish a state machine with exit action with parameter on a state".x(() => { var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <int, int>(); stateMachineDefinitionBuilder .In(State) .ExecuteOnExitParametrized(p => parameter = p, Parameter) .On(Event).Goto(AnotherState); machine = stateMachineDefinitionBuilder .WithInitialState(State) .Build() .CreatePassiveStateMachine(); }); "when leaving the state".x(() => { machine.Start(); machine.Fire(Event); }); "it should execute the exit action".x(() => parameter.Should().NotBeNull()); "it should pass parameter to the exit action".x(() => parameter.Should().Be(Parameter)); }
public void ExitAction( PassiveStateMachine <int, int> machine, bool exitActionExecuted) { "establish a state machine with exit action on a state".x(() => { var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <int, int>(); stateMachineDefinitionBuilder .In(State) .ExecuteOnExit(() => exitActionExecuted = true) .On(Event).Goto(AnotherState); machine = stateMachineDefinitionBuilder .WithInitialState(State) .Build() .CreatePassiveStateMachine(); }); "when leaving the state".x(() => { machine.Start(); machine.Fire(Event); }); "it should execute the exit action".x(() => exitActionExecuted.Should().BeTrue()); }
public void EventArgument( PassiveStateMachine <int, int> machine, int passedArgument) { const int Argument = 17; "establish a state machine with an exit action taking an event argument".x(() => { var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <int, int>(); stateMachineDefinitionBuilder .In(State) .ExecuteOnExit((int argument) => passedArgument = argument) .On(Event).Goto(AnotherState); stateMachineDefinitionBuilder .In(AnotherState) .ExecuteOnEntry((int argument) => passedArgument = argument); machine = stateMachineDefinitionBuilder .WithInitialState(State) .Build() .CreatePassiveStateMachine(); }); "when leaving the state".x(() => { machine.Start(); machine.Fire(Event, Argument); }); "it should pass event argument to exit action".x(() => passedArgument.Should().Be(Argument)); }
public void BeforeExecutingEntryActions( PassiveStateMachine <string, int> machine, IExtension <string, int> extension) { "establish an extension".x(() => extension = A.Fake <IExtension <string, int> >()); "establish a state machine using the extension".x(() => { var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <string, int>(); stateMachineDefinitionBuilder .In("0") .On(1) .Goto("1"); machine = stateMachineDefinitionBuilder .WithInitialState("0") .Build() .CreatePassiveStateMachine(Name); machine.AddExtension(extension); machine.Start(); }); "when firing an event onto the state machine".x(() => machine.Fire(1)); "it should call EnteringState on registered extensions for target state".x(() => A.CallTo(() => extension.EnteringState( A <IStateMachineInformation <string, int> > .That.Matches(x => x.Name == Name && x.CurrentStateId.ExtractOrThrow() == "1"), A <IStateDefinition <string, int> > .That.Matches(x => x.Id == "1"), A <ITransitionContext <string, int> > .That.Matches(x => x.EventId.Value == 1))) .MustHaveHappened()); }
public void Update() { if (TW.Graphics.Keyboard.IsKeyPressed(Key.E)) { fsm.Fire(Events.InventoryKey); } if (TW.Graphics.Keyboard.IsKeyPressed(Key.Return)) { fsm.Fire(Events.PlayKey); } simulateInventory(); simulateWorld(); simulatePlayMode(); }
public void CustomTypesForStatesAndEvents( PassiveStateMachine <MyState, MyEvent> machine, bool arrivedInStateB) { "establish a state machine with custom types for states and events".x(() => { var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <MyState, MyEvent>(); stateMachineDefinitionBuilder .In(new MyState("A")) .On(new MyEvent(1)).Goto(new MyState("B")); stateMachineDefinitionBuilder .In(new MyState("B")) .ExecuteOnEntry(() => arrivedInStateB = true); machine = stateMachineDefinitionBuilder .WithInitialState(new MyState("A")) .Build() .CreatePassiveStateMachine(); machine.Start(); }); "when using the state machine".x(() => machine.Fire(new MyEvent(1))); "it should use equals to compare states and events".x(() => arrivedInStateB.Should().BeTrue("state B should be current state")); }
public void NoMatchingGuard( PassiveStateMachine <int, int> machine) { var declined = false; "establish state machine with no matching guard".x(() => { var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <int, int>(); stateMachineDefinitionBuilder .In(SourceState) .On(Event) .If(() => false).Goto(ErrorState); machine = stateMachineDefinitionBuilder .WithInitialState(SourceState) .Build() .CreatePassiveStateMachine(); machine.TransitionDeclined += (sender, e) => declined = true; machine.Start(); }); "when an event is fired".x(() => machine.Fire(Event)); "it should notify about declined transition".x(() => declined.Should().BeTrue("TransitionDeclined event should be fired")); }
public void SavingEvents( PassiveStateMachine <string, int> machine, StateMachineSaver <string, int> saver) { "establish a state machine".x(() => { var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <string, int>(); stateMachineDefinitionBuilder .In("A") .On(1) .Goto("B"); stateMachineDefinitionBuilder .In("B") .On(2) .Goto("C"); stateMachineDefinitionBuilder .In("C") .On(3) .Goto("A"); machine = stateMachineDefinitionBuilder .WithInitialState("A") .Build() .CreatePassiveStateMachine(); }); "when events are fired".x(() => { machine.Fire(1); machine.Fire(2); }); "and it is saved".x(() => { saver = new StateMachineSaver <string, int>(); machine.Save(saver); }); "it should save those events".x(() => saver .Events .Select(x => x.EventId) .Should() .HaveCount(2) .And .ContainInOrder(1, 2)); }
public void CanStartFSM() { fsm = new PassiveStateMachine <SM.ProcessState, SM.Command>(); fsm.Initialize(SM.ProcessState.Initial); fsm.Fire(SM.Command.OnOpenBattleFront); fsm.Start(); Assert.IsTrue(fsm.IsRunning); }
public void StartToiletStateMachine() { if (!mStateMachineIsRunning) { ResetTempFlushCount(); mStateMachineIsRunning = true; mToiletStateMachine.Fire(ToiletEvents.StartStateMachine); mManDetection.StartManDetection(); } }
private void updatePickupStateMachine() { var down = hotbarController.GetDownSlots(); if (down.Count() == 0) { fsm.Fire(Events.NoSlotPressed); } else if (down.Count() == 1) { fsm.Fire(Events.SingleSlotPressed); } else { fsm.Fire(Events.MultipleSlotPressed); } if (timerElapsed) { timerElapsed = false; fsm.Fire(Events.Timer); } }
public static void Main() { // configure basic logging (all levels enabled, messages are written to the console) log4net.Config.BasicConfigurator.Configure(); var elevator = new PassiveStateMachine <States, Events>("Elevator"); elevator.AddExtension(new Extensions.Log4NetExtension <States, Events>("Elevator")); elevator.DefineHierarchyOn(States.Healthy, States.OnFloor, HistoryType.Deep, States.OnFloor, States.Moving); elevator.DefineHierarchyOn(States.Moving, States.MovingUp, HistoryType.Shallow, States.MovingUp, States.MovingDown); elevator.DefineHierarchyOn(States.OnFloor, States.DoorClosed, HistoryType.None, States.DoorClosed, States.DoorOpen); elevator.In(States.Healthy) .On(Events.ErrorOccured).Goto(States.Error); elevator.In(States.Error) .On(Events.Reset).Goto(States.Healthy); elevator.In(States.OnFloor) .ExecuteOnEntry(AnnounceFloor) .On(Events.CloseDoor).Goto(States.DoorClosed) .On(Events.OpenDoor).Goto(States.DoorOpen) .On(Events.GoUp) .If(CheckOverload).Goto(States.MovingUp) .Otherwise().Execute(AnnounceOverload) .On(Events.GoDown) .If(CheckOverload).Goto(States.MovingDown) .Otherwise().Execute(AnnounceOverload); elevator.In(States.Moving) .On(Events.Stop).Goto(States.OnFloor); elevator.Initialize(States.OnFloor); elevator.Fire(Events.ErrorOccured); elevator.Fire(Events.Reset); elevator.Start(); elevator.Fire(Events.OpenDoor); elevator.Fire(Events.CloseDoor); elevator.Fire(Events.GoUp); elevator.Fire(Events.Stop); elevator.Fire(Events.OpenDoor); elevator.Stop(); Console.ReadLine(); }
public void ExecutingTransition( PassiveStateMachine <int, int> machine, string actualParameter, bool exitActionExecuted, bool entryActionExecuted) { "establish a state machine with transitions".x(() => { var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <int, int>(); stateMachineDefinitionBuilder .In(SourceState) .ExecuteOnExit(() => exitActionExecuted = true) .On(Event) .Goto(DestinationState) .Execute <string>(p => actualParameter = p); stateMachineDefinitionBuilder .In(DestinationState) .ExecuteOnEntry(() => entryActionExecuted = true); machine = stateMachineDefinitionBuilder .WithInitialState(SourceState) .Build() .CreatePassiveStateMachine(); machine.AddExtension(CurrentStateExtension); machine.Start(); }); "when firing an event onto the state machine".x(() => machine.Fire(Event, Parameter)); "it should_execute_transition_by_switching_state".x(() => CurrentStateExtension.CurrentState.Should().Be(DestinationState)); "it should_execute_transition_actions".x(() => actualParameter.Should().NotBeNull()); "it should_pass_parameters_to_transition_action".x(() => actualParameter.Should().Be(Parameter)); "it should_execute_exit_action_of_source_state".x(() => exitActionExecuted.Should().BeTrue()); "it should_execute_entry_action_of_destination_state".x(() => entryActionExecuted.Should().BeTrue()); }
public void ExceptionHandling( PassiveStateMachine <int, int> machine, bool exitAction1Executed, bool exitAction2Executed, bool exitAction3Executed) { var exception2 = new Exception(); var exception3 = new Exception(); var receivedExceptions = new List <Exception>(); "establish a state machine with several exit actions on a state and some of them throw an exception".x(() => { var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <int, int>(); stateMachineDefinitionBuilder .In(State) .ExecuteOnExit(() => exitAction1Executed = true) .ExecuteOnExit(() => { exitAction2Executed = true; throw exception2; }) .ExecuteOnExit(() => { exitAction3Executed = true; throw exception3; }) .On(Event).Goto(AnotherState); machine = stateMachineDefinitionBuilder .WithInitialState(State) .Build() .CreatePassiveStateMachine(); machine.TransitionExceptionThrown += (s, e) => receivedExceptions.Add(e.Exception); }); "when entering the state".x(() => { machine.Start(); machine.Fire(Event); }); "it should execute all entry actions on entry".x(() => { exitAction1Executed .Should().BeTrue("action 1 should be executed"); exitAction2Executed .Should().BeTrue("action 2 should be executed"); exitAction3Executed .Should().BeTrue("action 3 should be executed"); }); "it should handle all exceptions of all throwing entry actions by firing the TransitionExceptionThrown event".x(() => receivedExceptions .Should() .HaveCount(2) .And .Contain(exception2) .And .Contain(exception3)); }
public void NoCommonAncestor( PassiveStateMachine <string, int> machine) { const string SourceState = "SourceState"; const string ParentOfSourceState = "ParentOfSourceState"; const string SiblingOfSourceState = "SiblingOfSourceState"; const string DestinationState = "DestinationState"; const string ParentOfDestinationState = "ParentOfDestinationState"; const string SiblingOfDestinationState = "SiblingOfDestinationState"; const string GrandParentOfSourceState = "GrandParentOfSourceState"; const string GrandParentOfDestinationState = "GrandParentOfDestinationState"; const int Event = 0; var log = string.Empty; "establish a hierarchical state machine".x(() => { var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <string, int>(); stateMachineDefinitionBuilder .DefineHierarchyOn(ParentOfSourceState) .WithHistoryType(HistoryType.None) .WithInitialSubState(SourceState) .WithSubState(SiblingOfSourceState); stateMachineDefinitionBuilder .DefineHierarchyOn(ParentOfDestinationState) .WithHistoryType(HistoryType.None) .WithInitialSubState(DestinationState) .WithSubState(SiblingOfDestinationState); stateMachineDefinitionBuilder .DefineHierarchyOn(GrandParentOfSourceState) .WithHistoryType(HistoryType.None) .WithInitialSubState(ParentOfSourceState); stateMachineDefinitionBuilder .DefineHierarchyOn(GrandParentOfDestinationState) .WithHistoryType(HistoryType.None) .WithInitialSubState(ParentOfDestinationState); stateMachineDefinitionBuilder .In(SourceState) .ExecuteOnExit(() => log += "exit" + SourceState) .On(Event).Goto(DestinationState); stateMachineDefinitionBuilder .In(ParentOfSourceState) .ExecuteOnExit(() => log += "exit" + ParentOfSourceState); stateMachineDefinitionBuilder .In(DestinationState) .ExecuteOnEntry(() => log += "enter" + DestinationState); stateMachineDefinitionBuilder .In(ParentOfDestinationState) .ExecuteOnEntry(() => log += "enter" + ParentOfDestinationState); stateMachineDefinitionBuilder .In(GrandParentOfSourceState) .ExecuteOnExit(() => log += "exit" + GrandParentOfSourceState); stateMachineDefinitionBuilder .In(GrandParentOfDestinationState) .ExecuteOnEntry(() => log += "enter" + GrandParentOfDestinationState); machine = stateMachineDefinitionBuilder .WithInitialState(SourceState) .Build() .CreatePassiveStateMachine(); machine.Start(); }); "when firing an event resulting in a transition without a common ancestor".x(() => machine.Fire(Event)); "it should execute exit action of source state".x(() => log.Should().Contain("exit" + SourceState)); "it should execute exit action of parents of source state (recursively)".x(() => log .Should().Contain("exit" + ParentOfSourceState) .And.Contain("exit" + GrandParentOfSourceState)); "it should execute entry action of parents of destination state (recursively)".x(() => log .Should().Contain("enter" + ParentOfDestinationState) .And.Contain("enter" + GrandParentOfDestinationState)); "it should execute entry action of destination state".x(() => log.Should().Contain("enter" + DestinationState)); "it should execute actions from source upwards and then downwards to destination state".x(() => { string[] states = { SourceState, ParentOfSourceState, GrandParentOfSourceState, GrandParentOfDestinationState, ParentOfDestinationState, DestinationState }; var statesInOrderOfAppearanceInLog = states .OrderBy(s => log.IndexOf(s.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal)); statesInOrderOfAppearanceInLog .Should().Equal(states); }); }
public void CommonAncestor( PassiveStateMachine <int, int> machine) { const int CommonAncestorState = 0; const int SourceState = 1; const int ParentOfSourceState = 2; const int SiblingOfSourceState = 3; const int DestinationState = 4; const int ParentOfDestinationState = 5; const int SiblingOfDestinationState = 6; const int Event = 0; var commonAncestorStateLeft = false; "establish a hierarchical state machine".x(() => { var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <int, int>(); stateMachineDefinitionBuilder .DefineHierarchyOn(CommonAncestorState) .WithHistoryType(HistoryType.None) .WithInitialSubState(ParentOfSourceState) .WithSubState(ParentOfDestinationState); stateMachineDefinitionBuilder .DefineHierarchyOn(ParentOfSourceState) .WithHistoryType(HistoryType.None) .WithInitialSubState(SourceState) .WithSubState(SiblingOfSourceState); stateMachineDefinitionBuilder .DefineHierarchyOn(ParentOfDestinationState) .WithHistoryType(HistoryType.None) .WithInitialSubState(DestinationState) .WithSubState(SiblingOfDestinationState); stateMachineDefinitionBuilder .In(SourceState) .On(Event).Goto(DestinationState); stateMachineDefinitionBuilder .In(CommonAncestorState) .ExecuteOnExit(() => commonAncestorStateLeft = true); machine = stateMachineDefinitionBuilder .WithInitialState(SourceState) .Build() .CreatePassiveStateMachine(); machine.Start(); }); "when firing an event resulting in a transition with a common ancestor".x(() => machine.Fire(Event)); "the state machine should remain inside common ancestor state".x(() => commonAncestorStateLeft .Should().BeFalse()); }
public void Fire(ApplicationStateEvent appEvent) { _fsm.Fire(appEvent); }
public SpeechInteraction(Hpi.Hci.Bachelorproject1617.PhotoBooth.MainWindow mainWindow, SpeechSynthesizer reader) { this.mainWindow = mainWindow; this.reader = reader; this.reader.SpeakStarted += reader_SpeakStarted; this.reader.SpeakCompleted += reader_SpeakCompleted; //SpeakText(@"Welcome to this magical Kinect Photobooth, the camera that produces tactile snapshots of your gestures. If you want a picture just position yourself 1 meter in front of the Kinect-Camera and spread your arms away from you to get recognized"); //SpeakText(@"Hey there, if you want a tactile snapshot of your gesture just position yourself 1 meter in front of the Kinect-Camera and spread your arms away from you to get recognized. I can detect two persons at the time so get a mate and let's go"); fsm = new PassiveStateMachine <ProcessState, Command>(); fsm.In(ProcessState.NoPersonRecognized) .On(Command.Repeat).Execute(() => { SpeakText(NoPersonRecognizedRepeat); StartTimer(35000); }) //reader.Speak(NoPersonRecognizedRepeat) .On(Command.FramesReady).Goto(ProcessState.PersonRecognized).Execute(() => { SpeakText(PersonRecognizedTransition); Console.WriteLine("Frames ready"); StartTimer(35000); }).On(Command.Test).Goto(ProcessState.PictureTaken); fsm.In(ProcessState.PersonRecognized) .On(Command.Repeat).Execute(() => { SpeakText(PersonRecognizedRepeat); StartTimer(35000); }) .On(Command.FramesNotReady).Goto(ProcessState.NoPersonRecognized).Execute(() => { SpeakText(PersonLeft); Console.WriteLine("Frames not ready"); StartTimer(35000); }) .On(Command.Outlines).Goto(ProcessState.PictureTaken).Execute(() => { outlines = true; new Thread(PreparePicture).Start(); StartTimer(45000); }) .On(Command.Skeleton).Goto(ProcessState.PictureTaken).Execute(() => { outlines = false; new Thread(PreparePicture).Start(); StartTimer(45000); }); fsm.In(ProcessState.PictureTaken) .On(Command.Print).Goto(ProcessState.Connected).Execute(() => { SpeakText(ConnectingString); if (mainWindow.BluetoothOn) { mainWindow.BluetoothConnect(); } else { fsm.Fire(Command.Connected); } }) .On(Command.Yes).Goto(ProcessState.Connected).Execute(() => { SpeakText(ConnectingString); if (mainWindow.BluetoothOn) { mainWindow.BluetoothConnect(); } else { fsm.Fire(Command.Connected); } }) .On(Command.Repeat).Execute(() => { SpeakText(PictureTakenRepeat); StartTimer(35000); }) .On(Command.Back).Goto(ProcessState.PersonRecognized).Execute(() => { SpeakText(BackToPersonRecognized); mainWindow.pictureTaken = false; mainWindow.AlreadyConvertedToSVG = false; StartTimer(35000); }); fsm.In(ProcessState.Connected) .On(Command.Connected).Goto(ProcessState.Printed).Execute(() => { SpeakText(PrintingString); if (mainWindow.BluetoothOn) { mainWindow.SendSvgBluetooth(mainWindow.svgImage); } else { mainWindow.SendSvgTCP(mainWindow.svgImage); } }); fsm.In(ProcessState.Printed) .On(Command.Printed).Goto(ProcessState.NoPersonRecognized).Execute(() => { SpeakText(PrintedString); }); fsm.In(ProcessState.Connected); fsm.Initialize(ProcessState.NoPersonRecognized); fsm.Start(); StartTimer(35000); }
private void HandleTimer(object source, ElapsedEventArgs evt) { fsm.Fire(SpeechInteraction.Command.Repeat); }
public static void Main() { // configure basic logging (all levels enabled, messages are written to the console) log4net.Config.BasicConfigurator.Configure(); var elevator = new PassiveStateMachine<States, Events>("Elevator"); elevator.AddExtension(new Extensions.Log4NetExtension<States, Events>("Elevator")); elevator.DefineHierarchyOn(States.Healthy, States.OnFloor, HistoryType.Deep, States.OnFloor, States.Moving); elevator.DefineHierarchyOn(States.Moving, States.MovingUp, HistoryType.Shallow, States.MovingUp, States.MovingDown); elevator.DefineHierarchyOn(States.OnFloor, States.DoorClosed, HistoryType.None, States.DoorClosed, States.DoorOpen); elevator.In(States.Healthy) .On(Events.ErrorOccured).Goto(States.Error); elevator.In(States.Error) .On(Events.Reset).Goto(States.Healthy); elevator.In(States.OnFloor) .ExecuteOnEntry(AnnounceFloor) .On(Events.CloseDoor).Goto(States.DoorClosed) .On(Events.OpenDoor).Goto(States.DoorOpen) .On(Events.GoUp) .If(CheckOverload).Goto(States.MovingUp) .Otherwise().Execute(AnnounceOverload) .On(Events.GoDown) .If(CheckOverload).Goto(States.MovingDown) .Otherwise().Execute(AnnounceOverload); elevator.In(States.Moving) .On(Events.Stop).Goto(States.OnFloor); elevator.Initialize(States.OnFloor); elevator.Fire(Events.ErrorOccured); elevator.Fire(Events.Reset); elevator.Start(); elevator.Fire(Events.OpenDoor); elevator.Fire(Events.CloseDoor); elevator.Fire(Events.GoUp); elevator.Fire(Events.Stop); elevator.Fire(Events.OpenDoor); elevator.Stop(); Console.ReadLine(); }
public void TurnOn() { machine .Fire( Events.TurnOn); }