2025-01-27 17:26:21 -05:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
// Checker.cs
|
|
|
|
|
2025-01-30 19:04:26 -05:00
|
|
|
#region snippet_Checker
|
2025-01-27 17:26:21 -05:00
|
|
|
using Microsoft.AutoGen.Contracts;
|
|
|
|
using Microsoft.AutoGen.Core;
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
using TerminationF = System.Func<int, bool>;
|
|
|
|
|
2025-01-30 19:04:26 -05:00
|
|
|
namespace GettingStartedSample;
|
2025-01-27 17:26:21 -05:00
|
|
|
|
|
|
|
[TypeSubscription("default")]
|
|
|
|
public class Checker(
|
|
|
|
AgentId id,
|
|
|
|
IAgentRuntime runtime,
|
|
|
|
IHostApplicationLifetime hostApplicationLifetime,
|
|
|
|
TerminationF runUntilFunc
|
|
|
|
) :
|
|
|
|
BaseAgent(id, runtime, "Modifier", null),
|
|
|
|
IHandle<CountUpdate>
|
|
|
|
{
|
|
|
|
public async ValueTask HandleAsync(CountUpdate item, MessageContext messageContext)
|
|
|
|
{
|
|
|
|
if (!runUntilFunc(item.NewCount))
|
|
|
|
{
|
|
|
|
Console.WriteLine($"\nChecker:\n{item.NewCount} passed the check, continue.");
|
|
|
|
await this.PublishMessageAsync(new CountMessage { Content = item.NewCount }, new TopicId("default"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Console.WriteLine($"\nChecker:\n{item.NewCount} failed the check, stopping.");
|
|
|
|
hostApplicationLifetime.StopApplication();
|
|
|
|
}
|
|
|
|
}
|
2025-01-27 19:27:01 -05:00
|
|
|
}
|
2025-01-30 19:04:26 -05:00
|
|
|
#endregion snippet_Checker
|