Inheritance: DDMap, IGroupSpec
Esempio n. 1
0
 /// <summary>
 /// Check that <paramref name="field"/> is supposed to be in the group defined in <paramref name="ddgrp"/>
 /// </summary>
 /// <param name="field"></param>
 /// <param name="ddgrp"></param>
 /// <param name="msgType">Message type that contains the group (included in exceptions thrown on failure)</param>
 public void CheckIsInGroup(Fields.IField field, DDGrp ddgrp, string msgType)
 {
     if (ddgrp.IsField(field.Tag))
     {
         return;
     }
     throw new TagNotDefinedForMessage(field.Tag, msgType);
 }
Esempio n. 2
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);
                }
            }
        }
Esempio n. 3
0
        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);
                    }
                }
            }
        }
Esempio n. 4
0
        public void IterateGroup(Group group, DDGrp ddgroup, string msgType)
        {
            DataDictionary.CheckHasNoRepeatedTags(group);

            int lastField = 0;

            foreach (KeyValuePair <int, Fields.IField> kvp in group)
            {
                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);

                        CheckIsInGroup(field, ddgroup, msgType);
                        CheckGroupCount(field, group, msgType);
                    }
                }
                lastField = field.Tag;
            }

            // check contents of each nested group
            foreach (int groupTag in group.GetGroupTags())
            {
                for (int i = 1; i <= group.GroupCount(groupTag); i++)
                {
                    Group g   = group.GetGroup(i, groupTag);
                    DDGrp ddg = ddgroup.GetGroup(groupTag);
                    IterateGroup(g, ddg, msgType);
                }
            }
        }
Esempio n. 5
0
 public void AddGroup(DDGrp grp)
 {
     Groups.Add(grp.Delim, grp);
 }
        /// <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);
                }
            }
        }
        public void IterateGroup(Group group, DDGrp ddgroup, string msgType)
        {
            DataDictionary.CheckHasNoRepeatedTags(group);

            int lastField = 0;
            foreach(KeyValuePair<int, Fields.IField> kvp in group)
            {
                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);

                        CheckIsInGroup(field, ddgroup, msgType);
                        CheckGroupCount(field, group, msgType);
                    }
                }
                lastField = field.Tag;
            }

            // check contents of each nested group
            foreach (int groupTag in group.GetGroupTags())
            {
                for (int i = 1; i <= group.GroupCount(groupTag); i++)
                {
                    Group g = group.GetGroup(i, groupTag);
                    DDGrp ddg = ddgroup.GetGroup(groupTag);
                    IterateGroup(g, ddg, msgType);
                }
            }
        }
 /// <summary>
 /// Check that <paramref name="field"/> is supposed to be in the group defined in <paramref name="ddgrp"/>
 /// </summary>
 /// <param name="field"></param>
 /// <param name="ddgrp"></param>
 /// <param name="msgType">Message type that contains the group (included in exceptions thrown on failure)</param>
 public void CheckIsInGroup(Fields.IField field, DDGrp ddgrp, string msgType)
 {
     if (ddgrp.IsField(field.Tag))
         return;
     throw new TagNotDefinedForMessage(field.Tag, msgType);
 }
Esempio n. 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);
                }
            }
        }
Esempio n. 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}'");
                }
            }
        }
Esempio n. 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);
                }
            }
        }
Esempio n. 12
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)
        {
            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"
                        && (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 <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"
                        && (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 + "']");
                    bool? compRequired = (childNode.Attributes["required"].Value == "Y");
                    parseMsgEl(compNode, ddmap, compRequired);
                }
            }
        }
Esempio n. 13
0
 public void AddGroup(DDGrp grp)
 {
     Groups.Add(grp.Delim, grp);
 }