Exemplo n.º 1
0
 public virtual void Closed(ICommandContext context)
 {
     if (context.EventDispatcher.Enabled)
     {
         context.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.JOB_EXECUTION_SUCCESS, job));
     }
 }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parentExecution"></param>
        /// <param name="subProcessInstance"></param>
        /// <param name="initialElement"></param>
        public virtual void RecordSubProcessInstanceStart(IExecutionEntity parentExecution, IExecutionEntity subProcessInstance, FlowElement initialElement)
        {
            if (IsHistoryLevelAtLeast(HistoryLevel.ACTIVITY))
            {
                IHistoricProcessInstanceEntity historicProcessInstance = HistoricProcessInstanceEntityManager.Create(subProcessInstance);

                // Fix for ACT-1728: startActivityId not initialized with subprocess instance
                if (historicProcessInstance.StartActivityId is null)
                {
                    historicProcessInstance.StartActivityId = initialElement.Id;
                }
                HistoricProcessInstanceEntityManager.Insert(historicProcessInstance, false);

                // Fire event
                IActivitiEventDispatcher activitiEventDispatcher = EventDispatcher;
                if (activitiEventDispatcher != null && activitiEventDispatcher.Enabled)
                {
                    activitiEventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_CREATED, historicProcessInstance));
                }

                IHistoricActivityInstanceEntity activitiyInstance = FindActivityInstance(parentExecution, false, true);
                if (activitiyInstance != null)
                {
                    activitiyInstance.CalledProcessInstanceId = subProcessInstance.ProcessInstanceId;
                }
            }
        }
Exemplo n.º 3
0
        public virtual object Execute(ICommandContext commandContext)
        {
            if (jobId is null)
            {
                throw new ActivitiIllegalArgumentException("jobId is null");
            }

            // We need to refetch the job, as it could have been deleted by another concurrent job
            // For exampel: an embedded subprocess with a couple of async tasks and a timer on the boundary of the subprocess
            // when the timer fires, all executions and thus also the jobs inside of the embedded subprocess are destroyed.
            // However, the async task jobs could already have been fetched and put in the queue.... while in reality they have been deleted.
            // A refetch is thus needed here to be sure that it exists for this transaction.

            IJob job = commandContext.JobEntityManager.FindById <IJobEntity>(jobId);

            if (job == null)
            {
                log.LogDebug("Job does not exist anymore and will not be executed. It has most likely been deleted as part of another concurrent part of the process instance.");
                return(null);
            }

            if (log.IsEnabled(LogLevel.Debug))
            {
                log.LogDebug($"Executing async job {job.Id}");
            }

            commandContext.JobManager.Execute(job);

            if (commandContext.EventDispatcher.Enabled)
            {
                commandContext.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.JOB_EXECUTION_SUCCESS, job));
            }

            return(null);
        }
Exemplo n.º 4
0
        public override void Insert(ICommentEntity commentEntity)
        {
            if (HistoryManager.HistoryEnabled == false)
            {
                return;
            }

            CheckHistoryEnabled();

            Insert(commentEntity, false);

            IComment comment = commentEntity;

            if (EventDispatcher.Enabled)
            {
                // Forced to fetch the process-instance to associate the right
                // process definition
                string processDefinitionId = null;
                string processInstanceId   = comment.ProcessInstanceId;
                if (comment.ProcessInstanceId is object)
                {
                    IExecutionEntity process = ExecutionEntityManager.FindById <IExecutionEntity>(comment.ProcessInstanceId);
                    if (process != null)
                    {
                        processDefinitionId = process.ProcessDefinitionId;
                    }
                }
                EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_CREATED, commentEntity, processInstanceId, processInstanceId, processDefinitionId));
                EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, commentEntity, processInstanceId, processInstanceId, processDefinitionId));
            }
        }
