Hermod
A cross-platform, modular and fully GDPR-compliant email archival solution!
Loading...
Searching...
No Matches
Hermod.PluginFramework.PluginDelegator Class Reference

Allows delegating topics and command execution requests from plugins through Hermod to other plugins. More...

Inheritance diagram for Hermod.PluginFramework.PluginDelegator:
Hermod.Core.Delegation.IPluginDelegator Hermod.Core.Delegation.IMessagePublished

Public Member Functions

 PluginDelegator (IPlugin plugin, ILogger? logger=null)
 Instantiates a new instance of this class.
 
void SubscribeTopic (string topicName)
 Allows a plugin to subscribe to an individual topic.
Parameters
topicNameThe topic to subscribe to
Exceptions
Exceptions.MalformedTopicExceptionIf the topic does not meet the topic string requirements.

 
void SubscribeTopics (params string[] topics)
 Allows a plugin to subscribe to multiple individual topics.This method will fail silently and ignore any non-conforming topics.
 
void UnsubscribeTopic (string topicName)
 Allows a plugin to unsubscribe from a single topic.
Parameters
topicName

 
void PublishMessage (string topic, object? message)
 Allows a plugin to publish a message on a given topic.
Parameters
topicThe topic to publish to.
messageThe message to publish to any subscribed plugins.

 
ICommandResult ExecuteCommand (params string[] command)
 Executes a single command.If command execution has been disabled for this plugin, then a Exceptions.CommandExecutionException will be raised.
 
void Information (string? msg)
 Logs an information message to the logger.This will prefix the message with [name of plugin].
 
void Debug (string? msg)
 Logs a debug message to the logger.This will prefix the message with [name of plugin].
 
void Error (string? msg)
 Logs an error message to the logger.This will prefix the message with [name of plugin].
 
void Warning (string? msg)
 Logs a warning message to the logger.This will prefix the message with [name of plugin].
 
void Trace (string? msg)
 Logs a trace message to the logger.This will prefix the message with [name of plugin].
 
GetApplicationConfig< T > (string config)
 Retrieves an application configuration value.
Template Parameters
TThe type of the config.
Parameters
configThe config name.
Returns
The desired configuration.
Exceptions
ExceptionIf an error occurs.

 
bool TryGetApplicationConfig< T > (string config, out T? value)
 Tries to retrieve an application configuration value.
Template Parameters
TThe type of the config.
Parameters
configThe config name.
valueThe config value.
Returns
true
if retrieving the configuration was successful.
false
otherwise.

 
void SubscribeTopic (string topicName)
 Allows a plugin to subscribe to an individual topic.
 
void SubscribeTopics (params string[] topics)
 Allows a plugin to subscribe to multiple individual topics.
 
void UnsubscribeTopic (string topicName)
 Allows a plugin to unsubscribe from a single topic.
 
void PublishMessage (string topic, object? message)
 Allows a plugin to publish a message on a given topic.
 
ICommandResult ExecuteCommand (params string[] command)
 Executes a single command.
 
GetApplicationConfig< T > (string config)
 Retrieves an application configuration value.
 
bool TryGetApplicationConfig< T > (string config, out T? value)
 Tries to retrieve an application configuration value.
 
void Information (string? msg)
 Logs an information message to the logger.
 
void Debug (string? msg)
 Logs a debug message to the logger.
 
void Error (string? msg)
 Logs an error message to the logger.
 
void Warning (string? msg)
 Logs a warning message to the logger.
 
void Trace (string? msg)
 Logs a trace message to the logger.
 

Package Functions

void OnMessageReceived (MessageReceivedEventArgs e)
 

Properties

IPlugin Plugin [get]
 
ILogger? Logger [get]
 

Events

MessageReceivedEventHandlerMessageReceived
 
- Events inherited from Hermod.Core.Delegation.IMessagePublished
MessageReceivedEventHandlerMessageReceived
 An event that is fired by Hermod when a message was published by a plugin or Hermod.
 

Detailed Description

Allows delegating topics and command execution requests from plugins through Hermod to other plugins.

Definition at line 13 of file PluginDelegator.cs.

Constructor & Destructor Documentation

◆ PluginDelegator()

Hermod.PluginFramework.PluginDelegator.PluginDelegator ( IPlugin  plugin,
ILogger?  logger = null 
)
inline

Instantiates a new instance of this class.

Parameters
pluginThe plugin this delegator handles.

Definition at line 22 of file PluginDelegator.cs.

Member Function Documentation

◆ Debug()

void Hermod.PluginFramework.PluginDelegator.Debug ( string?  msg)

Logs a debug message to the logger.This will prefix the message with [name of plugin].

Implements Hermod.Core.Delegation.IPluginDelegator.

Referenced by Hermod.PluginFramework.PluginDelegator.SubscribeTopics().

◆ Error()

void Hermod.PluginFramework.PluginDelegator.Error ( string?  msg)

Logs an error message to the logger.This will prefix the message with [name of plugin].

Implements Hermod.Core.Delegation.IPluginDelegator.

Referenced by Hermod.PluginFramework.PluginDelegator.SubscribeTopics().

◆ ExecuteCommand()

