public override void OnEvent(IActivitiEvent @event) { if (IsValidEvent(@event)) { if (@event.ProcessInstanceId is null && processInstanceScope) { throw new ActivitiIllegalArgumentException("Cannot throw process-instance scoped signal, since the dispatched event is not part of an ongoing process instance"); } ICommandContext commandContext = Context.CommandContext; IEventSubscriptionEntityManager eventSubscriptionEntityManager = commandContext.EventSubscriptionEntityManager; IList <ISignalEventSubscriptionEntity> subscriptionEntities; if (processInstanceScope) { subscriptionEntities = eventSubscriptionEntityManager.FindSignalEventSubscriptionsByProcessInstanceAndEventName(@event.ProcessInstanceId, signalName); } else { string tenantId = null; if (!(@event.ProcessDefinitionId is null)) { IProcessDefinition processDefinition = commandContext.ProcessEngineConfiguration.DeploymentManager.FindDeployedProcessDefinitionById(@event.ProcessDefinitionId); tenantId = processDefinition.TenantId; } subscriptionEntities = eventSubscriptionEntityManager.FindSignalEventSubscriptionsByEventName(signalName, tenantId); } foreach (ISignalEventSubscriptionEntity signalEventSubscriptionEntity in subscriptionEntities) { eventSubscriptionEntityManager.EventReceived(signalEventSubscriptionEntity, null, false); } } }
public override void Execute(IExecutionEntity execution) { ICommandContext commandContext = Context.CommandContext; string eventSubscriptionName; if (signalEventName is object) { eventSubscriptionName = signalEventName; } else { IExpression expressionObject = commandContext.ProcessEngineConfiguration.ExpressionManager.CreateExpression(signalExpression); eventSubscriptionName = expressionObject.GetValue(execution).ToString(); } IEventSubscriptionEntityManager eventSubscriptionEntityManager = commandContext.EventSubscriptionEntityManager; IList <ISignalEventSubscriptionEntity> subscriptionEntities; if (processInstanceScope) { subscriptionEntities = eventSubscriptionEntityManager.FindSignalEventSubscriptionsByProcessInstanceAndEventName(execution.ProcessInstanceId, eventSubscriptionName); } else { subscriptionEntities = eventSubscriptionEntityManager.FindSignalEventSubscriptionsByEventName(eventSubscriptionName, execution.TenantId); } foreach (ISignalEventSubscriptionEntity signalEventSubscriptionEntity in subscriptionEntities) { Context.ProcessEngineConfiguration.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateSignalEvent(ActivitiEventType.ACTIVITY_SIGNALED, signalEventSubscriptionEntity.ActivityId, eventSubscriptionName, null, signalEventSubscriptionEntity.ExecutionId, signalEventSubscriptionEntity.ProcessInstanceId, signalEventSubscriptionEntity.ProcessDefinitionId)); eventSubscriptionEntityManager.EventReceived(signalEventSubscriptionEntity, null, signalEventDefinition.Async); } Context.Agenda.PlanTakeOutgoingSequenceFlowsOperation(execution, true); }
public virtual object Execute(ICommandContext commandContext) { IEventSubscriptionEntityManager eventSubscriptionEntityManager = commandContext.EventSubscriptionEntityManager; IList <ISignalEventSubscriptionEntity> signalEvents; if (executionId is null) { signalEvents = eventSubscriptionEntityManager.FindSignalEventSubscriptionsByEventName(eventName, tenantId); } else { IExecutionEntity execution = commandContext.ExecutionEntityManager.FindById <IExecutionEntity>(executionId); if (execution == null) { throw new ActivitiObjectNotFoundException("Cannot find execution with id '" + executionId + "'", typeof(IExecution)); } if (execution.Suspended) { throw new ActivitiException("Cannot throw signal event '" + eventName + "' because execution '" + executionId + "' is suspended"); } if (execution.ProcessInstanceType) { string processInstanceId = execution.ProcessInstanceId; IExecutionEntity superExection = execution.SuperExecution; while (superExection is object) { processInstanceId = superExection.ProcessInstanceId; superExection = superExection.SuperExecution; } signalEvents = eventSubscriptionEntityManager.FindSignalEventSubscriptionsByProcessInstanceAndEventName(processInstanceId, eventName); } else { signalEvents = eventSubscriptionEntityManager.FindSignalEventSubscriptionsByNameAndExecution(eventName, executionId); } if (signalEvents.Count == 0) { throw new ActivitiException("Execution '" + executionId + "' has not subscribed to a signal event with name '" + eventName + "'."); } } foreach (ISignalEventSubscriptionEntity signalEventSubscriptionEntity in signalEvents) { // 信号事件是多播,消息事件是单播,所以这里应当只需要GlobalScoped,后增加的 // execionId也可以讲信号事件用于单播. // We only throw the event to globally scoped signals. // Process instance scoped signals must be thrown within the process itself if (string.IsNullOrWhiteSpace(executionId) == false || signalEventSubscriptionEntity.GlobalScoped) { Context.ProcessEngineConfiguration.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateSignalEvent(ActivitiEventType.ACTIVITY_SIGNALED, signalEventSubscriptionEntity.ActivityId, eventName, payload, signalEventSubscriptionEntity.ExecutionId, signalEventSubscriptionEntity.ProcessInstanceId, signalEventSubscriptionEntity.ProcessDefinitionId)); eventSubscriptionEntityManager.EventReceived(signalEventSubscriptionEntity, payload, async); } } return(null); }