Exemplo n.º 1
0
        /// <summary>
        /// 指定码流回调函数
        /// </summary>
        /// <param name="dataCallBack">回调函数</param>
        public void SetDataCallBackFunc(DataCallBack dataCallBack)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: VideoMonitorManage.SetVideoDataCallBackFunc({0})", dataCallBack);
            //向上回调,平台管理接到码流后,对摄像头编号加上平台标识,再执行回调转发码流
            this.dataCallBack = dataCallBack;

            //向下注册回调,在该回调函数VideoDataCallBackFunc内要先对摄像头编号加上平台标识
            DataCallBack callBack = this.DataCallBackFunc;

            if (this.monitorsOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    foreach (KeyValuePair <string, IVideoMonitor> monitor in monitorsDictionary)
                    {
                        IVideoMonitor videoMonitor = monitor.Value;
                        videoMonitor.SetDataCallBackFunc(callBack, monitor.Key);
                    }
                }
                catch (Exception e)
                {
                    logEx.Error("Set VideoDataCallBackFunc failed.Execption message:{0}", e.Message);
                }
                finally
                {
                    this.monitorsOperateLock.ExitReadLock();
                }
            }
            logEx.Trace("Set VideoDataCallBackFunc success.");
        }
Exemplo n.º 2
0
        /// <summary>
        /// 刷新监控摄像头列表
        /// </summary>
        /// <returns></returns>
        public SmcErr RefreshMonitorCamera()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: VideoMonitorManage.RefreshMonitorCamera.");
            SmcErr err = new SmcErr();

            //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("RefreshMonitorCamera failed.Execption message:{0}", e.Message);
                }
                finally
                {
                    this.monitorsOperateLock.ExitReadLock();
                }
            }
            if (monitorsDictionaryTemp == null)
            {
                //记录日志,获取*监控平台的摄像头列表失败
                logEx.Error("RefreshMonitorCamera from monitor failed.No any monitor.");
                err.SetErrorNo(CgwError.ERR_REFRESH_MONITOR_CAMERA_FAIL);
                return(err);
            }

            //循环已加载的所有的监控平台,将所有摄像头和分组组成一个list返回
            foreach (KeyValuePair <string, IVideoMonitor> monitor in monitorsDictionaryTemp)
            {
                IVideoMonitor videoMonitor = monitor.Value;
                err = videoMonitor.RefreshMonitorCamera();

                if (err.IsSuccess())
                {
                    logEx.Info("RefreshMonitorCamera success.");
                }
                else
                {
                    logEx.Error("RefreshMonitorCamera failed.");
                    err.SetErrorNo(CgwError.ERR_REFRESH_MONITOR_CAMERA_FAIL);
                    break;
                }
            }
            return(err);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 注销监控平台资源
        /// </summary>
        /// <returns></returns>
        public SmcErr Unload()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Info("Enter: VideoMonitorManage.Unload().");
            SmcErr err = new CgwError();

            if (this.monitorsOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    foreach (KeyValuePair <string, IVideoMonitor> monitor in monitorsDictionary)
                    {
                        IVideoMonitor videoMonitor = monitor.Value;
                        SmcErr        result       = videoMonitor.Unload();
                        if (!result.IsSuccess())
                        {
                            logEx.Error("Unload monitor failed.Monitor id:{0} ,Error code:{1}", monitor.Key, result.ErrNo);
                            //一个失败,记录失败,继续其他平台卸载
                            err.SetErrorNo(result.ErrNo);
                            continue;
                        }
                    }
                    monitorsDictionary.Clear();
                }
                catch (Exception e)
                {
                    logEx.Error("Unload monitor failed..Execption message:{0}", e.Message);
                }
                finally
                {
                    this.monitorsOperateLock.ExitWriteLock();
                }
            }

            return(err);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 创建监控平台实例
        /// </summary>
        /// <param name="monitorElement"></param>
        /// <returns></returns>
        private SmcErr CreateMonitor(string monitorId, string className, out IVideoMonitor videoMonitor)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: VideoMonitorManage.CreateMonitor().");
            SmcErr err = new CgwError();

            videoMonitor = null;
            if (this.monitorsOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    if (monitorsDictionary.ContainsKey(monitorId))
                    {
                        //监控平台的id重复
                        err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID_ID_EXIST);
                        logEx.Error("Monitor id has been exist. Monitor id:{0}.", monitorId);
                        return(err);
                    }
                }
                catch (Exception e)
                {
                    logEx.Error("CreateMonitor failed..Execption message:{0}", e.Message);
                }
                finally
                {
                    this.monitorsOperateLock.ExitWriteLock();
                }
            }

            Type monitorType = Type.GetType(className);

            if (monitorType == null)
            {
                //class不合法
                err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID_CLASS_INVALID);
                logEx.Error("The class of Monitor is invalid. Class:{0}, Monitor id:{1}.", className, monitorId);
                return(err);
            }

            try
            {
                //create instance
                logEx.Info("VideoMonitorManage.className = {0}", className);

                if (className == "CgwMonitorManage.eLTE.eLTEVideoMonitor,CgwMonitorManage.eLTE")
                {
                    //eLTE dll放在eLTeSDK目录下,否则跟ivs DLL冲突
                    string strPath = System.AppDomain.CurrentDomain.BaseDirectory;
                    System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(strPath + @"eLTeSDK\CgwMonitorManage.eLTE.dll");
                    Type[] types = assembly.GetTypes();

                    if (types.Length > 0)
                    {
                        monitorType = types.First((x) => x.FullName == "CgwMonitorManage.eLTE.eLTEVideoMonitor");
                    }
                }
                else if (className == "CgwMonitorManage.Ivs.IvsVideoMonitor,CgwMonitorManage.Ivs")
                {
                    string strPath = System.AppDomain.CurrentDomain.BaseDirectory;
                    System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(strPath + @"IVSSDK\CgwMonitorManage.Ivs.dll");
                    Type[] types = assembly.GetTypes();
                    if (types.Length > 0)
                    {
                        monitorType = types.First((x) => x.FullName == "CgwMonitorManage.Ivs.IvsVideoMonitor");
                    }
                }
                logEx.Info("VideoMonitorManage.monitorType = {0}", monitorType);
                videoMonitor = Activator.CreateInstance(monitorType) as CgwMonitorManage.Common.IVideoMonitor;
            }
            catch (Exception e)
            {
                //无法加载指定的类
                err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID_CLASS_INVALID);
                logEx.Error("The class of Monitor is invalid. May be not as IVideoMonitor. Class:{0}, Monitor id:{1},Exception message:{2}.",
                            className, monitorId, e.Message);
                return(err);
            }

            if (videoMonitor == null)
            {
                //无法加载指定的类
                err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID_CLASS_INVALID);
                logEx.Error("The class of Monitor is invalid. May be not as IVideoMonitor. Class:{0}, Monitor id:{1}.", className, monitorId);
                return(err);
            }

            return(err);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取监控摄像头列表刷新状态,返回结果为0是表示刷新完毕,为1是刷新操作中。当查询刷新状态为0时,可调用获取监控摄像头列表接口,获取刷新后监控摄像头列表
        /// </summary>
        /// <returns></returns>
        public SmcErr GetRefreshStatus(out SmcErr refreshStatus)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: VideoMonitorManage.GetRefreshStatus.");

            refreshStatus       = new SmcErr();
            refreshStatus.ErrNo = CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_END;
            SmcErr err = new SmcErr();

            //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("GetRefreshStatus failed.Execption message:{0}", e.Message);
                }
                finally
                {
                    this.monitorsOperateLock.ExitReadLock();
                }
            }
            if (monitorsDictionaryTemp == null)
            {
                //记录日志,获取*监控平台的摄像头列表失败
                logEx.Error("GetRefreshStatus from monitor failed.No any monitor.");
                err.SetErrorNo(CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_FAILED);
                return(err);
            }
            //循环已加载的所有的监控平台,将所有摄像头和分组组成一个list返回

            SmcErr tempMonitor = new SmcErr();

            tempMonitor.ErrNo = CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_END;
            SmcErr tempLTE = new SmcErr();

            tempLTE.ErrNo = CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_END;

            foreach (KeyValuePair <string, IVideoMonitor> monitor in monitorsDictionaryTemp)
            {
                IVideoMonitor videoMonitor = monitor.Value;

                if (monitor.Key != "eLTE")
                {
                    if (tempMonitor.ErrNo == CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_END)
                    {
                        err = videoMonitor.GetRefreshStatus(out tempMonitor);
                    }
                }
                else
                {
                    err = videoMonitor.GetRefreshStatus(out tempLTE);
                }

                if (!err.IsSuccess())
                {
                    logEx.Error("GetRefreshStatus failed.");
                    err.SetErrorNo(CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_FAILED);
                    refreshStatus.ErrNo = CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_FAILED;
                    return(err);
                }
            }

            //监控和elte都刷新完毕
            if (tempMonitor.ErrNo == CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_END && tempLTE.ErrNo == CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_END)
            {
                refreshStatus.ErrNo = CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_END;
            }
            //监控和elte都刷新执行中
            else if (tempMonitor.ErrNo == CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_EXECUTING && tempLTE.ErrNo == CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_EXECUTING)
            {
                refreshStatus.ErrNo = CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_EXECUTING;
            }
            //监控和elte都刷新失败
            else if (tempMonitor.ErrNo == CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_FAILED && tempLTE.ErrNo == CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_FAILED)
            {
                refreshStatus.ErrNo = CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_FAILED;
            }
            //监控成功、elte失败
            else if (tempMonitor.ErrNo == CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_END && tempLTE.ErrNo == CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_FAILED)
            {
                refreshStatus.ErrNo = CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_MONITOR_SUCCESS_ELTE_FAIL;
            }
            //监控成功、elte执行中
            else if (tempMonitor.ErrNo == CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_END && tempLTE.ErrNo == CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_EXECUTING)
            {
                refreshStatus.ErrNo = CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_MONITOR_SUCCESS_ELTE_EXECUTING;
            }
            //监控执行中、elte成功
            else if (tempMonitor.ErrNo == CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_EXECUTING && tempLTE.ErrNo == CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_END)
            {
                refreshStatus.ErrNo = CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_MONITOR_EXECUTING_ELTE_SUCCESS;
            }
            //监控执行中、elte失败
            else if (tempMonitor.ErrNo == CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_EXECUTING && tempLTE.ErrNo == CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_FAILED)
            {
                refreshStatus.ErrNo = CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_MONITOR_EXECUTING_ELTE_FAIL;
            }
            //监控失败、elte成功
            else if (tempMonitor.ErrNo == CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_FAILED && tempLTE.ErrNo == CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_END)
            {
                refreshStatus.ErrNo = CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_MONITOR_FAIL_ELTE_SUCCESS;
            }
            //监控失败、elte执行中
            else if (tempMonitor.ErrNo == CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_FAILED && tempLTE.ErrNo == CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_EXECUTING)
            {
                refreshStatus.ErrNo = CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_MONITOR_FAIL_ELTE_EXECUTING;
            }
            return(err);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 解码摄像头编号
        /// </summary>
        /// <param name="encodedCameraNo">编码过的摄像头编号</param>
        /// <param name="cameraNo">解码后的摄像头编号</param>
        /// <param name="videoMonitor">监控平台实例</param>
        /// <returns></returns>
        private SmcErr DecoderCameraNo(string encodedCameraNo, out string cameraNo, out IVideoMonitor videoMonitor)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: VideoMonitorManage.DecoderCameraNo({0}).", encodedCameraNo);
            SmcErr err = new CgwError();

            cameraNo     = string.Empty;
            videoMonitor = null;

            //判断方式不合适
            if (string.IsNullOrEmpty(encodedCameraNo))
            //if (encodedCameraNo == null)
            {
                logEx.Error("Camera no is null.");
                err.SetErrorNo(CgwError.CAMERA_NOT_FOUND);
                return(err);
            }

            if (!encodedCameraNo.Contains(CgwConst.MONITOR_SEPARATOR_TAG))
            {
                logEx.Error("Camera no is not found. Camera no:{0}.", encodedCameraNo);
                err.SetErrorNo(CgwError.CAMERA_NOT_FOUND);
                return(err);
            }
            string[] monirotAndCamera = encodedCameraNo.Split(
                new string[] { CgwConst.MONITOR_SEPARATOR_TAG },
                StringSplitOptions.RemoveEmptyEntries);


            if (this.monitorsOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    //encodedCameraNo是用监控平台id+分割符MONITOR_SEPARATOR_TAG编码的,
                    //用分隔符MONITOR_SEPARATOR_TAG分割后,长度为2,否则为非法编号
                    if (monirotAndCamera.Length == CgwConst.ENCODE_CAMERANO_LENGHT)
                    {
                        if (monitorsDictionary.ContainsKey(monirotAndCamera[0]))
                        {
                            videoMonitor = monitorsDictionary[monirotAndCamera[0]];
                            cameraNo     = monirotAndCamera[1];
                            return(err);
                        }
                        else
                        {
                            logEx.Error("Monitor id is not found. Monitor id:{0}.", monirotAndCamera[0]);
                            err.SetErrorNo(CgwError.MONITOR_NOT_FOUND);
                            return(err);
                        }
                    }
                    else
                    {
                        logEx.Error("Camera no is invalid. Camera no:{0}.", encodedCameraNo);
                        err.SetErrorNo(CgwError.CAMERA_NOT_FOUND);
                        return(err);
                    }
                }
                catch (Exception e)
                {
                    err.SetErrorNo(CgwError.CAMERA_NOT_FOUND);
                    logEx.Error("Decoder camera no failed. Execption message:{0}", e.Message);
                }
                finally
                {
                    this.monitorsOperateLock.ExitReadLock();
                }
            }
            return(err);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 创建监控平台实例
        /// </summary>
        /// <param name="monitorElement"></param>
        /// <returns></returns>
        private SmcErr CreateMonitor(string monitorId, string className, out IVideoMonitor videoMonitor)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: VideoMonitorManage.CreateMonitor().");
            SmcErr err = new CgwError();
            videoMonitor = null;
            if (this.monitorsOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    if (monitorsDictionary.ContainsKey(monitorId))
                    {
                        //监控平台的id重复
                        err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID_ID_EXIST);
                        logEx.Error("Monitor id has been exist. Monitor id:{0}.", monitorId);
                        return err;
                    }
                }
                catch (Exception e)
                {
                    logEx.Error("CreateMonitor failed..Execption message:{0}", e.Message);
                }
                finally
                {
                    this.monitorsOperateLock.ExitWriteLock();
                }
            }

            Type monitorType = Type.GetType(className);
            if (monitorType == null)
            {
                //class不合法
                err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID_CLASS_INVALID);
                logEx.Error("The class of Monitor is invalid. Class:{0}, Monitor id:{1}.", className, monitorId);
                return err;
            }

            try
            {
                //create instance
                logEx.Info("VideoMonitorManage.className = {0}", className);

                if (className == "CgwMonitorManage.eLTE.eLTEVideoMonitor,CgwMonitorManage.eLTE")
                {
                    //eLTE dll放在eLTeSDK目录下,否则跟ivs DLL冲突
                    string strPath = System.AppDomain.CurrentDomain.BaseDirectory;
                    System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(strPath + @"eLTeSDK\CgwMonitorManage.eLTE.dll");
                    Type[] types = assembly.GetTypes();

                    if (types.Length > 0)
                    {
                        monitorType = types.First((x) => x.FullName == "CgwMonitorManage.eLTE.eLTEVideoMonitor");
                    }
                }
                else if (className == "CgwMonitorManage.Ivs.IvsVideoMonitor,CgwMonitorManage.Ivs")
                {
                    string strPath = System.AppDomain.CurrentDomain.BaseDirectory;
                    System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(strPath + @"IVSSDK\CgwMonitorManage.Ivs.dll");
                    Type[] types = assembly.GetTypes();
                    if (types.Length > 0)
                    {
                        monitorType = types.First((x) => x.FullName == "CgwMonitorManage.Ivs.IvsVideoMonitor");
                    }
                }
                logEx.Info("VideoMonitorManage.monitorType = {0}", monitorType);
                videoMonitor = Activator.CreateInstance(monitorType) as CgwMonitorManage.Common.IVideoMonitor;
            }
            catch (Exception e)
            {
                //无法加载指定的类
                err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID_CLASS_INVALID);
                logEx.Error("The class of Monitor is invalid. May be not as IVideoMonitor. Class:{0}, Monitor id:{1},Exception message:{2}.",
                             className, monitorId, e.Message);
                return err;
            }

            if (videoMonitor == null)
            {
                //无法加载指定的类
                err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID_CLASS_INVALID);
                logEx.Error("The class of Monitor is invalid. May be not as IVideoMonitor. Class:{0}, Monitor id:{1}.", className, monitorId);
                return err;
            }

            return err;
        }
