Exemple #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());
            }
        }
 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 item = new CloseStateAction(currentState.QualifiedName);
         this.Actions.Enqueue(item);
         currentState = currentState.Parent as StateActivity;
     }
     if (currentState == null)
     {
         throw new InvalidOperationException(SR.GetUnableToTransitionToState(targetStateName));
     }
     while (!currentState.QualifiedName.Equals(targetStateName))
     {
         foreach (Activity activity in currentState.EnabledActivities)
         {
             StateActivity state = activity as StateActivity;
             if ((state != null) && StateMachineHelpers.ContainsState(state, targetStateName))
             {
                 ExecuteChildStateAction action2 = new ExecuteChildStateAction(currentState.QualifiedName, state.QualifiedName);
                 this.Actions.Enqueue(action2);
                 currentState = state;
                 break;
             }
         }
     }
     if (!StateMachineHelpers.IsLeafState(currentState))
     {
         throw new InvalidOperationException(SR.GetInvalidStateTransitionPath());
     }
 }