public IEnumerable <RebalanceInfo> Execute(string input)
        {
            IList <Node> definitionNodes;
            string       error;
            Position     position;
            bool         successfullParse = ValveParser.TryParse(input, out definitionNodes, out error, out position);

            if (!successfullParse)
            {
                Log.Error("Error parsing input: {Error} at {Position}", error, position);
                return(null);
            }
            if (definitionNodes.Count == 0)
            {
                Log.Error("no data found in input");
                return(null);
            }

            var groupings = FindItemNodes(definitionNodes)
                            .SelectMany(node => FindAllInfos(node.Parent.Name)
                                        .Select(i => new RebalanceInfo
            {
                id        = i.Id,
                name      = _classNames.ContainsKey(i.Name.ToLowerInvariant()) ? _classNames[i.Name.ToLowerInvariant()] : i.Name,
                info      = node.Value.Replace("\n", "\r\n"),
                category  = i.Category,
                itemclass = NormalizeClassName(i.Class),
                slot      = i.Slot
            }));

            return(groupings);
        }
        public IList <Node> Parse(string input)
        {
            IList <Node> definitionNodes;
            string       error;
            Position     position;
            bool         successfullParse = ValveParser.TryParse(input, out definitionNodes, out error, out position);

            if (!successfullParse)
            {
                Log.Error("Error parsing input: {Error} at {Position}", error, position);
                return(null);
            }
            if (definitionNodes.Count == 0)
            {
                Log.Error("no data found in input");
                return(null);
            }

            return(definitionNodes);
        }
        public void TestMethodRealanceExample()
        {
            string dir     = Directory.GetCurrentDirectory();
            string path    = Path.Combine(dir, "tf2rebalance_attributes.example.txt");
            string content = File.ReadAllText(path);

            IList <Node> dict;
            string       error;
            Position     errorPosition;
            bool         success = ValveParser.TryParse(content, out dict, out error, out errorPosition);

            Assert.IsTrue(success, error);

            List <Node> expectedNodes = new List <Node>
            {
                new Node
                {
                    Name   = "tf2rebalance_attributes",
                    Childs = new List <Node>
                    {
                        new Node
                        {
                            Name   = "classes",
                            Childs = new List <Node>
                            {
                                new Node
                                {
                                    Name   = "scout",
                                    Childs = new List <Node>
                                    {
                                        new Node
                                        {
                                            Name  = "info",
                                            Value = "This is a cool info piece.\nAwesome!"
                                        },
                                        new Node
                                        {
                                            Name   = "attribute1",
                                            Childs = new List <Node>
                                            {
                                                new Node
                                                {
                                                    Name  = "id",
                                                    Value = "26"
                                                },
                                                new Node
                                                {
                                                    Name  = "value",
                                                    Value = "100"
                                                },
                                            }
                                        },
                                    }
                                },
                                new Node
                                {
                                    Name   = "soldier",
                                    Childs = new List <Node>
                                    {
                                        new Node
                                        {
                                            Name  = "info",
                                            Value = "Soldier:\n- Your torso is now 100% bigger. Whoa.\n- +2 HP per second."
                                        },
                                        new Node
                                        {
                                            Name   = "attribute1",
                                            Childs = new List <Node>
                                            {
                                                new Node
                                                {
                                                    Name  = "id",
                                                    Value = "620"
                                                },
                                                new Node
                                                {
                                                    Name  = "value",
                                                    Value = "2.0"
                                                },
                                            }
                                        },
                                        new Node
                                        {
                                            Name   = "attribute2",
                                            Childs = new List <Node>
                                            {
                                                new Node
                                                {
                                                    Name  = "id",
                                                    Value = "190"
                                                },
                                                new Node
                                                {
                                                    Name  = "value",
                                                    Value = "2"
                                                },
                                            }
                                        },
                                    }
                                },
                            }
                        },
                        new Node
                        {
                            Name   = "127",
                            Childs = new List <Node>
                            {
                                new Node
                                {
                                    Name  = "keepattribs",
                                    Value = "1"
                                },
                                new Node
                                {
                                    Name  = "info",
                                    Value = "Direct Hit:\n- 25% jump height.\n- -50% less clip size."
                                },
                                new Node
                                {
                                    Name   = "attribute1",
                                    Childs = new List <Node>
                                    {
                                        new Node
                                        {
                                            Name  = "id",
                                            Value = "326"
                                        },
                                        new Node
                                        {
                                            Name  = "value",
                                            Value = "1.25"
                                        },
                                    }
                                },
                                new Node
                                {
                                    Name   = "attribute2",
                                    Childs = new List <Node>
                                    {
                                        new Node
                                        {
                                            Name  = "id",
                                            Value = "3"
                                        },
                                        new Node
                                        {
                                            Name  = "value",
                                            Value = "1.50"
                                        },
                                    }
                                },
                            }
                        },
                        new Node
                        {
                            Name   = "225 ; 574",
                            Childs = new List <Node>
                            {
                                new Node
                                {
                                    Name   = "attribute1",
                                    Childs = new List <Node>
                                    {
                                        new Node
                                        {
                                            Name  = "id",
                                            Value = "201"
                                        },
                                        new Node
                                        {
                                            Name  = "value",
                                            Value = "2.0"
                                        },
                                    }
                                },
                                new Node
                                {
                                    Name   = "attribute2",
                                    Childs = new List <Node>
                                    {
                                        new Node
                                        {
                                            Name  = "id",
                                            Value = "6"
                                        },
                                        new Node
                                        {
                                            Name  = "value",
                                            Value = "2.0"
                                        },
                                    }
                                },
                            }
                        },
                        new Node
                        {
                            Name   = "131",
                            Childs = new List <Node>
                            {
                                new Node
                                {
                                    Name  = "info",
                                    Value = "Why are you using a shield?"
                                },

                                new Node
                                {
                                    Name  = "keepattribs",
                                    Value = "1"
                                },
                            }
                        },
                    }
                }
            };

            AssertEquallity(dict, expectedNodes);
        }
        public void TestMethod1()
        {
            string dir     = Directory.GetCurrentDirectory();
            string path    = Path.Combine(dir, "1.txt");
            string content = File.ReadAllText(path);

            IList <Node> dict;
            string       error;
            Position     errorPosition;
            bool         success = ValveParser.TryParse(content, out dict, out error, out errorPosition);

            Assert.IsTrue(success, error);

            List <Node> expectedNodes = new List <Node>
            {
                new Node
                {
                    Name   = "custom_weapons_v3",
                    Childs = new List <Node>
                    {
                        new Node
                        {
                            Name   = "*",
                            Childs = new List <Node>
                            {
                                new Node
                                {
                                    Name   = "60",
                                    Childs = new List <Node>
                                    {
                                        new Node
                                        {
                                            Name  = "1",
                                            Value = "292 ; 58"
                                        },
                                        new Node
                                        {
                                            Name  = "2",
                                            Value = "48 ; 2"
                                        },
                                        new Node
                                        {
                                            Name  = "3",
                                            Value = "35 ; 2"
                                        },
                                        new Node
                                        {
                                            Name  = "4",
                                            Value = "728 ; 1"
                                        },
                                        new Node
                                        {
                                            Name  = "5",
                                            Value = "729 ; 0.65"
                                        },
                                        new Node
                                        {
                                            Name  = "6",
                                            Value = "1 ; 0.9"
                                        },
                                    }
                                }
                            }
                        }
                    }
                }
            };

            AssertEquallity(dict, expectedNodes);
        }