public void TestExceptionFromPredicatePassed() { using (var testInst = new MonitorObject()) { int result = 0; int state = 0; var task = Task.Run(() => { using (var waiter = testInst.Enter(60000)) { if (waiter.Wait((s) => { if (Volatile.Read(ref state) > 0) { throw new ApplicationException(); } return(false); }, new object())) { Interlocked.Exchange(ref result, 1); } else { Interlocked.Exchange(ref result, 2); } } }); TimingAssert.AreEqual(10000, 1, () => testInst.WaiterCount); Assert.AreEqual(0, Volatile.Read(ref result)); testInst.Pulse(); Thread.Sleep(1); Assert.AreEqual(0, Volatile.Read(ref result)); Interlocked.Increment(ref state); testInst.Pulse(); TimingAssert.AreEqual(10000, 0, () => testInst.WaiterCount); Assert.AreEqual(0, result); try { task.Wait(); } catch (AggregateException aE) { if (aE.InnerExceptions.Count != 1 || !(aE.InnerExceptions[0] is ApplicationException)) { throw; } } } }
private void InitChannelInfos() { mListVoiceChanStateItems.Clear(); for (int i = 0; i < 10; i++) { MonitorObject obj = new MonitorObject(); obj.MonType = MonitorType.State; obj.ObjID = i + 2250000000000000001; obj.ObjType = ConstValue.RESOURCE_VOICECHANNEL; VoiceChanStateItem item = new VoiceChanStateItem(); item.ChanObjID = obj.ObjID; item.MonitorObject = obj; mListVoiceChanStateItems.Add(item); } }
private void DealQueryStateResponse(ReturnMessage retMessage) { try { OperationReturn optReturn; if (retMessage.ListData == null || retMessage.ListData.Count < 2) { CurrentApp.WriteLog("DealQueryState", string.Format("ListData is null or count invalid")); return; } string strMonID = retMessage.ListData[0]; string strState = retMessage.ListData[1]; if (strMonID == mMonitorObject.MonID) { MonitorObject obj = mMonitorObject; optReturn = XMLHelper.DeserializeObject <ChanState>(strState); if (!optReturn.Result) { CurrentApp.WriteLog("DealQueryState", string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return; } ChanState chanState = optReturn.Data as ChanState; if (chanState == null) { CurrentApp.WriteLog("DealQueryState", string.Format("ChannelState object is null")); return; } if (mMonitorItem != null) { if (obj.Role == 1) { mMonitorItem.VoiceChanState = chanState; } if (obj.Role == 2) { mMonitorItem.ScreenChanState = chanState; } mMonitorItem.TimeDeviation = mTimeDeviation; Dispatcher.Invoke(new Action(mMonitorItem.UpdateState)); } } } catch (Exception ex) { ShowException(ex.Message); } }
private void UpdateChanState(MonitorObject monObj, ChanState chanState) { //try //{ // var item = // mListVoiceChanStateItems.FirstOrDefault( // o => o.VoiceID.ToString() == monObj.Other01 && o.ChanID.ToString() == monObj.Name); // if (item != null) // { // item.UpdateInfo(chanState); // } //} //catch (Exception ex) //{ // AppendMessage(string.Format("UpdateChanState fail.\t{0}", ex.Message)); //} }
private void Init() { try { string strTitle = string.Format("{0} —— ", CurrentApp.GetLanguageInfo("2102016", "Screen Monitor")); if (MonitorData != null) { mMonitorItem = MonitorItem.CreateItem(MonitorData); mMonitorItem.CurrentApp = CurrentApp; mMonitorItem.ListUserParams = ListUserParams; mMonitorObject = new MonitorObject(); mMonitorObject.MonType = MonitorType.MonScr; mMonitorObject.ObjID = MonitorData.ObjID; mMonitorObject.ObjType = MonitorData.ObjType; mMonitorObject.ObjValue = MonitorData.Name; mMonitorObject.Role = 2; string strOther03 = MonitorData.Other03; if (!string.IsNullOrEmpty(strOther03)) { string[] arrOther03 = strOther03.Split(new[] { ';' }, StringSplitOptions.None); if (arrOther03.Length > 1) { mMonitorObject.Other03 = arrOther03[1]; } else if (arrOther03.Length > 0) { mMonitorObject.Other03 = arrOther03[0]; } } mMonitorItem.ScreenChanMonObject = mMonitorObject; Dispatcher.Invoke(new Action(mMonitorItem.UpdateState)); DataContext = mMonitorItem; strTitle += mMonitorItem.Name; ImageIcon.SetResourceReference(StyleProperty, string.Format("NMonImageIcon{0}Style", mMonitorItem.ObjType)); InitMonitorClient(); } TxtObjListTitle.Text = strTitle; } catch (Exception ex) { ShowException(ex.Message); } }
/// <summary> /// 更新信息 /// </summary> /// <param name="monObj"></param> public void UpdateInfo(MonitorObject monObj) { int intValue; ChanObjID = monObj.ChanObjID; if (int.TryParse(monObj.Other01, out intValue)) { ChanID = intValue; } if (int.TryParse(monObj.Other02, out intValue)) { ServerID = intValue; } ServerAddress = monObj.Other03; ServerChannel = string.Format("{0} [{1}]", ServerAddress, ChanID); Info = monObj; }
private void DealNMonDataMessage(NotifyMessage notMessage) { try { if (notMessage.ListData == null || notMessage.ListData.Count < 3) { CurrentApp.WriteLog("NMonDataMessage", string.Format("ListData count invalid")); return; } string strMonID = notMessage.ListData[0]; string strLength = notMessage.ListData[1]; string strData = notMessage.ListData[2]; if (strMonID == mMonitorObject.MonID) { MonitorObject monObj = mMonitorObject; int intLength; if (!int.TryParse(strLength, out intLength)) { CurrentApp.WriteLog("NMonDataMessage", string.Format("DataLength invalid")); return; } byte[] tempData = new byte[intLength]; byte[] data = Converter.Hex2Byte(strData); Array.Copy(data, 0, tempData, 0, intLength); if (mNMonCore == null || mNMonCore.User == null) { CurrentApp.WriteLog("NMonDataMessage", string.Format("MonitorObject is null")); return; } var temp = mNMonCore.User as MonitorObject; if (temp == null || temp.ObjID != monObj.ObjID) { CurrentApp.WriteLog("NMonDataMessage", string.Format("MonitorObject invalid")); return; } mNMonCore.ReceiveData(tempData, intLength); } } catch (Exception ex) { CurrentApp.WriteLog("NMonDataMessage", string.Format("Fail.\t{0}", ex.Message)); } }
private void DealNMonAddMonObjectMessage(ReturnMessage retMessage) { try { if (retMessage.ListData.Count < 2) { AppendMessage(string.Format("ReturnMessage param count invalid.")); return; } string strValid = retMessage.ListData[0]; string strTotal = retMessage.ListData[1]; AppendMessage(string.Format("AddMonObjResponse \tValid:{0};Total:{1}", strValid, strTotal)); if (retMessage.ListData.Count < 3) { AppendMessage(string.Format("ReturnMessage param count invalid.")); return; } string strInfo = retMessage.ListData[2]; OperationReturn optReturn; optReturn = XMLHelper.DeserializeObject <MonitorObject>(strInfo); if (!optReturn.Result) { AppendMessage(string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return; } MonitorObject monObj = optReturn.Data as MonitorObject; if (monObj == null) { AppendMessage(string.Format("Fail.\tMonObject is null")); return; } if (mNMonItem == null) { return; } mNMonItem.MonID = monObj.MonID; mNMonItem.MonObject = monObj; StartNMon(); } catch (Exception ex) { AppendMessage(ex.Message); } }
private void DealNMonHeadMessage(NotifyMessage notMessage) { try { if (notMessage.ListData == null || notMessage.ListData.Count < 2) { AppendMessage(string.Format("NotifyMessage param count invalid.")); return; } string strMonID = notMessage.ListData[0]; string strHead = notMessage.ListData[1]; if (mNMonItem == null) { return; } if (mNMonItem.MonID != strMonID) { return; } MonitorObject monObj = mNMonItem.MonObject; if (monObj == null) { return; } byte[] data = Converter.Hex2Byte(strHead); SNM_RESPONSE head = (SNM_RESPONSE)Converter.Bytes2Struct(data, typeof(SNM_RESPONSE)); if (mNMonCore != null) { mNMonCore.StopMon(); mNMonCore = null; } mNMonCore = new NMonCore(monObj); mNMonCore.IsConnectServer = false; mNMonCore.IsDecodeData = false; mNMonCore.Debug += (s, msg) => AppendMessage(string.Format("NMonCore:{0}", msg)); mNMonCore.ReceiveHead(head); } catch (Exception ex) { AppendMessage(ex.Message); } }
/// <summary> /// 创建一个新项目 /// </summary> /// <param name="monObj"></param> /// <returns></returns> public static MonitorObjectItem CreateItem(MonitorObject monObj) { MonitorObjectItem item = new MonitorObjectItem(); item.ObjID = monObj.ObjID; item.ObjType = monObj.ObjType; item.Name = monObj.ObjValue; item.Info = monObj; switch (monObj.ObjType) { case ConstValue.RESOURCE_AGENT: item.Icon = string.Format("Images/00002.png"); break; case ConstValue.RESOURCE_EXTENSION: item.Icon = string.Format("Images/00003.png"); break; } return(item); }
private void DoStopSMonMessage(RequestMessage request) { ReturnMessage retMessage = new ReturnMessage(); retMessage.Result = true; retMessage.SessionID = SessionID; retMessage.Code = 0; try { if (request.ListData == null || request.ListData.Count < 1) { SendErrorMessage(request.Command, Defines.RET_PARAM_INVALID, string.Format("ListData is null or count invalid")); return; } string strMonID = request.ListData[0]; LogDebugMessage(request.Command, string.Format("MonID:{0};", strMonID)); if (mMonType != MonType.MonScr) { SendErrorMessage(request.Command, Defines.RET_CHECK_FAIL, string.Format("MonType invalid.\t{0}", mMonType)); return; } MonitorObject monObj = mListMonObjects.FirstOrDefault(o => o.MonID == strMonID); if (monObj == null) { SendErrorMessage(request.Command, Defines.RET_NOT_EXIST, string.Format("Monitor object not in the monitor list")); return; } retMessage.Command = (int)Service10Command.ResStopSMon; retMessage.ListData.Add(strMonID); SendMessage(retMessage); } catch (Exception ex) { SendErrorMessage(request.Command, Defines.RET_FAIL, ex.Message); } }
private void InitNMon(MonitorObject monObj, NETMON_PARAM param) { try { if (mNMonCore != null) { mNMonCore.StopMon(); mNMonCore = null; } mNMonCore = new NMonCore(monObj); mNMonCore.Debug += (s, msg) => OnDebug(LogMode.Debug, string.Format("{0}\t{1}", s, msg)); mNMonCore.HeadReceived += NMonCore_HeadReceived; mNMonCore.DataReceived += NMonCore_DataReceived; mNMonCore.IsPlayWave = false; mNMonCore.StartMon(param); } catch (Exception ex) { OnDebug(LogMode.Error, string.Format("InitNMon fail.\t{0}", ex.Message)); } }
private void DealNMonHeadMessage(NotifyMessage notMessage) { try { if (notMessage.ListData == null || notMessage.ListData.Count < 2) { CurrentApp.WriteLog("NMonHeadMessage", string.Format("ListData count invalid")); return; } string strMonID = notMessage.ListData[0]; string strHead = notMessage.ListData[1]; if (strMonID == mMonitorObject.MonID) { MonitorObject monObj = mMonitorObject; byte[] data = Converter.Hex2Byte(strHead); SNM_RESPONSE head = (SNM_RESPONSE)Converter.Bytes2Struct(data, typeof(SNM_RESPONSE)); if (mNMonCore != null) { mNMonCore.StopMon(); mNMonCore = null; } mMonitorItem.VoiceFormat = head.format; mMonitorItem.TimeDeviation = mTimeDeviation; mMonitorItem.UpdateState(); mNMonCore = new NMonCore(monObj); mNMonCore.IsConnectServer = false; mNMonCore.IsDecodeData = false; mNMonCore.Debug += (s, msg) => { CurrentApp.WriteLog("NMonCore", msg); }; mNMonCore.ReceiveHead(head); } } catch (Exception ex) { CurrentApp.WriteLog("NMonHeadMessage", string.Format("Fail.\t{0}", ex.Message)); } }
public void TestCancellationWorks() { using (var testInst = new MonitorObject()) { int result = 0; CancellationTokenSource tokenSrc = new CancellationTokenSource(); var task = Task.Run(() => { try { using (var waiter = testInst.Enter(60000, tokenSrc.Token)) { if (waiter.Wait(_ => false, (object)null)) { Interlocked.Exchange(ref result, 1); } else { Interlocked.Exchange(ref result, 2); } } } catch (OperationCanceledException) { Interlocked.Exchange(ref result, 3); } }); testInst.Pulse(); Thread.Sleep(100); Assert.AreEqual(0, Volatile.Read(ref result)); tokenSrc.Cancel(); TimingAssert.AreEqual(10000, 3, () => Volatile.Read(ref result)); } }
/// <summary> /// LevelingQueue constructor /// </summary> /// <param name="highLevelQueue">High level queue (queue with higher priority)</param> /// <param name="lowLevelQueue">Low level queue (queue with lower priority)</param> /// <param name="addingMode">Adding mode of the queue</param> /// <param name="isBackgroundTransferingEnabled">Is background transfering items from LowLevelQueue to HighLevelQueue enabled</param> public LevelingQueue(IQueue <T> highLevelQueue, IQueue <T> lowLevelQueue, LevelingQueueAddingMode addingMode, bool isBackgroundTransferingEnabled) { if (highLevelQueue == null) { throw new ArgumentNullException(nameof(highLevelQueue)); } if (lowLevelQueue == null) { throw new ArgumentNullException(nameof(lowLevelQueue)); } _highLevelQueue = highLevelQueue; _lowLevelQueue = lowLevelQueue; _addingMode = addingMode; _isBackgroundTransferingEnabled = isBackgroundTransferingEnabled; _addMonitor = new MonitorObject("LevelingQueue.AddMonitor"); _takeMonitor = new MonitorObject("LevelingQueue.TakeMonitor"); _peekMonitor = new MonitorObject("LevelingQueue.PeekMonitor"); _itemCount = highLevelQueue.Count + lowLevelQueue.Count; _isDisposed = false; if (isBackgroundTransferingEnabled) { _backgoundTransfererExclusive = new MutuallyExclusivePrimitive(); if (addingMode == LevelingQueueAddingMode.PreferLiveData) { _backgoundTransfererExclusive.AllowBackgroundGate(); // Allow background transfering from the start } _backgroundTransferer = new DelegateThreadSetManager(1, this.GetType().GetCSName() + "_" + this.GetHashCode().ToString() + " Background Transferer", BackgroundTransferProc); _backgroundTransferer.IsBackground = true; _backgroundTransferer.Start(); } }
public static void SendRequest(HTTPRequest_ClientToGateway request) { using (var bus = RabbitHutch.CreateBus("host=localhost;timeout=5")) { try { MonitorObject = new MonitorObject(); MonitorObject.StartMonitoring(); request.Cookie = ClientSession.ClientCookie; #region HTTP command setup #endregion var task = bus.RequestAsync <HTTPRequest_ClientToGateway, HTTPRequest_RetailerToClientGateway>(request); // Each response is handled by a separate task. // the requester can have multiple outstanding requests. task.ContinueWith(response => HandleResponse(response)).Wait(); } catch (AggregateException ex) { Console.WriteLine("Request to server failed."); } } }
public abstract void MonitorEnter(MonitorObject monitorObject);
public void Start(MonitorObject lock1, MonitorObject lock2) { ServerReceiveBufferLock = lock1; ClientReceiveBufferLock = lock2; }
public abstract void MonitorExit(MonitorObject monitorObject);
private void DoStartSMonMessage(RequestMessage request) { ReturnMessage retMessage = new ReturnMessage(); retMessage.Result = true; retMessage.SessionID = SessionID; retMessage.Code = 0; try { if (request.ListData == null || request.ListData.Count < 1) { SendErrorMessage(request.Command, Defines.RET_PARAM_INVALID, string.Format("ListData is null or count invalid")); return; } string strMonID = request.ListData[0]; LogDebugMessage(request.Command, string.Format("MonID:{0};", strMonID)); if (mMonType != MonType.MonScr) { SendErrorMessage(request.Command, Defines.RET_CHECK_FAIL, string.Format("MonType invalid.\t{0}", mMonType)); return; } MonitorObject monObj = mListMonObjects.FirstOrDefault(o => o.MonID == strMonID); if (monObj == null) { SendErrorMessage(request.Command, Defines.RET_NOT_EXIST, string.Format("Monitor object not in the monitor list")); return; } string strExt = monObj.Name; if (ListExtensionInfos == null) { SendErrorMessage(request.Command, Defines.RET_OBJECT_NULL, string.Format("ListExtensionInfos is null")); return; } var extInfo = ListExtensionInfos.FirstOrDefault(e => e.Extension == strExt); if (extInfo == null) { SendErrorMessage(request.Command, Defines.RET_NOT_EXIST, string.Format("ExtInfo not exist.\t{0}", strExt)); return; } if (ListResourceInfos == null) { SendErrorMessage(request.Command, Defines.RET_OBJECT_NULL, string.Format("ListResourceInfos is null")); return; } ScreenChanInfo chanInfo = null; for (int i = 0; i < ListResourceInfos.Count; i++) { var resource = ListResourceInfos[i]; chanInfo = resource as ScreenChanInfo; if (chanInfo == null) { continue; } if (chanInfo.Extension != strExt) { continue; } break; } if (chanInfo == null) { SendErrorMessage(request.Command, Defines.RET_NOT_EXIST, string.Format("ScreenChanInfo not exist.\t{0}", strExt)); return; } int chanID = chanInfo.ID; long screenObjID = chanInfo.ParentObjID; var screenInfo = ListResourceInfos.FirstOrDefault(r => r.ObjID == screenObjID) as ScreenServerInfo; if (screenInfo == null) { SendErrorMessage(request.Command, Defines.RET_NOT_EXIST, string.Format("ScreenInfo not exist.\t{0}", screenObjID)); return; } int monPort = screenInfo.MonPort; string address = screenInfo.HostAddress; retMessage.Command = (int)Service10Command.ResStartSMon; retMessage.ListData.Add(strMonID); retMessage.ListData.Add(monPort.ToString()); retMessage.ListData.Add(address); retMessage.ListData.Add(chanID.ToString()); SendMessage(retMessage); } catch (Exception ex) { SendErrorMessage(request.Command, Defines.RET_FAIL, ex.Message); } }
private void DoAddMonObjectMessage(RequestMessage request) { ReturnMessage retMessage = new ReturnMessage(); retMessage.Result = true; retMessage.SessionID = SessionID; retMessage.Code = 0; try { OperationReturn optReturn; if (request.ListData == null || request.ListData.Count < 2) { SendErrorMessage(request.Command, Defines.RET_PARAM_INVALID, string.Format("ListData is null or count invalid")); return; } string strMethod = request.ListData[0]; string strCount = request.ListData[1]; LogDebugMessage(request.Command, string.Format("Method:{0};Count:{1}", strMethod, strCount)); int intMethod; if (!int.TryParse(strMethod, out intMethod) || intMethod < 0) { SendErrorMessage(request.Command, Defines.RET_PARAM_INVALID, string.Format("Method invalid.\t{0}", strMethod)); return; } int intCount; if (!int.TryParse(strCount, out intCount) || intCount < 0) { SendErrorMessage(request.Command, Defines.RET_PARAM_INVALID, string.Format("Count invalid.\t{0}", strCount)); return; } if (request.ListData.Count < 2 + intCount) { SendErrorMessage(request.Command, Defines.RET_PARAM_INVALID, string.Format("Ext count invalid.")); return; } List <MonitorObject> listObjs = new List <MonitorObject>(); for (int i = 0; i < intCount; i++) { string strExt = request.ListData[i + 2]; if (intMethod == 0) { var temp = mListMonObjects.FirstOrDefault(m => m.Name == strExt); if (temp == null) { MonitorObject obj = new MonitorObject(); obj.MonID = Guid.NewGuid().ToString(); obj.Name = strExt; mListMonObjects.Add(obj); listObjs.Add(obj); } } } int validCount = listObjs.Count; int totalCount = mListMonObjects.Count; retMessage.Command = (int)Service10Command.ResAddMonObj; retMessage.ListData.Add(validCount.ToString()); retMessage.ListData.Add(totalCount.ToString()); for (int i = 0; i < validCount; i++) { optReturn = XMLHelper.SeriallizeObject(listObjs[i]); if (!optReturn.Result) { SendErrorMessage(request.Command, optReturn); return; } retMessage.ListData.Add(optReturn.Data.ToString()); } SendMessage(retMessage); } catch (Exception ex) { SendErrorMessage(request.Command, Defines.RET_FAIL, ex.Message); } }
private void DealStartSMonResponse(ReturnMessage retMessage) { try { if (retMessage.ListData == null || retMessage.ListData.Count < 2) { CurrentApp.WriteLog("StartSMonResponse", string.Format("ListData count invalid")); return; } string strMonID = retMessage.ListData[0]; string strMonPort = retMessage.ListData[1]; if (strMonID == mMonitorObject.MonID) { MonitorObject monObj = mMonitorObject; int intMonPort; if (!int.TryParse(strMonPort, out intMonPort)) { CurrentApp.WriteLog("StartSMonResponse", string.Format("Monitor port invalid")); return; } string strHost = monObj.Other03; //录屏服务器的地址 string strChanID = monObj.Other01; int intChanID; if (!int.TryParse(strChanID, out intChanID)) { CurrentApp.WriteLog("StartSMonResponse", string.Format("Channel ID invalid")); return; } OperationReturn optReturn = Utils.DownloadMediaUtils(CurrentApp.Session); if (!optReturn.Result) { CurrentApp.WriteLog("StartSMonResponse", string.Format("DownloadMediaUtil fail.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return; } //获取本窗口的句柄 int handle = 0; HwndSource hwndSource = HwndSource.FromVisual(this) as HwndSource; if (hwndSource != null) { //hwndSource.AddHook(WndProc); handle = hwndSource.Handle.ToInt32(); } int intReturn; //设置反馈进度的频率 intReturn = ScreenMPInterop.VLSMonSetWaterMark(1); CurrentApp.WriteLog("StartSMonResponse", string.Format("VLSMonSetWaterMarkReturn:{0}", intReturn)); //设置窗口尺寸 int intScale = 100; if (ListUserParams != null) { var userParam = ListUserParams.FirstOrDefault(p => p.ParamID == S2102Consts.UP_PLAYSCREEN_SCALE); if (userParam != null) { int temp; if (int.TryParse(userParam.ParamValue, out temp)) { if (temp > 0 && temp <= 100) { intScale = temp; } } } } intReturn = ScreenMPInterop.VLSMonSetScale(intScale); CurrentApp.WriteLog("StartSMonResponse", string.Format("VLSMonSetScaleReturn:{0}", intReturn)); SRCMON_PARAM param = new SRCMON_PARAM(); param.sVocIp = Converter.String2ByteArray(strHost, ScreenMPDefines.SIZE_IPADDRESS); param.nPort = (ushort)intMonPort; param.nChannel = (ushort)intChanID; intReturn = ScreenMPInterop.VLSMonStart(ref param, null, handle); CurrentApp.WriteLog("StartSMonResponse", string.Format("VLSMonStartReturn:{0}", intReturn)); if (intReturn == 0) { mIsScrWinOpened = true; IntPtr hwdPlayer = ScreenMPInterop.VLSMonGetPlayerHwnd(); //窗口置顶 if (ListUserParams != null) { var userParam = ListUserParams.FirstOrDefault(p => p.ParamID == S2102Consts.UP_PLAYSCREEN_TOPMOST); if (userParam != null && userParam.ParamValue == "1" && hwdPlayer != IntPtr.Zero) { intReturn = User32Interop.SetWindowPos(hwdPlayer, -1, 0, 0, 0, 0, 3); CurrentApp.WriteLog("StartSMonResponse", string.Format("SetWindowPos:{0}", intReturn)); } } } } } catch (Exception ex) { CurrentApp.WriteLog("StartSMonResponse", string.Format("Fail.\t{0}", ex.Message)); } }
void MonitorClient_ReturnMessageReceived(ReturnMessage retMessage) { try { if (!retMessage.Result) { AppendMessage(string.Format("Fail.\t{0}\t{1}\t{2}", retMessage.Command, retMessage.Code, retMessage.Message)); return; } switch (retMessage.Command) { case (int)RequestCode.NCWelcome: SetMonType(); break; case (int)Service04Command.ResSetMonType: AppendMessage(string.Format("End.\t{0}\t{1}", retMessage.Command, retMessage.ListData[0])); AddMonObj(); break; case (int)Service04Command.ResAddMonObj: AppendMessage(string.Format("End.\t{0}\t{1}\t{2}", retMessage.Command, retMessage.ListData[0], retMessage.ListData[1])); QueryChanInfo(); break; case (int)Service04Command.ResQueryChan: AppendMessage(string.Format("End.\t{0}\t{1}", retMessage.Command, retMessage.ListData[0])); int count; if (int.TryParse(retMessage.ListData[0], out count)) { for (int i = 0; i < count; i++) { string str = retMessage.ListData[i + 1]; OperationReturn optReturn = XMLHelper.DeserializeObject <MonitorObject>(str); if (!optReturn.Result) { AppendMessage(string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return; } MonitorObject obj = optReturn.Data as MonitorObject; if (obj == null) { AppendMessage(string.Format("MonitorObject is null")); return; } var temp = mListVoiceChanStateItems.FirstOrDefault(c => c.MonitorObject.ObjID == obj.ObjID); if (temp != null) { temp.MonitorObject.ChanObjID = obj.ChanObjID; temp.ChanObjID = obj.ChanObjID; } } } QueryChanState(); break; case (int)Service04Command.ResQueryState: AppendMessage(string.Format("End.\t{0}\t{1}\t{2}", retMessage.Command, retMessage.ListData[0], retMessage.ListData[1])); break; } } catch (Exception ex) { AppendMessage(string.Format("DealMessage fail.\t{0}", ex.Message)); } }
/// <summary> /// 解包MAP层协议数据包 /// </summary> /// <param name="mapData"></param> /// <param name="mapLayer"></param> /// <returns></returns> private static CmccUnpacketResult UnpacketMapLayer(byte[] mapData, ref MapLayer mapLayer) { if (mapData.Length <= 2) { if (mapData.Length == 2) { mapLayer.objects = null; } else { return CmccUnpacketResult.OtherError; } } int offset = 0; mapLayer.commandId = mapData[offset++]; mapLayer.ackFlag = mapData[offset++]; byte OL = 0; List<MonitorObject> list = new List<MonitorObject>(); while ((offset + 1) <= mapData.Length) { MonitorObject mo = new MonitorObject(); OL = mapData[offset++]; if (OL < 3) { return CmccUnpacketResult.OtherError; } if ((offset + 2) <= mapData.Length) { mo.Moid = BitConverter.ToUInt16(mapData, offset); offset += 2; } else { return CmccUnpacketResult.OtherError; } if ((offset + (OL - 3)) <= mapData.Length) { if ((OL - 3) > 0) { mo.Data = new byte[OL - 3]; Array.Copy(mapData, offset, mo.Data, 0, mo.Length); } else { mo.Data = null; } offset += (OL - 3); } else { return CmccUnpacketResult.OtherError; } list.Add(mo); } mapLayer.objects = list.ToArray(); return CmccUnpacketResult.Succeed; }
/// <summary> /// DiskQueue constructor /// </summary> /// <param name="path">Path to the folder on the disk to store queue segments</param> /// <param name="segmentFactory">Factory to create DiskQueueSegments</param> /// <param name="maxSegmentCount">Maximum number of simultaniously active segments</param> /// <param name="backgroundCompaction">Is background compaction allowed (if not then compaction happens synchronously within the Take operation)</param> /// <param name="compactionPeriod">Compaction period in milliseconds</param> internal DiskQueue(string path, DiskQueueSegmentFactory <T> segmentFactory, int maxSegmentCount, bool backgroundCompaction, int compactionPeriod) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } if (segmentFactory == null) { throw new ArgumentNullException(nameof(segmentFactory)); } if (compactionPeriod <= 0) { throw new ArgumentOutOfRangeException(nameof(compactionPeriod), "Compaction period should be positive"); } if (maxSegmentCount == 0 || maxSegmentCount == 1) { throw new ArgumentOutOfRangeException(nameof(maxSegmentCount), "At least two segments should be available"); } if (maxSegmentCount > int.MaxValue / 4) { throw new ArgumentOutOfRangeException(nameof(maxSegmentCount), "Segment count is too large"); } if (maxSegmentCount <= 0 || maxSegmentCount > int.MaxValue / 4) { maxSegmentCount = int.MaxValue / 4; } _addMonitor = new MonitorObject("DiskQueue.AddMonitor"); _takeMonitor = new MonitorObject("DiskQueue.TakeMonitor"); _peekMonitor = new MonitorObject("DiskQueue.PeekMonitor"); _segmentFactory = segmentFactory; _segmentOperationsLock = new object(); _maxSegmentCount = maxSegmentCount; _segmentsPath = path; _itemCount = 0; _boundedCapacity = -1; if (_segmentFactory.SegmentCapacity > 0) { _boundedCapacity = (long)_segmentFactory.SegmentCapacity * maxSegmentCount; } _nonFairItemThreshold = Environment.ProcessorCount; _nonFairSegmentThreshold = _segmentFactory.SegmentCapacity > 0 ? Math.Max(1, (8 * Environment.ProcessorCount) / _segmentFactory.SegmentCapacity) : 16; var discoveredSegments = segmentFactory.DiscoverSegmentsWrapped(path); _segments = new CircularList <DiskQueueSegmentWrapper <T> >(discoveredSegments.OrderBy(o => o.Number)); if (_segments.Count > 0) { for (int i = 0; i < _segments.Count; i++) { if (i + 1 < _segments.Count) { _segments[i].NextSegment = _segments[i + 1]; // Build linked-list if (_segments[i].Number == _segments[i + 1].Number) { throw new InvalidOperationException("DiscoverSegments returned duplicated segment numbers"); } } _itemCount += _segments[i].Count; } _headSegment = _segments[0]; _tailSegment = _segments[_segments.Count - 1]; _lastSegmentNumber = _tailSegment.Number; if (_tailSegment.IsFull) { // Allocate new segment when tail is Full (prevent write modifications of segments from previous run) var newTailSegment = segmentFactory.CreateSegmentWrapped(path, ++_lastSegmentNumber); _tailSegment.NextSegment = newTailSegment; _tailSegment = newTailSegment; _segments.Add(newTailSegment); } } else { // Allocate new segment _headSegment = _tailSegment = segmentFactory.CreateSegmentWrapped(path, ++_lastSegmentNumber); _segments.Add(_tailSegment); } _compactionPeriod = compactionPeriod; if (backgroundCompaction) { _backgroundCompactionThread = new DelegateThreadSetManager(1, this.GetType().GetCSName() + "_" + this.GetHashCode().ToString() + " Background compaction", BackgroundCompactionProc); _backgroundCompactionThread.IsBackground = true; _backgroundCompactionThread.Start(); } _isDisposed = false; }
private void DealAddMonObjectMessage(ReturnMessage retMessage) { try { if (retMessage.ListData.Count < 2) { AppendMessage(string.Format("ReturnMessage param count invalid.")); return; } string strValid = retMessage.ListData[0]; string strTotal = retMessage.ListData[1]; AppendMessage(string.Format("AddMonObjResponse \tValid:{0};Total:{1}", strValid, strTotal)); int valid; if (!int.TryParse(strValid, out valid) || valid < 0) { AppendMessage(string.Format("Valid count invalid.\t{0}", strValid)); return; } if (retMessage.ListData.Count < 2 + valid) { AppendMessage(string.Format("MonObject count invalid.")); return; } List <string> listMonIDs = new List <string>(); OperationReturn optReturn; for (int i = 0; i < valid; i++) { string strInfo = retMessage.ListData[i + 2]; optReturn = XMLHelper.DeserializeObject <MonitorObject>(strInfo); if (!optReturn.Result) { AppendMessage(string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message)); return; } MonitorObject monObj = optReturn.Data as MonitorObject; if (monObj == null) { AppendMessage(string.Format("Fail.\tMonObject is null")); return; } var temp = mListMonitorObjects.FirstOrDefault(m => m.MonID == monObj.MonID); if (temp == null) { mListMonitorObjects.Add(monObj); } var item = mListExtStateItems.FirstOrDefault(e => e.Extension == monObj.Name); if (item != null) { item.MonID = monObj.MonID; item.MonObject = monObj; } listMonIDs.Add(monObj.MonID); } QueryExtState(listMonIDs); } catch (Exception ex) { AppendMessage(ex.Message); } }
private void DoStartNMonMessage(RequestMessage request) { ReturnMessage retMessage = new ReturnMessage(); retMessage.Result = true; retMessage.SessionID = SessionID; retMessage.Code = 0; try { if (request.ListData == null || request.ListData.Count < 1) { SendErrorMessage(request.Command, Defines.RET_PARAM_INVALID, string.Format("ListData is null or count invalid")); return; } string strMonID = request.ListData[0]; LogDebugMessage(request.Command, string.Format("MonID:{0};", strMonID)); if (mMonType != MonType.NMon) { SendErrorMessage(request.Command, Defines.RET_CHECK_FAIL, string.Format("MonType invalid.\t{0}", mMonType)); return; } MonitorObject monObj = mListMonObjects.FirstOrDefault(o => o.MonID == strMonID); if (monObj == null) { SendErrorMessage(request.Command, Defines.RET_NOT_EXIST, string.Format("Monitor object not in the monitor list")); return; } string strExt = monObj.Name; if (ListExtensionInfos == null) { SendErrorMessage(request.Command, Defines.RET_OBJECT_NULL, string.Format("ListExtensionInfos is null")); return; } var extInfo = ListExtensionInfos.FirstOrDefault(e => e.Extension == strExt); if (extInfo == null) { SendErrorMessage(request.Command, Defines.RET_NOT_EXIST, string.Format("ExtInfo not exist.\t{0}", strExt)); return; } if (ListResourceInfos == null) { SendErrorMessage(request.Command, Defines.RET_OBJECT_NULL, string.Format("ListResourceInfos is null")); return; } VoiceChanInfo chanInfo = null; for (int i = 0; i < ListResourceInfos.Count; i++) { var resource = ListResourceInfos[i]; chanInfo = resource as VoiceChanInfo; if (chanInfo == null) { continue; } if (chanInfo.Extension != strExt) { continue; } break; } if (chanInfo == null) { SendErrorMessage(request.Command, Defines.RET_NOT_EXIST, string.Format("VoiceChanInfo not exist.\t{0}", strExt)); return; } int chanID = chanInfo.ID; long voiceObjID = chanInfo.ParentObjID; var voiceInfo = ListResourceInfos.FirstOrDefault(r => r.ObjID == voiceObjID) as VoiceServerInfo; if (voiceInfo == null) { SendErrorMessage(request.Command, Defines.RET_NOT_EXIST, string.Format("VoiceInfo not exist.\t{0}", voiceObjID)); return; } int monPort = voiceInfo.NMonPort; string address = voiceInfo.HostAddress; bool isTransAudioData = true; if (ConfigInfo != null) { var setting = ConfigInfo.ListSettings.FirstOrDefault(s => s.Key == Service10Consts.GS_KEY_S10_TRANSAUDIODATA); if (setting != null) { if (setting.Value == "0") { isTransAudioData = false; } } } retMessage.Command = (int)Service10Command.ResStartNMon; retMessage.ListData.Add(strMonID); retMessage.ListData.Add(monPort.ToString()); retMessage.ListData.Add(isTransAudioData ? "1" : "0"); retMessage.ListData.Add(address); retMessage.ListData.Add(chanID.ToString()); SendMessage(retMessage); if (isTransAudioData) { //启动NMonCore进行网络监听 NETMON_PARAM param = new NETMON_PARAM(); param.Host = voiceInfo.HostAddress; param.Port = voiceInfo.NMonPort; param.Channel = chanID; InitNMon(monObj, param); } } catch (Exception ex) { SendErrorMessage(request.Command, Defines.RET_FAIL, ex.Message); } }
public override void MonitorExit(MonitorObject monitorObject) { System.Threading.Monitor.Exit(monitorObject); }