예제 #1
0
        // CREATE METHODS

        public virtual IExecutionEntity CreateProcessInstanceExecution(IProcessDefinition processDefinition, string businessKey, string tenantId, string initiatorVariableName)
        {
            IExecutionEntity processInstanceExecution = executionDataManager.Create();

            if (ExecutionRelatedEntityCountEnabledGlobally)
            {
                ((ICountingExecutionEntity)processInstanceExecution).IsCountEnabled = true;
            }

            processInstanceExecution.ProcessDefinitionId      = processDefinition.Id;
            processInstanceExecution.ProcessDefinitionKey     = processDefinition.Key;
            processInstanceExecution.ProcessDefinitionName    = processDefinition.Name;
            processInstanceExecution.ProcessDefinitionVersion = processDefinition.Version;
            processInstanceExecution.BusinessKey = businessKey;
            processInstanceExecution.IsScope     = true; // process instance is always a scope for all child executions

            // Inherit tenant id (if any)
            if (tenantId is object)
            {
                processInstanceExecution.TenantId = tenantId;
            }

            string authenticatedUserId = Authentication.AuthenticatedUser.Id;

            processInstanceExecution.StartTime   = Context.ProcessEngineConfiguration.Clock.CurrentTime;
            processInstanceExecution.StartUserId = authenticatedUserId;
            processInstanceExecution.StartUser   = Authentication.AuthenticatedUser.FullName;

            // Store in database
            Insert(processInstanceExecution, false);

            if (string.IsNullOrWhiteSpace(processInstanceExecution.StartUserId) == false)
            {
                IUserInfo                 starter           = null;
                IUserServiceProxy         userService       = ProcessEngineServiceProvider.Resolve <IUserServiceProxy>();
                ExternalConnectorProvider externalConnector = ProcessEngineServiceProvider.Resolve <ExternalConnectorProvider>();

                starter = new UserInfo
                {
                    Id       = processInstanceExecution.StartUserId,
                    FullName = processInstanceExecution.StartUserId
                };
                //TODO: 考虑性能问题,暂时不要获取人员信息
                //try
                //{
                //    starter = AsyncHelper.RunSync<IUserInfo>(() => userService.GetUser(processInstanceExecution.StartUserId));
                //    starter.TenantId = processInstanceExecution.TenantId;
                //}
                //catch (Exception ex)
                //{
                //    logger.LogError(ex, ex.Message);
                //    starter = new UserInfo
                //    {
                //        Id = processInstanceExecution.StartUserId,
                //        FullName = processInstanceExecution.StartUserId
                //    };
                //}

                //保存调用用户变量
                processInstanceExecution.SetVariable(processInstanceExecution.StartUserId, starter);
            }

            if (initiatorVariableName is object)
            {
                processInstanceExecution.SetVariable(initiatorVariableName, authenticatedUserId);
            }

            // Need to be after insert, cause we need the id
            processInstanceExecution.ProcessInstanceId     = processInstanceExecution.Id;
            processInstanceExecution.RootProcessInstanceId = processInstanceExecution.Id;
            //TODO: 当没有用户任务的时候,添加identity会报错
            if (authenticatedUserId is object)
            {
                IdentityLinkEntityManager.AddIdentityLink(processInstanceExecution, authenticatedUserId, null, IdentityLinkType.STARTER);
            }

            // Fire events
            if (EventDispatcher.Enabled)
            {
                EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_CREATED, processInstanceExecution));
            }

            return(processInstanceExecution);
        }
예제 #2
0
        // CREATE METHODS
        /// <summary>
        ///
        /// </summary>
        /// <param name="processDefinition"></param>
        /// <param name="businessKey"></param>
        /// <param name="tenantId"></param>
        /// <param name="initiatorVariableName"></param>
        /// <returns></returns>
        public virtual IExecutionEntity CreateProcessInstanceExecution(IProcessDefinition processDefinition, string businessKey, string tenantId, string initiatorVariableName)
        {
            IExecutionEntity processInstanceExecution = executionDataManager.Create();

            if (ExecutionRelatedEntityCountEnabledGlobally)
            {
                ((ICountingExecutionEntity)processInstanceExecution).IsCountEnabled = true;
            }

            processInstanceExecution.ProcessDefinitionId      = processDefinition.Id;
            processInstanceExecution.ProcessDefinitionKey     = processDefinition.Key;
            processInstanceExecution.ProcessDefinitionName    = processDefinition.Name;
            processInstanceExecution.ProcessDefinitionVersion = processDefinition.Version;
            processInstanceExecution.BusinessKey = businessKey;
            processInstanceExecution.IsScope     = true; // process instance is always a scope for all child executions

            // Inherit tenant id (if any)
            if (tenantId is object)
            {
                processInstanceExecution.TenantId = tenantId;
            }

            string authenticatedUserId = Authentication.AuthenticatedUser.Id;

            processInstanceExecution.StartTime   = Context.ProcessEngineConfiguration.Clock.CurrentTime;
            processInstanceExecution.StartUserId = authenticatedUserId;

            // Store in database
            Insert(processInstanceExecution, false);

            IUserInfo starter = null;

            if (string.IsNullOrWhiteSpace(authenticatedUserId) == false)
            {
                starter = GetUser(processInstanceExecution, authenticatedUserId);

                //保存调用用户变量
                processInstanceExecution.SetVariable(processInstanceExecution.StartUserId, starter);
            }
            processInstanceExecution.StartUser = starter.FullName;

            if (initiatorVariableName is object)
            {
                processInstanceExecution.SetVariable(initiatorVariableName, authenticatedUserId);
            }

            // Need to be after insert, cause we need the id
            processInstanceExecution.ProcessInstanceId     = processInstanceExecution.Id;
            processInstanceExecution.RootProcessInstanceId = processInstanceExecution.Id;
            //TODO: 当没有用户任务的时候,添加identity会报错
            if (authenticatedUserId is object)
            {
                IdentityLinkEntityManager.AddIdentityLink(processInstanceExecution, authenticatedUserId, null, IdentityLinkType.STARTER);
            }

            // Fire events
            if (EventDispatcher.Enabled)
            {
                EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_CREATED, processInstanceExecution));
            }

            return(processInstanceExecution);
        }