/// <summary> /// 获取摄像头列表及分组信息 /// </summary> /// <param name="isRealTime">是否实时获取,融合网关有个缓存,间隔一段时间获取,默认是从融合网关获取列表,如果该值为true,则实时获取</param> /// <param name="cameraList">摄像头列表</param> /// <param name="groupList">组信息</param> /// <param name="nodeRelationList">分组关系</param> /// <returns></returns> public SmcErr GetAllCameras(bool fromMonitorSys, out List<Camera> cameraList, out List<CameraGroup> groupList, out List<NodeRelation> nodeRelationList) { cameraList = new List<Camera>(); groupList = new List<CameraGroup>(); nodeRelationList = new List<NodeRelation>(); for (int i = 1; i < 10000; i++) { Camera cs = new Camera("41552873131314642203" + i.ToString(), i.ToString()); cs.DeviceType = "01"; cs.Status = CameraStatus.Online; //cs.ParentID = "41552873135005642565"; cameraList.Add(cs); } //CameraGroup group = new CameraGroup("41552873135005642565","group"); //groupList.Add(group); //NodeRelation rea = new NodeRelation("41552873135005642565", new List<string>(), NodeType.GROUP); //nodeRelationList.Add(rea); for (int i = 1; i < 10000; i++) { NodeRelation rea1 = new NodeRelation("41552873131314642203" + i.ToString(), new List<string>(), NodeType.CAMERA); nodeRelationList.Add(rea1); } return new CgwError(); //NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); //logEx.Trace("Enter: T28181VideoMonitor.GetAllCameras()."); //SmcErr err = new CgwError(); //cameraList = new List<Camera>(); //groupList = new List<CameraGroup>(); //nodeRelationList = new List<NodeRelation>(); //if (fromMonitorSys) //{ // //开始查询设备列表 // Thread th = new Thread(new ThreadStart(() // => // { // GetAllCamerasTimer(null, null); // })); // th.Priority = ThreadPriority.Highest; // th.Start(); // //等待结束查询 // th.Join(); //} //if (this.cameraOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME)) //{ // try // { // #region 深度克隆数据 // foreach (Camera ivsCamera in this.cameraList) // { // //从缓存获取 // Camera camera = new Camera(ivsCamera.No, ivsCamera.Name); // camera.Status = ivsCamera.Status; // cameraList.Add(camera); // } // foreach (CameraGroup cameraGroup in this.groupList) // { // CameraGroup cameraGroupTemp = new CameraGroup(cameraGroup.No, cameraGroup.Name); // groupList.Add(cameraGroupTemp); // } // foreach (NodeRelation nodeRelation in this.nodeRelationList) // { // NodeRelation nodeRelationTemp = new NodeRelation(nodeRelation.No, nodeRelation.Path, nodeRelation.Type); // nodeRelationList.Add(nodeRelationTemp); // } // #endregion // } // catch (Exception e) // { // err.SetErrorNo(CgwError.GET_ALL_CAMERAS_FAILED); // logEx.Error("Get all cameras failed.Execption message:{0}", e.Message); // return err; // } // finally // { // this.cameraOperateLock.ExitReadLock(); // } //} //logEx.Info("cameraList.{0}", cameraList.Count); //logEx.Info("groupList.{0}", groupList.Count); //logEx.Info("nodeRelationList.{0}", nodeRelationList.Count); //logEx.Info("Get all cameras success."); //return err; }
/// <summary> /// 获取摄像头和组之间的关联 /// </summary> /// <param name="cameraListTemp">摄像机列表</param> /// <param name="groupListTemp">分组列表</param> /// <param name="nodeRelationListTemp">组关系列表</param> 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); } }