Example #1
0
        /// <summary>
        /// If field is an enum, make sure the value is valid.
        /// </summary>
        /// <param name="field"></param>
        public void CheckValue(Fields.IField field)
        {
            DDField fld = FieldsByTag[field.Tag];

            if (fld.HasEnums() && !fld.EnumDict.ContainsKey(field.ToString()))
            {
                throw new IncorrectTagValue(field.Tag);
            }
        }
Example #2
0
        private void ParseFields(XmlDocument doc)
        {
            XmlNodeList nodeList = doc.SelectNodes("//fields/field");

            foreach (XmlNode fldEl in nodeList)
            {
                DDField fld = NewField(fldEl);
                FieldsByTag[fld.Tag]   = fld;
                FieldsByName[fld.Name] = fld;
            }
        }
Example #3
0
        private void parseMsgEl(XmlNode node, DDMap ddmap)
        {
            if (!node.HasChildNodes)
            {
                return;
            }
            foreach (XmlNode childNode in node.ChildNodes)
            {
                if (childNode.Name == "field")
                {
                    DDField fld = FieldsByName[childNode.Attributes["name"].Value];
                    if (childNode.Attributes["required"].Value == "Y")
                    {
                        fld.Required = true;
                        ddmap.ReqFields.Add(fld.Tag);
                    }
                    if (!ddmap.IsField(fld.Tag))
                    {
                        ddmap.Fields.Add(fld.Tag, fld);
                    }

                    // if first field in group, make it the DELIM <3 FIX
                    if ((ddmap.GetType() == typeof(DDGrp) && ((DDGrp)ddmap).Delim == 0))
                    {
                        ((DDGrp)ddmap).Delim = fld.Tag;
                    }
                }
                else if (childNode.Name == "group")
                {
                    DDField fld = FieldsByName[childNode.Attributes["name"].Value];
                    DDGrp   grp = new DDGrp();
                    if (childNode.Attributes["required"].Value == "Y")
                    {
                        fld.Required = true;
                        ddmap.ReqFields.Add(fld.Tag);
                        grp.Required = true;
                    }
                    if (!ddmap.IsField(fld.Tag))
                    {
                        ddmap.Fields.Add(fld.Tag, fld);
                    }
                    grp.NumFld = fld.Tag;
                    parseMsgEl(childNode, grp);
                    ddmap.Groups.Add(fld.Tag, grp);
                }
                else if (childNode.Name == "component")
                {
                    String  name     = childNode.Attributes["name"].Value;
                    XmlNode compNode = RootDoc.SelectSingleNode("//components/component[@name='" + name + "']");
                    parseMsgEl(compNode, ddmap);
                }
            }
        }
        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("}");
        }
Example #5
0
        public void ObsoleteConstructor()
        {
            HashSet<String> enums = new HashSet<string>();
            enums.Add("a");
            enums.Add("b");

            DDField ddf = new DDField(5, "Foo", enums, "STRING");

            Assert.AreEqual(String.Empty, ddf.EnumDict["a"]);
            Assert.AreEqual(String.Empty, ddf.EnumDict["b"]);

            //obsolete accessor
            Assert.AreEqual(2,ddf.Enums.Count);
            Assert.IsTrue(ddf.Enums.Contains("a"));
            Assert.IsTrue(ddf.Enums.Contains("b"));
        }
Example #6
0
        public void Constructor()
        {
            Dictionary<String, String> enums = new Dictionary<string, string>();
            enums["a"] = "AAA";
            enums["b"] = "BBB";

            DDField ddf = new DDField(5, "Foo", enums, "STRING");

            Assert.AreEqual(2, ddf.EnumDict.Count);
            Assert.AreEqual("AAA", ddf.EnumDict["a"]);
            Assert.AreEqual("BBB", ddf.EnumDict["b"]);

            //obsolete accessor
            Assert.AreEqual(2, ddf.Enums.Count);
            Assert.IsTrue(ddf.Enums.Contains("a"));
            Assert.IsTrue(ddf.Enums.Contains("b"));
        }
Example #7
0
        /// <summary>
        /// If field is an enum, make sure the value is valid.
        /// </summary>
        /// <param name="field"></param>
        public void CheckValue(Fields.IField field)
        {
            DDField fld = FieldsByTag[field.Tag];

            if (fld.HasEnums())
            {
                if (fld.IsMultipleValueFieldWithEnums)
                {
                    string[] splitted = field.ToString().Split(' ');

                    foreach (string value in splitted)
                    {
                        if (!fld.EnumDict.ContainsKey(value))
                        {
                            throw new IncorrectTagValue(field.Tag);
                        }
                    }
                }
                else if (!fld.EnumDict.ContainsKey(field.ToString()))
                {
                    throw new IncorrectTagValue(field.Tag);
                }
            }
        }
Example #8
0
 public void AddField(DDField fld)
 {
     Fields.Add(fld.Tag, fld);
 }
