public static IDisposable AsObservable <TInternalState, TEvent>( this IObservable <TEvent> t , MachineDefinition <TInternalState> machineDefinition , IMachineState <TInternalState> internalState) { return(t.Subscribe(x => MachineRunner.Dispatch(machineDefinition, internalState, x))); }
public void GivenANewlyInitialisedSM() { machine.AddEventInterceptor((evnt) => { Console.WriteLine("Rx'd Event: {0}", evnt.GetType().Name); return(evnt); }); machine.AddEventInterceptor((evnt) => { Console.WriteLine("Rx'd Event2: {0}", evnt.GetType().Name); return(evnt); }); MachineDefinition = machine.GetMachineDefinition(config => { /* Name the Statemachine */ config.Name("FastSlow"); /* Define where the logging information is going! */ config.Logger(x => Console.WriteLine(x)); /* Define a function that will be used to serialise an event to a string */ config.LogEventWith(x => x.ToString()); /* Hmmm - Every state machine needs a unique Id - Get this one from here, otherwise it's a GUID! */ config.UniqueId.FromProperty(p => p.Id); }); MachineState = MachineDefinition.NewMachineInstance(new SlowFastStoppedInternalState()); }
public void GivenANewlyInitialisedSM() { MachineBuilder = new InitialMachineBuilder(); MachineDefinition = MachineBuilder.GetMachineDefinition(); MachineState = MachineDefinition.NewMachineInstance(new State()); }
public void GivenANewlyInitialisedSM() { MachineBuilder = new HistoryStateMachineBuilder(); MachineDefinition = MachineBuilder.GetMachineDefinition(); InternalState = MachineDefinition.NewMachineInstance(new HistoryState()); // Given - The Machine is started MachineRunner.Start(MachineDefinition, InternalState); }
public void Init() { MachineDefinition = MachineBuilder.GetMachineDefinition(config => { config.Name("DefaultHandler"); config.Logger(x => Console.WriteLine(x)); config.LogEventWith(x => x.ToString()); config.UniqueId.FromProperty(p => p.Id); }); MachineState = MachineDefinition.NewMachineInstance(new DefaultHandlerState()); MachineRunner.Start(MachineDefinition, MachineState); }
public void GivenANewlyInitialisedSM() { MachineBuilder = new TransitionMachineBuilder(); MachineDefinition = MachineBuilder.GetMachineDefinition(configure => { configure.Logger((x) => Console.WriteLine(x)); }); InternalState = MachineDefinition.NewMachineInstance(new TransistionState()); Lift = new Lift <TransistionState>(InternalState, MachineDefinition); // Given - The Machine is started MachineRunner.Start(MachineDefinition, InternalState); }
public void Init() { MachineBuilder = new MultipleEventsStateMachine(); MachineDefinition = MachineBuilder.GetMachineDefinition((x) => { x.Name("Roger"); x.UniqueId.FromProperty(t => t.Id); x.Logger((str) => Console.WriteLine(str)); }); MachineState = MachineDefinition.NewMachineInstance(new MultipleEventsMachineState()); MachineRunner.Start(MachineDefinition, MachineState); }
public void Setup() { Console.WriteLine("Starting..."); machineBuilder.RegisterState(On); machineBuilder.RegisterState(Off); machineBuilder.InState(On) .OnEntry() .Then((s, e) => this.executed = 13); machineBuilder.InState(On) .When <SwitchUp>() .Then((state, evnt) => { state.counter += 3; Console.WriteLine("Rx'd Switchup!"); }); machineBuilder.InState(On) .When <SwitchUp>() .WithGuard((state, x) => false) .Then((state, x) => { throw new Exception("The guard should prevent this from being thrown!"); }); machineBuilder.InState(On) .When <SwitchUp>() .WithGuard((state, x) => true) .Then((state, x) => Console.WriteLine("Rx'd Switchup! - with a Guard Condition")); machineBuilder.InState(On) .When <SwitchUp>() .WithGuard((state, x) => true) .Then() .TransitionTo(Off); machineBuilder.InState(Off) .When <SwitchDown>() .TransitionTo(On); MachineDefintion = machineBuilder.GetMachineDefinition(); MachineState = MachineDefintion.NewMachineInstance(new OnOffInternalState()); MachineRunner.Start(MachineDefintion, MachineState); Assert.IsTrue(MachineRunner.IsInState(MachineState, MachineDefintion, On)); }
public Lift(IMachineState <TInternalState> state, MachineDefinition <TInternalState> machineState) { _internalState = state; _machineDefinition = machineState; }