static void Main(string[] args) { var phoneCall = new State_Machine <State, Trigger>(State.OffHook); phoneCall.Configure(State.OffHook).Go_To_State(Trigger.CallDialed, State.Ringing); phoneCall.Configure(State.Ringing).Go_To_State(Trigger.CallConnected, State.Connected) .On_Entry(() => Console.WriteLine("start ringing")) .On_Exit(() => Console.WriteLine("stop ringing")); phoneCall.Configure(State.Connected). On_Entry(() => StartCallTimer()). On_Exit(() => StopCallTimer()); phoneCall.Fire(Trigger.CallDialed); phoneCall.Fire(Trigger.CallConnected); Thread.Sleep(2000); phoneCall.Fire(Trigger.close); Console.ReadKey(); }
static void SetVolume(State_Machine <State, Trigger> phoneCall, Trigger trigger, int volume) { phoneCall.Fire(trigger, volume); }
static void Fire(State_Machine <State, Trigger> phoneCall, Trigger trigger) { Console.WriteLine("[Firing:] {0}", trigger); phoneCall.Fire(trigger); }