Event Usage Demonstration

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
nwhelchel
Sr. Member
Sr. Member
Posts: 14
Joined: 16 Oct 2012, 16:33

Event Usage Demonstration

Post by nwhelchel »

I would like to implement event handling. I see that there is some example code, etc. but I am unable to get anything to work in the example code using the Getting Started Client solution. I recently downloaded the non-beta version the the .NET SDK, but the tutorial documentation doesn't align with the example servers and it is lacking somehow in explaining what elements should be selected and what the out come should be. Can you possibly provide some guidance here to get the example Monitored Events to work. Which server to I run, what items can I select. How can I get the events to fire, etc.

Regards,
Nathan

Randy
Jr. Member
Jr. Member
Posts: 4
Joined: 27 Mar 2013, 23:57

Re: Event Usage Demonstration

Post by Randy »

This creates a simple subscription for all events with Severity > 500.
If you call the StartSimulation method on the Sample Server it will generate a SystemEvent with Severity = 700 every few seconds.

Code: Select all

Subscription subscription = new Subscription(session);

subscription.PublishingInterval = 1000;
subscription.MaxKeepAliveTime = 10000;
subscription.Lifetime = 60000;
subscription.MaxNotificationsPerPublish = 0;
subscription.Priority = 0;
subscription.PublishingEnabled = true;
subscription.NewEvents += new NewEventsEventHandler(Subscription_NewEvents);

// create subscription.
subscription.Create();

EventMonitoredItem monitoredItem = new EventMonitoredItem(ObjectIds.Server);
monitoredItem.MonitoringMode = MonitoringMode.Reporting;
monitoredItem.QueueSize = 1000;
monitoredItem.SamplingInterval = 0;

ItemEventFilter filter = new ItemEventFilter(session.NamespaceUris);

filter.SelectClauses.Add(BrowseNames.EventId);
filter.SelectClauses.Add(BrowseNames.Time);
filter.SelectClauses.Add(BrowseNames.Message);

filter.WhereClauses.Add(FilterOperator.GreaterThan, BrowseNames.Severity, (ushort)500);

monitoredItem.Filter = filter;

List<MonitoredItem> monitoredItems = new List<MonitoredItem>();
monitoredItems.Add(monitoredItem);

List<StatusCode> results = subscription.CreateMonitoredItems(monitoredItems);

for (int ii = 0; ii < results.Count; ii++)
{
    if (results[ii].IsBad())
    {
        MessageBox.Show(results[ii].ToString(true));
    }
}

User avatar
Support Team
Hero Member
Hero Member
Posts: 2670
Joined: 18 Mar 2011, 15:09

Re: Event Usage Demonstration

Post by Support Team »

Hi Nathan,

You can force the .NET DemoServer to send events. There are trigger variables at Demo/004_Events.
If you subscribe to the Server Object or the SampleEventNotifier Object you receive an event after changing the value of Trigger_BaseEvent or Trigger_SampleEvent.

Kind Regards,
Support Team

nwhelchel
Sr. Member
Sr. Member
Posts: 14
Joined: 16 Oct 2012, 16:33

Re: Event Usage Demonstration

Post by nwhelchel »

That's great - thank you both....

Post Reply