private static void FindFinalFS(ref List <ParsRowView> rowViewList, ref List <TemplateView> TvList, ref bool isFoundFS_x, string msgCurrentFieldContent) { string[] gsGroup = msgCurrentFieldContent.Split(XDCSplictorChar.GS); if (gsGroup.Length > 1) { //GS情况 FindFinalGS(ref rowViewList, ref TvList, msgCurrentFieldContent); //SetFS_GS_(ref rowViewList, TvList, "GS", gsGroup); } else { #region 正是当前要找的FS int currentContentIndex = 0; foreach (TemplateView tvItem in TvList) { ParsRowView prv = new ParsRowView(); prv.FieldName = tvItem.FieldName; //加上prv.FieldName == "GS**"的判断,解决显示GS**行而内容又为空的情况。edit by frde 20160106 if ((prv.FieldName == "GS" || prv.FieldName == "GS**") && msgCurrentFieldContent.Length == currentContentIndex) { break; } try { if (tvItem.FieldSize <= 0 || msgCurrentFieldContent.Length < tvItem.FieldSize - currentContentIndex) { prv.FieldValue = msgCurrentFieldContent.Substring(currentContentIndex, msgCurrentFieldContent.Length - currentContentIndex); } else { prv.FieldValue = msgCurrentFieldContent.Substring(currentContentIndex, tvItem.FieldSize); } } catch { prv.FieldValue = ""; } if (tvItem.FieldValue != null) { if (string.IsNullOrEmpty(prv.FieldValue)) { prv.FieldComment = ""; } else if (tvItem.FieldValue.ContainsKey(prv.FieldValue)) { prv.FieldComment = tvItem.FieldValue[prv.FieldValue]; } else if (tvItem.FieldValue.ContainsKey("*")) { prv.FieldComment = tvItem.FieldValue["*"]; } else { bool isFind = false; foreach (KeyValuePair <string, string> kvpItem in tvItem.FieldValue) { //&运算 if (kvpItem.Key.Contains("&")) { try { isFind = true; string ampValue = kvpItem.Key.Substring(0, kvpItem.Key.IndexOf("&")); string ampOperator = kvpItem.Key.Substring(kvpItem.Key.IndexOf("&") + 5, kvpItem.Key.Length - kvpItem.Key.IndexOf("&") - 5); int ampResult = int.Parse(prv.FieldValue) & int.Parse(ampOperator); if (ampResult.ToString() == ampValue) { prv.FieldComment += kvpItem.Value + ";"; } } catch { prv.FieldComment = ""; } } } if (!isFind) { prv.FieldComment = "UnKnow Value"; } } } else { prv.FieldComment = ""; } rowViewList.Add(prv); if (tvItem.FieldSize <= 0) { currentContentIndex += msgCurrentFieldContent.Length - currentContentIndex; } else { currentContentIndex += tvItem.FieldSize; } } TvList.Clear(); #endregion } TvList.Clear(); isFoundFS_x = false; }
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); } }
private static void FindFinalFS(ref List <ParsRowView> rowViewList, ref List <TemplateView> TvList, ref bool isFoundFS_x, string msgCurrentFieldContent) { string[] gsGroup = msgCurrentFieldContent.Split(XDCSplictorChar.GS); if (gsGroup.Length > 1) { //GS情况 FindFinalGS(ref rowViewList, ref TvList, msgCurrentFieldContent); //SetFS_GS_(ref rowViewList, TvList, "GS", gsGroup); } else { #region 正是当前要找的FS int currentContentIndex = 0; foreach (TemplateView tvItem in TvList) { if (tvItem.FieldName == "ICC data objects (and Further ICC data objects) requested by Central") { #region 生成IC卡数据提示行 ParsRowView ic = new ParsRowView(); ic.FieldName = "IC"; ic.FieldComment = tvItem.FieldName; rowViewList.Add(ic); #endregion string tempvalueAll = msgCurrentFieldContent.Substring(currentContentIndex, msgCurrentFieldContent.Length - currentContentIndex); string tempAll = tempvalueAll; string key = "tagMeaning"; bool isFirst = true; string sub_4 = tempAll.Substring(0, 4); string sub_2 = tempAll.Substring(0, 2); string tagIniPath = XDCUnity.CurrentPath + @"\Config\Protocol\TagList.ini"; string tagMeaning = XDCUnity.ReadIniData(sub_4, key, "", tagIniPath); int currentLen = -1; string tagName = string.Empty; while (tempAll.Length > 0) { if (!isFirst) { ParsRowView tg = new ParsRowView(); tg.FieldName = "TG"; rowViewList.Add(tg); } isFirst = false; sub_4 = tempAll.Substring(0, 4); sub_2 = tempAll.Substring(0, 2); tagMeaning = XDCUnity.ReadIniData(sub_4, key, "", tagIniPath); currentLen = -1; tagName = string.Empty; if (!string.IsNullOrEmpty(tagMeaning)) { currentLen = 4; tagName = sub_4; } else { //长度为4的tag找不到,找长度为2的。 tagMeaning = XDCUnity.ReadIniData(sub_2, key, "", tagIniPath); if (string.IsNullOrEmpty(tagMeaning)) { break; } currentLen = 2; tagName = sub_2; } #region 增加行 //tagName tempAll = tempAll.Substring(currentLen, tempAll.Length - currentLen); ParsRowView prv_tagName = new ParsRowView(); prv_tagName.FieldName = "TagName"; prv_tagName.FieldComment = tagMeaning; prv_tagName.FieldValue = tagName; rowViewList.Add(prv_tagName); //tagLen string len = tempAll.Substring(0, 2); tempAll = tempAll.Substring(2, tempAll.Length - 2); ParsRowView prv_tagLen = new ParsRowView(); prv_tagLen.FieldName = "ValueLength"; prv_tagLen.FieldComment = "Hex"; prv_tagLen.FieldValue = len; rowViewList.Add(prv_tagLen); //tagValue int valueLen = Convert.ToInt32(len, 16); string value = tempAll.Substring(0, valueLen * 2); tempAll = tempAll.Substring(valueLen * 2, tempAll.Length - valueLen * 2); ParsRowView prv_tagValue = new ParsRowView(); prv_tagValue.FieldName = "Value"; prv_tagValue.FieldComment = ""; prv_tagValue.FieldValue = value; rowViewList.Add(prv_tagValue); #endregion } } else { #region MyRegion ParsRowView prv = new ParsRowView(); prv.FieldName = tvItem.FieldName; //加上prv.FieldName == "GS**"的判断,解决显示GS**行而内容又为空的情况。edit by frde 20160106 if (/*(prv.FieldName == "GS" || prv.FieldName == "GS**")*/ prv.FieldName.StartsWith("GS") /* && msgCurrentFieldContent.Length == currentContentIndex*/) { break; } try { if (tvItem.FieldSize <= 0) { prv.FieldValue = msgCurrentFieldContent.Substring(currentContentIndex, msgCurrentFieldContent.Length - currentContentIndex); } else { prv.FieldValue = msgCurrentFieldContent.Substring(currentContentIndex, tvItem.FieldSize); } } catch { prv.FieldValue = ""; } if (tvItem.FieldValue != null) { if (string.IsNullOrEmpty(prv.FieldValue)) { prv.FieldComment = ""; } else if (tvItem.FieldValue.ContainsKey(prv.FieldValue)) { prv.FieldComment = tvItem.FieldValue[prv.FieldValue]; } else if (tvItem.FieldValue.ContainsKey("*")) { prv.FieldComment = tvItem.FieldValue["*"]; } else { bool isFind = false; foreach (KeyValuePair <string, string> kvpItem in tvItem.FieldValue) { //&运算 if (kvpItem.Key.Contains("&")) { try { isFind = true; string ampValue = kvpItem.Key.Substring(0, kvpItem.Key.IndexOf("&")); string ampOperator = kvpItem.Key.Substring(kvpItem.Key.IndexOf("&") + 5, kvpItem.Key.Length - kvpItem.Key.IndexOf("&") - 5); int ampResult = int.Parse(prv.FieldValue) & int.Parse(ampOperator); if (ampResult.ToString() == ampValue) { prv.FieldComment += kvpItem.Value + ";"; } } catch { prv.FieldComment = ""; } } } if (!isFind) { prv.FieldComment = "UnKnow Value"; } } } else { prv.FieldComment = ""; } rowViewList.Add(prv); if (tvItem.FieldSize <= 0) { currentContentIndex += msgCurrentFieldContent.Length - currentContentIndex; } else { currentContentIndex += tvItem.FieldSize; } #endregion } } TvList.Clear(); #endregion } TvList.Clear(); isFoundFS_x = false; }
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 = "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); } }