Esempio n. 1
0
        void OnChildStateComplete(NativeActivityContext context, ActivityInstance instance, string targetStateId)
        {
            InternalState completedState = (InternalState)instance.Activity;

            this.hasRunningChildState.Set(context, false);
            //When child state is completed, current state become the deepest child state.
            this.EventManager.Get(context).CompleteDeepestChildBookmark = this.completeStateBookmark.Get(context);
            switch (instance.State)
            {
            case ActivityInstanceState.Closed:
                Debug.Assert(!completedState.IsFinal, "Final state is only on root level.");

                if (StateMachineHelper.IsAncestor(this.StateId, targetStateId))
                {
                    ScheduleChildState(context, targetStateId);
                }
                else
                {
                    //The target state does not belong to this state or the target state equals this state.
                    //In this case, this state should be completed.
                    PrepareForExit(context, targetStateId);
                }
                break;

            case ActivityInstanceState.Canceled:
                if (this.currentRunningTriggers.Get(context) == 0)
                {
                    ScheduleExit(context);
                }
                break;
            }
        }
Esempio n. 2
0
 void OnStateComplete(NativeActivityContext context, ActivityInstance completedInstance, string result)
 {
     if (StateMachineHelper.IsAncestor(rootId, result))
     {
         int index = StateMachineHelper.GetChildStateIndex(rootId, result);
         context.ScheduleFunc <string, StateMachineEventManager, string>(this.internalStateFuncs[index], result,
                                                                         this.eventManager.Get(context), onStateComplete);
     }
 }
Esempio n. 3
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));
                    }
                }
                ;
            }
        }