Exemplo n.º 9
0
        /// <summary>
        /// 解码摄像头编号
        /// </summary>
        /// <param name="encodedCameraNo">编码过的摄像头编号</param>
        /// <param name="cameraNo">解码后的摄像头编号</param>
        /// <param name="videoMonitor">监控平台实例</param>
        /// <returns></returns>
        private SmcErr DecoderCameraNo(string encodedCameraNo, out string cameraNo, out IVideoMonitor videoMonitor)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: VideoMonitorManage.DecoderCameraNo({0}).", encodedCameraNo);
            SmcErr err = new CgwError();
            cameraNo = string.Empty;
            videoMonitor = null;

            //判断方式不合适
            if(string.IsNullOrEmpty(encodedCameraNo))
            //if (encodedCameraNo == null)
            {
                logEx.Error("Camera no is null.");
                err.SetErrorNo(CgwError.CAMERA_NOT_FOUND);
                return err;
            }

            if (!encodedCameraNo.Contains(CgwConst.MONITOR_SEPARATOR_TAG))
            {
                logEx.Error("Camera no is not found. Camera no:{0}.", encodedCameraNo);
                err.SetErrorNo(CgwError.CAMERA_NOT_FOUND);
                return err;
            }
            string[] monirotAndCamera = encodedCameraNo.Split(
                                                             new string[] { CgwConst.MONITOR_SEPARATOR_TAG },
                                                             StringSplitOptions.RemoveEmptyEntries);

            if (this.monitorsOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    //encodedCameraNo是用监控平台id+分割符MONITOR_SEPARATOR_TAG编码的,
                    //用分隔符MONITOR_SEPARATOR_TAG分割后,长度为2,否则为非法编号
                    if (monirotAndCamera.Length == CgwConst.ENCODE_CAMERANO_LENGHT)
                    {
                        if (monitorsDictionary.ContainsKey(monirotAndCamera[0]))
                        {
                            videoMonitor = monitorsDictionary[monirotAndCamera[0]];
                            cameraNo = monirotAndCamera[1];
                            return err;
                        }
                        else
                        {
                            logEx.Error("Monitor id is not found. Monitor id:{0}.", monirotAndCamera[0]);
                            err.SetErrorNo(CgwError.MONITOR_NOT_FOUND);
                            return err;
                        }
                    }
                    else
                    {
                        logEx.Error("Camera no is invalid. Camera no:{0}.", encodedCameraNo);
                        err.SetErrorNo(CgwError.CAMERA_NOT_FOUND);
                        return err;
                    }
                }
                catch (Exception e)
                {
                    err.SetErrorNo(CgwError.CAMERA_NOT_FOUND);
                    logEx.Error("Decoder camera no failed. Execption message:{0}", e.Message);
                }
                finally
                {
                    this.monitorsOperateLock.ExitReadLock();
                }
            }
            return err;
        }