Cgw.T28181.T28181VideoMonitor.GetCameraAndGroupRelation C# (CSharp) Method

GetCameraAndGroupRelation() private method

获取摄像头和组之间的关联
private GetCameraAndGroupRelation ( List cameraListTemp, List groupListTemp, List nodeRelationListTemp ) : void
cameraListTemp List 摄像机列表
groupListTemp List 分组列表
nodeRelationListTemp List 组关系列表
return void
        private void GetCameraAndGroupRelation(List<Camera> cameraListTemp, List<CameraGroup> groupListTemp, List<NodeRelation> nodeRelationListTemp)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: T28181VideoMonitor.GetCameraAndGroupRelation().");

            try
            {
                //查询摄像机的父节点,保存摄像机父节点关系列表
                foreach (Camera ca in cameraListTemp)
                {
                    //IVS 摄像机子设备通过主设备跟父节点关联,子设备没有父节点
                    if (ca.DeviceType == "01")
                    {
                        continue;
                    }
                    //摄像机没有父节点
                    if (string.IsNullOrEmpty(ca.ParentID))
                    {
                        NodeRelation nodeRelation = new NodeRelation(ca.No, null, NodeType.CAMERA);
                        nodeRelationListTemp.Add(nodeRelation);
                    }
                    else
                    {
                        string parentID = ca.ParentID;
                        //获取所有父节点路径
                        List<string> pathList = new List<string>();
                        FindNodeRelationPath(parentID, groupListTemp, ref pathList);

                        if (pathList.Count > 1)
                        {
                            //按照从顶到底排序
                            pathList.Reverse();
                        }

                        ////查询主设备的子设备
                        //Camera camera = cameraListTemp.Find((x)
                        //  =>
                        //{
                        //    if (x.ParentID == ca.No)
                        //    {
                        //        return true;
                        //    }
                        //    else
                        //    {
                        //        return false;
                        //    }
                        //});

                        //if (camera != null)
                        //{
                            //节点关系列表中将摄像机代替摄像机主设备
                        NodeRelation nodeRelation = new NodeRelation(ca.No, pathList, NodeType.CAMERA);
                            nodeRelationListTemp.Add(nodeRelation);
                        //}
                    }
                }

                //设备列表过滤掉摄像机主设备
                cameraListTemp.RemoveAll((x)
                    =>
                {
                    if (x.DeviceType == "00")
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                });

                //查询设备组的父节点,保存设备组父节点关系列表
                foreach (CameraGroup cg in groupListTemp)
                {
                    //设备组没有父节点
                    if (string.IsNullOrEmpty(cg.ParentID))
                    {
                        NodeRelation nodeRelation = new NodeRelation(cg.No, null, NodeType.GROUP);
                        nodeRelationListTemp.Add(nodeRelation);
                    }
                    else
                    {
                        string parentID = cg.ParentID;
                        //获取分组所有父节点路径
                        List<string> pathList = new List<string>();
                        FindNodeRelationPath(parentID, groupListTemp, ref pathList);

                        if (pathList.Count > 1)
                        {
                            //按照从顶到底排序
                            pathList.Reverse();
                        }
                        //保存分组的父节点列表
                        NodeRelation nodeRelation = new NodeRelation(cg.No, pathList, NodeType.GROUP);
                        nodeRelationListTemp.Add(nodeRelation);
                    }
                }

                //将实时获取的值放到缓存
                if (this.cameraOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                {
                    try
                    {
                        this.cameraList = cameraListTemp;
                        this.groupList = groupListTemp;
                        this.nodeRelationList = nodeRelationListTemp;
                    }
                    catch (Exception ex)
                    {
                        logEx.Error("Set the list to the buffer failed. ", ex.Message);
                    }
                    finally
                    {
                        this.cameraOperateLock.ExitWriteLock();
                    }
                }
            }
            catch (System.Exception ex)
            {
                logEx.Error("GetCameraAndGroupRelation failed. {0} ", ex.Message);
            }
        }