Ejemplo n.º 1
0
        public override void Execute(IActivityExecution execution)
        {
            execution.InActivate();
            LockConcurrentRoot(execution);

            var activity = execution.Activity;

            if (ActivatesGateway(execution, activity))
            {
                Log.ActivityActivation(activity.Id);

                var joinedExecutions    = execution.FindInactiveConcurrentExecutions(activity);
                var defaultSequenceFlow = (string)execution.Activity.GetProperty("default");
                IList <IPvmTransition> transitionsToTake = new List <IPvmTransition>();

                // find matching non-default sequence flows
                foreach (var outgoingTransition in execution.Activity.OutgoingTransitions)
                {
                    if (ReferenceEquals(defaultSequenceFlow, null) || !outgoingTransition.Id.Equals(defaultSequenceFlow))
                    {
                        var condition = (ICondition)outgoingTransition.GetProperty(BpmnParse.PropertynameCondition);
                        if ((condition == null) || condition.Evaluate(execution))
                        {
                            transitionsToTake.Add(outgoingTransition);
                        }
                    }
                }

                // if none found, add default flow
                if (transitionsToTake.Count == 0)
                {
                    if (!ReferenceEquals(defaultSequenceFlow, null))
                    {
                        var defaultTransition = execution.Activity.FindOutgoingTransition(defaultSequenceFlow);
                        if (defaultTransition == null)
                        {
                            throw Log.MissingDefaultFlowException(execution.Activity.Id, defaultSequenceFlow);
                        }

                        transitionsToTake.Add(defaultTransition);
                    }
                    else
                    {
                        // No sequence flow could be found, not even a default one
                        throw Log.StuckExecutionException(execution.Activity.Id);
                    }
                }
                // take the flows found
                execution.LeaveActivityViaTransitions(transitionsToTake, joinedExecutions);
            }
            else
            {
                Log.NoActivityActivation(activity.Id);
            }
        }
Ejemplo n.º 2
0
        public void Complete(IActivityExecution execution)
        {
            var outgoingTransitions = execution.Activity.OutgoingTransitions;

            if (!outgoingTransitions.Any())
            {
                execution.End(true);
            }
            else
            {
                execution.LeaveActivityViaTransitions(outgoingTransitions, new List <IActivityExecution>());
            }
        }
Ejemplo n.º 3
0
//private static Logger LOG = ProcessEngineLogger.TEST_LOGGER.GetLogger();

        public void Execute(IActivityExecution execution)
        {
            var activity = execution.Activity;

            var outgoingTransitions = execution.Activity.OutgoingTransitions;

            execution.InActivate();

            var joinedExecutions = execution.FindInactiveConcurrentExecutions(activity);

            var nbrOfExecutionsToJoin = execution.Activity.IncomingTransitions.Count;
            var nbrOfExecutionsJoined = joinedExecutions.Count;

            if (nbrOfExecutionsJoined == nbrOfExecutionsToJoin)
            {
                Debug.WriteLine("parallel gateway '" + activity.Id + "' activates: " + nbrOfExecutionsJoined + " of " + nbrOfExecutionsToJoin + " joined");
                execution.LeaveActivityViaTransitions(outgoingTransitions, joinedExecutions);
            }
        }
Ejemplo n.º 4
0
        public override void Execute(IActivityExecution execution)
        {
            // Join
            var activity            = execution.Activity;
            var outgoingTransitions = execution.Activity.OutgoingTransitions;

            execution.InActivate();
            LockConcurrentRoot(execution);

            var joinedExecutions      = execution.FindInactiveConcurrentExecutions(activity);
            var nbrOfExecutionsToJoin = execution.Activity.IncomingTransitions.Count;
            var nbrOfExecutionsJoined = joinedExecutions.Count;

            if (nbrOfExecutionsJoined == nbrOfExecutionsToJoin)
            {
                // Fork
                Log.ActivityActivation(activity.Id, nbrOfExecutionsJoined, nbrOfExecutionsToJoin);
                execution.LeaveActivityViaTransitions(outgoingTransitions, joinedExecutions);
            }
            else
            {
                Log.NoActivityActivation(activity.Id, nbrOfExecutionsJoined, nbrOfExecutionsToJoin);
            }
        }
Ejemplo n.º 5
0
        public void Completed(IActivityExecution execution)
        {
            var outgoingTransitions = (List <IPvmTransition>)execution.Activity.OutgoingTransitions;

            execution.LeaveActivityViaTransitions(outgoingTransitions, null);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Actual implementation of leaving an activity.
        /// </summary>
        /// <param name="execution">
        ///     The current execution context
        /// </param>
        /// <param name="checkConditions">
        ///     Whether or not to check conditions before determining whether or
        ///     not to take a transition.
        /// </param>
        /// <param name="throwExceptionIfExecutionStuck">
        ///     If true, an <seealso cref="ProcessEngineException" /> will be thrown in case no
        ///     transition could be found to leave the activity.
        /// </param>
        protected internal virtual void PerformOutgoingBehavior(IActivityExecution execution, bool checkConditions,
                                                                bool throwExceptionIfExecutionStuck, IList <IActivityExecution> reusableExecutions)
        {
            Log.LeavingActivity(execution.Activity.Id);

            var defaultSequenceFlow = (string)execution.Activity.GetProperty("default");
            IList <IPvmTransition> transitionsToTake = new List <IPvmTransition>();

            IList <IPvmTransition> outgoingTransitions = execution.Activity.OutgoingTransitions;

            foreach (IPvmTransition outgoingTransition in outgoingTransitions)
            {
                if (defaultSequenceFlow == null || outgoingTransition.Id != defaultSequenceFlow)
                {
                    var condition = (ICondition)outgoingTransition.GetProperty(BpmnParse.PropertynameCondition);
                    if ((condition == null) || !checkConditions || condition.Evaluate(execution))
                    {
                        transitionsToTake.Add(outgoingTransition);
                    }
                }
            }

            if (transitionsToTake.Count == 1)
            {
                execution.LeaveActivityViaTransition(transitionsToTake.ElementAt(0));
            }
            else if (transitionsToTake.Count >= 1)
            {
                if (reusableExecutions == null || reusableExecutions.Count == 0)
                {
                    execution.LeaveActivityViaTransitions(transitionsToTake, new List <IActivityExecution>()
                    {
                        execution
                    });
                }
                else
                {
                    execution.LeaveActivityViaTransitions(transitionsToTake, reusableExecutions);
                }
            }
            else
            {
                //if (!ReferenceEquals(defaultSequenceFlow, null))
                if (!string.IsNullOrEmpty(defaultSequenceFlow))
                {
                    var defaultTransition = execution.Activity.FindOutgoingTransition(defaultSequenceFlow);
                    if (defaultTransition != null)
                    {
                        execution.LeaveActivityViaTransition(defaultTransition);
                    }
                    else
                    {
                        throw Log.MissingDefaultFlowException(execution.Activity.Id, defaultSequenceFlow);
                    }
                }
                else if (outgoingTransitions.Count > 0)
                {
                    throw Log.MissingConditionalFlowException(execution.Activity.Id);
                }
                else
                {
                    if (((ActivityImpl)execution.Activity).CompensationHandler &&
                        IsAncestorCompensationThrowing(execution))
                    {
                        execution.EndCompensation();
                    }
                    else
                    {
                        Log.MissingOutgoingSequenceFlow(execution.Activity.Id);
                        execution.End(true);

                        if (throwExceptionIfExecutionStuck)
                        {
                            throw Log.StuckExecutionException(execution.Activity.Id);
                        }
                    }
                }
            }
        }