Beispiel #1
0
        public async Task <CommandResult> ExecuteAsync(ICommand command, CommandReturnType commandReturnType)
        {
            Ensure.NotNull(_commandResultProcessor, "commandResultProcessor");
            var taskCompletionSource = new TaskCompletionSource <CommandResult>();

            _commandResultProcessor.RegisterProcessingCommand(command, commandReturnType, taskCompletionSource);

            try
            {
                await _sendMessageService.SendMessageAsync(Producer, "command", command.GetType().Name, BuildCommandMessage(command, true), command.AggregateRootId, command.Id, command.Items).ConfigureAwait(false);
            }
            catch
            {
                _commandResultProcessor.ProcessFailedSendingCommand(command);
                throw;
            }

            return(await taskCompletionSource.Task.ConfigureAwait(false));
        }
Beispiel #2
0
        public async Task <AsyncTaskResult <CommandResult> > ExecuteAsync(ICommand command, CommandReturnType commandReturnType)
        {
            try
            {
                Ensure.NotNull(_commandResultProcessor, "commandResultProcessor");
                var taskCompletionSource = new TaskCompletionSource <AsyncTaskResult <CommandResult> >();
                _commandResultProcessor.RegisterProcessingCommand(command, commandReturnType, taskCompletionSource);

                var result = await _sendMessageService.SendMessageAsync(_producer, CreateENodeMessage(command, true), _commandRouteKeyProvider.GetRoutingKey(command), command.Id, null).ConfigureAwait(false);

                if (result.Status == AsyncTaskStatus.Success)
                {
                    return(await taskCompletionSource.Task.ConfigureAwait(false));
                }
                _commandResultProcessor.ProcessFailedSendingCommand(command);
                return(new AsyncTaskResult <CommandResult>(result.Status, result.ErrorMessage));
            }
            catch (Exception ex)
            {
                return(new AsyncTaskResult <CommandResult>(AsyncTaskStatus.Failed, ex.Message));
            }
        }