Inheritance: IFieldMapSpec
Exemple #1
0
        private void ParseMessages(XmlDocument doc)
        {
            XmlNodeList nodeList = doc.SelectNodes("//messages/message");

            foreach (XmlNode msgEl in nodeList)
            {
                DDMap msg = new DDMap();
                ParseMsgEl(msgEl, msg);
                String msgtype = msgEl.Attributes["msgtype"].Value;
                Messages.Add(msgtype, msg);
            }
        }
Exemple #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);
                }
            }
        }
 /// <summary>
 /// Copy a data dictionary
 /// </summary>
 /// <param name="src">the source dictionary that will be copied into this dictionary</param>
 public DataDictionary(DataDictionary src)
     : this()
 {
     this.Messages = src.Messages;
     this.FieldsByName = src.FieldsByName;
     this.FieldsByTag = src.FieldsByTag;
     if (null != src.MajorVersion)
         this.MajorVersion = string.Copy(src.MajorVersion);
     if (null != src.MinorVersion)
         this.MinorVersion = string.Copy(src.MinorVersion);
     if (null != src.Version)
         this.Version = string.Copy(src.Version);
     this.CheckFieldsHaveValues = src.CheckFieldsHaveValues;
     this.CheckFieldsOutOfOrder = src.CheckFieldsOutOfOrder;
     this.CheckUserDefinedFields = src.CheckUserDefinedFields;
     this.Header = src.Header;
     this.Trailer = src.Trailer;
 }
Exemple #4
0
 /// <summary>
 /// Copy a data dictionary
 /// </summary>
 /// <param name="src">the source dictionary that will be copied into this dictionary</param>
 public DataDictionary(DataDictionary src)
     : this()
 {
     this.Messages     = src.Messages;
     this.FieldsByName = src.FieldsByName;
     this.FieldsByTag  = src.FieldsByTag;
     if (null != src.MajorVersion)
     {
         this.MajorVersion = string.Copy(src.MajorVersion);
     }
     if (null != src.MinorVersion)
     {
         this.MinorVersion = string.Copy(src.MinorVersion);
     }
     if (null != src.Version)
     {
         this.Version = string.Copy(src.Version);
     }
     this.CheckFieldsHaveValues  = src.CheckFieldsHaveValues;
     this.CheckFieldsOutOfOrder  = src.CheckFieldsOutOfOrder;
     this.CheckUserDefinedFields = src.CheckUserDefinedFields;
     this.Header  = src.Header;
     this.Trailer = src.Trailer;
 }
        /// <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);
                }
            }
        }
 /// <summary>
 /// Implied null third componentRequired parameter
 /// </summary>
 /// <param name="node"></param>
 /// <param name="ddmap"></param>
 private void parseMsgEl(XmlNode node, DDMap ddmap)
 {
     parseMsgEl(node, ddmap, null);
 }
 private void parseMessages(XmlDocument doc)
 {
     XmlNodeList nodeList = doc.SelectNodes("//messages/message");
     foreach (XmlNode msgEl in nodeList)
     {
         DDMap msg = new DDMap();
         parseMsgEl(msgEl, msg);
         String msgtype = msgEl.Attributes["msgtype"].Value;
         Messages.Add(msgtype, msg);
     }
 }
Exemple #8
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);
                }
            }
        }
Exemple #9
0
 /// <summary>
 /// Implied null third componentRequired parameter
 /// </summary>
 /// <param name="node"></param>
 /// <param name="ddmap"></param>
 private void ParseMsgEl(XmlNode node, DDMap ddmap)
 {
     ParseMsgEl(node, ddmap, null);
 }
Exemple #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}'");
                }
            }
        }
Exemple #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);
                }
            }
        }
Exemple #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);
                }
            }
        }