Esempio n. 1
0
        static void Main(string[] args)
        {
            var projectPath = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));

            string path = Path.Combine(projectPath, "Config.txt");

            var config = new TxtReader(path);

            Console.WriteLine(config["id"]);
            Console.WriteLine(config["session"]["timeout"]);
            Console.WriteLine(config["session"]["server"]["1"]["port"]);
            Console.WriteLine(config["image"]["cat"]["width"]);
            Console.WriteLine(config["image"]["folder"]);

            Console.ReadKey();
        }
Esempio n. 2
0
        public TxtReader Add(string name, string value, TxtReader parent)
        {
            var existingElement = AllItems.Where(x => x.Name == name && x.Parent == parent).SingleOrDefault();

            if (existingElement != null)
            {
                return(existingElement);
            }
            else
            {
                TxtReader newItem = new TxtReader(name, value, parent);

                Items.Add(newItem);

                AllItems.Add(newItem);

                return(newItem);
            }
        }
Esempio n. 3
0
        public void ParseFile()
        {
            try
            {
                var lines = File.ReadAllLines(Path);

                foreach (var line in lines)
                {
                    TxtReader parent        = null;
                    var       splittedLines = line.Split('=');

                    var leftLines = splittedLines[0].Split('.');

                    for (int i = 0; i < leftLines.Length; i++)
                    {
                        parent = Add(leftLines[i], i != leftLines.Length - 1 ? String.Empty : splittedLines[1], parent);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 4
0
 public TxtReader(string name, string value, TxtReader parent)
 {
     Name   = name;
     Value  = value;
     Parent = parent;
 }