Exemplo n.º 1
0
        /// <summary>
        /// 获取摄像头列表及分组信息
        /// </summary>
        /// <param name="fromMonitorSys">如果该值为true,则实时从监控平台获取,否则从融合网关缓存获取</param>
        /// <param name="cameraList">摄像头列表</param>
        /// <param name="groupList">组信息</param>
        /// <param name="nodeRelationList">分组关系</param>
        /// <returns></returns>
        public SmcErr GetAllCameras(PlatformType platformType, PagesParam pageParam, out List<Camera> cameraList, out List<CameraGroup> groupList, out List<NodeRelation> nodeRelationList, out PageInfo pagesInfo, PlatformLicenseInfo licenseInfo = null)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            cameraList = null;
            groupList = null;
            nodeRelationList = null;
            pagesInfo = null;

            err = CheckSession(currentSessionID);
            //调任何接口前 需要判断监控平台是否加载成功
            if (err.IsSuccess())
            {
                err = VideoMonitorManage.Instance().GetAllCameras(pageParam, out cameraList, out groupList, out nodeRelationList, out pagesInfo, licenseInfo);
            }
            if (err.IsSuccess())
            {
                logEx.Info("MonitorManageService QueryMonitorCamera  Successful,Current Cgw IP is : {0}", CgwConst.ClientIp);
            }
            else
            {
                logEx.Error("MonitorManageService QueryMonitorCamera failed,ErrNo :{0}", err.ErrNo);
            }
            return err;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取摄像头列表及分组信息
        /// </summary>
        /// <param name="fromMonitorSys">如果该值为true,则实时从监控平台获取,否则从融合网关缓存获取</param>
        /// <param name="cameraList">摄像头列表</param>
        /// <param name="groupList">组信息</param>
        /// <param name="nodeRelationList">分组关系</param>
        /// <returns></returns>
        public SmcErr GetAllCameras(PagesParam pageparam, out List<Camera> cameraList, out List<CameraGroup> groupList, out List<NodeRelation> nodeRelationList, out PageInfo pageinfo, PlatformLicenseInfo licenseInfo = null)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: VideoMonitorManage.GetAllCameras().");
            SmcErr err = new CgwError();
            cameraList = new List<Camera>();
            groupList = new List<CameraGroup>();
            nodeRelationList = new List<NodeRelation>();
            pageinfo = new PageInfo();
            //copy 一份,防止长时间占用锁
            Dictionary<string, IVideoMonitor> monitorsDictionaryTemp = null;

            if (this.monitorsOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    monitorsDictionaryTemp = new Dictionary<string, IVideoMonitor>(monitorsDictionary);
                }
                catch (Exception e)
                {
                    logEx.Error("Get all cameras failed.Execption message:{0}", e.Message);
                }
                finally
                {
                    this.monitorsOperateLock.ExitReadLock();
                }
            }
            if (monitorsDictionaryTemp == null)
            {
                //记录日志,获取*监控平台的摄像头列表失败
                logEx.Error("Get all cameras from monitor failed.No any monitor.");
                err.SetErrorNo(CgwError.GET_ALL_CAMERAS_FAILED);
                return err;
            }
            //循环已加载的所有的监控平台,将所有摄像头和分组组成一个list返回
            foreach (KeyValuePair<string, IVideoMonitor> monitor in monitorsDictionaryTemp)
            {
                //if ((monitor.Key == "ivs" || monitor.Key == "tiandy" || monitor.Key == "T28181IVS") && licenseInfo.IsMonitorPlatform == false)
                //{
                //    logEx.Warn("GetAllCameras.smc license no right:{0}", monitor.Key);
                //    continue;
                //}
                //if (monitor.Key == "eLTE" && licenseInfo.IsEltePlatform == false)
                //{
                //    logEx.Warn("GetAllCameras.smc license no right:{0}", monitor.Key);
                //    continue;
                //}
                IVideoMonitor videoMonitor = monitor.Value;

                List<Camera> cameraListTemp;
                List<CameraGroup> groupListTemp;
                List<NodeRelation> nodeRelationListTemp;

                err = videoMonitor.GetAllCameras(out cameraListTemp, out groupListTemp, out nodeRelationListTemp);

                if (err.IsSuccess())
                {
                    //摄像头编号加上监控平台唯一标识
                    foreach (Camera camera in cameraListTemp)
                    {
                        camera.No = EncodeNo(camera.No, monitor.Key);
                        cameraList.Add(camera);
                    }

                    //组编号加上监控平台唯一标识
                    foreach (CameraGroup cameraGroup in groupListTemp)
                    {
                        cameraGroup.No = EncodeNo(cameraGroup.No, monitor.Key);
                        groupList.Add(cameraGroup);
                    }

                    //节点关系编号加上监控平台唯一标识
                    foreach (NodeRelation nodeRelation in nodeRelationListTemp)
                    {
                        nodeRelation.No = EncodeNo(nodeRelation.No, monitor.Key);
                        List<string> pathListTemp = null;
                        if (null != nodeRelation.Path)
                        {
                            pathListTemp = new List<string>();
                            foreach (string path in nodeRelation.Path)
                            {
                                pathListTemp.Add(EncodeNo(path, monitor.Key));
                            }
                        }
                        nodeRelation.Path = pathListTemp;

                        nodeRelationList.Add(nodeRelation);
                    }

                }
                else
                {
                    //记录日志,获取*监控平台的摄像头列表失败
                    logEx.Error("Get all cameras from monitor failed.Monitor id:{0} ,Error code:{1}", monitor.Key, err.ErrNo);
                    err.SetErrorNo(CgwError.GET_ALL_CAMERAS_FAILED);
                    continue;
                }
            }

            //2015/2/26 打印日志
            logEx.Info("all List Counts.");
            logEx.Info("cameraList:" + cameraList.Count);
            logEx.Info("groupList:" + groupList.Count);
            logEx.Info("nodeRelationList:" + nodeRelationList.Count);

            #region 判断传递的pageParam信息的合法性
            //计算cameraList、groupList、nodeRelationList中数据最多的列表长度
            int maxNum = (cameraList.Count > groupList.Count) ? cameraList.Count : groupList.Count;
            maxNum = maxNum > nodeRelationList.Count ? maxNum : nodeRelationList.Count;

            pageinfo.TotalRecords = maxNum;
            logEx.Info("GetAllCameras.pageparam.CurrentPage ={0},pageparam.NumberPerPage ={1}", pageparam.CurrentPage, pageparam.NumberPerPage);
            if (pageparam.CurrentPage <= 0 || pageparam.NumberPerPage <= 0) //如果当前页数或者每页条数小于0,则提示错误
            {
                logEx.Error("The CurrentPage or NumberPerPage can not be smaller than zero ,the CurrentPage is {0},the NumberPerPage is {1}", pageparam.CurrentPage, pageparam.NumberPerPage);
                err.SetErrorNo(CgwError.GET_ALL_CAMERAS_FAILED);
                cameraList = new List<Camera>();
                groupList = new List<CameraGroup>();
                nodeRelationList = new List<NodeRelation>();
                pageinfo = new PageInfo();
                return err;
            }
            else if (maxNum == 0)
            {
                pageinfo = new PageInfo();
                return err;
            }
            else if (maxNum % pageparam.NumberPerPage != 0)
            {
                if (pageparam.CurrentPage > (pageinfo.TotalRecords / pageparam.NumberPerPage + 1)) //如果当前页数大于记录总页数,则提示错误
                {
                    logEx.Error("The CurrentPage can not be more than The Total pageNum(odd),the CurrentPage is {0},the Total PageNum is {1}", pageparam.CurrentPage, pageinfo.TotalRecords / pageparam.NumberPerPage + 1);
                    err.SetErrorNo(CgwError.GET_ALL_CAMERAS_FAILED);
                    cameraList = new List<Camera>();
                    groupList = new List<CameraGroup>();
                    nodeRelationList = new List<NodeRelation>();
                    pageinfo = new PageInfo();
                    return err;
                }
            }
            else
            {
                if (pageparam.CurrentPage > (pageinfo.TotalRecords / pageparam.NumberPerPage)) //如果当前页数大于记录总页数,则提示错误
                {
                    logEx.Error("The CurrentPage can not be more than The Total pageNum(even),the CurrentPage is {0},the Total PageNum is {1}", pageparam.CurrentPage, pageinfo.TotalRecords / pageparam.NumberPerPage);
                    err.SetErrorNo(CgwError.GET_ALL_CAMERAS_FAILED);
                    cameraList = new List<Camera>();
                    groupList = new List<CameraGroup>();
                    nodeRelationList = new List<NodeRelation>();
                    pageinfo = new PageInfo();
                    return err;
                }
            }
            #endregion

            #region 设置返回项PageInfo的值
            pageinfo.TotalRecords = maxNum;
            pageinfo.CurrentPage = pageparam.CurrentPage;
            if (pageinfo.TotalRecords % pageparam.NumberPerPage != 0)
            {
                pageinfo.TotalPages = pageinfo.TotalRecords / pageparam.NumberPerPage + 1;
            }
            else
            {
                pageinfo.TotalPages = pageinfo.TotalRecords / pageparam.NumberPerPage;

            }
            #endregion

            #region 分割数据列表
            List<Camera> CameraListTemp = new List<Camera>(); ;
            List<CameraGroup> CameraGroupTemp = new List<CameraGroup>(); ;
            List<NodeRelation> CamerNodeRelationaListTemp = new List<NodeRelation>();

            int BeforeCurrentPageNum = (pageparam.CurrentPage - 1) * pageparam.NumberPerPage;   //vsd传递的当前页(PageParam.CurrentPage)之前的数据总数
            //cameraList ↓↓
            if (null != cameraList && cameraList.Count > 0)
            {
                for (int i = BeforeCurrentPageNum; i < BeforeCurrentPageNum + pageparam.NumberPerPage; i++)  //i从0开始
                {
                    if (i > cameraList.Count - 1)
                    {
                        break;
                    }
                    CameraListTemp.Add(cameraList[i]);
                }
                cameraList = CameraListTemp;
            }
            //groupList↓↓
            if (null != groupList && groupList.Count > 0)
            {
                for (int i = BeforeCurrentPageNum; i < BeforeCurrentPageNum + pageparam.NumberPerPage; i++)   //将请求页中包含的数据读取出来,并赋值给groupList
                {
                    if (i > groupList.Count - 1)
                    {
                        break;
                    }
                    CameraGroupTemp.Add(groupList[i]);
                }
                groupList = CameraGroupTemp;
            }
            //nodeRelationList↓↓
            if (null != nodeRelationList && nodeRelationList.Count > 0)
            {
                for (int i = BeforeCurrentPageNum; i < BeforeCurrentPageNum + pageparam.NumberPerPage; i++)   //将请求页中包含的数据读取出来,并赋值给nodeRelationList
                {
                    if (i > nodeRelationList.Count - 1)
                    {
                        break;
                    }
                    CamerNodeRelationaListTemp.Add(nodeRelationList[i]);
                }
                nodeRelationList = CamerNodeRelationaListTemp;
            }
            #endregion

            logEx.Info("Get all cameras success.");
            //特殊处理,监控平台统一返回成功,做轮询处理
            err.SetErrorNo(SmcErr.SMC_ERR_SUCCESS);
            return err;
        }