public static BrowseSuperTypes ( Session session, NodeId typeId, bool throwOnError ) : ReferenceDescriptionCollection | ||
session | Session | The session. |
typeId | NodeId | The NodeId for a type node in the address space. |
throwOnError | bool | if set to |
리턴 | ReferenceDescriptionCollection |
/// <summary> /// Collects the instance declarations for a type. /// </summary> public static List <InstanceDeclaration> CollectInstanceDeclarationsForType(Session session, NodeId typeId, bool includeSupertypes) { // process the types starting from the top of the tree. List <InstanceDeclaration> instances = new List <InstanceDeclaration>(); Dictionary <string, InstanceDeclaration> map = new Dictionary <string, InstanceDeclaration>(); // get the supertypes. if (includeSupertypes) { ReferenceDescriptionCollection supertypes = ClientUtils.BrowseSuperTypes(session, typeId, false); if (supertypes != null) { for (int ii = supertypes.Count - 1; ii >= 0; ii--) { CollectInstanceDeclarations(session, (NodeId)supertypes[ii].NodeId, null, instances, map); } } } // collect the fields for the selected type. CollectInstanceDeclarations(session, typeId, null, instances, map); // return the complete list. return(instances); }
/// <summary> /// Collects the fields for the type. /// </summary> /// <param name="session">The session.</param> /// <param name="typeId">The type id.</param> /// <param name="fields">The fields.</param> /// <param name="fieldNodeIds">The node id for the declaration of the field.</param> private static void CollectFieldsForType(Session session, NodeId typeId, SimpleAttributeOperandCollection fields, List <NodeId> fieldNodeIds) { // get the supertypes. ReferenceDescriptionCollection supertypes = ClientUtils.BrowseSuperTypes(session, typeId, false); if (supertypes == null) { return; } // process the types starting from the top of the tree. Dictionary <NodeId, QualifiedNameCollection> foundNodes = new Dictionary <NodeId, QualifiedNameCollection>(); QualifiedNameCollection parentPath = new QualifiedNameCollection(); for (int ii = supertypes.Count - 1; ii >= 0; ii--) { CollectFields(session, (NodeId)supertypes[ii].NodeId, parentPath, fields, fieldNodeIds, foundNodes); } // collect the fields for the selected type. CollectFields(session, typeId, parentPath, fields, fieldNodeIds, foundNodes); }
/// <summary> /// Constructs an event object from a notification. /// </summary> /// <param name="session">The session.</param> /// <param name="monitoredItem">The monitored item that produced the notification.</param> /// <param name="notification">The notification.</param> /// <param name="knownEventTypes">The known event types.</param> /// <param name="eventTypeMappings">Mapping between event types and known event types.</param> /// <returns> /// The event object. Null if the notification is not a valid event type. /// </returns> public static BaseEventState ConstructEvent( Session session, MonitoredItem monitoredItem, EventFieldList notification, Dictionary <NodeId, Type> knownEventTypes, Dictionary <NodeId, NodeId> eventTypeMappings) { // find the event type. NodeId eventTypeId = FindEventType(monitoredItem, notification); if (eventTypeId == null) { return(null); } // look up the known event type. Type knownType = null; NodeId knownTypeId = null; if (eventTypeMappings.TryGetValue(eventTypeId, out knownTypeId)) { knownType = knownEventTypes[knownTypeId]; } // try again. if (knownType == null) { if (knownEventTypes.TryGetValue(eventTypeId, out knownType)) { knownTypeId = eventTypeId; eventTypeMappings.Add(eventTypeId, eventTypeId); } } // try mapping it to a known type. if (knownType == null) { // browse for the supertypes of the event type. ReferenceDescriptionCollection supertypes = ClientUtils.BrowseSuperTypes(session, eventTypeId, false); // can't do anything with unknown types. if (supertypes == null) { return(null); } // find the first supertype that matches a known event type. for (int ii = 0; ii < supertypes.Count; ii++) { NodeId superTypeId = (NodeId)supertypes[ii].NodeId; if (knownEventTypes.TryGetValue(superTypeId, out knownType)) { knownTypeId = superTypeId; eventTypeMappings.Add(eventTypeId, superTypeId); } if (knownTypeId != null) { break; } } // can't do anything with unknown types. if (knownTypeId == null) { return(null); } } // construct the event based on the known event type. BaseEventState e = (BaseEventState)Activator.CreateInstance(knownType, new object[] { (NodeState)null }); // get the filter which defines the contents of the notification. EventFilter filter = monitoredItem.Status.Filter as EventFilter; // initialize the event with the values in the notification. e.Update(session.SystemContext, filter.SelectClauses, notification); // save the orginal notification. e.Handle = notification; return(e); }