/// <summary> /// 接收消息方法 /// </summary> /// <param name="message">消息</param> public override void OnReceive(CMessage message) { if (message.m_functionID != FUNCTIONID_INDICATOR_GETINDICATORS) { message.m_requestID = m_operatorRequestID; } List <Indicator> indicators = new List <Indicator>(); GetIndicators(indicators, message.m_body, message.m_bodyLength); int indicatorsSize = indicators.Count; switch (message.m_functionID) { case FUNCTIONID_INDICATOR_GETINDICATORS: { m_indicators = indicators; m_loaded = true; break; } case FUNCTIONID_INDICATOR_ADDINDICATORS: { bool add = false; for (int i = 0; i < indicatorsSize; i++) { Indicator indicator = null; if (!GetIndicatorByID(indicators[i].m_indicatorID, ref indicator)) { m_indicators.Add(indicators[i]); add = true; } } if (!add) { return; } break; } case FUNCTIONID_INDICATOR_DELETEINDICATORS: { for (int i = 0; i < indicatorsSize; i++) { Indicator indicator = null; if (GetIndicatorByID(indicators[i].m_indicatorID, ref indicator)) { m_indicators.Remove(indicator); } } break; } case FUNCTIONID_INDICATOR_UPDATEINDICATORS: { for (int i = 0; i < indicatorsSize; i++) { Indicator updateIndicator = indicators[i]; int curIndicatorsSize = m_indicators.Count; for (int j = 0; j < curIndicatorsSize; j++) { Indicator indicator = m_indicators[j]; if (indicator.m_indicatorID == updateIndicator.m_indicatorID) { m_indicators[j] = updateIndicator; break; } } } break; } } base.OnReceive(message); }
/// <summary> /// 聊天数据回调 /// </summary> /// <param name="message">消息</param> private void ChatDataCallBack(CMessage message) { OnChatDataCallBack(message); }
/// <summary> /// 最新的数据的回调 /// </summary> /// <param name="message">消息</param> public void LatestDataCallBack(CMessage message) { OnLatestDataCallBack(message); }
/// <summary> /// 接收消息方法 /// </summary> /// <param name="message">消息</param> public override void OnReceive(CMessage message) { if (message.m_functionID != SecurityFilterService.FUNCTIONID_SECURITYFILTER_STARTFILTER && message.m_functionID != SecurityFilterService.FUNCTIONID_SECURITYFILTER_STOPFILTER) { if (message.m_functionID != FUNCTIONID_SECURITYFILTER_GETTEMPLATES) { message.m_requestID = m_operatorRequestID; } List <SecurityFilterTemplate> templates = new List <SecurityFilterTemplate>(); SecurityFilterService.GetTemplates(templates, message.m_body, message.m_bodyLength); int templatesSize = templates.Count; switch (message.m_functionID) { case FUNCTIONID_SECURITYFILTER_GETTEMPLATES: { m_templates = templates; m_loaded = true; break; } case FUNCTIONID_SECURITYFILTER_ADDTEMPLATES: { bool add = false; for (int i = 0; i < templatesSize; i++) { SecurityFilterTemplate template = null; if (!GetTemplate(templates[i].m_templateID, ref template)) { m_templates.Add(templates[i]); add = true; } } if (!add) { return; } break; } case FUNCTIONID_SECURITYFILTER_DELETETEMPLATES: { for (int i = 0; i < templatesSize; i++) { SecurityFilterTemplate template = null; if (GetTemplate(templates[i].m_templateID, ref template)) { m_templates.Remove(template); } } break; } case FUNCTIONID_SECURITYFILTER_UPDATETEMPLATES: { for (int i = 0; i < templatesSize; i++) { SecurityFilterTemplate updateTemplate = templates[i]; int curTemplatesSize = m_templates.Count; for (int j = 0; j < curTemplatesSize; j++) { SecurityFilterTemplate sfTemplate = m_templates[j]; if (sfTemplate.m_templateID == updateTemplate.m_templateID) { m_templates[j] = updateTemplate; break; } } } break; } } } base.OnReceive(message); }
/// <summary> /// 证券数据回调方法 /// </summary> /// <param name="message">消息</param> public void OnSecurityDataCallBack(CMessage message) { m_window.BeginInvoke(message); }
/// <summary> /// 宏数据回调 /// </summary> /// <param name="message">消息</param> private void MacroDataCallBack(CMessage message) { m_window.BeginInvoke(message); }
/// <summary> /// 自选股数据回调 /// </summary> /// <param name="message">消息</param> public void OnIndicatorDataCallBack(CMessage message) { m_window.BeginInvoke(message); }
/// <summary> /// 接收消息方法 /// </summary> /// <param name="message">消息</param> public override void OnReceive(CMessage message) { if (message.m_functionID != FUNCTIONID_MACRO_GETMACROS) { message.m_requestID = m_operatorRequestID; } List <Macro> macros = new List <Macro>(); GetMacros(macros, message.m_body, message.m_bodyLength); int macrosSize = macros.Count; switch (message.m_functionID) { case FUNCTIONID_MACRO_GETMACROS: { m_macros = macros; m_loaded = true; break; } case FUNCTIONID_MACRO_ADDMACROS: { bool add = false; for (int i = 0; i < macrosSize; i++) { Macro macro = null; if (!GetMacroByID(macros[i].m_macroID, ref macro)) { m_macros.Add(macros[i]); add = true; } } if (!add) { return; } break; } case FUNCTIONID_MACRO_DELETEMACROS: { for (int i = 0; i < macrosSize; i++) { Macro macro = null; if (GetMacroByID(macros[i].m_macroID, ref macro)) { m_macros.Remove(macro); } } break; } case FUNCTIONID_MACRO_EXECUTEMACROS: { for (int i = 0; i < macrosSize; i++) { Macro macro = null; if (GetMacroByID(macros[i].m_macroID, ref macro)) { m_chart.Chart.BeginInvoke(macro); } else { m_chart.Chart.BeginInvoke(macros[i]); } } break; } case FUNCTIONID_MACRO_UPDATEMACROS: { for (int i = 0; i < macrosSize; i++) { Macro updateMacro = macros[i]; int curMacrosSize = m_macros.Count; for (int j = 0; j < curMacrosSize; j++) { Macro macro = m_macros[j]; if (macro.m_macroID == updateMacro.m_macroID) { m_macros[j] = updateMacro; break; } } } break; } } base.OnReceive(message); }
/// <summary> /// 调用控件线程方法 /// </summary> /// <param name="args">参数</param> public void OnInvoke(object args) { CMessage message = (CMessage)args; if (message.m_serviceID == m_quoteService.ServiceID) { LatestDataInfo dataInfo = new LatestDataInfo(); List <SecurityLatestData> datas = new List <SecurityLatestData>(); QuoteService.GetLatestDatas(ref dataInfo, datas, message.m_body, message.m_bodyLength); int datasSize = datas.Count; for (int i = 0; i < datasSize; i++) { m_latestDatas[datas[i].m_securityCode] = datas[i]; } datas.Clear(); } else { List <UserSecurityCategory> categories = new List <UserSecurityCategory>(); UserSecurityService.GetCategories(categories, message.m_body, message.m_bodyLength); UserSecurityCategory category = categories[0]; switch (message.m_functionID) { case UserSecurityService.FUNCTIONID_USERSECURITY_ADDCATEGORIES: AddCategoriesToCategoryGrid(categories); break; case UserSecurityService.FUNCTIONID_USERSECURITY_DELETECATEGORIES: RemoveCategoriesFromCategoryGrid(categories); break; case UserSecurityService.FUNCTIONID_USERSECURITY_UPDATECATEGORIES: UpdateCategoriesToCategoryGrid(categories); break; case UserSecurityService.FUNCTIONID_USERSECURITY_ADDSECURITIES: case UserSecurityService.FUNCTIONID_USERSECURITY_DELETESECURITIES: { String categoryID = ""; List <GridRow> selectedRows = m_gridCategory.SelectedRows; int selectedRowsSize = selectedRows.Count; if (selectedRowsSize > 0) { categoryID = selectedRows[0].GetCell(0).Text; } if (categoryID != null && categoryID == category.m_categoryID) { List <Security> securities = new List <Security>(); m_securityService.GetSecuritiesByCodes(category.m_codes, securities); if (message.m_functionID == UserSecurityService.FUNCTIONID_USERSECURITY_ADDSECURITIES) { AddSecuritiesToSecuritiesGrid(securities); } else if (message.m_functionID == UserSecurityService.FUNCTIONID_USERSECURITY_DELETESECURITIES) { RemoveSecuritiesFromSecuritiesGrid(securities); } } break; } } } m_window.Invalidate(); }
/// <summary> /// 自选股数据回调 /// </summary> /// <param name="message">消息</param> private void IndicatorDataCallBack(CMessage message) { OnIndicatorDataCallBack(message); }
/// <summary> /// 登录数据回调 /// </summary> /// <param name="message">消息</param> private void LoginDataCallBack(CMessage message) { OnLoginDataCallBack(message); }
/// <summary> /// 最新数据回调事件 /// </summary> /// <param name="message">消息</param> private void LatestDataCallBack(CMessage message) { OnLatestDataCallBack(message); }
/// <summary> /// 调用控件线程方法 /// </summary> /// <param name="args">参数</param> public override void OnInvoke(object args) { base.OnInvoke(args); if (args != null) { CMessage message = (CMessage)args; if (message.m_requestID == m_requestID) { //分时数据 if (message.m_functionID == QuoteService.FUNCTIONID_QUOTE_PUSHLATESTDATA) { LatestDataInfo dataInfo = new LatestDataInfo(); List <SecurityLatestData> datas = new List <SecurityLatestData>(); QuoteService.GetLatestDatas(ref dataInfo, datas, message.m_body, message.m_bodyLength); SecurityLatestData latestData = datas[0]; if (latestData != null && latestData.m_securityCode == m_securityCode && !latestData.Equal(m_latestData)) { m_latestData = latestData; //设置保留小数的位数 int digit = 2; if (m_latestData.m_securityCode.StartsWith("1") || m_latestData.m_securityCode.StartsWith("5")) { digit = 3; } m_chart.Digit = digit; m_chart.RefreshData(); } } //LV2分时数据 else if (message.m_functionID == QuoteService.FUNCTIONID_QUOTE_PUSHLATESTDATALV2) { LatestDataInfoLV2 dataInfo = new LatestDataInfoLV2(); List <SecurityLatestDataLV2> datas = new List <SecurityLatestDataLV2>(); QuoteService.GetLatestDatasLV2(ref dataInfo, datas, message.m_body, message.m_bodyLength); SecurityLatestDataLV2 latestDataLV2 = datas[0]; if (latestDataLV2 != null && latestDataLV2.m_securityCode == m_securityCode && !latestDataLV2.Equal(m_latestDataLV2)) { m_latestDataLV2 = latestDataLV2; } } //成交数据 else if (message.m_functionID == QuoteService.FUNCTIONID_QUOTE_PUSHTRANSACTIONDATA) { String securityCode = ""; List <TransactionData> transactionDatas = new List <TransactionData>(); QuoteService.GetTransactionDatas(ref securityCode, transactionDatas, message.m_body, message.m_bodyLength); int transactionDatasSize = transactionDatas.Count; for (int i = 0; i < transactionDatasSize; i++) { TransactionData transactionData = transactionDatas[i]; DateTime date = CStrA.ConvertNumToDate(transactionData.m_date); GridRow row = new GridRow(); m_gridTransaction.InsertRow(0, row); TransactionDateCell dateCell = new TransactionDateCell(); dateCell.Text = date.ToString("HH:mm:ss"); row.AddCell(0, dateCell); GridCellStyle dateCellStyle = new GridCellStyle(); dateCellStyle.BackColor = COLOR.EMPTY; dateCellStyle.Font = new FONT("SimSun", 14, true, false, false); dateCellStyle.ForeColor = CDraw.PCOLORS_FORECOLOR2; dateCell.Style = dateCellStyle; TransactionDataDoubleCell priceCell = new TransactionDataDoubleCell(); priceCell.Digit = 2; priceCell.SetDouble(transactionData.m_price); row.AddCell(1, priceCell); GridCellStyle priceCellStyle = new GridCellStyle(); priceCellStyle.BackColor = COLOR.EMPTY; priceCellStyle.Font = new FONT("SimSun", 14, true, false, false); priceCellStyle.ForeColor = CDraw.GetPriceColor(transactionData.m_price, m_latestData.m_lastClose); priceCell.Style = priceCellStyle; TransactionDataDoubleCell volumeCell = new TransactionDataDoubleCell(); volumeCell.SetDouble(transactionData.m_volume); row.AddCell(2, volumeCell); GridCellStyle volumeCellStyle = new GridCellStyle(); volumeCellStyle.BackColor = COLOR.EMPTY; volumeCellStyle.Font = new FONT("SimSun", 14, true, false, false); if (transactionData.m_type == 0) { volumeCellStyle.ForeColor = CDraw.PCOLORS_FORECOLOR; } else if (transactionData.m_type == 1) { volumeCellStyle.ForeColor = CDraw.PCOLORS_UPCOLOR; } else { volumeCellStyle.ForeColor = CDraw.PCOLORS_DOWNCOLOR; } volumeCell.Style = volumeCellStyle; } m_gridTransaction.Update(); } } Invalidate(); } }
/// <summary> /// 聊天数据回调处理方法 /// </summary> /// <param name="message">消息</param> private void OnChatDataCallBack(CMessage message) { m_window.BeginInvoke(message); }
/// <summary> /// 接收数据 /// </summary> /// <param name="message">消息</param> public virtual void OnReceive(CMessage message) { }
/// <summary> /// 指标数据数据回调 /// </summary> /// <param name="message">消息</param> private void IndicatorLayoutDataCallBack(CMessage message) { m_window.BeginInvoke(message); }
/// <summary> /// 接收消息方法 /// </summary> /// <param name="message">消息</param> public override void OnReceive(CMessage message) { if (message.m_functionID != FUNCTIONID_INDICATORLAYOUT_GETLAYOUTS) { message.m_requestID = m_operatorRequestID; } List <IndicatorLayout> layouts = new List <IndicatorLayout>(); GetLayouts(layouts, message.m_body, message.m_bodyLength); int layoutsSize = layouts.Count; switch (message.m_functionID) { case FUNCTIONID_INDICATORLAYOUT_GETLAYOUTS: { m_layouts = layouts; m_loaded = true; break; } case FUNCTIONID_INDICATORLAYOUT_ADDLAYOUTS: { bool add = false; for (int i = 0; i < layoutsSize; i++) { IndicatorLayout layout = null; if (!GetLayoutByID(layouts[i].m_layoutID, ref layout)) { m_layouts.Add(layouts[i]); add = true; } } if (!add) { return; } break; } case FUNCTIONID_INDICATORLAYOUT_DELETELAYOUTS: { for (int i = 0; i < layoutsSize; i++) { IndicatorLayout layout = null; if (GetLayoutByID(layouts[i].m_layoutID, ref layout)) { m_layouts.Remove(layout); } } break; } case FUNCTIONID_INDICATORLAYOUT_UPDATELAYOUTS: { for (int i = 0; i < layoutsSize; i++) { IndicatorLayout updateLayout = layouts[i]; int curLayoutsSize = m_layouts.Count; for (int j = 0; j < curLayoutsSize; j++) { IndicatorLayout layout = m_layouts[j]; if (layout.m_layoutID == updateLayout.m_layoutID) { m_layouts[j] = updateLayout; break; } } } break; } } base.OnReceive(message); }
public override void OnReceive(CMessage message) { base.OnReceive(message); this.SendToListener(message); }
/// <summary> /// 发送POST数据 /// </summary> /// <param name="message">消息</param> /// <returns>返回消息</returns> public int SendRequest(CMessage message) { Binary bw = new Binary(); byte[] body = message.m_body; int bodyLength = message.m_bodyLength; int uncBodyLength = bodyLength; if (message.m_compressType == COMPRESSTYPE_GZIP) { using (MemoryStream cms = new MemoryStream()) { using (GZipStream gzip = new GZipStream(cms, CompressionMode.Compress)) { gzip.Write(body, 0, body.Length); } body = cms.ToArray(); bodyLength = body.Length; } } int len = sizeof(int) * 4 + bodyLength + sizeof(short) * 3 + sizeof(byte) * 2; bw.WriteInt(len); bw.WriteShort((short)message.m_groupID); bw.WriteShort((short)message.m_serviceID); bw.WriteShort((short)message.m_functionID); bw.WriteInt(message.m_sessionID); bw.WriteInt(message.m_requestID); bw.WriteByte((byte)message.m_state); bw.WriteByte((byte)message.m_compressType); bw.WriteInt(uncBodyLength); bw.WriteBytes(body); byte[] bytes = bw.GetBytes(); int length = bytes.Length; HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(m_url); webReq.Method = "POST"; webReq.ContentType = "application/x-www-form-urlencoded"; webReq.ContentLength = bytes.Length; if (bytes != null) { Stream writer = webReq.GetRequestStream(); writer.Write(bytes, 0, bytes.Length); writer.Close(); } HttpWebResponse response = (HttpWebResponse)webReq.GetResponse(); Stream reader = response.GetResponseStream(); long contentLength = response.ContentLength; byte[] dataArray = new byte[contentLength]; reader.Read(dataArray, 0, (int)contentLength); response.Close(); reader.Dispose(); bw.Close(); int ret = dataArray.Length; UpFlow += ret; IntPtr ptr = Marshal.AllocHGlobal(sizeof(byte) * ret); for (int i = 0; i < ret; i++) { IntPtr iptr = (IntPtr)((int)ptr + i); Marshal.WriteByte(iptr, dataArray[i]); } BaseService.CallBack(message.m_socketID, 0, ptr, ret); Marshal.FreeHGlobal(ptr); return(ret); }
/// <summary> /// 股票数据回调事件 /// </summary> /// <param name="message">消息</param> private void SecurityDataCallBack(CMessage message) { OnSecurityDataCallBack(message); }
/// <summary> /// 接收消息方法 /// </summary> /// <param name="message">消息</param> public override void OnReceive(CMessage message) { if (message.m_functionID == FUNCTIONID_USERSECURITY_GETVISITSCOUNT) { UserSecurityVisitsCount visitsCount = new UserSecurityVisitsCount(); Binary br = new Binary(); br.Write(message.m_body, message.m_bodyLength); visitsCount.m_userID = br.ReadInt(); visitsCount.CodesFromString(br.ReadString()); m_visitsCount = visitsCount.m_codes; br.Close(); } else { List <UserSecurityCategory> categories = new List <UserSecurityCategory>(); UserSecurityService.GetCategories(categories, message.m_body, message.m_bodyLength); int categoriesSize = categories.Count; if (message.m_functionID != FUNCTIONID_USERSECURITY_GETCATEGORIES) { message.m_requestID = m_operatorRequestID; } switch (message.m_functionID) { case FUNCTIONID_USERSECURITY_GETCATEGORIES: { m_categories = categories; m_loaded = true; break; } case FUNCTIONID_USERSECURITY_ADDCATEGORIES: { bool add = false; for (int i = 0; i < categoriesSize; i++) { UserSecurityCategory category = null; if (!GetCategory(categories[i].m_categoryID, ref category)) { m_categories.Add(categories[i]); add = true; } } if (!add) { return; } break; } case FUNCTIONID_USERSECURITY_DELETECATEGORIES: { for (int i = 0; i < categoriesSize; i++) { UserSecurityCategory category = null; if (GetCategory(categories[i].m_categoryID, ref category)) { m_categories.Remove(category); } } break; } case FUNCTIONID_USERSECURITY_UPDATECATEGORIES: { for (int i = 0; i < categoriesSize; i++) { UserSecurityCategory updateCategory = categories[i]; int curCategoriesSize = m_categories.Count; for (int j = 0; j < curCategoriesSize; j++) { UserSecurityCategory category = m_categories[j]; if (category.m_categoryID == updateCategory.m_categoryID) { m_categories[j] = updateCategory; break; } } } break; } case FUNCTIONID_USERSECURITY_ADDSECURITIES: { for (int i = 0; i < categoriesSize; i++) { UserSecurityCategory updateCategory = categories[i]; int curCategoriesSize = m_categories.Count; for (int j = 0; j < curCategoriesSize; j++) { UserSecurityCategory category = m_categories[j]; if (category.m_categoryID == updateCategory.m_categoryID) { if (category.m_codes != null && category.m_codes.Length > 0) { updateCategory.m_codes = m_categories[j].m_codes + "," + updateCategory.m_codes; } m_categories[j] = updateCategory; break; } } } break; } case FUNCTIONID_USERSECURITY_DELETESECURITIES: { for (int i = 0; i < categoriesSize; i++) { UserSecurityCategory updateCategory = categories[i]; int curCategoriesSize = m_categories.Count; for (int j = 0; j < curCategoriesSize; j++) { UserSecurityCategory category = m_categories[j]; if (category.m_categoryID == updateCategory.m_categoryID) { if (updateCategory.m_codes != null && updateCategory.m_codes.Length > 0 && category.m_codes != null && category.m_codes.Length > 0) { String[] deleteCodes = updateCategory.m_codes.Split(','); int deleteCodesSize = deleteCodes.Length; Dictionary <String, String> deleteCodesMap = new Dictionary <String, String>(); for (int m = 0; m < deleteCodesSize; m++) { deleteCodesMap[deleteCodes[m]] = ""; } String[] codes = category.m_codes.Split(','); int codesSize = codes.Length; String newCodes = ""; for (int m = 0; m < codesSize; m++) { if (!deleteCodesMap.ContainsKey(codes[m])) { newCodes += codes[m] + ","; } } if (newCodes != null && newCodes.Length > 0) { if (newCodes.Substring(newCodes.Length - 1) == ",") { newCodes = newCodes.Substring(0, newCodes.Length - 1); } } updateCategory.m_codes = newCodes; } m_categories[j] = updateCategory; break; } } } break; } } } base.OnReceive(message); }