Ejemplo n.º 1
0
        private static SectionEntry GenerateTestTree()
        {
            SectionEntry root = new EntryGrouper();

            SectionEntry n1 = new SectionEntry("n1", "First Node: [!/n1-1:[VALUE]!]", null);
            root.Entries.Add(n1);
            n1.Parent = root;
            n1.Root = root;
            n1.Entries.Add(new ValueEntry("n1-1", "First Value", "string", "A Value That Is A Name", "!/n2", n1, root));
            n1.Entries.Add(new ValueEntry("n1-2", "Second Value", "misc", "something", "/..", n1, root));
            root.Entries.Add(new ValueEntry("n2", "[!/../n1:[VNAME]!]", "number", "a normal value", null, root, root));

            return root;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks if the node has the "multiple" attribute, and if so, initializes a dictionary entry for its grouper if one does not yet exist
        /// </summary>
        /// <param name="node">The xml node that describes the current entry</param>
        /// <param name="multiples">The dictionary holding the multiples groupers for the current section</param>
        /// <param name="parent">The parent of the current entry</param>
        /// <returns><paramref name="parent"/> if the "multiple" attribute was not found, and the grouper otherwise</returns>
        private SectionEntry HandleMultiples(XmlNode node, ref Dictionary <string, EntryGrouper> multiples, SectionEntry parent)
        {
            XmlAttribute multAtt = node.Attributes["multiple"];

            if (multAtt == null)
            {
                return(parent);
            }
            else
            {
                EntryGrouper grouper = null;

                if (multiples == null)
                {
                    multiples = new Dictionary <string, EntryGrouper>();
                }
                if (!multiples.TryGetValue(multAtt.Value, out grouper))
                {//grouper initialization
                    grouper = new EntryGrouper();
                    grouper.InternalName = null;
                    grouper.FriendlyName = node.Attributes["grouper-name"].Value;

                    XmlAttribute series = node.ParentNode.Attributes["series"];
                    if (series != null)
                    {
                        grouper.SeriesFormatting = SectionEntry.ParseSeriesType(series.Value);
                        parent.SeriesFormatting  = grouper.SeriesFormatting;
                    }

                    multiples[multAtt.Value] = grouper;
                    parent.Entries.Add(grouper);
                    grouper.Parent = parent;
                }
                return(grouper);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Checks if the node has the "multiple" attribute, and if so, initializes a dictionary entry for its grouper if one does not yet exist
        /// </summary>
        /// <param name="node">The xml node that describes the current entry</param>
        /// <param name="multiples">The dictionary holding the multiples groupers for the current section</param>
        /// <param name="parent">The parent of the current entry</param>
        /// <returns><paramref name="parent"/> if the "multiple" attribute was not found, and the grouper otherwise</returns>
        private SectionEntry HandleMultiples(XmlNode node, ref Dictionary<string, EntryGrouper> multiples, SectionEntry parent)
        {
            XmlAttribute multAtt = node.Attributes["multiple"];
            if (multAtt == null)
                return parent;
            else
            {
                EntryGrouper grouper = null;

                if (multiples == null)
                    multiples = new Dictionary<string, EntryGrouper>();
                if (!multiples.TryGetValue(multAtt.Value, out grouper))
                {//grouper initialization
                    grouper = new EntryGrouper();
                    grouper.InternalName = null;
                    grouper.FriendlyName = node.Attributes["grouper-name"].Value;

                    XmlAttribute series = node.ParentNode.Attributes["series"];
                    if (series != null)
                    {
                        grouper.SeriesFormatting = SectionEntry.ParseSeriesType(series.Value);
                        parent.SeriesFormatting = grouper.SeriesFormatting;
                    }

                    multiples[multAtt.Value] = grouper;
                    parent.Entries.Add(grouper);
                    grouper.Parent = parent;
                }
                return grouper;
            }
        }
Ejemplo n.º 4
0
        public SectionEntry ReadSection(string file, XmlNode formatNode, SectionEntry root = null)
        {
            SectionEntry re;
            if (root == null)
            {
                re = new EntryGrouper();
                root = re; //if no root was provided, the current editor is the root
            }
            else
                re = new SectionEntry();
            re.Root = root;

            Dictionary<string, EntryGrouper> multiples = null;
            foreach (var pair in FormatUtil.ListEntriesWithIndexes(file))
            {
                SectionEntry parent = re;

                XmlNode childNode = FindNode(formatNode, pair.Value);//look for a format node that can describe this entry
                if (childNode != null)
                {
                    parent = HandleMultiples(childNode, ref multiples, re);

                    if (!childNode.HasChildNodes)
                    {//the node is a value
                        ValueEntry ent = new ValueEntry();
                        ent.InternalName = pair.Value;
                        ent.FriendlyName = childNode.Attributes["name"].Value;
                        ent.Type = childNode.Attributes["type"] != null ? childNode.Attributes["type"].Value : "misc";
                        ent.Value = FormatUtil.ReadValue(file, ent.InternalName, ent.Type, pair.Key);
                        ent.Link = childNode.Attributes["link"] != null ? childNode.Attributes["link"].Value : null;
                        ent.Parent = parent;
                        ent.Root = root;
                        parent.Entries.Add(ent);
                    }
                    else
                    {//the node is a section
                        SectionEntry ent = ReadSection(FormatUtil.ExtractDelimited(file, pair.Value, pair.Key), childNode, re.Root);
                        ent.InternalName = pair.Value;
                        ent.FriendlyName = childNode.Attributes["name"].Value;
                        ent.Link = childNode.Attributes["link"] != null ? childNode.Attributes["link"].Value : null;
                        ent.Parent = parent;
                        parent.Entries.Add(ent);
                    }
                }
                else //if no format node was found, try to supplement information
                {
                    string type = DetectType(file, pair);
                    if (type != "section")
                    {//the node is a value
                        ValueEntry ent = new ValueEntry();
                        ent.InternalName = pair.Value;
                        ent.Type = type;
                        ent.Value = FormatUtil.ReadValue(file, ent.InternalName, ent.Type, pair.Key);
                        ent.Parent = re;
                        ent.Root = root;
                        parent.Entries.Add(ent);
                    }
                    else
                    {//the node is a section
                        SectionEntry ent = new SectionEntry();
                        ent.InternalName = pair.Value;
                        ent = ReadSection(FormatUtil.ExtractDelimited(file, pair.Value, pair.Key), childNode, re.Root);
                        ent.Parent = parent;
                        parent.Entries.Add(ent);
                    }
                }
            }
            return re;
        }
Ejemplo n.º 5
0
        public SectionEntry ReadSection(string file, XmlNode formatNode, SectionEntry root = null)
        {
            SectionEntry re;

            if (root == null)
            {
                re   = new EntryGrouper();
                root = re; //if no root was provided, the current editor is the root
            }
            else
            {
                re = new SectionEntry();
            }
            re.Root = root;

            Dictionary <string, EntryGrouper> multiples = null;

            foreach (var pair in FormatUtil.ListEntriesWithIndexes(file))
            {
                SectionEntry parent = re;

                XmlNode childNode = FindNode(formatNode, pair.Value);//look for a format node that can describe this entry
                if (childNode != null)
                {
                    parent = HandleMultiples(childNode, ref multiples, re);

                    if (!childNode.HasChildNodes)
                    {//the node is a value
                        ValueEntry ent = new ValueEntry();
                        ent.InternalName = pair.Value;
                        ent.FriendlyName = childNode.Attributes["name"].Value;
                        ent.Type         = childNode.Attributes["type"] != null ? childNode.Attributes["type"].Value : "misc";
                        ent.Value        = FormatUtil.ReadValue(file, ent.InternalName, ent.Type, pair.Key);
                        ent.Link         = childNode.Attributes["link"] != null ? childNode.Attributes["link"].Value : null;
                        ent.Parent       = parent;
                        ent.Root         = root;
                        parent.Entries.Add(ent);
                    }
                    else
                    {//the node is a section
                        SectionEntry ent = ReadSection(FormatUtil.ExtractDelimited(file, pair.Value, pair.Key), childNode, re.Root);
                        ent.InternalName = pair.Value;
                        ent.FriendlyName = childNode.Attributes["name"].Value;
                        ent.Link         = childNode.Attributes["link"] != null ? childNode.Attributes["link"].Value : null;
                        ent.Parent       = parent;
                        parent.Entries.Add(ent);
                    }
                }
                else //if no format node was found, try to supplement information
                {
                    string type = DetectType(file, pair);
                    if (type != "section")
                    {//the node is a value
                        ValueEntry ent = new ValueEntry();
                        ent.InternalName = pair.Value;
                        ent.Type         = type;
                        ent.Value        = FormatUtil.ReadValue(file, ent.InternalName, ent.Type, pair.Key);
                        ent.Parent       = re;
                        ent.Root         = root;
                        parent.Entries.Add(ent);
                    }
                    else
                    {//the node is a section
                        SectionEntry ent = new SectionEntry();
                        ent.InternalName = pair.Value;
                        ent        = ReadSection(FormatUtil.ExtractDelimited(file, pair.Value, pair.Key), childNode, re.Root);
                        ent.Parent = parent;
                        parent.Entries.Add(ent);
                    }
                }
            }
            return(re);
        }