Exemplo n.º 1
0
        /// <summary>
        /// 检查Session
        /// </summary>
        /// <returns></returns>
        private SmcErr CheckSession()
        {
            NLogEx.LoggerEx logEx      = new NLogEx.LoggerEx(log);
            SmcErr          err        = new CgwError();
            CGWSession      CgwSession = null;

            if (OperationContext.Current != null)
            {
                string strSessionId = OperationContext.Current.SessionId;
                err = SessionManage.Instance().GetSessionsBySessionId(strSessionId, out CgwSession);

                if (err.IsSuccess() == false || CgwSession == null)
                {
                    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_SESSION_NULL);
                }
                else
                {
                    //更新Session最后访问时间
                    CgwSession.LastVisitedTime = DateTime.Now;
                    logEx.Trace("Current SessionId is:{0}, LastVisitedTime is :{1}", strSessionId, CgwSession.LastVisitedTime.ToLongTimeString());
                }
            }
            else
            {
                err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CURRENTSESSION_NULL);
            }

            return(err);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取监控平台配置
        /// </summary>
        /// <param name="monitorElement"></param>
        /// <returns></returns>
        private SmcErr GetMonitorConfig(XmlElement monitorElement, out string monitorId, out string className)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: VideoMonitorManage.GetMonitorConfig().");
            SmcErr err = new CgwError();

            monitorId = CommonFunction.GetSingleNodeValue(monitorElement, CgwConst.ID_TAG);

            className = CommonFunction.GetSingleNodeValue(monitorElement, CgwConst.CLASS_TAG);

            if (string.IsNullOrEmpty(monitorId))
            {
                //监控平台id不能为空
                err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID_ID_NULL);

                logEx.Error("Monitor id can not be null.");
                return(err);
            }

            if (string.IsNullOrEmpty(className))
            {
                //监控平台 {0}的class不能为空
                err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID_CLASS_NULL);

                logEx.Error("The class of Monitor is null. Monitor id:{0}.", monitorId);
                return(err);
            }

            return(err);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 断开监控管理连接
        /// </summary>
        /// <returns></returns>
        public SmcErr Disconnect()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            SmcErr          err   = new CgwError();

            if (OperationContext.Current != null)
            {
                //string strSessionId = OperationContext.Current.SessionId;
                string strSessionId = currentSessionID;
                if (!string.IsNullOrEmpty(strSessionId))
                {
                    err = SessionManage.Instance().RemoveSessionBySessionId(strSessionId);
                    logEx.Info("Client DisConnect MonitorManageService Successful,Current.Cgw IP is : {0}", CgwConst.ClientIp);
                }
                else
                {
                    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CURRENTSESSION_NULL);
                    logEx.Warn("Current SessionId is null ! ");
                }
            }
            else
            {
                err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CURRENTSESSION_NULL);
                logEx.Warn("Current SessionId is null ! ");
            }

            return(err);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 断开融合网关
        /// </summary>
        /// <returns></returns>
        public SmcErr DisConnect()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            SmcErr          err   = new CgwError();

            if (OperationContext.Current != null)
            {
                string strSessionId = OperationContext.Current.SessionId;
                if (!string.IsNullOrEmpty(strSessionId))
                {
                    err = SessionManage.Instance().RemoveSessionBySessionId(strSessionId);
                    logEx.Trace("DisConnect Successful,Current.SessionId is : ", strSessionId);
                }
                else
                {
                    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CURRENTSESSION_NULL);
                    logEx.Warn("Current SessionId is null ! ");
                }
            }
            else
            {
                err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CURRENTSESSION_NULL);
                logEx.Warn("Current SessionId is null ! ");
            }

            return(err);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 连接融合网关
        /// </summary>
        /// <param name="cgwPwd">连接字符串</param>
        /// <returns></returns>
        public SmcErr Connect(string cgwPwd)
        {
            SmcErr err = new CgwError();

            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            if (isLoadSuccess == false)
            {
                err.SetErrorNo(CgwError.ERR_CGW_IS_LOADING);
                return(err);
            }
            //if (false == string.IsNullOrEmpty(cgwPwd))
            //{

            ////进行SHA256加密
            //string newPassword = CommonFunction.SHA256Encrypt(strPwd);
            //保存当前会话
            //if (newPassword == cgwPwd)
            //{
            //获取SessionManage中Session个数
            if (SessionManage.Instance().GetSessionsCount() == 0)
            {
                Guid sessionGuid = Guid.NewGuid();
                //保存至CGW的session管理中
                CgwSession CgwSession = new CgwSession(sessionGuid, OperationContext.Current.SessionId);

                isChangeLic = false;
                MessageProperties properties = OperationContext.Current.IncomingMessageProperties;                                        //获取传进的消息属性

                RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; //获取消息发送的远程终结点IP和端口
                if (endpoint != null)
                {
                    CgwConst.SmcIp = endpoint.Address;         // 获取发送消息的客户端的 IP 地址。
                    logEx.Info("SMC Connect CgwService Successful,Current.SMC IP is : {0}", CgwConst.SmcIp);
                }
                else
                {
                    logEx.Info("SMC Connect CgwService Successful,Current.SMC IP is  null.");
                }
            }
            else
            {
                err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_SESSION_COUNT_MAX);
                logEx.Warn("Session Count is  Top Of Max number !");
            }

            //}
            //else
            //{
            //    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_PASSWORD_INCORRECT);
            //    logEx.Error("Connect Password is Incorrect !");
            //}
            //}
            //else
            //{
            //    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_PASSWORD_NULL);
            //    logEx.Error("Connect Password is null !");
            //}
            return(err);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 停止预览
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <returns>成功返回0,失败返回错误码</returns>
        public SmcErr StopReceiveVideo(string cameraNo)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: T28181VideoMonitor.StopReceiveVideo({0}).", cameraNo);
            SmcErr err = new CgwError();
            //需要停止的预览句柄
            uint needToStopChannel = 0;

            if (this.handelOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    if (this.cameraVideoChannelDic.ContainsKey(cameraNo))
                    {
                        needToStopChannel = this.cameraVideoChannelDic[cameraNo];
                        this.videoChannelDataSenderDic.Remove(needToStopChannel);
                        this.cameraVideoChannelDic.Remove(cameraNo);
                        //关闭rtp回调
                        rtpAdapter.ESDK_RTP_CloseChannel(needToStopChannel);
                    }
                    else
                    {
                        logEx.Warn("Stop Receive camera video data failed. Don't need to end the preview.Camera No:{0}.", cameraNo);
                        //如果预览句柄不存在,不需要处理,直接返回
                        return(err);
                    }
                }
                catch (Exception ex)
                {
                    err.SetErrorNo(CgwError.STOP_RECEIVE_VIDEO_FAILED);
                    logEx.Error("Stop Receive camera video data failed.Execption message:{0}", ex.Message);
                    return(err);
                }
                finally
                {
                    this.handelOperateLock.ExitWriteLock();
                }
            }

            //调用sdk的停止方法,放在handelOperateLock外面,防止长时间占用锁
            if (needToStopChannel != 0)
            {
                int result = sipStack.StopRecvStream(needToStopChannel);
                //如果不为0,表示预览失败
                if (result != CgwConst.IVS_SDK_SUCCESS_TAG)
                {
                    err.SetErrorNo(CgwError.STOP_RECEIVE_VIDEO_FAILED);
                    logEx.Error("Stop Receive camera video data failed. error code:{0}", result);
                    return(err);
                }
                logEx.Info("Stop Receive camera video data success.Camera No:{0},Handle:{1}.", cameraNo, needToStopChannel);
            }

            return(err);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 停止预览
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <returns>成功返回0,失败返回错误码</returns>
        public SmcErr StopReceiveVideo(string cameraNo)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: IvsVideoMonitor.StopReceiveVideo({0}).", cameraNo);
            SmcErr err = new CgwError();
            //需要停止的预览句柄
            int needToStopHandel = CgwConst.START_RECEIVE_VIDEO_DATA_FAILED;

            if (this.handelOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    if (this.cameraVideoHandeDic.ContainsKey(cameraNo))
                    {
                        needToStopHandel = this.cameraVideoHandeDic[cameraNo];
                        this.videoHandleCameraDic.Remove(needToStopHandel);
                        this.cameraVideoHandeDic.Remove(cameraNo);
                    }
                    else
                    {
                        logEx.Warn("Stop Receive camera video data failed. Don't need to end the preview.Camera No:{0}.", cameraNo);
                        //如果预览句柄不存在,不需要处理,直接返回
                        return(err);
                    }
                }
                catch (Exception ex)
                {
                    err.SetErrorNo(CgwError.STOP_RECEIVE_VIDEO_FAILED);
                    logEx.Error("Stop Receive camera video data failed.Execption message:{0}", ex.Message);
                    return(err);
                }
                finally
                {
                    this.handelOperateLock.ExitWriteLock();
                }
            }

            //调用sdk的停止方法,放在handelOperateLock外面,防止长时间占用锁
            if (needToStopHandel != CgwConst.START_RECEIVE_VIDEO_DATA_FAILED)
            {
                int result = this.ivsSdkClient.StopRealPlay(needToStopHandel);
                //如果不为0,表示预览失败
                if (result != CgwConst.IVS_SDK_SUCCESS_TAG)
                {
                    err.SetErrorNo(CgwError.STOP_RECEIVE_VIDEO_FAILED);
                    logEx.Error("Stop Receive camera video data failed.Ivs sdk error code:{0}", result);
                    return(err);
                }
                logEx.Info("Stop Receive camera video data success.Camera No:{0},Handle:{1}.", cameraNo, needToStopHandel);
            }

            return(err);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 注销T28181监控平台资源
        /// </summary>
        /// <returns></returns>
        public SmcErr Unload()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: T28181IvsVideoMonitor.Unload().");
            SmcErr err = new CgwError();

            //停止定时器
            this.updateCameraTimer.Stop();

            int result = sipStack.SIP_SDK_UNREGISTER();

            //释放所有实况通道,释放NETSOURCE资源
            result += sipStack.IVS_NETSOURCE_UnInit();
            result += sipStack.SIP_SDK_UnInit();
            result += rtpAdapter.ESDK_RTP_UnInit();

            if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
            {
                logEx.Info("Unload T28181video monitor success.Monitor id:{0}.", this.monitorId);
            }
            else
            {
                err.SetErrorNo(CgwError.MONITOR_UDLOAD_FAILED);
                logEx.Error("Unload T28181video monitor failed.Monitor id:{0}.", this.monitorId);
            }
            return(err);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 停止云台控制,摄像头控制
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <param name="ptzCommandType">命令类型</param>
        /// <returns></returns>
        public SmcErr StopControlPtz(string cameraNo, PtzCommandType ptzCommandType)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: T28181VideoMonitor.StopControlPtz({0}).", cameraNo);

            SmcErr err = new CgwError();

            //将ptz命令转换成T28181的命令
            T28181PTZCmd cmd    = new T28181PTZCmd(ptzCommandType, 0);
            string       ptzCmd = cmd.ToString();

            //控制权限级别设为1
            int result = sipStack.PtzControl(cameraNo, ptzCmd, "1");

            //如果为0,表示成功
            if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
            {
                logEx.Info("Stop control ptz success.Camera No:{0}.", cameraNo);
            }
            else
            {
                //直接将IVS的错误码返回
                err.SetErrorNo(CgwError.STOP_CONTROL_PTZ_FAILED);
                logEx.Error("Stop control ptz failed.Camera No:{0}.Ivs sdk error code:{1}.", cameraNo, result);
                return(err);
            }
            return(err);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 开始云台控制,摄像头控制
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <param name="ptzCommandType">命令类型</param>
        /// <param name="param">命令参数,速度或倍数</param>
        /// <returns></returns>
        public SmcErr StartControlPtz(string cameraNo, PtzCommandType ptzCommand, int param)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: T28181VideoMonitor.StartControlPtz({0},{1},{2}).", cameraNo, ptzCommand, param);
            SmcErr err = new CgwError();

            //将ptz命令转换成T28181的命令
            T28181PTZCmd cmd    = new T28181PTZCmd(ptzCommand, param);
            string       ptzCmd = cmd.ToString();

            logEx.Trace("Call T28181VideoMonitor.StartPtzControl({0},{1},{2}).", cameraNo, Enum.GetName(typeof(PtzCommandType), (int)ptzCommand), param);
            //控制权限级别设为1
            int result = sipStack.PtzControl(cameraNo, ptzCmd, "1");

            //如果为0,表示成功
            if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
            {
                logEx.Info("Start control ptz success.Camera No:{0}.", cameraNo);
            }
            else
            {
                err.SetErrorNo(CgwError.START_CONTROL_PTZ_FAILED);
                logEx.Error("Start control ptz failed.Camera No:{0}.T28181VideoMonitor error code:{1}.", cameraNo, result);
                return(err);
            }

            return(err);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 开启PTZ控制
        /// </summary>
        /// <param name="cameraNo">摄像头NO</param>
        /// <param name="ptzCommand">操作类型</param>
        /// <param name="param">命令参数</param>
        /// <returns></returns>
        public SmcErr StartControlPtz(string cameraNo, Common.PtzCommandType ptzCommand, int param)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            SmcErr          err   = new CgwError();

            if (serviceControl.MonitorServiceRun())
            {
                err = CgwMonitorManageAdapter.Instance().StartControlPtz(cameraNo, ptzCommand, param);
            }
            else
            {
                err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING);
            }


            //日志记录
            if (err.IsSuccess())
            {
                logEx.Trace("StartControlPtz Successful");
            }
            else
            {
                logEx.Error("StartControlPtz failed,ErrNo :{0}", err.ErrNo);
            }
            return(err);
        }
