protected override void Enqueue(ActivityExecutionContext context)
        {
            StateActivity rootState = StateMachineHelpers.GetRootState((StateActivity)context.Activity);
            StateMachineExecutionState executionState = StateMachineExecutionState.Get(rootState);

            executionState.SubscriptionManager.Enqueue(context, this.SubscriptionId);
        }
Пример #2
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = new ValidationErrorCollection(base.Validate(manager, obj));
            SetStateActivity          setState         = obj as SetStateActivity;

            if (setState == null)
            {
                throw new ArgumentException(SR.GetString("Error_UnexpectedArgumentType", new object[] { typeof(StateActivity).FullName }), "obj");
            }
            if (SetStateContainment.Validate(setState, validationErrors))
            {
                if (string.IsNullOrEmpty(setState.TargetStateName))
                {
                    validationErrors.Add(new ValidationError(SR.GetString("Error_PropertyNotSet", new object[] { "TargetStateName" }), 0x116, false, "TargetStateName"));
                    return(validationErrors);
                }
                StateActivity state = StateMachineHelpers.FindStateByName(StateMachineHelpers.GetRootState(StateMachineHelpers.FindEnclosingState(setState)), setState.TargetStateName);
                if (state == null)
                {
                    validationErrors.Add(new ValidationError(SR.GetError_SetStateMustPointToAState(), 0x5f3, false, "TargetStateName"));
                    return(validationErrors);
                }
                if (!StateMachineHelpers.IsLeafState(state))
                {
                    validationErrors.Add(new ValidationError(SR.GetError_SetStateMustPointToALeafNodeState(), 0x5f4, false, "TargetStateName"));
                }
            }
            return(validationErrors);
        }
        internal override void Execute(ActivityExecutionContext context)
        {
            base.Execute(context);
            StateActivity         rootState = StateMachineHelpers.GetRootState(base.State);
            Queue <StateActivity> queue     = new Queue <StateActivity>();

            queue.Enqueue(rootState);
            while (queue.Count > 0)
            {
                foreach (Activity activity3 in queue.Dequeue().EnabledActivities)
                {
                    EventDrivenActivity eventDriven = activity3 as EventDrivenActivity;
                    if (eventDriven != null)
                    {
                        IComparable queueName = StateMachineHelpers.GetEventActivity(eventDriven).QueueName;
                        if (queueName != null)
                        {
                            WorkflowQueue workflowQueue = StateMachineSubscriptionManager.GetWorkflowQueue(context, queueName);
                            if (workflowQueue != null)
                            {
                                workflowQueue.Enabled = base.SubscriptionManager.Subscriptions.ContainsKey(queueName);
                            }
                        }
                    }
                    else
                    {
                        StateActivity item = activity3 as StateActivity;
                        if (item != null)
                        {
                            queue.Enqueue(item);
                        }
                    }
                }
            }
        }
Пример #4
0
        protected override void Initialize(IServiceProvider provider)
        {
            base.Initialize(provider);

            ActivityExecutionContext context = (ActivityExecutionContext)provider;

            StateActivity rootState = StateMachineHelpers.GetRootState(this);

            if (!StateMachineHelpers.IsStateMachine(rootState))
            {
                throw new InvalidOperationException(SR.GetError_StateActivityMustBeContainedInAStateMachine());
            }

            string initialStateName = StateMachineHelpers.GetInitialStateName(this);

            if (String.IsNullOrEmpty(initialStateName))
            {
                throw new InvalidOperationException(SR.GetError_CannotExecuteStateMachineWithoutInitialState());
            }

            //


            if (this.QualifiedName != initialStateName)
            {
                StateMachineSubscriptionManager.DisableStateWorkflowQueues(context, this);
            }
        }
Пример #5
0
 private static StateMachineExecutionState GetExecutionState(StateActivity state)
 {
     if (state == null)
     {
         throw new ArgumentNullException("state");
     }
     return(StateMachineExecutionState.Get(StateMachineHelpers.GetRootState(state)));
 }
Пример #6
0
        internal override void ProcessEvent(ActivityExecutionContext context)
        {
            StateMachineExecutionState state  = StateMachineExecutionState.Get(StateMachineHelpers.GetRootState((StateActivity)context.Activity));
            ExternalEventAction        action = new ExternalEventAction(this.StateName, this.EventDrivenName);

            state.EnqueueAction(action);
            state.ProcessActions(context);
        }