Example #9
0
        /// <summary>
        /// Parse a message element
        /// </summary>
        /// <param name="node"></param>
        /// <param name="ddmap"></param>
        /// <param name="componentRequired">
        /// If non-null, parsing is inside a component that is required (true) or not (false).
        /// If null, parser is not inside a component.
        /// </param>
        private void ParseMsgEl(XmlNode node, DDMap ddmap, bool?componentRequired)
        {
            /*
             * // This code is great for debugging DD parsing issues.
             * string s = "+ " + node.Name;  // node.Name is probably "message"
             * if (node.Attributes["name"] != null)
             *  s += " | " + node.Attributes["name"].Value;
             * Console.WriteLine(s);
             */

            string messageTypeName = (node.Attributes["name"] != null) ? node.Attributes["name"].Value : node.Name;

            if (!node.HasChildNodes)
            {
                return;
            }
            foreach (XmlNode childNode in node.ChildNodes)
            {
                /*
                 * // Continuation of code that's great for debugging DD parsing issues.
                 * s = "    + " + childNode.Name;  // childNode.Name is probably "field"
                 * if (childNode.Attributes["name"] != null)
                 *  s += " | " + childNode.Attributes["name"].Value;
                 * Console.WriteLine(s);
                 */

                var fieldName = (childNode.Attributes["name"] != null) ? childNode.Attributes["name"].Value : "no-name";

                if (childNode.Name == "field")
                {
                    if (FieldsByName.ContainsKey(fieldName) == false)
                    {
                        throw new Exception(
                                  $"Field '{fieldName}' is used in '{messageTypeName}', but is not defined in <fields> set.");
                    }

                    DDField      fld = FieldsByName[fieldName];
                    XmlAttribute req = childNode.Attributes["required"];
                    if (req != null && req.Value == "Y" &&
                        (componentRequired == null || componentRequired.Value == true))
                    {
                        ddmap.ReqFields.Add(fld.Tag);
                    }
                    if (!ddmap.IsField(fld.Tag))
                    {
                        ddmap.Fields.Add(fld.Tag, fld);
                    }

                    // if first field in group, make it the DELIM
                    if ((ddmap.GetType() == typeof(DDGrp) && ((DDGrp)ddmap).Delim == 0))
                    {
                        ((DDGrp)ddmap).Delim = fld.Tag;
                    }
                }
                else if (childNode.Name == "group")
                {
                    DDField      fld = FieldsByName[fieldName];
                    DDGrp        grp = new DDGrp();
                    XmlAttribute req = childNode.Attributes["required"];
                    if (req != null && req.Value == "Y" &&
                        (componentRequired == null || componentRequired.Value == true))
                    {
                        ddmap.ReqFields.Add(fld.Tag);
                        grp.Required = true;
                    }
                    if (!ddmap.IsField(fld.Tag))
                    {
                        ddmap.Fields.Add(fld.Tag, fld);
                    }
                    grp.NumFld = fld.Tag;
                    ParseMsgEl(childNode, grp);
                    ddmap.Groups.Add(fld.Tag, grp);

                    // if first field in group, make it the DELIM
                    if ((ddmap.GetType() == typeof(DDGrp) && ((DDGrp)ddmap).Delim == 0))
                    {
                        ((DDGrp)ddmap).Delim = fld.Tag;
                    }
                }
                else if (childNode.Name == "component")
                {
                    XmlNode      compNode     = RootDoc.SelectSingleNode("//components/component[@name='" + fieldName + "']");
                    XmlAttribute req          = childNode.Attributes["required"];
                    bool?        compRequired = (req != null && req.Value == "Y");
                    ParseMsgEl(compNode, ddmap, compRequired);
                }
            }
        }