Exemplo n.º 5
0
        public override void Delete(ICommentEntity commentEntity)
        {
            CheckHistoryEnabled();

            Delete(commentEntity, false);

            IComment comment = commentEntity;

            if (EventDispatcher.Enabled)
            {
                // Forced to fetch the process-instance to associate the right
                // process definition
                string processDefinitionId = null;
                string processInstanceId   = comment.ProcessInstanceId;
                if (!(comment.ProcessInstanceId is null))
                {
                    IExecutionEntity process = ExecutionEntityManager.FindById <IExecutionEntity>(comment.ProcessInstanceId);
                    if (process != null)
                    {
                        processDefinitionId = process.ProcessDefinitionId;
                    }
                }
                EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_DELETED, commentEntity, processInstanceId, processInstanceId, processDefinitionId));
            }
        }
Exemplo n.º 6
0
        public override void Delete(IVariableInstanceEntity entity, bool fireDeleteEvent)
        {
            base.Delete(entity, false);
            IByteArrayRef byteArrayRef = entity.ByteArrayRef;

            if (byteArrayRef != null)
            {
                byteArrayRef.Delete();
            }
            entity.Deleted = true;

            if (!(entity.ExecutionId is null) && ExecutionRelatedEntityCountEnabledGlobally)
            {
                ICountingExecutionEntity executionEntity = ExecutionEntityManager.FindById <ICountingExecutionEntity>(entity.ExecutionId);
                if (IsExecutionRelatedEntityCountEnabled(executionEntity))
                {
                    executionEntity.VariableCount -= 1;
                }
            }

            IActivitiEventDispatcher eventDispatcher = EventDispatcher;

            if (fireDeleteEvent && eventDispatcher.Enabled)
            {
                eventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_DELETED, entity));

                eventDispatcher.DispatchEvent(CreateVariableDeleteEvent(entity));
            }
        }
Exemplo n.º 7
0
        public virtual object  Execute(ICommandContext commandContext)
        {
            if (string.IsNullOrWhiteSpace(processDefinitionId))
            {
                throw new ActivitiIllegalArgumentException("Process definition id is null");
            }

            IProcessDefinitionEntity processDefinition = commandContext.ProcessDefinitionEntityManager.FindById <IProcessDefinitionEntity>(processDefinitionId);

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

            // Update category
            processDefinition.Category = category;

            // Remove process definition from cache, it will be refetched later
            IDeploymentCache <ProcessDefinitionCacheEntry> processDefinitionCache = commandContext.ProcessEngineConfiguration.ProcessDefinitionCache;

            if (processDefinitionCache != null)
            {
                processDefinitionCache.Remove(processDefinitionId);
            }

            if (commandContext.EventDispatcher.Enabled)
            {
                commandContext.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_UPDATED, processDefinition));
            }

            return(null);
        }
Exemplo n.º 8
0
 protected internal virtual void SendCancelEvent(IJobEntity jobToDelete)
 {
     if (Context.ProcessEngineConfiguration.EventDispatcher.Enabled)
     {
         Context.ProcessEngineConfiguration.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.JOB_CANCELED, jobToDelete));
     }
 }
Exemplo n.º 9
0
        // Activity related history

        /// <summary>
        ///
        /// </summary>
        /// <param name="executionEntity"></param>
        public virtual void RecordActivityStart(IExecutionEntity executionEntity)
        {
            if (IsHistoryLevelAtLeast(HistoryLevel.ACTIVITY))
            {
                if (executionEntity.ActivityId != null && executionEntity.CurrentFlowElement != null)
                {
                    // Historic activity instance could have been created (but only in cache, never persisted)
                    // for example when submitting form properties
                    IHistoricActivityInstanceEntity historicActivityInstanceEntityFromCache = GetHistoricActivityInstanceFromCache(executionEntity.Id, executionEntity.ActivityId, true);
                    IHistoricActivityInstanceEntity historicActivityInstanceEntity;
                    if (historicActivityInstanceEntityFromCache != null)
                    {
                        historicActivityInstanceEntity = historicActivityInstanceEntityFromCache;
                    }
                    else
                    {
                        historicActivityInstanceEntity = CreateHistoricActivityInstanceEntity(executionEntity);
                    }

                    // Fire event
                    IActivitiEventDispatcher activitiEventDispatcher = EventDispatcher;
                    if (activitiEventDispatcher != null && activitiEventDispatcher.Enabled)
                    {
                        activitiEventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_CREATED, historicActivityInstanceEntity));
                    }
                }
            }
        }
