Repräsentiert eine Einstellungsdatei.
Ejemplo n.º 1
0
 /// <summary>
 /// Erstellt eine neue Option, die einen der angegebenen Werte aus validValues annehmen kann, mit dem angegebenen Namen in dem
 /// angegebenen Abschnitt der angegebenen Einstellungsdatei.
 /// [base=section, name, defaultValue, configFile]
 /// </summary>
 public DistinctOption(string section, string name, string defaultValue, IEnumerable<string> validValues, ConfigFile configFile)
     : base(section, name, defaultValue, configFile)
 {
     ValidValues = new HashSet<string> (validValues);
     ValidValues.Add (defaultValue);
     DisplayValidValues = new Dictionary<string,string> (ValidValues.ToDictionary (x=>x,x=>x));
 }
Ejemplo n.º 2
0
        public void BooleanOptionInfo_Constructor_Test()
        {
            string name = "test-option";
            string section = "test-section";
            bool defaultValue = false;

            ConfigFile configFile = new ConfigFile (TestHelper.RandomFilename (extension: "ini"));

            BooleanOption option = new BooleanOption (section, name, defaultValue, configFile);

            Assert.IsFalse (option.Value);
            string falseStr = option.DisplayValue;
            Assert.IsTrue (option.DisplayValidValues.ContainsKey (falseStr));

            option.Value = true;
            Assert.IsTrue (option.Value);
            string trueStr = option.DisplayValue;
            Assert.IsTrue (option.DisplayValidValues.ContainsKey (trueStr));

            Assert.AreNotEqual (falseStr, trueStr);

            option.Value = !option.Value;
            Assert.IsFalse (option.Value);
            Assert.AreEqual (falseStr, option.DisplayValue);

            option.Value = !option.Value;
            Assert.IsTrue (option.Value);
            Assert.AreEqual (trueStr, option.DisplayValue);

            (option as DistinctOption).Value = "invalid!!";
            Assert.AreEqual (option.Value, defaultValue);
        }
Ejemplo n.º 3
0
        public void Test()
        {
            string name = "test-option";
            string section = "test-section";
            float defaultValue = 5f;
            float[] validValues = new float[] { 0f, 5f, 10f, 15f, 20f };

            ConfigFile configFile = new ConfigFile (TestHelper.RandomFilename (extension: "ini"));

            FloatOption option = new FloatOption (section, name, defaultValue, validValues, configFile);

            Assert.AreEqual (option.Value, defaultValue);
            string defaultStr = option.DisplayValue;
            Assert.IsTrue (option.DisplayValidValues.ContainsKey (defaultStr));

            option.Value = 10f;
            Assert.AreEqual (option.Value, 10f);
            string tenStr = option.DisplayValue;
            Assert.IsTrue (option.DisplayValidValues.ContainsKey (tenStr));

            Assert.AreNotEqual (defaultStr, tenStr);

            option.Value = 99f;
            Assert.AreEqual (option.Value, defaultValue);
            Assert.AreEqual (defaultStr, option.DisplayValue);

            (option as DistinctOption).Value = "invalid!!";
            Assert.AreEqual (option.Value, defaultValue);
            Assert.AreEqual (defaultStr, option.DisplayValue);
        }
Ejemplo n.º 4
0
        public void Test()
        {
            string name = "test-option";
            string section = "test-section";
            Keys defaultValue = Keys.Escape;

            ConfigFile configFile = new ConfigFile (TestHelper.RandomFilename (extension: "ini"));

            KeyOption option = new KeyOption (section, name, defaultValue, configFile);

            Assert.AreEqual (option.Value, defaultValue);
            string defaultStr = option.DisplayValue;
            Assert.IsTrue (option.DisplayValidValues.ContainsKey (defaultStr));

            option.Value = Keys.LeftShift;
            Assert.AreEqual (option.Value, Keys.LeftShift);
            string tenStr = option.DisplayValue;
            Assert.IsTrue (option.DisplayValidValues.ContainsKey (tenStr));

            Assert.AreNotEqual (defaultStr, tenStr);

            (option as DistinctOption).Value = "invalid!!";
            Assert.AreEqual (option.Value, defaultValue);
            Assert.AreEqual (defaultStr, option.DisplayValue);
        }
Ejemplo n.º 5
0
 public Option(string section, string name, string defaultValue, ConfigFile configFile)
 {
     Section = section;
     Name = name;
     DefaultValue = defaultValue;
     ConfigFile = configFile != null ? configFile : Config.Default;
     Verbose = false; //SystemInfo.IsRunningOnLinux ();
 }