Exemplo n.º 12
0
        /// <summary>
        /// 停止预览摄像头视频,并清理命名管道
        /// </summary>
        /// <param name="cameraNo"></param>
        /// <returns></returns>
        public SmcErr StopReceiveVideoByPipe(string cameraNo)
        {
            SmcErr err = new CgwError();

            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);

            err = CheckSession(currentSessionID);
            //调任何接口前 需要判断监控平台是否加载成功
            if (err.IsSuccess())
            {
                err = VideoMonitorManage.Instance().StopReceiveVideo(cameraNo);
                VideoPipe videoPipe = VideoPipeManage.Instance().DeleteVideoPipe(cameraNo);
                if (videoPipe == null)
                {
                    logEx.Error("MonitorManageService StopReceiveVideoByPipe failed,VideoPipe is null,cameraNo = {0}", cameraNo);
                    err.SetErrorNo(CgwError.STOP_RECEIVE_VIDEO_FAILED);
                }
                else
                {
                    videoPipe.Stop();
                }
            }
            if (err.IsSuccess())
            {
                logEx.Info("MonitorManageService StopReceiveVideoByPipe  Successful,Current Cgw IP is : {0}", CgwConst.ClientIp);
            }
            else
            {
                logEx.Error("MonitorManageService StopReceiveVideoByPipe failed,ErrNo :{0}", err.ErrNo);
            }
            return(err);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 获取监控摄像头列表刷新状态,返回结果为0是表示刷新完毕,为1是刷新操作中。当查询刷新状态为0时,可调用获取监控摄像头列表接口,获取刷新后监控摄像头列表
        /// </summary>
        /// <param name="refreshStatus"></param>
        /// <returns></returns>
        public SmcErr GetRefreshStatus(out SmcErr refreshStatus)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            SmcErr          err   = new CgwError();

            refreshStatus       = new SmcErr();
            refreshStatus.ErrNo = CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_END;
            if (serviceControl.MonitorServiceRun())
            {
                err = CgwMonitorManageAdapter.Instance().GetRefreshStatus(out refreshStatus);
            }
            else
            {
                err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING);
            }
            //日志记录
            if (err.IsSuccess())
            {
                logEx.Trace("GetRefreshStatus Successful");
            }
            else
            {
                logEx.Error("GetRefreshStatus failed,ErrNo :{0}", err.ErrNo);
            }
            return(err);
        }
Exemplo n.º 14
0
        /// <summary>
        /// 注销IVS监控平台资源
        /// </summary>
        /// <returns></returns>
        public SmcErr Unload()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Info("Enter: IvsVideoMonitor.Unload().");
            SmcErr err = new CgwError();

            loadResult = true;
            //停止定时器
            this.updateCameraTimer.Stop();
            logEx.Trace("Call ivsSdkClient.Logout().");
            int result = this.ivsSdkClient.Logout();

            logEx.Trace("Call ivsSdkClient.Cleanup().");
            result = this.ivsSdkClient.Cleanup();

            if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
            {
                logEx.Info("Unload video monitor success.Monitor id:{0}.", this.monitorId);
            }
            else
            {
                err.SetErrorNo(CgwError.MONITOR_UDLOAD_FAILED);
                logEx.Error("Unload video monitor failed.Monitor id:{0}.", this.monitorId);
            }
            return(err);
        }
Exemplo n.º 15
0
        /// <summary>
        /// 同步通道信息
        /// </summary>
        /// <param name="ChannelInfoList">通道列表</param>
        /// <returns></returns>
        public SmcErr SyncMonitorChannel(List <ChannelInfo> ChannelInfoList)
        {
            SmcErr err = new CgwError();

            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            err = CheckSession();
            //调任何接口前 需要判断监控平台是否加载成功
            if (err.IsSuccess())
            {
                if (ChannelInfoList != null)
                {
                    err = MonitorChannelBll.Instance().SyncMonitorChannel(ChannelInfoList);
                }
                else
                {
                    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CHANNELLIST_NULL);
                }
            }
            if (err.IsSuccess())
            {
                logEx.Trace("SyncMonitorChannel Successful");
            }
            else
            {
                logEx.Error("SyncMonitorChannel failed,ErrNo :{0}", err.ErrNo);
            }
            return(err);
        }
Exemplo n.º 16
0
        /// <summary>
        /// 分配监控通道
        /// </summary>
        public SmcErr UpdateMonitorChannel(List <ChannelInfo> channelInfoList)
        {
            SmcErr err = new CgwError();

            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            err = CheckSession();
            if (err.IsSuccess())
            {
                if (channelInfoList != null)
                {
                    err = MonitorChannelBll.Instance().AssignMonitorChannel(channelInfoList);
                }
                else
                {
                    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CHANNELLIST_NULL);
                }
            }
            if (err.IsSuccess())
            {
                logEx.Info("SMC AssignMonitorChannel  Successful,Current SMC IP is : {0}", CgwConst.SmcIp);
            }
            else
            {
                logEx.Error("SMC AssignMonitorChannel failed,ErrNo :{0}", err.ErrNo);
            }
            return(err);
        }
Exemplo n.º 17
0
        /// <summary>
        /// 连接融合网关
        /// </summary>
        /// <param name="password">连接字符串</param>
        /// <returns></returns>
        public SmcErr Connect(out string sessionID)
        {
            SmcErr err = new CgwError();

            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            sessionID = "";
            if (isLoadSuccess == false)
            {
                err.SetErrorNo(CgwError.ERR_CGW_IS_LOADING);
                return(err);
            }

            //获取SessionManage中Session个数
            if (SessionManage.Instance().GetSessionsCount() == 0)
            {
                Guid sessionGuid = Guid.NewGuid();

                sessionID        = OperationContext.Current.SessionId;
                currentSessionID = sessionID;
                //保存至CGW的session管理中
                CgwSession CgwSession = new CgwSession(sessionGuid, OperationContext.Current.SessionId);

                MessageProperties properties = OperationContext.Current.IncomingMessageProperties;                                        //获取传进的消息属性

                RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; //获取消息发送的远程终结点IP和端口
                if (endpoint != null)
                {
                    CgwConst.ClientIp = endpoint.Address; // 获取发送消息的客户端的 IP 地址。
                    logEx.Info("Client Connect MonitorManageService Successful,Current.Client IP is : {0}", CgwConst.ClientIp);
                }
                else
                {
                    logEx.Info("Client Connect MonitorManageService Successful,Current.Client IP is  null.");
                }
            }
            else
            {
                err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_SESSION_COUNT_MAX);
                logEx.Warn("Session Count is  Top Of Max number !");
            }

            return(err);
        }
Exemplo n.º 18
0
        /// <summary>
        /// 获取摄像头列表及分组信息
        /// </summary>
        /// <param name="fromMonitorSys">如果该值为true,则实时从监控平台获取,否则从融合网关缓存获取</param>
        /// <param name="cameraList">摄像头列表</param>
        /// <param name="groupList">组信息</param>
        /// <param name="nodeRelationListT">分组关系</param>
        /// <returns></returns>
        public SmcErr GetAllCameras(out List <Camera> cameraList, out List <CameraGroup> groupList, out List <NodeRelation> nodeRelationListT)
        {
            monitorManageServiceGetCameraList.Stop();
            isGetDevicesFinish = false;

            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: TiandyVideoMonitor.GetAllCameras().");
            SmcErr err = new CgwError();

            cameraList        = new List <Camera>();
            groupList         = new List <CameraGroup>();
            nodeRelationListT = new List <NodeRelation>();

            if (this.cameraOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    #region 深度克隆数据
                    foreach (KeyValuePair <string, TiandyCamera> tiandyCameraKeyValue in this.tiandyCameraDictionary)
                    {
                        TiandyCamera tiandyCamera = tiandyCameraKeyValue.Value;
                        //从缓存获取
                        Camera camera = new Camera(tiandyCamera.No, tiandyCamera.Name);
                        cameraList.Add(camera);
                    }
                    foreach (KeyValuePair <string, CameraGroup> groupDicKeyValue in this.groupDic)
                    {
                        CameraGroup cameraGroupTemp = new CameraGroup(groupDicKeyValue.Value.No, groupDicKeyValue.Value.Name);
                        groupList.Add(cameraGroupTemp);
                    }

                    foreach (NodeRelation nodeRelation in this.nodeRelationList)
                    {
                        NodeRelation nodeRelationTemp = new NodeRelation(nodeRelation.No,
                                                                         nodeRelation.Path,
                                                                         nodeRelation.Type);
                        nodeRelationListT.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();
                }
            }
            monitorManageServiceGetCameraList.Start();
            logEx.Info("Get all cameras success.");
            return(err);
        }
