Page 1 of 1

Event subscription

Posted: 22 Feb 2017, 14:04
by glawi00s
I have set up a subscription for newEvents and has also defined a filter like:

ItemEventFilter eventFilter = new ItemEventFilter();
eventFilter.SelectClauses.Add(BrowseNames.AckedState);
eventFilter.SelectClauses.Add(BrowseNames.ConfirmedState);
eventFilter.SelectClauses.Add(BrowseNames.Time);
eventFilter.SelectClauses.Add(BrowseNames.Severity);

I have added the filter to the monitored item as well.

In the Subscription_EventHandler I print the EventsFields to text file.

My question is are the results in EventFields in the order that I defined them in the filter?

My Subscription_NewEvent hndler looks like this:

private void Subscription_NewEvents(Subscription subscription, NewEventsEventArgs e)
{
try
{
if (
_subscriptions.TakeWhile(t => !Objects.ReferenceEquals(_subscriptions[0], subscription))
.Where((t, i) => i == _subscriptions.Count)
.Any())
{
return;
}

foreach (NewEvent newEvent in e.Events)
{
for (int i = 0; i < newEvent.Event.EventFields.Count; i++)
{
if (newEvent.Event.EventFields.Value != null)
{
s += newEvent.Event.EventFields.Value.ToString().Trim() + ",";
}
else
{
s += ",";
}
}
s = s.Remove(s.Length - 1);

s += Environment.NewLine;

using (System.IO.StreamWriter file =
new System.IO.StreamWriter(@"c:\temp\textfile.txt", true))
{
file.WriteLine(s);
}
}
}
catch (Exception ex)
{
var a = ex;
throw;
}
}

Re: Event subscription

Posted: 13 Mar 2017, 12:32
by Support Team
Yes, the EventFields are sent in the same order than specified in the SelectClause.

Re: Event subscription

Posted: 07 Feb 2022, 11:14
by sudhapc
How do you mock this event using Moq ?