Пример #7
0
 protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
 {
     if (executionContext == null)
     {
         throw new ArgumentNullException("executionContext");
     }
     StateMachineExecutionState.Get(StateMachineHelpers.GetRootState(StateMachineHelpers.FindEnclosingState(executionContext.Activity))).NextStateName = this.TargetStateName;
     return(ActivityExecutionStatus.Closed);
 }
        internal override void ProcessEvent(ActivityExecutionContext context)
        {
            StateActivity rootState = StateMachineHelpers.GetRootState((StateActivity)context.Activity);
            StateMachineExecutionState executionState = StateMachineExecutionState.Get(rootState);
            ExternalEventAction        action         = new ExternalEventAction(this.StateName, this.EventDrivenName);

            Debug.Assert(!executionState.HasEnqueuedActions);
            executionState.EnqueueAction(action);
            executionState.ProcessActions(context);
        }
Пример #9
0
        private void PopulateDropDownList(ListBox dropDownList, Activity activity)
        {
            StateActivity state = StateMachineHelpers.FindEnclosingState(activity);

            if (state != null)
            {
                StateActivity rootState = StateMachineHelpers.GetRootState(state);
                this.FindStates(dropDownList, rootState);
            }
        }
Пример #10
0
        internal virtual void Execute(ActivityExecutionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            this._state        = (StateActivity)context.Activity;
            this._currentState = StateMachineHelpers.GetCurrentState(context);
            StateActivity rootState = StateMachineHelpers.GetRootState(this._state);

            this._executionState      = StateMachineExecutionState.Get(rootState);
            this._subscriptionManager = this._executionState.SubscriptionManager;
        }
Пример #11
0
        internal virtual void Execute(ActivityExecutionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            Debug.Assert(context.Activity.QualifiedName.Equals(this.StateName));
            _state        = (StateActivity)context.Activity;
            _currentState = StateMachineHelpers.GetCurrentState(context);
            StateActivity rootState = StateMachineHelpers.GetRootState(_state);

            _executionState      = StateMachineExecutionState.Get(rootState);
            _subscriptionManager = _executionState.SubscriptionManager;
        }
Пример #12
0
        internal override void ProcessEvent(ActivityExecutionContext context)
        {
            SetStateEventArgs args         = context.GetService <WorkflowQueuingService>().GetWorkflowQueue("SetStateQueue").Dequeue() as SetStateEventArgs;
            StateActivity     currentState = StateMachineHelpers.GetCurrentState(context);

            if (currentState == null)
            {
                throw new InvalidOperationException(SR.GetStateMachineWorkflowMustHaveACurrentState());
            }
            StateMachineExecutionState state  = StateMachineExecutionState.Get(StateMachineHelpers.GetRootState((StateActivity)context.Activity));
            SetStateAction             action = new SetStateAction(currentState.QualifiedName, args.TargetStateName);

            state.EnqueueAction(action);
            state.ProcessActions(context);
        }
Пример #13
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = new ValidationErrorCollection(base.Validate(manager, obj));

            SetStateActivity setState = obj as SetStateActivity;

            if (setState == null)
            {
                throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(StateActivity).FullName), "obj");
            }

            if (!SetStateContainment.Validate(setState, validationErrors))
            {
                return(validationErrors); // could not find a valid parent
            }
            if (String.IsNullOrEmpty(setState.TargetStateName))
            {
                validationErrors.Add(new ValidationError(
                                         SR.GetString(SR.Error_PropertyNotSet, SetStateActivity.TargetStateNamePropertyName),
                                         ErrorNumbers.Error_PropertyNotSet, false,
                                         SetStateActivity.TargetStateNamePropertyName));
            }
            else
            {
                StateActivity enclosingState = StateMachineHelpers.FindEnclosingState(setState);
                Debug.Assert(enclosingState != null); // this should be caught by the SetStateContainment.Validate call above

                StateActivity rootState = StateMachineHelpers.GetRootState(enclosingState);

                StateActivity targetActivity = StateMachineHelpers.FindStateByName(
                    rootState,
                    setState.TargetStateName);
                StateActivity targetState = targetActivity as StateActivity;
                if (targetState == null)
                {
                    validationErrors.Add(new ValidationError(SR.GetError_SetStateMustPointToAState(), ErrorNumbers.Error_SetStateMustPointToAState, false, SetStateActivity.TargetStateNamePropertyName));
                }
                else
                {
                    if (!StateMachineHelpers.IsLeafState(targetState))
                    {
                        validationErrors.Add(new ValidationError(SR.GetError_SetStateMustPointToALeafNodeState(), ErrorNumbers.Error_SetStateMustPointToALeafNodeState, false, SetStateActivity.TargetStateNamePropertyName));
                    }
                }
            }

            return(validationErrors);
        }
