public virtual void DeleteAttachmentsByTaskId(string taskId) { CheckHistoryEnabled(); IList <IAttachmentEntity> attachments = FindAttachmentsByTaskId(taskId); bool dispatchEvents = EventDispatcher.Enabled; string processInstanceId = null; string processDefinitionId = null; string executionId = null; if (dispatchEvents && attachments != null && attachments.Count > 0) { // Forced to fetch the task to get hold of the process definition // for event-dispatching, if available ITask task = TaskEntityManager.FindById <ITask>(new KeyValuePair <string, object>("id", taskId)); if (task != null) { processDefinitionId = task.ProcessDefinitionId; processInstanceId = task.ProcessInstanceId; executionId = task.ExecutionId; } } foreach (IAttachment attachment in attachments) { string contentId = attachment.ContentId; if (!(contentId is null)) { ByteArrayEntityManager.DeleteByteArrayById(contentId); } attachmentDataManager.Delete((IAttachmentEntity)attachment); if (dispatchEvents) { EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_DELETED, attachment, executionId, processInstanceId, processDefinitionId)); } } }
public virtual void DeleteDataForExecution(IExecutionEntity executionEntity, string deleteReason, bool cancel) { // To start, deactivate the current incoming execution executionEntity.Ended = true; executionEntity.IsActive = false; bool enableExecutionRelationshipCounts = IsExecutionRelatedEntityCountEnabled(executionEntity); if (executionEntity.Id.Equals(executionEntity.ProcessInstanceId) && (!enableExecutionRelationshipCounts || (enableExecutionRelationshipCounts && ((ICountingExecutionEntity)executionEntity).IdentityLinkCount > 0))) { IIdentityLinkEntityManager identityLinkEntityManager = IdentityLinkEntityManager; ICollection <IIdentityLinkEntity> identityLinks = identityLinkEntityManager.FindIdentityLinksByProcessInstanceId(executionEntity.ProcessInstanceId); foreach (IIdentityLinkEntity identityLink in identityLinks) { identityLinkEntityManager.Delete(identityLink); } } // Get variables related to execution and delete them if (!enableExecutionRelationshipCounts || (enableExecutionRelationshipCounts && ((ICountingExecutionEntity)executionEntity).VariableCount > 0)) { ICollection <IVariableInstance> executionVariables = executionEntity.VariableInstancesLocal.Values; foreach (IVariableInstance variableInstance in executionVariables) { if (variableInstance is IVariableInstanceEntity variableInstanceEntity) { IVariableInstanceEntityManager variableInstanceEntityManager = VariableInstanceEntityManager; variableInstanceEntityManager.Delete(variableInstanceEntity); if (variableInstanceEntity.ByteArrayRef != null && variableInstanceEntity.ByteArrayRef.Id is object) { ByteArrayEntityManager.DeleteByteArrayById(variableInstanceEntity.ByteArrayRef.Id); } } } } // Delete current user tasks if (!enableExecutionRelationshipCounts || (enableExecutionRelationshipCounts && ((ICountingExecutionEntity)executionEntity).TaskCount > 0)) { ITaskEntityManager taskEntityManager = TaskEntityManager; ICollection <ITaskEntity> tasksForExecution = taskEntityManager.FindTasksByExecutionId(executionEntity.Id); foreach (ITaskEntity taskEntity in tasksForExecution) { taskEntityManager.DeleteTask(taskEntity, deleteReason, false, cancel); } } // Delete jobs if (!enableExecutionRelationshipCounts || (enableExecutionRelationshipCounts && ((ICountingExecutionEntity)executionEntity).TimerJobCount > 0)) { ITimerJobEntityManager timerJobEntityManager = TimerJobEntityManager; ICollection <ITimerJobEntity> timerJobsForExecution = timerJobEntityManager.FindJobsByExecutionId(executionEntity.Id); foreach (ITimerJobEntity job in timerJobsForExecution) { timerJobEntityManager.Delete(job); if (EventDispatcher.Enabled) { EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.JOB_CANCELED, job)); } } } if (!enableExecutionRelationshipCounts || (enableExecutionRelationshipCounts && ((ICountingExecutionEntity)executionEntity).JobCount > 0)) { IJobEntityManager jobEntityManager = JobEntityManager; ICollection <IJobEntity> jobsForExecution = jobEntityManager.FindJobsByExecutionId(executionEntity.Id); foreach (IJobEntity job in jobsForExecution) { JobEntityManager.Delete(job); if (EventDispatcher.Enabled) { EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.JOB_CANCELED, job)); } } } if (!enableExecutionRelationshipCounts || (enableExecutionRelationshipCounts && ((ICountingExecutionEntity)executionEntity).SuspendedJobCount > 0)) { ISuspendedJobEntityManager suspendedJobEntityManager = SuspendedJobEntityManager; ICollection <ISuspendedJobEntity> suspendedJobsForExecution = suspendedJobEntityManager.FindJobsByExecutionId(executionEntity.Id); foreach (ISuspendedJobEntity job in suspendedJobsForExecution) { suspendedJobEntityManager.Delete(job); if (EventDispatcher.Enabled) { EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.JOB_CANCELED, job)); } } } if (!enableExecutionRelationshipCounts || (enableExecutionRelationshipCounts && ((ICountingExecutionEntity)executionEntity).DeadLetterJobCount > 0)) { IDeadLetterJobEntityManager deadLetterJobEntityManager = DeadLetterJobEntityManager; ICollection <IDeadLetterJobEntity> deadLetterJobsForExecution = deadLetterJobEntityManager.FindJobsByExecutionId(executionEntity.Id); foreach (IDeadLetterJobEntity job in deadLetterJobsForExecution) { deadLetterJobEntityManager.Delete(job); if (EventDispatcher.Enabled) { EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.JOB_CANCELED, job)); } } } // Delete event subscriptions if (!enableExecutionRelationshipCounts || (enableExecutionRelationshipCounts && ((ICountingExecutionEntity)executionEntity).EventSubscriptionCount > 0)) { IEventSubscriptionEntityManager eventSubscriptionEntityManager = EventSubscriptionEntityManager; IList <IEventSubscriptionEntity> eventSubscriptions = eventSubscriptionEntityManager.FindEventSubscriptionsByExecution(executionEntity.Id); foreach (IEventSubscriptionEntity eventSubscription in eventSubscriptions) { eventSubscriptionEntityManager.Delete(eventSubscription); } } }