コード例 #1
0
ファイル: Lifts.cs プロジェクト: DespotBob/Herstamac
 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)));
 }
コード例 #2
0
        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());
        }
コード例 #3
0
ファイル: InternalState.cs プロジェクト: DespotBob/Herstamac
        public void GivenANewlyInitialisedSM()
        {
            MachineBuilder = new InitialMachineBuilder();

            MachineDefinition = MachineBuilder.GetMachineDefinition();
            MachineState      = MachineDefinition.NewMachineInstance(new State());
        }
コード例 #4
0
ファイル: HistoryTests.cs プロジェクト: DespotBob/Herstamac
        public void GivenANewlyInitialisedSM()
        {
            MachineBuilder    = new HistoryStateMachineBuilder();
            MachineDefinition = MachineBuilder.GetMachineDefinition();
            InternalState     = MachineDefinition.NewMachineInstance(new HistoryState());

            // Given - The Machine is started
            MachineRunner.Start(MachineDefinition, InternalState);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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));
        }
コード例 #9
0
 public Lift(IMachineState <TInternalState> state, MachineDefinition <TInternalState> machineState)
 {
     _internalState     = state;
     _machineDefinition = machineState;
 }