Ejemplo n.º 6
0
        public void ConfigFile_RandomAccess_Test()
        {
            int countSections = 10;
            int countKeysPerSection = 10;
            string filename = TestHelper.RandomFilename ("ini");
            ConfigFile cfg = new ConfigFile (filename);
            Console.WriteLine (filename);

            string[] sections = RandomStrings (count: countSections).ToArray ();
            Dictionary<string, string[]> keyMap = new Dictionary<string, string[]> ();
            sections.ForEach (section => keyMap [section] = RandomStrings (count: countKeysPerSection).ToArray ());

            Dictionary<string, string[]> stringValueMap = new Dictionary<string, string[]> ();
            sections.ForEach (section => stringValueMap [section] = RandomStrings (count: countKeysPerSection).ToArray ());
            string stringDefaultValue = "default";

            foreach (string section in sections) {
                string[] keys = keyMap [section];
                string[] values = stringValueMap [section];

                keys.Length.Repeat (i => Assert.AreEqual (stringDefaultValue, cfg [section, keys [i], stringDefaultValue]));
                keys.Length.Repeat (i => cfg [section, keys [i], stringDefaultValue] = values [i]);
                keys.Length.Repeat (i => Assert.AreEqual (values [i], cfg [section, keys [i], stringDefaultValue]));
            }

            Dictionary<string, float[]> floatValueMap = new Dictionary<string, float[]> ();
            sections.ForEach (section => floatValueMap [section] = RandomFloats (count: countKeysPerSection).ToArray ());
            float floatDefaultValue = -1;

            foreach (string section in sections) {
                string[] keys = keyMap [section];
                float[] values = floatValueMap [section];

                keys.Length.Repeat (i => Assert.Greater ((values [i] - cfg [section, keys [i], floatDefaultValue]).Abs (), 0.00001f));
                keys.Length.Repeat (i => cfg [section, keys [i], floatDefaultValue] = values [i]);
                keys.Length.Repeat (i => Assert.Less ((values [i] - cfg [section, keys [i], floatDefaultValue]).Abs (), 0.001f));
            }

            Dictionary<string, bool[]> boolValueMap = new Dictionary<string, bool[]> ();
            sections.ForEach (section => boolValueMap [section] = RandomBooleans (count: countKeysPerSection).ToArray ());
            bool boolDefaultValue = false;

            foreach (string section in sections) {
                string[] keys = keyMap [section];
                bool[] values = boolValueMap [section];

                keys.Length.Repeat (i => cfg [section, keys [i], boolDefaultValue] = values [i]);
                keys.Length.Repeat (i => Assert.AreEqual (values [i], cfg [section, keys [i], boolDefaultValue]));
            }
        }
Ejemplo n.º 7
0
 public RenderEffectOption(string section, string name, ConfigFile configFile)
     : base(section, name, "default", RenderEffectLibrary.Names, configFile)
 {
 }
Ejemplo n.º 8
0
 public KeyOption(string section, string name, Keys defaultValue, ConfigFile configFile)
     : base(section, name, defaultValue.ToEnumDescription<Keys> (), ValidValues, configFile)
 {
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Erstellt eine neue Option, welche die Werte \glqq Wahr\grqq~oder \glqq Falsch\grqq~annehmen kann. Mit dem angegebenen Namen, in dem
 /// angegebenen Abschnitt der angegebenen Einstellungsdatei.
 /// [base=section, name, defaultValue?ConfigFile.True:ConfigFile.False, ValidValues, configFile]
 /// </summary>
 public FloatOption(string section, string name, float defaultValue, IEnumerable<float> validValues, ConfigFile configFile)
     : base(section, name, convertToString (defaultValue),validValues.Select (convertToString), configFile)
 {
 }
Ejemplo n.º 10
0
 public KeyOption(string section, string name, Keys defaultValue, ConfigFile configFile)
     : base(section, name, defaultValue.ToEnumDescription <Keys> (), ValidValues, configFile)
 {
 }
Ejemplo n.º 11
0
 public Language(string file)
 {
     Code = Path.GetFileNameWithoutExtension (file).ToLower ();
     file = Localizer.LanguageDirectory + Code + ".ini";
     Localization = new ConfigFile (file);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Erstellt eine neue Option, welche die Werte \glqq Wahr\grqq~oder \glqq Falsch\grqq~annehmen kann. Mit dem angegebenen Namen, in dem
 /// angegebenen Abschnitt der angegebenen Einstellungsdatei.
 /// [base=section, name, defaultValue?ConfigFile.True:ConfigFile.False, ValidValues, configFile]
 /// </summary>
 public BooleanOption(string section, string name, bool defaultValue, ConfigFile configFile)
     : base(section, name, defaultValue?ConfigFile.True:ConfigFile.False, ValidValues, configFile)
 {
 }
Ejemplo n.º 13
0
 public LanguageOption(string section, string name, ConfigFile configFile)
     : base(section, name, Localizer.DefaultLanguageCode, from lang in Localizer.ValidLanguages select lang.Code, configFile)
 {
 }