Пример #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));
        }
Пример #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 SendAsync(command).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));
            }
        }
Пример #3
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, BuildCommandMessage(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));
            }
        }