private void OnEvent(Subscription subscription, EventNotificationList notification, IList <string> stringTable)
        {
            if (!Object.ReferenceEquals(subscription, m_subscription))
            {
                return;
            }

            if (this.InvokeRequired)
            {
                this.BeginInvoke(new FastEventNotificationEventHandler(OnEvent), subscription, notification, stringTable);
                return;
            }

            try
            {
                foreach (EventFieldList e in notification.Events)
                {
                    EventsCTRL.DisplayEvent(e);
                }
            }
            catch (Exception exception)
            {
                ClientUtils.HandleException(this.Text, exception);
            }
        }
Exemple #2
0
        /// <see cref="BaseListCtrl.UpdateItem" />
        protected override void UpdateItem(ListViewItem listItem, object item)
        {
            ItemData itemData = item as ItemData;

            if (itemData == null)
            {
                base.UpdateItem(listItem, item);
                return;
            }

            listItem.SubItems[0].Text = String.Format("{0}", itemData.Subscription.DisplayName);
            listItem.SubItems[1].Text = String.Format("{0}", itemData.NotificationMessage.SequenceNumber);
            listItem.SubItems[2].Text =
                String.Format("{0:HH:mm:ss.fff}", itemData.NotificationMessage.PublishTime.ToLocalTime());

            int events        = 0;
            int datachanges   = 0;
            int notifications = 0;

            foreach (ExtensionObject notification in itemData.NotificationMessage.NotificationData)
            {
                notifications++;

                if (ExtensionObject.IsNull(notification))
                {
                    continue;
                }

                DataChangeNotification datachangeNotification = notification.Body as DataChangeNotification;

                if (datachangeNotification != null)
                {
                    datachanges += datachangeNotification.MonitoredItems.Count;
                }

                EventNotificationList EventNotification = notification.Body as EventNotificationList;

                if (EventNotification != null)
                {
                    events += EventNotification.Events.Count;
                }
            }

            listItem.SubItems[3].Text = String.Format("{0}", notifications);
            listItem.SubItems[4].Text = String.Format("{0}", datachanges);
            listItem.SubItems[5].Text = String.Format("{0}", events);

            listItem.Tag = item;
        }
Exemple #3
0
        /// <summary>
        /// Returns the events contained in the notification message.
        /// </summary>
        public IList <EventFieldList> GetEvents(bool reverse)
        {
            List <EventFieldList> events = new List <EventFieldList>();

            foreach (ExtensionObject extension in m_notificationData)
            {
                if (ExtensionObject.IsNull(extension))
                {
                    continue;
                }

                EventNotificationList notification = extension.Body as EventNotificationList;

                if (notification == null)
                {
                    continue;
                }

                if (reverse)
                {
                    for (int ii = notification.Events.Count - 1; ii >= 0; ii--)
                    {
                        EventFieldList eventFields = notification.Events[ii];

                        if (eventFields != null)
                        {
                            eventFields.Message = this;
                            events.Add(eventFields);
                        }
                    }
                }
                else
                {
                    for (int ii = 0; ii < notification.Events.Count; ii++)
                    {
                        EventFieldList eventFields = notification.Events[ii];

                        if (eventFields != null)
                        {
                            eventFields.Message = this;
                            events.Add(eventFields);
                        }
                    }
                }
            }

            return(events);
        }