Пример #14
0
        private void PopulateDropDownList(ListBox dropDownList, Activity activity)
        {
            Debug.Assert(dropDownList != null);
            Debug.Assert(activity != null);

            StateActivity enclosingState = StateMachineHelpers.FindEnclosingState(activity);

            if (enclosingState == null)
            {
                return;
            }

            StateActivity rootState = StateMachineHelpers.GetRootState(enclosingState);

            FindStates(dropDownList, rootState);
        }
Пример #15
0
        protected override void OnActivityChangeAdd(ActivityExecutionContext executionContext, Activity addedActivity)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }
            if (addedActivity == null)
            {
                throw new ArgumentNullException("addedActivity");
            }

            if (!addedActivity.Enabled)
            {
                return;
            }

            if (executionContext.Activity.ExecutionStatus != ActivityExecutionStatus.Executing)
            {
                return; // activity is not executing
            }
            EventDrivenActivity eventDriven = addedActivity as EventDrivenActivity;

            if (eventDriven == null)
            {
                return;
            }

            // Activity we added is an EventDrivenActivity

            // First we disable the queue
            StateMachineSubscriptionManager.ChangeEventDrivenQueueState(executionContext, eventDriven, false);
            StateActivity rootState = StateMachineHelpers.GetRootState(executionContext.Activity as StateActivity);
            StateMachineExecutionState executionState = StateMachineExecutionState.Get(rootState);
            StateActivity currentState = StateMachineHelpers.GetCurrentState(executionContext);

            if (currentState == null)
            {
                return; // Dynamic update happened before we entered the initial state
            }
            StateMachineSubscriptionManager subscriptionManager = executionState.SubscriptionManager;

            subscriptionManager.ReevaluateSubscriptions(executionContext);
            executionState.LockQueue();
            executionState.ProcessActions(executionContext);
        }
        internal override void ProcessEvent(ActivityExecutionContext context)
        {
            WorkflowQueuingService workflowQueuingService = context.GetService <WorkflowQueuingService>();
            WorkflowQueue          workflowQueue          = workflowQueuingService.GetWorkflowQueue(StateMachineWorkflowActivity.SetStateQueueName);
            SetStateEventArgs      eventArgs    = workflowQueue.Dequeue() as SetStateEventArgs;
            StateActivity          currentState = StateMachineHelpers.GetCurrentState(context);

            if (currentState == null)
            {
                throw new InvalidOperationException(SR.GetStateMachineWorkflowMustHaveACurrentState());
            }

            StateActivity rootState = StateMachineHelpers.GetRootState((StateActivity)context.Activity);
            StateMachineExecutionState executionState = StateMachineExecutionState.Get(rootState);
            SetStateAction             action         = new SetStateAction(currentState.QualifiedName, eventArgs.TargetStateName);

            Debug.Assert(!executionState.HasEnqueuedActions);
            executionState.EnqueueAction(action);
            executionState.ProcessActions(context);
        }
Пример #17
0
        internal override void Execute(ActivityExecutionContext context)
        {
            base.Execute(context);

            StateActivity         state     = this.State;
            StateActivity         rootState = StateMachineHelpers.GetRootState(state);
            Queue <StateActivity> states    = new Queue <StateActivity>();

            states.Enqueue(rootState);
            while (states.Count > 0)
            {
                state = states.Dequeue();
                foreach (Activity activity in state.EnabledActivities)
                {
                    EventDrivenActivity eventDriven = activity as EventDrivenActivity;
                    if (eventDriven != null)
                    {
                        IEventActivity eventActivity = StateMachineHelpers.GetEventActivity(eventDriven);
                        IComparable    queueName     = eventActivity.QueueName;
                        if (queueName != null)
                        {
                            WorkflowQueue queue = StateMachineSubscriptionManager.GetWorkflowQueue(context, queueName);
                            if (queue != null)
                            {
                                queue.Enabled = this.SubscriptionManager.Subscriptions.ContainsKey(queueName);
                            }
                        }
                    }
                    else
                    {
                        StateActivity childState = activity as StateActivity;
                        if (childState != null)
                        {
                            states.Enqueue(childState);
                        }
                    }
                }
            }
        }
