static void OnWorkflowIdled(object sender, WorkflowEventArgs e) { WorkflowInstance workflow = e.WorkflowInstance; Console.WriteLine("\n...waiting for 3 seconds... \n"); Thread.Sleep(3000); // what activity is blocking the workflow ReadOnlyCollection <WorkflowQueueInfo> wqi = workflow.GetWorkflowQueueData(); foreach (WorkflowQueueInfo q in wqi) { EventQueueName eq = q.QueueName as EventQueueName; if (eq != null) { // get activity that is waiting for event ReadOnlyCollection <string> blockedActivity = q.SubscribedActivityNames; Console.WriteLine("Host: Workflow is blocked on " + blockedActivity[0]); // this event is never going to arrive eg. employee left the company // lets send an exception to this queue // it will either be handled by exception handler that was modeled in workflow // or the runtime will unwind running compensation handlers and exit the workflow Console.WriteLine("Host: This event is not going to arrive"); Console.WriteLine("Host: Cancel workflow with unhandled exception"); workflow.EnqueueItem(q.QueueName, new Exception("ExitWorkflowException"), null, null); } } }
private void SetWorkflowQueueInfo(Guid instanceId, Guid ParentWorkflowId) { if (instanceId != Guid.Empty && ParentWorkflowId != Guid.Empty) { if (!this._SubWorkflowService.IsContainChildWorkflow(instanceId, ParentWorkflowId)) { WorkflowInstance parentInstance = this.GetWorkflowRuntime().GetWorkflow(ParentWorkflowId); WorkflowInstance childInstance = this.GetWorkflowRuntime().GetWorkflow(instanceId); Activity a = childInstance.GetWorkflowDefinition(); a.GetType(); ReadOnlyCollection <WorkflowQueueInfo> queue = parentInstance.GetWorkflowQueueData(); this._SubWorkflowService.SetChildWorkflow(queue, instanceId, ParentWorkflowId, a.Name); } } }
static public WorkflowAction[] GetSubscribedActions(Guid workflowId) { List <WorkflowAction> actions = new List <WorkflowAction>(); SqlTrackingQuery sqlTrackingQuery = new SqlTrackingQuery(ConfigurationManager.ConnectionStrings[Constants.Database.TenantWorkflowStore].ConnectionString); SqlTrackingWorkflowInstance trackingWorkflow; if (!sqlTrackingQuery.TryGetWorkflow(workflowId, out trackingWorkflow) || trackingWorkflow.Status == WorkflowStatus.Completed || trackingWorkflow.Status == WorkflowStatus.Terminated) { return(actions.ToArray()); } WorkflowInstance instance = Runtime.GetWorkflow(workflowId); Activity workflow = instance.GetWorkflowDefinition(); ReadOnlyCollection <WorkflowQueueInfo> queues = instance.GetWorkflowQueueData(); foreach (WorkflowQueueInfo s in queues) { if (s.SubscribedActivityNames.Count == 0) { continue; } EventQueueName eventQueueName = s.QueueName as EventQueueName; if (eventQueueName != null) { WorkflowAction action = new WorkflowAction(); action.ActionName = eventQueueName.MethodName; string activityName = s.SubscribedActivityNames[0]; string[] splittedNames = activityName.Split('.'); action.StepName = splittedNames[0]; HandleExternalEventActivity activity = workflow.GetActivityByName(activityName) as HandleExternalEventActivity; if (activity != null && activity.Roles != null && activity.Roles.Count > 0) { List <string> roleNames = new List <string>(); foreach (WorkflowRole role in activity.Roles) { roleNames.Add(role.Name); } action.QualifiedRoles = roleNames.ToArray(); } actions.Add(action); } } return(actions.ToArray()); }
public void OnFinishCallworkflowActivity(Guid instanceId) { WorkflowInstance instance = this.Runtime.GetWorkflow(instanceId); ReadOnlyCollection <WorkflowQueueInfo> qeue = instance.GetWorkflowQueueData(); bool flag = true; foreach (WorkflowQueueInfo item in qeue) { //string regExp = instanceId + ":" + @"\w*:\w*"; //if (Regex.IsMatch(item.QueueName.ToString(), regExp)) if (item.QueueName.ToString().Contains("ThisIsSubWorkflowSupportForkJoin") && item.QueueName.ToString().Contains(instanceId.ToString())) { flag = false; } // QueueName "2dbe6430-4ef3-432e-af2c-954d2a5cfa88:Subworkflow2:callWorkflowActivity1" System.IComparable {string} } if (flag) { SubWorkflowArgs arg = new SubWorkflowArgs(Guid.Empty, Guid.Empty, instanceId, null); this.OnAllSubWorkflowFinished(arg); } }