Example #1
0
        protected internal virtual IList <CorrelationHandlerResult> CorrelateStartMessageByEventSubscription(
            CommandContext commandContext, string messageName, CorrelationSet correlationSet)
        {
            IList <CorrelationHandlerResult> results = new List <CorrelationHandlerResult>();
            DeploymentCache deploymentCache          = commandContext.ProcessEngineConfiguration.DeploymentCache;

            var messageEventSubscriptions = FindMessageStartEventSubscriptions(commandContext, messageName,
                                                                               correlationSet);

            foreach (var messageEventSubscription in messageEventSubscriptions)
            {
                if (messageEventSubscription.Configuration != null)
                {
                    var processDefinitionId = messageEventSubscription.Configuration;
                    ProcessDefinitionEntity processDefinition = deploymentCache.FindDeployedProcessDefinitionById(processDefinitionId);
                    // only an active process definition will be returned
                    if (processDefinition != null && !processDefinition.Suspended)
                    {
                        CorrelationHandlerResult result = CorrelationHandlerResult.MatchedProcessDefinition(processDefinition, messageEventSubscription.ActivityId);
                        results.Add(result);
                    }
                    else
                    {
                        Log.CouldNotFindProcessDefinitionForEventSubscription(messageEventSubscription, processDefinitionId);
                    }
                }
            }
            return(results);
        }
        public static CorrelationHandlerResult MatchedExecution(ExecutionEntity executionEntity)
        {
            var messageCorrelationResult = new CorrelationHandlerResult();

            messageCorrelationResult.resultType      = MessageCorrelationResultType.Execution;
            messageCorrelationResult.executionEntity = executionEntity;
            return(messageCorrelationResult);
        }
        public static CorrelationHandlerResult MatchedProcessDefinition(ProcessDefinitionEntity processDefinitionEntity,
                                                                        string startEventActivityId)
        {
            var messageCorrelationResult = new CorrelationHandlerResult();

            messageCorrelationResult.processDefinitionEntity = processDefinitionEntity;
            messageCorrelationResult.startEventActivityId    = startEventActivityId;
            messageCorrelationResult.resultType = MessageCorrelationResultType.ProcessDefinition;
            return(messageCorrelationResult);
        }
Example #4
0
        protected internal virtual CorrelationHandlerResult CorrelateStartMessageByProcessDefinitionId(
            CommandContext commandContext, string messageName, string processDefinitionId)
        {
            DeploymentCache         deploymentCache   = commandContext.ProcessEngineConfiguration.DeploymentCache;
            ProcessDefinitionEntity processDefinition = deploymentCache.FindDeployedProcessDefinitionById(processDefinitionId);

            //only an active process definition will be returned
            if (processDefinition != null && !processDefinition.Suspended)
            {
                string startActivityId = FindStartActivityIdByMessage(processDefinition, messageName);
                if (!string.ReferenceEquals(startActivityId, null))
                {
                    return(CorrelationHandlerResult.MatchedProcessDefinition(processDefinition, startActivityId));
                }
            }
            return(null);
        }
Example #5
0
 public MessageCorrelationResultImpl(CorrelationHandlerResult handlerResult)
 {
     execution  = handlerResult.Execution;
     resultType = handlerResult.ResultType;
 }
Example #6
0
        //Correlate联系; 使互相关联; 相关物; 相关联的人; 相关的; 相应特点的
        protected internal virtual IList <CorrelationHandlerResult> CorrelateMessageToExecutions(
            CommandContext commandContext, string messageName, CorrelationSet correlationSet)
        {
            //TODO 复杂查询可能有误
            //var query = new ExecutionQueryImpl();
            var exp             = commandContext.ExecutionManager.Find((t) => true);
            var correlationKeys = correlationSet.CorrelationKeys;

            if (correlationKeys != null)
            {
                foreach (var correlationKey in correlationKeys)
                {
                    //query.ProcessVariableValueEquals(correlationKey.Key, correlationKey.Value);
                    ProcessVariableValueEquals(correlationKey.Key, correlationKey.Value);
                }
            }


            var localCorrelationKeys = correlationSet.LocalCorrelationKeys;

            if (localCorrelationKeys != null)
            {
                foreach (var correlationKey in localCorrelationKeys)
                {
                    //query.VariableValueEquals(correlationKey.Key, correlationKey.Value);
                    throw new NotImplementedException();
                }
            }


            var businessKey = correlationSet.BusinessKey;

            if (!ReferenceEquals(businessKey, null))
            {
                //query.ProcessInstanceBusinessKey(businessKey);
                exp.Where(m => m.BusinessKey == businessKey);
            }


            var processInstanceId = correlationSet.ProcessInstanceId;

            if (!ReferenceEquals(processInstanceId, null))
            {
                //query.processInstanceId(processInstanceId);
                exp.Where(m => m.ProcessInstanceId == processInstanceId);
            }


            if (!ReferenceEquals(messageName, null))
            {
                //query.MessageEventSubscriptionName(messageName);
                //exp= exp.Where(m => m.EventName == messageName);
                exp = from a in exp
                      join b in commandContext.GetDbEntityManager <EventSubscriptionEntity>().Find(m => m.EventType == "message" && m.EventName == messageName) on a.Id equals b.ExecutionId
                      select a;
            }
            else
            {
                //query.MessageEventSubscription();
                throw new NotImplementedException();
            }

            if (correlationSet.IsTenantIdSet)
            {
                var tenantId = correlationSet.TenantId;
                if (!ReferenceEquals(tenantId, null))
                {
                    //query.TenantIdIn(tenantId);
                    exp = exp.Where(m => m.TenantId == tenantId);
                }

                else
                {
                    //query.WithoutTenantId();
                    exp = exp.Where(m => m.TenantId == null);
                }
            }

            //// restrict to active executions
            //query.Active();
            exp.Where(m => m.SuspensionState == SuspensionStateFields.Active.StateCode);
            //var matchingExecutions = query.EvaluateExpressionsAndExecuteList(commandContext, null);
            var matchingExecutions = exp.ToList();
            IList <CorrelationHandlerResult> result = new List <CorrelationHandlerResult>(/*matchingExecutions.Count*/);

            foreach (var matchingExecution in matchingExecutions)
            {
                var correlationResult = CorrelationHandlerResult.MatchedExecution(matchingExecution);
                result.Add(correlationResult);
            }
            return(result);
        }