Exemplo n.º 19
0
        /// <summary>
        /// 连接融合网关
        /// </summary>
        /// <param name="password">连接字符串</param>
        /// <returns></returns>
        public SmcErr Connect(string password)
        {
            SmcErr err = new CgwError();

            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            if (false == string.IsNullOrEmpty(password))
            {
                //获取后台密码字符串
                string s = CommonFunction.GetAppSetting("PassWord");
                //进行SHA256加密
                string newPassword = CommonFunction.SHA256Encrypt(s);
                //保存当前会话
                if (newPassword == password)
                {
                    //获取SessionManage中Session个数
                    if (SessionManage.Instance().GetSessionsCount() == 0)
                    {
                        Guid sessionGuid = Guid.NewGuid();

                        //保存至CGW的session管理中
                        CGWSession CgwSession = new CGWSession(sessionGuid, OperationContext.Current.SessionId);
                        logEx.Trace("Connect Successful,Current.SessionId is : ", OperationContext.Current.SessionId);
                    }
                    else
                    {
                        err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_SESSION_COUNT_MAX);
                        logEx.Warn("Session Count is  Top Of Max number !");
                    }
                }
                else
                {
                    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_PASSWORD_INCORRECT);
                    logEx.Error("Connect Password is Incorrect !");
                }
            }
            else
            {
                err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_PASSWORD_NULL);
                logEx.Error("Connect Password is null !");
            }
            return(err);
        }
Exemplo n.º 20
0
        /// <summary>
        /// 初始化天地伟业监控平台
        /// </summary>
        /// <param name="monitorConfigElement">监控平台配置节点</param>
        /// <returns></returns>
        public SmcErr Load(XmlElement monitorConfigElement)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: TiandyVideoMonitor.Load().");
            SmcErr err = new CgwError();

            string userLevel = "";

            //解析xml节点,获取所需参数
            try
            {
                #region Tiandy视频监控平台(Easy7)连接信息
                this.monitorId = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.ID_TAG);

                userLevel = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.PTZCONTROLLEVEL_TAG);

                string httpUser = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.PLATFORM_USER_TAG);

                string httpPassword = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.PLATFORM_PASSWORD_TAG);

                string httpUrl = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.PLATFORM_URL_TAG);

                string mediaServerId = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.MEDIASERVER_SERVERID_TAG);
                #endregion
                this.httpClient = new TiandyHttpClient(httpUrl, httpUser, httpPassword);

                //使用线程轮询加载监控平台
                Thread loaderThread = new Thread(LoaderThread);
                loaderThread.Start(mediaServerId);
            }
            catch (Exception e)
            {
                err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID);
                logEx.Error("Load Tiandy monitor failed.Execption message:{0}.", e.Message);
                return(err);
            }

            this.sdkClient = new TiandySdkClient();
            //如果控制级别配置错误,只记录错误日志,不向外报错
            try
            {
                this.sdkClient.PtzControlLevel = int.Parse(userLevel);
            }
            catch (Exception e)
            {
                logEx.Error("Ptz Control Level is invalid.Execption message:{0}.", e.Message);
                this.sdkClient.PtzControlLevel = CgwConst.PTZ_CONTROL_LEVEL;
            }
            logEx.Info("Load video monitor success.Monitor id:{0}.", this.monitorId);
            return(err);
        }
Exemplo n.º 21
0
        /// <summary>
        /// 开始云台控制,摄像头控制
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <param name="ptzCommand">命令类型</param>
        /// <param name="param">命令参数(速度、倍数)</param>
        /// <returns></returns>
        public SmcErr StartControlPtz(string cameraNo, PtzCommandType ptzCommand, int param)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: IvsVideoMonitor.StartControlPtz({0},{1},{2}).", cameraNo, ptzCommand, param);
            SmcErr err = new CgwError();

            //将ptz命令转换成IVS的命令
            string name = Enum.GetName(typeof(PtzCommandType), ptzCommand);

            if (Enum.IsDefined(typeof(IvsPtzCommandType), name))
            {
                IvsPtzCommandType ivsPtzCommandType = (IvsPtzCommandType)Enum.Parse(typeof(IvsPtzCommandType), name);

                logEx.Trace("Call ivsSdkClient.StartPtzControl({0},{1},{2}).", cameraNo, (int)ivsPtzCommandType, param);
                int result = this.ivsSdkClient.StartPtzControl(cameraNo, (int)ivsPtzCommandType, param.ToString());

                //如果为0,表示成功
                if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
                {
                    logEx.Info("Start control ptz success.Camera No:{0}.", cameraNo);
                }
                else
                {
                    err.SetErrorNo(CgwError.START_CONTROL_PTZ_FAILED);
                    logEx.Error("Start control ptz failed.Camera No:{0}.Ivs sdk error code:{1}.", cameraNo, result);
                    return(err);
                }
            }
            else
            {
                err.SetErrorNo(CgwError.START_CONTROL_PTZ_FAILED);
                logEx.Error("The ivs monitor is not support the command.ptzCommand:{0}.", ptzCommand);
                return(err);
            }

            return(err);
        }
Exemplo n.º 22
0
        /// <summary>
        /// 获取软终端被叫sip端口号
        /// </summary>
        /// <param name="sipPort"></param>
        /// <returns></returns>
        public SmcErr GetSipPort(out uint sipPort)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: CgwService.GetSipPort");

            SmcErr err = new CgwError();

            sipPort = (uint)ConfigSettings.CgwChanelCallPort;
            logEx.Debug("sipPort = {0}", sipPort);

            if (0 == sipPort)
            {
                err.SetErrorNo(CgwError.ERR_CGW_CONFIGURE_FORMAT);
            }
            return(err);
        }
Exemplo n.º 23
0
        /// <summary>
        /// 注销天地伟业监控平台资源
        /// </summary>
        /// <returns></returns>
        public SmcErr Unload()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: TiandyVideoMonitor.Unload().");
            SmcErr err = new CgwError();

            //停止定时器
            this.updateCameraTimer.Stop();
            if (this.sdkClient.Unload())
            {
                logEx.Info("Unload video monitor success.Monitor id:{0}.", this.monitorId);
            }
            else
            {
                err.SetErrorNo(CgwError.UNLOAD_MONITOR_FAILED);
                logEx.Error("Unload video monitor failed.Monitor id:{0}.", this.monitorId);
            }
            return(err);
        }
Exemplo n.º 24
0
        /// <summary>
        /// 预览摄像头视频,使用命名管道方式接收数据
        /// </summary>
        /// <param name="cameraNo"></param>
        /// <param name="pipeName"></param>
        /// <returns></returns>
        public SmcErr StartReceiveVideoByPipe(string cameraNo, out string pipeName)
        {
            SmcErr err = new CgwError();

            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            pipeName = string.Empty;
            err      = CheckSession(currentSessionID);
            //调任何接口前 需要判断监控平台是否加载成功
            if (err.IsSuccess())
            {
                err = VideoMonitorManage.Instance().StartReceiveVideo(cameraNo);

                //开始监控平台成功、开始通过管道发送数据
                if (err.IsSuccess())
                {
                    VideoPipeManage.Instance().DeleteVideoPipe(cameraNo);
                    VideoPipe videoPipe = VideoPipeManage.Instance().AddVideoPipe(cameraNo);
                    if (videoPipe != null)
                    {
                        pipeName = videoPipe.PipeName;
                        videoPipe.Run();

                        logEx.Info("MonitorManageService StartReceiveVideoByPipe  Successful,Current Cgw IP is : {0}", CgwConst.ClientIp);
                    }
                    else
                    {
                        logEx.Error("MonitorManageService AddVideoPipe failed.cameraNo = {0}", cameraNo);
                        err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                        StopReceiveVideoByPipe(cameraNo);
                    }
                }
                else
                {
                    logEx.Error("MonitorManageService StartReceiveVideoByPipe failed,ErrNo :{0}", err.ErrNo);
                }
            }
            else
            {
                logEx.Error("MonitorManageService StartReceiveVideoByPipe failed,ErrNo :{0}", err.ErrNo);
            }
            return(err);
        }
Exemplo n.º 25
0
        /// <summary>
        /// 停止云台控制,摄像头控制
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <param name="ptzCommand">命令类型</param>
        /// <returns></returns>
        public SmcErr StopControlPtz(string cameraNo, PtzCommandType ptzCommand)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: IvsVideoMonitor.StopControlPtz({0}).", cameraNo);
            SmcErr err = new CgwError();

            logEx.Trace("Call ivsSdkClient.StopPtzControl({0}).", cameraNo);
            int result = this.ivsSdkClient.StopPtzControl(cameraNo);

            //如果为0,表示成功
            if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
            {
                logEx.Info("Stop control ptz success.Camera No:{0}.", cameraNo);
            }
            else
            {
                //直接将IVS的错误码返回
                err.SetErrorNo(CgwError.STOP_CONTROL_PTZ_FAILED);
                logEx.Error("Stop control ptz failed.Camera No:{0}.Ivs sdk error code:{1}.", cameraNo, result);
                return(err);
            }
            return(err);
        }
Exemplo n.º 26
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.º 27
0
        public SmcErr SetSpeaker(string channelLabel, string cameraNo, bool isOn)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            SmcErr          err   = new CgwError();

            if (serviceControl.MonitorServiceRun())
            {
                err = CgwMonitorManageAdapter.Instance().SetSpeaker(cameraNo, isOn);
            }
            else
            {
                err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING);
            }
            //日志记录
            if (err.IsSuccess())
            {
                logEx.Trace("SetMic Successful");
            }
            else
            {
                logEx.Error("SetMic failed,ErrNo :{0}", err.ErrNo);
            }
            return(err);
        }
Exemplo n.º 28
0
        /// <summary>
        /// 刷新监控摄像头列表
        /// </summary>
        /// <returns></returns>
        public SmcErr RefreshMonitorCamera()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            SmcErr          err   = new CgwError();

            if (serviceControl.MonitorServiceRun())
            {
                err = CgwMonitorManageAdapter.Instance().RefreshMonitorCamera();
            }
            else
            {
                err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING);
            }
            //日志记录
            if (err.IsSuccess())
            {
                logEx.Trace("RefreshMonitorCamera Successful");
            }
            else
            {
                logEx.Error("RefreshMonitorCamera failed,ErrNo :{0}", err.ErrNo);
            }
            return(err);
        }
Exemplo n.º 29
0
        /// <summary>
        /// 软终端初始化
        /// </summary>
        /// <param name="addr"></param>
        /// <returns></returns>
        public SmcErr Init(InitSotParam param)
        {
            SmcErr err = new CgwError();

            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);

            try
            {
                SoftTerminalCallback handler = new SoftTerminalCallback();
                handler.NlogHandler      = new NLogCallback(this.WriteLog);
                handler.IFrameHandler    = this.makeIFrameCallback;
                handler.errReportHandler = this.errReportCallback;
                bool isSuccess = this.softTerminalAdapter.RegistSotCallback(handler);
                if (!isSuccess)
                {
                    logEx.Trace("Init Regist callback failed.");
                    err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_SOT_REGIST_CALLBACK_FAIL);
                    return(err);
                }

                err = this.softTerminalAdapter.Init(param);
                if (!err.IsSuccess())
                {
                    logEx.Trace("Init failed.");
                    return(err);
                }
            }
            catch (System.Exception ex)
            {
                logEx.Error(ex, "Init Exception.");
            }


            logEx.Trace("Init successfully.");
            return(err);
        }
Exemplo n.º 30
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.º 31
0
        /// <summary>
        /// 停止云台控制,摄像头控制
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <param name="ptzCommand">命令类型</param>
        /// <returns></returns>
        public SmcError.SmcErr StopControlPtz(string cameraNo, PtzCommandType ptzCommandType)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: eLTEVideoMonitor.StopControlPtz({0}).", cameraNo);
            SmcErr err = new CgwError();
            ELTE_RESULT result = (ELTE_RESULT)lteSdkClient.PTZControl(Convert.ToInt32(cameraNo), (uint)eLTEPTZControlCode.STOP_SEQ, 1);

            if (result != ELTE_RESULT.RET_SUCCESS)
            {
                err.SetErrorNo(CgwError.START_CONTROL_PTZ_FAILED);
                logEx.Error("StopControlPtz failed.eLTE sdk error code:{0}", result);
                return err;
            }
            else
            {
                logEx.Debug("StopControlPtz Success");
            }

            return err;
        }
Exemplo n.º 32
0
        /// <summary>
        /// 预览摄像头视频,使用命名管道方式接收数据
        /// </summary>
        /// <param name="cameraNo"></param>
        /// <param name="pipeName"></param>
        /// <returns></returns>
        public SmcErr StartReceiveVideoByPipe(string cameraNo, out string pipeName)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            pipeName = string.Empty;
            err = CheckSession(currentSessionID);
            //调任何接口前 需要判断监控平台是否加载成功
            if (err.IsSuccess())
            {
                err = VideoMonitorManage.Instance().StartReceiveVideo(cameraNo);

                //开始监控平台成功、开始通过管道发送数据
                if (err.IsSuccess())
                {
                    VideoPipeManage.Instance().DeleteVideoPipe(cameraNo);
                    VideoPipe videoPipe = VideoPipeManage.Instance().AddVideoPipe(cameraNo);
                    if (videoPipe != null)
                    {
                        pipeName = videoPipe.PipeName;
                        videoPipe.Run();

                        logEx.Info("MonitorManageService StartReceiveVideoByPipe  Successful,Current Cgw IP is : {0}", CgwConst.ClientIp);
                    }
                    else
                    {
                        logEx.Error("MonitorManageService AddVideoPipe failed.cameraNo = {0}", cameraNo);
                        err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                        StopReceiveVideoByPipe(cameraNo);
                    }
                }
                else
                {
                    logEx.Error("MonitorManageService StartReceiveVideoByPipe failed,ErrNo :{0}", err.ErrNo);
                }
            }
            else
            {
                logEx.Error("MonitorManageService StartReceiveVideoByPipe failed,ErrNo :{0}", err.ErrNo);
            }
            return err;
        }
Exemplo n.º 33
0
        /// <summary>
        /// 注销IVS监控平台资源
        /// </summary>
        /// <returns></returns>
        public SmcErr Unload()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Info("Enter: IvsVideoMonitor.Unload().");
            SmcErr err = new CgwError();

            loadResult = true;
            //停止定时器
            this.updateCameraTimer.Stop();
            logEx.Trace("Call ivsSdkClient.Logout().");
            int result = this.ivsSdkClient.Logout();
            logEx.Trace("Call ivsSdkClient.Cleanup().");
            result = this.ivsSdkClient.Cleanup();

            if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
            {
                logEx.Info("Unload video monitor success.Monitor id:{0}.", this.monitorId);
            }
            else
            {
                err.SetErrorNo(CgwError.MONITOR_UDLOAD_FAILED);
                logEx.Error("Unload video monitor failed.Monitor id:{0}.", this.monitorId);
            }
            return err;
        }
Exemplo n.º 34
0
 /// <summary>
 /// 停止云台控制,摄像头控制
 /// </summary>
 /// <param name="cameraNo">摄像头编号</param>
 /// <param name="ptzCommand">命令类型</param>
 /// <returns></returns>
 public SmcErr StopControlPtz(string cameraNo, PtzCommandType ptzCommand)
 {
     NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
     logEx.Trace("Enter: IvsVideoMonitor.StopControlPtz({0}).", cameraNo);
     SmcErr err = new CgwError();
     logEx.Trace("Call ivsSdkClient.StopPtzControl({0}).", cameraNo);
     int result = this.ivsSdkClient.StopPtzControl(cameraNo);
     //如果为0,表示成功
     if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
     {
         logEx.Info("Stop control ptz success.Camera No:{0}.", cameraNo);
     }
     else
     {
         //直接将IVS的错误码返回
         err.SetErrorNo(CgwError.STOP_CONTROL_PTZ_FAILED);
         logEx.Error("Stop control ptz failed.Camera No:{0}.Ivs sdk error code:{1}.", cameraNo, result);
         return err;
     }
     return err;
 }
Exemplo n.º 35
0
        /// <summary>
        /// 开始云台控制,摄像头控制
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <param name="ptzCommand">命令类型</param>
        /// <param name="param">命令参数(速度、倍数)</param>
        /// <returns></returns>
        public SmcErr StartControlPtz(string cameraNo, PtzCommandType ptzCommand, int param)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: IvsVideoMonitor.StartControlPtz({0},{1},{2}).", cameraNo, ptzCommand, param);
            SmcErr err = new CgwError();

            //将ptz命令转换成IVS的命令
            string name = Enum.GetName(typeof(PtzCommandType), ptzCommand);
            if (Enum.IsDefined(typeof(IvsPtzCommandType), name))
            {
                IvsPtzCommandType ivsPtzCommandType = (IvsPtzCommandType)Enum.Parse(typeof(IvsPtzCommandType), name);

                logEx.Trace("Call ivsSdkClient.StartPtzControl({0},{1},{2}).", cameraNo, (int)ivsPtzCommandType, param);
                int result = this.ivsSdkClient.StartPtzControl(cameraNo, (int)ivsPtzCommandType, param.ToString());

                //如果为0,表示成功
                if (result == CgwConst.IVS_SDK_SUCCESS_TAG)
                {
                    logEx.Info("Start control ptz success.Camera No:{0}.", cameraNo);
                }
                else
                {
                    err.SetErrorNo(CgwError.START_CONTROL_PTZ_FAILED);
                    logEx.Error("Start control ptz failed.Camera No:{0}.Ivs sdk error code:{1}.", cameraNo, result);
                    return err;
                }

            }
            else
            {
                err.SetErrorNo(CgwError.START_CONTROL_PTZ_FAILED);
                logEx.Error("The ivs monitor is not support the command.ptzCommand:{0}.", ptzCommand);
                return err;
            }

            return err;
        }
Exemplo n.º 36
0
        /// <summary>
        /// 断开监控管理连接
        /// </summary>
        /// <returns></returns>
        public SmcErr Disconnect()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            SmcErr err = new CgwError();
            if (OperationContext.Current != null)
            {
                //string strSessionId = OperationContext.Current.SessionId;
                string strSessionId = currentSessionID;
                if (!string.IsNullOrEmpty(strSessionId))
                {
                    err = SessionManage.Instance().RemoveSessionBySessionId(strSessionId);
                    logEx.Info("Client DisConnect MonitorManageService Successful,Current.Cgw IP is : {0}", CgwConst.ClientIp);
                }
                else
                {
                    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CURRENTSESSION_NULL);
                    logEx.Warn("Current SessionId is null ! ");
                }
            }
            else
            {
                err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CURRENTSESSION_NULL);
                logEx.Warn("Current SessionId is null ! ");
            }

            return err;

        }
Exemplo n.º 37
0
        /// <summary>
        /// 停止云台控制,摄像头控制
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <param name="ptzCommand">命令类型</param>
        /// <returns></returns>
        public SmcErr StopControlPtz(string cameraNo, PtzCommandType ptzCommand)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: TiandyVideoMonitor.StopControlPtz({0}).", cameraNo);
            SmcErr err = new CgwError();

            int handel = CgwConst.START_RECEIVE_VIDEO_DATA_FAILED;
            if (this.handelOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    if (this.cameraVideoHandeDic.ContainsKey(cameraNo))
                    {
                        handel = this.cameraVideoHandeDic[cameraNo];
                    }
                    else
                    {
                        logEx.Warn("The camera was not Preview.Don't need to end the control.Camera No:{0}.", cameraNo);
                    }
                }
                finally
                {
                    this.handelOperateLock.ExitReadLock();
                }

            }

            if (handel != CgwConst.START_RECEIVE_VIDEO_DATA_FAILED)
            {
                Client_PTZ_Command client_ptz_command = new Client_PTZ_Command();
                client_ptz_command.start = false;

                //将ptz命令转换成天地伟业的命令
                string name = Enum.GetName(typeof(PtzCommandType), ptzCommand);
                if (Enum.IsDefined(typeof(TiandyPtzCommandType), name))
                {
                    TiandyPtzCommandType tiandyPtzCommandType = (TiandyPtzCommandType)Enum.Parse(typeof(TiandyPtzCommandType), name);
                    client_ptz_command.cmd = (int)tiandyPtzCommandType;
                }
                else
                {
                    err.SetErrorNo(CgwError.STOP_CONTROL_PTZ_FAILED);
                    logEx.Error("The tiandy monitor is not support the command.ptzCommand:{0}.", ptzCommand);
                    return err;
                }

                bool result = this.sdkClient.ControlPtz(handel, client_ptz_command);
                if (result)
                {
                    logEx.Info("Stop control camera ptz success.Camera No:{0}.", cameraNo);
                }
                else
                {
                    err.SetErrorNo(CgwError.STOP_CONTROL_PTZ_FAILED);
                    logEx.Error("Stop control camera ptz failed.Camera No:{0}.", cameraNo);
                }
            }
            else
            {
                err.SetErrorNo(CgwError.STOP_CONTROL_PTZ_FAILED);
                logEx.Error("Handel is not found. Stop control camera ptz failed. Camera No:{0}.", cameraNo);
                return err;
            }

            return err;
        }
