Esempio n. 1
0
        public override Task <StateTransitionResult <TState, TTrigger> > ExecuteAsync(ExecutionParameters <T, TTrigger> parameters
                                                                                      , StateTransitionResult <TState, TTrigger> currentResult = null)
        {
            if (currentResult != null &&
                !parameters.CancellationToken.IsCancellationRequested &&
                _startState.IsEqual(currentResult.PreviousState) &&
                (_triggerState.IsEqual(currentResult.CurrentState) ||
                 _stateMachine.IsInState(parameters.Context, _triggerState)))
            {
                StateMutator(parameters.Context, _stateFunction.Invoke(parameters.Context));

                var transitioned = !StateAccessor(parameters.Context).IsEqual(_triggerState);
                var result       = GetFreshResult(parameters
                                                  , currentResult
                                                  , currentResult.StartingState
                                                  , wasCancelled: parameters.CancellationToken.IsCancellationRequested
                                                  , transitionDefined: true
                                                  , conditionMet: transitioned);

                return(Task.FromResult(result));
            }

            return(Task.FromResult(GetFreshResult(parameters
                                                  , currentResult
                                                  , StateAccessor(parameters.Context)
                                                  , wasCancelled: parameters.CancellationToken.IsCancellationRequested
                                                  , transitionDefined: true
                                                  , conditionMet: false)));
        }
Esempio n. 2
0
        public override StateTransitionResult <TState, TTrigger> Execute(ExecutionParameters <T, TTrigger> parameters
                                                                         , StateTransitionResult <TState, TTrigger> currentResult = null)
        {
            if (!(parameters.Request is TRequest typeSafeParam))
            {
                throw new ArgumentException($"Expected a {typeof(TRequest).Name} parameter, but received a {parameters.Request?.GetType().Name ?? "null"}.");
            }

            if (currentResult != null &&
                !parameters.CancellationToken.IsCancellationRequested &&
                _startState.IsEqual(currentResult.PreviousState) &&
                (_triggerState.IsEqual(currentResult.CurrentState) ||
                 _stateMachine.IsInState(parameters.Context, _triggerState)))
            {
                StateMutator(parameters.Context, _stateFunction(parameters.Context, typeSafeParam));

                var transitioned = !StateAccessor(parameters.Context).IsEqual(_triggerState);
                var result       = GetFreshResult(parameters
                                                  , currentResult
                                                  , currentResult.StartingState
                                                  , wasCancelled: false
                                                  , transitionDefined: true
                                                  , conditionMet: transitioned);

                return(result);
            }

            return(GetFreshResult(parameters
                                  , currentResult
                                  , StateAccessor(parameters.Context)
                                  , wasCancelled: parameters.CancellationToken.IsCancellationRequested
                                  , transitionDefined: true
                                  , conditionMet: false));
        }
Esempio n. 3
0
        public override async Task <StateTransitionResult <TState, TTrigger> > ExecuteAsync(ExecutionParameters <T, TTrigger> parameters
                                                                                            , StateTransitionResult <TState, TTrigger> currentResult = null)
        {
            if (currentResult != null &&
                !parameters.CancellationToken.IsCancellationRequested &&
                (_triggerState.IsEqual(currentResult.CurrentState) ||
                 _stateMachine.IsInState(parameters.Context, _triggerState)))
            {
                return(await base.ExecuteAsync(parameters, currentResult));
            }

            return(GetFreshResult(parameters
                                  , currentResult
                                  , StateAccessor(parameters.Context)
                                  , wasCancelled: parameters.CancellationToken.IsCancellationRequested
                                  , transitionDefined: true
                                  , conditionMet: false));
        }