Exemple #1
0
        void Transition(Composer composer, TInstance instance)
        {
            composer.Execute(() =>
            {
                State <TInstance> currentState = _currentStateAccessor.Get(instance);
                if (_toState.Equals(currentState))
                {
                    return(composer.ComposeCompleted());
                }

                var taskComposer = new TaskComposer <TInstance>(composer.CancellationToken);

                if (currentState != null)
                {
                    currentState.Raise(taskComposer, instance, currentState.Leave);
                }

                _toState.Raise(taskComposer, instance, _toState.BeforeEnter, currentState);

                ((Composer)taskComposer).Execute(() => _currentStateAccessor.Set(instance, _toState));

                if (currentState != null)
                {
                    currentState.Raise(taskComposer, instance, currentState.AfterLeave, _toState);
                }

                _toState.Raise(taskComposer, instance, _toState.Enter);

                return(taskComposer.Finish());
            });
        }
Exemple #2
0
        public override void Execute(TInstance instance)
        {
            State <TInstance> currentState = _currentStateAccessor.Get(instance);

            if (currentState == _targetState)
            {
                return;
            }

            if (currentState != null)
            {
                currentState.RaiseEvent(instance, currentState.Exit);
            }

            _currentStateAccessor.Set(instance, _targetState);

            _targetState.RaiseEvent(instance, _targetState.Entry);
        }
        async Task Transition(BehaviorContext <TInstance> context)
        {
            State <TInstance> currentState = await _currentStateAccessor.Get(context).ConfigureAwait(false);

            if (_toState.Equals(currentState))
            {
                return; // Homey don't play re-entry, at least not yet.
            }
            if (currentState != null && !currentState.HasState(_toState))
            {
                await RaiseCurrentStateLeaveEvents(context, currentState).ConfigureAwait(false);
            }

            await RaiseBeforeEnterEvents(context, currentState, _toState).ConfigureAwait(false);

            await _currentStateAccessor.Set(context, _toState).ConfigureAwait(false);

            if (currentState != null)
            {
                await RaiseAfterLeaveEvents(context, currentState, _toState).ConfigureAwait(false);
            }

            if (currentState == null || !_toState.HasState(currentState))
            {
                State <TInstance> superState = _toState.SuperState;
                while (superState != null && (currentState == null || !superState.HasState(currentState)))
                {
                    BehaviorContext <TInstance> superStateEnterContext = context.GetProxy(superState.Enter);
                    await superState.Raise(superStateEnterContext).ConfigureAwait(false);

                    superState = superState.SuperState;
                }

                BehaviorContext <TInstance> enterContext = context.GetProxy(_toState.Enter);
                await _toState.Raise(enterContext).ConfigureAwait(false);
            }
        }
Exemple #4
0
 Task StateAccessor <TInstance> .Set(InstanceContext <TInstance> context, State <TInstance> state)
 {
     return(_stateAccessor.Set(context, state));
 }
 void StateAccessor <TInstance> .Set(TInstance instance, State <TInstance> state)
 {
     _rawStateAccessor.Set(instance, state);
 }