/// <summary> /// 获取xml节点列表 /// </summary> /// <returns></returns> public static List <TemplateView> GetXmlConfig(XDCMessage CurrentMessage) { string[] tempArrary = CurrentMessage.MsgASCIIStringFields; XmlNode root = null; string attrID = ""; //1NDC|2DDC string attrProtocolType = "1"; //1State //2Screen //3Fit //4Message string attrDataType = "4"; XmlNode cur = null; string commandCode = ""; string MessageIdentifier = ""; int sdIndex = 3; root = XMLHelper.instance.XMLFiles["ProtocolTemplate"].XmlDoc.SelectSingleNode("ProtocolTemplate"); switch (CurrentMessage.MsgType) { case MessageType.DataCommand: { #region 3x_DataCommand commandCode = tempArrary[3].Substring(0, 1); MessageIdentifier = commandCode; attrID = "3FSFSFS" + commandCode; cur = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType); if (null == cur) { //通常查询xml文件中ID=1的配置 attrID = tempArrary[0].Substring(0, 1); cur = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType); } #endregion } break; case MessageType.TerminalCommand: { #region 1x_TerminalCommand commandCode = tempArrary[3].Substring(0, 1); //TerminalCommand消息中,MessageIdentifier的值等于commandCode,因为 //TerminalCommand消息LUNO号后只有一个FS MessageIdentifier = commandCode; attrID = "1FSFSFS" + commandCode; cur = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType); if (null == cur) { //通常查询xml文件中ID=1的配置 attrID = tempArrary[0].Substring(0, 1); cur = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType); } #endregion } break; case MessageType.SolicitedMessage: { #region 22||23_SolicitedMessage attrID = tempArrary[0] + "FSFSFS"; int fsCount = 3; try { commandCode = tempArrary[sdIndex].Substring(0, 1); } catch { commandCode = ""; } if (tempArrary.Length > sdIndex + 1) { MessageIdentifier = tempArrary[sdIndex + 1].Substring(0, 1); } attrID += commandCode; string tempXMLid = ""; string miString = ""; if (commandCode == "8" || commandCode == "C" || commandCode == "F") { miString = "FS" + MessageIdentifier; fsCount++; } int maxFsCountRear = tempArrary.Length - fsCount - 1; //最多的FS,并逐个递减 while (maxFsCountRear > -1) { tempXMLid = attrID + miString + XDCUnity.GetFS(maxFsCountRear); cur = XDCUnity.GetNodeDetail(root, tempXMLid, attrProtocolType, attrDataType); if (null != cur) { break; } maxFsCountRear--; } //如果还未空,去掉MessageIdentifier if (null == cur) { tempXMLid = attrID; cur = XDCUnity.GetNodeDetail(root, tempXMLid, attrProtocolType, attrDataType); if (null == cur) { tempXMLid = tempArrary[0]; cur = XDCUnity.GetNodeDetail(root, tempXMLid, attrProtocolType, attrDataType); } } #endregion } break; case MessageType.UnSolicitedMessage: { #region 12||11_UnSolicitedMessage try { commandCode = tempArrary[3].Substring(0, 1); } catch { commandCode = ""; } attrID = tempArrary[0] + "FSFSFS" + commandCode; if (tempArrary[0].Equals("11")) { try { MessageIdentifier = tempArrary[13].Substring(0, 1); } catch { MessageIdentifier = ""; } } cur = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType); if (null == cur) { attrID = tempArrary[0]; cur = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType); } #endregion } break; case MessageType.TransactionReplyCommand: { #region 4_TransactionReplyCommand attrID = "4"; cur = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType); #endregion } break; case MessageType.UploadEJMessage: { #region 6x_UploadEJMessage try { commandCode = tempArrary[3].Substring(0, 1); MessageIdentifier = commandCode; } catch { commandCode = ""; MessageIdentifier = commandCode; } attrID = tempArrary[0].Substring(0, tempArrary[0].Length); cur = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType); if (null == cur) { attrID = tempArrary[0].Substring(0, 1); cur = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType); } #endregion } break; case MessageType.ExitToHostMessages: { } break; case MessageType.HostToExitMessages: { #region 7_HostToExitMessages attrID = tempArrary[0].Substring(0, 1); cur = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType); #endregion } break; case MessageType.Unknow: break; default: break; } if (null == cur) { return(null); } bool alreadyFS_X = true;; List <TemplateView> TvList = new List <TemplateView>(); foreach (XmlNode item in cur.ChildNodes) { TemplateView tv = new TemplateView(); XmlAttribute fieldName = item.Attributes["Name"]; XmlAttribute fieldSize = item.Attributes["Size"]; if (fieldName != null) { tv.FieldName = fieldName.Value; } if ((tv.FieldName.StartsWith("FS") && tv.FieldName.Length > 2) || (tv.FieldName.StartsWith("GS") && tv.FieldName.Length > 2)) { if (tv.FieldName.Contains('|')) { bool isFoundInnerFS = false; string[] fsSpliterArray = tv.FieldName.Replace("FS", "").Split('|'); foreach (string fsSpliterStr in fsSpliterArray) { if (MessageIdentifier == fsSpliterStr) { tv.FieldName = "FS"; isFoundInnerFS = true; alreadyFS_X = true; break; } else { isFoundInnerFS = false; } } if (!isFoundInnerFS) { continue; } } else if (tv.FieldName.Equals("FS" + "*")) { //找到FS* tv.FieldName = "FS*"; alreadyFS_X = true; } //已FS开头,但是不等於FS/GS的需要越过两行 else if (!tv.FieldName.Equals("FS" + MessageIdentifier) && !tv.FieldName.Equals("GS" + MessageIdentifier)) { alreadyFS_X = false; continue; } else { tv.FieldName = tv.FieldName.Substring(0, 2); alreadyFS_X = true; } } else if (tv.FieldName.Equals("FS")) { alreadyFS_X = true; } if (!alreadyFS_X) { continue; } if (fieldSize != null) { int fSize; bool isNumeric = int.TryParse(fieldSize.Value, out fSize); if (isNumeric) { tv.FieldSize = fSize; } else { //非数字的情况,如* tv.FieldSize = -1; } } if (item.HasChildNodes) { Dictionary <string, string> dic = new Dictionary <string, string>(); foreach (XmlNode valueItem in item.ChildNodes) { XmlAttribute attrComment = valueItem.Attributes["Comment"]; XmlAttribute attrOperation = valueItem.Attributes["Operation"]; if (attrOperation != null) { //进行&运算 if (attrOperation.Value.StartsWith("&")) { //&运算 string ampValue = attrOperation.Value.Replace("&", ""); dic.Add(valueItem.InnerText + "&" + ampValue, attrComment.Value); } } else if (null != attrComment && !dic.ContainsKey(valueItem.InnerText)) { dic.Add(valueItem.InnerText, attrComment.Value); } if (valueItem.InnerText != "*") { tv.FieldSize = valueItem.InnerText.Length > tv.FieldSize ? valueItem.InnerText.Length : tv.FieldSize; } } tv.FieldValue = dic; } TvList.Add(tv); } return(TvList); }
public static List <ParsRowView> GetViewList(XDCMessage XDCmsg, string msgCurrentFieldContent, int currentFSindex, ref int currXmlNodeIndex) { #region 修复12消息解析错误的问题 if (string.IsNullOrEmpty(msgCurrentFieldContent) && CurrentNode != null && CurrentNode.ChildNodes.Count > currXmlNodeIndex) { XmlAttribute fieldName = CurrentNode.ChildNodes[currXmlNodeIndex].Attributes["Name"]; if (fieldName != null && fieldName.Value.StartsWith("FS")) { //解决存款消息中,310,311等buffer先生不正确的问题。edit by frde 20160106 currXmlNodeIndex += 1; return(null); } } #endregion List <ParsRowView> rowViewList = new List <ParsRowView>(); List <TemplateView> TvList = new List <TemplateView>(); int FSCountIndex = 0; bool isFSrepeat = false; bool isFoundFS_x = false; bool isOccurFS_x = false; int tempIndex = currXmlNodeIndex; if (CurrentNode == null) { return(rowViewList); } for (int i = tempIndex; i < CurrentNode.ChildNodes.Count; i++) { if (!isFSrepeat) { currXmlNodeIndex++; } TemplateView tv = new TemplateView(); XmlAttribute fieldName = CurrentNode.ChildNodes[i].Attributes["Name"]; XmlAttribute fieldSize = CurrentNode.ChildNodes[i].Attributes["Size"]; if (fieldName != null) { if (fieldName.Value.ToString() == "FS") { isOccurFS_x = false; FindFinalFS(ref rowViewList, ref TvList, ref isFoundFS_x, msgCurrentFieldContent); break; } else if (fieldName.Value.ToString().StartsWith("FS")) { isOccurFS_x = true; //if(string.IsNullOrEmpty(msgCurrentFieldContent)) //{ // FindFinalFS(ref rowViewList, ref TvList, ref isFoundFS_x, msgCurrentFieldContent); // currXmlNodeIndex = currXmlNodeIndex - 1; // isOccurFS_x = false; // break; //} if (TvList != null && TvList.Count > 0) { FindFinalFS(ref rowViewList, ref TvList, ref isFoundFS_x, msgCurrentFieldContent); currXmlNodeIndex = currXmlNodeIndex - 1; isOccurFS_x = false; break; } //FS*表示除了枚举的情况之外的所有通用情况 if (fieldName.Value == "FS*") { isOccurFS_x = false; if (TvList != null && TvList.Count > 0) { FindFinalFS(ref rowViewList, ref TvList, ref isFoundFS_x, msgCurrentFieldContent); break; } } else if (fieldName.Value == "FS**") { currXmlNodeIndex = currXmlNodeIndex - 1; isFSrepeat = true; isOccurFS_x = false; if (TvList != null && TvList.Count > 0) { FindFinalFS(ref rowViewList, ref TvList, ref isFoundFS_x, msgCurrentFieldContent); break; } } else { //如果当前消息域为空,且接下来都不是直接的FS,则直接跳过,XML节点下标向上跳回一个 //if (string.IsNullOrEmpty(msgCurrentFieldContent)) //{ // currXmlNodeIndex = currXmlNodeIndex - 1; // break; // //isFoundFS_x = false; // //continue; //} isFoundFS_x = false; string tempcontent = msgCurrentFieldContent; string tempStringBehind = fieldName.Value.Substring(2, fieldName.Value.Length - 2); string[] identifyArray = tempStringBehind.Split('|'); int tempLength = 0; string tempIde = ""; foreach (string ideItem in identifyArray) { tempLength = ideItem.Length; try { tempIde = tempcontent.Substring(0, tempLength); } catch { tempIde = ""; } if (tempIde == ideItem) { isFoundFS_x = true; TvList.Clear(); break; } } if (isFoundFS_x) { if (TvList != null && TvList.Count > 0) { FindFinalFS(ref rowViewList, ref TvList, ref isFoundFS_x, msgCurrentFieldContent); TvList.Clear(); break; } FSCountIndex++; } else { } } } else { //出现FS_x但是又没匹配上,接下来的都跳过 if (isOccurFS_x && !isFoundFS_x) { continue; } #region 普通节点,加入列表中( 永远为当前一个FS中的内容 ) tv.FieldName = fieldName.Value; int size; int.TryParse(fieldSize.Value, out size); tv.FieldSize = size; if (CurrentNode.ChildNodes[i].HasChildNodes) { Dictionary <string, string> dic = new Dictionary <string, string>(); foreach (XmlNode valueItem in CurrentNode.ChildNodes[i].ChildNodes) { XmlAttribute attrComment = valueItem.Attributes["Comment"]; XmlAttribute attrOperation = valueItem.Attributes["Operation"]; if (attrOperation != null) { //进行&运算 if (attrOperation.Value.StartsWith("&")) { //&运算 string ampValue = attrOperation.Value.Replace("&", ""); dic.Add(valueItem.InnerText + "&" + ampValue, attrComment.Value); } } else if (null != attrComment && !dic.ContainsKey(valueItem.InnerText)) { dic.Add(valueItem.InnerText, attrComment.Value); } } tv.FieldValue = dic; } TvList.Add(tv); #endregion } } else { } } if (TvList.Count > 0) { FindFinalFS(ref rowViewList, ref TvList, ref isFoundFS_x, msgCurrentFieldContent); isOccurFS_x = false; } return(rowViewList); }