Exemple #1
0
        private void NextStepCompletionCallback(IRunState context, ActivityImplementationBase completedInstance, EntityRef exitPointRef)
        {
            var childActivity = ((ActivityImplementationBase)completedInstance).ActivityInstance;

            var transition = context.Metadata.GetTransitionForExitPoint(childActivity, exitPointRef);

            if (transition != null)
            {
                if (NeedToSuspend(context))
                {
                    MarkRunSuspended(context, childActivity);
                }
                else
                {
                    var nextActivity = transition.ToActivity;
                    context.ExitPointId = null;
                    ScheduleNextStep(context, nextActivity);
                }
            }
            else
            {
                Termination termination;

                try
                {
                    termination =
                        _activityInstanceAsWf.Terminations.Single(
                            t => t.FromActivity.Id == childActivity.Id && t.FromExitPoint.Id == exitPointRef.Id);
                }
                catch (InvalidOperationException err)
                {
                    throw new WorkflowRunException(string.Format("There should be only one valid termination found for the given activity and exit point. \nWorkflow: {0} \n Last activity: {1}", _activityInstanceAsWf.GetIdString(), childActivity.Name ?? "(Unnamed)"), err);
                }

                context.ExitPointId = termination.WorkflowExitPoint;

                MarkRunCompleted(context);

                context.FlushInternalArgs();
            }
        }
Exemple #2
0
        private WorkflowRun ProcessWorkflowInContext(WorkflowRun run, IWorkflowEvent wfEvent)
        {
            var workflow = run.WorkflowBeingRun;

            using (Profiler.Measure("WorkflowRunner.Instance.StartWorkflowInContext " + workflow.Id))
            {
                var stopWatch = StartWorkflowTimer();

                IRunState runState = null;

                try
                {
                    if (!run.IsTemporaryId)
                    {
                        PrecacheWorkflow(run.Id);
                    }

                    using (new SecurityBypassContext())
                    {
                        var metadata = MetadataFactory.Create(workflow);

                        runState = CreateRunState(metadata, run);

                        if (runState.EffectiveSecurityContext == null)
                        {
                            throw new WorkflowMissingOwnerException();
                        }
                    }

                    // Wrap a Security bypass with the effective context. This less us "Pop" to run as the effective context.
                    using (CustomContext.SetContext(runState.EffectiveSecurityContext))
                    {
                        using (new SecurityBypassContext())
                        {
                            if (runState.Metadata.HasViolations)
                            {
                                MarkRunFailedHasErrors(runState);
                            }
                            else if (run.TriggerDepth > WorkflowTriggerHelper.MaxTriggerDepth)
                            {
                                MarkRunFailedTriggerDepth(runState);
                            }
                            else
                            {
                                var isCompleted = ProcessWorkflow(workflow, runState, wfEvent);
                            }
                        }
                    }
                }
                catch (WorkflowRunException ex)
                {
                    MarkRunFailed(runState, ex);

                    if (runState != null)
                    {
                        runState.FlushInternalArgs();
                    }
                }
                catch (Exception ex)
                {
                    MarkRunInternalError(runState, ex);

                    if (runState != null)
                    {
                        runState.FlushInternalArgs();
                    }
                }
                finally
                {
                    if (!Factory.WorkflowRunTaskManager.HasCancelled(runState.RunTaskId))
                    {
                        run = FinalizeRun(runState);
                    }
                }

                EndWorkflowTimer(stopWatch);
            }

            return(run);
        }