Ejemplo n.º 1
0
        private void RemoveActiveBookmark(ActivityContext context)
        {
            StateMachineEventManager eventManager = this.EventManager.Get(context);
            Bookmark bookmark = _evaluateConditionBookmark.Get(context);

            if (bookmark != null)
            {
                eventManager.RemoveActiveBookmark(bookmark);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Execution of StateMachine
        /// </summary>
        /// <param name="context">NativeActivityContext reference</param>
        //[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
        //Justification = "The context is used by workflow runtime. The parameter should be fine.")]
        protected override void Execute(NativeActivityContext context)
        {
            // We view the duration before moving to initial state is on transition.
            StateMachineEventManager localEventManager = _eventManager.Get(context);

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

            context.ScheduleFunc <StateMachineEventManager, string>(
                _internalStateFuncs[index],
                localEventManager,
                _onStateComplete);
        }
Ejemplo n.º 3
0
        private 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.º 4
0
        private void ScheduleAction(NativeActivityContext context)
        {
            StateMachineEventManager eventManager = this.EventManager.Get(context);

            if (eventManager.IsReferredByBeingProcessedEvent(_evaluateConditionBookmark.Get(context)))
            {
                InternalTransition transition = this.GetInternalTransition(eventManager.CurrentBeingProcessedEvent.TriggedId);
                Activity           action     = transition.TransitionDataList[-1 == eventManager.CurrentConditionIndex ? 0 : eventManager.CurrentConditionIndex].Action;

                if (action != null)
                {
                    context.ScheduleActivity(action);
                }
            }

            this.RemoveBookmarks(context);
        }
Ejemplo n.º 5
0
        private 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),
                    _onConditionComplete,
                    null);
            }
        }
Ejemplo n.º 6
0
        private 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);
            }
        }