CgwMonitorManage.Tiandy.TiandyVideoMonitor.RecursionCameraGroup C# (CSharp) Method

RecursionCameraGroup() private method

递归天地伟业返回的自定义设备列表,只获取分组节点(TypeId为1000)和通道(摄像头)节点(TypeId为5),舍弃其他节点(如主机,中间件服务器等)
private RecursionCameraGroup ( List customTree, List pathList, CameraGroup>.Dictionary groupDic, NodeRelation>.Dictionary nodeRelationDic, List nodeRelationListT ) : void
customTree List 天地伟业返回的自定义设备列表树
pathList List 节点路径,如果为跟节点,传null即可,主要是用于递归函数处理
groupDic CameraGroup>.Dictionary 组列表
nodeRelationDic NodeRelation>.Dictionary 组、摄像头关系列表Dic,不能重复
nodeRelationListT List 组、摄像头关系列表,可以重复,解决同一摄像头在不同分组下,融合网关报错的问题
return void
        private void RecursionCameraGroup(List<Resource> customTree, List<string> pathList, Dictionary<string, CameraGroup> groupDic, Dictionary<string, NodeRelation> nodeRelationDic, List<NodeRelation> nodeRelationListT)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);

            if (customTree == null)
            {
                logEx.Error("RecursionCameraGroup failed.CustomTree is null.");
                return;
            }

            if (pathList == null)
            {
                pathList = new List<string>();
            }

            if (groupDic == null)
            {
                groupDic = new Dictionary<string, CameraGroup>();
            }

            if (nodeRelationDic == null)
            {
                nodeRelationDic = new Dictionary<string, NodeRelation>();
            }

            if (nodeRelationListT == null)
            {
                nodeRelationListT = new List<NodeRelation>();
            }

            foreach (Resource custom in customTree)
            {
                //TypeId为5时,表示该节点为通道,对应一个摄像头
                if (((int)NodeType.CAMERA).ToString().Equals(custom.TypeId))
                {
                    //pathList.Add(custom.Id);
                    NodeRelation nodeRelation = new NodeRelation(custom.Id, new List<string>(pathList), CgwMonitorManage.Common.NodeType.CAMERA);
                    if (!nodeRelationDic.ContainsKey(custom.Id))
                    {
                        nodeRelationDic.Add(custom.Id, nodeRelation);
                    }
                    nodeRelationListT.Add(nodeRelation);

                    //获取完路径后,要返回上一级路径
                    //pathList.Remove(custom.Id);
                }
                //TypeId为1000时,表示该节点为分组
                else if (((int)NodeType.GROUP).ToString().Equals(custom.TypeId))
                {
                    //添加组信息
                    CameraGroup cameraGroup = new CameraGroup(custom.Id, custom.Caption);
                    groupDic.Add(custom.Id, cameraGroup);

                    NodeRelation nodeRelation = new NodeRelation(custom.Id, new List<string>(pathList), CgwMonitorManage.Common.NodeType.GROUP);
                    if (!nodeRelationDic.ContainsKey(custom.Id))
                    {
                        nodeRelationDic.Add(custom.Id, nodeRelation);
                    }
                    nodeRelationListT.Add(nodeRelation);

                    //添加分组关系
                    pathList.Add(custom.Id);

                    //如果是组,还需要递归处理,遍历子节点
                    RecursionCameraGroup(custom.items, pathList, groupDic, nodeRelationDic, nodeRelationListT);

                    //获取完路径后,要返回上一级路径
                    pathList.Remove(custom.Id);

                }
                else
                {
                    //其他类型节点不做处理
                }
            }
        }