///<inheritdoc />
        public virtual IProcessInstance Execute(ICommandContext commandContext)
        {
            if (messageName is null)
            {
                throw new ActivitiIllegalArgumentException("Cannot start process instance by message: message name is null");
            }

            IMessageEventSubscriptionEntity messageEventSubscription = commandContext.EventSubscriptionEntityManager.FindMessageStartEventSubscriptionByName(messageName, tenantId);

            if (messageEventSubscription == null)
            {
                throw new ActivitiObjectNotFoundException("Cannot start process instance by message: no subscription to message with name '" + messageName + "' found.", typeof(IMessageEventSubscriptionEntity));
            }

            string processDefinitionId = messageEventSubscription.Configuration;

            if (string.IsNullOrWhiteSpace(processDefinitionId))
            {
                throw new ActivitiException("Cannot start process instance by message: subscription to message with name '" + messageName + "' is not a message start event.");
            }

            DeploymentManager deploymentCache = commandContext.ProcessEngineConfiguration.DeploymentManager;

            IProcessDefinition processDefinition = deploymentCache.FindDeployedProcessDefinitionById(processDefinitionId);

            if (processDefinition == null)
            {
                throw new ActivitiObjectNotFoundException("No process definition found for id '" + processDefinitionId + "'", typeof(IProcessDefinition));
            }

            ProcessInstanceHelper processInstanceHelper = commandContext.ProcessEngineConfiguration.ProcessInstanceHelper;
            IProcessInstance      processInstance       = processInstanceHelper.CreateAndStartProcessInstanceByMessage(processDefinition, messageName, processVariables, transientVariables);

            return(processInstance);
        }
예제 #2
0
        public virtual IProcessInstance Execute(ICommandContext commandContext)
        {
            DeploymentManager deploymentCache = commandContext.ProcessEngineConfiguration.DeploymentManager;

            IProcessDefinition processDefinition = deploymentCache.FindDeployedProcessDefinitionById(processDefinitionId);

            if (processDefinition == null)
            {
                throw new ActivitiObjectNotFoundException("No process definition found for id '" + processDefinitionId + "'", typeof(IProcessDefinition));
            }

            ProcessInstanceHelper processInstanceHelper = commandContext.ProcessEngineConfiguration.ProcessInstanceHelper;

            // Get model from cache
            Process process = ProcessDefinitionUtil.GetProcess(processDefinition.Id);

            if (process == null)
            {
                throw new ActivitiException("Cannot start process instance. Process model " + processDefinition.Name + " (id = " + processDefinition.Id + ") could not be found");
            }

            FlowElement initialFlowElement = process.FlowElements.FirstOrDefault(x => x.Id == activityId);

            IProcessInstance processInstance = processInstanceHelper.CreateAndStartProcessInstanceWithInitialFlowElement(processDefinition, businessKey, processInstanceName, initialFlowElement, process, processVariables, transientVariables, startProcessInstance);

            return(processInstance);
        }
예제 #3
0
        public virtual void Execute(IJobEntity job, string configuration, IExecutionEntity execution, ICommandContext commandContext)
        {
            IProcessDefinitionEntity processDefinitionEntity = ProcessDefinitionUtil.GetProcessDefinitionFromDatabase(job.ProcessDefinitionId); // From DB -> need to get latest suspended state

            if (processDefinitionEntity == null)
            {
                throw new ActivitiException("Could not find process definition needed for timer start event");
            }

            try
            {
                if (!processDefinitionEntity.Suspended)
                {
                    if (commandContext.EventDispatcher.Enabled)
                    {
                        commandContext.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.TIMER_FIRED, job));
                    }

                    // Find initial flow element matching the signal start event
                    Process process    = ProcessDefinitionUtil.GetProcess(job.ProcessDefinitionId);
                    string  activityId = GetActivityIdFromConfiguration(configuration);
                    if (string.IsNullOrWhiteSpace(activityId) == false)
                    {
                        FlowElement flowElement = process.GetFlowElement(activityId, true);
                        if (flowElement == null)
                        {
                            throw new ActivitiException("Could not find matching FlowElement for activityId " + activityId);
                        }
                        ProcessInstanceHelper processInstanceHelper = commandContext.ProcessEngineConfiguration.ProcessInstanceHelper;
                        processInstanceHelper.CreateAndStartProcessInstanceWithInitialFlowElement(processDefinitionEntity, null, null, flowElement, process, null, null, true);
                    }
                    else
                    {
                        (new StartProcessInstanceCmd(processDefinitionEntity.Key, null, null, null, job.TenantId)).Execute(commandContext);
                    }
                }
                else
                {
                    log.LogDebug($"ignoring timer of suspended process definition {processDefinitionEntity.Name}");
                }
            }
            catch (Exception e)
            {
                log.LogError($"exception during timer execution: {e.Message}");

                throw new ActivitiException("exception during timer execution: " + e.Message, e);
            }
        }
예제 #4
0
        public override void HandleEvent(IEventSubscriptionEntity eventSubscription, object payload, ICommandContext commandContext)
        {
            if (eventSubscription.ExecutionId is object)
            {
                base.HandleEvent(eventSubscription, payload, commandContext);
            }
            else if (eventSubscription.ProcessDefinitionId is object)
            {
                // Find initial flow element matching the signal start event
                string             processDefinitionId = eventSubscription.ProcessDefinitionId;
                IProcessDefinition processDefinition   = ProcessDefinitionUtil.GetProcessDefinition(processDefinitionId);

                if (processDefinition == null)
                {
                    throw new ActivitiObjectNotFoundException("No process definition found for id '" + processDefinitionId + "'", typeof(IProcessDefinition));
                }

                if (processDefinition.Suspended)
                {
                    throw new ActivitiException("Could not handle signal: process definition with id: " + processDefinitionId + " is suspended");
                }

                Process     process     = ProcessDefinitionUtil.GetProcess(processDefinitionId);
                FlowElement flowElement = process.GetFlowElement(eventSubscription.ActivityId, true);
                if (flowElement == null)
                {
                    throw new ActivitiException("Could not find matching FlowElement for activityId " + eventSubscription.ActivityId);
                }

                // Start process instance via that flow element
                IDictionary <string, object> variables = null;
                if (payload is System.Collections.IDictionary)
                {
                    variables = (IDictionary <string, object>)payload;
                }
                ProcessInstanceHelper processInstanceHelper = commandContext.ProcessEngineConfiguration.ProcessInstanceHelper;
                processInstanceHelper.CreateAndStartProcessInstanceWithInitialFlowElement(processDefinition, null, null, flowElement, process, variables, null, true);
            }
            else
            {
                throw new ActivitiException("Invalid signal handling: no execution nor process definition set");
            }
        }