Пример #1
0
        /// <summary>
        /// 解析JObject到一个容器当中;
        /// </summary>
        /// <param name="obj">从文件中解析出来的JSON对象;</param>
        /// <returns>返回一个保存了所有节点的容器;</returns>
        private void ParseJObject(JObject obj)
        {
            // 筛选出所有节点的ID;
            IEnumerable <int> AllNodes = from nodes in obj.First.Next.First select(int) nodes["ObjID"];

            m_NodeList = new List <ObjNode>();
            int TempCount = 0;


            // 遍历所有JSON文件中的节点,并添加进列表中;
            foreach (var iter in AllNodes)
            {
                ObjNode node;
                var     ObjParentNodes = (int)obj.First.Next.First[TempCount]["ObjParentID"];
                var     name           = (string)obj.First.Next.First[TempCount]["ObjName"];
                var     TableName      = (string)obj.First.Next.First[TempCount]["MibTableName"];
                var     version        = (string)obj.First.First;

                if ((int)obj.First.Next.First[TempCount]["ChildRenCount"] != 0)
                {
                    node = new ObjTreeNode(iter, ObjParentNodes, version, name, TableName);
                }
                else
                {
                    node = new ObjLeafNode(iter, ObjParentNodes, version, name, TableName);
                }

                m_NodeList.Add(node);
                TempCount++;
            }
            m_RootNode = ArrangeParentage(m_NodeList);
        }
Пример #2
0
        /// <summary>
        /// 确认亲子关系;
        /// </summary>
        /// <param name="NodeList"></param>
        /// <returns></returns>
        public static List <ObjNode> ArrangeParentage(List <ObjNode> NodeList)
        {
            List <ObjNode> RootNodeShow = new List <ObjNode>();
            ObjNode        Root         = new ObjTreeNode(0, 0, "1.0", "基站节点列表", @"/");

            // 遍历所有节点确认亲子关系;
            foreach (ObjNode iter in NodeList)
            {
                if (iter.ObjParentID == 0)
                {
                    Root.Add(iter);
                }
                else
                {
                    foreach (ObjNode iterParent in NodeList)
                    {
                        if (iterParent.ObjID == iter.ObjParentID)
                        {
                            iterParent.Add(iter);
                        }
                    }
                }
            }

            RootNodeShow.Add(Root);

            return(RootNodeShow);
        }
Пример #3
0
        private void Collect_Node_Click(object sender, EventArgs e)
        {
            ObjNode        Objnode;
            List <ObjNode> m_NodeList   = new List <ObjNode>();
            List <ObjNode> RootNodeShow = new List <ObjNode>();
            ObjNode        Root         = new ObjTreeNode(0, 0, "1.0", "收藏节点", @"/");
            NodeB          node         = new NodeB("172.27.245.92", "NodeB");
            string         cfgFile      = node.m_ObjTreeDataPath;
            StreamReader   reader       = File.OpenText(cfgFile);
            JObject        JObj         = new JObject();

            JObj = (JObject)JToken.ReadFrom(new JsonTextReader(reader));
            IEnumerable <int> AllNodes = from nodes in JObj.First.Next.First
                                         select(int) nodes["ObjID"];

            int TempCount = 0;

            foreach (var iter in AllNodes)
            {
                var ObjParentNodes = (int)JObj.First.Next.First[TempCount]["ObjParentID"];
                var name           = (string)JObj.First.Next.First[TempCount]["ObjName"];
                var TableName      = (string)JObj.First.Next.First[TempCount]["MibTableName"];
                var version        = (string)JObj.First.First;
                if (JObj.First.Next.First[TempCount]["ObjCollect"] == null)
                {
                    TempCount++;
                    continue;
                }
                int ObjCollect = (int)JObj.First.Next.First[TempCount]["ObjCollect"];


                Objnode = new ObjTreeNode(iter, ObjParentNodes, version, name, TableName);
                if (ObjCollect == 1)
                {
                    int index = m_NodeList.IndexOf(Objnode);
                    if (index < 0)
                    {
                        m_NodeList.Add(Objnode);
                    }
                }

                TempCount++;
            }
            reader.Close();
            ObjNodeControl Ctrl = new ObjNodeControl(node);

            // 遍历所有节点确认亲子关系;
            foreach (ObjNode iter in m_NodeList)
            {
                //Root.Add(iter);
                if (Root.SubObj_Lsit != null)
                {
                    bIsRepeat = false;
                    IsRepeatNode(iter, Root.SubObj_Lsit);
                    if (bIsRepeat)
                    {
                        continue;
                    }
                }

                // 遍历所有节点确认亲子关系;
                foreach (ObjNode iter1 in Ctrl.m_NodeList)
                {
                    if (iter1.ObjID == iter.ObjID)
                    {
                        Root.Add(iter1);
                    }
                    else if (iter1.ObjID > iter.ObjID)
                    {
                        foreach (ObjNode iterParent in Ctrl.m_NodeList)
                        {
                            if (iterParent.ObjID == iter1.ObjParentID)
                            {
                                iterParent.Add(iter1);
                            }
                        }
                    }
                }
            }
            RootNodeShow.Add(Root);

            // 将右侧叶节点容器容器加入到对象树子容器中;
            this.Obj_Collect.Clear();
            this.Obj_Collect.SubExpender = this.FavLeaf_Lists;

            foreach (ObjNode items in RootNodeShow)
            {
                items.TraverseCollectChildren(this.Obj_Collect, this.FavLeaf_Lists, 0);
            }
        }