GetEventType() public method

Returns value of the field name containing the event type.
public GetEventType ( EventFieldList eventFields ) : INode
eventFields EventFieldList
return INode
Esempio n. 1
0
        /// <summary>
        /// Processes a Publish response from the UA server for AddressSpace changes.
        /// </summary>
        /// <param name="monitoredItem"></param>
        /// <param name="e"></param>
        void AddressSpaceChange_Notification(MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs e)
        {
            try
            {
                EventFieldList eventFields = e.NotificationValue as EventFieldList;

                if (eventFields == null)
                {
                    return;
                }
                if (monitoredItem != null)
                {
                    if (monitoredItem.ClientHandle != eventFields.ClientHandle)
                    {
                        return;
                    }
                }
                INode eventUA = monitoredItem.GetEventType(eventFields);
                if (eventUA.NodeId == new NodeId(Opc.Ua.ObjectTypes.BaseModelChangeEventType))
                {
                    //TODO:if we get this event we know a change was made, but we do not know what so we will beed to get all EventTypes and compare and update our config data
                }
                else if (eventUA.NodeId != new NodeId(Opc.Ua.ObjectTypes.GeneralModelChangeEventType))
                {
                    //We are not interested in any other event, so we will return.
                    //If we can set the where clause on the filter for this item, this else clause can be removed.
                    return;
                }
                else
                {
                    object v = monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.GeneralModelChangeEventType, new QualifiedName(Opc.Ua.BrowseNames.Changes));

                    //ChangeStructureDataTypeCollection changes = (ChangeStructureDataTypeCollection) monitoredItem.GetFieldValue(eventFields, ObjectTypes.GeneralModelChangeEventType, new QualifiedName(GeneralModelChangeEvent.Names.Changes));



                }

            }
            catch (Exception ex)
            {
                Utils.Trace(ex, "Unexpected error in AddressSpaceChange_Notification");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Processes a Publish response from the UA server.
        /// </summary>
        /// <param name="monitoredItem"></param>
        /// <param name="e"></param>
        void MonitoredItem_Notification(MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs e)
        {
            try
            {
                EventFieldList eventFields = e.NotificationValue as EventFieldList;

                if (eventFields == null)
                {
                    return;
                }
                if (monitoredItem != null)
                {
                    if (monitoredItem.ClientHandle != eventFields.ClientHandle)
                    {
                        return;
                    }
                }
                INode eventUA = monitoredItem.GetEventType(eventFields);
                EventCategory cat = FindEventCatInfo(eventUA.BrowseName.ToString());

                if (cat == null) return; // The event is not of a category that we recognize.
           
                if (cat.EventType == OpcRcw.Ae.Constants.CONDITION_EVENT)
                {
                    NodeId branchId = monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.ConditionType, Opc.Ua.BrowseNames.BranchId) as NodeId;
                    if (!NodeId.IsNull(branchId)) return; // We don't support condition branches in the COM Proxy
                }

                EventNotification ev = new EventNotification();

                ev.EventId = monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.BaseEventType, new QualifiedName(Opc.Ua.BrowseNames.EventId)) as byte[];
                ev.SourceID = System.Convert.ToString(monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.BaseEventType, new QualifiedName(Opc.Ua.BrowseNames.SourceName)));
                ev.Time = System.Convert.ToDateTime(monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.BaseEventType, new QualifiedName(Opc.Ua.BrowseNames.Time)));
                ev.Message = System.Convert.ToString(monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.BaseEventType, new QualifiedName(Opc.Ua.BrowseNames.Message)));
                ev.EventType = cat.EventType;
                ev.EventCategory = cat.CategoryID;
                ev.Severity = System.Convert.ToInt32(monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.BaseEventType, new QualifiedName(Opc.Ua.BrowseNames.Severity)));

                List<EventAttribute> Attrs = GetEventAttributes(cat.CategoryID);
                UniqueList<string> strEventNodeIds = new UniqueList<string>();
                foreach (EventAttribute attr in Attrs)
                    if (attr.strEventNodeId != "")
                        strEventNodeIds.AddUnique(attr.strEventNodeId);

                ev.EventAttributes = new Dictionary<int, object>();
                foreach (EventAttribute attr in m_configFile.Attributes)
                {
                    foreach (string strEventNodeId in strEventNodeIds)
                    {
                        if (attr.strEventNodeId == strEventNodeId)
                        {
                            object value = monitoredItem.GetFieldValue(eventFields, (NodeId)attr.strEventNodeId, new QualifiedName(attr.BrowseName, attr.BrowseNameNSIndex));
                            if (value == null)
                            {
                                ev.EventAttributes.Add(attr.AttributeID, "");
                            }
                            else if ((value.GetType() != null) & (short)ComUtils.GetVarType(value) != 0)
                            {
                                ev.EventAttributes.Add(attr.AttributeID, value);
                            }
                            else
                            {
                                // any value with a UA type that does not have a corresponding COM type will be returned as a string 
                                ev.EventAttributes.Add(attr.AttributeID, value.ToString());
                            }
                        }
                    }
                }

                //Condition-Related Event properties
                ev.ConditionName = "";
                ev.SubConditionName = "";
                ev.ChangeMask = 0;
                ev.NewState = OpcRcw.Ae.Constants.CONDITION_ENABLED | OpcRcw.Ae.Constants.CONDITION_ACKED;
                ev.Quality = OpcRcw.Da.Qualities.OPC_QUALITY_GOOD;
                ev.AckRequired = false;
                ev.ActiveTime = DateTime.Now;
                ev.Cookie = 0;

                if (ev.EventType == OpcRcw.Ae.Constants.CONDITION_EVENT)
                    SetConditionEventFields(monitoredItem, eventFields, ev, cat);

                //Tracking Events and for Condition-Related Events which are acknowledgment notifications
                if (cat.EventType == OpcRcw.Ae.Constants.TRACKING_EVENT)
                    ev.ActorID = System.Convert.ToString(monitoredItem.GetFieldValue(eventFields, (NodeId)eventUA.NodeId, new QualifiedName(Opc.Ua.BrowseNames.ClientUserId)));

                IncomingEventHandler eventHandler = new IncomingEventHandler();
                
                //extract the area associated with this event.
                AreaNode areaNode;
                string[] areas = null;
                if (m_notifiers.TryGetValue(monitoredItem.ClientHandle, out areaNode))
                {
                    areas = new string[] { areaNode.AreaName };
                }
                eventHandler.ProcessEventNotificationList(ev, areas);
            }
            catch (Exception ex)
            {
                Utils.Trace(ex, "Unexpected error in MonitoredItem_Notification");
            }
        }