Events Between Plugins

Tags: v9preview2 v9

In the V9Preview2 API, the ability to create and use custom events has been added.

The following operations have been introduced for this purpose:

GetExternalNotificationSubscription(string subscriptionName) - this operation allows subscribing to a custom event with the name subscriptionName. If it does not exist, it will register it and immediately subscribe to it. The maximum length of the event name is 256 characters.

Example usage:

IDisposable subscription;
subscription =
	PluginContext.Operations
		.GetExternalNotificationSubscription(subscriptionName)
		.Subscribe(Console.WriteLine);

GetAllExternalNotificationsNames() - this operation allows retrieving a list of all registered event names on the terminal.

InvokeExternalNotification(string subscriptionName, string notificationData) - this operation triggers the notification of a custom event with the name subscriptionName to all its subscribers and passes the information in text form notificationData. The maximum length of the information is 32000 characters.

Example usage:

var subscriptionName = PluginContext.Operations.GetAllExternalNotificationsNames().Last();
PluginContext.Operations.InvokeExternalNotification(subscriptionName, Guid.NewGuid().ToString());

It is important to know that events are shared across all terminals in the group, allowing notifications to be sent not only to local plugins but also to plugins of other terminals. Notifications can also be triggered from any plugin of the terminal group, even if that plugin is not subscribed to the event.

In the SamplePlugin, a sample of using custom events has been added.