-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
680c3d0
commit 851f8c7
Showing
10 changed files
with
102 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
dotnet/test/Microsoft.AutoGen.Runtime.Grpc.Tests/TestAgent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// TestAgent.cs | ||
|
||
using System.Collections.Concurrent; | ||
using Microsoft.AutoGen.Core; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using Tests.Events; | ||
|
||
namespace Microsoft.AutoGen.Runtime.Grpc.Tests; | ||
|
||
public class PBAgent([FromKeyedServices("EventTypes")] EventTypes eventTypes, ILogger<Agent>? logger = null) | ||
: Agent(eventTypes, logger) | ||
, IHandle<NewMessageReceived> | ||
, IHandle<GoodBye> | ||
{ | ||
public async Task Handle(NewMessageReceived item, CancellationToken cancellationToken = default) | ||
{ | ||
ReceivedMessages[AgentId.Key] = item.Message; | ||
var hello = new Hello { Message = item.Message }; | ||
await PublishEventAsync(hello); | ||
} | ||
public Task Handle(GoodBye item, CancellationToken cancellationToken) | ||
{ | ||
_logger.LogInformation($"Received GoodBye message {item.Message}"); | ||
return Task.CompletedTask; | ||
} | ||
|
||
public static ConcurrentDictionary<string, object> ReceivedMessages { get; private set; } = new(); | ||
} | ||
|
||
public class GMAgent([FromKeyedServices("EventTypes")] EventTypes eventTypes, ILogger<Agent>? logger = null) | ||
: Agent(eventTypes, logger) | ||
, IHandle<Hello> | ||
{ | ||
public async Task Handle(Hello item, CancellationToken cancellationToken) | ||
{ | ||
_logger.LogInformation($"Received Hello message {item.Message}"); | ||
ReceivedMessages[AgentId.Key] = item.Message; | ||
await PublishEventAsync(new GoodBye { Message = "" }); | ||
} | ||
|
||
public static ConcurrentDictionary<string, object> ReceivedMessages { get; private set; } = new(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters