/// <summary>
        /// 获取指标数据
        /// </summary>
        /// <param name="indicatorCode"></param>
        /// <param name="blockType"></param>
        /// <param name="codes"></param>
        /// <returns></returns>
        public static IndicatorRootData GetIndicatorData(String indicatorCode, String blockType, String codes)
        {
            if (!IndicatorDataCore._IndicatorEntityDict.ContainsKey(indicatorCode))
            {
                IndicatorEntityDataPacket newEntity = new IndicatorEntityDataPacket(indicatorCode);
                ConnectManager.CreateInstance().Request(newEntity);
                int tick2 = 0;
                while (newEntity.ReserveFlag == 0 && tick2 < 100)
                {
                    tick2++;
                    Thread.Sleep(100);
                }
            }
            IndicatorRootData        rootData = new IndicatorRootData();
            List <IndicatorItemData> datas    = new List <IndicatorItemData>();

            rootData.items = datas;
            String[]        strs     = codes.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            int             strsSize = strs.Length;
            IndicatorEntity entity   = IndicatorDataCore.GetIndicatorEntityByCategoryCode(indicatorCode);

            if (entity != null)
            {
                if (entity.Parameters != null)
                {
                    entity.Parameters = entity.Parameters.Replace("EmDataPara.", "dataquery.");
                    entity.Parameters = entity.Parameters.Replace("\"DefaultValue\":\"2013\"", "\"DefaultValue\":\"2016\"");
                    entity.Parameters = entity.Parameters.Replace("\"DefaultValue\":\"2014-04-21\"", "\"DefaultValue\":\"2017-03-27\"");
                }
                List <int> ids = new List <int>();
                ids.Add((int)entity.ID);
                Dictionary <String, String> codesMap = new Dictionary <String, String>();
                List <StockEntity>          stocks   = new List <StockEntity>();
                String idStr = entity.ID.ToString();
                for (int i = 0; i < strsSize; i++)
                {
                    StockEntity stock   = new StockEntity();
                    String[]    subStrs = strs[i].Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    stock.StockCode = subStrs[0];
                    stocks.Add(stock);
                    codesMap[subStrs[0] + idStr] = subStrs[0];
                }
                IndicatorDataCore.SetCustomerIndicatorEntity((int)entity.ID, entity);
                IndicatorDataPacket2 indicatorDataPacket = new IndicatorDataPacket2(CommonEnumerators.IndicatorRequestType.Fun, stocks, ids);
                if (blockType == "Block")
                {
                    indicatorDataPacket = new IndicatorDataPacket2(CommonEnumerators.IndicatorRequestType.Blk, stocks, ids);
                }
                ConnectManager.CreateInstance().Request(indicatorDataPacket);
                int tick = 0;
                while (indicatorDataPacket.ReserveFlag == 0 && tick < 100)
                {
                    tick++;
                    Thread.Sleep(100);
                }
                Dictionary <String, double> _doubleIndicatorDict = IndicatorTableDataCore.DoubleIndicatorDict;
                Dictionary <String, float>  _floatIndicatorDict  = IndicatorTableDataCore.FloatIndicatorDict;
                Dictionary <String, int>    _intIndicatorDict    = IndicatorTableDataCore.Int32IndicatorDict;
                Dictionary <String, long>   _longIndicatorDict   = IndicatorTableDataCore.LongIndicatorDict;
                Dictionary <String, String> _strIndicatorDict    = IndicatorTableDataCore.StrIndicatorDict;
                StringBuilder sb = new StringBuilder();
                rootData.categoryName = entity.CategoryName;
                rootData.categoryCode = entity.CategoryCode;
                if (entity.Parameters != null)
                {
                    rootData.parameters = entity.Parameters;
                    sb.Append("参数:" + entity.Parameters + "\r\n");
                }
                foreach (String key in _strIndicatorDict.Keys)
                {
                    if (codesMap.ContainsKey(key))
                    {
                        datas.Add(new IndicatorItemData(codesMap[key], _strIndicatorDict[key]));
                    }
                }
                foreach (String key in _doubleIndicatorDict.Keys)
                {
                    if (codesMap.ContainsKey(key))
                    {
                        datas.Add(new IndicatorItemData(codesMap[key], _doubleIndicatorDict[key]));
                    }
                }
                foreach (String key in _floatIndicatorDict.Keys)
                {
                    if (codesMap.ContainsKey(key))
                    {
                        datas.Add(new IndicatorItemData(codesMap[key], _floatIndicatorDict[key]));
                    }
                }
                foreach (String key in _intIndicatorDict.Keys)
                {
                    if (codesMap.ContainsKey(key))
                    {
                        datas.Add(new IndicatorItemData(codesMap[key], _intIndicatorDict[key]));
                    }
                }
                foreach (String key in _longIndicatorDict.Keys)
                {
                    if (codesMap.ContainsKey(key))
                    {
                        datas.Add(new IndicatorItemData(codesMap[key], _longIndicatorDict[key]));
                    }
                }
                codesMap.Clear();
            }
            return(rootData);
        }
