How to setup Plugin events

I want to set up events specific to a plugin that I can simply retrieve and configure to listen to. I’ve already established the event listeners, but I would like to configure these events within Milestone.

**Example Use Case:**

The plugin should create events upon initialisation or automatically recognise them while the plugin is installed. Under “Rules and Events,” users should see a section for the plugin labelled as [Plugin Name], displaying a list of the events.

In the Milestone Plugins section, users can navigate to [Plugin Name] and either select “View”(or access the events directly under “Rules and Events” => [Plugin Name]). Here, the user will be able to link those events to selected cameras. When my backend detects an event from the external device, I can then send the event to the Smart Client view (to display the payload) or to the Alarm Manager (if it is processed as an alarm).

While it is possible to handle this without configuring events within Milestone. I’m thinking of eventually having the option to set up rules for these events.

How do I set up these events in the plugin? I’m not sure if this is the right direction, but I read about the following.

    // newItem (Item) created "Event"
    EventSource eventSource = new EventSource() { FQID = newItem.FQID, Name = newItem.Name };
 
    EventHeader eventHeader = new EventHeader()
    {
        ID = Guid.NewGuid(),
        Class = EventProjectDefinition.EventProjecEventGroup.ToString(),
        Type = "Event Project",
        Timestamp = DateTime.UtcNow,
        Message = "EventProject Event 1 Triggered",
        MessageId = EventProjectDefinition.EventProjecEvent1,
        Name = "EventProject Event 1",
        Source = eventSource,
        Priority = 2,
        PriorityName = "Medium",
    };
 
    BaseEvent baseEvent = new BaseEvent
    {
        EventHeader = eventHeader,
    };
 
    EnvironmentManager.Instance.SendMessage(
        new VideoOS.Platform.Messaging.Message(MessageId.Server.NewEventCommand)
        {
            Data = baseEvent,
        }
    );

The recommended way is to create a User-defined event in the Management Client (or through code). Then use Control.TriggerCommand. This can be explored in the ConfigAccesViaSDK sample or the MessageTester plugin sample.

https://doc.developer.milestonesys.com/html/index.html?base=samples/componentsamples/configaccessviasdk/readme.html&tree=tree_2.html

https://doc.developer.milestonesys.com/html/index.html?base=samples/pluginsamples/messagetester/readme.html&tree=tree_1.html

https://github.com/milestonesys

I have a feeling that what you suggest with your code will actually inject events, but as you might have experienced, when there is no defined events setup in the system you cannot make rules that react on them or use the event to trigger alarms.

If you want guidance on doing the setup of user-defined events through code, let me know.

If you might want events that can carry more information you should explore analytics events instead of user-defined events, if that is the case, let me know, and I can point to other samples.

Hi @Bo Ellegård Andersen (Milestone Systems)​ ,

Thank you for the feedback.

Yes, my code will create or inject events that are pre-configured inside my plug-in for an external device. Essentially, I can generate the Analytics events, but the issue I have is that these events, which are specifically for the plugin, should not be listed under “Analytics Events” in the management client, but rather under “[Plugin Name] Events”.

So the flow would be as follows:

External device sends event => Plugin get the event with payload => Plugin uses the created Milestone event type (This is the part I need assistance with) => sends the event with payload to whoever is listening to the event type or the alarm manager if the event is considered an alarm by the plugin.

I hope this is more informative for you to perhaps guide me on doing the setup.

Please explore the Sensor Monitor plugin sample. It creates events that are looking much like what you describe. You can make events that have a camera as source, you do not have to have your own custom items as source. When you have seen the sample you can ask again if the sample is not complete fitting or answering how you might use these kinds of events…

https://doc.developer.milestonesys.com/html/index.html?base=samples/pluginsamples/sensormonitor/readme.html&tree=tree_1.html

Hi @Bo Ellegård Andersen (Milestone Systems)​,

I reviewed the sample and had a few questions about it.

I believe this is leading me in the right direction, but I need clarification on a few things.

In the above image, events are listed under the added Controller. How are these set up to be under the controller, and can I make it so that one device can have multiple events instead of just selecting one? The only information I can find is that there’s a resource ‘Strings.resx’ and inside the below:

 _controllerCM = new Collection<MapAlarmContextMenu>
 {
     new MapAlarmContextMenu("Power controller off", "POWEROFF", null),
     new MapAlarmContextMenu("Power controller on", "POWERON", null),
     new MapAlarmContextMenu("Start Recording", "STARTREC", null),
     new MapAlarmContextMenu("Stop Recording", "STOPREC", null),
     new MapAlarmContextMenu("Trigger event", "TRIGGEREVENT", null),
 };

I see that these events are set up within the ‘ItemManager’ using ‘GetKnownEventTypes’. Is that correct?

Hi,

In SensorMonitorControllerItemManager, there is an override method called GetKnownEventGroups. This method is used by the event server and management client to sort events into groups, and specifies which groups are used for events from this item type.

Also in SensorMonitorControllerItemManager, there is an override method called GetKnownEventTypes (Please use the culture specific overload to ensure translations for your events are correctly applied). This method is used by the event server and management client to retrieve definitions for all event types this particular item type delivers to the event server. This list is used in particular when configuring alarms.

If your events change the state of an item, those possible states should be listed in the override method GetKnownStateGroups.

The context menu items you found in the SensorMonitor sample are used to populate the context menu when an item of the Controller type is right clicked on the map. I don’t believe this is relevant for what you are trying to do. If it is, however, please note that these commands in the context menu are controlled also by the SecurityActions (the lists for Controller and Sensor are populated in the same place in the SensorMonitorDefinition), which allow granular control of who is allowed to trigger these actions. Also note that the handling of these events is back in the ItemManagers, where there is (in the Init method) an event subscription to TriggerEvent.

I hope this helps, otherwise please reach out again.

Best regards,

Simon