Opc.Ua.Com.Server.ComAeUtils.CollectInstanceDeclarations C# (CSharp) Method

CollectInstanceDeclarations() public static method

Collects instance declarations nodes from with a type.
public static CollectInstanceDeclarations ( Session session, ComNamespaceMapper mapper, NodeState node, AeEventAttribute parent, List instances, AeEventAttribute>.IDictionary map ) : void
session Opc.Ua.Client.Session
mapper ComNamespaceMapper
node NodeState
parent AeEventAttribute
instances List
map AeEventAttribute>.IDictionary
return void
        public static void CollectInstanceDeclarations(
            Session session,
            ComNamespaceMapper mapper,
            NodeState node,
            AeEventAttribute parent,
            List<AeEventAttribute> instances,
            IDictionary<string, AeEventAttribute> map)
        {
            List<BaseInstanceState> children = new List<BaseInstanceState>();
            node.GetChildren(session.SystemContext, children);
            
            if (children.Count == 0)
            {
                return;
            }

            // process the children.
            for (int ii = 0; ii < children.Count; ii++)
            {
                BaseInstanceState instance = children[ii];

                // only interested in objects and variables.
                if (instance.NodeClass != NodeClass.Object && instance.NodeClass != NodeClass.Variable)
                {
                    return;
                }

                // ignore instances without a modelling rule.
                if (NodeId.IsNull(instance.ModellingRuleId))
                {
                    return;
                }

                // create a new declaration.
                AeEventAttribute declaration = new AeEventAttribute();

                declaration.RootTypeId = (parent != null)?parent.RootTypeId:node.NodeId;
                declaration.NodeId = (NodeId)instance.NodeId;
                declaration.BrowseName = instance.BrowseName;
                declaration.NodeClass = instance.NodeClass;
                declaration.Description = (instance.Description != null)?instance.Description.ToString():null;
                
                // get data type information.
                BaseVariableState variable = instance as BaseVariableState;
 
                if (variable != null)
                {
                    declaration.DataType = variable.DataType;
                    declaration.ValueRank = variable.ValueRank;

                    if (!NodeId.IsNull(variable.DataType))
                    {
                        declaration.BuiltInType = DataTypes.GetBuiltInType(declaration.DataType, session.TypeTree);
                    }
                }

                if (!LocalizedText.IsNullOrEmpty(instance.DisplayName))
                {
                    declaration.DisplayName = instance.DisplayName.Text;
                }
                else
                {
                    declaration.DisplayName = instance.BrowseName.Name;
                }

                if (parent != null)
                {
                    declaration.BrowsePath = new QualifiedNameCollection(parent.BrowsePath);
                    declaration.BrowsePathDisplayText = Utils.Format("{0}/{1}", parent.BrowsePathDisplayText, mapper.GetLocalBrowseName(instance.BrowseName));
                    declaration.DisplayPath = Utils.Format("{0}/{1}", parent.DisplayPath, instance.DisplayName);
                }
                else
                {
                    declaration.BrowsePath = new QualifiedNameCollection();
                    declaration.BrowsePathDisplayText = Utils.Format("{0}", instance.BrowseName);
                    declaration.DisplayPath = Utils.Format("{0}", instance.DisplayName);
                }

                declaration.BrowsePath.Add(instance.BrowseName);

                // check if reading an overridden declaration.
                AeEventAttribute overriden = null;

                if (map.TryGetValue(declaration.BrowsePathDisplayText, out overriden))
                {
                    declaration.OverriddenDeclaration = overriden;
                }

                map[declaration.BrowsePathDisplayText] = declaration;

                // only interested in variables.
                if (instance.NodeClass == NodeClass.Variable)
                {
                    instances.Add(declaration);
                }

                // recusively build tree.
                CollectInstanceDeclarations(session, mapper, instance, declaration, instances, map);
            }
        }

Same methods

ComAeUtils::CollectInstanceDeclarations ( Session session, ComNamespaceMapper mapper, NodeId typeId, AeEventAttribute parent, List instances, AeEventAttribute>.IDictionary map ) : void

Usage Example

示例#1
0
        /// <summary>
        /// Recursively populates the event types table.
        /// </summary>
        private void IndexTypesFromServer(NodeId baseTypeId, int eventType)
        {
            // check if event type needs to be revised.
            if (baseTypeId == Opc.Ua.ObjectTypeIds.ConditionType)
            {
                eventType = OpcRcw.Ae.Constants.CONDITION_EVENT;
            }

            else if (baseTypeId == Opc.Ua.ObjectTypeIds.AuditEventType)
            {
                eventType = OpcRcw.Ae.Constants.TRACKING_EVENT;
            }

            else if (baseTypeId == Opc.Ua.ObjectTypeIds.BaseEventType)
            {
                eventType = OpcRcw.Ae.Constants.SIMPLE_EVENT;
            }

            // browse for subtypes.
            BrowseDescription nodeToBrowse = new BrowseDescription();

            nodeToBrowse.NodeId          = baseTypeId;
            nodeToBrowse.BrowseDirection = BrowseDirection.Forward;
            nodeToBrowse.ReferenceTypeId = Opc.Ua.ReferenceTypeIds.HasSubtype;
            nodeToBrowse.IncludeSubtypes = false;
            nodeToBrowse.NodeClassMask   = (uint)NodeClass.ObjectType;
            nodeToBrowse.ResultMask      = (uint)(BrowseResultMask.BrowseName | BrowseResultMask.DisplayName | BrowseResultMask.NodeClass);

            ReferenceDescriptionCollection references = ComAeUtils.Browse(
                m_session,
                nodeToBrowse,
                false);

            for (int ii = 0; ii < references.Count; ii++)
            {
                // these types have t
                if (references[ii].NodeId.IsAbsolute)
                {
                    continue;
                }

                NodeId typeId = (NodeId)references[ii].NodeId;

                if (!m_eventTypes.ContainsKey(typeId))
                {
                    // collection the instances declared by the type.
                    List <AeEventAttribute> declarations      = new List <AeEventAttribute>();
                    Dictionary <string, AeEventAttribute> map = new Dictionary <string, AeEventAttribute>();

                    ComAeUtils.CollectInstanceDeclarations(
                        m_session,
                        this,
                        (NodeId)references[ii].NodeId,
                        null,
                        declarations,
                        map);

                    AeEventCategory declaration = new AeEventCategory();
                    declaration.TypeId               = (NodeId)references[ii].NodeId;
                    declaration.SuperTypeId          = baseTypeId;
                    declaration.EventType            = eventType;
                    declaration.Description          = (LocalizedText.IsNullOrEmpty(references[ii].DisplayName)) ? references[ii].BrowseName.Name : references[ii].DisplayName.Text;
                    declaration.Attributes           = declarations;
                    m_eventTypes[declaration.TypeId] = declaration;
                }

                // recursively look for subtypes.
                IndexTypesFromServer(typeId, eventType);
            }
        }
All Usage Examples Of Opc.Ua.Com.Server.ComAeUtils::CollectInstanceDeclarations