Пример #1
0
        private void SetNewsData(ResNews24HOrgDataPacket dataPacket)
        {
            List <OneNews24HOrgDataRec> packetData = (dataPacket).News24HData;

            if (News24HOrgData.Count == 0)
            {
                News24HOrgData = packetData;
            }
            else
            {
                long memDate     = 0;
                long packetDate  = 0;
                int  insertIndex = -1;
                bool isAddEnd    = false;
                for (int i = 0; i < packetData.Count; i++)
                {
                    isAddEnd   = false;
                    packetDate = ((long)packetData[i].PublishDate) * 1000000 + packetData[i].PublishTime;
                    bool isSame = false;
                    for (int k = 0; k < News24HOrgData.Count; k++)
                    {
                        if (packetData[i].InfoCode == News24HOrgData[k].InfoCode)
                        {
                            isSame = true;
                            break;
                        }
                    }
                    if (!isSame)
                    {
                        for (int j = 0; j < News24HOrgData.Count; j++)
                        {
                            memDate = ((long)News24HOrgData[j].PublishDate * 1000000) + News24HOrgData[j].PublishTime;
                            if (packetDate >= memDate)
                            {
                                insertIndex = j;
                                break;
                            }
                            if (j == News24HOrgData.Count - 1)
                            {
                                isAddEnd    = true;
                                insertIndex = -1;
                            }
                        }
                        if (insertIndex >= 0)
                        {
                            News24HOrgData.Insert(insertIndex, packetData[i]);
                        }
                        else if (isAddEnd)
                        {
                            News24HOrgData.AddRange(packetData.GetRange(i, packetData.Count - i));
                            break;
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 异步接收数据
        /// </summary>
        /// <param name="response"></param>
        public void SendDataCallBack(MessageEntity response)
        {
            if (response.MsgBody is byte[])
            {
                InfoOrgBaseDataPacket dataPacket = null;
                using (MemoryStream ms = new MemoryStream(response.MsgBody as byte[]))
                {
                    lock (ms)
                    {
                        using (BinaryReader br = new BinaryReader(ms))
                        {
                            FuncTypeInfoOrg requestId = (FuncTypeInfoOrg)br.ReadByte();
                            switch (requestId)
                            {
                            case FuncTypeInfoOrg.InfoMineOrg:
                                dataPacket = new ResInfoOrgDataPacket();
                                break;

                            case FuncTypeInfoOrg.News24H:
                                dataPacket = new ResNews24HOrgDataPacket();
                                break;

                            case FuncTypeInfoOrg.ProfitForecast:
                                dataPacket = new ResProfitForecastOrgDataPacket();
                                break;

                            case FuncTypeInfoOrg.ImportantNews:
                                dataPacket = new ResImportantNewsDataPacket();
                                break;

                            case FuncTypeInfoOrg.NewsFlash:
                                dataPacket = new ResNewsFlashDataPacket();
                                break;

                            case FuncTypeInfoOrg.OrgRate:
                                dataPacket = new ResInfoRateOrgDataPacket();
                                break;

                            case FuncTypeInfoOrg.ResearchReport:
                                dataPacket = new ResResearchReportOrgDataPacket();
                                break;

                            case FuncTypeInfoOrg.NewInfoMineOrg:
                                dataPacket = new ResNewInfoOrgDataPacket();
                                break;

                            case FuncTypeInfoOrg.InfoMineOrgByIds:
                                dataPacket = new ResInfoOrgByIdsDataPacket();
                                break;
                            }
                            if (dataPacket != null)
                            {
                                dataPacket.RequestId = requestId;
                                if (_dicMsgId.ContainsKey((String)response.Tag))
                                {
                                    dataPacket.MsgId = _dicMsgId[(String)response.Tag];
                                    LogUtilities.LogMessage("收到响应, id=" + (String)response.Tag + ", msgId=" + dataPacket.MsgId);
                                    lock (_dicMsgId)
                                        _dicMsgId.Remove((String)response.Tag);
                                }
                                dataPacket.Decoding(br);
                            }
                        }
                    }
                }
                if (dataPacket != null)
                {
                    lock (_DataPacketQueue)
                        _DataPacketQueue.Enqueue(new CMRecvDataEventArgs(TcpService.ZXCFT, dataPacket, ((byte[])response.MsgBody).Length));
                }
            }
        }