예제 #1
0
        static void ValidateTransitions(NativeActivityMetadata metadata, State currentState)
        {
            Collection<Transition> transitions = currentState.Transitions;
            HashSet<Activity> conditionalTransitionTriggers = new HashSet<Activity>();
            Dictionary<Activity, List<Transition>> unconditionalTransitionMapping = new Dictionary<Activity, List<Transition>>();

            foreach (Transition transition in transitions)
            {
                if (transition.Source != null)
                {
                    metadata.AddValidationError(string.Format(CultureInfo.CurrentCulture, SR.TransitionCannotBeAddedTwice, transition.DisplayName, currentState.DisplayName, transition.Source.DisplayName));
                    continue;
                }
                else
                {
                    transition.Source = currentState;
                }

                if (transition.To == null)
                {
                    metadata.AddValidationError(string.Format(CultureInfo.CurrentCulture, SR.TransitionTargetCannotBeNull, transition.DisplayName, currentState.DisplayName));
                }
                else
                {
                    if (transition.To.States.Count > 0)
                    {
                        metadata.AddValidationError(string.Format(CultureInfo.CurrentCulture, SR.TargetStateMustBeSimpleState, transition.To.DisplayName, transition.DisplayName));
                    }

                    if (StateMachineHelper.IsAncestor(currentState.StateId, transition.To.StateId))
                    {
                        metadata.AddValidationError(string.Format(CultureInfo.CurrentCulture, SR.AncestorCannotHaveTransitionToDescendant, currentState.DisplayName, transition.DisplayName, transition.To.DisplayName));
                    }
                }

                if (transition.Trigger != null)
                {
                    if (transition.Condition == null)
                    {
                        if (!unconditionalTransitionMapping.ContainsKey(transition.Trigger))
                        {
                            unconditionalTransitionMapping.Add(transition.Trigger, new List<Transition>());
                        }
                        unconditionalTransitionMapping[transition.Trigger].Add(transition);
                    }
                    else
                    {
                        conditionalTransitionTriggers.Add(transition.Trigger);
                    }
                }
                else
                {
                    metadata.AddValidationError(string.Format(CultureInfo.CurrentCulture, SR.TriggerCannotBeNull, transition.DisplayName, currentState.DisplayName));
                }

            }
            foreach (KeyValuePair<Activity, List<Transition>> unconditionalTransitions in unconditionalTransitionMapping)
            {
                if (conditionalTransitionTriggers.Contains(unconditionalTransitions.Key) || unconditionalTransitions.Value.Count > 1)
                {
                    foreach (Transition transition in unconditionalTransitions.Value)
                    {
                        metadata.AddValidationError(string.Format(CultureInfo.CurrentCulture, SR.UnconditionalTransitionShouldnotShareTriggersWithOthers, transition.DisplayName,
                                   currentState.DisplayName, transition.Trigger.DisplayName));
                    }
                };
            }
        }
예제 #2
0
 static void ValidateState(NativeActivityMetadata metadata, State state)
 {
     if (state.IsFinal)
     {
         if (state.Entry != null)
         {
             metadata.AddValidationError(string.Format(CultureInfo.CurrentCulture, SR.FinalStateCannotHaveEntry, state.DisplayName));
         }
         if (state.Exit != null)
         {
             metadata.AddValidationError(string.Format(CultureInfo.CurrentCulture, SR.FinalStateCannotHaveExit, state.DisplayName));
         }
         if (state.States.Count > 0)
         {
             metadata.AddValidationError(string.Format(CultureInfo.CurrentCulture, SR.FinalStateCannotHaveChildState, state.DisplayName));
         }
         if (state.Transitions.Count > 0)
         {
             metadata.AddValidationError(string.Format(CultureInfo.CurrentCulture, SR.FinalStateCannotHaveTransition, state.DisplayName));
         }
         if (state.ParentState != null)
         {
             metadata.AddValidationError(string.Format(CultureInfo.CurrentCulture, SR.FinalStateCanOnlyBeOnRootLevel, state.DisplayName, state.ParentState.DisplayName));
         }
     }
     else
     {
         if (state.States.Count == 0 && !state.HasInheritedTransition && state.Transitions.Count == 0)
         {
             metadata.AddValidationError(string.Format(CultureInfo.CurrentCulture, SR.SimpleStateWithoutInheritedTransitionMustHaveTransition, state.DisplayName));
         }
     }
 }
예제 #3
0
 static void ClearTransitions(State state)
 {
     foreach (Transition transition in state.Transitions)
     {
         ClearTransition(transition);
     }
 }
예제 #4
0
 static void ClearState(State state)
 {
     state.ParentState = null;
     state.StateId = null;
     state.Reachable = false;
     state.ClearInternalState();
     state.HasInheritedTransition = false;
 }
예제 #5
0
 static void MarkStateViaTransition(NativeActivityMetadata metadata, State state)
 {
     if (string.IsNullOrEmpty(state.StateId))
     {
         metadata.AddValidationError(string.Format(CultureInfo.CurrentCulture, SR.StateNotBelongToAnyParent, state.DisplayName));
     }
     state.Reachable = true;
 }
예제 #6
0
 static void StateCannotHaveMultipleParents(NativeActivityMetadata metadata, State state)
 {
     metadata.AddValidationError(string.Format(CultureInfo.CurrentCulture, SR.StateCannotHaveMultipleParents, state.DisplayName));
 }