Пример #1
0
 public void RegisterProcessingCommand(ICommand command, CommandReturnType commandReturnType, TaskCompletionSource<AsyncTaskResult<CommandResult>> taskCompletionSource)
 {
     if (!_commandTaskDict.TryAdd(command.Id, new CommandTaskCompletionSource { CommandReturnType = commandReturnType, TaskCompletionSource = taskCompletionSource }))
     {
         throw new Exception(string.Format("Duplicate processing command registration, type:{0}, id:{1}", command.GetType().Name, command.Id));
     }
 }
Пример #2
0
 public void RegisterProcessingCommand(ICommand command, CommandReturnType commandReturnType, TaskCompletionSource <CommandResult> taskCompletionSource)
 {
     if (!_commandTaskDict.TryAdd(command.Id, new CommandTaskCompletionSource {
         CommandReturnType = commandReturnType, TaskCompletionSource = taskCompletionSource
     }))
     {
         throw new Exception(string.Format("Duplicate processing command registration, type:{0}, id:{1}", command.GetType().Name, command.Id));
     }
 }
Пример #3
0
        public CommandResult Execute(ICommand command, CommandReturnType commandReturnType, int timeoutMillis)
        {
            var result = ExecuteAsync(command, commandReturnType).WaitResult(timeoutMillis);

            if (result == null)
            {
                throw new CommandExecuteTimeoutException("Command execute timeout, commandId: {0}, aggregateRootId: {1}", command.Id, command.AggregateRootId);
            }
            return(result.Data);
        }
Пример #4
0
        public Task<CommandResult> Execute(ICommand command, CommandReturnType commandReturnType)
        {
            var message = BuildCommandMessage(command);
            var taskCompletionSource = new TaskCompletionSource<CommandResult>();

            _commandResultProcessor.RegisterCommand(command, commandReturnType, taskCompletionSource);

            _producer.SendAsync(message, command.AggregateRootId).ContinueWith(sendTask =>
            {
                if (sendTask.Result.SendStatus == SendStatus.Failed)
                {
                    _commandResultProcessor.NotifyCommandSendFailed(command);
                }
            });

            return taskCompletionSource.Task;
        }
Пример #5
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));
        }
Пример #6
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);
            }
        }
Пример #7
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)).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);
            }
        }
Пример #8
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));
            }
        }
Пример #9
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));
            }
        }
Пример #10
0
 public CommandResult Execute(ICommand command, CommandReturnType commandReturnType, int timeoutMillis)
 {
     var result = ExecuteAsync(command, commandReturnType).WaitResult(timeoutMillis);
     if (result == null)
     {
         throw new CommandExecuteTimeoutException("Command execute timeout, commandId: {0}, aggregateRootId: {1}", command.Id, command.AggregateRootId);
     }
     return result.Data;
 }
 public Task<CommandResult> Execute(ICommand command, CommandReturnType commandReturnType)
 {
     throw new NotImplementedException();
 }
Пример #12
0
 public Task <AsyncTaskResult <CommandResult> > ExecuteAsync(ICommand command, CommandReturnType commandReturnType)
 {
     throw new NotImplementedException();
 }
Пример #13
0
 public CommandResult Execute(ICommand command, CommandReturnType commandReturnType, int timeoutMillis)
 {
     throw new NotImplementedException();
 }
Пример #14
0
 /// <summary>
 /// Execute a delayed command asynchronously with the specified command return type.
 /// </summary>
 /// <param name="commandService"></param>
 /// <param name="command"></param>
 /// <param name="commandReturnType"></param>
 /// <returns></returns>
 public static Task ExecuteDelayedCommandAsync(this ICommandService commandService, DelayedCommand command, CommandReturnType commandReturnType)
 {
     return(commandService.ExecuteAsync(command, commandReturnType));
 }
Пример #15
0
 public CommandResult Execute(ICommand command, CommandReturnType commandReturnType, int timeoutMillis)
 {
     throw new NotImplementedException();
 }
Пример #16
0
 public CommandResultProcessor RegisterCommand(ICommand command, CommandReturnType commandReturnType, TaskCompletionSource<CommandResult> taskCompletionSource)
 {
     _commandTaskDict.TryAdd(command.Id, new CommandTaskCompletionSource { CommandReturnType = commandReturnType, TaskCompletionSource = taskCompletionSource });
     return this;
 }