Ejemplo n.º 1
0
        protected override void Execute(NativeActivityContext context)
        {
            StateMachineEventManager eventManager = this.EventManager.Get(context);

            eventManager.CurrentBeingProcessedEvent = null;
            this.isExiting.Set(context, false);
            this.ScheduleEntry(context);
        }
        protected override void Execute(NativeActivityContext context)
        {
            StateMachineEventManager argument = this.eventManager.Get(context);

            argument.OnTransition = true;
            int childStateIndex = StateMachineIdHelper.GetChildStateIndex("0", this.InitialState.StateId);

            context.ScheduleFunc <StateMachineEventManager, string>(this.internalStateFuncs[childStateIndex], argument, this.onStateComplete, null);
        }
Ejemplo n.º 3
0
 void RemoveActiveBookmark(ActivityContext context)
 {
     StateMachineEventManager eventManager = this.EventManager.Get(context);
     Bookmark bookmark = this.evaluateConditionBookmark.Get(context);
     if (bookmark != null)
     {
         eventManager.RemoveActiveBookmark(bookmark);
     }
 }
Ejemplo n.º 4
0
        static void ProcessNextTriggerCompletedEvent(NativeActivityContext context, StateMachineEventManager eventManager)
        {
            eventManager.CurrentBeingProcessedEvent = null;
            eventManager.OnTransition = false;

            TriggerCompletedEvent completedEvent = eventManager.GetNextCompletedEvent();

            if (completedEvent != null)
            {
                StateMachineExtension extension = context.GetExtension<StateMachineExtension>();
                Fx.Assert(extension != null, "Failed to obtain a StateMachineExtension.");
                extension.ResumeBookmark(completedEvent.Bookmark);
            }
        }
Ejemplo n.º 5
0
        protected override void Execute(NativeActivityContext context)
        {
            // We view the duration before moving to initial state is on transition.
            StateMachineEventManager localEventManager = this.eventManager.Get(context);

            localEventManager.OnTransition = true;
            localEventManager.CurrentBeingProcessedEvent = null;
            int index = StateMachineIdHelper.GetChildStateIndex(RootId, this.InitialState.StateId);

            context.ScheduleFunc <StateMachineEventManager, string>(
                this.internalStateFuncs[index],
                localEventManager,
                this.onStateComplete);
        }
Ejemplo n.º 6
0
        private void ScheduleAction(NativeActivityContext context)
        {
            StateMachineEventManager manager = this.EventManager.Get(context);

            if (manager.IsReferredByBeingProcessedEvent(this.evaluateConditionBookmark.Get(context)))
            {
                Activity action = this.GetInternalTransition(manager.CurrentBeingProcessedEvent.TriggedId).TransitionDataList[manager.CurrentConditionIndex].Action;
                if (action != null)
                {
                    context.ScheduleActivity(action);
                }
            }
            this.RemoveBookmarks(context);
        }
Ejemplo n.º 7
0
        private void StartEvaluateCondition(NativeActivityContext context, Bookmark bookmark, object value)
        {
            StateMachineEventManager eventManager = this.EventManager.Get(context);
            int triggedId = eventManager.CurrentBeingProcessedEvent.TriggedId;

            eventManager.CurrentConditionIndex = 0;
            if (this.GetInternalTransition(triggedId).IsUnconditional)
            {
                this.TakeTransition(context, eventManager, triggedId);
            }
            else
            {
                context.ScheduleActivity <bool>(this.GetCondition(triggedId, eventManager.CurrentConditionIndex), this.onConditionComplete, null);
            }
        }
Ejemplo n.º 8
0
        void TakeTransition(NativeActivityContext context, StateMachineEventManager eventManager, int triggerId)
        {
            this.EventManager.Get(context).OnTransition = true;
            InternalTransition transition = this.GetInternalTransition(triggerId);

            if (transition.IsUnconditional)
            {
                Fx.Assert(-1 == eventManager.CurrentConditionIndex, "CurrentConditionIndex should be -1, if the transition is unconditional.");
                this.PrepareForExit(context, this.GetTo(triggerId));
            }
            else
            {
                Fx.Assert(-1 != eventManager.CurrentConditionIndex, "CurrentConditionIndex should not be -1, if the transition is conditional.");
                this.PrepareForExit(context, this.GetTo(triggerId, eventManager.CurrentConditionIndex));
            }
        }
