public void ReplaceGroupTest() { Group g1 = new Group(100, 200); Group g2 = new Group(100, 201); FieldMap fm = new FieldMap(); fm.AddGroup(g1); fm.AddGroup(g2); Assert.That(fm.GetGroup(1, 100), Is.EqualTo(g1)); Assert.That(fm.GetGroup(2, 100), Is.EqualTo(g2)); Group g3 = new Group(100, 202); Assert.Throws(typeof(FieldNotFoundException), delegate { fieldmap.ReplaceGroup(0, 101, g3); }); Assert.Throws(typeof(FieldNotFoundException), delegate { fieldmap.ReplaceGroup(3, 100, g3); }); Assert.Throws(typeof(FieldNotFoundException), delegate { fieldmap.ReplaceGroup(1, 101, g3); }); fm.ReplaceGroup(1, 100, g3); fm.ReplaceGroup(2, 100, g3); Assert.That(fm.GetGroup(1, 100), Is.EqualTo(g3)); Assert.That(fm.GetGroup(2, 100), Is.EqualTo(g3)); }
private static void DecodeFieldMap(string prefix, DataDictionary dd, StringBuilder str, string msgType, FieldMap fieldMap) { foreach (var kvp in fieldMap) { if (dd.IsGroup(msgType, kvp.Key)) { continue; } var field = dd.FieldsByTag[kvp.Key]; var value = fieldMap.GetString(field.Tag); if (dd.FieldHasValue(field.Tag, value)) { value = $"{field.EnumDict[value]} ({value})"; } str.AppendFormat("{0}{1} = {2};\n", prefix, field.Name, value); } foreach (var groupTag in fieldMap.GetGroupTags()) { var groupField = dd.FieldsByTag[groupTag]; str.AppendFormat("{0}{1} (count {2}) {{\n", prefix, groupField.Name, fieldMap.GetInt(groupTag)); for (var i = 1; i <= fieldMap.GetInt(groupTag); i++) { var group = fieldMap.GetGroup(i, groupTag); var groupPrefix = prefix + " "; str.AppendFormat("{0}{{\n", groupPrefix); DecodeFieldMap(groupPrefix + " ", dd, str, msgType, group); str.AppendFormat("{0}}},\n", groupPrefix); } str.Remove(str.Length - 2, 1); // Remove last "," str.AppendFormat("{0}}};\n", prefix); } }
public void AddGetGroupTest() { Group g1 = new Group(100, 200); Group g2 = new Group(100, 201); FieldMap fm = new FieldMap(); fm.AddGroup(g1); fm.AddGroup(g2); Assert.That(fm.GetGroup(1, 100), Is.EqualTo(g1)); Assert.That(fm.GetGroup(2, 100), Is.EqualTo(g2)); Assert.Throws(typeof(FieldNotFoundException), delegate { fieldmap.GetGroup(0, 101); }); Assert.Throws(typeof(FieldNotFoundException), delegate { fieldmap.GetGroup(3, 100); }); Assert.Throws(typeof(FieldNotFoundException), delegate { fieldmap.GetGroup(1, 101); }); }
public void AddGroupKeepTypeTest() { // bug found during issue 56 - Group object was losing type after being added FieldMap fm = new FieldMap(); QuickFix.FIX42.News.LinesOfTextGroup linesGroup = new QuickFix.FIX42.News.LinesOfTextGroup(); linesGroup.Text = new QuickFix.Fields.Text("foo"); fm.AddGroup(linesGroup); var rvGroup = fm.GetGroup(1, Tags.LinesOfText); Assert.IsInstanceOf<QuickFix.FIX42.News.LinesOfTextGroup>(rvGroup); }
private void ProcessFieldMapToJSON(string sNode, StringBuilder sb, FieldMap fieldMap, string origChkSum = null) { Type fieldType; sb.Append($@"""{sNode}"":"); foreach (var field in fieldMap) { if (dataDictionary.TryGetFieldType(field.Key, out fieldType)) { FIXDictionary.DDField ddField = dataDictionary.FieldsByTag[field.Key]; child = new XElement(ddField.Name); child.Add(new XAttribute("Tag", field.Key)); child.Add(new XAttribute("Value", field.Value)); if (ddField.HasEnums()) { child.Add(new XAttribute("HasEnums", true)); string enumTranslation = ddField.EnumDict.FirstOrDefault(t => t.Key == field.Value.ToString()).Value; if (!string.IsNullOrEmpty(enumTranslation)) { child.Add(new XAttribute("EnumTranslation", enumTranslation)); } } if (field.Key == Tags.CheckSum && origChkSum != null) { child.Add(new XAttribute("OrigChks", origChkSum)); } int groupCount = fieldMap.GroupCount(field.Key); if (groupCount > 0) { child.Add(new XAttribute("IsGroup", "Y")); child.Add(new XAttribute("GroupsCount", groupCount)); for (int i = 1; i <= groupCount; i++) { Group currGroup = fieldMap.GetGroup(i, field.Key); ProcessFieldMapToXML(child, currGroup); } } } else { child = new XElement("UserDefined_" + field.Key.ToString()); child.Add(new XAttribute("Tag", field.Key)); child.Add(new XAttribute("Value", field.Value)); } parent.Add(child); } sb.Append("}"); }
public void AddGroupKeepTypeTest() { // bug found during issue 56 - Group object was losing type after being added FieldMap fm = new FieldMap(); QuickFix.FIX42.News.LinesOfTextGroup linesGroup = new QuickFix.FIX42.News.LinesOfTextGroup(); linesGroup.Text = new QuickFix.Fields.Text("foo"); fm.AddGroup(linesGroup); var rvGroup = fm.GetGroup(1, Tags.LinesOfText); Assert.IsInstanceOf <QuickFix.FIX42.News.LinesOfTextGroup>(rvGroup); }
public void Iterate(FieldMap map, string msgType) { DataDictionary.CheckHasNoRepeatedTags(map); // check non-group fields int lastField = 0; foreach (KeyValuePair <int, Fields.IField> kvp in map) { Fields.IField field = kvp.Value; if (lastField != 0 && field.Tag == lastField) { throw new RepeatedTag(lastField); } CheckHasValue(field); if (!string.IsNullOrEmpty(this.Version)) { CheckValidFormat(field); if (ShouldCheckTag(field)) { CheckValidTagNumber(field.Tag); CheckValue(field); if (!Message.IsHeaderField(field.Tag, this) && !Message.IsTrailerField(field.Tag, this)) { CheckIsInMessage(field, msgType); CheckGroupCount(field, map, msgType); } } } lastField = field.Tag; } // check contents of each group foreach (int groupTag in map.GetGroupTags()) { if (!Message.IsHeaderField(groupTag, this) && !Message.IsTrailerField(groupTag, this)) { for (int i = 1; i <= map.GroupCount(groupTag); i++) { Group g = map.GetGroup(i, groupTag); DDGrp ddg = this.Messages[msgType].GetGroup(groupTag); IterateGroup(g, ddg, msgType); } } } }
public void Iterate(FieldMap map, string msgType) { DataDictionary.CheckHasNoRepeatedTags(map); // check non-group fields int lastField = 0; foreach (KeyValuePair<int, Fields.IField> kvp in map) { Fields.IField field = kvp.Value; if (lastField != 0 && field.Tag == lastField) throw new RepeatedTag(lastField); CheckHasValue(field); if (null != this.Version && this.Version.Length > 0) { CheckValidFormat(field); if (ShouldCheckTag(field)) { CheckValidTagNumber(field.Tag); CheckValue(field); if (!Message.IsHeaderField(field.Tag, this) && !Message.IsTrailerField(field.Tag, this)) { CheckIsInMessage(field, msgType); CheckGroupCount(field, map, msgType); } } } lastField = field.Tag; } // check contents of each group foreach (int groupTag in map.GetGroupTags()) { for (int i = 1; i <= map.GroupCount(groupTag); i++) { Group g = map.GetGroup(i, groupTag); DDGrp ddg = this.Messages[msgType].GetGroup(groupTag); IterateGroup(g, ddg, msgType); } } }
public string toXMLFields(FieldMap fields, int space) { StringBuilder s = new StringBuilder(); string name = string.Empty; // fields foreach (var f in fields) { s.Append("<field "); if ((dataDictionary_ != null) && ( dataDictionary_.FieldsByTag.ContainsKey(f.Key))) { s.Append("name=\"" + dataDictionary_.FieldsByTag[f.Key].Name + "\" "); } s.Append("number=\"" + f.Key.ToString() + "\">"); s.Append("<![CDATA[" + f.Value.ToString() + "]]>"); s.Append("</field>"); } // now groups List<int> groupTags = fields.GetGroupTags(); foreach (int groupTag in groupTags) { for (int counter = 1; counter <= fields.GroupCount(groupTag); counter++) { s.Append("<group>"); s.Append( toXMLFields( fields.GetGroup(counter, groupTag), space+1)); s.Append("</group>"); } } return s.ToString(); }