Exemple #2
0
        private void PushSendDataPacket()
        {
            while (true)
            {
                try
                {
                    DataPacketBase base2 = null;
                    lock (this._sendDataPacketQueue)
                    {
                        if (this._sendDataPacketQueue.Count > 0)
                        {
                            base2 = this._sendDataPacketQueue.Dequeue();
                        }
                    }
                    if ((base2 != null) && (this._dataQuery != null))
                    {
                        String str = base2.Coding();
                        ////LogUtility.LogTableMessage(String.Format("数据中心关键点|发送请求,  RequestId={0}, msgId={1}, requestCommand={2} ", base2.RequestId, base2.MsgId, str));
                        switch (base2.RequestId)
                        {
                        case RequestType.IndicatorCategory:
                        case RequestType.IndicatorEntity:
                        case RequestType.IndicatorLeaf:
                        case RequestType.IndicatorEntityList:
                            this._dataQuery.NewQueryGlobalData(str, out this._idSend, new EmSocketClient.DelegateMgr.SendBackHandle(this.SendDataCallBack));
                            break;

                        case RequestType.IndicatorData:
                        {
                            IndicatorDataPacket2 packet = base2 as IndicatorDataPacket2;
                            List <String>        list   = new List <String>();
                            foreach (IndicatorEntity entity in packet.IndicatorList)
                            {
                                list.Add(entity.CategoryName);
                            }
                            ////LogUtility.LogTableMessage(String.Format("数据中心关键点|发送请求,  RequestId={0}, msgId={1}, 指标名称={2} ", base2.RequestId, base2.MsgId, String.Join("|", list.ToArray())));
                            this._dataQuery.QueryIndicateStream(str, out this._idSend, new EmSocketClient.DelegateMgr.SendBackHandle(this.SendDataCallBack));
                            break;
                        }

                        case RequestType.CustomIndicatorData:
                        {
                            CustomIndicatorDataPacket packet2 = base2 as CustomIndicatorDataPacket;
                            List <String>             list2   = new List <String>();
                            foreach (IndicatorEntity entity2 in packet2.IndicatorList)
                            {
                                list2.Add(entity2.CategoryName);
                            }
                            ////LogUtility.LogTableMessage(String.Format("数据中心关键点|发送请求,  RequestId={0}, msgId={1}, 指标名称={2} ", base2.RequestId, base2.MsgId, String.Join("|", list2.ToArray())));
                            this._dataQuery.QueryIndicateStream(str, out this._idSend, new EmSocketClient.DelegateMgr.SendBackHandle(this.SendDataCallBack));
                            break;
                        }

                        case RequestType.QuoteSeriesData:
                        {
                            QuoteSeriesDataPacket packet3 = base2 as QuoteSeriesDataPacket;
                            List <String>         list3   = new List <String>();
                            foreach (IndicatorEntity entity3 in packet3.IndicatorList)
                            {
                                list3.Add(entity3.CategoryName);
                            }
                            ////LogUtility.LogTableMessage(String.Format("数据中心关键点|发送请求,  RequestId={0}, msgId={1}, 指标名称={2} ", base2.RequestId, base2.MsgId, String.Join("|", list3.ToArray())));
                            this._dataQuery.QueryIndicateStream(str, out this._idSend, new EmSocketClient.DelegateMgr.SendBackHandle(this.SendDataCallBack));
                            break;
                        }

                        case RequestType.FinanceSeriesData:
                        {
                            FinanceSeriesDataPacket packet4 = base2 as FinanceSeriesDataPacket;
                            List <String>           list4   = new List <String>();
                            foreach (IndicatorEntity entity4 in packet4.IndicatorList)
                            {
                                list4.Add(entity4.CategoryName);
                            }
                            ////LogUtility.LogTableMessage(String.Format("数据中心关键点|发送请求,  RequestId={0}, msgId={1}, 指标名称={2} ", base2.RequestId, base2.MsgId, String.Join("|", list4.ToArray())));
                            this._dataQuery.QueryIndicateStream(str, out this._idSend, new EmSocketClient.DelegateMgr.SendBackHandle(this.SendDataCallBack));
                            break;
                        }

                        case RequestType.BlockQuoteSeriesData:
                        {
                            BlockIndicatorDataPacket packet5 = base2 as BlockIndicatorDataPacket;
                            List <String>            list5   = new List <String>();
                            foreach (IndicatorEntity entity5 in packet5.IndicatorList)
                            {
                                list5.Add(entity5.CategoryName);
                            }
                            ////LogUtility.LogTableMessage(String.Format("数据中心关键点|发送请求,  RequestId={0}, msgId={1}, 指标名称={2} ", base2.RequestId, base2.MsgId, String.Join("|", list5.ToArray())));
                            this._dataQuery.QueryIndicateStream(str, out this._idSend, new EmSocketClient.DelegateMgr.SendBackHandle(this.SendDataCallBack));
                            break;
                        }
                        }
                        lock (this._dicMsgId)
                        {
                            this._dicMsgId[this._idSend] = base2;
                        }
                    }
                    Thread.Sleep(5);
                    continue;
                }
                catch (Exception exception)
                {
                    ////LogUtility.LogTableMessage("数据中心|请求包报错," + exception.Message);
                    Thread.Sleep(5);
                    continue;
                }
            }
        }