Ejemplo n.º 9
0
        void StartEvaluateCondition(NativeActivityContext context, Bookmark bookmark, object value)
        {
            // Start to evaluate conditions of the trigger which represented by currentTriggerIndex
            StateMachineEventManager eventManager = this.EventManager.Get(context);
            int triggerId = eventManager.CurrentBeingProcessedEvent.TriggedId;
            InternalTransition transition = this.GetInternalTransition(triggerId);

            if (transition.IsUnconditional)
            {
                eventManager.CurrentConditionIndex = -1;
                this.TakeTransition(context, eventManager, triggerId);
            }
            else
            {
                eventManager.CurrentConditionIndex = 0;
                context.ScheduleActivity<bool>(
                    this.GetCondition(
                        triggerId,
                        eventManager.CurrentConditionIndex),
                    this.onConditionComplete,
                    null);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Used for Dynamic Update: after the instance is updated, if the statemachine is already transitioning, the index of the to-be-scheduled state 
        /// would need to be updated.
        /// </summary>
        /// <param name="updateContext">Dynamic Update context</param>
        /// <param name="eventManager">Internal StateMachineEventManager</param>
        /// <returns>True, 1. if update is successful and the instanced is updated with the new indexes, and 2 all the trigger ID in the queue are updated;
        /// false otherwise and the update should fail.</returns>
        private bool UpdateEventManager(
            NativeActivityUpdateContext updateContext,
            StateMachineEventManager eventManager)
        {
            Fx.Assert(null != eventManager.CurrentBeingProcessedEvent, "The eventManager must have some info that needs to be updated during transition.");

            int updatedEventsInQueue = 0;
            int originalTriggerId = int.MinValue;
            int originalConditionIndex = int.MinValue;
            bool updateCurrentEventSucceed = null == eventManager.CurrentBeingProcessedEvent ? true : false;

            foreach (InternalTransition transition in this.internalTransitions)
            {
                object savedTriggerIndex = updateContext.GetSavedOriginalValue(transition.Trigger);
                if (savedTriggerIndex != null)
                {
                    Fx.Assert(!updateContext.IsNewlyAdded(transition.Trigger), "the trigger in transition already exist.");

                    if (null != eventManager.CurrentBeingProcessedEvent &&
                        eventManager.CurrentBeingProcessedEvent.TriggedId == (int)savedTriggerIndex)
                    {
                        // found a match of the running trigger update the current processed event
                        // Don't match the trigger ID, match only when the Condition is also matched.
                        if (eventManager.CurrentConditionIndex == -1)
                        {
                            if (transition.IsUnconditional)
                            {
                                // executing transition before persist is unconditional
                                originalTriggerId = eventManager.CurrentBeingProcessedEvent.TriggedId;
                                originalConditionIndex = 0;
                                eventManager.CurrentBeingProcessedEvent.TriggedId = transition.InternalTransitionIndex;

                                if (updateContext.GetValue(this.isExiting))
                                {
                                    Fx.Assert(eventManager.OnTransition, "The state is transitioning.");
                                    updateContext.SetValue(this.Result, GetTo(transition.InternalTransitionIndex));
                                }

                                updateCurrentEventSucceed = true;
                            }
                            else
                            {
                                updateContext.DisallowUpdate(SR.ChangeTransitionTypeDuringTransitioningBlockDU);
                                return false;
                            }
                        }
                        else if (eventManager.CurrentConditionIndex >= 0)
                        {
                            Fx.Assert(!transition.IsUnconditional, "Cannot update a running conditional transition with a unconditional one.");

                            if (!transition.IsUnconditional)
                            {
                                // executing transition before and after are conditional
                                for (int updatedIndex = 0; updatedIndex < transition.TransitionDataList.Count; updatedIndex++)
                                {
                                    Activity condition = transition.TransitionDataList[updatedIndex].Condition;
                                    Fx.Assert(null != condition, "Conditional transition must have Condition activity.");
                                    int? savedCondIndex = updateContext.GetSavedOriginalValue(condition) as int?;

                                    if (eventManager.CurrentConditionIndex == savedCondIndex)
                                    {
                                        originalTriggerId = eventManager.CurrentBeingProcessedEvent.TriggedId;
                                        originalConditionIndex = eventManager.CurrentConditionIndex;
                                        eventManager.CurrentBeingProcessedEvent.TriggedId = transition.InternalTransitionIndex;
                                        eventManager.CurrentConditionIndex = updatedIndex;

                                        if (updateContext.GetValue(this.isExiting))
                                        {
                                            Fx.Assert(eventManager.OnTransition, "The state is transitioning.");
                                            updateContext.SetValue(this.Result, this.GetTo(transition.InternalTransitionIndex, (int)updatedIndex));
                                        }

                                        updateCurrentEventSucceed = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    foreach (TriggerCompletedEvent completedEvent in eventManager.Queue)
                    {
                        if ((int)savedTriggerIndex == completedEvent.TriggedId)
                        {
                            completedEvent.TriggedId = transition.InternalTransitionIndex;
                            updatedEventsInQueue++;
                        }
                    }
                }
            }

            return eventManager.Queue.Count() == updatedEventsInQueue ? updateCurrentEventSucceed : false;
        }
Ejemplo n.º 11
0
 private void TakeTransition(NativeActivityContext context, StateMachineEventManager eventManager, int triggerId)
 {
     this.EventManager.Get(context).OnTransition = true;
     this.PrepareForExit(context, this.GetTo(triggerId, eventManager.CurrentConditionIndex));
 }
Ejemplo n.º 12
0
        private static void ProcessNextTriggerCompletedEvent(NativeActivityContext context, StateMachineEventManager eventManager)
        {
            eventManager.CurrentBeingProcessedEvent = null;
            eventManager.OnTransition = false;
            TriggerCompletedEvent nextCompletedEvent = eventManager.GetNextCompletedEvent();

            if (nextCompletedEvent != null)
            {
                context.GetExtension <StateMachineExtension>().ResumeBookmark(nextCompletedEvent.Bookmark);
            }
        }