Esempio n. 1
0
        private void ThrowEvent(ExecutionContext context,
                                ILogger logger,
                                IEventThrower eventThrower)
        {
            _history.Add(HistoryItem.Create(context.Token, HistoryItemActions.EventThrown));

            eventThrower.Throw(context.WithRunningElement(eventThrower));
            logger?.LogInformation($"Event {context.Token.ExecutionPoint} was thrown.");

            if (context.Model.IsEndEventThrower(context.Token.ExecutionPoint))
            {
                context.Token.ExecutionPoint = null;
                context.Token.Release();
                IsDone = true;
            }
            else
            {
                var connections = context.Model.GetOutcomingConnections(
                    context.Token.ExecutionPoint
                    ).ToArray();

                // TODO: Move this to the model validation
                if (connections.Length != 1)
                {
                    throw new NotSupportedException();
                }

                context.Token.ExecutionPoint = connections.FirstOrDefault()?.Element.To;
                MoveOn(context, logger);
            }
        }
Esempio n. 2
0
        private void RunActivity(ExecutionContext context,
                                 ILogger logger,
                                 Activity activity)
        {
            _history.Add(HistoryItem.Create(context.Token, HistoryItemActions.ActitvityStarted));

            logger?.LogInformation($"Activity {context.Token.ExecutionPoint} execution will start now.");
            activity.Run(context.WithRunningElement(activity));
        }
        // TODO: Invalidate parallel tokens (?!)
        // TODO: Wait for pending tokens (?!)

        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>))
            {
                return(Enumerable.Empty <Token>());
            }

            // TODO: Handle Exceptions
            _history.Add(HistoryItem.Create(context.Token, completionData, HistoryItemActions.ActivityCompleted));

            return(ContinueExecutionFromTheContextPointConnections(context));
        }
        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();
            }
        }
Esempio n. 5
0
        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());
        }