Exemplo n.º 38
0
        /// <summary>
        /// 启动摄像头预览
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <returns></returns>
        public SmcError.SmcErr StartReceiveVideo(string cameraNo)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: eLTEVideoMonitor.StartReceiveVideo({0}).", cameraNo);
            SmcErr err = new CgwError();

            //预览成功,需要停止原来的预览,并将预览句柄添加到缓存
            //需要停止的预览句柄
            UInt32 needToStopChannel = CgwConst.T28181_ERROR_HANDLE;
            if (this.handelOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    //如果预览句柄已经存在,删除掉原来的句柄,用新的句柄替换
                    if (this.cameraVideoChannelDic.ContainsKey(cameraNo.ToString()))
                    {
                        needToStopChannel = this.cameraVideoChannelDic[cameraNo.ToString()];
                        this.videoChannelDataSenderDic.Remove(needToStopChannel);
                        this.cameraVideoChannelDic.Remove(cameraNo.ToString());

                        //用户参数,4字节整数
                        IntPtr pUser = Marshal.AllocHGlobal(4);
                        NetSourcedInterface.IVS_NETSOURCE_SetDataCallBack(needToStopChannel, null, pUser);

                        NetSourcedInterface.IVS_NETSOURCE_CloseNetStream(needToStopChannel);
                        //释放NETSOURCE通道资源
                        NetSourcedInterface.IVS_NETSOURCE_FreeChannel(needToStopChannel);
                        //关闭rtp回调
                        rtpAdapter.ESDK_RTP_CloseChannel(needToStopChannel);

                        //释放用户数据内存 
                        foreach (KeyValuePair<UInt32, IntPtr> kvp in channelInPtrDic)
                        {
                            if (kvp.Key == needToStopChannel)
                            {
                                Marshal.FreeHGlobal(kvp.Value);
                                channelInPtrDic.Remove(kvp.Key);
                                break;
                            }
                        }
                    }
                }
                finally
                {
                    this.handelOperateLock.ExitWriteLock();
                }
            }

            //重新预览后,更新了预览句柄,需要将原来的预览停止
            if (needToStopChannel != CgwConst.T28181_ERROR_HANDLE)
            {
                ELTE_RESULT result = (ELTE_RESULT)this.lteSdkClient.StopP2PVideo(Convert.ToInt32(cameraNo));
                //如果不为0,表示停止原来的预览失败,只记录日志,不返回错误,不设置错误码
                if (result != ELTE_RESULT.RET_SUCCESS)
                {
                    logEx.Error("Get a new preview success. But stop old preview failed.CameraNo:{0},Ivs sdk error code:{0}", cameraNo, result);
                }
            }
            //设置实况参数
            eLTEVideoParameter para = new eLTEVideoParameter();
            para.cameratype = cameraType;
            para.fmtvalue = fmtValue;
            para.mutetype = muteType;
            para.user_confirm_type = userConfirmType;

            if (this.videoAutOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    if (!videoAutoEvents.ContainsKey(cameraNo))
                    {
                        AutoResetEvent startAutoEvent = new AutoResetEvent(false);
                        startAutoEvent.Reset();

                        eLTEAutoReset elTEAutoEvent = new eLTEAutoReset();
                        elTEAutoEvent.eLTEVideoEvent = startAutoEvent;
                        elTEAutoEvent.VideoSuccess = false;

                        logEx.Trace("StartReceiveVideo add CameraNo");
                        videoAutoEvents.Add(cameraNo, elTEAutoEvent);
                    }
                    //else
                    //{
                    //    cameraNoExists = true;
                    //    logEx.Info("StartReceiveVideo Contains CameraNo");
                    //}
                }
                finally
                {
                    this.videoAutOperateLock.ExitWriteLock();
                }
            }         

            ELTE_RESULT iRet = (ELTE_RESULT)lteSdkClient.StartP2PVideoMonitor(Convert.ToInt32(cameraNo), para);

            if (iRet != ELTE_RESULT.RET_SUCCESS)
            {
                err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                //logEx.Error("StartReceiveVideo.StartP2PVideoMonitor failed.CameraNo:{0},ELTE_RESULT:{1}", cameraNo, Enum.GetName(typeof(ELTE_RESULT), iRet));
                logEx.Error("StartReceiveVideo.StartP2PVideoMonitor failed.CameraNo:{0},ELTE_RESULT:{1}", cameraNo, iRet.ToString());
            }
            else
            {
                if (!videoAutoEvents[cameraNo].eLTEVideoEvent.WaitOne(start_Wait_Time))
                {
                    //等待播放超时,设置错误码
                    err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                }
                else
                {
                    if (!videoAutoEvents[cameraNo].VideoSuccess)//未超时,但播放失败
                    {
                        err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                    }
                }
            }

            if (this.videoAutOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    if (videoAutoEvents.ContainsKey(cameraNo))
                    {
                        videoAutoEvents.Remove(cameraNo);
                        logEx.Trace("StartReceiveVideo Remove CameraNo:{0} Success", cameraNo);
                    }
                }
                finally
                {
                    this.videoAutOperateLock.ExitWriteLock();
                }
            }

            return err;
        }
Exemplo n.º 39
0
        /// <summary>
        /// 停止预览
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <returns>成功返回0,失败返回错误码</returns>
        public SmcError.SmcErr StopReceiveVideo(string cameraNo)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: eLTEVideoMonitor.StopReceiveVideo({0}).", cameraNo);
            SmcErr err = new CgwError();
            //需要停止的预览句柄
            uint needToStopChannel = CgwConst.T28181_ERROR_HANDLE;
            if (this.handelOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    if (this.cameraVideoChannelDic.ContainsKey(cameraNo))
                    {
                        needToStopChannel = this.cameraVideoChannelDic[cameraNo];
                        this.videoChannelDataSenderDic.Remove(needToStopChannel);
                        this.cameraVideoChannelDic.Remove(cameraNo);

                        //释放用户数据内存 
                        foreach (KeyValuePair<UInt32, IntPtr> kvp in channelInPtrDic)
                        {
                            if (kvp.Key == needToStopChannel)
                            {
                                Marshal.FreeHGlobal(kvp.Value);
                                channelInPtrDic.Remove(kvp.Key);
                                break;
                            }
                        }

                        //用户参数,4字节整数
                        IntPtr pUser = Marshal.AllocHGlobal(4);
                        NetSourcedInterface.IVS_NETSOURCE_SetDataCallBack(needToStopChannel, null, pUser);
                        //释放NETSOURCE通道资源
                        IVS_NETSOURCE_RESULT iNet = NetSourcedInterface.IVS_NETSOURCE_CloseNetStream(needToStopChannel);
                        if (iNet != IVS_NETSOURCE_RESULT.SUCCESS)
                        {
                            logEx.Error("IVS_NETSOURCE_CloseNetStream failed channel={0}", needToStopChannel);
                            err.SetErrorNo(CgwError.STOP_RECEIVE_VIDEO_FAILED);
                        }

                        iNet = NetSourcedInterface.IVS_NETSOURCE_FreeChannel(needToStopChannel);
                        if (iNet != IVS_NETSOURCE_RESULT.SUCCESS)
                        {
                            logEx.Error("IVS_NETSOURCE_FreeChannel failed channel={0}", needToStopChannel);
                            err.SetErrorNo(CgwError.STOP_RECEIVE_VIDEO_FAILED);
                        }

                        //关闭rtp回调
                        rtpAdapter.ESDK_RTP_CloseChannel(needToStopChannel);
                    }
                    else
                    {
                        logEx.Warn("Stop Receive camera video data failed. Don't need to end the preview.Camera No:{0}.", cameraNo);
                        //如果预览句柄不存在,不需要处理,直接返回
                        return err;
                    }
                }
                catch (Exception ex)
                {
                    err.SetErrorNo(CgwError.STOP_RECEIVE_VIDEO_FAILED);
                    logEx.Error("Stop Receive camera video data failed.Execption message:{0}", ex.Message);
                    return err;
                }
                finally
                {
                    this.handelOperateLock.ExitWriteLock();
                }
            }

            //调用sdk的停止方法,放在handelOperateLock外面,防止长时间占用锁
            if (needToStopChannel != CgwConst.T28181_ERROR_HANDLE)
            {
                ELTE_RESULT result = (ELTE_RESULT)this.lteSdkClient.StopP2PVideo(Convert.ToInt32(cameraNo));
                //如果不为0,表示预览失败
                if (result != ELTE_RESULT.RET_SUCCESS)
                {
                    err.SetErrorNo(CgwError.STOP_RECEIVE_VIDEO_FAILED);
                    logEx.Error("Stop Receive camera video data failed.eLTE sdk error code:{0}", result);
                    return err;
                }
                logEx.Info("Stop Receive camera video data success.Camera No:{0},Handle:{1}.", cameraNo, needToStopChannel);
            }
            return err;
        }
Exemplo n.º 40
0
        /// <summary>
        /// 检查Session
        /// </summary>
        /// <returns></returns>
        private SmcErr CheckSession(string sessionID)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            SmcErr err = new CgwError();
            CgwSession CgwSession = null;
            if (OperationContext.Current != null)
            {
                //string strSessionId = OperationContext.Current.SessionId;
                string strSessionId = sessionID;
                err = SessionManage.Instance().GetSessionsBySessionId(strSessionId, out CgwSession);

                if (err.IsSuccess() == false || CgwSession == null)
                {
                    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_SESSION_NULL);
                }
                else
                {
                    if (CgwSession != null)
                    {
                        //更新Session最后访问时间
                        CgwSession.LastVisitedTime = DateTime.Now;
                        //logEx.Trace("Current SessionId is:{0}, LastVisitedTime is :{1}", strSessionId, CgwSession.LastVisitedTime.ToLongTimeString());
                        logEx.Trace("LastVisitedTime is :{0}", CgwSession.LastVisitedTime.ToLongTimeString());

                        if (isLoadSuccess == false)
                        {
                            err.SetErrorNo(CgwError.ERR_CGW_IS_LOADING);
                        }
                    }
                }
            }
            else
            {
                err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CURRENTSESSION_NULL);
            }
            return err;
        }
Exemplo n.º 41
0
        /// <summary>
        /// 停止预览摄像头视频,并清理命名管道
        /// </summary>
        /// <param name="cameraNo"></param>
        /// <returns></returns>
        public SmcErr StopReceiveVideoByPipe(string cameraNo)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);

            err = CheckSession(currentSessionID);
            //调任何接口前 需要判断监控平台是否加载成功
            if (err.IsSuccess())
            {
                err = VideoMonitorManage.Instance().StopReceiveVideo(cameraNo);
                VideoPipe videoPipe = VideoPipeManage.Instance().DeleteVideoPipe(cameraNo);
                if (videoPipe == null)
                {
                    logEx.Error("MonitorManageService StopReceiveVideoByPipe failed,VideoPipe is null,cameraNo = {0}", cameraNo);
                    err.SetErrorNo(CgwError.STOP_RECEIVE_VIDEO_FAILED);
                }
                else
                {
                    videoPipe.Stop();
                }
            }
            if (err.IsSuccess())
            {
                logEx.Info("MonitorManageService StopReceiveVideoByPipe  Successful,Current Cgw IP is : {0}", CgwConst.ClientIp);
            }
            else
            {
                logEx.Error("MonitorManageService StopReceiveVideoByPipe failed,ErrNo :{0}", err.ErrNo);
            }
            return err;
        }
