// Copyright (c) Microsoft Corporation. All rights reserved. // AgentsMetadata.cs using System.Collections.Concurrent; using Google.Protobuf.Reflection; namespace Microsoft.AutoGen.RuntimeGateway.Grpc.Tests; /// /// Represents a collection of event types and their associated metadata. /// public sealed class AgentsMetadata { /// /// Initializes a new instance of the class. /// /// The type registry containing protobuf type information. /// A dictionary mapping event names to their corresponding types. /// A dictionary mapping types to a set of event names associated with those types. /// A dictionary mapping types to a set of topics associated with those types. /// A dictionary mapping types to a set of topics associated with those types. /// public AgentsMetadata( TypeRegistry typeRegistry, Dictionary types, Dictionary> eventsMap, Dictionary> topicsMap, Dictionary> topicsPrefixMap) { TypeRegistry = typeRegistry; _types = new(types); _eventsMap = new(eventsMap); _topicsMap = new(topicsMap); _topicsPrefixMap = new(topicsPrefixMap); } /// /// Gets the type registry containing protobuf type information. /// public TypeRegistry TypeRegistry { get; } private ConcurrentDictionary _types; private ConcurrentDictionary> _eventsMap; private ConcurrentDictionary> _topicsMap; private ConcurrentDictionary> _topicsPrefixMap; /// /// Checks if a given type handles a specific event name. /// /// The type to check. /// The event name to check. /// true if the type handles the event name; otherwise, false. public bool CheckIfTypeHandles(Type type, string eventName) { if (_eventsMap.TryGetValue(type, out var events)) { return events.Contains(eventName); } return false; } /// /// Gets the event type by its name. /// /// The name of the event type. /// The event type if found; otherwise, null. public Type? GetEventTypeByName(string type) { if (_types.TryGetValue(type, out var eventType)) { return eventType; } return null; } public HashSet? GetEventsForAgent(Type agent) { if (_eventsMap.TryGetValue(agent, out var events)) { return events; } return null; } public HashSet? GetTopicsForAgent(Type agent) { if (_topicsMap.TryGetValue(agent, out var topics)) { return topics; } return null; } public HashSet? GetTopicsPrefixForAgent(Type type) { if (_topicsPrefixMap.TryGetValue(type, out var topics)) { return topics; } return null; } }