Exemplo n.º 10
0
        public virtual IExecutionEntity CreateSubprocessInstance(IProcessDefinition processDefinition, IExecutionEntity superExecutionEntity, string businessKey)
        {
            IExecutionEntity subProcessInstance = executionDataManager.Create();

            InheritCommonProperties(superExecutionEntity, subProcessInstance);
            subProcessInstance.ProcessDefinitionId   = processDefinition.Id;
            subProcessInstance.ProcessDefinitionKey  = processDefinition.Key;
            subProcessInstance.SuperExecution        = superExecutionEntity;
            subProcessInstance.RootProcessInstanceId = superExecutionEntity.RootProcessInstanceId;
            subProcessInstance.IsScope     = true; // process instance is always a scope for all child executions
            subProcessInstance.StartUserId = Authentication.AuthenticatedUser.Id;
            subProcessInstance.BusinessKey = businessKey;

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

            //if (logger.DebugEnabled)
            //{
            //    logger.debug("Child execution {} created with super execution {}", subProcessInstance, superExecutionEntity.Id);
            //}

            subProcessInstance.ProcessInstanceId    = subProcessInstance.Id;
            superExecutionEntity.SubProcessInstance = subProcessInstance;

            ProcessEngineConfigurationImpl processEngineConfiguration1 = Context.ProcessEngineConfiguration;

            if (processEngineConfiguration1 is object && processEngineConfiguration1.EventDispatcher.Enabled)
            {
                processEngineConfiguration1.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_CREATED, subProcessInstance));
            }

            return(subProcessInstance);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Creates a new execution. properties processDefinition, processInstance and activity will be initialized.
        /// </summary>
        public virtual IExecutionEntity CreateChildExecution(IExecutionEntity parentExecutionEntity)
        {
            IExecutionEntity childExecution = executionDataManager.Create();

            childExecution.Name = parentExecutionEntity.Name;
            InheritCommonProperties(parentExecutionEntity, childExecution);
            childExecution.Parent = parentExecutionEntity;
            childExecution.ProcessDefinitionId  = parentExecutionEntity.ProcessDefinitionId;
            childExecution.ProcessDefinitionKey = parentExecutionEntity.ProcessDefinitionKey;
            childExecution.ProcessInstanceId    = parentExecutionEntity.ProcessInstanceId is object?parentExecutionEntity.ProcessInstanceId : parentExecutionEntity.Id;
            childExecution.IsScope      = false;
            childExecution.ActivityId   = parentExecutionEntity.ActivityId;
            childExecution.BusinessKey  = parentExecutionEntity.BusinessKey;
            childExecution.DeploymentId = parentExecutionEntity.DeploymentId;
            childExecution.TenantId     = parentExecutionEntity.TenantId;

            // manage the bidirectional parent-child relation
            parentExecutionEntity.AddChildExecution(childExecution);

            // Insert the child execution
            Insert(childExecution, false);

            if (logger.IsEnabled(LogLevel.Debug))
            {
                logger.LogDebug("Child execution {} created with parent {}", childExecution, parentExecutionEntity.Id);
            }

            if (EventDispatcher.Enabled)
            {
                EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_CREATED, childExecution));
                EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, childExecution));
            }

            return(childExecution);
        }
Exemplo n.º 12
0
 protected internal virtual void FireAssignmentEvents(ITaskEntity taskEntity)
 {
     RecordTaskAssignment(taskEntity);
     if (EventDispatcher.Enabled)
     {
         EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.TASK_ASSIGNED, taskEntity));
     }
 }
