5 using Core.Commands.Results;
8 using System.Text.RegularExpressions;
10 partial class PluginRegistry {
15 internal Dictionary<string, List<IPlugin>>
TopicSubscriptions {
get; } =
new Dictionary<string, List<IPlugin>>();
24 if (!TopicIsValid(ref topic)) {
33 if (subList.Contains(plugin)) {
return; }
45 if (!TopicIsValid(ref topic)) {
52 if (!subList.Contains(plugin)) {
return; }
54 subList.Remove(plugin);
57 [GeneratedRegex(
"^[A-z0-9-_Ä-ü]+$", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)]
58 public static partial Regex TopicRegex();
65 bool TopicIsValid(ref
string topic) {
67 string.IsNullOrEmpty(topic) ||
68 string.IsNullOrWhiteSpace(topic) ||
75 var splitTopic = topic.Split(
'/').Where(x => x !=
"/").Where(x => !TopicRegex().IsMatch(x));
77 return splitTopic.Count() > 0;
80 internal void OnMessagePublished(
string topic,
object? message) {
81 if (!TopicIsValid(ref topic)) {
throw new MalformedTopicException(topic,
"The given topic is invalid!"); }
88 var eventArgs =
new MessageReceivedEventArgs(topic, message);
90 PluginDelegators.FirstOrDefault(p => p.Plugin == subscriber)?.OnMessageReceived(eventArgs);
94 internal ICommandResult ExecuteCommand(params
string[] commands) {
95 throw new NotImplementedException();
Dictionary< string, List< IPlugin > > TopicSubscriptions
The topic subscription list.
void AddSubscription(IPlugin plugin, string topic)
Adds a plugin to a topic subscription list.
void RemoveSubscription(IPlugin plugin, string topic)
Removes a plugin from a topic subscription list.
List< PluginDelegator > PluginDelegators
Basic contract between Hermod and any plugins.