示例#1
0
        internal void CalculateStateTransition(StateActivity currentState, string targetStateName)
        {
            if (currentState == null)
            {
                throw new ArgumentNullException("currentState");
            }
            if (String.IsNullOrEmpty(targetStateName))
            {
                throw new ArgumentNullException("targetStateName");
            }

            while (currentState != null && (currentState.QualifiedName.Equals(targetStateName) || !StateMachineHelpers.ContainsState(currentState, targetStateName)))
            {
                CloseStateAction action = new CloseStateAction(currentState.QualifiedName);
                this.Actions.Enqueue(action);
                currentState = currentState.Parent as StateActivity;
            }
            if (currentState == null)
            {
                throw new InvalidOperationException(SR.GetUnableToTransitionToState(targetStateName));
            }

            while (!currentState.QualifiedName.Equals(targetStateName))
            {
                foreach (Activity childActivity in currentState.EnabledActivities)
                {
                    StateActivity childState = childActivity as StateActivity;
                    if (childState != null)
                    {
                        //
                        if (StateMachineHelpers.ContainsState(childState, targetStateName))
                        {
                            ExecuteChildStateAction action = new ExecuteChildStateAction(currentState.QualifiedName, childState.QualifiedName);
                            this.Actions.Enqueue(action);
                            currentState = childState;
                            break;
                        }
                    }
                }
            }
            if (!StateMachineHelpers.IsLeafState(currentState))
            {
                throw new InvalidOperationException(SR.GetInvalidStateTransitionPath());
            }
        }