/// <summary> /// 获取xml节点列表 /// </summary> /// <returns></returns> public static void GetXmlConfig(XDCMessage CurrentMessage) { string[] tempArrary = CurrentMessage.MsgASCIIStringFields; XmlNode root = null; string attrID = ""; //1NDC|2DDC string attrProtocolType = "2"; //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 //DDC的状态、屏幕、FIT等,有 tempArrary[3]做为commandCode commandCode = tempArrary[3].Substring(0, 1); MessageIdentifier = tempArrary[3].Substring(1, 1); attrID = "3FSFSFS" + commandCode + MessageIdentifier; cur = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType); if (null == cur) { 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 = ""; } MessageIdentifier = 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"; if (CurrentMessage.MsgASCIIString.Contains(XDCSplictorChar.FS + "'")) { MessageIdentifier = "'"; } 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; } CurrentNode = cur; }
/// <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 List <ParsRowView> GetView(string parsText) { List <ParsRowView> result = new List <ParsRowView>(); //NDC OR DDC string attrProtocolType = "0"; //State string attrDataType = "3"; XmlNode cur = XDCUnity.GetNodeDetail(XDCUnity.Root, attrProtocolType, attrDataType); if (cur == null) { //NDC OR DDC attrProtocolType = "0"; cur = XDCUnity.GetNodeDetail(XDCUnity.Root, attrProtocolType, attrDataType); } if (cur != null) { //each 3 bit for one group,this values will be used as the base value to calculate for hex. List <string> parsTextInList = new List <string>(); string SingFieldText = string.Empty; for (int i = 0; i < parsText.Length; i++) { SingFieldText += parsText[i]; if ((i + 1) % 3 == 0) { parsTextInList.Add(SingFieldText); SingFieldText = ""; } } string tempValue = ""; string tempValueBeforHex = ""; int listIndex = 0; foreach (XmlNode item in cur.ChildNodes) { TemplateView tv = new TemplateView(); XmlAttribute fieldName = item.Attributes["Name"]; XmlAttribute fieldSize = item.Attributes["Size"]; ParsRowView prv = new ParsRowView(); tempValue = ""; tempValueBeforHex = ""; int size; int.TryParse(fieldSize.Value, out size); int realSize = size / 3;// 3 bit to calculate for hex value--frde 20151117 string tempComment = ""; for (int i = 0; i < realSize; i++) { try { //可能缺少数据的情况 tempValue += int.Parse(parsTextInList[listIndex]).ToString("X2"); tempValueBeforHex += parsTextInList[listIndex]; } catch { tempComment = "Invalid Length"; } finally { listIndex++; } } if (string.IsNullOrEmpty(tempComment) && item.HasChildNodes) { foreach (XmlNode commentItem in item.ChildNodes) { string commentValue = commentItem.InnerText; string commentText = commentItem.Attributes["Comment"].Value; XmlAttribute commentIsOperation = commentItem.Attributes["Operation"]; if (null != commentIsOperation) { if (commentIsOperation.Value.StartsWith("&")) { //&运算 string ampValue = commentIsOperation.Value.Replace("&", ""); int ampResult = int.Parse(tempValueBeforHex) & int.Parse(ampValue); //string hexValue = ampResult.ToString("X2"); if (ampResult == int.Parse(commentValue)) { tempComment = commentText; break; } } } else if (tempValue.Equals(commentValue.Trim())) { tempComment = commentText; } } } result.Add(new ParsRowView(fieldName.Value.ToString(), tempValue, tempComment)); } return(result); } else { return(null); } }
public List <ParsRowView> GetView(string parsText) { List <ParsRowView> result = new List <ParsRowView>(); //NDC string attrProtocolType = "2"; //State string attrDataType = "1"; string attrKey = ""; if (parsText.Contains(" ")) { attrKey = parsText.Substring(0, parsText.IndexOf(" ")); } else { attrKey = parsText.Substring(0, 1); } XmlNode cur = XDCUnity.GetNodeDetail(XDCUnity.Root, attrKey, attrProtocolType, attrDataType); if (cur == null) { //NDC OR DDC attrProtocolType = "0"; cur = XDCUnity.GetNodeDetail(XDCUnity.Root, attrKey, attrProtocolType, attrDataType); } if (cur != null) { int curIndex = 0; foreach (XmlNode item in cur.ChildNodes) { TemplateView tv = new TemplateView(); XmlAttribute fieldName = item.Attributes["Name"]; XmlAttribute fieldSize = item.Attributes["Size"]; ParsRowView prv = new ParsRowView(); int size; int.TryParse(fieldSize.Value, out size); string tempValue = ""; string tempComment = ""; try { tempValue = parsText.Substring(curIndex, size); curIndex += size; } catch { if (parsText.Length - curIndex > 0) { tempValue = parsText.Substring(curIndex, parsText.Length - curIndex); } else { tempValue = ""; } tempComment = "Invalid Length"; curIndex += size; } if (string.IsNullOrEmpty(tempComment) && item.HasChildNodes) { bool isFindComment = false; bool isStartFound = false; foreach (XmlNode commentItem in item.ChildNodes) { string commentValue = commentItem.InnerText; string commentText = commentItem.Attributes["Comment"].Value; if (tempValue.Equals(commentValue.Trim()) || commentValue.Trim() == "*") { tempComment = commentText; isFindComment = true; break; } } if (!isFindComment) { tempComment = "UnKnow Value"; } } result.Add(new ParsRowView(fieldName.Value.ToString(), tempValue, tempComment)); } return(result); } else { return(null); } }
public List <ParsRowView> GetView(string parsText) { List <ParsRowView> result = new List <ParsRowView>(); //NDC string attrProtocolType = "1"; //State string attrDataType = "1"; string attrKey = parsText.Substring(0, 1); XmlNode cur = XDCUnity.GetNodeDetail(XDCUnity.Root, attrKey, attrProtocolType, attrDataType); if (cur == null) { //NDC OR DDC attrProtocolType = "0"; cur = XDCUnity.GetNodeDetail(XDCUnity.Root, attrKey, attrProtocolType, attrDataType); } if (cur != null) { int curIndex = 0; foreach (XmlNode item in cur.ChildNodes) { TemplateView tv = new TemplateView(); XmlAttribute fieldName = item.Attributes["Name"]; XmlAttribute fieldSize = item.Attributes["Size"]; ParsRowView prv = new ParsRowView(); int size; int.TryParse(fieldSize.Value, out size); string tempComment = ""; string tempValue = ""; try { tempValue = parsText.Substring(curIndex, size); curIndex += size; } catch { if (parsText.Length - curIndex > 0) { tempValue = parsText.Substring(curIndex, parsText.Length - curIndex); } else { tempValue = ""; } tempComment = "Invalid Length"; curIndex += size; } if (string.IsNullOrEmpty(tempComment) && item.HasChildNodes) { bool isFindComment = false; foreach (XmlNode commentItem in item.ChildNodes) { string commentValue = commentItem.InnerText; string commentText = commentItem.Attributes["Comment"].Value; XmlAttribute attrOperation = commentItem.Attributes["Operation"]; if (attrOperation != null && attrOperation.Value.StartsWith("&")) { //&运算 //<Value Comment="Active FDK C" Operation="&4">4</Value> string ampValue = attrOperation.Value.Replace("&", ""); int ampResult = int.Parse(ampValue) & int.Parse(tempValue); if (ampResult.ToString() == commentValue) { tempComment += commentText + ";"; isFindComment = true; } } else if (tempValue.Equals(commentValue.Trim())) { tempComment = commentText; isFindComment = true; break; } } if (!isFindComment) { tempComment = "UnKnow Value"; } } result.Add(new ParsRowView(fieldName.Value.ToString(), tempValue, tempComment)); } return(result); } else { return(null); } }