public async Task <TResult> Invoke <TCommand, TResult>(object sender, TCommand command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null) where TCommand : IRequest <TResult> { var payload = new UiExecutingPayload <TCommand>(sender, command); this.eventAggregator.GetEvent <UiExecutingEvent <TCommand> >().Publish(payload); if (payload.Cancel) { this.eventAggregator.GetEvent <UiCancelledEvent <TCommand> >().Publish(new UiCancelledPayload <TCommand>(sender, command)); } try { this.eventAggregator.GetEvent <UiStartedEvent <TCommand> >().Publish(new UiStartedPayload <TCommand>(sender, command)); var result = await this.mediator.Send(command, cancellationToken).ConfigureAwait(false); this.eventAggregator.GetEvent <UiExecutedEvent <TCommand, TResult> >().Publish(new UiExecutedPayload <TCommand, TResult>(sender, command, result)); this.eventAggregator.GetEvent <UiExecutedEvent <TCommand> >().Publish(new UiExecutedPayload <TCommand>(sender, command)); return(result); } catch (OperationCanceledException) { this.eventAggregator.GetEvent <UiCancelledEvent <TCommand> >().Publish(new UiCancelledPayload <TCommand>(sender, command)); throw; } catch (Exception exception) { this.eventAggregator.GetEvent <UiFailedEvent <TCommand> >().Publish(new UiFailedPayload <TCommand>(sender, command, exception)); throw; } }
public async Task Invoke <TCommand>(object sender, TCommand command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null) where TCommand : IRequest { if (this.IsCommandWithOutput(command.GetType(), out var resultType)) { // this will call the overload that returns the results var findMethod = typeof(BaseMsixHeroCommandExecutor).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic).First(m => m.Name == nameof(Invoke) && m.ReturnType.IsGenericType); findMethod = findMethod.MakeGenericMethod(typeof(TCommand), resultType); var task = (Task)findMethod.Invoke(this, new[] { sender, command, cancellationToken, progress }); if (task == null) { throw new InvalidOperationException(); } await task.ConfigureAwait(false); return; } var payload = new UiExecutingPayload <TCommand>(sender, command); this.eventAggregator.GetEvent <UiExecutingEvent <TCommand> >().Publish(payload); if (payload.Cancel) { this.eventAggregator.GetEvent <UiCancelledEvent <TCommand> >().Publish(new UiCancelledPayload <TCommand>(sender, command)); } try { this.eventAggregator.GetEvent <UiStartedEvent <TCommand> >().Publish(new UiStartedPayload <TCommand>(sender, command)); var unit = await this.mediator.Send(command, cancellationToken).ConfigureAwait(false); this.eventAggregator.GetEvent <UiExecutedEvent <TCommand> >().Publish(new UiExecutedPayload <TCommand>(sender, command)); } catch (OperationCanceledException) { this.eventAggregator.GetEvent <UiCancelledEvent <TCommand> >().Publish(new UiCancelledPayload <TCommand>(sender, command)); throw; } catch (Exception exception) { this.eventAggregator.GetEvent <UiFailedEvent <TCommand> >().Publish(new UiFailedPayload <TCommand>(sender, command, exception)); throw; } }
private void OnGetLogsCommandExecuting(UiExecutingPayload <GetLogsCommand> obj) { this.ListBox.SelectionChanged -= this.OnSelectionChanged; }