Пример #1
0
            protected internal virtual ActivityInstanceTreeBuilder Id(string expectedActivityInstanceId)
            {
                ActivityInstanceImpl activityInstanceImpl = ActivityInstanceStack.Peek();

                activityInstanceImpl.Id = expectedActivityInstanceId;
                return(this);
            }
Пример #2
0
        protected internal virtual void PopulateChildInstances(IDictionary <string, ActivityInstanceImpl> activityInstances, IDictionary <string, TransitionInstanceImpl> transitionInstances)
        {
            IDictionary <ActivityInstanceImpl, IList <ActivityInstanceImpl> >   childActivityInstances   = new Dictionary <ActivityInstanceImpl, IList <ActivityInstanceImpl> >();
            IDictionary <ActivityInstanceImpl, IList <TransitionInstanceImpl> > childTransitionInstances = new Dictionary <ActivityInstanceImpl, IList <TransitionInstanceImpl> >();

            foreach (ActivityInstanceImpl instance in activityInstances.Values)
            {
                if (!string.IsNullOrEmpty(instance.ParentActivityInstanceId))
                {
                    ActivityInstanceImpl parentInstance = activityInstances.GetValueOrNull(instance.ParentActivityInstanceId);
                    if (parentInstance == null)
                    {
                        throw new ProcessEngineException("No parent activity instance with id " + instance.ParentActivityInstanceId + " generated");
                    }
                    PutListElement(childActivityInstances, parentInstance, instance);
                }
            }

            foreach (TransitionInstanceImpl instance in transitionInstances.Values)
            {
                if (!string.IsNullOrEmpty(instance.ParentActivityInstanceId))
                {
                    ActivityInstanceImpl parentInstance = activityInstances.GetValueOrNull(instance.ParentActivityInstanceId);
                    if (parentInstance == null)
                    {
                        throw new ProcessEngineException("No parent activity instance with id " + instance.ParentActivityInstanceId + " generated");
                    }
                    PutListElement(childTransitionInstances, parentInstance, instance);
                }
            }

            foreach (KeyValuePair <ActivityInstanceImpl, IList <ActivityInstanceImpl> > entry in childActivityInstances)
            {
                ActivityInstanceImpl         instance       = entry.Key;
                IList <ActivityInstanceImpl> childInstances = entry.Value;
                if (childInstances != null)
                {
                    instance.ChildActivityInstances = childInstances.ToArray();
                }
            }

            foreach (KeyValuePair <ActivityInstanceImpl, IList <TransitionInstanceImpl> > entry in childTransitionInstances)
            {
                ActivityInstanceImpl           instance       = entry.Key;
                IList <TransitionInstanceImpl> childInstances = entry.Value;
                if (childTransitionInstances != null)
                {
                    instance.ChildTransitionInstances = childInstances.ToArray();
                }
            }
        }
Пример #3
0
            public virtual ActivityInstanceTreeBuilder Transition(string activityId)
            {
                TransitionInstanceImpl newInstance = new TransitionInstanceImpl();

                newInstance.ActivityId = activityId;
                ActivityInstanceImpl parentInstance = ActivityInstanceStack.Peek();

                IList <ITransitionInstance> childInstances = new List <ITransitionInstance>((parentInstance.ChildTransitionInstances));

                childInstances.Add(newInstance);
                parentInstance.ChildTransitionInstances = childInstances.ToArray();

                return(this);
            }
Пример #4
0
            public virtual ActivityInstanceTreeBuilder BeginScope(string activityId, string activityInstanceId)
            {
                ActivityInstanceImpl newInstance = new ActivityInstanceImpl();

                newInstance.ActivityId = activityId;
                newInstance.Id         = activityInstanceId;

                ActivityInstanceImpl      parentInstance = ActivityInstanceStack.Peek();
                IList <IActivityInstance> childInstances = new List <IActivityInstance>((parentInstance.ChildActivityInstances));

                childInstances.Add(newInstance);
                parentInstance.ChildActivityInstances = childInstances.ToArray();

                ActivityInstanceStack.Push(newInstance);

                return(this);
            }
