コード例 #1
0
        /// <summary>
        /// Fire an event on the current state to raise a state transition.
        /// </summary>
        /// <param name="e">Event to fire.</param>
        public void BroadcastEvent(IMachineEvent e)
        {
            CurrentState.Data = Data;
            var s = CurrentState.ReceiveEvent(e);

            if (s != null)
            {
                CurrentState = s;
            }
        }
コード例 #2
0
        /// <summary>
        /// Handle an event.
        /// </summary>
        /// <param name="e">Event to handle.</param>
        /// <returns>Returns the new state of the machine.</returns>
        public IState <D> ReceiveEvent(IMachineEvent e)
        {
            var transition = Transitions.FirstOrDefault(t => t.Event.Equals(e) && (t.Guard?.Invoke(Data, e) ?? true));

            if (transition == null)
            {
                return(null);
            }
            transition.Data = Data;
            transition.Action?.Invoke(Data, e);
            return(transition.To);
        }