Пример #1
0
        /// <summary>
        /// Defines an action to take any time <see cref="TTrigger"/> occurs.
        /// </summary>
        /// <typeparam name="TRequest">Parameter to be passed in from FireTrigger.</typeparam>
        /// <param name="trigger">The <see cref="TTrigger"/> for the action.</param>
        /// <param name="action">The action to execute.</param>
        /// <remarks><see cref="StateConfiguration{T,TState,TTrigger}"/> also has trigger actions that should only occur while T is in a specific state.</remarks>
        /// <returns></returns>
        public IStateMachine <T, TState, TTrigger> AddTriggerAction <TRequest>(TTrigger trigger, Action <T, TRequest> action)
        {
            if (_triggerActions.ContainsKey(trigger))
            {
                throw new InvalidOperationException($"Only one action is allowed for {trigger} trigger.");
            }

            _triggerActions.Add(trigger, TriggerActionFactory <T, TTrigger> .GetTriggerAction(action));

            return(this);
        }
Пример #2
0
        /// <summary>
        /// Defines an action to execute when a specified <see cref="TTrigger"/> occurs.
        /// </summary>
        /// <param name="trigger">The <see cref="TTrigger"/> for the action.</param>
        /// <param name="action">The action to execute.</param>
        /// <returns></returns>
        public IStateConfigurationAsync <T, TState, TTrigger> AddTriggerAction(TTrigger trigger, Func <T, CancellationToken, Task> action)
        {
            if (_triggerActions.ContainsKey(trigger))
            {
                throw new InvalidOperationException($"Only one action is allowed for {trigger} trigger.");
            }

            _triggerActions.Add(trigger, TriggerActionFactory <T, TTrigger> .GetTriggerAction(action));

            return(this);
        }