Example #10
0
        /// <summary>
        /// Parse a message element.  Its data is added to parameter `ddmap`.
        /// </summary>
        /// <param name="node">a message, group, or component node</param>
        /// <param name="ddmap">the still-being-constructed DDMap for this node</param>
        /// <param name="componentRequired">
        /// If non-null, parsing is inside a component that is required (true) or not (false).
        /// If null, parser is not inside a component.
        /// </param>
        private void ParseMsgEl(XmlNode node, DDMap ddmap, bool?componentRequired)
        {
            /*
             * // This code is great for debugging DD parsing issues.
             * string s = "+ " + node.Name;  // node.Name is probably "message"
             * if (node.Attributes["name"] != null)
             *  s += " | " + node.Attributes["name"].Value;
             * Console.WriteLine(s);
             */

            string messageTypeName = (node.Attributes["name"] != null) ? node.Attributes["name"].Value : node.Name;

            if (!node.HasChildNodes)
            {
                return;
            }
            foreach (XmlNode childNode in node.ChildNodes)
            {
                /*
                 * // Continuation of code that's great for debugging DD parsing issues.
                 * s = "    + " + childNode.Name;  // childNode.Name is probably "field"
                 * if (childNode.Attributes["name"] != null)
                 *  s += " | " + childNode.Attributes["name"].Value;
                 * Console.WriteLine(s);
                 */

                VerifyChildNode(childNode, node);

                var nameAttribute = childNode.Attributes["name"].Value;

                switch (childNode.Name)
                {
                case "field":
                case "group":
                    if (FieldsByName.ContainsKey(nameAttribute) == false)
                    {
                        throw new DictionaryParseException(
                                  $"Field '{nameAttribute}' is not defined in <fields> section.");
                    }
                    DDField fld = FieldsByName[nameAttribute];

                    bool required = (childNode.Attributes["required"]?.Value == "Y") && componentRequired.GetValueOrDefault(true);

                    if (required)
                    {
                        ddmap.ReqFields.Add(fld.Tag);
                    }

                    if (ddmap.IsField(fld.Tag) == false)
                    {
                        ddmap.Fields.Add(fld.Tag, fld);
                    }

                    // if this is in a group whose delim is unset, then this must be the delim (i.e. first field)
                    if (ddmap is DDGrp ddGroup && ddGroup.Delim == 0)
                    {
                        ddGroup.Delim = fld.Tag;
                    }

                    if (childNode.Name == "group")
                    {
                        DDGrp grp = new DDGrp();
                        grp.NumFld = fld.Tag;
                        if (required)
                        {
                            grp.Required = true;
                        }

                        ParseMsgEl(childNode, grp);
                        ddmap.Groups.Add(fld.Tag, grp);
                    }
                    break;

                case "component":
                    XmlNode compNode = RootDoc.SelectSingleNode("//components/component[@name='" + nameAttribute + "']");
                    ParseMsgEl(compNode, ddmap, (childNode.Attributes["required"]?.Value == "Y"));
                    break;

                default:
                    throw new DictionaryParseException($"Malformed data dictionary: child node type should be one of {{field,group,component}} but is '{childNode.Name}' within parent '{node.Name}/{messageTypeName}'");
                }
            }
        }
Example #11
0
        /// <summary>
        /// Parse a message element
        /// </summary>
        /// <param name="node"></param>
        /// <param name="ddmap"></param>
        /// <param name="componentRequired">
        /// If non-null, parsing is inside a component that is required (true) or not (false).
        /// If null, parser is not inside a component.
        /// </param>
        private void parseMsgEl(XmlNode node, DDMap ddmap, bool?componentRequired)
        {
            /*
             * // This code is great for debugging DD parsing issues.
             * string s = "+ " + node.Name;
             * if (node.Attributes["name"] != null)
             *  s += " | " + node.Attributes["name"].Value;
             * Console.WriteLine(s);
             */

            if (!node.HasChildNodes)
            {
                return;
            }
            foreach (XmlNode childNode in node.ChildNodes)
            {
                /*
                 * // Continuation of code that's great for debugging DD parsing issues.
                 * s = "    + " + childNode.Name;
                 * if (node.Attributes["name"] != null)
                 *  s += " | " + childNode.Attributes["name"].Value;
                 * Console.WriteLine(s);
                 */

                if (childNode.Name == "field")
                {
                    DDField      fld = FieldsByName[childNode.Attributes["name"].Value];
                    XmlAttribute req = childNode.Attributes["required"];
                    if (req != null && req.Value == "Y" &&
                        (componentRequired == null || componentRequired.Value == true))
                    {
                        ddmap.ReqFields.Add(fld.Tag);
                    }
                    if (!ddmap.IsField(fld.Tag))
                    {
                        ddmap.Fields.Add(fld.Tag, fld);
                    }

                    // if first field in group, make it the DELIM
                    if ((ddmap.GetType() == typeof(DDGrp) && ((DDGrp)ddmap).Delim == 0))
                    {
                        ((DDGrp)ddmap).Delim = fld.Tag;
                    }
                }
                else if (childNode.Name == "group")
                {
                    DDField      fld = FieldsByName[childNode.Attributes["name"].Value];
                    DDGrp        grp = new DDGrp();
                    XmlAttribute req = childNode.Attributes["required"];
                    if (req != null && req.Value == "Y" &&
                        (componentRequired == null || componentRequired.Value == true))
                    {
                        ddmap.ReqFields.Add(fld.Tag);
                        grp.Required = true;
                    }
                    if (!ddmap.IsField(fld.Tag))
                    {
                        ddmap.Fields.Add(fld.Tag, fld);
                    }
                    grp.NumFld = fld.Tag;
                    parseMsgEl(childNode, grp);
                    ddmap.Groups.Add(fld.Tag, grp);
                }
                else if (childNode.Name == "component")
                {
                    String       name         = childNode.Attributes["name"].Value;
                    XmlNode      compNode     = RootDoc.SelectSingleNode("//components/component[@name='" + name + "']");
                    XmlAttribute req          = childNode.Attributes["required"];
                    bool?        compRequired = (req != null && req.Value == "Y");
                    parseMsgEl(compNode, ddmap, compRequired);
                }
            }
        }
Example #12
0
 public void AddField(DDField fld)
 {
     Fields.Add(fld.Tag, fld);
 }