Exemplo n.º 42
0
        /// <summary>
        /// 注销T28181监控平台资源
        /// </summary>
        /// <returns></returns>
        public SmcErr Unload()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Info("Enter: T28181IvsVideoMonitor.Unload().");
            SmcErr err = new CgwError();
            //停止定时器
            this.updateCameraTimer.Stop();

            //copy 一份,防止长时间占用锁
            Dictionary<string, uint> monitorChannelRelationDicTemp = null;
            try
            {
                monitorChannelRelationDicTemp = new Dictionary<string, uint>(cameraVideoChannelDic);
            }
            catch (Exception e)
            {
                logEx.Error("Unload.Execption message:{0}", e.Message);
            }

            if (monitorChannelRelationDicTemp == null)
            {
                //记录日志,获取*监控平台的摄像头列表失败
                logEx.Error("Unload failed.No any cameraVideoChannelDic.");
                return err;
            }

            //遍历通道字典,停止流
            foreach (KeyValuePair<string, uint> videoChannelRelation in monitorChannelRelationDicTemp)
            {
                string cameraNo = videoChannelRelation.Key.ToString();
                string channel = videoChannelRelation.Value.ToString();
                if (!string.IsNullOrEmpty(cameraNo))
                {
                    SmcErr errs = this.StopReceiveVideo(cameraNo);
                    if (!errs.IsSuccess())
                    {
                        logEx.Error("@@Unload.StopReceiveVideo failed, cameraNo:{0},errNo={1}.", cameraNo, errs.ErrNo);
                    }
                    else
                    {
                        logEx.Trace("@@Unload.StopReceiveVideo success, cameraNo:{0} ", cameraNo);
                    }
                }
                else
                {
                    logEx.Error("@@Unload.StopReceiveVideo failed, cameraNo is null.");
                }
            }
            logEx.Trace("Leave: T28181IvsVideoMonitor.Unload().");
            EM_SIP_RESULT iRet = sipStack.SIP_SDK_UNREGISTER();
            //释放所有实况通道,释放NETSOURCE资源
            IVS_NETSOURCE_RESULT iNet = sipStack.IVS_NETSOURCE_UnInit();
            iRet += (int)sipStack.SIP_SDK_UnInit();
            iNet += rtpAdapter.ESDK_RTP_UnInit();

            logEx.Info("Unload T28181video.Monitor id:{0},iRet:{1} ,iNet:{2}", this.monitorId, iRet, iNet);
            //if (iRet == EM_SIP_RESULT.RET_SUCCESS || iNet != IVS_NETSOURCE_RESULT.SUCCESS)
            if (iRet == EM_SIP_RESULT.RET_SUCCESS && iNet == IVS_NETSOURCE_RESULT.SUCCESS)
            {
                logEx.Info("Unload T28181video monitor success.Monitor id:{0}.", this.monitorId);
            }
            else
            {
                err.SetErrorNo(CgwError.MONITOR_UDLOAD_FAILED);
                logEx.Error("Unload T28181video monitor failed.Monitor id:{0}.", this.monitorId);
            }
            return err;
        }
Exemplo n.º 43
0
        /// <summary>
        /// 获取监控平台配置
        /// </summary>
        /// <param name="monitorElement"></param>
        /// <returns></returns>
        private SmcErr GetMonitorConfig(XmlElement monitorElement, out string monitorId, out string className)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: VideoMonitorManage.GetMonitorConfig().");
            SmcErr err = new CgwError();

            monitorId = CommonFunction.GetSingleNodeValue(monitorElement, CgwConst.ID_TAG);

            className = CommonFunction.GetSingleNodeValue(monitorElement, CgwConst.CLASS_TAG);

            if (string.IsNullOrEmpty(monitorId))
            {
                //监控平台id不能为空
                err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID_ID_NULL);

                logEx.Error("Monitor id can not be null.");
                return err;
            }

            if (string.IsNullOrEmpty(className))
            {
                //监控平台 {0}的class不能为空
                err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID_CLASS_NULL);

                logEx.Error("The class of Monitor is null. Monitor id:{0}.", monitorId);
                return err;
            }

            return err;
        }
Exemplo n.º 44
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.º 45
0
        /// <summary>
        /// 初始化IVS监控平台
        /// </summary>
        /// <param name="monitorConfigElement">监控平台配置节点</param>
        /// <returns></returns>
        public SmcErr Load(XmlElement monitorConfigElement)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Info("Enter: IvsVideoMonitor.Load().");
            SmcErr err = new CgwError();

            try
            {
                //解析xml节点,获取所需参数
                this.monitorId = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.ID_TAG);
                ip = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.IP_TAG);
                port = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.PORT_TAG);
                user = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.USER_TAG);

                //password = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.PASSWORD_TAG);
                pwdByte = CommonFunction.EncryptStr2Byte(CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.PASSWORD_TAG),CgwConst.PASSWORD_TAG);

                //从配置文件读取的参数要简单判断一下合法性

                //初始化之前设置日志路径
                logEx.Trace("Call SetLogPath:{0}", ivsLogPath);
                this.ivsSdkClient.SetLogPath(ivsLogPath);

                logEx.Trace("Call ivsSdkClient.Init().");
                //初始化
                int result = this.ivsSdkClient.Init();
                if (result != CgwConst.IVS_SDK_SUCCESS_TAG)
                {
                    //直接将IVS的错误码返回
                    err.SetErrorNo(CgwError.MONITOR_LOAD_FAILED);
                    logEx.Error("Init ivs monitor failed.Monitor id:{0}.ivs sdk error code:{1}.", this.monitorId, result);
                    return err;
                }
                else
                {
                    logEx.Info("Init ivs sdk success.Monitor id:{0}", this.monitorId);
                }

                //设置监控平台id
                this.ivsSdkClient.SetId(this.monitorId);

                this.sdkCallbackFunc = IvsRealPlayCallBackRaw;
                this.ivsSdkClient.SetRealPlayCBRawCallBackFunc(this.sdkCallbackFunc);

                //sdk事件回调
                this.ivsEventCallBackFunc = IvsEventCallBackFunc;
                this.ivsSdkClient.SetEventCallBackFunc(this.ivsEventCallBackFunc);

                IvsLoginInfo loginInfo = new IvsLoginInfo();
                loginInfo.Ip = ip;
                loginInfo.Port = int.Parse(port);
                loginInfo.User = user;
                //loginInfo.Pwd = password;
                loginInfo.Pwd = CommonFunction.DecryptByte2Str(pwdByte,CgwConst.PASSWORD_TAG);

                loadResult = false;
                //使用线程轮询加载监控平台
                Thread loaderThread = new Thread(LoginThread);
                loaderThread.IsBackground = true;
                loaderThread.Start(loginInfo);
            }
            catch (Exception e)
            {
                err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID);
                logEx.Error("Load ivs monitor failed.Execption message:{0}.", e.Message);
                return err;
            }

            logEx.Info("Load video monitor success.Monitor id:{0}.", this.monitorId);
            return err;
        }
Exemplo n.º 46
0
        /// <summary>
        /// 获取摄像头列表及分组信息
        /// </summary>
        /// <param name="isRealTime">是否实时获取,融合网关有个缓存,间隔一段时间获取,默认是从融合网关获取列表,如果该值为true,则实时获取</param>
        /// <param name="cameraList">摄像头列表</param>
        /// <param name="groupList">组信息</param>
        /// <param name="nodeRelationList">分组关系</param>
        /// <returns></returns>
        public SmcError.SmcErr GetAllCameras(out List<Camera> cameraList, out List<CameraGroup> groupList, out List<NodeRelation> nodeRelationList)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: eLTEVideoMonitor.GetAllCameras().");
            SmcErr err = new CgwError();
            cameraList = new List<Camera>();
            groupList = new List<CameraGroup>();
            nodeRelationList = new List<NodeRelation>();

            isGetDevicesFinish = false;
            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);

                        try
                        {
                            if (this.cameraStatusOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                            {
                                camera.Status = onlineUser.Exists((x) =>
                                {
                                    if (x == camera.No)
                                    {
                                        return true;
                                    }
                                    else
                                    {
                                        return false;
                                    }
                                }) == true ? CameraStatus.Online : CameraStatus.Offline;
                            }
                        }
                        finally
                        {
                            this.cameraStatusOperateLock.ExitReadLock();
                        }
                        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("Get all cameras success.");
            return err;
        }
Exemplo n.º 47
0
        /// <summary>
        /// 启动摄像头预览
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <returns></returns>
        public SmcErr StartReceiveVideo(string cameraNo)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: IvsVideoMonitor.StartReceiveVideo({0}).", cameraNo);
            SmcErr err = new CgwError();
            int handle;
            logEx.Trace("Call ivsSdkClient.StartRealPlayCBRaw({0}).", cameraNo);
            int result = this.ivsSdkClient.StartRealPlayCBRaw(cameraNo, out handle);

            //如果不为0,表示预览失败
            if (result != CgwConst.IVS_SDK_SUCCESS_TAG)
            {
                err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                logEx.Error("Start Receive camera video data failed.Camera No:{0}.Ivs sdk error code:{1}", cameraNo, result);
                return err;
            }
            else
            {
                logEx.Info("Start Receive camera video data success.Camera No:{0},Handle:{1}.", cameraNo, handle);
            }

            //预览成功,需要停止原来的预览,并将预览句柄添加到缓存
            //需要停止的预览句柄
            int needToStopHandel = CgwConst.START_RECEIVE_VIDEO_DATA_FAILED;
            if (this.handelOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    //如果预览句柄已经存在,删除掉原来的句柄,用新的句柄替换
                    if (this.cameraVideoHandeDic.ContainsKey(cameraNo))
                    {
                        needToStopHandel = this.cameraVideoHandeDic[cameraNo];
                        this.videoHandleCameraDic.Remove(needToStopHandel);
                        this.cameraVideoHandeDic.Remove(cameraNo);
                    }
                    this.cameraVideoHandeDic.Add(cameraNo, handle);
                    MediaDataSender mediaDataSender = new MediaDataSender(cameraNo, this.dataCallBack);
                    this.videoHandleCameraDic.Add(handle, mediaDataSender);
                }
                finally
                {
                    this.handelOperateLock.ExitWriteLock();
                }
            }

            //重新预览后,更新了预览句柄,需要将原来的预览停止,放在handelOperateLock外面,防止长时间占用锁
            if (needToStopHandel != CgwConst.START_RECEIVE_VIDEO_DATA_FAILED)
            {
                result = this.ivsSdkClient.StopRealPlay(needToStopHandel);
                //如果不为0,表示停止原来的预览失败,只记录日志,不返回错误,不设置错误码
                if (result != CgwConst.IVS_SDK_SUCCESS_TAG)
                {
                    logEx.Error("Get a new preview success. But stop old preview failed.CameraNo:{0},Ivs sdk error code:{0}", cameraNo, result);
                    return err;
                }
            }

            return err;
        }
