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);
     }
 }
Пример #2
0
        public void GetIntTest()
        {
            IntField field = new IntField(200, 101);

            fieldmap.SetField(field);
            Assert.That(fieldmap.GetInt(200), Is.EqualTo(101));
            fieldmap.SetField(new StringField(202, "2222"));
            Assert.That(fieldmap.GetInt(202), Is.EqualTo(2222));
            Assert.Throws(typeof(FieldNotFoundException),
                          delegate { fieldmap.GetInt(99900); });
        }
Пример #3
0
 /// <summary>
 /// If <paramref name="field"/> is a group-counter for <paramref name="msgType"/>, check that it is accurate, else do nothing.
 /// </summary>
 /// <param name="field">a group's counter field</param>
 /// <param name="map">the FieldMap that contains the group being checked</param>
 /// <param name="msgType">msg type of message that is/contains <paramref name="map"/></param>
 public void CheckGroupCount(Fields.IField field, FieldMap map, string msgType)
 {
     if (IsGroup(msgType, field.Tag) && map.GetInt(field.Tag) != map.GroupCount(field.Tag))
     {
         throw new RepeatingGroupCountMismatch(field.Tag);
     }
 }
Пример #4
0
        public void GroupDelimTest()
        {
            Group g1 = new Group(100, 200);

            Assert.AreEqual(100, g1.Field); //counter
            Assert.AreEqual(200, g1.Delim);

            g1.SetField(new StringField(200, "delim!"));

            FieldMap fm = new FieldMap();

            fm.AddGroup(g1);
            Assert.AreEqual(1, fm.GetInt(100));

            Group g2 = new Group(100, 200);

            g2.SetField(new StringField(200, "again!"));
            fm.AddGroup(g2);
            Assert.AreEqual(2, fm.GetInt(100));
        }
Пример #5
0
 /// <summary>
 /// If <paramref name="field"/> is a group-counter for <paramref name="msgType"/>, check that it is accurate, else do nothing.
 /// </summary>
 /// <param name="field">a group's counter field</param>
 /// <param name="map">the FieldMap that contains the group being checked</param>
 /// <param name="msgType">msg type of message that is/contains <paramref name="map"/></param>
 public void CheckGroupCount(Fields.IField field, FieldMap map, string msgType)
 {
     if(IsGroup(msgType, field.Tag))
     {
         if (map.GetInt(field.Tag) != map.GroupCount(field.Tag))
         {
             throw new RepeatingGroupCountMismatch(field.Tag);
         }
     }
 }
Пример #6
0
        public void GroupDelimTest()
        {
            Group g1 = new Group(100, 200);
            Assert.AreEqual(100, g1.Field); //counter
            Assert.AreEqual(200, g1.Delim);

            g1.SetField(new StringField(200, "delim!"));

            FieldMap fm = new FieldMap();
            fm.AddGroup(g1);
            Assert.AreEqual(1, fm.GetInt(100));

            Group g2 = new Group(100, 200);
            g2.SetField(new StringField(200, "again!"));
            fm.AddGroup(g2);
            Assert.AreEqual(2, fm.GetInt(100));
        }