/// <summary> /// 断开监控平台管理服务 /// </summary> /// <returns></returns> public Cgw.SmcError.SmcErr Disconnect() { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Trace("Enter: CgwMonitorManageAdapter.Disconnect"); Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); try { //判断Monitor服务是否在线,在线调用DisConnect方法 if (serviceControl.MonitorServiceRun()) { client = new MonitorManageServiceClient(); CgwMonitorManageServiceReference.SmcErr serviceErr = client.Disconnect(); client.Close(); if (serviceErr.ErrNo != Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_SUCCESS) { logEx.Error("CgwMonitorManageAdapter.Disconnect failed. ErrNo = {0} ", serviceErr.ErrNo); err = SetCgwErrNo(serviceErr); } } else //不在线,无需调用DisConnect方法 { logEx.Info("CgwMonitorManageAdapter.Disconnect,MonitorManage Stopped"); } } catch (System.Exception ex) { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); logEx.Error("CgwMonitorManageServiceReference.Disconnect failed. Exception is {0} ", ex.ToString()); } return(err); }
/// <summary> /// 刷新监控摄像头列表 /// </summary> /// <returns></returns> public Cgw.SmcError.SmcErr RefreshMonitorCamera() { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Trace("Enter: CgwMonitorManageAdapter.RefreshMonitorCamera"); Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); try { //if (serviceControl.MonitorServiceRun() && client.State == CommunicationState.Opened) if (serviceControl.MonitorServiceRun()) { client = new MonitorManageServiceClient(); CgwMonitorManageServiceReference.SmcErr serviceErr = client.RefreshMonitorCamera(); client.Close(); if (serviceErr.ErrNo != Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_SUCCESS) { logEx.Error("CgwMonitorManageAdapter.RefreshMonitorCamera failed. ErrNo = {0} ", serviceErr.ErrNo); err = SetCgwErrNo(serviceErr); } } else { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); } } catch (System.Exception ex) { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); logEx.Error("CgwMonitorManageServiceReference.RefreshMonitorCamera failed. Exception is {0} ", ex.ToString()); } return(err); }
/// <summary> /// 连接监控平台管理服务 /// </summary> /// <param name="monitorPwd">加密后的密码字符串</param> /// <returns></returns> public Cgw.SmcError.SmcErr Connect(string monitorPwd) { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Info("Enter: CgwMonitorManageAdapter.Connect"); Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); try { if (serviceControl.MonitorServiceRun()) { logEx.Info("CgwMonitorManageAdapter.Connect Opened"); client = new MonitorManageServiceClient(); CgwMonitorManageServiceReference.SmcErr serviceErr = client.Connect(out monitorPwd); sessionID = monitorPwd; client.Close(); if (serviceErr.ErrNo != Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_SUCCESS) { logEx.Error("CgwMonitorManageAdapter.Connect failed. ErrNo = {0} ", serviceErr.ErrNo); err = SetCgwErrNo(serviceErr); } } else { logEx.Info("CgwMonitorManageAdapter.Connect MonitorServiceStart"); err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); serviceControl.MonitorServiceStart();//自动重连监控服务 } } catch (System.Exception ex) { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); logEx.Error("CgwMonitorManageServiceReference.Connect failed. Exception is {0} ", ex.ToString()); } return(err); }
/// <summary> /// 保存错误描述包括的扩展错误原因 /// </summary> /// <param name="err">错误信息</param> public virtual void AddSmcErrInfo(SmcErr err) { if (null == this.ExternErrs) { this.ExternErrs = new List <SmcErr>(); } if (null != err) { this.ExternErrs.Add(err); } }
/// <summary> /// 保存批量操作的错误描述 /// </summary> /// <param name="err">错误信息</param> public virtual void AddMultipleErrs(SmcErr err) { if (null == this.MultipleErrs) { this.MultipleErrs = new List <SmcErr>(); } if (null != err) { SmcErr oldErr = this.MultipleErrs.Find(delegate(SmcErr target) { return(target.ErrNo == err.ErrNo); }); if (oldErr != null) { try { if (err.ErrorInfoParam.ParametersDictionary != null && err.ErrorInfoParam.ParametersDictionary.Count > 0) { for (int i = 0; i < err.ErrorInfoParam.ParametersDictionary.Count; i++) { if (err.ErrorInfoParam.ParametersDictionary[i] != null && err.ErrorInfoParam.ParametersDictionary[i].Count > 0) { for (int j = 0; j < err.ErrorInfoParam.ParametersDictionary[i].Count; j++) { if (err.ErrorInfoParam.ParametersDictionary[i][j].Name == oldErr.ErrorInfoParam.ParametersDictionary[i][j].Name && err.ErrorInfoParam.ParametersDictionary[i][j].Value != oldErr.ErrorInfoParam.ParametersDictionary[i][j].Value) { //批量操作错误描述对象如果超过3个则用“...”代替 if (oldErr.ErrorInfoParam.ParametersDictionary[i][j].Value.Split(',').Length < 3) { oldErr.ErrorInfoParam.ParametersDictionary[i][j].Value += ", " + err.ErrorInfoParam.ParametersDictionary[i][j].Value; } else if (oldErr.ErrorInfoParam.ParametersDictionary[i][j].Value.Split(',').Length == 3) { oldErr.ErrorInfoParam.ParametersDictionary[i][j].Value += ", ..."; } } } } } } } catch (Exception) { } } else { this.MultipleErrs.Add(err); } } }
/// <summary> /// 设置返回smc的错误码 /// </summary> /// <param name="monitorSmcErr"></param> /// <returns></returns> private Cgw.SmcError.SmcErr SetCgwErrNo(CgwMonitorManageServiceReference.SmcErr monitorSmcErr) { Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); if (monitorSmcErr.ErrNo == Cgw.SmcError.CgwError.ERR_CGW_IS_LOADING || monitorSmcErr.ErrNo == Cgw.SmcError.CgwError.ERR_CGW_BUSINESS_CURRENTSESSION_NULL || monitorSmcErr.ErrNo == Cgw.SmcError.CgwError.ERR_CGW_BUSINESS_SESSION_NULL ) { err.ErrNo = Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING; } else { err.ErrNo = monitorSmcErr.ErrNo; } return(err); }
/// <summary> /// 停止预览摄像头视频,并清理命名管道 /// </summary> /// <param name="cameraNo"></param> /// <returns></returns> public Cgw.SmcError.SmcErr StopReceiveVideoByPipe(string cameraNo) { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Trace("Enter: CgwMonitorManageAdapter.StopReceiveVideoByPipe"); Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); try { //if (serviceControl.MonitorServiceRun() && client.State == CommunicationState.Opened) if (serviceControl.MonitorServiceRun()) { client = new MonitorManageServiceClient(); CgwMonitorManageServiceReference.SmcErr serviceErr = client.StopReceiveVideoByPipe(cameraNo); client.Close(); if (serviceErr.ErrNo != Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_SUCCESS) { logEx.Error("CgwMonitorManageAdapter.StopReceiveVideoByPipe failed. ErrNo = {0} ", serviceErr.ErrNo); err = SetCgwErrNo(serviceErr); } else { VideoPipe videoPipe = VideoPipeManage.Instance().DeleteVideoPipe(cameraNo); if (videoPipe != null) { videoPipe.Stop(); logEx.Info("CgwMonitorManageAdapter.StopReceiveVideoByPipe Success. cameraNo = {0} ", cameraNo); } else { logEx.Error("CgwMonitorManageAdapter.StopReceiveVideoByPipe failed. ErrNo = {0} ", serviceErr.ErrNo); } } } else { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); } } catch (System.Exception ex) { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); logEx.Error("CgwMonitorManageServiceReference.StopReceiveVideoByPipe failed. Exception is {0} ", ex.ToString()); logEx.Error("CameraNo:" + cameraNo); } return(err); }
/// <summary> /// 获取监控摄像头列表刷新状态,返回结果为0是表示刷新完毕,为1是刷新操作中。当查询刷新状态为0时,可调用获取监控摄像头列表接口,获取刷新后监控摄像头列表 /// </summary> /// <param name="refreshStatus">返回值,刷新状态</param> /// <returns></returns> public Cgw.SmcError.SmcErr GetRefreshStatus(out SmcError.SmcErr refreshStatus) { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Trace("Enter: CgwMonitorManageAdapter.GetRefreshStatus"); refreshStatus = new Cgw.SmcError.SmcErr(); refreshStatus.ErrNo = Cgw.SmcError.CgwError.ERR_DEVICE_LIST_REFRESH_STATUS_END; Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); try { //if (serviceControl.MonitorServiceRun() && client.State == CommunicationState.Opened) if (serviceControl.MonitorServiceRun()) { CgwMonitorManageServiceReference.SmcErr i_refreshStatus = new CgwMonitorManageServiceReference.SmcErr(); client = new MonitorManageServiceClient(); CgwMonitorManageServiceReference.SmcErr serviceErr = client.GetRefreshStatus(out i_refreshStatus); client.Close(); refreshStatus.ErrNo = i_refreshStatus.ErrNo; if (serviceErr.ErrNo != Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_SUCCESS) { logEx.Error("CgwMonitorManageAdapter.GetRefreshStatus failed. ErrNo = {0} ", serviceErr.ErrNo); err = SetCgwErrNo(serviceErr); } else { logEx.Info("CgwMonitorManageAdapter.GetRefreshStatus Success. "); } } else { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); } } catch (System.Exception ex) { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); logEx.Error("CgwMonitorManageServiceReference.GetRefreshStatus failed. Exception is {0} ", ex.ToString()); } return(err); }
/// <summary> /// 关闭PTZ操作 /// </summary> /// <param name="Camerano">摄像头</param> /// <returns></returns> public Cgw.SmcError.SmcErr StopControlPtz(string cameraNo, Common.PtzCommandType ptzCommandType) { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Trace("Enter: CgwMonitorManageAdapter.StopControlPtz"); Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); try { //if (serviceControl.MonitorServiceRun() && client.State == CommunicationState.Opened) if (serviceControl.MonitorServiceRun()) { client = new MonitorManageServiceClient(); CgwMonitorManageServiceReference.PtzCommandType ptzCommand = (CgwMonitorManageServiceReference.PtzCommandType)ptzCommandType; //将平台的枚举转换成服务中的枚举 CgwMonitorManageServiceReference.SmcErr serviceErr = client.StopControlPtz(cameraNo, ptzCommand); client.Close(); if (serviceErr.ErrNo != Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_SUCCESS) { logEx.Error("Stop control ptz failed.Camera no:{0},ptzCommandType:{1},Error Code:{2} ", cameraNo, ptzCommand, err.ErrNo); err = SetCgwErrNo(serviceErr); } else { logEx.Info("Stop control ptz success.Camera no:{0},ptzCommandType:{1}.", cameraNo, ptzCommand); } } else { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); } } catch (System.Exception ex) { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); logEx.Error("CgwMonitorManageServiceReference.StopControlPtz failed. Exception is {0} ", ex.ToString()); } return(err); }
/// <summary> /// 重发I帧(暂不支持) /// </summary> /// <param name="cameraNo">摄像头编号</param> /// <returns></returns> public Cgw.SmcError.SmcErr MakeIFrame(string cameraNo) { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Trace("Enter: CgwMonitorManageAdapter.MakeIFrame"); Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); //MakeIFrame不存在重发I帧的效果,注销代码 zWX231378 2015/7/14 //try //{ // //if (serviceControl.MonitorServiceRun() && client.State == CommunicationState.Opened) // if(serviceControl.MonitorServiceRun()) // { // client = new MonitorManageServiceClient(); // CgwMonitorManageServiceReference.SmcErr serviceErr = client.MakeIFrame(cameraNo); // client.Close(); // if (serviceErr.ErrNo == Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_SUCCESS) // { // logEx.Info("Cgw MakeIFrame Successful,Current Cgw IP is : {0}", CgwConst.CGWSERVICE_IP_TAG); // } // else // { // logEx.Error("Cgw MakeIFrame failed,ErrNo :{0}", err.ErrNo); // err = SetCgwErrNo(serviceErr); // } // } // else // { // err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); // } //} //catch (System.Exception ex) //{ // err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); // logEx.Error("CgwMonitorManageServiceReference.MakeIFrame failed. Exception is {0} ", ex.ToString()); //} return(err); }
/// <summary> /// 设置扬声器 /// </summary> /// <param name="cameraNo"></param> /// <param name="isOn"></param> /// <returns></returns> public Cgw.SmcError.SmcErr SetSpeaker(string cameraNo, bool isOn) { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Trace("Enter: CgwMonitorManageAdapter.SetSpeaker"); Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); try { //if (serviceControl.MonitorServiceRun() && client.State == CommunicationState.Opened) if (serviceControl.MonitorServiceRun()) { client = new MonitorManageServiceClient(); CgwMonitorManageServiceReference.SmcErr serviceErr = client.SetSpeaker(cameraNo, isOn); client.Close(); if (serviceErr.ErrNo == Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_SUCCESS) { logEx.Info("Cgw SetSpeaker Successful,Current Cgw IP is : {0}", CgwConst.CGWSERVICE_IP_TAG); } else { logEx.Error("Cgw SetSpeaker failed,ErrNo :{0}", err.ErrNo); err = SetCgwErrNo(serviceErr); } } else { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); } } catch (System.Exception ex) { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); logEx.Error("CgwMonitorManageServiceReference.SetSpeaker failed. Exception is {0} ", ex.ToString()); } return(err); }
/// <summary> /// 保持连接 /// </summary> /// <returns></returns> public Cgw.SmcError.SmcErr KeepAliver() { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Trace("Enter: CgwMonitorManageAdapter.KeepAliver"); Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); try { client = new MonitorManageServiceClient(); CgwMonitorManageServiceReference.SmcErr serviceErr = client.KeepAliver(sessionID); client.Close(); if (serviceErr.ErrNo != Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_SUCCESS) { logEx.Error("CgwMonitorManageAdapter.KeepAliver failed. ErrNo = {0} ", serviceErr.ErrNo); err = SetCgwErrNo(serviceErr); } } catch (System.Exception ex) { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); logEx.Error("CgwMonitorManageServiceReference.KeepAliver failed. Exception is {0} ", ex.ToString()); } return(err); }
/// <summary> /// 带异常信息的Trace类日志输出。 /// </summary> /// <param name="err">错误码,即信息</param> /// <param name="e">e</param> /// <param name="message">message</param> /// <param name="args">args</param> public void Trace(SmcErr err, Exception e, string message, params object[] args) { if (this.Log.IsTraceEnabled) { this.WriteToLog(LogLevel.Trace, err, e, message, args); } }
/// <summary> /// 停止预览摄像头视频,并清理命名管道 /// </summary> /// <param name="cameraNo"></param> /// <returns></returns> public Cgw.SmcError.SmcErr StopReceiveVideoByPipe(string cameraNo) { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Trace("Enter: CgwMonitorManageAdapter.StopReceiveVideoByPipe"); Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); try { //if (serviceControl.MonitorServiceRun() && client.State == CommunicationState.Opened) if(serviceControl.MonitorServiceRun()) { client = new MonitorManageServiceClient(); CgwMonitorManageServiceReference.SmcErr serviceErr = client.StopReceiveVideoByPipe(cameraNo); client.Close(); if (serviceErr.ErrNo != Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_SUCCESS) { logEx.Error("CgwMonitorManageAdapter.StopReceiveVideoByPipe failed. ErrNo = {0} ", serviceErr.ErrNo); err = SetCgwErrNo(serviceErr); } else { VideoPipe videoPipe = VideoPipeManage.Instance().DeleteVideoPipe(cameraNo); if (videoPipe != null) { videoPipe.Stop(); logEx.Info("CgwMonitorManageAdapter.StopReceiveVideoByPipe Success. cameraNo = {0} ", cameraNo); } else { logEx.Error("CgwMonitorManageAdapter.StopReceiveVideoByPipe failed. ErrNo = {0} ", serviceErr.ErrNo); } } } else { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); } } catch (System.Exception ex) { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); logEx.Error("CgwMonitorManageServiceReference.StopReceiveVideoByPipe failed. Exception is {0} ", ex.ToString()); logEx.Error("CameraNo:" + cameraNo); } return err; }
/// <summary> /// 根据sessionId获取session /// </summary> /// <param name="sessionId">sessionId</param> /// <param name="sessions">session</param> /// <returns></returns> public SmcErr GetSessionsBySessionId(string sessionId, out CgwSession sessions) { SmcErr err = new SmcErr(); sessions = null; if (rwl.TryEnterReadLock(CgwConst.ENTER_LOCK_WAIT_TIME)) { try { foreach (CgwSession cgwSession in sessionDict.Values) { if (cgwSession.SessionId == sessionId) { sessions = cgwSession; break; } } } finally { rwl.ExitReadLock(); } } return err; }
/// <summary> /// 重发I帧(暂不支持) /// </summary> /// <param name="cameraNo">摄像头编号</param> /// <returns></returns> public Cgw.SmcError.SmcErr MakeIFrame(string cameraNo) { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Trace("Enter: CgwMonitorManageAdapter.MakeIFrame"); Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); //MakeIFrame不存在重发I帧的效果,注销代码 zWX231378 2015/7/14 //try //{ // //if (serviceControl.MonitorServiceRun() && client.State == CommunicationState.Opened) // if(serviceControl.MonitorServiceRun()) // { // client = new MonitorManageServiceClient(); // CgwMonitorManageServiceReference.SmcErr serviceErr = client.MakeIFrame(cameraNo); // client.Close(); // if (serviceErr.ErrNo == Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_SUCCESS) // { // logEx.Info("Cgw MakeIFrame Successful,Current Cgw IP is : {0}", CgwConst.CGWSERVICE_IP_TAG); // } // else // { // logEx.Error("Cgw MakeIFrame failed,ErrNo :{0}", err.ErrNo); // err = SetCgwErrNo(serviceErr); // } // } // else // { // err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); // } //} //catch (System.Exception ex) //{ // err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); // logEx.Error("CgwMonitorManageServiceReference.MakeIFrame failed. Exception is {0} ", ex.ToString()); //} return err; }
/// <summary> /// 预览摄像头视频,使用命名管道方式接收数据 /// </summary> /// <param name="cameraNo"></param> /// <param name="pipeName"></param> /// <returns></returns> public Cgw.SmcError.SmcErr StartReceiveVideoByPipe(string cameraNo, out string pipeName) { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Trace("Enter: CgwMonitorManageAdapter.StartReceiveVideoByPipe"); pipeName = ""; Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); try { //if (serviceControl.MonitorServiceRun() && client.State == CommunicationState.Opened) if (serviceControl.MonitorServiceRun()) { client = new MonitorManageServiceClient(); CgwMonitorManageServiceReference.SmcErr serviceErr = client.StartReceiveVideoByPipe(out pipeName, cameraNo); client.Close(); if (serviceErr.ErrNo != Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_SUCCESS) { logEx.Error("CgwMonitorManageAdapter.StartReceiveVideoByPipe failed. ErrNo = {0} ", serviceErr.ErrNo); err = SetCgwErrNo(serviceErr); } else { //将摄像头通道删除。避免重启服务后,VideoPipe未清除,导致调用停止播放。by zWX231378 2015/7/16 VideoPipe delVideoPipe = VideoPipeManage.Instance().DeleteVideoPipe(cameraNo); if (delVideoPipe != null) { logEx.Info("CgwMonitorManageAdapter.StartReceiveVideoByPipe delete VideoPipe. cameraNo = {0}", cameraNo); delVideoPipe.Stop(); } VideoPipe videoPipe = VideoPipeManage.Instance().AddVideoPipe(cameraNo, pipeName); if (videoPipe != null) { try { videoPipe.Run(); if (videoPipe.HaveConnect) { videoPipe.ReadData(this.dataCallBack); logEx.Info("CgwMonitorManageAdapter.StartReceiveVideoByPipe Success. pipeName = {0} ", pipeName); } else { logEx.Error("CgwMonitorManageAdapter.StartReceiveVideoByPipe failed. cameraNo = {0} ", cameraNo); } } catch (System.Exception ex) { logEx.Error("CgwMonitorManageAdapter.StartReceiveVideoByPipe Exception= {0} ", ex.ToString()); } } else { logEx.Error("CgwMonitorManageAdapter.StartReceiveVideoByPipe failed. cameraNo = {0} ", cameraNo); } } } else { //当监控服务未启动,则关闭管道。 //StopReceiveVideoByPipe(cameraNo); err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); } } catch (System.Exception ex) { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); logEx.Error("CgwMonitorManageServiceReference.StartReceiveVideoByPipe failed. Exception is {0} ", ex.ToString()); } return(err); }
/// <summary> /// 写入日志 /// </summary> /// <param name="level">日志等级</param> /// <param name="err">err</param> private void WriteToLog(LogLevel level, SmcErr err, Exception e, string message, params object[] args) { //暂时先这样处理,保证log2console能够看到异常信息 StringBuilder log = new StringBuilder(); if (null != e) { log.AppendFormat("{0},{1}", e.Message, e.StackTrace); log.AppendLine(); if (null != e.InnerException) { log.AppendFormat("InnerException {0},{1}", e.InnerException.Message, e.InnerException.StackTrace); log.AppendLine(); } } if (null == args || (null != args && args.Length == 0)) { log.Append(message); } else { log.AppendFormat(message, args); } LogEventInfo logEvent = new LogEventInfo(level, this.Log.Name, null, log.ToString(), null, null); if (null != err) { Param = err.GetXmlParamter(); Model = err.GetModelName(); ErrNo = err.ErrNo; } foreach (KeyValuePair<string, object> de in this.Properties) { logEvent.Properties[de.Key] = de.Value; } this.Log.Log(logEvent); //ClearProperties(); }
/// <summary> /// 刷新监控摄像头列表 /// </summary> /// <returns></returns> public Cgw.SmcError.SmcErr RefreshMonitorCamera() { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Trace("Enter: CgwMonitorManageAdapter.RefreshMonitorCamera"); Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); try { //if (serviceControl.MonitorServiceRun() && client.State == CommunicationState.Opened) if(serviceControl.MonitorServiceRun()) { client = new MonitorManageServiceClient(); CgwMonitorManageServiceReference.SmcErr serviceErr = client.RefreshMonitorCamera(); client.Close(); if (serviceErr.ErrNo != Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_SUCCESS) { logEx.Error("CgwMonitorManageAdapter.RefreshMonitorCamera failed. ErrNo = {0} ", serviceErr.ErrNo); err = SetCgwErrNo(serviceErr); } } else { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); } } catch (System.Exception ex) { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); logEx.Error("CgwMonitorManageServiceReference.RefreshMonitorCamera failed. Exception is {0} ", ex.ToString()); } return err; }
/// <summary> /// Error类日志输出。 /// </summary> /// <param name="err">错误码,即信息</param> /// <param name="args">args</param> public void Error(SmcErr err, params object[] args) { if (this.Log.IsErrorEnabled) { this.WriteToLog(LogLevel.Error, err, null, String.Empty, args); } }
/// <summary> /// Error类日志输出。 /// </summary> /// <param name="err">错误码,即信息</param> /// <param name="message">message</param> /// <param name="args">args</param> public void Error(SmcErr err, string message, params object[] args) { if (this.Log.IsErrorEnabled) { this.WriteToLog(LogLevel.Error, err, null, message, args); } }
/// <summary> /// 带异常信息的Debug日志输出。 /// </summary> /// <param name="err">错误码,即信息</param> /// <param name="e">e</param> /// <param name="message">message</param> /// <param name="args">args</param> public void Debug(SmcErr err, Exception e, string message, params object[] args) { if (this.Log.IsDebugEnabled) { this.WriteToLog(LogLevel.Debug, err, e, message, args); } }
/// <summary> /// Error类日志输出。 /// </summary> /// <param name="err">错误码,即信息</param> /// <param name="message">message</param> /// <param name="args">args</param> public void Error(SmcErr err) { if (this.Log.IsErrorEnabled) { this.WriteToLog(LogLevel.Error, err, null, String.Empty, null); } }
/// <summary> /// 添加会话 /// </summary> /// <param name="sessionGuid">会话GuidID</param> /// <param name="smcSession">会话数据</param> /// <returns></returns> public SmcErr AddSession(Guid sessionGuid, CgwSession smcSession) { SmcErr err = new SmcErr(); if (rwl.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME)) { try { if (sessionDict.ContainsKey(sessionGuid)) { sessionDict.Remove(sessionGuid); } sessionDict.Add(sessionGuid, smcSession); } finally { rwl.ExitWriteLock(); } } return err; }
/// <summary> /// 删除会话 /// </summary> /// <param name="sessionGuid">会话Guid</param> /// <returns></returns> public SmcErr RemoveSessionBySessionId(string sessionId) { SmcErr err = new SmcErr(); if (rwl.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME)) { try { foreach (CgwSession cgwSession in sessionDict.Values) { if (cgwSession.SessionId == sessionId) { sessionDict.Remove(cgwSession.SessionGuid); break; } } } finally { rwl.ExitWriteLock(); } } return err; }
/// <summary> /// 删除会话 /// </summary> /// <param name="sessionGuid">会话Guid</param> /// <returns></returns> public SmcErr RemoveSession(Guid sessionGuid) { SmcErr err = new SmcErr(); if (rwl.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME)) { try { CgwSession session; if (sessionDict.TryGetValue(sessionGuid, out session)) { if (session != null) { sessionDict.Remove(sessionGuid); session = null; } } } finally { rwl.ExitWriteLock(); } } return err; }
/// <summary> /// Warn类日志输出。 /// </summary> /// <param name="err">错误码</param> /// <param name="args">参数</param> public void Warn(SmcErr err, params object[] args) { if (this.Log.IsWarnEnabled) { this.WriteToLog(LogLevel.Warn, err, null, String.Empty, args); } }
/// <summary> /// Fatal类(致命)日志输出。 /// </summary> /// <param name="err">错误码,即信息</param> /// <param name="args">args</param> public void Fatal(SmcErr err, params object[] args) { if (this.Log.IsFatalEnabled) { this.WriteToLog(LogLevel.Fatal, err, null, String.Empty, args); } }
/// <summary> /// 带异常信息的Warn类日志输出。 /// </summary> /// <param name="err">错误码,即信息</param> /// <param name="e">e</param> /// <param name="message">message</param> /// <param name="args">args</param> public void Warn(SmcErr err, Exception e, string message, params object[] args) { if (this.Log.IsWarnEnabled) { this.WriteToLog(LogLevel.Warn, err, e, message, args); } }
/// <summary> /// 同步通道会议信息 /// </summary> /// <param name="channelNo">通道号码</param> /// <param name="confNo">会议号</param> private SmcErr SyncChannelConfAccessCode(string channelLabel, string confAccessCode, ChannelControlType controlType) { SmcErr err = new SmcErr(); NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); string oldConfAccessCode = string.Empty; logEx.Trace("SyncChannelConfAccessCode Start. input channelLabel:{0}, ConfAccessCode:{1}, ControlType:{2}.", channelLabel, confAccessCode, controlType); if ((this.monitorChannelRelationDic.ContainsKey(channelLabel) && controlType == ChannelControlType.Add) || (!this.monitorChannelRelationDic.ContainsKey(channelLabel) && controlType != ChannelControlType.Add)) { err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_INPUT_ERROR); logEx.Trace("SyncChannelConfAccessCode input error channelLabel:{0}, ConfAccessCode:{1}, ControlType:{2}.", channelLabel, confAccessCode, controlType); return err; } // 判断是否需要添加通道 if (ChannelControlType.Add == controlType) { // 通道关系字典添加一个通道 this.monitorChannelRelationDic.Add(channelLabel, new MonitorChannelRelation(channelLabel)); // 通道字典添加一个新通道 this.monitorChannelManager.AddChannel(channelLabel); // 判断需要切换的会议号是否为空 if (!string.IsNullOrEmpty(confAccessCode)) { // 添加通道到软终端 this.monitorChannelManager.AddSotChannel(channelLabel, confAccessCode); this.monitorChannelRelationDic[channelLabel].ConfAccessCode = confAccessCode; } logEx.Trace("SyncChannelConfAccessCode add channel:{0} successfully.", channelLabel); } else if (ChannelControlType.None == controlType) { oldConfAccessCode = this.monitorChannelRelationDic[channelLabel].ConfAccessCode; if (string.IsNullOrEmpty(oldConfAccessCode)) // 判断本地通道号码是否入会 { // 判断需要切换的会议号是否为空 if (!string.IsNullOrEmpty(confAccessCode)) { // 添加通道到软终端 this.monitorChannelManager.AddSotChannel(channelLabel, confAccessCode); this.monitorChannelRelationDic[channelLabel].ConfAccessCode = confAccessCode; } } else { // 判断需要切换的会议号是否为空 if (!string.IsNullOrEmpty(confAccessCode)) { if (confAccessCode == oldConfAccessCode) { logEx.Trace("SyncChannelConfAccessCode [oldConfAccessCode:{0},ConfAccessNo:{1}] is same.", oldConfAccessCode, confAccessCode); return err; } // 关闭视频码流 //err = this.SwitchChannelVideo(channelLabel, string.Empty); err = this.StopCameraRtpAudio(channelLabel); if (!err.IsSuccess()) { logEx.Trace("SyncChannelConfAccessCode [oldConfAccessCode:{0},ConfAccessNo:{1}] stoprtp failed.", oldConfAccessCode, confAccessCode); return err; } // 软终端删除该通道 this.monitorChannelManager.RemoveSotChannel(channelLabel); // 软终端重新添加该通道 this.monitorChannelManager.AddSotChannel(channelLabel, confAccessCode); } else { // 关闭视频码流 //err = this.SwitchChannelVideo(channelLabel, string.Empty); err = this.StopCameraRtpAudio(channelLabel); if (!err.IsSuccess()) { logEx.Trace("SyncChannelConfAccessCode [oldConfAccessCode:{0},ConfAccessNo:{1}] stoprtp failed.", oldConfAccessCode, confAccessCode); return err; } // 软终端删除该通道 this.monitorChannelManager.RemoveSotChannel(channelLabel); } this.monitorChannelRelationDic[channelLabel].ConfAccessCode = confAccessCode; } } else { oldConfAccessCode = this.monitorChannelRelationDic[channelLabel].ConfAccessCode; if (!string.IsNullOrEmpty(oldConfAccessCode)) { // 关闭视频码流 //err = this.SwitchChannelVideo(channelLabel, string.Empty); err = this.StopCameraRtpAudio(channelLabel); if (!err.IsSuccess()) { logEx.Trace("SyncChannelConfAccessCode [oldConfAccessCode:{0},ConfAccessNo:{1}] stoprtp failed.", oldConfAccessCode, confAccessCode); return err; } // 软终端删除该通道 this.monitorChannelManager.RemoveSotChannel(channelLabel); this.monitorChannelRelationDic[channelLabel].ConfAccessCode = string.Empty; } // 通道关系字典删除该通道 if (this.monitorChannelRelationDic.ContainsKey(channelLabel)) { this.monitorChannelRelationDic.Remove(channelLabel); } // 通道字典删除该通道 this.monitorChannelManager.RemoveChannel(channelLabel); logEx.Trace("SyncChannelConfAccessCode remove channel:{0} successfully.", channelLabel); } logEx.Trace("SyncChannelConfAccessCode [oldConfAccessCode:{0},ConfAccessNo:{1}] successfully.", oldConfAccessCode, confAccessCode); return err; }
/// <summary> /// 初始化融合网管服务 /// </summary> public void InitService() { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); //初始化监控平台 SmcErr err = new SmcErr(); err = MonitorChannelBll.Instance().LoadMonitor(); if (err.IsSuccess()) { logEx.Trace("Load VideoMonitor Successful !"); } else { logEx.Fatal("Load VideoMonitor Failed, ErrNo : {0}!", err.ErrNo); } }
/// <summary> /// 保存错误描述包括的扩展错误原因 /// </summary> /// <param name="err">错误信息</param> public virtual void AddSmcErrInfo(SmcErr err) { if (null == this.ExternErrs) { this.ExternErrs = new List<SmcErr>(); } if (null != err) { this.ExternErrs.Add(err); } }
/// <summary> /// 获取监控设备列表 /// </summary> /// <param name="CameraInfoList">摄像头基本信息</param> /// <param name="CameraGroupList">组基本信息</param> /// <param name="nodeRelationList">所属分组关系信息</param> /// <returns></returns> public Cgw.SmcError.SmcErr GetAllCameras(Cgw.Common.PlatformType platformType, Common.PageParam pageParam, out List <Cgw.Common.Camera> cameraList, out List <Cgw.Common.CameraGroup> groupList, out List <Cgw.Common.NodeRelation> nodeRelationList, out PagesInfo pageInfo, Cgw.Common.PlatformLicenseInfo licenseInfo = null) { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Trace("Enter: CgwMonitorManageAdapter.GetAllCameras"); cameraList = new List <Cgw.Common.Camera>(); groupList = new List <Common.CameraGroup>(); nodeRelationList = new List <Common.NodeRelation>(); pageInfo = new PagesInfo(); CgwMonitorManageServiceReference.Camera[] cameraListTemp = null; CgwMonitorManageServiceReference.CameraGroup[] groupListTemp = null; CgwMonitorManageServiceReference.NodeRelation[] nodeRelationListTemp = null; CgwMonitorManageServiceReference.PageInfo pagesInfoTemp = null; CgwMonitorManageServiceReference.PlatformLicenseInfo info = new CgwMonitorManageServiceReference.PlatformLicenseInfo(); if (licenseInfo != null) { info.IsEltePlatform = licenseInfo.IsEltePlatform; info.IsMonitorPlatform = licenseInfo.IsMonitorPlatform; } Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); try { //if (client.State == CommunicationState.Opened) if (serviceControl.MonitorServiceRun()) { CgwMonitorManageServiceReference.PlatformType platformTypeTemp = (CgwMonitorManageServiceReference.PlatformType)platformType; CgwMonitorManageServiceReference.PagesParam pageParamTemp = new CgwMonitorManageServiceReference.PagesParam(); pageParamTemp.CurrentPage = pageParam.CurrentPage; pageParamTemp.NumberPerPage = pageParam.NumberPerPage; client = new MonitorManageServiceClient(); CgwMonitorManageServiceReference.SmcErr serviceErr = client.GetAllCameras(out cameraListTemp, out groupListTemp, out nodeRelationListTemp, out pagesInfoTemp, platformTypeTemp, pageParamTemp, info); client.Close(); if (serviceErr.ErrNo != Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_SUCCESS) { logEx.Error("CgwMonitorManageAdapter.GetAllCameras failed. ErrNo = {0} ", serviceErr.ErrNo); err = SetCgwErrNo(serviceErr); } else { if (pagesInfoTemp != null) { pageInfo.CurrentPage = pagesInfoTemp.CurrentPage; pageInfo.TotalPages = pagesInfoTemp.TotalPages; pageInfo.TotalRecords = pagesInfoTemp.TotalRecords; } if (cameraListTemp != null) { foreach (CgwMonitorManageServiceReference.Camera ca in cameraListTemp) { Common.Camera temp = new Common.Camera(ca.No, ca.Name, (Common.CameraStatus)ca.Status); cameraList.Add(temp); } } if (groupListTemp != null) { foreach (CgwMonitorManageServiceReference.CameraGroup cg in groupListTemp) { Common.CameraGroup temp = new Common.CameraGroup(cg.No, cg.Name); groupList.Add(temp); } } if (nodeRelationList != null && nodeRelationListTemp != null) { foreach (CgwMonitorManageServiceReference.NodeRelation no in nodeRelationListTemp) { Common.NodeRelation temp = new Common.NodeRelation(no.No, new List <String>(no.Path), (Common.NodeType)no.Type); nodeRelationList.Add(temp); } } //增加顶层分组 if (string.IsNullOrEmpty(monitorPlatformCameraGroupName)) { monitorPlatformCameraGroupName = "MonitorPlatform"; } if (string.IsNullOrEmpty(eLTEPlatformCameraGroupName)) { eLTEPlatformCameraGroupName = "eLTEPlatform"; } //查询第一页数据时增加顶层分组信息 if (pageParam.CurrentPage == 1) { //if (licenseInfo != null && licenseInfo.IsEltePlatform) if (licenseInfo != null) { groupList.Add(new Common.CameraGroup(eLTEPlatformCameraGroupName, eLTEPlatformCameraGroupName)); } //if (licenseInfo != null && licenseInfo.IsMonitorPlatform) if (licenseInfo != null) { groupList.Add(new Common.CameraGroup(monitorPlatformCameraGroupName, monitorPlatformCameraGroupName)); } } if (nodeRelationList.Count > 0) { List <Common.NodeRelation> nodeRelationTemp = new List <Common.NodeRelation>(nodeRelationList); nodeRelationList.Clear(); foreach (Common.NodeRelation no in nodeRelationTemp) { List <String> path = new List <String>(no.Path); if (path.Count > 1) { //按照从底到顶排序 path.Reverse(); } if (no.No.IndexOf("eLTE") > -1) { path.Add(eLTEPlatformCameraGroupName); } else { path.Add(monitorPlatformCameraGroupName); } if (path.Count > 1) { //按照从顶到底排序 path.Reverse(); } Common.NodeRelation temp = new Common.NodeRelation(no.No, path, (Common.NodeType)no.Type); nodeRelationList.Add(temp); } } if (pageParam.CurrentPage == 1) { //if (licenseInfo != null && licenseInfo.IsEltePlatform) if (licenseInfo != null) { Common.NodeRelation tempELTE = new Common.NodeRelation(eLTEPlatformCameraGroupName, new List <String>(), Common.NodeType.GROUP); nodeRelationList.Add(tempELTE); } //if (licenseInfo != null && licenseInfo.IsMonitorPlatform) if (licenseInfo != null) { Common.NodeRelation tempMonitor = new Common.NodeRelation(monitorPlatformCameraGroupName, new List <String>(), Common.NodeType.GROUP); nodeRelationList.Add(tempMonitor); } } } } else { err.ErrNo = Cgw.SmcError.CgwError.GET_ALL_CAMERAS_FAILED; } } catch (System.Exception ex) { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); logEx.Error("CgwMonitorManageServiceReference.GetAllCameras failed. Exception is {0} ", ex.ToString()); } return(err); }
/// <summary> /// 关闭PTZ操作 /// </summary> /// <param name="Camerano">摄像头</param> /// <returns></returns> public Cgw.SmcError.SmcErr StopControlPtz(string cameraNo, Common.PtzCommandType ptzCommandType) { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Trace("Enter: CgwMonitorManageAdapter.StopControlPtz"); Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); try { //if (serviceControl.MonitorServiceRun() && client.State == CommunicationState.Opened) if(serviceControl.MonitorServiceRun()) { client = new MonitorManageServiceClient(); CgwMonitorManageServiceReference.PtzCommandType ptzCommand = (CgwMonitorManageServiceReference.PtzCommandType)ptzCommandType; //将平台的枚举转换成服务中的枚举 CgwMonitorManageServiceReference.SmcErr serviceErr = client.StopControlPtz(cameraNo, ptzCommand); client.Close(); if (serviceErr.ErrNo != Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_SUCCESS) { logEx.Error("Stop control ptz failed.Camera no:{0},ptzCommandType:{1},Error Code:{2} ", cameraNo, ptzCommand, err.ErrNo); err = SetCgwErrNo(serviceErr); } else { logEx.Info("Stop control ptz success.Camera no:{0},ptzCommandType:{1}.", cameraNo, ptzCommand); } } else { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); } } catch (System.Exception ex) { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); logEx.Error("CgwMonitorManageServiceReference.StopControlPtz failed. Exception is {0} ", ex.ToString()); } return err; }
/// <summary> /// 保存批量操作的错误描述 /// </summary> /// <param name="err">错误信息</param> public virtual void AddMultipleErrs(SmcErr err) { if (null == this.MultipleErrs) { this.MultipleErrs = new List<SmcErr>(); } if (null != err) { SmcErr oldErr = this.MultipleErrs.Find(delegate(SmcErr target) { return target.ErrNo == err.ErrNo; }); if (oldErr != null) { try { if (err.ErrorInfoParam.ParametersDictionary != null && err.ErrorInfoParam.ParametersDictionary.Count > 0) { for (int i = 0; i < err.ErrorInfoParam.ParametersDictionary.Count; i++) { if (err.ErrorInfoParam.ParametersDictionary[i] != null && err.ErrorInfoParam.ParametersDictionary[i].Count > 0) { for (int j = 0; j < err.ErrorInfoParam.ParametersDictionary[i].Count; j++) { if (err.ErrorInfoParam.ParametersDictionary[i][j].Name == oldErr.ErrorInfoParam.ParametersDictionary[i][j].Name && err.ErrorInfoParam.ParametersDictionary[i][j].Value != oldErr.ErrorInfoParam.ParametersDictionary[i][j].Value) { //批量操作错误描述对象如果超过3个则用“...”代替 if (oldErr.ErrorInfoParam.ParametersDictionary[i][j].Value.Split(',').Length < 3) { oldErr.ErrorInfoParam.ParametersDictionary[i][j].Value += ", " + err.ErrorInfoParam.ParametersDictionary[i][j].Value; } else if (oldErr.ErrorInfoParam.ParametersDictionary[i][j].Value.Split(',').Length == 3) { oldErr.ErrorInfoParam.ParametersDictionary[i][j].Value += ", ..."; } } } } } } } catch (Exception) { } } else { this.MultipleErrs.Add(err); } } }
/// <summary> /// Info类日志输出。 /// </summary> /// <param name="err">错误码,即信息</param> /// <param name="message">message</param> /// <param name="args">args</param> public void Info(SmcErr err, string message, params object[] args) { if (this.Log.IsInfoEnabled) { this.WriteToLog(LogLevel.Info, err, null, message, args); } }
/// <summary> /// 设置返回smc的错误码 /// </summary> /// <param name="monitorSmcErr"></param> /// <returns></returns> private Cgw.SmcError.SmcErr SetCgwErrNo(CgwMonitorManageServiceReference.SmcErr monitorSmcErr) { Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); if (monitorSmcErr.ErrNo == Cgw.SmcError.CgwError.ERR_CGW_IS_LOADING || monitorSmcErr.ErrNo == Cgw.SmcError.CgwError.ERR_CGW_BUSINESS_CURRENTSESSION_NULL || monitorSmcErr.ErrNo == Cgw.SmcError.CgwError.ERR_CGW_BUSINESS_SESSION_NULL ) { err.ErrNo = Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING; } else { err.ErrNo = monitorSmcErr.ErrNo; } return err; }
/// <summary> /// 记录操作日志 /// </summary> /// <param name="operateName">操作名称</param> /// <param name="err">错误码</param> public void RecordOperateLog(string operateName, SmcErr err) { if (err.IsSuccess()) { this.Info("{0} Succeed", operateName); } else { this.Error("{0} Failed,ErrNo:{1}", operateName, err.ErrNo); } }
/// <summary> /// 设置扬声器 /// </summary> /// <param name="cameraNo"></param> /// <param name="isOn"></param> /// <returns></returns> public Cgw.SmcError.SmcErr SetSpeaker(string cameraNo, bool isOn) { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Trace("Enter: CgwMonitorManageAdapter.SetSpeaker"); Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); try { //if (serviceControl.MonitorServiceRun() && client.State == CommunicationState.Opened) if(serviceControl.MonitorServiceRun()) { client = new MonitorManageServiceClient(); CgwMonitorManageServiceReference.SmcErr serviceErr = client.SetSpeaker(cameraNo, isOn); client.Close(); if (serviceErr.ErrNo == Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_SUCCESS) { logEx.Info("Cgw SetSpeaker Successful,Current Cgw IP is : {0}", CgwConst.CGWSERVICE_IP_TAG); } else { logEx.Error("Cgw SetSpeaker failed,ErrNo :{0}", err.ErrNo); err = SetCgwErrNo(serviceErr); } } else { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); } } catch (System.Exception ex) { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); logEx.Error("CgwMonitorManageServiceReference.SetSpeaker failed. Exception is {0} ", ex.ToString()); } return err; }
/// <summary> /// 设置摄像头音频状态 /// </summary> /// <param name="channelLabel"></param> /// <param name="cameraNo"></param> /// <param name="isOn"></param> /// <returns></returns> public SmcErr SetMic(string channelLabel, string cameraNo, bool isOn) { SmcErr err = new SmcErr(); NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Info("SetMic start."); try { bool successed = this.monitorChannelRelationDicLocker.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME); // 申请互斥 if (successed) { try { err = this.SetCameraAudio(channelLabel, cameraNo, isOn); if (!err.IsSuccess()) { logEx.Error("SetMic channelLabel={0}, cameraNo={1},isOn={2} failed.", channelLabel, cameraNo, isOn); return err; } } finally { // 释放互斥量 this.monitorChannelRelationDicLocker.ExitWriteLock(); } } else { // 日志 logEx.Error("SetMic: Enert Write Lock Failed.WaitingReadCount:{0};WaitingWriteCount:{1}.", this.monitorChannelRelationDicLocker.WaitingReadCount, this.monitorChannelRelationDicLocker.WaitingWriteCount); err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_GET_LOCK_FAIL); } } catch (Exception ex) { // 日志 logEx.Error(ex, "SetMic: Enert Write Lock Exception."); err.SetErrorNo(CgwError.ERR_CGW_CHANNEL_SERVICE_ADNORMAL); } logEx.Info("SetMic SetMic={0}, cameraNo={1},isOn={2} successfully.", channelLabel, cameraNo, isOn); return err; }
/// <summary> /// Info类日志输出。 /// </summary> /// <param name="err">错误码,即信息</param> /// <param name="message">message</param> /// <param name="args">args</param> public void Info(SmcErr err) { if (this.Log.IsInfoEnabled) { this.WriteToLog(LogLevel.Info, err, null, String.Empty, null); } }
/// <summary> /// Info类日志输出。 /// </summary> /// <param name="err">错误码</param> /// <param name="args">参数</param> public void Info(SmcErr err, params object[] args) { if (this.Log.IsInfoEnabled) { this.WriteToLog(LogLevel.Info, err, null, String.Empty, args); } }
/// <summary> /// 带异常信息的Fatal类日志输出。 /// </summary> /// <param name="err">错误码,即信息</param> /// <param name="e">e</param> /// <param name="message">message</param> /// <param name="args">args</param> public void Fatal(SmcErr err, Exception e, string message, params object[] args) { if (this.Log.IsFatalEnabled) { this.WriteToLog(LogLevel.Fatal, err, e, message, args); } }
/// <summary> /// 预览摄像头视频,使用命名管道方式接收数据 /// </summary> /// <param name="cameraNo"></param> /// <param name="pipeName"></param> /// <returns></returns> public Cgw.SmcError.SmcErr StartReceiveVideoByPipe(string cameraNo, out string pipeName) { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); logEx.Trace("Enter: CgwMonitorManageAdapter.StartReceiveVideoByPipe"); pipeName = ""; Cgw.SmcError.SmcErr err = new Cgw.SmcError.SmcErr(); try { //if (serviceControl.MonitorServiceRun() && client.State == CommunicationState.Opened) if (serviceControl.MonitorServiceRun()) { client = new MonitorManageServiceClient(); CgwMonitorManageServiceReference.SmcErr serviceErr = client.StartReceiveVideoByPipe(out pipeName, cameraNo); client.Close(); if (serviceErr.ErrNo != Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_SUCCESS) { logEx.Error("CgwMonitorManageAdapter.StartReceiveVideoByPipe failed. ErrNo = {0} ", serviceErr.ErrNo); err = SetCgwErrNo(serviceErr); } else { //将摄像头通道删除。避免重启服务后,VideoPipe未清除,导致调用停止播放。by zWX231378 2015/7/16 VideoPipe delVideoPipe = VideoPipeManage.Instance().DeleteVideoPipe(cameraNo); if (delVideoPipe != null) { logEx.Info("CgwMonitorManageAdapter.StartReceiveVideoByPipe delete VideoPipe. cameraNo = {0}", cameraNo); delVideoPipe.Stop(); } VideoPipe videoPipe = VideoPipeManage.Instance().AddVideoPipe(cameraNo, pipeName); if (videoPipe != null) { try { videoPipe.Run(); if (videoPipe.HaveConnect) { videoPipe.ReadData(this.dataCallBack); logEx.Info("CgwMonitorManageAdapter.StartReceiveVideoByPipe Success. pipeName = {0} ", pipeName); } else { logEx.Error("CgwMonitorManageAdapter.StartReceiveVideoByPipe failed. cameraNo = {0} ", cameraNo); } } catch (System.Exception ex) { logEx.Error("CgwMonitorManageAdapter.StartReceiveVideoByPipe Exception= {0} ", ex.ToString()); } } else { logEx.Error("CgwMonitorManageAdapter.StartReceiveVideoByPipe failed. cameraNo = {0} ", cameraNo); } } } else { //当监控服务未启动,则关闭管道。 //StopReceiveVideoByPipe(cameraNo); err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); } } catch (System.Exception ex) { err.SetErrorNo(Cgw.SmcError.CgwError.ERR_MONITOR_MANAGE_SERVICE_RESTARTING); logEx.Error("CgwMonitorManageServiceReference.StartReceiveVideoByPipe failed. Exception is {0} ", ex.ToString()); } return err; }