Пример #5
0
        static AbstractRestServiceTest()
        {
            EXAMPLE_VARIABLES.putValueTyped(EXAMPLE_VARIABLE_KEY, EXAMPLE_VARIABLE_VALUE);
            EXAMPLE_VARIABLES_WITH_NULL_VALUE.putValueTyped(EXAMPLE_ANOTHER_VARIABLE_KEY, Variables.untypedNullValue());
            ActivityInstanceImpl instance = (ActivityInstanceImpl)EXAMPLE_ACTIVITY_INSTANCE;

            instance.Id = EXAMPLE_ACTIVITY_INSTANCE_ID;
            instance.ParentActivityInstanceId = EXAMPLE_PARENT_ACTIVITY_INSTANCE_ID;
            instance.ActivityId          = EXAMPLE_ACTIVITY_ID;
            instance.ActivityType        = CHILD_EXAMPLE_ACTIVITY_TYPE;
            instance.ActivityName        = EXAMPLE_ACTIVITY_NAME;
            instance.ProcessInstanceId   = EXAMPLE_PROCESS_INSTANCE_ID;
            instance.ProcessDefinitionId = EXAMPLE_PROCESS_DEFINITION_ID;
            instance.BusinessKey         = EXAMPLE_BUSINESS_KEY;
            instance.ExecutionIds        = new string[] { EXAMPLE_EXECUTION_ID };

            ActivityInstanceImpl childActivity = new ActivityInstanceImpl();

            childActivity.Id = CHILD_EXAMPLE_ACTIVITY_INSTANCE_ID;
            childActivity.ParentActivityInstanceId = CHILD_EXAMPLE_PARENT_ACTIVITY_INSTANCE_ID;
            childActivity.ActivityId               = CHILD_EXAMPLE_ACTIVITY_ID;
            childActivity.ActivityName             = CHILD_EXAMPLE_ACTIVITY_NAME;
            childActivity.ActivityType             = CHILD_EXAMPLE_ACTIVITY_TYPE;
            childActivity.ProcessInstanceId        = CHILD_EXAMPLE_PROCESS_INSTANCE_ID;
            childActivity.ProcessDefinitionId      = CHILD_EXAMPLE_PROCESS_DEFINITION_ID;
            childActivity.BusinessKey              = CHILD_EXAMPLE_BUSINESS_KEY;
            childActivity.ExecutionIds             = new string[] { EXAMPLE_EXECUTION_ID };
            childActivity.ChildActivityInstances   = new ActivityInstance[0];
            childActivity.ChildTransitionInstances = new TransitionInstance[0];

            TransitionInstanceImpl childTransition = new TransitionInstanceImpl();

            childTransition.Id = CHILD_EXAMPLE_ACTIVITY_INSTANCE_ID;
            childTransition.ParentActivityInstanceId = CHILD_EXAMPLE_PARENT_ACTIVITY_INSTANCE_ID;
            childTransition.ActivityId          = CHILD_EXAMPLE_ACTIVITY_ID;
            childTransition.ActivityName        = CHILD_EXAMPLE_ACTIVITY_NAME;
            childTransition.ActivityType        = CHILD_EXAMPLE_ACTIVITY_TYPE;
            childTransition.ProcessInstanceId   = CHILD_EXAMPLE_PROCESS_INSTANCE_ID;
            childTransition.ProcessDefinitionId = CHILD_EXAMPLE_PROCESS_DEFINITION_ID;
            childTransition.ExecutionId         = EXAMPLE_EXECUTION_ID;

            instance.ChildActivityInstances   = new ActivityInstance[] { childActivity };
            instance.ChildTransitionInstances = new TransitionInstance[] { childTransition };
        }
Пример #6
0
        protected internal virtual ActivityInstanceImpl CreateActivityInstance(PvmExecutionImpl scopeExecution, ScopeImpl scope, string activityInstanceId, string parentActivityInstanceId)
        {
            ActivityInstanceImpl actInst = new ActivityInstanceImpl();

            actInst.Id = activityInstanceId;
            actInst.ParentActivityInstanceId = parentActivityInstanceId;
            actInst.ProcessInstanceId        = scopeExecution.ProcessInstanceId;
            actInst.ProcessDefinitionId      = scopeExecution.ProcessDefinitionId;
            actInst.BusinessKey = scopeExecution.BusinessKey;
            actInst.ActivityId  = scope.Id;

            string name = scope.Name;

            if (string.IsNullOrEmpty(name))
            {
                name = (string)scope.GetProperty("name");
            }
            actInst.ActivityName = name;

            if (scope.Id.Equals(scopeExecution.ProcessDefinition.Id))
            {
                actInst.ActivityType = "processDefinition";
            }
            else
            {
                actInst.ActivityType = (string)scope.GetProperty("type");
            }

            IList <string> executionIds = new List <string>();

            executionIds.Add(scopeExecution.Id);

            foreach (PvmExecutionImpl childExecution in scopeExecution.NonEventScopeExecutions)
            {
                // add all concurrent children that are not in an activity
                if (childExecution.IsConcurrent && string.IsNullOrEmpty(childExecution.ActivityId))
                {
                    executionIds.Add(childExecution.Id);
                }
            }
            actInst.ExecutionIds = executionIds.ToArray();

            return(actInst);
        }
Пример #7
0
 public ActivityInstanceTreeBuilder(string rootActivityId)
 {
     RootInstance            = new ActivityInstanceImpl();
     RootInstance.ActivityId = rootActivityId;
     ActivityInstanceStack.Push(RootInstance);
 }
