private void ContinueExecutionFromTheContextPoint( ExecutionContext context ) { var logger = context.ServiceProvider? .GetService <ILogger <ProcessInstance> >(); // TODO: Ensure model is valid (all connections are valid) var e = context.Model.GetElementByName(context.Token.ExecutionPoint); var element = e.Element; switch (element) { case IEventCatcher _: break; case Activity a: { _history.Add(HistoryItem.Create(context.Token, HistoryItemActions.ActitvityStarted)); logger?.LogInformation($"Activity {context.Token.ExecutionPoint} execution will start now."); a.Run(context.WithRunningElement(a)); break; } case IEventThrower et: { _history.Add(HistoryItem.Create(context.Token, HistoryItemActions.EventThrown)); et.Throw(context.WithRunningElement(et)); logger?.LogInformation($"Event {context.Token.ExecutionPoint} was thrown."); ContinueExecutionFromTheContextPointConnections(context); break; } default: throw new NotSupportedException(); } }
public IEnumerable <Token> HandleActivityCompletion(ExecutionContext context, object completionData) { if (!IsRunning) { return(Enumerable.Empty <Token>()); } if (context.Token == null || !context.Token.IsActive) { return(Enumerable.Empty <Token>()); } if (!(context.Model.GetElementByName(context.Token.ExecutionPoint) is INamedProcessElement <Activity> activity)) { return(Enumerable.Empty <Token>()); } // TODO: Handle Exceptions _history.Add(HistoryItem.Create(context.Token, completionData, HistoryItemActions.ActivityCompleted)); var connections = context.Model .GetOutcomingConnections(activity.Name) .ToArray(); // TODO: Provide a better solution for a bad model structure if (!connections.Any()) { throw new NotSupportedException(); } if (connections.Length > 1) { MoveOn(context, connections .Where(connection => { if (!connection.Element.HasFilterValue) { return(true); } if (connection.Element.FilterValue == null) { return(context.Token.LastDefaultOutput == null); } return(connection.Element.FilterValue.Equals( context.Token.LastDefaultOutput )); }) .Select(connection => { var child = context.Token.AllocateChild(); child.ExecutionPoint = connection.Element.To; return(child); })); } else { context.Token.ExecutionPoint = connections.First().Element.To; var logger = context.ServiceProvider? .GetService <ILogger <ProcessInstance> >(); MoveOn(context, logger); } return(context.Token.GetActionableTokens()); }