Esempio n. 1
0
        private async Task ReplyApplicationCommandAsync(IEndSubTransactionDomainNotification notification, CancellationToken token)
        {
            var reply = new SagaTransactionDomainNotification(notification.Message);

            reply.FillFrom(notification);

            await PublishDomainNotificationAsync(reply, token);
        }
        private void SetApplicationCommandResult(SagaTransactionDomainNotification notification)
        {
            var applicationCommandId   = notification.ApplicationCommandId;
            var applicationCommandType = notification.ApplicationCommandType;

            const string prefix = "Received the saga domain 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:

                var replySchemeReceived = notification.ApplicationCommandReplyScheme;

                if (replyScheme != replySchemeReceived)
                {
                    _logger.LogWarning(FormatReplyMessage(notification, prefix, $"but return schema mis match, expected: {replyScheme}, actual: {replySchemeReceived}"));
                }

                var status = notification.IsCompleted
                        ? ApplicationCommandStatus.Succeed
                        : ApplicationCommandStatus.Failed;
                var result = new ApplicationCommandResult <string>(applicationCommandId, applicationCommandType, status, notification.Message);

                if (!executionPromise.TrySetResult(result))
                {
                    _logger.LogError(FormatReplyMessage(notification, "Failed to set the saga domain notification of application Command", $"ReplyScheme:{replyScheme}, message:{notification.Message}"));
                }

                break;

            case ApplicationCommandReplySchemes.OnDomainEventHandled:
                _logger.LogWarning(FormatReplyMessage(notification, prefix, $"but the return schema:{replyScheme} mis-match"));
                break;

            default:
                _logger.LogWarning(FormatReplyMessage(notification, prefix, $"but the return schema:{replyScheme} not supported"));
                break;
            }
        }
Esempio n. 3
0
        private async Task ReplyApplicationCommandAsync(IDomainCommand command, CancellationToken token)
        {
            IDomainNotification notification;

            switch (command)
            {
            case IEndSubTransactionDomainCommand endCommand:
                notification = new SagaTransactionDomainNotification(endCommand.Message, true);
                break;

            default:
                notification = new DomainCommandHandledNotification();
                break;
            }

            notification.FillFrom(command);

            await PublishDomainNotificationAsync(notification, token);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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(SagaTransactionDomainNotification notification) => SetApplicationCommandResult(notification);