public virtual bool Publish(OperationContext context, Queue<EventFieldList> notifications)
{
if (context == null) throw new ArgumentNullException("context");
if (notifications == null) throw new ArgumentNullException("notifications");
lock (m_lock)
{
// check if the item reports events.
if ((m_typeMask & MonitoredItemTypeMask.Events) == 0)
{
return false;
}
// only publish if reporting.
if (!IsReadyToPublish)
{
return false;
}
// go to the next sampling interval.
IncrementSampleTime();
// publish events.
if (m_events != null)
{
// Utils.Trace("MONITORED ITEM: Publish(QueueSize={0})", notifications.Count);
EventFieldList overflowEvent = null;
if (m_overflow)
{
// construct event.
EventQueueOverflowEventState e = new EventQueueOverflowEventState(null);
TranslationInfo message = new TranslationInfo(
"EventQueueOverflowEventState",
"en-US",
"Events lost due to queue overflow.");
ISystemContext systemContext = new ServerSystemContext(m_server, context);
e.Initialize(
systemContext,
null,
EventSeverity.Low,
new LocalizedText(message));
e.SetChildValue(systemContext, BrowseNames.SourceNode, ObjectIds.Server, false);
e.SetChildValue(systemContext, BrowseNames.SourceName, "Internal", false);
// fetch the event fields.
overflowEvent = GetEventFields(
new FilterContext(m_server.NamespaceUris, m_server.TypeTree, m_session.PreferredLocales),
m_filterToUse as EventFilter,
e);
}
// place event at the beginning of the queue.
if (overflowEvent != null && m_discardOldest)
{
notifications.Enqueue(overflowEvent);
}
for (int ii = 0; ii < m_events.Count; ii++)
{
EventFieldList fields = (EventFieldList)m_events[ii];
// apply any diagnostic masks.
for (int jj = 0; jj < fields.EventFields.Count; jj++)
{
object value = fields.EventFields[jj].Value;
StatusResult result = value as StatusResult;
if (result != null)
{
result.ApplyDiagnosticMasks(context.DiagnosticsMask, context.StringTable);
}
}
notifications.Enqueue((EventFieldList)m_events[ii]);
}
m_events.Clear();
// place event at the end of the queue.
if (overflowEvent != null && !m_discardOldest)
{
notifications.Enqueue(overflowEvent);
}
// Utils.Trace("MONITORED ITEM: Publish(QueueSize={0})", notifications.Count);
}
// reset state variables.
m_overflow = false;
m_readyToPublish = false;
m_readyToTrigger = false;
m_triggered = false;
return false;
}
}