Nevron .NET Vision Documentation
Node Event Sink Service

The node event sink service (or simply event sink) is a service, which provides centralized event handling. It is represented by the NNodeEventSinkService class. Instead of having events attached to nodes, nodes call the respective "Fire" methods of the event sink to fire the sink events and thus update subscribers. This approach has the following advantages:
Subscribing for Events

There are two ways in which you can subscribe for an event fired by the node event sink service:

  • Subscribe for a broadcased event - this is achieved by adding an event handler for one of the node events exposed by the service. For example:
    C#
    Copy Code
    ...
    // subscribe for a broadcasted event
    nodeEventSinkService.NodePropertyChanged += new NodePropertyEventHandler(OnAnyNodePropertyChanged);
    ...
    private void OnAnyNodePropertyChanged(NNodePropertyEventArgs args)
    {
    }
    
    Visual Basic
    Copy Code
    ...
    ' subscribe for a broadcasted event
    AddHandler nodeEventSinkService.NodePropertyChanged, AddressOf OnAnyNodePropertyChanged
    ...
    Private Sub OnAnyNodePropertyChanged(ByVal args As NNodePropertyEventArgs)
    End Sub
    
    The OnAnyNodePropertyChanged method will be called when a property of any of the nodes, which are connected to this service has changed. This is particularly useful if you do not want to hook/unhook the events of all nodes residing in the node scene.
  • Install an event listener - this is achieved with the help of the AddNodeEventListener method. For example:
    C#
    Copy Code
    ...
    // install node event listener for the NodePropertyChanged event
    nodeEventSinkService.AddNodeEventListener("NodePropertyChanged", node1, new NodePropertyEventHandler(OnNode1PropertyChanged));
    ...
    private void OnNode1PropertyChanged(NNodePropertyEventArgs args)
    {
    }
    
    Visual Basic
    Copy Code
    ...
    '  install node event listener for the NodePropertyChanged event
    Dim handler As NodePropertyEventHandler = AddressOf OnNode1PropertyChanged
    nodeEventSinkService.AddNodeEventListener("NodePropertyChanged", node1, handler)
    ...
    Private Sub OnNode1PropertyChanged(ByVal args As NNodePropertyEventArgs)
    End Sub
    
    The OnNode1PropertyChanged method will only be called when a property of node1 has changed. This method for event subscription is usefull if you want to monitor only the events of a particular node.

From a nodes' point of view it is enough to only call the respective FireXXX method in order to update all listeners and broadcasted event subscribers. By design the service first invokes the event handlers of the registered node listeners and then invokes the broadcasted event handlers.

Filtering Events
You can also specify a node event filter. This is achieved with the help of the NodeFilter property. If a node filter is specified (the NodeFilter property is not null), then a node event will only be fired if the node satisfies the provided filter. This helps you globally block any node event if the node for which it will be fired does not satisfy the filter criteria.
See Also

 

 


©2017. Nevron Software LLC.

Send Feedback