public virtual object Execute(CommandContext commandContext) { EnsureUtil.EnsureNotNull("executionId", ExecutionId); var eventSubscriptionManager = commandContext.EventSubscriptionManager; IList <EventSubscriptionEntity> eventSubscriptions = null; if (!string.ReferenceEquals(MessageName, null)) { eventSubscriptions = eventSubscriptionManager.FindEventSubscriptionsByNameAndExecution(EventType.Message.Name, MessageName, ExecutionId, Exclusive); } else { eventSubscriptions = eventSubscriptionManager.FindEventSubscriptionsByExecutionAndType(ExecutionId, EventType.Message.Name, Exclusive); } EnsureUtil.EnsureNotEmpty("Execution with id '" + ExecutionId + "' does not have a subscription to a message event with name '" + MessageName + "'", "eventSubscriptions", ListExt.ConvertToIlist(eventSubscriptions)); EnsureUtil.EnsureNumberOfElements("More than one matching message subscription found for execution " + ExecutionId, "eventSubscriptions", ListExt.ConvertToIlist(eventSubscriptions), 1); // there can be only one: var eventSubscriptionEntity = eventSubscriptions[0]; // check authorization var processInstanceId = eventSubscriptionEntity.ProcessInstanceId; foreach (var checker in commandContext.ProcessEngineConfiguration.CommandCheckers) { checker.CheckUpdateProcessInstanceById(processInstanceId); } eventSubscriptionEntity.EventReceived(ProcessVariables, false); return(null); }
public virtual object Execute(CommandContext commandContext) { //Query转换 EnsureUtil.EnsureNotEmpty("processInstanceIds", ProcessInstanceIds); // Check if process instance is still running //var instances = commandContext.HistoricProcessInstanceManager.Find // new HistoricProcessInstanceQueryImpl().ProcessInstanceIds(new HashSet<string>(ProcessInstanceIds)) // .list(); DbContext db = commandContext.Scope.Resolve <DbContext>(); var query = from a in db.Set <HistoricProcessInstanceEventEntity>() join b in db.Set <ProcessDefinitionEntity>() on a.ProcessDefinitionId equals b.Id where ProcessInstanceIds.Contains(a.ProcessInstanceId) select a; var instances = query.ToList(); EnsureUtil.EnsureNotEmpty("No historic process instances found ", instances); EnsureUtil.EnsureNumberOfElements("historic process instances", instances, ProcessInstanceIds.Count); foreach (var historicProcessInstance in instances) { foreach (var checker in commandContext.ProcessEngineConfiguration.CommandCheckers) { checker.CheckDeleteHistoricProcessInstance(historicProcessInstance); } EnsureUtil.EnsureNotNull( "Process instance is still running, cannot delete historic process instance: " + historicProcessInstance, "instance.getEndTime()", historicProcessInstance.EndTime); var toDelete = historicProcessInstance.Id; commandContext.HistoricProcessInstanceManager.DeleteHistoricProcessInstanceById(toDelete); } return(null); }
public virtual IAttachment Execute(CommandContext commandContext) { if (!ReferenceEquals(TaskId, null)) { _task = commandContext.TaskManager.FindTaskById(TaskId); } else { EnsureUtil.EnsureNotNull("taskId or processInstanceId has to be provided", ProcessInstanceId); IList <ExecutionEntity> executionsByProcessInstanceId = commandContext.ExecutionManager.FindExecutionsByProcessInstanceId(ProcessInstanceId); EnsureUtil.EnsureNumberOfElements("processInstances", executionsByProcessInstanceId, 1); ProcessInstance = executionsByProcessInstanceId[0]; } var attachment = new AttachmentEntity(); attachment.Name = AttachmentName; attachment.Description = AttachmentDescription; attachment.Type = AttachmentType; attachment.TaskId = TaskId; attachment.ProcessInstanceId = ProcessInstanceId; attachment.Url = Url; commandContext.AttachmentManager.Add(attachment); if (Content != null) { var bytes = IoUtil.ReadInputStream(Content, AttachmentName); var byteArray = new ResourceEntity(bytes); commandContext.ByteArrayManager.Add(byteArray); attachment.ContentId = byteArray.Id; } PropertyChange propertyChange = new PropertyChange("name", null, AttachmentName); if (_task != null) { commandContext.OperationLogManager.LogAttachmentOperation( UserOperationLogEntryFields.OperationTypeAddAttachment, _task, propertyChange); } else if (ProcessInstance != null) { commandContext.OperationLogManager.LogAttachmentOperation( UserOperationLogEntryFields.OperationTypeAddAttachment, ProcessInstance, propertyChange); } return(attachment); }