Beispiel #1
0
 public Entry(Entry other)
 {
     this.FriendlyName = other.FriendlyName;
     this.InternalName = other.InternalName;
     this.Link         = other.Link;
     this.Parent       = other.Parent;
     this.Root         = other.Root;
 }
Beispiel #2
0
 public ValueEntry(string internalName, string friendlyName, string type, string value, string link, SectionEntry parent, SectionEntry root) : this()
 {
     InternalName = internalName;
     FriendlyName = friendlyName;
     Type         = type;
     Value        = value;
     Link         = link;
     Parent       = parent;
     Root         = root;
 }
Beispiel #3
0
 public ValueEntry(string internalName, string friendlyName, string type, string value, string link, SectionEntry parent, SectionEntry root)
     : this()
 {
     InternalName = internalName;
     FriendlyName = friendlyName;
     Type = type;
     Value = value;
     Link = link;
     Parent = parent;
     Root = root;
 }
Beispiel #4
0
        protected override Entry CreateClone()
        {
            SectionEntry ret = new SectionEntry();

            ret.SeriesFormatting = this.SeriesFormatting;
            foreach (Entry child in this.Entries)
            {
                ret.Entries.Add(child.Clone());
            }
            return(ret);
        }
Beispiel #5
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;
        }
Beispiel #6
0
        public Entry GenerateDefault()
        {
            if (m_default == null)
            {
                m_default = new SectionEntry();
                m_default.InternalName = "";
                m_default.FriendlyName = "[!/birth_name:[VALUE]!]";
                ValueEntry bname = new ValueEntry();
                bname.InternalName = "birth_name";
                bname.FriendlyName = "Birth Name";
                bname.Parent = m_default;
                m_default.Entries.Add(bname);
            }

            return m_default.Clone();
        }
Beispiel #7
0
        public override bool Equals(Entry other)
        {
            SectionEntry others = other as SectionEntry;

            if (others == null || !base.Equals(other))
            {
                return(false);
            }
            var pairs = this.Entries.Zip(others.Entries, (a, b) => new { A = a, B = b });

            foreach (var pair in pairs)
            {
                if (!pair.A.Equals(pair.B))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #8
0
        public static IEnumerable <Entry> ParseRefPath(Entry start, string sref)
        {
            if (sref == null)
            {
                yield break;
            }
            Entry current = start;

            if (sref.Length > 0 && sref[0] == '!')//reference path starting with another '!' means it starts at the root
            {
                current = current.Root;
                sref    = sref.Remove(0, 1);
            }

            string[] comps = sref.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string compi in comps)
            {
                string comp = compi;

                foreach (Match match in Regex.Matches(comp, "\\[.*\\]"))
                {
                    comp = comp.Remove(match.Index, match.Length);
                    comp = comp.Insert(match.Index, ParseSymbol(start, current, match.Value));
                }
                if (compi == "..")
                {
                    current = current.Parent;
                    yield return(current);
                }
                else
                {
                    SectionEntry section = current as SectionEntry;
                    if (section == null)
                    {
                        yield break;
                    }
                    current = section.Entries.FirstOrDefault(ent => ent.InternalName == comp);
                }
                yield return(current);
            }
        }
Beispiel #9
0
 private static SectionEntry CreateTestTree()
 {
     SectionEntry root = new SectionEntry("0");
     root.AddMany(new SectionEntry("1"), new SectionEntry("2"), new SectionEntry("9"), new SectionEntry("12"), new SectionEntry("13"));
     var n2 = (SectionEntry)root.Entries[1];
     n2.AddMany(new SectionEntry("3"), new ValueEntry("6"), new SectionEntry("7"));
     var n3 = (SectionEntry)n2.Entries[0];
     n3.AddMany(new ValueEntry("4"), new ValueEntry("5"));
     var n7 = (SectionEntry)n2.Entries[2];
     n7.AddMany(new ValueEntry("8"));
     var n9 = (SectionEntry)root.Entries[2];
     n9.AddMany(new ValueEntry("10"), new ValueEntry("11"));
     var n13 = (SectionEntry)root.Entries[4];
     n13.AddMany(new SectionEntry("14"), new ValueEntry("21"));
     var n14 = (SectionEntry)n13.Entries[0];
     n14.AddMany(new SectionEntry("15"), new SectionEntry("18"), new SectionEntry("19"));
     var n15 = (SectionEntry)n14.Entries[0];
     n15.AddMany(new ValueEntry("16"), new ValueEntry("17"));
     var n19 = (SectionEntry)n14.Entries[2];
     n19.AddMany(new ValueEntry("20"));
     return root;
 }
Beispiel #10
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);
            }
        }
Beispiel #11
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;
            }
        }
Beispiel #12
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;
        }
Beispiel #13
0
 private void bworker_DoWork(object sender, DoWorkEventArgs e)
 {
     System.Threading.Thread.CurrentThread.Name = "File Reader";
     m_resultEditor = reader.ReadFile(path);
 }
Beispiel #14
0
 protected override Entry CreateClone()
 {
     SectionEntry ret = new SectionEntry();
     ret.SeriesFormatting = this.SeriesFormatting;
     foreach (Entry child in this.Entries)
     {
         ret.Entries.Add(child.Clone());
     }
     return ret;
 }
        public void FormattedReaderTest()
        {
            FormattedReader reader = new FormattedReader(TestsReference.FORMAT_PATH);
            SectionEntry root = reader.ReadFile(TestsReference.MIN_TEST_PATH);
            SectionEntry player = new SectionEntry("player", "Player", null);
            player.Root = root;
            player.Parent = root;
            player.Entries.Add(new ValueEntry("id", "Id", "number", "665369", null, player, root));
            player.Entries.Add(new ValueEntry("type", "Type", "number", "66", null, player, root));
            Assert.IsTrue(player.Equals(root.Entries[2]));
            Assert.AreEqual(12, root.Entries.Count);

            Entry start = root.Entries[0];
            string refpath = "..";
            Assert.AreEqual(start.Parent, FormattedReader.ParseRef(start, refpath));
        }
Beispiel #16
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);
        }