void PushSendDataPacket() { while (true) { try { IndicatorDataPacket dataPacket = null; lock (_SendDataPacketQueue) { if (_SendDataPacketQueue.Count > 0) { dataPacket = _SendDataPacketQueue.Dequeue(); } } if (dataPacket != null) { if (_dataQuery != null) { _dataQuery.QueryMacroIndicate(dataPacket.Cmd, out _id, SendDataCallBack); lock (_dicMsgId) { _dicMsgId.Add(_id, dataPacket.MsgId); LogUtilities.LogMessage("发送请求, id=" + _id + ", msgId=" + dataPacket.MsgId); } } } Thread.Sleep(2); } catch (Exception e) { LogUtilities.LogMessage("Indicator 请求报错," + e.Message); Thread.Sleep(2); } } }
/// <summary> /// 建立socket连接 /// </summary> private void ConnectSocketServer() { DateTime dtStart = DateTime.Now; _dataQuery = DataAccess.IDataQuery; _heartRealTime = new ReqHeartDataPacket(); _heartInfo = new ReqInfoHeart(); _heartOrg = new ReqHeartOrgDataPacket(); _heartOcean = new ReqOceanHeartDataPacket(); SocketConnections = new Dictionary <TcpService, SocketConnection>(5); CreateRealTimeSocket(); CreateHistorySocket(); //CreateInfoSocket(); CreateOceanSocket(); CreateOrgSocket(); CreateLowsOrgSocket(); Timer timerCheck = new Timer(65000); timerCheck.Elapsed += timerCheck_Elapsed; timerCheck.Start(); _queryConnnection = new DataQueryConnections(_dataQuery); _queryConnnection.OnReceiveData += _queryConnnection_OnReceiveData; _indicatorQueryConnectiuon.OnReceiveData += _indicatorQueryConnectiuon_OnReceiveData; //TcpConnections = new Dictionary<short, TcpConnection>(5); //CreateRealTimeTcp(); //CreateHistoryTcp(); //CreateInfoTcp(); //CreateOrgTcp(); //CreateOceanTcp(); TimeSpan ts = DateTime.Now - dtStart; LogUtilities.LogMessage("连接服务器总共用时:" + ts.TotalMilliseconds); }
/// <summary> /// 发送一个数据请求包 /// </summary> /// <param name="dataPacket">要发送的一个数据包</param> /// <returns>发送数据的长度</returns> public long DoSendPacket(DataPacket dataPacket) { if (dataPacket == null) { return(0); } long sendBytes = 0; _socket.NoDelay = false; using (MemoryStream memoryStream = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(memoryStream)) { try { int len = dataPacket.CodePacket(bw); if (len > 0) { //memoryStream.Flush(); DoSendDataWork(memoryStream.ToArray()); sendBytes = memoryStream.Length; if (dataPacket is RealTimeDataPacket) { Debug.Print("SendPacket : " + ((RealTimeDataPacket)dataPacket).RequestType.ToString()); //LogUtilities.LogMessage("SendPacket : " + // ((RealTimeDataPacket)dataPacket).RequestType.ToString()); } else if (dataPacket is InfoDataPacket) { Debug.Print("SendPacket : " + ((InfoDataPacket)dataPacket).RequestType.ToString()); //LogUtilities.LogMessage("SendPacket : " + // ((InfoDataPacket)dataPacket).RequestType.ToString()); } else if (dataPacket is OrgDataPacket) { Debug.Print("SendPacket : " + ((OrgDataPacket)dataPacket).RequestType.ToString()); //LogUtilities.LogMessage("SendPacket : " + // ((OrgDataPacket)dataPacket).RequestType.ToString()); } } else { LogUtilities.LogMessage("DoResponsWork Error"); } } catch (Exception ex) { LogUtilities.LogMessage("DoResponsWork" + ex.Message); } } } return(sendBytes); }
void tcpRealTime_OnConnectServSuccess(object sender, ConnectEventArgs e) { Debug.Print("实时行情服务器连接成功!"); LogUtilities.LogMessage("实时行情服务器连接成功!"); if (DoAddOneClient != null) { DoAddOneClient(this, e); } }
/// <summary> /// 异步接收数据 /// </summary> /// <param name="response"></param> public void SendDataCallBack(MessageEntity response) { if (response.MsgBody is DataSet) { IndicatorDataPacket dataPacket = null; using (DataSet ds = response.MsgBody as DataSet) { if (ds != null && ds.Tables != null && ds.Tables.Count > 0) { lock (ds) { using (DataTable dt = ds.Tables[0]) { IndicateRequestType requestId; String tableKeyCode; if (TryGetRequestType(dt.TableName, out requestId, out tableKeyCode)) { switch (requestId) { case IndicateRequestType.LeftIndicatorsReport: dataPacket = new ResIndicatorsReportDataPacket(tableKeyCode); break; case IndicateRequestType.RightIndicatorsReport: dataPacket = new ResIndicatorsReportDataPacket(tableKeyCode); break; case IndicateRequestType.IndicatorValuesReport: dataPacket = new ResIndicatorValuesDataPacket(tableKeyCode); break; } 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(dt); } } } } } if (dataPacket != null) { lock (_DataPacketQueue) _DataPacketQueue.Enqueue(new CMRecvDataEventArgs(TcpService.ZXCFT, dataPacket, 100000)); } } }
void RecvEndCallBack(IAsyncResult iAsyncResult) { try { //lock (this) { int readBytes = _tcpClient.Client.EndReceive(iAsyncResult); if (readBytes > 0) { _mutex.WaitOne(); try { RecvDataEventArgs e = new RecvDataEventArgs(_ipAddressPort, (byte[]) iAsyncResult.AsyncState, readBytes); switch (SerMode) { case ServerMode.RealTime: case ServerMode.History: RecvRealTimeData(this, e); break; case ServerMode.Information: RecvInfoData(this, e); break; case ServerMode.Org: RecvOrgData(this, e); break; case ServerMode.Oversea: RecvRealTimeData(this, e); break; } } catch (Exception ex) { LogUtilities.LogMessage(ex.Message); } finally { _mutex.ReleaseMutex(); } } _tcpClient.Client.BeginReceive((byte[])iAsyncResult.AsyncState, 0, _bufferSize, 0, new AsyncCallback(RecvEndCallBack), iAsyncResult.AsyncState); } } catch (Exception ex) { LogUtilities.LogMessage(SerMode.ToString() + ex.Message); } }
/// <summary> /// 导入公式 /// </summary> /// <param name="filename"></param> /// <returns></returns> public static SerializeFormula ImportFormula(String filename) { try { BinaryFormatter deserializer = new BinaryFormatter(); FileStream file = new FileStream(filename, FileMode.Open); return((SerializeFormula)deserializer.Deserialize(file)); } catch (Exception e) { LogUtilities.LogMessage(e.Message); return(null); } }
/// <summary> /// 获取公式字典 /// </summary> public static FormulaDict GetFormulaDict() { FormulaDict dict = new FormulaDict(); String filePath = PathUtilities.CfgPath + "formuladict.xml"; if (File.Exists(filePath)) { try { XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode root = doc.SelectSingleNode(@"formuladict/formulatype"); foreach (XmlNode node in root.ChildNodes) { if (node.NodeType != XmlNodeType.Element) { continue; } FormulaDict.FormulaType formulatype = new FormulaDict.FormulaType(); formulatype.Id = Convert.ToInt32(node.Attributes["type"].Value); formulatype.Name = node.Attributes["name"].Value; foreach (XmlNode subnode in node.ChildNodes) { if (subnode.NodeType != XmlNodeType.Element) { continue; } FormulaDict.FormulaSubType subType = new FormulaDict.FormulaSubType(); subType.Id = Convert.ToInt32(subnode.Attributes["id"].Value); subType.Name = subnode.Attributes["name"].Value; formulatype.SubTypes.Add(subType); } dict.FormulaTypes.Add(formulatype); } root = doc.SelectSingleNode(@"formuladict/drawtype"); foreach (XmlNode node in root.ChildNodes) { if (node.NodeType != XmlNodeType.Element) { continue; } FormulaDict.DrawType drawType = new FormulaDict.DrawType(); drawType.Id = Convert.ToInt32(node.Attributes["id"].Value); drawType.Name = node.Attributes["name"].Value; dict.DrawTypes.Add(drawType); } } catch (Exception e) { LogUtilities.LogMessage("FormulaDict.xml Wrong:" + e.Message); } } return(dict); }
void SendEndCallBack(IAsyncResult iAsyncResult) { try { if (_socket != null) { _socket.EndSend(iAsyncResult); } } catch (Exception e) { LogUtilities.LogMessage("SendEndCallBack" + e.Message); } }
void DoSendDataWork(byte[] data) { if (_socket.Connected) { try { _socket.BeginSend(data, 0, data.Length, 0, new AsyncCallback(SendEndCallBack), null); } catch (Exception e) { MessageBox.Show(_tcpService.ToString() + "断开链接" + e.Message); LogUtilities.LogMessage("TcpSend Error : " + e.Message); } } }
void tcpHistory_OnReceiveData(object sender, CMRecvDataEventArgs e) { try { if (DoCMReceiveData != null) //通知界面而已,对于数据的响应在这个类中完成。 { DoCMReceiveData(this, new CMRecvDataEventArgs(e.ServiceType, e.DataPacket, e.Length)); } } catch (Exception ex) { LogUtilities.LogMessage("Err OneTcpConnection_DoReceiveData" + ex.Message); } }
public static void SetFieldData <T>(int code, FieldIndex field, T fieldValue) { try { int nLen = 0; switch (GetFlag(field)) { case SetFuncFlag.SetInt32: { int nValue = Convert.ToInt32(fieldValue); DetailData.FieldIndexDataInt32[code][field] = nValue; return; } case SetFuncFlag.SetFloat: { float num3 = Convert.ToSingle(fieldValue); DetailData.FieldIndexDataSingle[code][field] = num3; return; } case SetFuncFlag.SetDouble: { double num4 = Convert.ToDouble(fieldValue); DetailData.FieldIndexDataDouble[code][field] = num4; return; } case SetFuncFlag.SetInt64: { long num5 = Convert.ToInt64(fieldValue); DetailData.FieldIndexDataInt64[code][field] = num5; return; } case SetFuncFlag.SetString: { String s = Convert.ToString(fieldValue); DetailData.FieldIndexDataString[code][field] = s; return; } } } catch (Exception exception) { LogUtilities.LogMessage(exception.Message); } }
void DoSendDataWork(byte[] data) { if (!_tcpClient.Connected) { return; } try { _tcpClient.Client.BeginSend(data, 0, data.Length, 0, new AsyncCallback(SendEndCallBack), null); } catch (Exception e) { LogUtilities.LogMessage("TcpSend Error : " + e.Message); //throw; } }
/// <summary> /// 发送多个数据包 /// </summary> /// <param name="packets"></param> public void Request(List <DataPacket> packets) { if (packets == null || packets.Count <= 0) { return; } try { foreach (DataPacket dataPacket in packets) { Request(dataPacket); } } catch (Exception ex) { LogUtilities.LogMessage(ex.Message); } }
void _httpConnection_OnReceiveData(object sender, CMRecvDataEventArgs e) { if (SystemConfig.UserInfo.IsSingle)//有新Level2用户登入服务器,则不对行情数据进行处理 { try { if (DoCMReceiveData != null) //通知界面而已,对于数据的响应在这个类中完成。 { DoCMReceiveData(this, new CMRecvDataEventArgs(e.ServiceType, e.DataPacket, e.Length)); } } catch (Exception ex) { LogUtilities.LogMessage("Err OneTcpConnection_DoReceiveData" + ex.Message); } } }
public void ReceiveDataCallBack(TcpService tcpService, byte[] data) { try { DataPacket dataPacket = null; if (tcpService == TcpService.JGFW) { Console.WriteLine("1"); } switch (tcpService) { case TcpService.SSHQ: case TcpService.LSHQ: case TcpService.WPFW: dataPacket = RealTimeDataPacket.DecodePacket(data, data.Length); break; case TcpService.DPZS: case TcpService.JGFW: case TcpService.GPZS: case TcpService.JGLS: dataPacket = OrgDataPacket.DecodePacket(data, data.Length); break; case TcpService.HQZX: dataPacket = InfoDataPacket.DecodePacket(data, data.Length); break; } if (dataPacket != null && dataPacket.IsResult) { if (DoCMReceiveData != null) //通知界面而已,对于数据的响应在这个类中完成。 { DoCMReceiveData(this, new CMRecvDataEventArgs(tcpService, dataPacket, data.Length)); } } } catch (Exception e) { LogUtilities.LogMessage("ReceiveDataCallBack Error" + e.Message); } }
/// <summary> /// 获取用户关注的短线精灵类型 /// </summary> /// <returns></returns> public static IList <ShortLineType> GetUserShortLineTypes() { IList <ShortLineType> result = new List <ShortLineType>(); String filePathUser = PathUtilities.UserPath + "shortlines.xml"; String filePathNomal = PathUtilities.CfgPath + "shortlines.xml"; XmlDocument doc = new XmlDocument(); try { if (File.Exists(filePathUser)) { doc.Load(filePathUser); } else if (File.Exists(filePathNomal)) { doc.Load(filePathNomal); } XmlNode root = doc.SelectSingleNode("ShortLines"); if (null != root) { foreach (XmlNode itemNode in root.ChildNodes) { if (Enum.IsDefined(typeof(ShortLineType), itemNode.Name)) { ShortLineType tmp = (ShortLineType)(Enum.Parse(typeof(ShortLineType), itemNode.Name)); result.Add(tmp); } } } } catch (Exception e) { LogUtilities.LogMessage(e.Message); } if (result.Count == 0) { Array arr = Enum.GetValues(typeof(ShortLineType)); foreach (ShortLineType item in arr) { result.Add(item); } } return(result); }
//private const int _bufferSize = 512; /// <summary> /// 临时用,建立tcp连接 /// </summary> /// <param name="ipAddressPort"></param> public void Connect(IpAddressPort ipAddressPort) { try { _ipAddressPort = ipAddressPort; _tcpClient = new TcpClient(); _tcpClient.Connect(ipAddressPort.HostName, ipAddressPort.Port); if (_tcpClient.Connected) { HaveConnected = true; byte[] buffer = new byte[_bufferSize]; _tcpClient.Client.BeginReceive(buffer, 0, _bufferSize, 0, new AsyncCallback(RecvEndCallBack), buffer); //if (OnConnectServSuccess != null) // OnConnectServSuccess(this, new ConnectEventArgs(SerMode, this, ipAddressPort)); } } catch (Exception e) { LogUtilities.LogMessage(this.SerMode.ToString() + "服务器连接失败..." + e.Message); } }
/// <summary> /// Start /// </summary> public static void Start() { try { LogUtilities.LogMessage("行情开始加载"); ConnectManager2.CreateInstance().DoNetConnect(); DataCenterCore dc = DataCenterCore.CreateInstance(); //dc.TimerStart(); //dc.DoTimerElapsed(); //var codes = dc.GetQuoteCodeList(new List<String>() {"600000.SH"}, FieldIndex.Code); //订阅一个指数行情 //…… } catch (Exception e) { LoggerHelper.Log.Debug(e.Message + "\r\n" + e.StackTrace); } }
public static void LoadConfig() { if (!File.Exists(QuoteFieldFilePath)) { return; } XmlDocument doc = new XmlDocument(); try { doc.Load(QuoteFieldFilePath); } catch (IOException ioe) { LogUtilities.LogMessage("Load FieldInfo Error : " + ioe.Message); throw; } catch (XmlException xe) { LogUtilities.LogMessage("Load FieldInfo Error : " + xe.Message); throw; } catch (Exception ex) { LogUtilities.LogMessage("Load FieldInfo Error : " + ex.Message); throw; } try { DicDefaultFieldInfo = GetDefaultFieldInfo(doc); DicMarketFieldInfo = GetMarketFieldInfo(doc); } catch (Exception ex) { LogUtilities.LogMessage("Load FieldInfo Error : " + ex.Message); throw; } }
private static void LoadConfig() { if (!File.Exists(FilePath)) { return; } XmlDocument doc = new XmlDocument(); try { doc.Load(FilePath); } catch (IOException ioe) { LogUtilities.LogMessage("Load StockCustIndicatorCfg.xml Error : " + ioe.Message); throw; } catch (XmlException xe) { LogUtilities.LogMessage("Load StockCustIndicatorCfg.xml Error : " + xe.Message); throw; } catch (Exception ex) { LogUtilities.LogMessage("Load StockCustIndicatorCfg.xml Error : " + ex.Message); throw; } try { DicStockCustIndicator = GetStockCustIndicator(doc); } catch (Exception ex) { LogUtilities.LogMessage("Load StockCustIndicatorCfg.xml Error : " + ex.Message); throw; } }
/// <summary> /// 导出公式 /// </summary> /// <param name="f"></param> /// <param name="filename"></param> /// <returns></returns> public static bool ExportFormula(Formula f, String filename) { try { SerializeFormula serializeFormula = new SerializeFormula(); serializeFormula.des = f.des; serializeFormula.drawtype = f.drawtype; serializeFormula.fid = f.fid; serializeFormula.flag = Marshal.PtrToStringAnsi(f.flag); serializeFormula.help = Marshal.PtrToStringAnsi(f.help); serializeFormula.name = f.name; serializeFormula.paracount = f.paracount; for (int i = 0; i < f.paracount; i++) { serializeFormula.para[i].name = f.para[i].name; serializeFormula.para[i].maxvalue = f.para[i].maxvalue; serializeFormula.para[i].minvalue = f.para[i].minvalue; serializeFormula.para[i].defvalue = f.para[i].defvalue; serializeFormula.para[i].step = f.para[i].step; serializeFormula.para[i].uservalue = f.para[i].uservalue; } serializeFormula.paramtip = Marshal.PtrToStringAnsi(f.paramtip); serializeFormula.password = Marshal.PtrToStringAnsi(f.password); serializeFormula.src = Marshal.PtrToStringAnsi(f.src); serializeFormula.subtype = f.subtype; serializeFormula.type = f.type; serializeFormula.y = f.y; serializeFormula.y2 = f.y2; serializeFormula.y2num = f.y2num; serializeFormula.ynum = f.ynum; BinaryFormatter serializer = new BinaryFormatter(); FileStream file = new FileStream(filename, FileMode.Create); serializer.Serialize(file, serializeFormula); return(true); } catch (Exception e) { LogUtilities.LogMessage(e.Message); return(false); } }
/// <summary> /// 获取公式的系统功能 /// </summary> public static FormulaFunctions GetFormulaSystemFunctions() { FormulaFunctions functions = new FormulaFunctions(); String filePath = PathUtilities.CfgPath + "formulafunctions.xml"; if (File.Exists(filePath)) { try { XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode root = doc.SelectSingleNode(@"functions"); foreach (XmlNode categoryNode in root.ChildNodes) { FormulaFunctions.Category category = new FormulaFunctions.Category(); category.Name = categoryNode.Attributes["name"].Value; foreach (XmlNode functionNode in categoryNode) { FormulaFunctions.Function function = new FormulaFunctions.Function(); function.Name = functionNode.Attributes["name"].Value; function.Description = functionNode.Attributes["des"].Value; foreach (XmlNode usagenode in functionNode.ChildNodes) { if (usagenode.NodeType == XmlNodeType.CDATA) { function.Usage = usagenode.Value; } } category.Functions.Add(function); } functions.FunctionCategories.Add(category); } } catch (Exception e) { LogUtilities.LogMessage("FormulaFunction.xml error:" + e.Message); } } return(functions); }
private static Dictionary <String, Dictionary <String, InfoPanelChart> > GetInfoPanelCharts(String filePath) { if (File.Exists(filePath)) { try { XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode root = doc.SelectSingleNode(@"InfoPanel/Charts"); Dictionary <String, Dictionary <String, InfoPanelChart> > charts = new Dictionary <String, Dictionary <String, InfoPanelChart> >(); foreach (XmlNode levelnode in root.ChildNodes) { Dictionary <String, InfoPanelChart> controls = new Dictionary <String, InfoPanelChart>(); if (levelnode.NodeType == XmlNodeType.Comment) { continue; } foreach (XmlNode node in levelnode.ChildNodes) { if (node.NodeType == XmlNodeType.Comment) { continue; } InfoPanelChart chart = new InfoPanelChart(); chart.Name = node.Attributes["Name"].Value; foreach (XmlNode rownode in node.ChildNodes) { if (rownode.NodeType == XmlNodeType.Comment) { continue; } InfoPanelChartRow row = new InfoPanelChartRow(); if (null != rownode.Attributes["Repeat"]) { row.Repeat = Convert.ToBoolean(rownode.Attributes["Repeat"].Value); } if (null != rownode.Attributes["TopLine"]) { row.TopLine = Convert.ToBoolean(rownode.Attributes["TopLine"].Value); } if (null != rownode.Attributes["BottomLine"]) { row.BottomLine = Convert.ToBoolean(rownode.Attributes["BottomLine"].Value); } if (null != rownode.Attributes["LineColor"]) { row.LineColor = Enum.IsDefined( typeof(LineColor), rownode.Attributes["LineColor"].Value) ? (LineColor) Enum.Parse( typeof(LineColor), rownode.Attributes["LineColor"].Value) : LineColor.Lite; } if (null != rownode.Attributes["Margin"]) { String[] temp = rownode.Attributes["Margin"].Value.Split(','); if (temp.Length > 0) { if (temp.Length == 1) { row.MarginTop = row.MarginBottom = Convert.ToInt32(temp[0]); } else { row.MarginTop = Convert.ToInt32(temp[0]); row.MarginBottom = Convert.ToInt32(temp[1]); } } } foreach (XmlNode columnode in rownode.ChildNodes) { if (columnode.NodeType == XmlNodeType.Comment) { continue; } InfoPanelChartColum colum = new InfoPanelChartColum(); if (null != columnode.Attributes["Caption"]) { colum.Caption = columnode.Attributes["Caption"].Value; } if (null != columnode.Attributes["ValueField"]) { colum.ValueField = columnode.Attributes["ValueField"].Value; } colum.X = Convert.ToSingle(columnode.Attributes["X"].Value); colum.Width = Convert.ToSingle(columnode.Attributes["Width"].Value); switch (columnode.Attributes["CaptionAlgin"].Value.ToUpper()) { case "LEFT": colum.CaptionAlgin = StringAlignment.Near; break; case "RIGHT": colum.CaptionAlgin = StringAlignment.Far; break; case "CENTER": colum.CaptionAlgin = StringAlignment.Center; break; default: colum.CaptionAlgin = StringAlignment.Near; break; } switch (columnode.Attributes["ValueAlign"].Value.ToUpper()) { case "LEFT": colum.ValueAlign = StringAlignment.Near; break; case "CENTER": colum.ValueAlign = StringAlignment.Center; break; case "RIGHT": colum.ValueAlign = StringAlignment.Far; break; default: colum.ValueAlign = StringAlignment.Far; break; } if (null != columnode.Attributes["Margin"]) { String[] temp = columnode.Attributes["Margin"].Value.Split(','); if (temp.Length > 0) { if (temp.Length == 1) { colum.MarginTop = colum.MarginBottom = Convert.ToInt32(temp[0]); } else { colum.MarginTop = Convert.ToInt32(temp[0]); colum.MarginBottom = Convert.ToInt32(temp[1]); } } } if (null != columnode.Attributes["Padding"]) { String[] temp = columnode.Attributes["Padding"].Value.Split(','); if (temp.Length > 0) { if (temp.Length == 1) { colum.PaddingLeft = colum.PaddingRight = Convert.ToInt32(temp[0]); } else { colum.PaddingLeft = Convert.ToInt32(temp[0]); colum.PaddingRight = Convert.ToInt32(temp[1]); } } } if (null != columnode.Attributes["MarkLocation"]) { String location = columnode.Attributes["MarkLocation"].Value; switch (location) { case "TopLeft": colum.MarkLocation = MarkLocation.TopLeft; break; case "TopRight": colum.MarkLocation = MarkLocation.TopRight; break; case "BottomLeft": colum.MarkLocation = MarkLocation.BottomLeft; break; case "BottomRight": colum.MarkLocation = MarkLocation.BottomRight; break; default: colum.MarkLocation = MarkLocation.None; break; } } if (null != columnode.Attributes["MarkValue"]) { colum.MarkValue = columnode.Attributes["MarkValue"].Value; } row.Colums.Add(colum); } chart.Rows.Add(row); } controls.Add(chart.Name, chart); } charts.Add(levelnode.Name, controls); } return(charts); } catch (Exception ex) { LogUtilities.LogMessage("Load infopanel charts config error : " + ex.Message); } } return(null); }
/// <summary> /// GetUserInfo /// </summary> /// <returns></returns> public static UserInfo GetUserInfo() { UserInfo userInfo = new UserInfo(); if (File.Exists(FileName)) { XmlDocument doc = new XmlDocument(); try { doc.Load(FileName); XmlNode root = doc.SelectSingleNode(@"SysConfig/UserInfo"); if (root != null) { XmlAttribute atr = root.Attributes["HKDelay"]; if (atr != null) userInfo.HaveHKDelayRight = (atr.Value == "YES"); atr = root.Attributes["HKReal"]; if (atr != null) { userInfo.HaveHKRealTimeRight = (atr.Value == "YES"); if (userInfo.HaveHKRealTimeRight) userInfo.HaveHKDelayRight = true; } atr = root.Attributes["SHLevel2"]; if (atr != null) userInfo.HaveSHLevel2Right = (atr.Value == "YES"); atr = root.Attributes["SZLevel2"]; if (atr != null) userInfo.HaveSZLevel2Right = (atr.Value == "YES"); atr = root.Attributes["InterbankBond"]; if (atr != null) userInfo.HaveInterbankBondRight = (atr.Value == "YES"); atr = root.Attributes["ThirdBoardMarket"]; if (atr != null) userInfo.HaveThirdBoardMarketRight = (atr.Value == "YES"); atr = root.Attributes["IndexChinaBond"]; if (atr != null) userInfo.HaveIndexChinaBondRight = (atr.Value == "YES"); atr = root.Attributes["IndexFuture"]; if (atr != null) userInfo.HaveIndexFutureRight = (atr.Value == "YES"); atr = root.Attributes["WebF10Address"]; if (atr != null) userInfo.WebF10Address = atr.Value; atr = root.Attributes["IsVIPTerminal"]; if (atr != null) userInfo.IsVIPTerminal = (atr.Value == "YES"); atr = root.Attributes["IsVerifyFromSrv"]; if (atr != null) userInfo.IsVerifyFromSrv = (atr.Value == "YES"); } } catch (Exception ex) { LogUtilities.LogMessage("Load SysCfg Error : " + ex.Message); } } return userInfo; }
/// <summary> /// long转code /// </summary> /// <param name="securityId"></param> /// <returns></returns> public static String ConvertLongToCode(long securityId) { if (securityId == 0) { return(String.Empty); } if (securityId > 10000000000) { String[] marketCode = new String[2]; String sidStr = securityId + ""; String marketStr = sidStr.Substring(0, 2); if (marketStr.StartsWith("1")) { marketCode[0] = marketStr.Substring(1, 1); } else { marketCode[0] = marketStr; } StringBuilder code = new StringBuilder(); bool isVariable = "7".Equals(sidStr.Substring(2, 1)); if (!isVariable) { for (int i = 2; i < sidStr.Length; i += 2) { String sus = sidStr.Substring(i, 2); Int32 tmp = Int32.Parse(sus); if (tmp >= 0 && tmp <= 9) { //48~57号为0~9十个阿拉伯数字,0补齐两位 code.Append(tmp); } else if (tmp >= 10 && tmp <= 35) { //65~90号为26个大写英文字母,10开始 code.Append((char)(tmp + 55)); } else if (tmp >= 40 && tmp <= 65) { //97~122号为26个小写英文字母 ,40开始 code.Append((char)(tmp + 57)); } } marketCode[1] = code.ToString(); } else { long tmp = long.Parse(sidStr.Substring(3)); while (tmp > 0) { int i = Convert.ToInt32(tmp % 36); if (i >= 0 && i <= 9) { //48~57号为0~9十个阿拉伯数字,0补齐两位 code.Append(i); } else { code.Append((char)(i + 87)); } tmp = tmp / 36; } marketCode[1] = code.ToString(); } ReqMarketType mt = (ReqMarketType)Convert.ToInt32(marketCode[0]); return(DataPacket.GetEmCode(mt, marketCode[1])); } else { String code = String.Empty; try { if (DetailData.FieldIndexDataString.ContainsKey(Convert.ToInt32(securityId))) { DetailData.FieldIndexDataString[Convert.ToInt32(securityId)].TryGetValue(FieldIndex.EMCode, out code); } } catch (Exception e) { LogUtilities.LogMessage("ConvertCode error " + e.Message); } return(code); } }
/// <summary> /// code转到long /// </summary> /// <param name="code"></param> /// <returns></returns> public static long ConvertCodeToLong(String code) { ReqMarketType reqMt; String shortCode; DataPacket.ParseCode(code, out reqMt, out shortCode); int codeLen = shortCode.Length; bool isVariable = codeLen > 8; char[] chars = null; if (!isVariable) { chars = new char[code.Length * 2 + 2]; if ((short)reqMt < 10) { chars[0] = '1'; chars[1] = Convert.ToChar(((short)reqMt).ToString()); } else { ((short)reqMt).ToString().ToCharArray().CopyTo(chars, 0); } int i = 2; foreach (char c in shortCode) { if (c >= 48 && c <= 57) { //48~57号为0~9十个阿拉伯数字,0补齐两位 chars[i] = '0'; chars[i + 1] = c; } else if (c >= 65 && c <= 90) { //65~90号为26个大写英文字母,10开始 // chars[i] = ('0'+ (10 + (c - 65))); chars[i] = Convert.ToChar((((c - 65) / 10) + 1).ToString()); chars[i + 1] = Convert.ToChar(((c - 65) % 10).ToString()); } else if (c >= 97 && c <= 122) { //97~122号为26个小写英文字母 ,40开始 chars[i] = Convert.ToChar((((c - 97) / 10) + 4).ToString()); chars[i + 1] = Convert.ToChar(((c - 97) % 10).ToString()); } i = i + 2; } try { long security = long.Parse(new String(chars)); return(security); } catch (Exception e) { LogUtilities.LogMessage(e.Message); } } else { shortCode = shortCode.ToLower(); StringBuilder varStr = new StringBuilder(); if ((short)reqMt < 10) { varStr.Append('1').Append(Convert.ToChar(((short)reqMt).ToString())); } else { varStr.Append(Convert.ToChar(((short)reqMt).ToString())); } varStr.Append(7); int i = 0; long varL = 0L; foreach (char c in shortCode) { if (c >= 48 && c <= 57) { //48~57号为0~9十个阿拉伯数字 varL += (c - 48) * (long)Math.Pow(36, i); } else if (c >= 97 && c <= 122) { //97~122号为26个小写英文字母 varL += (c - 87) * (long)Math.Pow(36, i); } i++; } varStr.Append(varL); return(long.Parse(varStr.ToString()));; } return(0); }
private static Dictionary <MarketType, InfoPanelLayout> GetInfoPanelLayout(String filePath) { if (File.Exists(filePath)) { try { XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode root = doc.SelectSingleNode(@"InfoPanel/Layouts"); Dictionary <MarketType, InfoPanelLayout> result = new Dictionary <MarketType, InfoPanelLayout>(); if (null == root) { return(result); } foreach (XmlNode layoutnode in root.ChildNodes) { if (layoutnode.NodeType == XmlNodeType.Comment) { continue; } InfoPanelLayout layout = new InfoPanelLayout(); if (null != layoutnode.Attributes["MarketType"]) { MarketType type; if (Enum.IsDefined(typeof(MarketType), layoutnode.Attributes["MarketType"].Value)) { layout.Market = (MarketType) Enum.Parse(typeof(MarketType), layoutnode.Attributes["MarketType"].Value); if (null != layoutnode.Attributes["Columns"]) { layout.Columns = Convert.ToInt32(layoutnode.Attributes["Columns"].Value); } if (null != layoutnode.Attributes["TopHalfHeight"]) { layout.TopHalfHeight = Convert.ToSingle( layoutnode.Attributes["TopHalfHeight"].Value); } foreach (XmlNode chartnode in layoutnode.ChildNodes) { if (chartnode.NodeType == XmlNodeType.Comment) { continue; } switch (chartnode.Name) { case "Chart": { InfoPanelLayoutChart chart = new InfoPanelLayoutChart(); if (null != chartnode.Attributes["Name"]) { chart.Name = chartnode.Attributes["Name"].Value; } if (null != chartnode.Attributes["ColIndex"]) { chart.ColIndex = Convert.ToInt32(chartnode.Attributes["ColIndex"].Value); } if (null != chartnode.Attributes["RowIndex"]) { chart.RowIndex = Convert.ToInt32(chartnode.Attributes["RowIndex"].Value); } if (null != chartnode.Attributes["RowHeight"]) { chart.Height = Convert.ToSingle(chartnode.Attributes["RowHeight"].Value); } if (null != chartnode.Attributes["IsSplitter"]) { chart.IsSplitter = Convert.ToBoolean(chartnode.Attributes["IsSplitter"].Value); } layout.Charts.Add(chart); break; } case "BottomTab": { InfoPanelLayoutTabs chart = new InfoPanelLayoutTabs(); if (null != chartnode.Attributes["Name"]) { chart.Name = chartnode.Attributes["Name"].Value; } if (null != chartnode.Attributes["ColIndex"]) { chart.ColIndex = Convert.ToInt32(chartnode.Attributes["ColIndex"].Value); } if (null != chartnode.Attributes["RowIndex"]) { chart.RowIndex = Convert.ToInt32(chartnode.Attributes["RowIndex"].Value); } foreach (XmlNode tabnode in chartnode.ChildNodes) { if (tabnode.NodeType == XmlNodeType.Comment) { continue; } InfoPanelLayoutTab tab = new InfoPanelLayoutTab(); if (null != tabnode.Attributes["Name"]) { tab.Name = tabnode.Attributes["Name"].Value; } foreach (XmlNode tabchartnode in tabnode.ChildNodes) { if (tabchartnode.NodeType == XmlNodeType.Comment) { continue; } InfoPanelLayoutChart tabChart = new InfoPanelLayoutChart(); tabChart.Location = InfoPanelLayoutChartLocation.BottomTabChart; if (null != tabchartnode.Attributes["Name"]) { tabChart.Name = tabchartnode.Attributes["Name"].Value; } if (null != tabchartnode.Attributes["ColIndex"]) { tabChart.ColIndex = Convert.ToInt32( tabchartnode.Attributes["ColIndex"].Value); } if (null != tabchartnode.Attributes["RowIndex"]) { tabChart.RowIndex = Convert.ToInt32( tabchartnode.Attributes["RowIndex"].Value); } if (null != tabchartnode.Attributes["RowHeight"]) { tabChart.Height = Convert.ToSingle(tabchartnode.Attributes["RowHeight"].Value); } if (null != tabchartnode.Attributes["IsSplitter"]) { tabChart.IsSplitter = Convert.ToBoolean(tabchartnode.Attributes["IsSplitter"].Value); } tab.TabCharts.Add(tabChart); } chart.Tabs.Add(tab); } layout.BottomTab = chart; break; } case "TopTab": { InfoPanelLayoutTabs chart = new InfoPanelLayoutTabs(); if (null != chartnode.Attributes["Name"]) { chart.Name = chartnode.Attributes["Name"].Value; } if (null != chartnode.Attributes["ColIndex"]) { chart.ColIndex = Convert.ToInt32(chartnode.Attributes["ColIndex"].Value); } if (null != chartnode.Attributes["RowIndex"]) { chart.RowIndex = Convert.ToInt32(chartnode.Attributes["RowIndex"].Value); } foreach (XmlNode tabnode in chartnode.ChildNodes) { if (tabnode.NodeType == XmlNodeType.Comment) { continue; } InfoPanelLayoutTab tab = new InfoPanelLayoutTab(); if (null != tabnode.Attributes["Name"]) { tab.Name = tabnode.Attributes["Name"].Value; } if (null != tabnode.Attributes["Vline"]) { tab.VLine = Convert.ToBoolean(tabnode.Attributes["Vline"].Value); } foreach (XmlNode tabchartnode in tabnode.ChildNodes) { if (tabchartnode.NodeType == XmlNodeType.Comment) { continue; } InfoPanelLayoutChart tabChart = new InfoPanelLayoutChart(); tabChart.Location = InfoPanelLayoutChartLocation.TopTabChart; if (null != tabchartnode.Attributes["Name"]) { tabChart.Name = tabchartnode.Attributes["Name"].Value; } if (null != tabchartnode.Attributes["ColIndex"]) { tabChart.ColIndex = Convert.ToInt32( tabchartnode.Attributes["ColIndex"].Value); } if (null != tabchartnode.Attributes["RowIndex"]) { tabChart.RowIndex = Convert.ToInt32( tabchartnode.Attributes["RowIndex"].Value); } if (null != tabchartnode.Attributes["RowHeight"]) { tabChart.Height = Convert.ToSingle(tabchartnode.Attributes["RowHeight"].Value); } if (null != tabchartnode.Attributes["IsSplitter"]) { tabChart.IsSplitter = Convert.ToBoolean(tabchartnode.Attributes["IsSplitter"].Value); } tab.TabCharts.Add(tabChart); } chart.Tabs.Add(tab); } layout.TopTab = chart; break; } } } result.Add(layout.Market, layout); } } } return(result); } catch (Exception ex) { LogUtilities.LogMessage("Load infopanel layout config error : " + ex.Message); } } return(null); }
/// <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)); } } }
public static Dictionary <MarketType, List <TopBannerMenuItemPair> > GetTopBannerMenu() { String filePath = PathUtilities.CfgPath + "TopBannerMenu.xml"; if (File.Exists(filePath)) { try { Dictionary <MarketType, List <TopBannerMenuItemPair> > result = new Dictionary <MarketType, List <TopBannerMenuItemPair> >(); XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlNode root = doc.SelectSingleNode("Menu"); foreach (XmlNode marketNode in root.ChildNodes) { if (marketNode.NodeType == XmlNodeType.Comment) { continue; } if (Enum.IsDefined(typeof(MarketType), marketNode.Attributes["Type"].Value)) { MarketType market = (MarketType)Enum.Parse(typeof(MarketType), marketNode.Attributes["Type"].Value); List <TopBannerMenuItemPair> pairs = new List <TopBannerMenuItemPair>(); foreach (XmlNode pairNode in marketNode.ChildNodes) { int count = pairNode.ChildNodes.Count; if (count > 0) { TopBannerMenuItemPair pair = new TopBannerMenuItemPair(); if (count == 1) { TopBannerMenuItem item = new TopBannerMenuItem(); item.Caption = pairNode.FirstChild.Attributes["Caption"].Value ?? String.Empty; item.Url = pairNode.FirstChild.Attributes["Url"].Value ?? String.Empty; item.UrlTitle = pairNode.FirstChild.Attributes["UrlTitle"].Value ?? String.Empty; pair.Item1 = item; } else { TopBannerMenuItem item1 = new TopBannerMenuItem(); item1.Caption = pairNode.FirstChild.Attributes["Caption"].Value ?? String.Empty; item1.Url = pairNode.FirstChild.Attributes["Url"].Value ?? String.Empty; item1.UrlTitle = pairNode.FirstChild.Attributes["UrlTitle"].Value ?? String.Empty; TopBannerMenuItem item2 = new TopBannerMenuItem(); item2.UrlTitle = pairNode.LastChild.Attributes["UrlTitle"].Value ?? String.Empty; item2.Url = pairNode.LastChild.Attributes["Url"].Value ?? String.Empty; item2.Caption = pairNode.LastChild.Attributes["Caption"].Value ?? String.Empty; pair.Item1 = item1; pair.Item2 = item2; } pairs.Add(pair); } } result.Add(market, pairs); } } return(result); } catch (Exception e) { LogUtilities.LogMessage(e.Message); return(null); } } else { return(null); } }