private static async Task CreerFamilleCommandAsync(string familleName) { var result = await CoreDispatcher.DispatchCommandAsync(new CreerFamilleCommand(familleName)); if (!result) { var color = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.DarkRed; string raisonText = string.Empty; if (result is Result <FamilleNonCreeeCar> resultErreurFamille) { raisonText = resultErreurFamille.Value == FamilleNonCreeeCar.FamilleDejaExistante ? "cette famille existe déjà." : "le nom de la famille est incorrect."; } if (!string.IsNullOrWhiteSpace(raisonText)) { Console.WriteLine($"La famille {familleName} n'a pas pu être créée car {raisonText}"); } Console.ForegroundColor = color; } }
public async Task CoreDispatcher_DispatchCommandAsync_AsExpected() { var cmd = new TestCommand(); ICommand callbackCommand = null; var cg = new DispatcherConfigurationBuilder(); CoreDispatcher.OnCommandDispatched += (c) => { callbackCommand = c; return(Task.FromResult(Result.Ok())); }; await CoreDispatcher.DispatchCommandAsync(cmd).ConfigureAwait(false); var elapsed = 0; while (callbackCommand == null && elapsed < 2000) { await Task.Delay(10); elapsed += 10; } callbackCommand.Should().NotBeNull(); }
public async Task DispatchRangeAsync() { await CoreDispatcher.DispatchCommandAsync(new Cmd()); await CoreDispatcher.DispatchCommandAsync(new Cmd()); await CoreDispatcher.DispatchCommandAsync(new Cmd()); }
public MainPage() { InitializeComponent(); CoreDispatcher.AddHandlerToDispatcher(this); SayHelloBtn.Clicked += async(s, e) => { await CoreDispatcher.DispatchCommandAsync(new SayHello()); }; }
private static async Task Main(string[] args) { bool automaticConfig = ProgramMenus.DrawChoiceMenu(); if (automaticConfig) { System.Console.ForegroundColor = ConsoleColor.DarkGreen; System.Console.WriteLine("Automatic configuration will be applied with the following : "); System.Console.WriteLine("\tDispatcher will show error in console"); System.Console.WriteLine("\tInMemory events & commands bus will be used for anything"); System.Console.WriteLine("\tEF Core with SQL Server will be used as repositories"); System.Console.WriteLine("\tEF Core with SQL Server will be used as event store"); System.Console.WriteLine("\tAutofac will be used as ioc container"); System.Console.WriteLine("System is initializing, please wait ..."); System.Console.ForegroundColor = ConsoleColor.White; new Bootstrapper() .ConfigureDispatcher(GetCoreDispatcherConfiguration()) .UseInMemoryEventBus(GetInMemoryEventBusConfiguration()) .UseInMemoryCommandBus() .UseEFCoreAsMainRepository(new AppDbContext()) .UseEFCoreAsEventStore(new EFEventStoreOptions(opt => opt.UseSqlServer(Consts.CONST_EVENT_DB_CONNECTION_STRING))) .UseAutofacAsIoC(c => { }) .Bootstrapp(); } else { ProgramMenus.DrawConfigurationMenu(); } System.Console.Clear(); using (var ctx = new AppDbContext()) { await ctx.Database.MigrateAsync().ConfigureAwait(false); } System.Console.WriteLine("Message manager"); System.Console.WriteLine("Enter '/q' to exit system"); string message = string.Empty; while (true) { System.Console.WriteLine("Enter your message to be proceed by system : "); message = System.Console.ReadLine(); if (message == "/q") { break; } else if (!string.IsNullOrWhiteSpace(message)) { await CoreDispatcher.DispatchCommandAsync(new SendMessageCommand(message)).ConfigureAwait(false); } } }
/// <summary> /// Helper method to dispatch a command through Saga custom dispatcher or, if not defined, CoreDispatcher. /// </summary> /// <param name="command">Command to dispatch.</param> protected Task DispatchCommandAsync(ICommand command) { if (_dispatcher != null) { return(_dispatcher.DispatchCommandAsync(command, this)); } else { return(CoreDispatcher.DispatchCommandAsync(command, this)); } }
public async Task AutoLoad_Should_Enable_Bus_WithDefaultConfig() { AutoLoadCommandHandler.Called = false; try { new Bootstrapper(new BootstrapperOptions { AutoLoad = true }).Bootstrapp(); await CoreDispatcher.DispatchCommandAsync(new AutoLoadCommand()); AutoLoadCommandHandler.Called.Should().BeTrue(); } finally { AutoLoadCommandHandler.Called = false; } }
private static async Task CreerPersonneAsync(NomFamille nomFamille) { Console.WriteLine("Veuillez entrer le nom de la personne à créer"); var prenom = Console.ReadLine(); Console.WriteLine("Veuillez entrer le lieu de naissance de la personne à créer"); var lieu = Console.ReadLine(); Console.WriteLine("Veuillez entrer la date de naissance (dd/MM/yyyy)"); DateTime date = DateTime.MinValue; DateTime.TryParseExact(Console.ReadLine(), "dd/MM/yyyy", CultureInfo.GetCultureInfo("fr-FR"), DateTimeStyles.None, out date); if (!string.IsNullOrWhiteSpace(prenom) && !string.IsNullOrWhiteSpace(lieu) && date != DateTime.MinValue) { var result = await CoreDispatcher.DispatchCommandAsync( new AjouterPersonneCommand(nomFamille, prenom, lieu, date)); if (!result) { Console.ForegroundColor = ConsoleColor.Red; var message = $"La personne n'a pas pu être ajoutée à la famille {nomFamille.Value}"; if (result is Result <PersonneNonAjouteeCar> resultRaison) { switch (resultRaison.Value) { case PersonneNonAjouteeCar.InformationsDeNaissanceInvalides: message += " car les informations de naissance sont invalides"; break; case PersonneNonAjouteeCar.PersonneExistante: message += " car cette personne existe déjà dans cette famille"; break; case PersonneNonAjouteeCar.PrenomInvalide: message += " car son prénom n'est pas reconnu valide"; break; } } Console.WriteLine(message); } } }
public async Task Ajouter_Personne_Should_Publish_Event_PersonneAjoute() { new Bootstrapper() .UseInMemoryEventBus() .UseInMemoryCommandBus() .UseAutofacAsIoC(_ => { }) .UseEFCoreAsEventStore( new CQELight.EventStore.EFCore.EFEventStoreOptions( c => c.UseSqlite("FileName=events_tests.db", opts => opts.MigrationsAssembly(typeof(FamilleIntegrationTests).Assembly.GetName().Name)), archiveBehavior: CQELight.EventStore.SnapshotEventsArchiveBehavior.Delete)) .Bootstrapp(); await CoreDispatcher.DispatchCommandAsync(new CreerFamilleCommand("UnitTest")); var command = new AjouterPersonneCommand("UnitTest", "First", "Paris", new DateTime(1965, 12, 03)); var evt = await Test.WhenAsync(() => CoreDispatcher.DispatchCommandAsync(command)) .ThenEventShouldBeRaised <PersonneAjoutee>(); evt.Prenom.Should().Be("First"); evt.DateNaissance.Should().BeSameDateAs(new DateTime(1965, 12, 03)); evt.LieuNaissance.Should().Be("Paris"); }
public Task DispatchAsync() { return(CoreDispatcher.DispatchCommandAsync(new Cmd())); }