public async Task FireAsync(SmartphoneEvent evt)
 {
     if (!CanFire(evt))
     {
         throw new InvalidOperationException($"Cannot fire event {evt} in the current state {_sm.State}");
     }
     await _sm.FireAsync(evt);
 }
Ejemplo n.º 2
0
 public void Fire(SmartphoneEvent evt)
 {
     if (!CanFire(evt))
     {
         throw new InvalidOperationException($"Cannot fire event {evt} in the current state {_sm.State}");
     }
     _sm.Fire(evt);
 }
 public async Task FireAsync <T>(SmartphoneEvent evt, T parameter)
 {
     if (!CanFire(evt))
     {
         throw new InvalidOperationException($"Cannot fire event {evt} in the current state {_sm.State}");
     }
     var param = GetParameter <T>(evt);
     await _sm.FireAsync(param, parameter);
 }
        private void AddParameter(SmartphoneEvent evt, Type paramType, StateMachine <SmartphoneState, SmartphoneEvent> .TriggerWithParameters trigger)
        {
            Dictionary <Type, StateMachine <SmartphoneState, SmartphoneEvent> .TriggerWithParameters> dict;

            if (!_parameters.TryGetValue(evt, out dict))
            {
                dict = new Dictionary <Type, StateMachine <SmartphoneState, SmartphoneEvent> .TriggerWithParameters>();
                _parameters.Add(evt, dict);
            }
            dict[paramType] = trigger;
        }
 protected SmartphoneReentryAsyncEvent(SmartphoneState state, Smartphone item, SmartphoneEvent evt) : base(item, evt, true)
 {
     State = state;
 }
 protected SmartphoneTransitionAsyncEvent(SmartphoneState oldState, SmartphoneState newState, Smartphone item, SmartphoneEvent evt) : base(item, evt, false)
 {
     OldState = oldState;
     NewState = newState;
 }
        private StateMachine <SmartphoneState, SmartphoneEvent> .TriggerWithParameters <T> GetParameter <T>(SmartphoneEvent evt)
        {
            Dictionary <Type, StateMachine <SmartphoneState, SmartphoneEvent> .TriggerWithParameters> dict;

            if (!_parameters.TryGetValue(evt, out dict))
            {
                throw new KeyNotFoundException($"Key {evt} was not found in trigger parameters dictionary");
            }
            return((StateMachine <SmartphoneState, SmartphoneEvent> .TriggerWithParameters <T>)dict[typeof(T)]);
        }
 public bool CanFire(SmartphoneEvent evt)
 {
     return(_sm.CanFire(evt));
 }
 protected SmartphoneFireAsyncEvent(Smartphone item, SmartphoneEvent evt, bool isReentry)
 {
     Smartphone = item;
     Event      = evt;
     IsReentry  = isReentry;
 }