Пример #8
0
        public virtual IActivityInstance Execute(CommandContext commandContext)
        {
            EnsureUtil.EnsureNotNull("processInstanceId", ProcessInstanceId);
            IList <ExecutionEntity> executionList = LoadProcessInstance(ProcessInstanceId, commandContext);

            if (executionList.Count == 0)
            {
                return(null);
            }

            CheckGetActivityInstance(ProcessInstanceId, commandContext);

            IList <ExecutionEntity> nonEventScopeExecutions = FilterNonEventScopeExecutions(executionList);
            IList <ExecutionEntity> leaves = FilterLeaves(nonEventScopeExecutions);//.OrderBy(m => m.Id).ToList();

            // Leaves must be ordered in a predictable way (e.g. by ID)
            // in order to return a stable execution tree with every repeated invocation of this command.
            // For legacy process instances, there may miss scope executions for activities that are now a scope.
            // In this situation, there may be multiple scope candidates for the same instance id; which one
            // can depend on the order the leaves are iterated.
            OrderById(leaves);

            ExecutionEntity processInstance = FilterProcessInstance(executionList);

            if (processInstance.IsEnded)
            {
                return(null);
            }

            //create act instance for process instance

            ActivityInstanceImpl processActInst = CreateActivityInstance(processInstance, processInstance.ProcessDefinition, ProcessInstanceId, null);
            IDictionary <string, ActivityInstanceImpl> activityInstances = new Dictionary <string, ActivityInstanceImpl>();

            activityInstances[ProcessInstanceId] = processActInst;

            IDictionary <string, TransitionInstanceImpl> transitionInstances = new Dictionary <string, TransitionInstanceImpl>();

            foreach (ExecutionEntity leaf in leaves)
            {
                // skip leafs without activity, e.g. if only the process instance exists after cancellation
                // it will not have an activity set
                if (leaf.Activity == null)
                {
                    continue;
                }

                IDictionary <ScopeImpl, PvmExecutionImpl> activityExecutionMapping = leaf.CreateActivityExecutionMapping();
                IDictionary <ScopeImpl, PvmExecutionImpl> scopeInstancesToCreate   = new Dictionary <ScopeImpl, PvmExecutionImpl>(activityExecutionMapping);

                // create an activity/transition instance for each leaf that executes a non-scope activity
                // and does not throw compensation
                if (leaf.ActivityInstanceId != null)
                {
                    if (!CompensationBehavior.IsCompensationThrowing(leaf) || LegacyBehavior.IsCompensationThrowing(leaf, activityExecutionMapping))
                    {
                        string parentActivityInstanceId = null;

                        parentActivityInstanceId = activityExecutionMapping[leaf.Activity.FlowScope].ParentActivityInstanceId;

                        ActivityInstanceImpl leafInstance = CreateActivityInstance(leaf, (ScopeImpl)leaf.Activity, leaf.ActivityInstanceId, parentActivityInstanceId);
                        activityInstances[leafInstance.Id] = leafInstance;

                        scopeInstancesToCreate.Remove((ScopeImpl)leaf.Activity);
                    }
                }
                else
                {
                    TransitionInstanceImpl transitionInstance = CreateTransitionInstance(leaf);
                    transitionInstances[transitionInstance.Id] = transitionInstance;

                    scopeInstancesToCreate.Remove((ScopeImpl)leaf.Activity);
                }

                LegacyBehavior.RemoveLegacyNonScopesFromMapping(scopeInstancesToCreate);
                scopeInstancesToCreate.Remove(leaf.ProcessDefinition);

                // create an activity instance for each scope (including compensation throwing executions)
                foreach (KeyValuePair <ScopeImpl, PvmExecutionImpl> scopeExecutionEntry in scopeInstancesToCreate)
                {
                    ScopeImpl        scope          = scopeExecutionEntry.Key;
                    PvmExecutionImpl scopeExecution = scopeExecutionEntry.Value;

                    string activityInstanceId       = null;
                    string parentActivityInstanceId = null;

                    activityInstanceId       = scopeExecution.ParentActivityInstanceId;
                    parentActivityInstanceId = activityExecutionMapping[scope.FlowScope].ParentActivityInstanceId;

                    if (activityInstances.ContainsKey(activityInstanceId))
                    {
                        continue;
                    }
                    else
                    {
                        // regardless of the tree structure (compacted or not), the scope's activity instance id
                        // is the activity instance id of the parent execution and the parent activity instance id
                        // of that is the actual parent activity instance id
                        ActivityInstanceImpl scopeInstance = CreateActivityInstance(scopeExecution, scope, activityInstanceId, parentActivityInstanceId);
                        activityInstances[activityInstanceId] = scopeInstance;
                    }
                }
            }

            LegacyBehavior.RepairParentRelationships(activityInstances.Values, ProcessInstanceId);
            PopulateChildInstances(activityInstances, transitionInstances);

            return(processActInst);
        }