/// <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> 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="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> /// <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> /// 线程Unload cgw /// </summary> /// <returns></returns> public SmcErr StopAllStream() { SmcErr err = new SmcErr(); NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); //Stop VideoData err = MonitorChannelBll.Instance().StopAllStream(); if (err.IsSuccess()) { logEx.Info("UnLoad CgwService Successful !"); } else { logEx.Fatal("UnLoad CgwService Failed, ErrNo : {0}!", err.ErrNo); } return err; }
/// <summary> /// 线程加载cgw /// </summary> /// <returns></returns> public SmcErr Load() { SmcErr err = new SmcErr(); NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); //初始化监控平台 err = MonitorChannelBll.Instance().Load(); if (err.IsSuccess()) { logEx.Trace("Load CgwService Successful !"); isLoadSuccess = true; } else { logEx.Fatal("Load CgwService Failed, ErrNo : {0}!", err.ErrNo); } return err; }
/// <summary> /// Disconnect monitorPlat /// </summary> /// <returns></returns> public Cgw.SmcError.SmcErr DisconnectMonitor() { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); SmcErr err = new SmcErr(); err = MonitorChannelBll.Instance().Disconnect(); if (err.IsSuccess()) { logEx.Info("CgwService.Disconnect Successful !"); } return err; }
/// <summary> /// 线程加载监控平台 /// </summary> private static void LoadMonitorTimer_Elapsed() { NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); System.Threading.Thread.Sleep(1000); SmcErr smcErr = new SmcErr(); try { smcErr = CgwService.Instance().Load(); if (false == smcErr.IsSuccess()) { logEx.Error("CGW service Start failed! Errno :{0}", smcErr.ErrNo); NLog.LogManager.Flush(); System.Diagnostics.Process.GetCurrentProcess().Kill(); } else { logEx.Info("CGW service Start Success"); } } catch (Exception ex) { logEx.Fatal(ex, "CGW service LoadMonitor Failed!"); NLog.LogManager.Flush(); } }
static void Main(string[] args) { SmcErr smcErr = new SmcErr(); NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log); try { logEx.Info("Enter: Start Cgw Service"); CgwServiceInit cgwService = new CgwServiceInit(); smcErr = CgwService.Instance().InitService(); if (smcErr.IsSuccess()) { cgwService.InitServiceInfo(); string LocalServiceStartMode = CommonFunction.GetAppSetting("LocalServiceStartMode"); if (string.IsNullOrEmpty(LocalServiceStartMode)) { LocalServiceStartMode = "1"; } CgwService.Instance().LicenseInit(); Thread dbConnectionThread = new Thread(new ThreadStart(LoadMonitorTimer_Elapsed)); dbConnectionThread.Start(); ServiceRun.StarUpService(LocalServiceStartMode, "HUAWEI SMC 2.0 ConvergeGateway", cgwService); //logEx.Info("CGW service Start Successful!"); } else { logEx.Error("CGW service Start failed! Errno :{0}", smcErr.ErrNo); NLog.LogManager.Flush(); System.Diagnostics.Process.GetCurrentProcess().Kill(); } } catch (System.Exception e) { logEx.Fatal(e, "CGW service Start Failed!"); NLog.LogManager.Flush(); } }