ICommandResult Hermod.PluginFramework.PluginDelegator.ExecuteCommand ( params string[]  command)

Executes a single command.If command execution has been disabled for this plugin, then a Exceptions.CommandExecutionException will be raised.

Implements Hermod.Core.Delegation.IPluginDelegator.

◆ GetApplicationConfig< T >()

T Hermod.PluginFramework.PluginDelegator.GetApplicationConfig< T > ( string  config)

Retrieves an application configuration value.

Template Parameters
TThe type of the config.
Parameters
configThe config name.
Returns
The desired configuration.
Exceptions
ExceptionIf an error occurs.

Implements Hermod.Core.Delegation.IPluginDelegator.

Referenced by Hermod.PluginFramework.PluginDelegator.TryGetApplicationConfig< T >().

◆ Information()

void Hermod.PluginFramework.PluginDelegator.Information ( string?  msg)

Logs an information message to the logger.This will prefix the message with [name of plugin].

Implements Hermod.Core.Delegation.IPluginDelegator.

◆ OnMessageReceived()

void Hermod.PluginFramework.PluginDelegator.OnMessageReceived ( MessageReceivedEventArgs  e)
package

◆ PublishMessage()

void Hermod.PluginFramework.PluginDelegator.PublishMessage ( string  topic,
object?  message 
)

Allows a plugin to publish a message on a given topic.

Parameters
topicThe topic to publish to.
messageThe message to publish to any subscribed plugins.

Implements Hermod.Core.Delegation.IPluginDelegator.

◆ SubscribeTopic()

void Hermod.PluginFramework.PluginDelegator.SubscribeTopic ( string  topicName)

Allows a plugin to subscribe to an individual topic.

Parameters
topicNameThe topic to subscribe to
Exceptions
Exceptions.MalformedTopicExceptionIf the topic does not meet the topic string requirements.

Implements Hermod.Core.Delegation.IPluginDelegator.

◆ SubscribeTopics()

void Hermod.PluginFramework.PluginDelegator.SubscribeTopics ( params string[]  topics)
inline

Allows a plugin to subscribe to multiple individual topics.This method will fail silently and ignore any non-conforming topics.

Implements Hermod.Core.Delegation.IPluginDelegator.

Definition at line 38 of file PluginDelegator.cs.

38 {
39 foreach (var topic in topics) {
40 try { PluginRegistry.Instance.AddSubscription(Plugin, topic); } catch (Exception ex) {
41 Error($"Subscription failed: {ex.Message}");
42 Debug($"Stacktrace: {ex.StackTrace}");
43 }
44 }
45 }
void Debug(string? msg)
Logs a debug message to the logger.This will prefix the message with [name of plugin].
void Error(string? msg)
Logs an error message to the logger.This will prefix the message with [name of plugin].

References Hermod.PluginFramework.PluginRegistry.AddSubscription(), Hermod.PluginFramework.PluginDelegator.Debug(), Hermod.PluginFramework.PluginDelegator.Error(), and Hermod.PluginFramework.PluginRegistry.Instance.

◆ Trace()

void Hermod.PluginFramework.PluginDelegator.Trace ( string?  msg)

Logs a trace message to the logger.This will prefix the message with [name of plugin].

Implements Hermod.Core.Delegation.IPluginDelegator.

◆ TryGetApplicationConfig< T >()

bool Hermod.PluginFramework.PluginDelegator.TryGetApplicationConfig< T > ( string  config,
out T?  value 
)
inline

Tries to retrieve an application configuration value.

Template Parameters
TThe type of the config.
Parameters
configThe config name.
valueThe config value.
Returns
true
if retrieving the configuration was successful.
false
otherwise.

Implements Hermod.Core.Delegation.IPluginDelegator.

Definition at line 75 of file PluginDelegator.cs.

75 {
76 try {
77 value = GetApplicationConfig<T>(config);
78 } catch {
79 value = default;
80 return false;
81 }
82
83 return true;
84 }
T GetApplicationConfig< T >(string config)
Retrieves an application configuration value.The desired configuration.

References Hermod.PluginFramework.PluginDelegator.GetApplicationConfig< T >().

◆ UnsubscribeTopic()

void Hermod.PluginFramework.PluginDelegator.UnsubscribeTopic ( string  topicName)

Allows a plugin to unsubscribe from a single topic.

Parameters
topicName

Implements Hermod.Core.Delegation.IPluginDelegator.

◆ Warning()

void Hermod.PluginFramework.PluginDelegator.Warning ( string?  msg)

Logs a warning message to the logger.This will prefix the message with [name of plugin].

Implements Hermod.Core.Delegation.IPluginDelegator.

Property Documentation

◆ Logger

ILogger? Hermod.PluginFramework.PluginDelegator.Logger
getpackage

Definition at line 16 of file PluginDelegator.cs.

16{ get; }

◆ Plugin

IPlugin Hermod.PluginFramework.PluginDelegator.Plugin
getpackage

Definition at line 15 of file PluginDelegator.cs.

15{ get; }

Event Documentation

◆ MessageReceived

MessageReceivedEventHandler? Hermod.PluginFramework.PluginDelegator.MessageReceived

Definition at line 29 of file PluginDelegator.cs.


The documentation for this class was generated from the following file: