/// <summary> /// 生成报文头 /// </summary> /// yaoy 16.07.05 /// <param name="fileId"></param> /// <param name="messageTypeId"></param> /// <returns></returns> public string BuildMessageTop(int fileId, int messageTypeId, int i) { // 报文头临时变量 string messageTopData = string.Empty; // 补位码临时变量 string complementBits = string.Empty; // 版本号 string version = "A2.1"; // 企业金融机构代码 string comFinancialInstitutionCode = "33207991216"; // 获取报文文件信息 ReportFilesInfo reportFilesInfo = _dataRule.GetReportFilesInfoById(fileId); int messageFileId = reportFilesInfo == null ? 0 : reportFilesInfo.MessageFileId; MessageFileInfo messageFileInfo = _dataRule.GetMessageFileInfoById(messageFileId); int messageFileTypeId = messageFileInfo == null ? 0 : messageFileInfo.MessageFileTypeId; MessageTypeInfo messageTypeInfo = _dataRule.GetMessageTypeInfoById(messageTypeId); string messageTypeCode = messageTypeInfo == null ? string.Empty : messageTypeInfo.BMP_Code; // 采集类报文文件 if (messageFileTypeId == 1) { messageTopData = version + comFinancialInstitutionCode + DateTime.Now.ToString("yyyyMMddHHmmss") + messageTypeCode + complementBits.PadRight(30, ' '); } // 业务管理类报文文件 if (messageFileTypeId == 2) { } // 反馈类报文文件 if (messageFileTypeId == 3) { } return(messageTopData); }
/// <summary> /// 패킷 메세지 타입 문자열과 실제 파라미터 타입 매칭을 추가한다. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="typeStr"></param> protected void AddMessageType <T>(string typeStr) where T : class { ThrowExceptionIfAlreadyStarted(); // 시작하면 실행할 수 없음 var typeInfo = new MessageTypeInfo() { typeStr = typeStr, paramType = typeof(T) }; typeInfo.funcMakeRecv = (packet) => { var obj = new Receive <T>(packet); return(obj); }; typeInfo.funcMakeSend = () => { var obj = new Send <T>(); return(obj); }; m_typeInfoDict[typeStr] = typeInfo; }
public static void LoadAssembly(Assembly assembly) { Type netMsgType = typeof(NetworkMessage); foreach (var t in assembly.GetTypes()) { if (t.IsSubclassOf(netMsgType)) { int id = t.GetHashCode(); if (MessageIDs.ContainsKey(id)) { MessageIDs.Remove(id); } try { MessageTypeInfo info = new MessageTypeInfo(); info.ClassType = t; NetworkMessage msg = Activator.CreateInstance(t) as NetworkMessage; info.IsCustomPacked = msg.CustomPack(); MessageIDs.Add(id, info); } catch (Exception /*ex*/) { } } } }
public static NetworkMessage ParseMessage(NetIncomingMessage msg) { if (msg.LengthBytes < sizeof(int)) { return(NetworkMessage.Empty); } int id = msg.ReadInt32(); MessageTypeInfo t = null; lock (MessageIDs) { if (MessageIDs.ContainsKey(id)) { t = MessageIDs[id]; } } if (t == null) { return(NetworkMessage.Empty); } NetworkMessage outMsg = null; outMsg = (NetworkMessage)Activator.CreateInstance(t.ClassType); if (t.IsCustomPacked) { outMsg.Unpack(msg); } else { msg.ReadAllFields(outMsg); } return(outMsg); }