/// <summary>Gets the next activities or null when no condition is available. </summary> /// <param name="activity">The current workflow activity. </param> /// <param name="definition">The workflow definition. </param> /// <returns>The next activities. </returns> /// <exception cref="WorkflowException">No next activities could be found based on the given condition. </exception> /// <exception cref="WorkflowException">More then one activity found for condition but activity is not a ForkActivity. </exception> public IWorkflowActivityBase[] GetNextActivities(IWorkflowActivityBase activity, WorkflowDefinition definition) { if (string.IsNullOrEmpty(NextActivitiesCondition)) { return(null); } var nextActivities = definition.GetOutboundTransitions(activity) .Where(t => t.Condition == NextActivitiesCondition) .Select(t => definition.GetActivityById(t.To)) .ToArray(); if (nextActivities.Length == 0) { throw new WorkflowException( string.Format("No next activities could be found based on the given condition '{0}'. ", NextActivitiesCondition)); } if (nextActivities.Length > 1 && !(activity is ForkActivity)) { throw new WorkflowException( string.Format("More then one activity found for condition '{0}' " + "but activity is not a ForkActivity. ", NextActivitiesCondition)); } return(nextActivities); }
/// <exception cref="WorkflowException">Default outgoing transitions of cannot be conditional. </exception> private IWorkflowActivityBase[] GetDefaultNextActivities(IWorkflowActivityBase activity) { var transitions = WorkflowDefinition.GetOutboundTransitions(activity).ToArray(); if (transitions.Any(t => t.IsConditional)) { throw new WorkflowException(string.Format("Default outgoing transitions of ({0}) cannot be conditional. ", activity.Id)); } return(transitions .Select(t => WorkflowDefinition.GetActivityById(t.To)) .ToArray()); }
/// <summary>Gets the next activities or null when no condition is available. </summary> /// <param name="activity">The current workflow activity. </param> /// <param name="definition">The workflow definition. </param> /// <returns>The next activities. </returns> /// <exception cref="WorkflowException">No next activities could be found based on the given condition. </exception> /// <exception cref="WorkflowException">More then one activity found for condition but activity is not a ForkActivity. </exception> public IWorkflowActivityBase[] GetNextActivities(IWorkflowActivityBase activity, WorkflowDefinition definition) { if (string.IsNullOrEmpty(NextActivitiesCondition)) return null; var nextActivities = definition.GetOutboundTransitions(activity) .Where(t => t.Condition == NextActivitiesCondition) .Select(t => definition.GetActivityById(t.To)) .ToArray(); if (nextActivities.Length == 0) throw new WorkflowException( string.Format("No next activities could be found based on the given condition '{0}'. ", NextActivitiesCondition)); if (nextActivities.Length > 1 && !(activity is ForkActivity)) throw new WorkflowException( string.Format("More then one activity found for condition '{0}' " + "but activity is not a ForkActivity. ", NextActivitiesCondition)); return nextActivities; }
/// <exception cref="WorkflowException">A workflow exception occurred. </exception> private async Task AddNextActivitiesAsync(IWorkflowActivityBase activity, IList <IWorkflowActivityBase> nextActivities) { var allowedTransitions = WorkflowDefinition.GetOutboundTransitions(activity); var hasFollowingActivities = allowedTransitions.Length > 0; if (!hasFollowingActivities) { return; } var areNextActivitiesAllowed = nextActivities.All(a => allowedTransitions.Any(t => t.To == a.Id)); if (areNextActivitiesAllowed) { await PrepareNextActivities(nextActivities); } else { throw new WorkflowException( string.Format("Transitions for activities ({0}) produced by activity ({1}) could not be found. ", string.Join(", ", nextActivities.Select(a => a.Id)), activity.Id)); } }