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)); } }; } }
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)); } } }
static void ClearTransitions(State state) { foreach (Transition transition in state.Transitions) { ClearTransition(transition); } }
static void ClearState(State state) { state.ParentState = null; state.StateId = null; state.Reachable = false; state.ClearInternalState(); state.HasInheritedTransition = false; }
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; }
static void StateCannotHaveMultipleParents(NativeActivityMetadata metadata, State state) { metadata.AddValidationError(string.Format(CultureInfo.CurrentCulture, SR.StateCannotHaveMultipleParents, state.DisplayName)); }