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)); } }
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)); } }
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) { 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; }
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)); }
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); } }
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); } }
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)); } }
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)); } }
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(); }
public Task <AsyncTaskResult <CommandResult> > ExecuteAsync(ICommand command, CommandReturnType commandReturnType) { throw new NotImplementedException(); }
public CommandResult Execute(ICommand command, CommandReturnType commandReturnType, int timeoutMillis) { throw new NotImplementedException(); }
/// <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)); }
public CommandResultProcessor RegisterCommand(ICommand command, CommandReturnType commandReturnType, TaskCompletionSource<CommandResult> taskCompletionSource) { _commandTaskDict.TryAdd(command.Id, new CommandTaskCompletionSource { CommandReturnType = commandReturnType, TaskCompletionSource = taskCompletionSource }); return this; }