Пример #18
0
        internal void ProcessActions(ActivityExecutionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (this.SchedulerBusy)
            {
                return;
            }

            StateActivity state = (StateActivity)context.Activity;

            if (this.Actions.Count == 0)
            {
                this.SubscriptionManager.ProcessQueue(context);
                return;
            }

            StateMachineAction action = this.Actions.Peek();

            while (action.StateName.Equals(state.QualifiedName))
            {
                action = DequeueAction();
                action.Execute(context);

                // If the previous action just
                // requested something to the runtime
                // scheduler, then we quit, since
                // the scheduler takes precedence.
                // we'll pick up the processing of actions
                // after the scheduler return the control to us.
                if (this.SchedulerBusy)
                {
                    return;
                }

                if (this.Actions.Count == 0)
                {
                    break;
                }

                action = this.Actions.Peek();
            }

            if (this.Actions.Count > 0)
            {
                StateActivity rootState       = StateMachineHelpers.GetRootState(state);
                StateActivity nextActionState = StateMachineHelpers.FindDynamicStateByName(rootState, action.StateName);
                if (nextActionState == null)
                {
                    throw new InvalidOperationException(SR.GetInvalidStateMachineAction(action.StateName));
                }

                nextActionState.RaiseProcessActionEvent(context);
            }
            else
            {
                this.SubscriptionManager.ProcessQueue(context);
            }
        }
Пример #19
0
 protected override void Enqueue(ActivityExecutionContext context)
 {
     StateMachineExecutionState.Get(StateMachineHelpers.GetRootState((StateActivity)context.Activity)).SubscriptionManager.Enqueue(context, this.QueueName);
 }
Пример #20
0
 internal void ProcessActions(ActivityExecutionContext context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if (!this.SchedulerBusy)
     {
         StateActivity state = (StateActivity)context.Activity;
         if (this.Actions.Count == 0)
         {
             this.SubscriptionManager.ProcessQueue(context);
         }
         else
         {
             StateMachineAction action = this.Actions.Peek();
             while (action.StateName.Equals(state.QualifiedName))
             {
                 action = this.DequeueAction();
                 action.Execute(context);
                 if (this.SchedulerBusy)
                 {
                     return;
                 }
                 if (this.Actions.Count == 0)
                 {
                     break;
                 }
                 action = this.Actions.Peek();
             }
             if (this.Actions.Count > 0)
             {
                 StateActivity activity3 = StateMachineHelpers.FindDynamicStateByName(StateMachineHelpers.GetRootState(state), action.StateName);
                 if (activity3 == null)
                 {
                     throw new InvalidOperationException(SR.GetInvalidStateMachineAction(action.StateName));
                 }
                 activity3.RaiseProcessActionEvent(context);
             }
             else
             {
                 this.SubscriptionManager.ProcessQueue(context);
             }
         }
     }
 }
Пример #21
0
 protected override void OnActivityChangeAdd(ActivityExecutionContext executionContext, Activity addedActivity)
 {
     if (executionContext == null)
     {
         throw new ArgumentNullException("executionContext");
     }
     if (addedActivity == null)
     {
         throw new ArgumentNullException("addedActivity");
     }
     if (addedActivity.Enabled && (executionContext.Activity.ExecutionStatus == ActivityExecutionStatus.Executing))
     {
         EventDrivenActivity eventDriven = addedActivity as EventDrivenActivity;
         if (eventDriven != null)
         {
             StateMachineSubscriptionManager.ChangeEventDrivenQueueState(executionContext, eventDriven, false);
             StateMachineExecutionState state = StateMachineExecutionState.Get(StateMachineHelpers.GetRootState(executionContext.Activity as StateActivity));
             if (StateMachineHelpers.GetCurrentState(executionContext) != null)
             {
                 state.SubscriptionManager.ReevaluateSubscriptions(executionContext);
                 state.LockQueue();
                 state.ProcessActions(executionContext);
             }
         }
     }
 }