Exemplo n.º 13
0
        public virtual void Delete(EntityImpl entity, bool fireDeleteEvent)
        {
            DataManager.Delete(entity);

            if (fireDeleteEvent && EventDispatcher.Enabled)
            {
                EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_DELETED, entity));
            }
        }
Exemplo n.º 14
0
        public virtual EntityImpl Update(EntityImpl entity, bool fireUpdateEvent)
        {
            EntityImpl updatedEntity = DataManager.Update(entity);

            if (fireUpdateEvent && EventDispatcher.Enabled)
            {
                EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_UPDATED, entity));
            }

            return(updatedEntity);
        }
Exemplo n.º 15
0
        public virtual void Insert(EntityImpl entity, bool fireCreateEvent)
        {
            DataManager.Insert(entity);

            IActivitiEventDispatcher eventDispatcher = EventDispatcher;

            if (fireCreateEvent && eventDispatcher.Enabled)
            {
                eventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_CREATED, entity));
                eventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, entity));
            }
        }
Exemplo n.º 16
0
        public virtual void DeleteProcessInstanceExecutionEntity(string processInstanceId, string currentFlowElementId, string deleteReason, bool cascade, bool cancel)
        {
            IExecutionEntity processInstanceEntity = FindById <IExecutionEntity>(new KeyValuePair <string, object>("id", processInstanceId));

            if (processInstanceEntity == null)
            {
                throw new ActivitiObjectNotFoundException("No process instance found for id '" + processInstanceId + "'", typeof(IProcessInstance));
            }

            if (processInstanceEntity.Deleted)
            {
                return;
            }

            // Call activities
            foreach (IExecutionEntity subExecutionEntity in processInstanceEntity.Executions)
            {
                if (subExecutionEntity.SubProcessInstance != null && !subExecutionEntity.Ended)
                {
                    DeleteProcessInstanceCascade(subExecutionEntity.SubProcessInstance, deleteReason, cascade);
                }
            }

            // delete event scope executions
            foreach (IExecutionEntity childExecution in processInstanceEntity.Executions)
            {
                if (childExecution.IsEventScope)
                {
                    DeleteExecutionAndRelatedData(childExecution, null, false);
                }
            }

            DeleteChildExecutions(processInstanceEntity, deleteReason, cancel);
            DeleteExecutionAndRelatedData(processInstanceEntity, deleteReason, cancel);

            if (EventDispatcher.Enabled)
            {
                if (!cancel)
                {
                    EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.PROCESS_COMPLETED, processInstanceEntity));
                }
                else
                {
                    EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateCancelledEvent(processInstanceEntity.Id, processInstanceEntity.Id, processInstanceEntity.ProcessDefinitionId, deleteReason));
                }
            }

            // TODO: what about delete reason?
            HistoryManager.RecordProcessInstanceEnd(processInstanceEntity.Id, deleteReason, currentFlowElementId);
            processInstanceEntity.Deleted = true;
        }
Exemplo n.º 17
0
        public override void Delete(IJobEntity jobEntity)
        {
            base.Delete(jobEntity);

            DeleteExceptionByteArrayRef(jobEntity);

            RemoveExecutionLink(jobEntity);

            // Send event
            if (EventDispatcher.Enabled)
            {
                EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_DELETED, this));
            }
        }
        public virtual void Execute(IJobEntity job, string configuration, IExecutionEntity execution, ICommandContext commandContext)
        {
            Context.Agenda.PlanTriggerExecutionOperation(execution);

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

            if (execution.CurrentFlowElement is BoundaryEvent)
            {
                IList <string> processedElements = new List <string>();
                DispatchExecutionTimeOut(job, execution, processedElements, commandContext);
            }
        }
Exemplo n.º 19
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);
            }
        }
