Exemple #1
0
        /// <summary>
        /// 发送队列中的消息
        /// </summary>
        protected void QueueSend()
        {
            while (m_IsSend)
            {
                if (m_SendQueue.IsEmpty)
                {
                    Thread.Sleep(50);
                    continue;
                }

                m_Logger.Debug("开始发送请求");
                ServiceCommand msg = null;
                if (m_SendQueue.TryPeek(out msg))
                {
                    if (!m_MSMQ.CanWrite)
                    {
                        continue;
                    }

                    m_MSMQ.Send(msg.ClassToCommandString());
                    m_SendQueue.TryDequeue(out msg);
                }
                m_Logger.Debug("发送请求结束");

                Thread.Sleep(50);
            }
        }
        /// <summary>
        /// 发送队列中的消息
        /// </summary>
        protected void QueueSend()
        {
            while (m_IsSend)
            {
                if (m_SendQueue.IsEmpty)
                {
                    Thread.Sleep(50);
                    continue;
                }

                ServiceCommand msg = null;
                if (m_SendQueue.TryPeek(out msg))
                {
                    if (!m_PipeClient.IsConnected)
                    {
                        m_PipeClient.Connect();
                    }

                    using (StreamWriter sw = new StreamWriter(m_PipeClient))
                    {
                        sw.AutoFlush = true;
                        sw.WriteLine(msg.ClassToCommandString());
                    }
                    m_SendQueue.TryDequeue(out msg);
                }

                Thread.Sleep(50);
            }
        }
Exemple #3
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="message">消息</param>
        public void SendMessage(ServiceCommand message)
        {
            try
            {
                m_Logger.Debug("开始发送的消息。");
                int WINDOW_HANDLER = 0;
                message.SendId = m_HostID;

                string content = message.ClassToCommandString();
                m_Logger.Debug("发送的消息为:" + content);
                m_Logger.Debug("目标窗体ID:" + message.ReceiveId);
                WINDOW_HANDLER = FindWindow(null, message.ReceiveId);
                m_Logger.Debug("目标窗体句柄:" + WINDOW_HANDLER);
                if (WINDOW_HANDLER != 0)
                {
                    IntPtr         ptr   = Marshal.StringToHGlobalUni(content);
                    COPYDATASTRUCT mystr = new COPYDATASTRUCT();
                    mystr.dwData = (IntPtr)59;
                    mystr.cbData = content.Length * 2;
                    mystr.lpData = ptr;
                    SendMessage(WINDOW_HANDLER, WM_COPYDATA, 0, ref mystr);
                    Marshal.FreeHGlobal(ptr);
                }
                m_Logger.Debug("发送的消息结束。");
            }
            catch (Exception ex)
            {
                m_Logger.Fatal(this.GetType().Name, ex);
            }
        }
        /// <summary>
        /// 处理结收到结果信息
        /// </summary>
        private void DealResult()
        {
            while (true)
            {
                if (!m_IsLoadService)
                {
                    continue;
                }

                try
                {
                    string         resultId       = "";
                    ResponseEntity responseEntity = Singleton <ResultCacheManager <ResponseEntity> > .Instance
                                                    .GetOneResult(out resultId);

                    if (!string.IsNullOrEmpty(resultId) && responseEntity != null)
                    {
                        ServiceCommand resultCommand = new ServiceCommand();
                        ServiceCommand command       = m_ReceiveCommandCaches.GetResult(resultId);
                        if (command == null)
                        {
                            continue;
                        }

                        m_Logger.Debug("处理结果返回。");

                        // 初始化结果
                        resultCommand.CreateTime  = DateTime.Now.ToString("yyyyMMdd HH:mm:ss:fff");
                        resultCommand.Entity      = responseEntity;
                        resultCommand.Guid        = command.Guid;
                        resultCommand.Priority    = command.Priority;
                        resultCommand.ReceiveId   = command.SendId;
                        resultCommand.SendId      = m_ServerId;
                        resultCommand.ServiceName = command.ServiceName;

                        //m_CommunicationControl.Send(resultCommand);

                        ResultService.ResultService resultService = new ResultService.ResultService();
                        //this.BeginInvoke(new ExportLogHandler(ExportLog), "WebService URL:" + resultService.Url);
                        m_Logger.Debug(resultService.Url);
                        byte[] bytResult   = ConvertUtility.CodingToByte(resultCommand.ClassToCommandString(), 2);
                        byte[] bytCompress = CompressHelper.Compress(EnumCompressType.MemCompress, bytResult);
                        resultService.SendByteResult(bytCompress);
                    }
                }
                catch (Exception ex)
                {
                    LogExport(ex.Message);
                    LogExport(ex.StackTrace);
                }

                Thread.Sleep(100);
            }
        }
        /// <summary>
        /// 发送队列中的消息
        /// </summary>
        protected void QueueSend()
        {
            while (m_IsSend)
            {
                if (m_SendQueue.IsEmpty)
                {
                    Thread.Sleep(50);
                    continue;
                }

                ServiceCommand msg = null;
                if (m_SendQueue.TryPeek(out msg))
                {
                    string[] lines = msg.ClassToCommandString()
                                     .Split(Const.Command_Field_Separater_ReturnLine.ToCharArray(), StringSplitOptions.None);

                    m_SendQueue.TryDequeue(out msg);

                    if (lines == null ||
                        lines.Length == 0)
                    {
                        continue;
                    }

                    using (StreamWriter sw = new StreamWriter(m_PipeServer))
                    {
                        sw.AutoFlush = true;
                        sw.WriteLine(lines.Length);
                        foreach (string line in lines)
                        {
                            sw.WriteLine(line);
                        }
                    }
                }

                Thread.Sleep(50);
            }
        }