CgwMonitorManage.Ivs.IvsVideoMonitor.GetAllCamerasMethod C# (CSharp) Method

GetAllCamerasMethod() private method

获取摄像头列表及分组信息
private GetAllCamerasMethod ( ) : void
return void
        private void GetAllCamerasMethod()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: IvsVideoMonitor.GetAllCamerasMethod().");
            try
            {
                //1、获取系统中所有的域
                List<IvsDomainRoute> ivsDomainRouteList;

                logEx.Trace("Call ivsSdkClient.GetDomainRoute().");
                int result = this.ivsSdkClient.GetDomainRoute(out ivsDomainRouteList);

                if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
                {
                    logEx.Info("GetDomainRoute success.List count:{0}", ivsDomainRouteList.Count);
                }
                else
                {
                    logEx.Error("GetDomainRoute failed.Ivs sdk error code:{0}", result);
                    ClearCamera();
                    isRefreshSucess = false;
                    return;
                }

                List<Camera> cameraListTemp = new List<Camera>();
                List<CameraGroup> groupListTemp = new List<CameraGroup>();
                List<NodeRelation> nodeRelationListTemp = new List<NodeRelation>();
                Dictionary<string, NodeRelation> nodeRelationDicTemp = new Dictionary<string, NodeRelation>();

                foreach (IvsDomainRoute route in ivsDomainRouteList)
                {
                    //加上此判断条件的话,子域将不会作查目录处理,不合理,故注释掉
                    //if (route.ParentDomain != "")
                    //{
                    //    continue;
                    //}
                    Dictionary<string, IvsCameraGroup> ivsCameraGroupDic;

                    logEx.Trace("Call ivsSdkClient.GetDeviceGroupList({0},{1},out groupCount, out ivsCameraGroupDic).",
                                route.DomainCode,
                                CgwConst.IVS_SDK_ROOTGROUP_TAG);

                    result = this.ivsSdkClient.GetDeviceGroupList(route.DomainCode,
                                                             CgwConst.IVS_SDK_ROOTGROUP_TAG,
                                                             out ivsCameraGroupDic);

                    if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
                    {
                        logEx.Info("GetDeviceGroupList success.Current group count:{0}", ivsCameraGroupDic.Count);
                    }
                    else
                    {
                        logEx.Error("GetDeviceGroupList failed.Ivs sdk error code:{0}", result);
                        ClearCamera();
                        isRefreshSucess = false;
                        return;
                    }

                    //域也当做分组使用
                    string encodeDomainNo = CgwConst.IVS_SDK_ROOTGROUP_TAG + CgwConst.IVS_SDK_DOMAINCODE_SEPARATOR_TAG + route.DomainCode;
                    CameraGroup domainGroup = new CameraGroup(encodeDomainNo, route.DomainName);
                    groupListTemp.Add(domainGroup);

                    List<string> pathDomainList = new List<string>();
                    RecursionGroupPath(route.DomainCode, ivsDomainRouteList,ref pathDomainList);
                    NodeRelation nodeDomainRelation = new NodeRelation(encodeDomainNo, pathDomainList, CgwMonitorManage.Common.NodeType.GROUP);
                    nodeRelationDicTemp.Add(encodeDomainNo, nodeDomainRelation);

                    foreach (KeyValuePair<string, IvsCameraGroup> ivsCameraGroupKeyValue in ivsCameraGroupDic)
                    {
                        IvsCameraGroup group = ivsCameraGroupKeyValue.Value;
                        string encodeGroupNo = group.GroupNo + CgwConst.IVS_SDK_DOMAINCODE_SEPARATOR_TAG + group.DomainCode;
                        //添加组信息
                        CameraGroup cameraGroup = new CameraGroup(encodeGroupNo, group.GroupName);
                        groupListTemp.Add(cameraGroup);

                        List<string> pathList = new List<string>();
                        RecursionPath(group.GroupNo, ivsCameraGroupDic, ref pathList);

                        NodeRelation nodeRelation = new NodeRelation(encodeGroupNo, pathList, CgwMonitorManage.Common.NodeType.GROUP);
                        nodeRelationDicTemp.Add(encodeGroupNo, nodeRelation);
                    }
                }
                //添加所有组节点
                nodeRelationListTemp.AddRange(nodeRelationDicTemp.Values);

                List<IvsCamera> ivsCameraPageList = new List<IvsCamera>();
                int cameraCount = 0;
                logEx.Trace("Call ivsSdkClient.GetDeviceList");

                //查询第一页记录,同时获取摄像头个数
                result = this.ivsSdkClient.GetDeviceList(CgwConst.PAGE_FIRST_INDEX, CgwConst.PAGE_LAST_INDEX, out cameraCount, out ivsCameraPageList);

                List<IvsCamera> ivsCameraLeaveList = new List<IvsCamera>();
                //如果总记录大于一页的总记录数
                if (cameraCount > CgwConst.PAGE_LAST_INDEX)
                {
                    //一次将剩下所有记录查询出来
                    result = this.ivsSdkClient.GetDeviceList(CgwConst.PAGE_LAST_INDEX + 1, cameraCount, out cameraCount, out ivsCameraLeaveList);
                }

                if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
                {
                    logEx.Info("GetDeviceList success.Current group count:{0}", cameraCount);
                    ivsCameraPageList.AddRange(ivsCameraLeaveList);
                }
                else
                {
                    logEx.Error("GetDeviceList failed.Ivs sdk error code:{0}", result);
                    ClearCamera();
                    isRefreshSucess = false;
                    return;
                }

                foreach (IvsCamera ivsCamera in ivsCameraPageList)
                {
                    Camera camera = new Camera(ivsCamera.No, ivsCamera.Name);
                    camera.Status = ivsCamera.Status;

                    List<string> cameraPathList = new List<string>();
                    //string encodeGroupNo = ivsCamera.GroupNo + CgwConst.IVS_SDK_DOMAINCODE_SEPARATOR_TAG + ivsCamera.DomainCode;//摄像头所属组号错误(与群组组号混淆了)。
                    string encodeGroupNo = ivsCamera.GroupNo;
                    if (nodeRelationDicTemp.ContainsKey(encodeGroupNo))
                    {
                        //如果自定义分组里面包含该摄像头的父节点,需要设置分组路径
                        cameraPathList.AddRange(nodeRelationDicTemp[encodeGroupNo].Path);
                        cameraPathList.Add(encodeGroupNo);
                    }

                    NodeRelation nodeRelation = new NodeRelation(camera.No, cameraPathList, CgwMonitorManage.Common.NodeType.CAMERA);

                    //解决问题单DTS2013080201001,规避因IVS服务器存在摄像头重复的bug导致融合网关异常的问题
                    if (!nodeRelationDicTemp.ContainsKey(camera.No))
                    {
                        cameraListTemp.Add(camera);
                        nodeRelationDicTemp.Add(camera.No, nodeRelation);
                    }

                    nodeRelationListTemp.Add(nodeRelation);
                }
                //nodeRelationListTemp.AddRange(nodeRelationDicTemp.Values);

                DateTime dtStart = DateTime.Now;
                DateTime dtNow = new DateTime();
                while (!isGetDevicesFinish)
                {
                    dtNow = DateTime.Now;

                    if ((dtNow - dtStart).TotalSeconds > refreshDeviceListOverTime)
                    {
                        isRefreshSucess = false;
                        return;
                    }
                    Thread.Sleep(1);
                    continue;
                }
                //将实时获取的值放到缓存
                if (this.cameraOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                {
                    try
                    {
                        this.cameraList = cameraListTemp;
                        this.groupList = groupListTemp;
                        this.nodeRelationList = nodeRelationListTemp;
                        isRefreshSucess = true;
                    }
                    catch (Exception ex)
                    {
                        isRefreshSucess = false;
                        logEx.Error("Set the list to the buffer failed. ", ex.Message);
                    }
                    finally
                    {
                        this.cameraOperateLock.ExitWriteLock();
                    }
                }
                else
                {
                    isRefreshSucess = false;
                }
            }
            catch (System.Exception ex)
            {
                logEx.Error("GetAllCamerasMethod failed.Exception message:{0}", ex.Message);
                isRefreshSucess = false;
            }
        }