public Task Handle(CancelTraining message, IMessageHandlerContext context) { log.Info($"Training #{message.TrainingId} was cancelled."); //TODO: Possibly publish an TrainingCancelled event? MarkAsComplete(); return(Task.CompletedTask); }
static async Task RunLoop(IEndpointInstance endpointInstance) { var lastTraining = string.Empty; while (true) { log.Info("Press 'S' to schedule a training, 'C' to cancel last scheduled training, or 'Q' to quit."); var key = Console.ReadKey(); Console.WriteLine(); switch (key.Key) { case ConsoleKey.S: // Instantiate the command var command = new ScheduleTraining { TrainingId = Guid.NewGuid().ToString() }; // Send the command log.Info($"Sending ScheduleTraining command, TrainingId = {command.TrainingId}"); await endpointInstance.Send(command) .ConfigureAwait(false); lastTraining = command.TrainingId; // Store training identifier to cancel if needed. break; case ConsoleKey.C: var cancelCommand = new CancelTraining { TrainingId = lastTraining }; await endpointInstance.Send(cancelCommand) .ConfigureAwait(false); log.Info($"Sent a correlated message to {cancelCommand.TrainingId}"); break; case ConsoleKey.Q: return; default: log.Info("Unknown input. Please try again."); break; } } }