Exemplo n.º 48
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.º 49
0
        /// <summary>
        /// 停止预览
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <returns>成功返回0,失败返回错误码</returns>
        public SmcErr StopReceiveVideo(string cameraNo)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: IvsVideoMonitor.StopReceiveVideo({0}).", cameraNo);
            SmcErr err = new CgwError();
            //需要停止的预览句柄
            int needToStopHandel = CgwConst.START_RECEIVE_VIDEO_DATA_FAILED;
            if (this.handelOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    if (this.cameraVideoHandeDic.ContainsKey(cameraNo))
                    {
                        needToStopHandel = this.cameraVideoHandeDic[cameraNo];
                        this.videoHandleCameraDic.Remove(needToStopHandel);
                        this.cameraVideoHandeDic.Remove(cameraNo);
                    }
                    else
                    {
                        logEx.Warn("Stop Receive camera video data failed. Don't need to end the preview.Camera No:{0}.", cameraNo);
                        //如果预览句柄不存在,不需要处理,直接返回
                        return err;
                    }
                }
                catch (Exception ex)
                {
                    err.SetErrorNo(CgwError.STOP_RECEIVE_VIDEO_FAILED);
                    logEx.Error("Stop Receive camera video data failed.Execption message:{0}", ex.Message);
                    return err;
                }
                finally
                {
                    this.handelOperateLock.ExitWriteLock();
                }
            }

            //调用sdk的停止方法,放在handelOperateLock外面,防止长时间占用锁
            if (needToStopHandel != CgwConst.START_RECEIVE_VIDEO_DATA_FAILED)
            {
                int result = this.ivsSdkClient.StopRealPlay(needToStopHandel);
                //如果不为0,表示预览失败
                if (result != CgwConst.IVS_SDK_SUCCESS_TAG)
                {
                    err.SetErrorNo(CgwError.STOP_RECEIVE_VIDEO_FAILED);
                    logEx.Error("Stop Receive camera video data failed.Ivs sdk error code:{0}", result);
                    return err;
                }
                logEx.Info("Stop Receive camera video data success.Camera No:{0},Handle:{1}.", cameraNo, needToStopHandel);
            }

            return err;
        }
Exemplo n.º 50
0
        /// <summary>
        /// 初始化天地伟业监控平台
        /// </summary>
        /// <param name="monitorConfigElement">监控平台配置节点</param>
        /// <returns></returns>
        public SmcErr Load(XmlElement monitorConfigElement)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: TiandyVideoMonitor.Load().");
            SmcErr err = new CgwError();

            string userLevel = "";
            //解析xml节点,获取所需参数
            try
            {
                #region Tiandy视频监控平台(Easy7)连接信息
                this.monitorId = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.ID_TAG);

                userLevel = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.PTZCONTROLLEVEL_TAG);

                string httpUser = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.PLATFORM_USER_TAG);

                string httpPassword = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.PLATFORM_PASSWORD_TAG);

                string httpUrl = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.PLATFORM_URL_TAG);

                string mediaServerId = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.MEDIASERVER_SERVERID_TAG);
                #endregion
                this.httpClient = new TiandyHttpClient(httpUrl, httpUser, httpPassword);

                //使用线程轮询加载监控平台
                Thread loaderThread = new Thread(LoaderThread);
                loaderThread.Start(mediaServerId);

            }
            catch (Exception e)
            {
                err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID);
                logEx.Error("Load Tiandy monitor failed.Execption message:{0}.", e.Message);
                return err;
            }

            this.sdkClient = new TiandySdkClient();
            //如果控制级别配置错误,只记录错误日志,不向外报错
            try
            {
                this.sdkClient.PtzControlLevel = int.Parse(userLevel);
            }
            catch (Exception e)
            {
                logEx.Error("Ptz Control Level is invalid.Execption message:{0}.", e.Message);
                this.sdkClient.PtzControlLevel = CgwConst.PTZ_CONTROL_LEVEL;
            }
            logEx.Info("Load video monitor success.Monitor id:{0}.", this.monitorId);
            return err;
        }
Exemplo n.º 51
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.º 52
0
        /// <summary>
        /// 连接融合网关
        /// </summary>
        /// <param name="password">连接字符串</param>
        /// <returns></returns>
        public SmcErr Connect(out string sessionID)
        {
            SmcErr err = new CgwError();
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            sessionID = "";
            if (isLoadSuccess == false)
            {
                err.SetErrorNo(CgwError.ERR_CGW_IS_LOADING);
                return err;
            }

            //获取SessionManage中Session个数
            if (SessionManage.Instance().GetSessionsCount() == 0)
            {
                Guid sessionGuid = Guid.NewGuid();

                sessionID = OperationContext.Current.SessionId;
                currentSessionID = sessionID;
                //保存至CGW的session管理中
                CgwSession CgwSession = new CgwSession(sessionGuid, OperationContext.Current.SessionId);

                MessageProperties properties = OperationContext.Current.IncomingMessageProperties;   //获取传进的消息属性  

                RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; //获取消息发送的远程终结点IP和端口 
                if (endpoint != null)
                {
                    CgwConst.ClientIp = endpoint.Address; // 获取发送消息的客户端的 IP 地址。
                    logEx.Info("Client Connect MonitorManageService Successful,Current.Client IP is : {0}", CgwConst.ClientIp);
                }
                else
                {
                    logEx.Info("Client Connect MonitorManageService Successful,Current.Client IP is  null.");
                }
            }
            else
            {
                err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_SESSION_COUNT_MAX);
                logEx.Warn("Session Count is  Top Of Max number !");
            }

            return err;
        }
Exemplo n.º 53
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.º 54
0
        /// <summary>
        /// 注销eLTE平台资源
        /// </summary>
        /// <returns></returns>
        public SmcError.SmcErr Unload()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Info("Enter: eLTEVideoMonitor.Unload().");

            IsNeedLogin = false;
            SmcErr err = new CgwError();
            //停止定时器
            this.updateCameraTimer.Stop();
            //SDK停止处理业务
            logEx.Trace("Call eLTEVideoMonitor SDK_STOP");
            ELTE_RESULT result = (ELTE_RESULT)this.lteSdkClient.SDK_STOP();

            //释放所有实况通道,释放NETSOURCE资源
            //IVS_NETSOURCE_RESULT iNet = NetSourcedInterface.IVS_NETSOURCE_UnInit();

            logEx.Trace("Call eLTEVideoMonitor IVS_NETSOURCE_UnInit");
            NetSourcedInterface.IVS_NETSOURCE_UnInit();
            logEx.Trace("Call eLTEVideoMonitor ESDK_RTP_UnInit");
            int iNet = rtpAdapter.ESDK_RTP_UnInit();

            //if (result == ELTE_RESULT.RET_SUCCESS || iNet != IVS_NETSOURCE_RESULT.SUCCESS)
            if (result == ELTE_RESULT.RET_SUCCESS && iNet == 0)
            {
                logEx.Info("Unload eLTEVideoMonitor monitor success.Monitor id:{0}.", this.monitorId);
            }
            else
            {
                err.SetErrorNo(CgwError.MONITOR_UDLOAD_FAILED);
                logEx.Error("Unload eLTEVideoMonitor monitor failed.Monitor id:{0}.", this.monitorId);
            }
            return err;
        }
Exemplo n.º 55
0
        /// <summary>
        /// 获取摄像头列表及分组信息
        /// </summary>
        /// <param name="fromMonitorSys">如果该值为true,则实时从监控平台获取,否则从融合网关缓存获取</param>
        /// <param name="cameraList">摄像头列表</param>
        /// <param name="groupList">组信息</param>
        /// <param name="nodeRelationListT">分组关系</param>
        /// <returns></returns>
        public SmcErr GetAllCameras(out List<Camera> cameraList, out List<CameraGroup> groupList, out List<NodeRelation> nodeRelationListT)
        {
            monitorManageServiceGetCameraList.Stop();
            isGetDevicesFinish = false;

            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: TiandyVideoMonitor.GetAllCameras().");
            SmcErr err = new CgwError();
            cameraList = new List<Camera>();
            groupList = new List<CameraGroup>();
            nodeRelationListT = new List<NodeRelation>();

            if (this.cameraOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    #region 深度克隆数据
                    foreach (KeyValuePair<string, TiandyCamera> tiandyCameraKeyValue in this.tiandyCameraDictionary)
                    {
                        TiandyCamera tiandyCamera = tiandyCameraKeyValue.Value;
                        //从缓存获取
                        Camera camera = new Camera(tiandyCamera.No, tiandyCamera.Name);
                        cameraList.Add(camera);
                    }
                    foreach (KeyValuePair<string, CameraGroup> groupDicKeyValue in this.groupDic)
                    {
                        CameraGroup cameraGroupTemp = new CameraGroup(groupDicKeyValue.Value.No, groupDicKeyValue.Value.Name);
                        groupList.Add(cameraGroupTemp);
                    }

                    foreach (NodeRelation nodeRelation in this.nodeRelationList)
                    {
                        NodeRelation nodeRelationTemp = new NodeRelation(nodeRelation.No,
                                                                          nodeRelation.Path,
                                                                          nodeRelation.Type);
                        nodeRelationListT.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();
                }
            }
            monitorManageServiceGetCameraList.Start();
            logEx.Info("Get all cameras success.");
            return err;
        }
Exemplo n.º 56
0
        /// <summary>
        /// 初始化eLTE台
        /// </summary>
        /// <param name="monitorConfigElement">监控平台配置节点</param>
        /// <returns></returns>
        public SmcError.SmcErr Load(System.Xml.XmlElement monitorConfigElement)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Info("Enter: eLTEVideoMonitor.Load().");
            SmcErr err = new CgwError();

            try
            {
                //解析xml节点,获取所需参数    
                this.monitorId = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.ID_TAG);
                string port = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.PORT_TAG);
                string localPort = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.LOCAL_ELTE_PORT);
                user = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.USER_TAG);

                pwdByte = CommonFunction.EncryptStr2Byte(CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.PASSWORD_TAG),CgwConst.PASSWORD_TAG);
                ip = CommonFunction.GetSingleNodeValue(monitorConfigElement, CgwConst.IP_TAG);

                bPttUser = bool.Parse(LoadElTEParamters(monitorConfigElement, CgwConst.PTT_USER, boolArrays));
                bFixedCamera = bool.Parse(LoadElTEParamters(monitorConfigElement, CgwConst.FIXED_CAMERA, boolArrays));

                fmtValue = LoadElTEParamters(monitorConfigElement, CgwConst.FMT_VALUE, fmtValueArrays);
                cameraType = LoadElTEParamters(monitorConfigElement, CgwConst.CAMERA_TYPE, cameraTypeArrays);

                userConfirmType = LoadElTEParamters(monitorConfigElement, CgwConst.USER_CONFIRM_TYPE,userConfirmTypeArrays);
                muteType = LoadElTEParamters(monitorConfigElement, CgwConst.MUTE_TYPE,muteTypeArrays);

                iPort = 0;
                if (!int.TryParse(port, out iPort))
                {
                    err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID);
                    logEx.Error("Load eLTE monitor failed.Execption PORT_TAG:{0}.", port);
                    return err;
                }

                ilocalPort = 0;
                if (!int.TryParse(localPort, out ilocalPort))
                {
                    err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID);
                    logEx.Error("Load eLTE monitor failed.Execption PORT_TAG:{0}.", localPort);
                    return err;
                }
                //用户名是数值
                int iUserName = 0;
                if (!int.TryParse(user, out iUserName))
                {
                    err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID);
                    logEx.Error("Load eLTE monitor failed.Execption PORT_TAG:{0}.", user);
                    return err;
                }

                eLTELoginInfo loginInfo = new eLTELoginInfo();
                loginInfo.Ip = ip;
                loginInfo.Port = iPort;
                loginInfo.User = user;
                loginInfo.Pwd = CommonFunction.DecryptByte2Str(pwdByte,CgwConst.PASSWORD_TAG);
                loginInfo.PTTUSER = bPttUser;
                loginInfo.FIXEDCAMERA = bFixedCamera;

                IsNeedLogin = true;
                //使用线程轮询加载监控平台
                Thread loaderThread = new Thread(LoginThread);
                loaderThread.IsBackground = true;
                loaderThread.Start(loginInfo);

            }
            catch (Exception e)
            {
                err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID);
                logEx.Error("Load eLTEVideoMonitor failed.Execption message:{0}.", e.Message);
                return err;
            }

            logEx.Info("Load video monitor success.Monitor id:{0}.", this.monitorId);
            return err;
        }
