Opc.Ua.Sample.TypeHierarchyListCtrl.CollectInstances C# (CSharp) Method

CollectInstances() private method

Collects the instance declarations to display in the control.
private CollectInstances ( ILocalNode parent, string basePath, InstanceDeclaration>.SortedDictionary instances ) : void
parent ILocalNode
basePath string
instances InstanceDeclaration>.SortedDictionary
return void
        private void CollectInstances(ILocalNode parent, string basePath, SortedDictionary<string,InstanceDeclaration> instances)
        {         
            if (parent == null)
            {
                return;
            }

            IList<IReference> supertypes = parent.References.Find(
                ReferenceTypeIds.HasSubtype,
                true,
                false,
                m_session.TypeTree);

            for (int ii = 0; ii < supertypes.Count; ii++)
            {
                ILocalNode supertype = m_session.NodeCache.Find(supertypes[ii].TargetId) as ILocalNode;

                if (supertype == null)
                {
                    continue;
                }

                CollectInstances(supertype, basePath, instances);
            }

            IList<IReference> children = parent.References.Find(
                ReferenceTypeIds.HierarchicalReferences,
                false,
                true,
                m_session.TypeTree);

            for (int ii = 0; ii < children.Count; ii++)
            {
                ILocalNode child = m_session.NodeCache.Find(children[ii].TargetId) as ILocalNode;

                if (child == null)
                {
                    continue;
                }

                if (child.NodeClass != NodeClass.Object && child.NodeClass != NodeClass.Variable)
                {
                    continue;
                }

                if (child.ModellingRule != Objects.ModellingRule_Mandatory && child.ModellingRule != Objects.ModellingRule_Optional)
                {
                    continue;
                }

                string displayPath = Utils.Format("{0}", child);
            
                if (!String.IsNullOrEmpty(basePath))
                {
                    displayPath = Utils.Format("{0}/{1}", basePath, displayPath);
                }
            
                InstanceDeclaration declaration = new InstanceDeclaration();

                declaration.Instance = child;
                declaration.DisplayPath = displayPath;
                declaration.Description = Utils.Format("{0}", child.Description);
                declaration.DataType = String.Empty;

                IVariableBase variable = child as IVariableBase;

                if (variable != null)
                {
                    INode dataType =  m_session.NodeCache.Find(variable.DataType);

                    if (dataType != null)
                    {
                        declaration.DataType = Utils.Format("{0}", dataType);
                    }

                    if (variable.ValueRank >= 0)
                    {
                        declaration.DataType += "[]";
                    }
                }
                
                IObject objectn = child as IObject;

                if (objectn != null)
                {                    
                    declaration.DataType = "NodeId";
                }

                instances[displayPath] = declaration;
                CollectInstances(child, displayPath, instances);
            }
        }
        #endregion