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

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