Exemplo n.º 20
0
        protected internal override void ExecuteTaskComplete(ICommandContext commandContext, ITaskEntity taskEntity, IDictionary <string, object> variables, bool localScope)
        {
            Transfer(commandContext);

            // Task complete logic

            if (taskEntity.DelegationState.HasValue && taskEntity.DelegationState.Value == DelegationState.PENDING)
            {
                throw new ActivitiException("A delegated task cannot be completed, but should be resolved instead.");
            }

            commandContext.ProcessEngineConfiguration.ListenerNotificationHelper.ExecuteTaskListeners(taskEntity, BaseTaskListenerFields.EVENTNAME_COMPLETE);
            IUserInfo user = Authentication.AuthenticatedUser;

            if (user != null && string.IsNullOrWhiteSpace(taskEntity.ProcessInstanceId) == false)
            {
                IExecutionEntity processInstanceEntity = commandContext.ExecutionEntityManager.FindById <IExecutionEntity>(taskEntity.ProcessInstanceId);//这里为什么取ProcessInstance而不是Exceution.
                commandContext.IdentityLinkEntityManager.InvolveUser(processInstanceEntity, user.Id, IdentityLinkType.PARTICIPANT);
            }

            IActivitiEventDispatcher eventDispatcher = Context.ProcessEngineConfiguration.EventDispatcher;

            if (eventDispatcher.Enabled)
            {
                if (variables != null)
                {
                    eventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityWithVariablesEvent(ActivitiEventType.TASK_COMPLETED, taskEntity, variables, localScope));
                }
                else
                {
                    eventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.TASK_COMPLETED, taskEntity));
                }
            }

            commandContext.TaskEntityManager.DeleteTask(taskEntity, completeReason, false, false);

            if (eventDispatcher.Enabled)
            {
                eventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateCustomTaskCompletedEvent(taskEntity, ActivitiEventType.TASK_TRANSFERED));
            }

            // Continue process (if not a standalone task)
            if (taskEntity.ExecutionId is object)
            {
                IExecutionEntity executionEntity = commandContext.ExecutionEntityManager.FindById <IExecutionEntity>(taskEntity.ExecutionId);
                Context.Agenda.PlanTriggerExecutionOperation(executionEntity);
            }
        }
Exemplo n.º 21
0
 protected internal static void DispatchStateChangeEvent(object entity, ISuspensionState state)
 {
     if (Context.CommandContext != null && Context.CommandContext.EventDispatcher.Enabled)
     {
         ActivitiEventType eventType;
         if (state == SuspensionStateProvider.ACTIVE)
         {
             eventType = ActivitiEventType.ENTITY_ACTIVATED;
         }
         else
         {
             eventType = ActivitiEventType.ENTITY_SUSPENDED;
         }
         Context.CommandContext.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(eventType, entity));
     }
 }
Exemplo n.º 22
0
        public virtual string UpdateProcessInstanceBusinessKey(IExecutionEntity executionEntity, string businessKey)
        {
            if (executionEntity.ProcessInstanceType && businessKey is object)
            {
                executionEntity.BusinessKey = businessKey;
                HistoryManager.UpdateProcessBusinessKeyInHistory(executionEntity);

                if (EventDispatcher.Enabled)
                {
                    EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_UPDATED, executionEntity));
                }

                return(businessKey);
            }
            return(null);
        }
Exemplo n.º 23
0
        protected internal virtual void removeTimerStartJobs(IProcessDefinition processDefinition)
        {
            IList <ITimerJobEntity> timerStartJobs = TimerJobEntityManager.FindJobsByTypeAndProcessDefinitionId(TimerStartEventJobHandler.TYPE, processDefinition.Id);

            if (timerStartJobs != null && timerStartJobs.Count > 0)
            {
                foreach (ITimerJobEntity timerStartJob in timerStartJobs)
                {
                    if (EventDispatcher.Enabled)
                    {
                        EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.JOB_CANCELED, timerStartJob, null, null, processDefinition.Id));
                    }

                    TimerJobEntityManager.Delete(timerStartJob);
                }
            }
        }
