Пример #1
0
        public NiniDatabase(string fileName)
        {
            if (string.IsNullOrWhiteSpace(fileName))
                throw new ArgumentNullException("fileName");

            if (!File.Exists(fileName))
            {
                //TODO Log error
                FileStream fileStream = File.Create(fileName);
                fileStream.Close();
            }

            IniConfigSource iniConfigSoruce = new Nini.Config.IniConfigSource();
            iniConfigSoruce.AutoSave = true;
            iniConfigSoruce.Load(fileName);

            _storage = iniConfigSoruce;
        }
Пример #2
0
        public NiniDatabase(string fileName)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentNullException("fileName");
            }

            if (!File.Exists(fileName))
            {
                //TODO Log error
                FileStream fileStream = File.Create(fileName);
                fileStream.Close();
            }

            IniConfigSource iniConfigSoruce = new Nini.Config.IniConfigSource();

            iniConfigSoruce.AutoSave = true;
            iniConfigSoruce.Load(fileName);

            _storage = iniConfigSoruce;
        }
Пример #3
0
        public void LoadPath()
        {
            string filePath = "Test.ini";

            StreamWriter writer = new StreamWriter (filePath);
            writer.WriteLine ("; some comment");
            writer.WriteLine ("[new section]");
            writer.WriteLine (" dog = Rover");
            writer.WriteLine (""); // empty line
            writer.WriteLine ("; a comment");
            writer.WriteLine (" cat = Muffy");
            writer.Close ();

            IniConfigSource source = new IniConfigSource (filePath);
            IConfig config = source.Configs["new section"];
            Assert.AreEqual ("Rover", config.Get ("dog"));
            Assert.AreEqual ("Muffy", config.Get ("cat"));

            config.Set ("dog", "Spots");
            config.Set ("cat", "Misha");
            config.Set ("DoesNotExist", "SomeValue");

            source.Load (filePath);

            config = source.Configs["new section"];
            Assert.AreEqual ("Rover", config.Get ("dog"));
            Assert.AreEqual ("Muffy", config.Get ("cat"));

            File.Delete (filePath);
        }