protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { foreach (条件分支 branch in EnabledActivities) { if (string.IsNullOrEmpty(this.分支表达式)) { if (branch.条件 == Root().当前节点提交结果) { branch.RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(branch); return(ActivityExecutionStatus.Executing); } } else { if (branch.条件 == this.分支表达式) { branch.RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(branch); return(ActivityExecutionStatus.Executing); } } } foreach (条件分支 branch in EnabledActivities) { if (branch.条件 == "else") { branch.RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(branch); return(ActivityExecutionStatus.Executing); } } return(ActivityExecutionStatus.Executing); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } Activity bodyActivity = this.BodyActivity; if (bodyActivity == null) { return(ActivityExecutionStatus.Closed); } // run EventHandlers EventHandlersActivity eventHandlers = this.EventHandlersActivity; if (eventHandlers != null) { eventHandlers.RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(eventHandlers); } // run body bodyActivity.RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(bodyActivity); // return the status return(this.ExecutionStatus); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } bool flag = true; for (int i = 0; i < base.EnabledActivities.Count; i++) { IfElseBranchActivity activity = base.EnabledActivities[i] as IfElseBranchActivity; if ((activity.Condition == null) || activity.Condition.Evaluate(activity, executionContext)) { flag = false; activity.RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(activity); break; } } if (!flag) { return(ActivityExecutionStatus.Executing); } return(ActivityExecutionStatus.Closed); }
private bool TryScheduleNextChild(ActivityExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } IList <Activity> enabledActivities = base.EnabledActivities; if (enabledActivities.Count == 0) { return(false); } int num = 0; for (int i = enabledActivities.Count - 1; i >= 0; i--) { if (enabledActivities[i].ExecutionStatus == ActivityExecutionStatus.Closed) { if (i == (enabledActivities.Count - 1)) { return(false); } num = i + 1; break; } } enabledActivities[num].RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(enabledActivities[num]); base.SetValue(ActiveChildQualifiedNameProperty, enabledActivities[num].QualifiedName); return(true); }
void IActivityEventListener <QueueEventArgs> .OnEvent(object sender, QueueEventArgs e) { if (sender == null) { throw new ArgumentNullException("sender"); } if (e == null) { throw new ArgumentNullException("e"); } ActivityExecutionContext context = sender as ActivityExecutionContext; if (context == null) { throw new ArgumentException("sender"); } EventHandlersActivity activityStatusChangeListener = context.Activity as EventHandlersActivity; if ((activityStatusChangeListener.ExecutionStatus == ActivityExecutionStatus.Executing) && activityStatusChangeListener.EnabledActivities.Contains(this.eventDrivenActivity)) { if (this.IsBlocked) { this.IsBlocked = false; ActivityExecutionContext context2 = context.ExecutionContextManager.CreateExecutionContext(this.eventDrivenActivity); context2.Activity.RegisterForStatusChange(Activity.ClosedEvent, activityStatusChangeListener); context2.ExecuteActivity(context2.Activity); } else { this.PendingExecutionCount++; } } }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } bool noneTrue = true; for (int i = 0; i < this.EnabledActivities.Count; ++i) { IfElseBranchActivity branch = this.EnabledActivities[i] as IfElseBranchActivity; // Else case dont have enable condition so find them and enable it if (branch.Condition == null || branch.Condition.Evaluate(branch, executionContext)) { noneTrue = false; branch.RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(branch); break; } } return(noneTrue ? ActivityExecutionStatus.Closed : ActivityExecutionStatus.Executing); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { this.Running = true; bool ActivityStarted = false; if (this.Condition.Evaluate(this, executionContext)) { for (int i = 0; i < this.Activities.Count; i++) { if ((string)this.Activities[i].UserData["logger"] == "logger") { LogToHistoryListActivity logger = (LogToHistoryListActivity)this.Activities[i]; logger.HistoryDescription = string.Format(@"Begin Activity Execution:{0} with {1} enabled Children", this.QualifiedName, this.EnabledActivities.Count.ToString()); break; } } } for (int childNum = 0; childNum < this.EnabledActivities.Count; childNum++) { Activity child = this.EnabledActivities[childNum] as Activity; if (null != child) { child.RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(child); ActivityStarted = true; } } return(ActivityStarted ? ActivityExecutionStatus.Executing : ActivityExecutionStatus.Closed); }
void IActivityEventListener <QueueEventArgs> .OnEvent(object sender, QueueEventArgs e) { if (sender == null) { throw new ArgumentNullException("sender"); } if (e == null) { throw new ArgumentNullException("e"); } ActivityExecutionContext parentContext = sender as ActivityExecutionContext; if (parentContext == null) { throw new ArgumentException(SR.Error_SenderMustBeActivityExecutionContext, "sender"); } ListenActivity activityStatusChangeListener = parentContext.Activity as ListenActivity; if (((!activityStatusChangeListener.IsListenTrigerred && (activityStatusChangeListener.ExecutionStatus != ActivityExecutionStatus.Canceling)) && (activityStatusChangeListener.ExecutionStatus != ActivityExecutionStatus.Closed)) && activityStatusChangeListener.EnabledActivities.Contains(this.eventDrivenActivity)) { activityStatusChangeListener.IsListenTrigerred = true; for (int i = 0; i < activityStatusChangeListener.EnabledActivities.Count; i++) { EventDrivenActivity activity2 = activityStatusChangeListener.EnabledActivities[i] as EventDrivenActivity; ListenActivity.ListenEventActivitySubscriber parentEventHandler = activityStatusChangeListener.ActivityState[i]; activity2.EventActivity.Unsubscribe(parentContext, parentEventHandler); } this.eventDrivenActivity.RegisterForStatusChange(Activity.ClosedEvent, activityStatusChangeListener); parentContext.ExecuteActivity(this.eventDrivenActivity); } }
private void ExecuteChild(ConditionedActivityGroup cag, Activity childActivity, ActivityExecutionContext context) { ActivityExecutionContext context2 = GetChildExecutionContext(context, childActivity, true); cag.CAGState.ChildrenStats[childActivity.QualifiedName].State = CAGChildState.Excuting; context2.Activity.RegisterForStatusChange(Activity.ClosedEvent, this); context2.ExecuteActivity(context2.Activity); }
public ActivityExecutionStatus Execute() { using (ActivityExecutionContext context = new ActivityExecutionContext(this.rootActivity, true)) { context.ExecuteActivity(this.rootActivity); } this.scheduler.Run(); return(this.TranslateExecutionStatus()); }
/// <summary> /// Executes any activities. /// </summary> /// <param name="executionContext">The execution context.</param> private void ExecuteActivities(ActivityExecutionContext executionContext) { for (int i = 0; i < base.EnabledActivities.Count; i++) { Activity activity = base.EnabledActivities[i]; activity.RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(activity); } }
public static ActivityExecutionStatus Execute(CompositeActivity activity, ActivityExecutionContext executionContext) { if (activity.EnabledActivities.Count == 0) { return ActivityExecutionStatus.Closed; } activity.EnabledActivities[0].RegisterForStatusChange(Activity.ClosedEvent, (IActivityEventListener<ActivityExecutionStatusChangedEventArgs>) activity); executionContext.ExecuteActivity(activity.EnabledActivities[0]); activity.SetValue(ActiveChildQualifiedNameProperty, activity.EnabledActivities[0].QualifiedName); return ActivityExecutionStatus.Executing; }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } Activity bodyActivity = this.BodyActivity; if (bodyActivity == null) { return(ActivityExecutionStatus.Closed); } System.Workflow.Activities.EventHandlersActivity eventHandlersActivity = this.EventHandlersActivity; if (eventHandlersActivity != null) { eventHandlersActivity.RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(eventHandlersActivity); } bodyActivity.RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(bodyActivity); return(base.ExecutionStatus); }
private bool TryNextIteration(ActivityExecutionContext context) { if (((base.ExecutionStatus == ActivityExecutionStatus.Canceling) || (base.ExecutionStatus == ActivityExecutionStatus.Faulting)) || !this.Condition.Evaluate(this, context)) { return(false); } if (base.EnabledActivities.Count > 0) { ActivityExecutionContext context2 = context.ExecutionContextManager.CreateExecutionContext(base.EnabledActivities[0]); context2.Activity.RegisterForStatusChange(Activity.ClosedEvent, this); context2.ExecuteActivity(context2.Activity); } return(true); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } if (base.EnabledActivities.Count == 0) { this.OnSequenceComplete(executionContext); return(ActivityExecutionStatus.Closed); } base.EnabledActivities[0].RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(base.EnabledActivities[0]); base.SetValue(ActiveChildQualifiedNameProperty, base.EnabledActivities[0].QualifiedName); return(ActivityExecutionStatus.Executing); }
private static void ExecuteChild(ActivityExecutionContext context, Activity childActivity) { if (context == null) { throw new ArgumentNullException("context"); } if (childActivity == null) { throw new ArgumentNullException("childActivity"); } StateActivity state = (StateActivity)context.Activity; GetExecutionState(state).SchedulerBusy = true; ActivityExecutionContext context2 = context.ExecutionContextManager.CreateExecutionContext(childActivity); context2.Activity.Closed += new EventHandler <ActivityExecutionStatusChangedEventArgs>(state.HandleChildActivityClosed); context2.ExecuteActivity(context2.Activity); }
protected override void OnActivityChangeAdd(ActivityExecutionContext executionContext, Activity addedActivity) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } if (addedActivity == null) { throw new ArgumentNullException("addedActivity"); } ParallelActivity activity = executionContext.Activity as ParallelActivity; if ((activity.ExecutionStatus == ActivityExecutionStatus.Executing) && activity.IsExecuting) { addedActivity.RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(addedActivity); } }
private void ExecuteChild(ConditionedActivityGroup cag, Activity childActivity, ActivityExecutionContext context) { Debug.Assert(cag != null); Debug.Assert(childActivity != null); Debug.Assert(context != null); Debug.Assert(childActivity.ExecutionStatus == ActivityExecutionStatus.Initialized); #if LOG Log("ExecuteChild " + childActivity.QualifiedName + " inside " + cag.QualifiedName); #endif ActivityExecutionContext childContext = GetChildExecutionContext(context, childActivity, true); cag.CAGState.ChildrenStats[childActivity.QualifiedName].State = CAGChildState.Excuting; // subscribe for child closure childContext.Activity.RegisterForStatusChange(Activity.ClosedEvent, this); // execute child in inner context childContext.ExecuteActivity(childContext.Activity); }
/// <summary> /// An activity has been added - hookup to that activites Closed event /// </summary> /// <param name="executionContext"></param> /// <param name="addedActivity"></param> protected override void OnActivityChangeAdd(ActivityExecutionContext executionContext, Activity addedActivity) { if (null == executionContext) { throw new ArgumentNullException("executionContext"); } if (null == addedActivity) { throw new ArgumentNullException("addedActivity"); } DaysOfWeekActivity act = executionContext.Activity as DaysOfWeekActivity; if ((act.ExecutionStatus == ActivityExecutionStatus.Executing) && act.IsExecuting) { addedActivity.RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(addedActivity); } }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } //Tomark that execute method is called for this activity. this.IsExecuting = true; for (int i = 0; i < this.EnabledActivities.Count; ++i) { Activity childActivity = this.EnabledActivities[i]; childActivity.RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(childActivity); } return((this.EnabledActivities.Count == 0) ? ActivityExecutionStatus.Closed : ActivityExecutionStatus.Executing); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } this.IsExecuting = true; for (int i = 0; i < base.EnabledActivities.Count; i++) { Activity activity = base.EnabledActivities[i]; activity.RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(activity); } if (base.EnabledActivities.Count != 0) { return(ActivityExecutionStatus.Executing); } return(ActivityExecutionStatus.Closed); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { ActivityExecutionStatus __status = ActivityExecutionStatus.Closed; if (executionContext == null) { throw new ArgumentNullException("executionContext"); } foreach (IfElseBranchActivityCustom branch in this.EnabledActivities) { if ((branch.Condition == null) || (branch.Condition.Evaluate(branch, executionContext))) { __status = ActivityExecutionStatus.Executing; branch.RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(branch); break; } } return(__status); }
void IActivityEventListener <QueueEventArgs> .OnEvent(object sender, QueueEventArgs e) { if (sender == null) { throw new ArgumentNullException("sender"); } if (e == null) { throw new ArgumentNullException("e"); } ActivityExecutionContext context = sender as ActivityExecutionContext; if (context == null) { throw new ArgumentException(SR.Error_SenderMustBeActivityExecutionContext, "sender"); } ListenActivity parentActivity = context.Activity as ListenActivity; if (!parentActivity.IsListenTrigerred && parentActivity.ExecutionStatus != ActivityExecutionStatus.Canceling && parentActivity.ExecutionStatus != ActivityExecutionStatus.Closed) { //Check whether it is still live in tree. if (!parentActivity.EnabledActivities.Contains(eventDrivenActivity))//Activity is dynamically removed. { return; } parentActivity.IsListenTrigerred = true; for (int i = 0; i < parentActivity.EnabledActivities.Count; ++i) { EventDrivenActivity eventDriven = parentActivity.EnabledActivities[i] as EventDrivenActivity; ListenEventActivitySubscriber eventSubscriber = parentActivity.ActivityState[i]; eventDriven.EventActivity.Unsubscribe(context, eventSubscriber); } eventDrivenActivity.RegisterForStatusChange(Activity.ClosedEvent, parentActivity); context.ExecuteActivity(eventDrivenActivity); } }
void IActivityEventListener <QueueEventArgs> .OnEvent(object sender, QueueEventArgs e) { if (sender == null) { throw new ArgumentNullException("sender"); } if (e == null) { throw new ArgumentNullException("e"); } ActivityExecutionContext context = sender as ActivityExecutionContext; if (context == null) { throw new ArgumentException("sender"); } EventHandlersActivity handlers = context.Activity as EventHandlersActivity; if (handlers.ExecutionStatus != ActivityExecutionStatus.Executing) { return; } if (!handlers.EnabledActivities.Contains(eventDrivenActivity)) { return; //Activity is dynamically removed. } if (IsBlocked) { IsBlocked = false; ActivityExecutionContextManager contextManager = context.ExecutionContextManager; ActivityExecutionContext childContext = contextManager.CreateExecutionContext(eventDrivenActivity); childContext.Activity.RegisterForStatusChange(Activity.ClosedEvent, handlers); childContext.ExecuteActivity(childContext.Activity); } else { PendingExecutionCount++; } }
private void ExecuteTemplate(ActivityExecutionContext executionContext, ChildExecutionStateInfo childStateInfo) { ActivityExecutionContextManager executionContextManager = executionContext.ExecutionContextManager; ActivityExecutionContext childContext = executionContextManager.CreateExecutionContext(base.EnabledActivities[0]); childStateInfo.RunId = childContext.ContextGuid; childStateInfo.Status = ChildRunStatus.Running; try { base.RaiseGenericEvent <ReplicatorChildEventArgs>(ChildInitializedEvent, this, new ReplicatorChildEventArgs(childStateInfo.InstanceData, childContext.Activity)); } catch { childStateInfo.RunId = Guid.Empty; childStateInfo.Status = ChildRunStatus.Completed; executionContextManager.CompleteExecutionContext(childContext); throw; } childContext.ExecuteActivity(childContext.Activity); childContext.Activity.RegisterForStatusChange(Activity.ClosedEvent, new ReplicatorSubscriber(this, childContext.ContextGuid)); }
/// <summary> /// Execute the activity /// </summary> /// <param name="executionContext"></param> /// <returns>Exedcuting if any children are running, otherwise Closed</returns> protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { if (null == executionContext) { throw new ArgumentNullException("executionContext"); } this.IsExecuting = true; for (int pos = 0; pos < base.EnabledActivities.Count; pos++) { SequenceActivity act = base.EnabledActivities[pos] as SequenceActivity; if (null != act) { /* foreach (Account account in Customer.Accounts) * { * if (account.GetType() == act.AccountType) * { * act.Account = account; * act.RegisterForStatusChange(Activity.ClosedEvent, this); * executionContext.ExecuteActivity(act); * } * }*/ act.RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(act); } } if (base.EnabledActivities.Count != 0) { return(ActivityExecutionStatus.Executing); } else { return(ActivityExecutionStatus.Closed); } }
private bool TryNextIteration(ActivityExecutionContext context) { if (this.ExecutionStatus == ActivityExecutionStatus.Canceling || this.ExecutionStatus == ActivityExecutionStatus.Faulting || !this.Condition.Evaluate(this, context)) { return(false); } else { if (this.EnabledActivities.Count > 0) { ActivityExecutionContextManager contextManager = context.ExecutionContextManager; ActivityExecutionContext innerContext = contextManager.CreateExecutionContext(this.EnabledActivities[0]); innerContext.Activity.RegisterForStatusChange(Activity.ClosedEvent, this); innerContext.ExecuteActivity(innerContext.Activity); } else { System.Diagnostics.Debug.Assert(false); } return(true); } }
private static void ExecuteChild(ActivityExecutionContext context, Activity childActivity) { if (context == null) { throw new ArgumentNullException("context"); } if (childActivity == null) { throw new ArgumentNullException("childActivity"); } StateActivity state = (StateActivity)context.Activity; StateMachineExecutionState executionState = GetExecutionState(state); Debug.Assert(!executionState.SchedulerBusy); executionState.SchedulerBusy = true; ActivityExecutionContextManager contextManager = context.ExecutionContextManager; ActivityExecutionContext childContext = contextManager.CreateExecutionContext(childActivity); childContext.Activity.Closed += state.HandleChildActivityClosed; childContext.ExecuteActivity(childContext.Activity); }
// This function executes the ForEach activity. It advances the current index of the collection. // If the end of the collection is reached, return false. Otherwise, it executes any child activity // and return true. private bool ExecuteNext(ActivityExecutionContext context) { // First, move to the next position. if (!this.Enumerator.MoveNext()) { return(false); } // Execute the child activity. if (this.EnabledActivities.Count > 0) { // Add the child activity to the execution context and setup the event handler to // listen to the child Close event. // A new instance of the child activity is created for each iteration. ActivityExecutionContext innerContext = context.ExecutionContextManager.CreateExecutionContext(this.EnabledActivities[0]); innerContext.Activity.Closed += this.OnChildClose; // Fire the Iterating event. base.RaiseEvent(IteratingEvent, this, EventArgs.Empty); // Execute the child activity again. innerContext.ExecuteActivity(innerContext.Activity); } else { // an empty foreach loop. // If the ForEach activity is still executing, then execute the next one. if (this.ExecutionStatus == ActivityExecutionStatus.Executing) { if (!ExecuteNext(context)) { context.CloseActivity(); } } } return(true); }
private bool TryScheduleNextChild(ActivityExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } IList <Activity> seqList = this.EnabledActivities; if (seqList.Count == 0) { return(false); } //Find index of next activity to run. int indexOfNextActivity = 0; for (int i = (seqList.Count - 1); i >= 0; i--) { if (seqList[i].ExecutionStatus == ActivityExecutionStatus.Closed) { //Check whether this is last child? if (i == (seqList.Count - 1)) { return(false); } indexOfNextActivity = i + 1; break; } } seqList[indexOfNextActivity].RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(seqList[indexOfNextActivity]); this.SetValue(ActiveChildQualifiedNameProperty, seqList[indexOfNextActivity].QualifiedName); return(true); }
/// <summary> /// Execute the activity /// </summary> /// <param name="executionContext"></param> /// <returns>Exedcuting if any children are running, otherwise Closed</returns> protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { if (null == executionContext) { throw new ArgumentNullException("executionContext"); } this.IsExecuting = true; bool executingChildren = false; DateTime date = (this.Date == DateTime.MinValue) ? DateTime.Now : this.Date; // Get the day of the week from this activity & convert to a WeekdayEnum WeekdayEnum weekday = date.DayOfWeek == 0 ? WeekdayEnum.Sunday : (WeekdayEnum)(Convert.ToInt32(Math.Pow(2, (int)date.DayOfWeek))); for (int pos = 0; pos < base.EnabledActivities.Count; pos++) { SequenceActivity act = base.EnabledActivities[pos] as SequenceActivity; if (null != act) { // Get the attached Weekday property for the activity WeekdayEnum weekdays = (WeekdayEnum)GetWeekday(act); // Now check for a match if ((weekdays & weekday) != WeekdayEnum.None) { executingChildren = true; act.RegisterForStatusChange(Activity.ClosedEvent, this); executionContext.ExecuteActivity(act); } } } return(executingChildren ? ActivityExecutionStatus.Executing : ActivityExecutionStatus.Closed); }
public ActivityExecutionStatus Execute() { using (ActivityExecutionContext activityExecutionContext = new ActivityExecutionContext(this.rootActivity, true)) { activityExecutionContext.ExecuteActivity(this.rootActivity); } scheduler.Run(); return TranslateExecutionStatus(); }
private static bool TryScheduleNextChild(CompositeActivity activity, ActivityExecutionContext executionContext) { IList<Activity> enabledActivities = activity.EnabledActivities; int num = 0; for (int i = enabledActivities.Count - 1; i >= 0; i--) { if (enabledActivities[i].ExecutionStatus == ActivityExecutionStatus.Closed) { if (i == (enabledActivities.Count - 1)) { return false; } num = i + 1; break; } } enabledActivities[num].RegisterForStatusChange(Activity.ClosedEvent, (IActivityEventListener<ActivityExecutionStatusChangedEventArgs>) activity); executionContext.ExecuteActivity(enabledActivities[num]); activity.SetValue(ActiveChildQualifiedNameProperty, enabledActivities[num].QualifiedName); return true; }
internal void Start() { using (new ScheduleWork(this)) { using (this.ExecutorLock.Enter()) { if (this.WorkflowStatus != System.Workflow.Runtime.WorkflowStatus.Created) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, ExecutionStringManager.CannotStartInstanceTwice, new object[] { this.InstanceId })); } this.WorkflowStatus = System.Workflow.Runtime.WorkflowStatus.Running; using (new ServiceEnvironment(this.rootActivity)) { this.FireWorkflowExecutionEvent(this, WorkflowEventInternal.Starting); try { using (ActivityExecutionContext context = new ActivityExecutionContext(this.rootActivity, true)) { this.schedulingContext.CanRun = true; using (new SchedulerLockGuard(this._schedulerLock, this)) { context.ExecuteActivity(this.rootActivity); } } } catch (Exception exception) { this.Terminate(exception.Message); throw; } this.FireWorkflowExecutionEvent(this, WorkflowEventInternal.Started); } } } }
internal void Start() { using (ScheduleWork work = new ScheduleWork(this)) { using (this.ExecutorLock.Enter()) { if (this.WorkflowStatus != WorkflowStatus.Created) throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, ExecutionStringManager.CannotStartInstanceTwice, this.InstanceId)); // Set a new ServiceEnvironment to establish a current batch in TLS // This is needed for synchronous status change notification at start // (status init->executing) when there is no batch in TLS yet // and there are subscribers like tracking this.WorkflowStatus = WorkflowStatus.Running; using (new ServiceEnvironment(this.rootActivity)) { FireWorkflowExecutionEvent(this, WorkflowEventInternal.Starting); try { using (ActivityExecutionContext executionContext = new ActivityExecutionContext(this.rootActivity, true)) { // make sure the scheduler is able to run this.schedulingContext.CanRun = true; // Since we are actually scheduling work at this point, we should grab // the scheduler lock. This will avoid ----s some operations we schedule // start executing before we are done scheduling all operations. using (new SchedulerLockGuard(this._schedulerLock, this)) { executionContext.ExecuteActivity(this.rootActivity); } } } catch (Exception e) { Terminate(e.Message); throw; } FireWorkflowExecutionEvent(this, WorkflowEventInternal.Started); } } } }
private static bool TryScheduleNextChild(CompositeActivity activity, ActivityExecutionContext executionContext) { IList<Activity> children = activity.EnabledActivities; // Find index of next activity to run. int indexOfNextActivity = 0; for (int i = (children.Count - 1); i >= 0; i--) { if (children[i].ExecutionStatus == ActivityExecutionStatus.Closed) { // Check whether this is last child? if (i == (children.Count - 1)) return false; indexOfNextActivity = i + 1; break; } } children[indexOfNextActivity].RegisterForStatusChange(Activity.ClosedEvent, (IActivityEventListener<ActivityExecutionStatusChangedEventArgs>)activity); executionContext.ExecuteActivity(children[indexOfNextActivity]); activity.SetValue(ActiveChildQualifiedNameProperty, children[indexOfNextActivity].QualifiedName); return true; }