You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Checker.cs 1.1 kB

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Checker.cs
  3. using Microsoft.AutoGen.Contracts;
  4. using Microsoft.AutoGen.Core;
  5. using Microsoft.Extensions.Hosting;
  6. using TerminationF = System.Func<int, bool>;
  7. namespace GettingStartedGrpcSample;
  8. [TypeSubscription("default")]
  9. public class Checker(
  10. AgentId id,
  11. IAgentRuntime runtime,
  12. IHostApplicationLifetime hostApplicationLifetime,
  13. TerminationF runUntilFunc
  14. ) :
  15. BaseAgent(id, runtime, "Modifier", null),
  16. IHandle<Events.CountUpdate>
  17. {
  18. public async ValueTask HandleAsync(Events.CountUpdate item, MessageContext messageContext)
  19. {
  20. if (!runUntilFunc(item.NewCount))
  21. {
  22. Console.WriteLine($"\nChecker:\n{item.NewCount} passed the check, continue.");
  23. await this.PublishMessageAsync(new Events.CountMessage { Content = item.NewCount }, new TopicId("default"));
  24. }
  25. else
  26. {
  27. Console.WriteLine($"\nChecker:\n{item.NewCount} failed the check, stopping.");
  28. hostApplicationLifetime.StopApplication();
  29. }
  30. }
  31. }