Exemplo n.º 1
0
        internal static FixedTransitionInfo Create <TState, TTrigger>(StateMachine <TState, TTrigger> .TriggerBehaviour behaviour, StateInfo destinationStateInfo)
        {
            var transition = new FixedTransitionInfo
            {
                Trigger          = new TriggerInfo(behaviour.Trigger),
                DestinationState = destinationStateInfo,
                GuardConditionsMethodDescriptions = (behaviour.Guard == null)
                    ? new List <InvocationInfo>() : behaviour.Guard.Conditions.Select(c => c.MethodDescription)
            };

            return(transition);
        }
Exemplo n.º 2
0
        internal static void AddRelationships <TState, TTrigger>(StateInfo info, StateMachine <TState, TTrigger> .StateRepresentation stateRepresentation, Func <TState, StateInfo> lookupState)
        {
            if (lookupState == null)
            {
                throw new ArgumentNullException(nameof(lookupState));
            }

            var substates = stateRepresentation.GetSubstates().Select(s => lookupState(s.UnderlyingState)).ToList();

            StateInfo superstate = null;

            if (stateRepresentation.Superstate != null)
            {
                superstate = lookupState(stateRepresentation.Superstate.UnderlyingState);
            }

            var fixedTransitions   = new List <FixedTransitionInfo>();
            var dynamicTransitions = new List <DynamicTransitionInfo>();

            foreach (var triggerBehaviours in stateRepresentation.TriggerBehaviours)
            {
                // First add all the deterministic transitions
                foreach (var item in triggerBehaviours.Value.Where(behaviour => (behaviour is StateMachine <TState, TTrigger> .TransitioningTriggerBehaviour)))
                {
                    var destinationInfo = lookupState(((StateMachine <TState, TTrigger> .TransitioningTriggerBehaviour)item).Destination);
                    fixedTransitions.Add(FixedTransitionInfo.Create(item, destinationInfo));
                }
                foreach (var item in triggerBehaviours.Value.Where(behaviour => (behaviour is StateMachine <TState, TTrigger> .ReentryTriggerBehaviour)))
                {
                    var destinationInfo = lookupState(((StateMachine <TState, TTrigger> .ReentryTriggerBehaviour)item).Destination);
                    fixedTransitions.Add(FixedTransitionInfo.Create(item, destinationInfo));
                }
                //Then add all the internal transitions
                foreach (var item in triggerBehaviours.Value.Where(behaviour => (behaviour is StateMachine <TState, TTrigger> .InternalTriggerBehaviour)))
                {
                    var destinationInfo = lookupState(stateRepresentation.UnderlyingState);
                    fixedTransitions.Add(FixedTransitionInfo.Create(item, destinationInfo));
                }
                // Then add all the dynamic transitions
                foreach (var item in triggerBehaviours.Value.Where(behaviour => behaviour is StateMachine <TState, TTrigger> .DynamicTriggerBehaviour))
                {
                    dynamicTransitions.Add(((StateMachine <TState, TTrigger> .DynamicTriggerBehaviour)item).TransitionInfo);
                }
            }

            info.AddRelationships(superstate, substates, fixedTransitions, dynamicTransitions);
        }