コード例 #1
0
        /// <summary>
        /// Adds a transition that automatically forwards to a new state that's determined at runtime.
        /// </summary>
        /// <param name="trigger">The trigger this transition is used with.</param>
        /// <param name="function">The function to determine the next state.</param>
        /// <param name="name">The name of the transition.</param>
        /// <param name="priority">The priority of the transition.</param>
        /// <returns></returns>
        public IStateConfiguration <T, TState, TTrigger> AddAutoDynamicTransition(TTrigger trigger, Func <T, TState> function, string name = null, uint priority = 1)
        {
            var initialTransition = StateTransitionFactory <T, TState, TTrigger> .GetStateTransition(_stateMachine
                                                                                                     , State
                                                                                                     , function
                                                                                                     , State
                                                                                                     , name
                                                                                                     , priority);

            AddAutoTransition(trigger, initialTransition);

            return(this);
        }
コード例 #2
0
        /// <summary>
        /// Defines a state transition where the end state is defined by a function.
        /// </summary>
        /// <param name="trigger">The <see cref="TTrigger"/> to use initiate this transition.</param>
        /// <param name="function">The function to determine the state.</param>
        /// <param name="name"></param>
        /// <param name="priority"></param>
        /// <returns></returns>
        public IStateConfiguration <T, TState, TTrigger> AddDynamicTransition(TTrigger trigger
                                                                              , Func <T, TState> function
                                                                              , string name   = null
                                                                              , uint priority = 1)
        {
            if (function == null)
            {
                throw new ArgumentNullException(nameof(function));
            }

            var transition = StateTransitionFactory <T, TState, TTrigger> .GetStateTransition(_stateMachine
                                                                                              , function
                                                                                              , name
                                                                                              , priority);

            AddTransition(trigger, transition);

            return(this);
        }
コード例 #3
0
        /// <summary>
        /// Adds a conditional transition to be applied on the specified <see cref="TTrigger"/>.
        /// </summary>
        /// <param name="trigger">The <see cref="TTrigger"/> to use this transition.</param>
        /// <param name="toState">The <see cref="TState"/> to transition to.</param>
        /// <param name="condition">StateFunction that must be met to complete the transition.</param>
        /// <param name="name"></param>
        /// <param name="priority"></param>
        /// <returns></returns>
        public IStateConfiguration <T, TState, TTrigger> AddTransition(TTrigger trigger
                                                                       , TState toState
                                                                       , Func <T, bool> condition = null
                                                                       , string name   = null
                                                                       , uint priority = 1)
        {
            if (condition == null)
            {
                condition = _ => true;
            }

            var transition = StateTransitionFactory <T, TState, TTrigger> .GetStateTransition(_stateMachine
                                                                                              , toState
                                                                                              , condition
                                                                                              , name
                                                                                              , priority);

            AddTransition(trigger, transition);

            return(this);
        }
コード例 #4
0
        /// <summary>
        /// Defines a conditional transition to apply on the given <see cref="TTrigger"/>.
        /// </summary>
        /// <param name="trigger">The <see cref="TTrigger"/> on which to execute this transition.</param>
        /// <param name="toState">The <see cref="TState"/> to transition to.</param>
        /// <param name="conditionAsync">The asynchronous function required to complete the transition.</param>
        /// <param name="name"></param>
        /// <param name="priority"></param>
        /// <returns></returns>
        public IStateConfigurationAsync <T, TState, TTrigger> AddTransition(TTrigger trigger
                                                                            , TState toState
                                                                            , Func <T, CancellationToken, Task <bool> > conditionAsync = null
                                                                            , string name   = null
                                                                            , uint priority = 1)
        {
            if (conditionAsync == null)
            {
                conditionAsync = (_, ct) => Task.FromResult(result: true);
            }

            var transition = StateTransitionFactory <T, TState, TTrigger> .GetStateTransition(_stateMachine
                                                                                              , toState
                                                                                              , conditionAsync
                                                                                              , name
                                                                                              , priority);

            AddTransition(trigger, transition);

            return(this);
        }
コード例 #5
0
        /// <summary>
        /// Adds a conditional transition to be applied on the specified <see cref="TTrigger"/>.
        /// </summary>
        /// <typeparam name="TRequest">Parameter to be passed in from StateMachine.FireTrigger.</typeparam>
        /// <param name="trigger">The <see cref="TTrigger"/> to use this transition.</param>
        /// <param name="toState">The <see cref="TState"/> to transition to.</param>
        /// <param name="condition">Asynchronous condition that must be met to complete the transition.</param>
        /// <param name="name"></param>
        /// <param name="priority"></param>
        /// <returns></returns>
        public IStateConfiguration <T, TState, TTrigger> AddTransition <TRequest>(TTrigger trigger
                                                                                  , TState toState
                                                                                  , Func <T, TRequest, bool> condition
                                                                                  , string name   = null
                                                                                  , uint priority = 1)
            where TRequest : class
        {
            if (condition == null)
            {
                throw new ArgumentNullException(nameof(condition));
            }

            var transition = StateTransitionFactory <T, TState, TTrigger> .GetStateTransition(_stateMachine
                                                                                              , toState
                                                                                              , condition
                                                                                              , name
                                                                                              , priority);

            AddTransition(trigger, transition);

            return(this);
        }
コード例 #6
0
        /// <summary>
        /// Defines an automatic, but conditional, transition from this state to a new state.
        /// </summary>
        /// <param name="trigger">The <see cref="TTrigger"/> to initiate this transition.</param>
        /// <param name="toState">The <see cref="TState"/> to transition to.</param>
        /// <param name="condition">The condition required to make the transition.</param>
        /// <param name="name"></param>
        /// <param name="priority"></param>
        /// <returns></returns>
        public IStateConfiguration <T, TState, TTrigger> AddAutoForwardTransition(TTrigger trigger
                                                                                  , TState toState
                                                                                  , Func <T, bool> condition
                                                                                  , string name   = null
                                                                                  , uint priority = 1)
        {
            if (condition == null)
            {
                throw new ArgumentNullException(nameof(condition));
            }

            var transition = StateTransitionFactory <T, TState, TTrigger> .GetStateTransition(_stateMachine
                                                                                              , triggerState : State
                                                                                              , toState : toState
                                                                                              , condition : condition
                                                                                              , name : name
                                                                                              , priority : priority);

            AddAutoTransition(trigger, transition);

            return(this);
        }