Exemplo n.º 24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="timerJob"></param>
        public virtual void ScheduleTimerJob(ITimerJobEntity timerJob)
        {
            if (timerJob == null)
            {
                throw new ActivitiException("Empty timer job can not be scheduled");
            }

            processEngineConfiguration.TimerJobEntityManager.Insert(timerJob);

            ICommandContext          commandContext  = Context.CommandContext;
            IActivitiEventDispatcher eventDispatcher = commandContext.EventDispatcher;

            if (eventDispatcher.Enabled)
            {
                eventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.TIMER_SCHEDULED, timerJob));
            }
        }
Exemplo n.º 25
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="executionEntity"></param>
        /// <param name="deleteReason"></param>
        public virtual void RecordActivityEnd(IExecutionEntity executionEntity, string deleteReason)
        {
            if (IsHistoryLevelAtLeast(HistoryLevel.ACTIVITY))
            {
                IHistoricActivityInstanceEntity historicActivityInstance = FindActivityInstance(executionEntity, false, true);
                if (historicActivityInstance != null)
                {
                    historicActivityInstance.markEnded(deleteReason);

                    // Fire event
                    IActivitiEventDispatcher activitiEventDispatcher = EventDispatcher;
                    if (activitiEventDispatcher != null && activitiEventDispatcher.Enabled)
                    {
                        activitiEventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.HISTORIC_ACTIVITY_INSTANCE_ENDED, historicActivityInstance));
                    }
                }
            }
        }
Exemplo n.º 26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="processInstance"></param>
        /// <param name="startElement"></param>
        public virtual void RecordProcessInstanceStart(IExecutionEntity processInstance, FlowElement startElement)
        {
            if (IsHistoryLevelAtLeast(HistoryLevel.ACTIVITY))
            {
                IHistoricProcessInstanceEntity historicProcessInstance = HistoricProcessInstanceEntityManager.Create(processInstance);
                historicProcessInstance.StartActivityId = startElement.Id;

                // Insert historic process-instance
                HistoricProcessInstanceEntityManager.Insert(historicProcessInstance, false);

                // Fire event
                IActivitiEventDispatcher activitiEventDispatcher = EventDispatcher;
                if (activitiEventDispatcher != null && activitiEventDispatcher.Enabled)
                {
                    activitiEventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_CREATED, historicProcessInstance));
                }
            }
        }
Exemplo n.º 27
0
        public virtual object Execute(ICommandContext commandContext)
        {
            ITimerJobEntity job = commandContext.TimerJobEntityManager.FindById <ITimerJobEntity>(jobId);

            if (job != null)
            {
                job.Retries = retries;

                if (commandContext.EventDispatcher.Enabled)
                {
                    commandContext.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_UPDATED, job));
                }
            }
            else
            {
                throw new ActivitiObjectNotFoundException("No timer job found with id '" + jobId + "'.", typeof(IJob));
            }
            return(null);
        }
