public async Task<bool> HandleEvent(string eventName, ICommandAsync command) { //var serializedEvent = JsonConvert.SerializeObject(command, Formatting.Indented); // TODO: Consider how to implement the sort of transaction scope for failing await EventStore.PersistEvent(command); await EventQueue.Enqueue(eventName, command); return true; }
public Task ProcessAsync(ICommandAsync command, CancellationToken token = default(CancellationToken)) { if (command == null) { throw new ArgumentNullException("command"); } var handlerType = typeof(ICommandHandlerAsync <>).MakeGenericType(command.GetType()); dynamic handler = _serviceProvider.GetService(handlerType); return(handler.Handle((dynamic)command, (dynamic)token)); }
static async Task <int> Main(string[] args) { Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; var tw = new TextWriterTraceListener(Console.Out); tw.TraceOutputOptions |= TraceOptions.None; Trace.Listeners.Add(tw); Trace.AutoFlush = true; Trace.Indent(); // Setup var httpClient = new HttpClient(); using CsvFileService fileService = new CsvFileService(httpClient); var app = new CommandLineApplication { Name = "TW ING Coding Challenge", Description = "The TeamWildenberg console app for the different assignments in the ING Coding Challenge" }; app.HelpOption("-?|-h|--help"); var versionOption = app.Option("-v|--version", "Check which version we are running", CommandOptionType.NoValue); app.OnExecute(() => { return(0); }); app.Execute(args); ICommandAsync cmd = null; if (versionOption.HasValue()) { cmd = new AssemblyVersionCommand(); } else { cmd = new PrintOrdersCommand(fileService); } return(await cmd.Execute().ConfigureAwait(false)); }
public async Task <Result <TResult> > DispatchAsync <TResult>(ICommandAsync <TResult> command) where TResult : struct { using var scope = _provider.CreateScope(); var type = typeof(ICommandHandlerAsync <,>); var handlerType = type.MakeGenericType(command.GetType(), typeof(TResult)); var handler = scope.ServiceProvider.GetRequiredService(handlerType); var handle = handlerType.GetMethod("HandleAsync"); if (handle == null) { throw new InvalidOperationException( $"Method 'HandleAsync' not found on type {handlerType.FullName}"); } var result = await(Task <Result <TResult> >) handle.Invoke(handler, new object[] { command }); return(result); }
public async Task ExecuteAsync(ICommandAsync command) { if (this.externalTransactionScope != null) { using (var connection = await this.connectionFactory.GetOpenConnectionAsync()) { await command.ExecuteAsync(connection); } } else { using (var transactionScope = new TransactionScope(TransactionScopeOption.Required)) { using (var connection = await this.connectionFactory.GetOpenConnectionAsync()) { await command.ExecuteAsync(connection); } transactionScope.Complete(); } } }
public async Task <T> ExecuteAsync <T>(ICommandAsync <T> command) { if (this.externalTransactionScope != null) { using (var connection = await this.connectionFactory.GetOpenConnectionAsync()) { T result = await command.ExecuteAsync(connection); return(result); } } using (var transactionScope = new TransactionScope(TransactionScopeOption.Required)) { using (var connection = await this.connectionFactory.GetOpenConnectionAsync()) { T result = await command.ExecuteAsync(connection); transactionScope.Complete(); return(result); } } }
/// <summary> /// Registers then asynchronously executes the current collection of registered commands /// </summary> /// <param name="command">A command to register</param> /// <returns>List of integers returned from each registered command</returns> public async Task <IEnumerable <int> > ExecuteAsync(ICommandAsync command) { Register(command); return(await ExecuteAsync()); }
public CommandResult(ICommandAsync command, Exception exception = null) { Command = command; Exception = exception; }
/// <summary> /// Executes a prebuilt <see cref="ICommandAsync" /> /// </summary> /// <param name="commandAsync">The command asynchronous.</param> /// <returns>Task<System.Int32>.</returns> public virtual async Task <int> ExecuteAsync(ICommandAsync commandAsync) { return(await commandAsync.ExecuteAsync(Executor)); }
public static async Task ExecuteAsync(this CloudTable table, ICommandAsync <CloudTable> command) { await command.ExecuteAsync(table); }
public static void SetPreviewMouseRightButtonDownCommand(DependencyObject o, ICommandAsync <MouseButtonEventArgs> value) { o.SetValue(PreviewMouseRightButtonDownCommandProperty, value); }
protected async Task<bool> ExecuteAsync(ICommandAsync cmd) { return await cmd.ExecuteAsync(_eventHandler); }
public bool Execute(ICommandAsync cmd) { return cmd.ExecuteAsync(_eventHandler).Result; }
public static void SetLoadedCommand(DependencyObject o, ICommandAsync <RoutedEventArgs> value) { o.SetValue(LoadedCommandProperty, value); }
public static void SetInitializedCommand(DependencyObject o, ICommandAsync <EventArgs> value) { o.SetValue(InitializedCommandProperty, value); }
public static void SetContextMenuClosingCommand(DependencyObject o, ICommandAsync <ContextMenuEventArgs> value) { o.SetValue(ContextMenuClosingCommandProperty, value); }
public static void SetSizeChangedCommand(DependencyObject o, ICommandAsync <SizeChangedEventArgs> value) { o.SetValue(SizeChangedCommandProperty, value); }
public static void SetMouseLeaveCommand(DependencyObject o, ICommandAsync <MouseEventArgs> value) { o.SetValue(MouseLeaveCommandProperty, value); }
public static void SetPreviewMouseWheelCommand(DependencyObject o, ICommandAsync <MouseWheelEventArgs> value) { o.SetValue(PreviewMouseWheelCommandProperty, value); }
public MainWindowViewModel(ICashValueNumberToWordsConverterServiceAdapter converterServiceAdapter) { _converterServiceAdapter = converterServiceAdapter; _converterServiceAdapter.ServerAddress = Properties.Settings.Default.ServerAddress; ConvertCashValue = new RelayCommandAsync(Convert, CanConvert, HandleError); }
public async Task ExecuteCommandAsync <TRequest>(ICommandAsync <TRequest> command, TRequest request) { logger.Log(command, request); await command.Execute(request); }
public CommandInvokerAsync(ICommandAsync startCommandAsync) { this.startCommandAsync = startCommandAsync; }
public static void SetClosingCommand(DependencyObject o, ICommandAsync <CancelEventArgs> value) { o.SetValue(ClosingCommandProperty, value); }
public static void SetPreviewKeyDownCommand(DependencyObject o, ICommandAsync <KeyEventArgs> value) { o.SetValue(PreviewKeyDownCommandProperty, value); }