protected internal virtual void SendProcessInstanceCancelledEvent(IExecutionEntity execution, FlowElement terminateEndEvent) { if (Context.ProcessEngineConfiguration.EventDispatcher.Enabled) { if ((execution.ProcessInstanceType && execution.SuperExecutionId is null) || (execution.ParentId is null && execution.SuperExecutionId is object)) { Context.ProcessEngineConfiguration.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateCancelledEvent(execution.Id, execution.ProcessInstanceId, execution.ProcessDefinitionId, execution.CurrentFlowElement)); } } DispatchExecutionCancelled(execution, terminateEndEvent); }
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; }
protected internal virtual void DeleteProcessInstanceCascade(IExecutionEntity execution, string deleteReason, bool deleteHistory) { // fill default reason if none provided if (deleteReason is null) { deleteReason = DeleteReasonFields.PROCESS_INSTANCE_DELETED; } foreach (IExecutionEntity subExecutionEntity in execution.Executions) { if (subExecutionEntity.IsMultiInstanceRoot) { foreach (IExecutionEntity miExecutionEntity in subExecutionEntity.Executions) { if (miExecutionEntity.SubProcessInstance != null) { DeleteProcessInstanceCascade(miExecutionEntity.SubProcessInstance, deleteReason, deleteHistory); } } } else if (subExecutionEntity.SubProcessInstance != null) { DeleteProcessInstanceCascade(subExecutionEntity.SubProcessInstance, deleteReason, deleteHistory); } } TaskEntityManager.DeleteTasksByProcessInstanceId(execution.Id, deleteReason, deleteHistory); if (EventDispatcher.Enabled) { EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateCancelledEvent(execution.ProcessInstanceId, execution.ProcessInstanceId, null, deleteReason)); } // delete the execution BEFORE we delete the history, otherwise we will // produce orphan HistoricVariableInstance instances IExecutionEntity processInstanceExecutionEntity = execution.ProcessInstance; if (processInstanceExecutionEntity == null) { return; } IList <IExecutionEntity> childExecutions = CollectChildren(execution.ProcessInstance); for (int i = childExecutions.Count - 1; i >= 0; i--) { IExecutionEntity childExecutionEntity = childExecutions[i]; DeleteExecutionAndRelatedData(childExecutionEntity, deleteReason, false); } DeleteExecutionAndRelatedData(execution, deleteReason, false); if (deleteHistory) { HistoricProcessInstanceEntityManager.Delete(new KeyValuePair <string, object>("id", execution.Id)); } HistoryManager.RecordProcessInstanceEnd(processInstanceExecutionEntity.Id, deleteReason, null); processInstanceExecutionEntity.Deleted = true; }