Page 1 of 1

Event Usage Demonstration

Posted: 05 Apr 2013, 03:11
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

Re: Event Usage Demonstration

Posted: 05 Apr 2013, 08:47
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));
    }
}

Re: Event Usage Demonstration

Posted: 05 Apr 2013, 09:02
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

Re: Event Usage Demonstration

Posted: 05 Apr 2013, 16:37
by nwhelchel
That's great - thank you both....