Exemple #4
0
        /// <see cref="BaseListCtrl.UpdateItem" />
        protected override void UpdateItem(ListViewItem listItem, object item)
        {
            ItemData itemData = item as ItemData;

            if (itemData == null)
            {
                base.UpdateItem(listItem, item);
                return;
            }

            int events        = 0;
            int datachanges   = 0;
            int notifications = 0;

            foreach (ExtensionObject notification in itemData.NotificationMessage.NotificationData)
            {
                notifications++;

                if (ExtensionObject.IsNull(notification))
                {
                    continue;
                }

                DataChangeNotification datachangeNotification = notification.Body as DataChangeNotification;

                if (datachangeNotification != null)
                {
                    datachanges += datachangeNotification.MonitoredItems.Count;
                }

                EventNotificationList EventNotification = notification.Body as EventNotificationList;

                if (EventNotification != null)
                {
                    events += EventNotification.Events.Count;
                }
            }

            listItem.Tag = item;
        }
        /// <summary>
        /// Construct a message from the queues.
        /// </summary>
        private NotificationMessage ConstructMessage(
            Queue<EventFieldList> events,
            Queue<MonitoredItemNotification> datachanges,
            Queue<DiagnosticInfo> datachangeDiagnostics,
            out int notificationCount)
        {
            notificationCount = 0;

            NotificationMessage message = new NotificationMessage();

            message.SequenceNumber = (uint)m_sequenceNumber; 
            message.PublishTime    = DateTime.UtcNow;

            Utils.IncrementIdentifier(ref m_sequenceNumber);

            lock (m_diagnostics)
            {
                m_diagnostics.NextSequenceNumber = (uint)m_sequenceNumber;
            }
             
            // add events.
            if (events.Count > 0 && notificationCount < m_maxNotificationsPerPublish)
            {
                EventNotificationList notification = new EventNotificationList();

                while (events.Count > 0 && notificationCount < m_maxNotificationsPerPublish)
                {
                    notification.Events.Add(events.Dequeue());
                    notificationCount++;
                }

                message.NotificationData.Add(new ExtensionObject(notification));
            }

            // add datachanges (space permitting).
            if (datachanges.Count > 0 && notificationCount < m_maxNotificationsPerPublish)
            {
                bool diagnosticsExist = false;
                DataChangeNotification notification = new DataChangeNotification();

                notification.MonitoredItems  = new MonitoredItemNotificationCollection(datachanges.Count);
                notification.DiagnosticInfos = new DiagnosticInfoCollection(datachanges.Count);

                while (datachanges.Count > 0 && notificationCount < m_maxNotificationsPerPublish)
                {
                    MonitoredItemNotification datachange = datachanges.Dequeue();
                    notification.MonitoredItems.Add(datachange);

                    DiagnosticInfo diagnosticInfo = datachangeDiagnostics.Dequeue();

                    if (diagnosticInfo != null)
                    {
                        diagnosticsExist = true;
                    }
                    
                    notification.DiagnosticInfos.Add(diagnosticInfo);

                    notificationCount++;
                }

                // clear diagnostics if not used.
                if (!diagnosticsExist)
                {
                    notification.DiagnosticInfos.Clear();
                }

                message.NotificationData.Add(new ExtensionObject(notification));
            }

            return message;
        }
        private void OnEventNotification(Subscription subscription, EventNotificationList notification, IList<string> stringTable)
        {
            try
            {
                // check if disposed.
                if (m_disposed)
                {
                    return;
                }

                // check if session still active.
                Session session = m_server.Session;

                if (session == null || !session.Connected)
                {
                    return;
                }

                // check if events are being reported.
                if (m_callback == null)
                {
                    return;
                }

                lock (m_lock)
                {
                    foreach (EventFieldList e in notification.Events)
                    {
                        // translate the notification and send the response.
                        AeEvent e2 = m_filter.TranslateNotification(m_server.Session, e);

                        if (e2 != null)
                        {
                            // check if refresh has started.
                            if (e2.EventType == Opc.Ua.ObjectTypeIds.RefreshStartEventType)
                            {
                                m_refreshInProgress = true;
                                continue;
                            }

                            // check if refresh has ended.
                            if (e2.EventType == Opc.Ua.ObjectTypeIds.RefreshEndEventType)
                            {
                                m_refreshInProgress = false;

                                // turn off publishing if the subscription is not active,
                                if (!Active)
                                {
                                    m_subscription.SetPublishingMode(false);
                                    List<MonitoredItem> itemsToUpdate = new List<MonitoredItem>(m_notifiers.Values);
                                    m_subscription.SetMonitoringMode(MonitoringMode.Disabled, itemsToUpdate);
                                }

                                if (m_refreshQueue != null)
                                {
                                    ThreadPool.QueueUserWorkItem(DoRefresh, m_refreshQueue);
                                }

                                continue;
                            }

                            // cache any conditions requiring acknowledgement.
                            m_conditionManager.ProcessEvent(e2);

                            // queue on refresh.
                            if (m_refreshInProgress)
                            {
                                if (m_refreshQueue != null)
                                {
                                    m_refreshQueue.Enqueue(e2);
                                }

                                continue;
                            }

                            // queue the event.
                            if (Active)
                            {
                                lock (m_queue)
                                {
                                    m_queue.Enqueue(e2);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Utils.Trace(exception, "Error processing event callback.");
            }
        }
        private void OnEvent(Subscription subscription, EventNotificationList notification, IList<string> stringTable)
        {
            if (!Object.ReferenceEquals(subscription, m_subscription))
            {
                return;
            }

            if (this.InvokeRequired)
            {
                this.BeginInvoke(new FastEventNotificationEventHandler(OnEvent), subscription, notification, stringTable);
                return;
            }

            try
            {
                foreach (EventFieldList e in notification.Events)
                {
                    EventsCTRL.DisplayEvent(e);
                }
            }
            catch (Exception exception)
            {
                ClientUtils.HandleException(this.Text, exception);
            }
        }
        /// <summary>
        /// The delegate used to receive event notifications via a direct function call instead of a .NET Event.
        /// </summary>
        public void OnEventNotification(Opc.Ua.Client.Subscription subscription, EventNotificationList notification, IList<string> stringTable)
        {
            for (int ii = 0; ii < notification.Events.Count; ii++)
            {
                MonitoredItem localItem = null;

                EventFieldList e = null;

                lock (subscription.Session)
                {
                    Opc.Ua.Client.MonitoredItem monitoredItem = subscription.FindItemByClientHandle(notification.Events[ii].ClientHandle);

                    if (monitoredItem != null)
                    {
                        e = notification.Events[ii];

                        for (int jj = 0; jj < e.EventFields.Count; jj++)
                        {
                            e.EventFields[jj] = m_mapper.ToLocalVariant(e.EventFields[jj]);
                        }

                        localItem = (MonitoredItem)monitoredItem.Handle;
                        e.ClientHandle = localItem.ClientHandle;
                    }
                }

                localItem.QueueEvent(e);
            }
        }
Exemple #9
0
        private void OnEventNotification(Subscription subscription, EventNotificationList notification, IList <string> stringTable)
        {
            try
            {
                // check if disposed.
                if (m_disposed)
                {
                    return;
                }

                // check if session still active.
                Session session = m_server.Session;

                if (session == null || !session.Connected)
                {
                    return;
                }

                // check if events are being reported.
                if (m_callback == null)
                {
                    return;
                }

                lock (m_lock)
                {
                    foreach (EventFieldList e in notification.Events)
                    {
                        // translate the notification and send the response.
                        AeEvent e2 = m_filter.TranslateNotification(m_server.Session, e);

                        if (e2 != null)
                        {
                            // check if refresh has started.
                            if (e2.EventType == Opc.Ua.ObjectTypeIds.RefreshStartEventType)
                            {
                                m_refreshInProgress = true;
                                continue;
                            }

                            // check if refresh has ended.
                            if (e2.EventType == Opc.Ua.ObjectTypeIds.RefreshEndEventType)
                            {
                                m_refreshInProgress = false;

                                // turn off publishing if the subscription is not active,
                                if (!Active)
                                {
                                    m_subscription.SetPublishingMode(false);
                                    List <MonitoredItem> itemsToUpdate = new List <MonitoredItem>(m_notifiers.Values);
                                    m_subscription.SetMonitoringMode(MonitoringMode.Disabled, itemsToUpdate);
                                }

                                if (m_refreshQueue != null)
                                {
                                    ThreadPool.QueueUserWorkItem(DoRefresh, m_refreshQueue);
                                }

                                continue;
                            }

                            // cache any conditions requiring acknowledgement.
                            m_conditionManager.ProcessEvent(e2);

                            // queue on refresh.
                            if (m_refreshInProgress)
                            {
                                if (m_refreshQueue != null)
                                {
                                    m_refreshQueue.Enqueue(e2);
                                }

                                continue;
                            }

                            // queue the event.
                            if (Active)
                            {
                                lock (m_queue)
                                {
                                    m_queue.Enqueue(e2);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Utils.Trace(exception, "Error processing event callback.");
            }
        }