protected override void Enqueue(ActivityExecutionContext context) { StateActivity rootState = StateMachineHelpers.GetRootState((StateActivity)context.Activity); StateMachineExecutionState executionState = StateMachineExecutionState.Get(rootState); executionState.SubscriptionManager.Enqueue(context, this.SubscriptionId); }
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); } } } } }
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); } }
private static StateMachineExecutionState GetExecutionState(StateActivity state) { if (state == null) { throw new ArgumentNullException("state"); } return(StateMachineExecutionState.Get(StateMachineHelpers.GetRootState(state))); }
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); }
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); }
private void PopulateDropDownList(ListBox dropDownList, Activity activity) { StateActivity state = StateMachineHelpers.FindEnclosingState(activity); if (state != null) { StateActivity rootState = StateMachineHelpers.GetRootState(state); this.FindStates(dropDownList, rootState); } }
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; }
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; }
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); }
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); }
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); }
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); }
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); } } } } }
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); } }
protected override void Enqueue(ActivityExecutionContext context) { StateMachineExecutionState.Get(StateMachineHelpers.GetRootState((StateActivity)context.Activity)).SubscriptionManager.Enqueue(context, this.QueueName); }
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); } } } }
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); } } } }