/// <summary> /// 处理接收的数据 /// </summary> void DealReceive() { while (m_IsReceived) { if (m_ReceiveQueue.IsEmpty) { Thread.Sleep(50); continue; } string message = null; m_Logger.Debug("开始处理接收的数据。"); if (m_ReceiveQueue.TryDequeue(out message)) { ServiceCommand requestMessage = new ServiceCommand(); requestMessage.CommandStringToClass(message); m_Logger.Debug("解析接收数据成功。"); if (MessageReceived != null && requestMessage != null && !string.IsNullOrEmpty(requestMessage.Guid)) { MessageReceived(requestMessage); } } m_Logger.Debug("处理接收的数据结束。"); Thread.Sleep(50); } }
/// <summary> /// 接收队列中的消息 /// </summary> protected void QueueReceive() { m_PipeServer.WaitForConnection(); while (m_IsReceived) { if (!m_PipeServer.IsConnected) { Thread.Sleep(50); continue; } ServiceCommand msg = new ServiceCommand(); using (StreamReader sr = new StreamReader(m_PipeServer)) { msg.CommandStringToClass(sr.ReadLine()); } if (msg == null || string.IsNullOrEmpty(msg.Guid)) { continue; } m_ReceiveCommandCaches.AddResult(msg.Guid, msg); if (MessageReceived != null) { // 事件不为为空时 if (MessageReceived != null) { MessageReceived(msg); } } Thread.Sleep(50); } }
public bool SendByteResult(byte[] bytResult) { byte[] temp = CompressHelper.DeCompress(EnumCompressType.MemCompress, bytResult); string result = ConvertUtility.CodingToString(temp, 2); //result = result.Replace("\n", "\r\n"); if (string.IsNullOrEmpty(result)) { return(false); } ServiceCommand command = new ServiceCommand(); command.CommandStringToClass(result, false); if (command == null || string.IsNullOrEmpty(command.Guid)) { return(false); } return (Singleton <ResultCacheManager <string> > .Instance.AddResult(command.Guid, command.EntityXmlContent)); }
/// <summary> /// 消息处理 /// </summary> /// <param name="m">消息</param> protected override void DefWndProc(ref Message m) { if (m.Msg == WM_COPYDATA) { try { COPYDATASTRUCT mystr = new COPYDATASTRUCT(); mystr = (COPYDATASTRUCT)Marshal.PtrToStructure(m.LParam, typeof(COPYDATASTRUCT)); if (mystr.cbData > 0) { int nLength = mystr.cbData / 2; string str = Marshal.PtrToStringUni(mystr.lpData, nLength); if (str.Length > nLength) { str = str.Substring(0, nLength); } ServiceCommand requestMessage = new ServiceCommand(); requestMessage.CommandStringToClass(str); ReceiveMessage(requestMessage); } } catch (Exception ex) { m_Logger.Fatal(this.GetType().Name, ex); } } else { base.DefWndProc(ref m); } }
public bool SendResult(string result) { result = result.Replace("\n", "\r\n"); if (string.IsNullOrEmpty(result)) { return(false); } ServiceCommand command = new ServiceCommand(); command.CommandStringToClass(result); if (command == null || string.IsNullOrEmpty(command.Guid)) { return(false); } return (Singleton <ResultCacheManager <string> > .Instance.AddResult(command.Guid, command.EntityXmlContent)); }
/// <summary> /// 接收队列中的消息 /// </summary> protected void QueueReceive() { while (m_IsReceived) { if (!m_PipeClient.IsConnected) { m_PipeClient.Connect(); Thread.Sleep(50); continue; } StringBuilder sb = new StringBuilder(); using (StreamReader sr = new StreamReader(m_PipeClient)) { int length = 0; if (int.TryParse(sr.ReadLine(), out length)) { for (int i = 0; i < length; i++) { sb.Append(sr.ReadLine()); } } if (sb.Length > 0) { ServiceCommand msg = new ServiceCommand(); msg.CommandStringToClass(sb.ToString()); //m_ReceiveCommandCaches.AddResult(msg.Guid, msg); //m_SendCommandCaches.RemoveResult(msg.Guid); // 事件不为为空时 //if (MessageReceived != null && msg != null) // MessageReceived(msg); } } Thread.Sleep(50); } }