Exemplo n.º 57
0
        /// <summary>
        /// 启动摄像头预览
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <returns></returns>
        public SmcErr StartReceiveVideo(string cameraNo)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: TiandyVideoMonitor.StartReceiveVideo({0}).", cameraNo);
            SmcErr err = new CgwError();

            TiandyCamera camera = null;
            Host host = null;

            //摄像头所连接的流媒体服务器
            MediaServer cameraMediaServer = null;
            if (this.cameraOperateLock.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                try
                {
                    if (!this.tiandyCameraDictionary.ContainsKey(cameraNo))
                    {
                        err.SetErrorNo(CgwError.CAMERA_NOT_FOUND);
                        logEx.Error("Start Receive camera video data failed.Camera No is not found.Camera No:{0}", cameraNo);
                        return err;
                    }
                    camera = this.tiandyCameraDictionary[cameraNo];
                    host = this.hostDictionary[camera.HostNo];
                    cameraMediaServer = this.mediaServerDictionary[host.MediaServerNo];
                }
                catch (Exception e)
                {
                    err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                    logEx.Error("Start Receive camera video data failed.Camera No:{0},Execption message:{1}", cameraNo, e.Message);
                    return err;
                }
                finally
                {
                    this.cameraOperateLock.ExitReadLock();
                }
            }

            if (camera == null)
            {
                err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                logEx.Error("Start Receive camera video data failed.Camera No is not found.Camera No:{0}", cameraNo);
                return err;
            }

            RealPlayInfo real = new RealPlayInfo();
            real.ch = camera.Channel;
            real.data_type = (int)TiandyDateType.PRIMARY;
            real.hPlayWnd = null;

            int result = this.sdkClient.StartReceiveVideo(host.No, cameraMediaServer, ref real);

            //如果为负数,表示预览失败
            if (result < 0)
            {
                err.SetErrorNo(CgwError.START_RECEIVE_VIDEO_FAILED);
                logEx.Error("Start Receive camera video data failed.Camera No:{0}.", cameraNo);
                return err;
            }
            else
            {
                //需要停止的预览句柄
                int needToStopHandel = CgwConst.START_RECEIVE_VIDEO_DATA_FAILED;
                if (this.handelOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                {
                    try
                    {
                        //如果预览句柄已经存在,删除掉原来的句柄,用新的句柄替换
                        if (this.cameraVideoHandeDic.ContainsKey(cameraNo))
                        {
                            needToStopHandel = this.cameraVideoHandeDic[cameraNo];
                            this.videoHandleCameraDic.Remove(needToStopHandel);
                            this.cameraVideoHandeDic.Remove(cameraNo);
                        }
                        this.cameraVideoHandeDic.Add(cameraNo, result);
                        this.videoHandleCameraDic.Add(result, cameraNo);
                    }
                    finally
                    {
                        this.handelOperateLock.ExitWriteLock();
                    }
                }
                logEx.Info("Start Receive camera video data success.Camera No:{0},Handle:{1}.", cameraNo, result);
                //重新预览后,更新了预览句柄,需要将原来的预览停止,放在handelOperateLock外面,防止长时间占用锁
                if (needToStopHandel != CgwConst.START_RECEIVE_VIDEO_DATA_FAILED)
                {
                    this.sdkClient.StopReceiveVideo(needToStopHandel);
                }
            }

            return err;
        }
Exemplo n.º 58
0
        /// <summary>
        /// 开始云台控制,摄像头控制
        /// </summary>
        /// <param name="cameraNo">摄像头编号</param>
        /// <param name="ptzCommand">命令类型</param>
        /// <param name="param">命令参数(速度、倍数)</param>
        /// <returns></returns>
        public SmcError.SmcErr StartControlPtz(string cameraNo, PtzCommandType ptzCommand, int param)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: eLTEVideoMonitor.StartControlPtz.cameraNo:{0},ptzCommand:{1},param:{2}", cameraNo, Enum.GetName(typeof(PtzCommandType), ptzCommand), param);
            SmcErr err = new CgwError();

            //将ptz命令转换成elte的命令
            eLTEPTZControlCode ptzControl = eLTEPTZControlCode.STOP_SEQ;

            switch (ptzCommand)
            {
                case PtzCommandType.PTZ_CMD_DOWN:
                    ptzControl = eLTEPTZControlCode.TILT_DOWN;
                    break;
                case PtzCommandType.PTZ_CMD_FOCUS_IN:
                    ptzControl = eLTEPTZControlCode.FOCUS_NEAR;
                    break;
                case PtzCommandType.PTZ_CMD_FOCUS_OUT:
                    ptzControl = eLTEPTZControlCode.FOCUS_FAR;
                    break;
                case PtzCommandType.PTZ_CMD_IRIS_ENLARGE:
                    ptzControl = eLTEPTZControlCode.IRIS_OPEN;
                    break;
                case PtzCommandType.PTZ_CMD_IRIS_SHRINK:
                    ptzControl = eLTEPTZControlCode.IRIS_CLOSE;
                    break;
                case PtzCommandType.PTZ_CMD_LEFT:
                    ptzControl = eLTEPTZControlCode.PAN_LEFT;
                    break;
                case PtzCommandType.PTZ_CMD_RIGHT:
                    ptzControl = eLTEPTZControlCode.PAN_RIGHT;
                    break;
                case PtzCommandType.PTZ_CMD_UP:
                    ptzControl = eLTEPTZControlCode.TILT_UP;
                    break;
                case PtzCommandType.PTZ_CMD_ZOOM_IN:
                    ptzControl = eLTEPTZControlCode.ZOOM_IN;
                    break;
                case PtzCommandType.PTZ_CMD_ZOOM_OUT:
                    ptzControl = eLTEPTZControlCode.ZOOM_OUT;
                    break;

            }

            ELTE_RESULT result = (ELTE_RESULT)lteSdkClient.PTZControl(Convert.ToInt32(cameraNo), (uint)ptzControl, (uint)(param * iPTZScale));//eLTE云台速度慢,放大20倍

            if (result != ELTE_RESULT.RET_SUCCESS)
            {
                err.SetErrorNo(CgwError.START_CONTROL_PTZ_FAILED);
                logEx.Error("StartControlPtz failed.eLTE sdk error code:{0}", result);
                return err;
            }
            else
            {
                logEx.Debug("StartControlPtz Success");
            }

            return err;
        }
Exemplo n.º 59
0
 /// <summary>
 /// 注销天地伟业监控平台资源
 /// </summary>
 /// <returns></returns>
 public SmcErr Unload()
 {
     NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
     logEx.Trace("Enter: TiandyVideoMonitor.Unload().");
     SmcErr err = new CgwError();
     //停止定时器
     this.updateCameraTimer.Stop();
     if (this.sdkClient.Unload())
     {
         logEx.Info("Unload video monitor success.Monitor id:{0}.", this.monitorId);
     }
     else
     {
         err.SetErrorNo(CgwError.UNLOAD_MONITOR_FAILED);
         logEx.Error("Unload video monitor failed.Monitor id:{0}.", this.monitorId);
     }
     return err;
 }
Exemplo n.º 60
0
        /// <summary>
        /// 初始化监控平台
        /// </summary>
        /// <returns></returns>
        public SmcErr Load()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Info("Enter: VideoMonitorManage.Load()");
            SmcErr err = new CgwError();
            XmlElement monitorsRootElement = ConfigSettings.MonitorSettings;
            if (monitorsRootElement == null)
            {
                err.SetErrorNo(CgwError.MONITOR_CONFIG_FILE_INVALID);
                logEx.Error("Monitor config file is invalid.Can not found monitorSettings node.");
                return err;
            }

            foreach (XmlNode monitorNode in monitorsRootElement)
            {
                XmlElement monitorElement = monitorNode as XmlElement;

                if (monitorElement == null)
                {
                    continue;
                }
                else if (CgwConst.MONITOR_TAG.Equals(monitorElement.Name))
                {
                    //判断监控平台是否启用
                    string isEnable = monitorElement.GetAttribute(CgwConst.ENABLE_TAG).Trim();
                    if (!CgwConst.TRUE_TAG.Equals(isEnable.ToLower()))
                    {
                        logEx.Warn("This monitor is disable.");
                        continue;
                    }

                    string monitorId;
                    string className;
                    err = GetMonitorConfig(monitorElement, out monitorId, out className);

                    if (!err.IsSuccess())
                    {
                        return err;
                    }

                    IVideoMonitor videoMonitor;
                    //加载监控平台
                    err = CreateMonitor(monitorId, className, out videoMonitor);
                    if (!err.IsSuccess())
                    {
                        logEx.Error("Create monitor failed.monitorId:{0}, className:{1}, Error code:{2}", monitorId, className, err.ErrNo);
                        return err;
                    }

                    err = videoMonitor.Load(monitorElement);
                    if (err.IsSuccess())
                    {
                        if (this.monitorsOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                        {
                            try
                            {
                                monitorsDictionary.Add(monitorId, videoMonitor);
                            }
                            catch (Exception e)
                            {
                                logEx.Error("Load monitor failed.Execption message:{0}", e.Message);
                                return err;
                            }
                            finally
                            {
                                this.monitorsOperateLock.ExitWriteLock();
                            }
                        }
                    }
                    else
                    {
                        logEx.Error("Load monitor failed.MonitorId:{0},Error code:{1}", monitorId, err.ErrNo);
                        return err;
                    }
                }
            }

            logEx.Info("Load all monitors success.");
            return err;
        }