private void SetApplicationCommandResult(DomainEventHandledNotification notification) { var applicationCommandId = notification.ApplicationCommandId; var applicationCommandType = notification.ApplicationCommandType; const string prefix = "Received the domain event handled notification of application Command"; if (!ExecutingPromiseDict.TryRemove(applicationCommandId, out var executionPromise)) { _logger.LogWarning(FormatReplyMessage(notification, prefix, "but task source does not exist")); return; } var replyScheme = executionPromise.ApplicationCommand.ReplyScheme; switch (replyScheme) { case ApplicationCommandReplySchemes.None: _logger.LogWarning(FormatReplyMessage(notification, prefix, $"but the return schema is {replyScheme}")); break; case ApplicationCommandReplySchemes.OnDomainCommandHandled: _logger.LogWarning(FormatReplyMessage(notification, prefix, $"but the return schema:{replyScheme} mis-match")); break; case ApplicationCommandReplySchemes.OnDomainEventHandled: var replySchemeReceived = notification.ApplicationCommandReplyScheme; if (replyScheme != replySchemeReceived) { _logger.LogWarning(FormatReplyMessage(notification, prefix, $"but return schema mis match, expected: {replyScheme}, actual: {replySchemeReceived}")); } var result = ApplicationCommandResult.Succeed(applicationCommandId, applicationCommandType); if (!executionPromise.TrySetResult(result)) { _logger.LogError(FormatReplyMessage(notification, "Failed to set the domain command handled notification of application Command", $"ReplyScheme:{replyScheme}")); } break; default: _logger.LogWarning(FormatReplyMessage(notification, prefix, $"but the return schema:{replyScheme} not supported")); break; } }
private async Task ReplyApplicationEventAsync(IDomainEvent @event, CancellationToken token) { IDomainNotification notification; switch (@event) { case IEndSubTransactionDomainEvent endEvent: notification = new SagaTransactionDomainNotification(endEvent.Message, true); break; default: notification = new DomainEventHandledNotification(); break; } notification.FillFrom(@event); await _context.PublishDomainNotificationAsync(notification, token); }
private void ReplyApplicationEvent(IDomainEvent @event) { IDomainNotification notification; switch (@event) { case IEndSubTransactionDomainEvent endEvent: notification = new SagaTransactionDomainNotification(endEvent.Message, true); break; default: notification = new DomainEventHandledNotification(); break; } notification.FillFrom(@event); _context.PublishDomainNotification(notification); }
public void Handle(DomainEventHandledNotification notification) => SetApplicationCommandResult(notification);