/// <summary> /// 获取表格数据 /// </summary> /// <param name="grid">表格</param> /// <returns>流</returns> public byte[] GetBytes(GridA grid) { Binary br = new Binary(); br.WriteString(grid.Name); List <GridColumn> columns = grid.GetColumns(); int columnsSize = columns.Count; br.WriteInt(columnsSize); for (int i = 0; i < columnsSize; i++) { GridColumn column = columns[i]; br.WriteString(column.Name); br.WriteString(column.ColumnType); } List <GridRow> rows = grid.GetRows(); int rowsCount = rows.Count; br.WriteInt(rowsCount); for (int i = 0; i < rowsCount; i++) { GridRow row = rows[i]; for (int j = 0; j < columnsSize; j++) { GridColumn column = columns[j]; String columnType = column.ColumnType.ToLower(); GridCell cell = row.GetCell(j); if (columnType == "bool") { br.WriteBool(cell.GetBool()); } else if (columnType == "double") { br.WriteDouble(cell.GetDouble()); } else if (columnType == "float") { br.WriteFloat(cell.GetFloat()); } else if (columnType == "int") { br.WriteInt(cell.GetInt()); } else if (columnType == "long") { br.WriteDouble(cell.GetLong()); } else if (columnType == "string") { br.WriteString(cell.GetString()); } } } byte[] bytes = br.GetBytes(); br.Close(); return(bytes); }
public int GetSecuritiesByBlockID(int requestID, string blockID) { Binary binary = new Binary(); binary.WriteString(blockID); byte[] bytes = binary.GetBytes(); int num = this.Send(new CMessage(base.GroupID, base.ServiceID, 1, base.SessionID, requestID, this.m_socketID, 0, base.CompressType, bytes.Length, bytes)); binary.Close(); return((num > 0) ? 1 : 0); }
/// <summary> /// 获取预测的成交量 /// </summary> /// <param name="requestID"></param> /// <param name="securityCode"></param> /// <returns></returns> public int GetVolumeForecast(int requestID, string securityCode) { Binary binary = new Binary(); binary.WriteInt(1); binary.WriteString(securityCode); binary.WriteDouble(0.0); byte[] bytes = binary.GetBytes(); binary.Close(); return((this.Send(new CMessage(base.GroupID, base.ServiceID, FUNCTIONID_QUOTE_GETVOLUMEFORECAST, base.SessionID, requestID, this.m_socketID, 0, base.CompressType, bytes.Length, bytes)) > 0) ? 1 : 0); }
public int SendVisitsCount(int functionID, int requestID, UserSecurityVisitsCount visitsCount) { Binary binary = new Binary(); binary.WriteInt(visitsCount.m_userID); binary.WriteString(visitsCount.CodesToString()); byte[] bytes = binary.GetBytes(); int num = this.Send(new CMessage(base.GroupID, base.ServiceID, functionID, base.SessionID, requestID, this.m_socketID, 0, base.CompressType, bytes.Length, bytes)); binary.Close(); return(num); }
/// <summary> /// 发送请求 /// </summary> /// <param name="functionID"></param> /// <param name="requestID"></param> /// <param name="socketID"></param> /// <param name="dataInfo"></param> /// <returns></returns> public int Send(int functionID, int requestID, int socketID, LatestDataInfo dataInfo) { Binary binary = new Binary(); binary.WriteString(dataInfo.m_codes); binary.WriteChar((char)dataInfo.m_formatType); binary.WriteChar((char)dataInfo.m_lv2); binary.WriteInt(dataInfo.m_size); byte[] bytes = binary.GetBytes(); int num = this.Send(new CMessage(base.GroupID, base.ServiceID, functionID, base.SessionID, requestID, socketID, 0, base.CompressType, bytes.Length, bytes)); binary.Close(); return(num); }
/// <summary> /// 发送消息 /// </summary> /// <param name="message">消息</param> public virtual int Send(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; IntPtr ptr = Marshal.AllocHGlobal(sizeof(byte) * length); for (int i = 0; i < length; i++) { IntPtr iptr = (IntPtr)((int)ptr + i); Marshal.WriteByte(iptr, bytes[i]); } int ret = SendByClient(message.m_socketID, ptr, length); m_upFlow += ret; Marshal.FreeHGlobal(ptr); bw.Close(); return(ret); }
/// <summary> /// 发送请求 /// </summary> /// <param name="functionID"></param> /// <param name="requestID"></param> /// <param name="socketID"></param> /// <param name="dataInfo"></param> /// <returns></returns> public int Send(int functionID, int requestID, int socketID, HistoryDataInfo dataInfo) { Binary binary = new Binary(); binary.WriteString(dataInfo.m_securityCode); binary.WriteChar((char)dataInfo.m_type); binary.WriteInt(dataInfo.m_size); binary.WriteInt(dataInfo.m_cycle); binary.WriteInt(dataInfo.m_subscription); binary.WriteDouble(dataInfo.m_startDate); binary.WriteDouble(dataInfo.m_endDate); binary.WriteBool(dataInfo.m_pushData); byte[] bytes = binary.GetBytes(); int num = this.Send(new CMessage(base.GroupID, base.ServiceID, functionID, base.SessionID, requestID, socketID, 0, base.CompressType, bytes.Length, bytes)); binary.Close(); return(num); }
/// <summary> /// 发送消息 /// </summary> /// <param name="functionID">方法ID</param> /// <param name="requestID">请求ID</param> /// <param name="sessions">用户会话集合</param> /// <returns>状态</returns> public int Send(int functionID, int requestID, List <UserSession> sessions) { Binary bw = new Binary(); int size = sessions.Count; bw.WriteInt(size); for (int i = 0; i < size; i++) { UserSession session = sessions[i]; bw.WriteInt(session.m_userID); bw.WriteString(session.m_key); bw.WriteString(session.m_value); } byte[] bytes = bw.GetBytes(); int ret = Send(new CMessage(GroupID, ServiceID, functionID, SessionID, requestID, m_socketID, 0, CompressType, bytes.Length, bytes)); bw.Close(); return(ret); }
/// <summary> /// 发送消息 /// </summary> /// <param name="userID">方法ID</param> /// <param name="userID">请求ID</param> /// <param name="text">发送字符</param> public int SendToAllClients(int functionID, int requestID, List <ChatData> datas) { Binary bw = new Binary(); int chatSize = datas.Count; bw.WriteInt(chatSize); for (int i = 0; i < chatSize; i++) { ChatData chat = datas[i]; bw.WriteInt(chat.m_userID); bw.WriteChar((char)chat.m_type); bw.WriteString(chat.m_text); } byte[] bytes = bw.GetBytes(); int ret = Send(new CMessage(GroupID, ServiceID, functionID, SessionID, requestID, m_socketID, 0, CompressType, bytes.Length, bytes)); bw.Close(); return(ret); }
/// <summary> /// 保持活跃 /// </summary> /// <param name="socketID">套接字ID</param> /// <returns>状态</returns> public virtual int KeepAlive(int socketID) { Binary bw = new Binary(); bw.WriteInt((int)4); byte[] bytes = bw.GetBytes(); int length = bytes.Length; IntPtr ptr = Marshal.AllocHGlobal(sizeof(byte) * length); for (int i = 0; i < length; i++) { IntPtr iptr = (IntPtr)((int)ptr + i); Marshal.WriteByte(iptr, bytes[i]); } int ret = SendByClient(socketID, ptr, length); Marshal.FreeHGlobal(ptr); bw.Close(); return(ret); }
public int Send(int functionID, int requestID, List <UserSecurityCategory> categories) { Binary binary = new Binary(); int count = categories.Count; binary.WriteInt(count); for (int i = 0; i < count; i++) { UserSecurityCategory category = categories[i]; binary.WriteString(category.m_categoryID); binary.WriteInt(category.m_userID); binary.WriteString(category.m_name); binary.WriteString(category.m_codes); binary.WriteInt(category.m_type); binary.WriteInt(category.m_orderNum); } byte[] bytes = binary.GetBytes(); int num3 = this.Send(new CMessage(base.GroupID, base.ServiceID, functionID, base.SessionID, requestID, this.m_socketID, 0, base.CompressType, bytes.Length, bytes)); binary.Close(); return(num3); }
public int Send(int functionID, int requestID, List <IndicatorLayout> layouts) { Binary binary = new Binary(); int count = layouts.Count; binary.WriteInt(count); for (int i = 0; i < count; i++) { IndicatorLayout layout = layouts[i]; binary.WriteString(layout.m_layoutID); binary.WriteInt(layout.m_userID); binary.WriteString(layout.m_name); binary.WriteString(layout.m_text); binary.WriteInt(layout.m_type); binary.WriteInt(layout.m_orderNum); } byte[] bytes = binary.GetBytes(); int num3 = this.Send(new CMessage(base.GroupID, base.ServiceID, functionID, base.SessionID, requestID, this.m_socketID, 0, base.CompressType, bytes.Length, bytes)); binary.Close(); return(num3); }
/// <summary> /// 发送消息 /// </summary> /// <param name="functionID">方法ID</param> /// <param name="requestID">请求ID</param> /// <param name="loginInfos">登录信息集合</param> /// <returns>状态</returns> public int Send(int functionID, int requestID, List <LoginInfo> loginInfos) { Binary bw = new Binary(); int loginInfosSize = loginInfos.Count; bw.WriteInt(loginInfosSize); for (int i = 0; i < loginInfosSize; i++) { LoginInfo loginInfo = loginInfos[i]; bw.WriteInt(loginInfo.m_userID); bw.WriteString(loginInfo.m_userName); bw.WriteString(loginInfo.m_passWord); bw.WriteString(loginInfo.m_nickName); bw.WriteInt(loginInfo.m_type); bw.WriteInt(loginInfo.m_state); bw.WriteInt(loginInfo.m_sessionID); } byte[] bytes = bw.GetBytes(); int ret = Send(new CMessage(GroupID, ServiceID, functionID, SessionID, requestID, m_socketID, 0, CompressType, bytes.Length, bytes)); bw.Close(); return(ret); }
/// <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); }