Example #1
0
        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();
        }
Example #2
0
        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();
        }