Exemple #1
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);
            }
        }
Exemple #2
0
        public virtual T  Execute(ICommandContext commandContext)
        {
            IProcessDefinitionEntity processDefinition = ProcessDefinitionUtil.GetProcessDefinitionFromDatabase(processDefinitionId);

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

            if (processDefinition.Suspended)
            {
                throw new ActivitiException("Cannot execute operation because process definition '" + processDefinition.Name + "' (id=" + processDefinition.Id + ") is suspended");
            }

            return(Execute(commandContext, processDefinition));
        }