Exemplo n.º 28
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="processDefinition"></param>
        /// <param name="superExecutionEntity"></param>
        /// <param name="businessKey"></param>
        /// <returns></returns>
        public virtual IExecutionEntity CreateSubprocessInstance(IProcessDefinition processDefinition, IExecutionEntity superExecutionEntity, string businessKey)
        {
            IExecutionEntity subProcessInstance = executionDataManager.Create();

            InheritCommonProperties(superExecutionEntity, subProcessInstance);
            subProcessInstance.ProcessDefinitionId   = processDefinition.Id;
            subProcessInstance.ProcessDefinitionKey  = processDefinition.Key;
            subProcessInstance.SuperExecution        = superExecutionEntity;
            subProcessInstance.RootProcessInstanceId = superExecutionEntity.RootProcessInstanceId;
            subProcessInstance.IsScope     = true; // process instance is always a scope for all child executions
            subProcessInstance.StartUserId = Authentication.AuthenticatedUser.Id;
            subProcessInstance.BusinessKey = businessKey;

            // Store in database
            Insert(subProcessInstance, false);
            IUserInfo starter = null;

            if (string.IsNullOrWhiteSpace(Authentication.AuthenticatedUser.Id) == false)
            {
                starter = GetUser(subProcessInstance, Authentication.AuthenticatedUser.Id);

                //保存调用用户变量
                subProcessInstance.SetVariable(subProcessInstance.StartUserId, starter);
            }
            subProcessInstance.StartUser = starter.FullName;
            if (logger.IsEnabled(LogLevel.Debug))
            {
                logger.LogDebug("Child execution {} created with super execution {}", subProcessInstance, superExecutionEntity.Id);
            }

            subProcessInstance.ProcessInstanceId    = subProcessInstance.Id;
            superExecutionEntity.SubProcessInstance = subProcessInstance;

            ProcessEngineConfigurationImpl processEngineConfiguration1 = Context.ProcessEngineConfiguration;

            if (processEngineConfiguration1 is object && processEngineConfiguration1.EventDispatcher.Enabled)
            {
                processEngineConfiguration1.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_CREATED, subProcessInstance));
            }

            return(subProcessInstance);
        }
Exemplo n.º 29
0
        // Process related history

        /// <summary>
        ///
        /// </summary>
        /// <param name="processInstanceId"></param>
        /// <param name="deleteReason"></param>
        /// <param name="activityId"></param>
        public virtual void RecordProcessInstanceEnd(string processInstanceId, string deleteReason, string activityId)
        {
            if (IsHistoryLevelAtLeast(HistoryLevel.ACTIVITY))
            {
                IHistoricProcessInstanceEntity historicProcessInstance = HistoricProcessInstanceEntityManager.FindById <IHistoricProcessInstanceEntity>(new KeyValuePair <string, object>("processInstanceId", processInstanceId));

                if (historicProcessInstance != null)
                {
                    historicProcessInstance.markEnded(deleteReason);
                    historicProcessInstance.EndActivityId = activityId;

                    // Fire event
                    IActivitiEventDispatcher activitiEventDispatcher = EventDispatcher;
                    if (activitiEventDispatcher != null && activitiEventDispatcher.Enabled)
                    {
                        activitiEventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.HISTORIC_PROCESS_INSTANCE_ENDED, historicProcessInstance));
                    }
                }
            }
        }
Exemplo n.º 30
0
        public virtual void DeleteTask(ITaskEntity task, string deleteReason, bool cascade, bool cancel)
        {
            if (!task.Deleted)
            {
                ProcessEngineConfiguration.ListenerNotificationHelper.ExecuteTaskListeners(task, BaseTaskListenerFields.EVENTNAME_DELETE);
                task.Deleted = true;

                string taskId = task.Id;

                IList <ITask> subTasks = FindTasksByParentTaskId(taskId);
                foreach (ITask subTask in subTasks)
                {
                    DeleteTask((ITaskEntity)subTask, deleteReason, cascade, cancel);
                }

                IdentityLinkEntityManager.DeleteIdentityLinksByTaskId(taskId);
                VariableInstanceEntityManager.DeleteVariableInstanceByTask(task);

                if (cascade)
                {
                    HistoricTaskInstanceEntityManager.Delete(new KeyValuePair <string, object>("id", taskId));
                }
                else
                {
                    HistoryManager.RecordTaskEnd(taskId, deleteReason);
                }

                Delete(task, false);

                if (EventDispatcher.Enabled)
                {
                    if (cancel && !task.Canceled)
                    {
                        task.Canceled = true;
                        EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateActivityCancelledEvent(task.Execution?.ActivityId, task.Name, task.ExecutionId, task.ProcessInstanceId, task.ProcessDefinitionId, "userTask", deleteReason));
                    }

                    EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_DELETED, task));
                }
            }
        }