示例#1
0
        static void main2(string[] args)
        {
            var phoneCall = new StateMachineAdapter <State, Trigger>(State.OffHook);

            phoneCall.Configure(State.OffHook)
            .Allow(Trigger.CallDialed, State.Ringing);

            phoneCall.Configure(State.Ringing)
            .Allow(Trigger.HungUp, State.OffHook)
            .Allow(Trigger.CallConnected, State.Connected);

            phoneCall.Configure(State.Connected)
            .OnEntry(StartCallTimer)
            .OnExit(StopCallTimer)
            .Allow(Trigger.LeftMessage, State.OffHook)
            .Allow(Trigger.HungUp, State.OffHook)
            .SuperstateOf(State.Talking, State.OnHold);

            phoneCall.Configure(State.Talking)
            //.SubstateOf(State.Connected)
            .Allow(Trigger.PlacedOnHold, State.OnHold);

            phoneCall.Configure(State.OnHold)
            //.SubstateOf(State.Connected)
            .Allow(Trigger.TakenOffHold, State.Talking)
            .Allow(Trigger.PhoneHurledAgainstWall, State.PhoneDestroyed);

            Print(phoneCall);
            Fire(phoneCall, Trigger.CallDialed);
            Print(phoneCall);
            Fire(phoneCall, Trigger.CallConnected);
            Print(phoneCall);
            Fire(phoneCall, Trigger.PlacedOnHold);
            Print(phoneCall);
            Fire(phoneCall, Trigger.TakenOffHold);
            Print(phoneCall);
            Fire(phoneCall, Trigger.HungUp);
            Print(phoneCall);

            Console.WriteLine("Press any key...");
            //Console.ReadKey(true);
        }
示例#2
0
 private static void Print(StateMachineAdapter <State, Trigger> phoneCall)
 {
     Console.WriteLine("[Status:] {0}", phoneCall);
 }
示例#3
0
 private static void Fire(StateMachineAdapter <State, Trigger> phoneCall, Trigger trigger)
 {
     Console.WriteLine("[Firing:] {0}", trigger);
     phoneCall.Fire(trigger);
 }