Пример #1
0
        public RailDriverSettings(IEnumerable <string> options, SettingsStore store) :
            base(SettingsStore.GetSettingsStore(store.StoreType, store.Location, "RailDriver"))
        {
            CalibrationSettings = new byte[DefaultCalibrationSettings.Length];

            LoadSettings(options);
        }
Пример #2
0
        public void GetLocalIniStoreFromNewFile()
        {
            string        path  = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            SettingsStore store = SettingsStore.GetSettingsStore(StoreType.Ini, path, null);

            Assert.IsInstanceOfType(store, typeof(SettingsStoreLocalIni));
        }
Пример #3
0
        public void GetLocalIniStoreFromExistingFile()
        {
            string        path  = Path.GetTempFileName();
            SettingsStore store = SettingsStore.GetSettingsStore(StoreType.Ini, path, null);

            Assert.IsInstanceOfType(store, typeof(SettingsStoreLocalIni));
        }
Пример #4
0
        public void OpenRegistryStoreTest()
        {
            string        path  = "SOFTWARE\\OpenRails";
            SettingsStore store = SettingsStore.GetSettingsStore(StoreType.Registry, path, null);

            Assert.IsInstanceOfType(store, typeof(SettingsStoreRegistry));
        }
Пример #5
0
 public void ReadSingleFolderTest()
 {
     using (TestFile testFile = new TestFile("[Folders]\r\nName=string:Value"))
     {
         FolderSettings folders = new FolderSettings(null, SettingsStore.GetSettingsStore(StoreType.Ini, testFile.FileName, null));
         Assert.IsTrue(folders.Folders.Count == 1);
     }
 }
Пример #6
0
 public void OpenFolderSettingsTest()
 {
     using (TestFile testFile = new TestFile(string.Empty))
     {
         FolderSettings folders = new FolderSettings(null, SettingsStore.GetSettingsStore(StoreType.Ini, testFile.FileName, null));
         Assert.IsNotNull(folders.Folders);
     }
 }
Пример #7
0
        public void GetSectionNamesTest()
        {
            string        path     = "SOFTWARE\\OpenRails";
            SettingsStore store    = SettingsStore.GetSettingsStore(StoreType.Registry, path, null);
            var           sections = store.GetSectionNames();

            Assert.IsNotNull(sections);
        }
Пример #8
0
        public void GetSettingValueTimeSpan()
        {
            string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", $"name={nameof(TimeSpan)}:1000" });

            using (TestFile file = new TestFile(content))
            {
                SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni;
                Assert.AreEqual(TimeSpan.FromSeconds(1000), store.GetSettingValue("name", TimeSpan.Zero));
            }
        }
Пример #9
0
        public void GetSettingValueInt()
        {
            string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", "name=int:7" });

            using (TestFile file = new TestFile(content))
            {
                SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni;
                Assert.AreEqual(7, store.GetSettingValue("name", 0));
            }
        }
Пример #10
0
        public void GetSettingValueBool()
        {
            string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", "name=bool:true" });

            using (TestFile file = new TestFile(content))
            {
                SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni;
                Assert.IsTrue(store.GetSettingValue("name", false));
            }
        }
Пример #11
0
        public void GetSettingValueNotExisting()
        {
            string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", "name=bool:value" });

            using (TestFile file = new TestFile(content))
            {
                SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni;
                Assert.IsNull(store.GetSettingValue("name1", (string)null));
            }
        }
Пример #12
0
        public void GetSettingValueStringArray()
        {
            string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", $"name=string[]:0,1,10,100,1000" });

            using (TestFile file = new TestFile(content))
            {
                SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni;
                CollectionAssert.AreEqual(new string[] { "0", "1", "10", "100", "1000" }, store.GetSettingValue("name", Array.Empty <string>()));
            }
        }
Пример #13
0
        public void GetSettingValueIntArrayGeneric()
        {
            string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", $"name=int[]:0,1,10,100,1000" });

            using (TestFile file = new TestFile(content))
            {
                SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni;
                CollectionAssert.AreEqual(new int[] { 0, 1, 10, 100, 1000 }, store.GetSettingValue("name", new int[0]));
            }
        }
Пример #14
0
        public void LoadSectionsEmptyTest()
        {
            using (TestFile file = new TestFile(string.Empty))
            {
                SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, null) as SettingsStoreLocalIni;
                string[] sections           = store.GetSectionNames();

                CollectionAssert.AreEqual(Array.Empty <string>(), sections);
            }
        }
Пример #15
0
        public void SetSettingValueEnum()
        {
            string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", $"name=string[]:0,1,10,100,1000" });

            using (TestFile file = new TestFile(content))
            {
                SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni;
                store.SetSettingValue("enumValue", TestEnum.Value2);
                Assert.AreEqual(TestEnum.Value2, store.GetSettingValue("enumValue", default(TestEnum)));
            }
        }
Пример #16
0
        public void SetSettingValueFlags()
        {
            string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", $"name=string[]:0,1,10,100,1000" });

            using (TestFile file = new TestFile(content))
            {
                SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni;
                store.SetSettingValue("flagsValue", SimpleFlagsTest.Value2 | SimpleFlagsTest.Value1);
                Assert.AreEqual(SimpleFlagsTest.Value2 | SimpleFlagsTest.Value1, store.GetSettingValue("flagsValue", default(SimpleFlagsTest)));
            }
        }
Пример #17
0
        public void SetSettingValueString()
        {
            string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", $"name=string[]:0,1,10,100,1000" });

            using (TestFile file = new TestFile(content))
            {
                SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni;
                store.SetSettingValue("stringValue", "abcdef");
                Assert.AreEqual("abcdef", store.GetSettingValue("stringValue", string.Empty));
            }
        }
Пример #18
0
        public void SetSettingValueByte()
        {
            string content = string.Join(Environment.NewLine, new string[] { "[ORTS]", $"name=string[]:0,1,10,100,1000" });

            using (TestFile file = new TestFile(content))
            {
                SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "ORTS") as SettingsStoreLocalIni;
                store.SetSettingValue("byteValue", 127);
                Assert.AreEqual(127, store.GetSettingValue("byteValue", byte.MaxValue));
            }
        }
Пример #19
0
 public void SavedDedicatdTest()
 {
     using (TestFile testFile = new TestFile("[Folders]\r\nName=string:Value"))
     {
         FolderSettings source = new FolderSettings(null, SettingsStore.GetSettingsStore(StoreType.Ini, testFile.FileName, null));
         source.Folders.Add("Another", "Folder");
         source.Save("Another");
         FolderSettings target = new FolderSettings(null, SettingsStore.GetSettingsStore(StoreType.Ini, testFile.FileName, null));
         Assert.IsTrue(target.Folders.Count == 2);
     }
 }
Пример #20
0
 public void ResetTest()
 {
     using (TestFile testFile = new TestFile("[Folders]\r\nName=string:Value"))
     {
         FolderSettings source = new FolderSettings(null, SettingsStore.GetSettingsStore(StoreType.Ini, testFile.FileName, null));
         source.Reset();
         source.Save();
         FolderSettings target = new FolderSettings(null, SettingsStore.GetSettingsStore(StoreType.Ini, testFile.FileName, null));
         Assert.IsTrue(target.Folders.Count == 0);
     }
 }
Пример #21
0
        public void LoadSectionsSimpleTest()
        {
            string[] contentArray = new string[] { "[ORTS]", "[End]", "#[End]" };
            string   content      = string.Join(Environment.NewLine, contentArray);

            using (TestFile file = new TestFile(content))
            {
                SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, null) as SettingsStoreLocalIni;
                var sections = store.GetSectionNames();

                CollectionAssert.AreEqual(contentArray.Where((s) => !s.StartsWith("#")).Select((s) => s.Trim('[', ']')).ToArray(), sections);
            }
        }
Пример #22
0
        public void GetValueNamesSectionNotExistingTest()
        {
            string[] contentArray = new string[] { "[ORTS]", "name=value", "name1=value", "name2=value", "#[End]", "name=value", "[End]", "name=value" };
            string   content      = string.Join(Environment.NewLine, contentArray);

            using (TestFile file = new TestFile(content))
            {
                SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, "STRO") as SettingsStoreLocalIni;
                string[] names = store.GetSettingNames();

                CollectionAssert.AreEqual(Array.Empty <string>(), names);
            }
        }
Пример #23
0
        public void LoadSectionsExtendedTest()
        {
            string[] contentArray = new string[] { "[ORTS]", "name=value", "[End]", "name=value", "name=value", "#[End]" };
            string   content      = string.Join(Environment.NewLine, contentArray);

            using (TestFile file = new TestFile(content))
            {
                SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, null) as SettingsStoreLocalIni;
                string[] sections           = store.GetSectionNames();

                CollectionAssert.AreEqual(contentArray.Where((s) => s.StartsWith("[", StringComparison.OrdinalIgnoreCase)).Select((s) => s.Trim('[', ']')).ToArray(), sections);
            }
        }
Пример #24
0
        public InputSettings(IEnumerable <string> options, SettingsStore store) :
            base(SettingsStore.GetSettingsStore(store?.StoreType ?? StoreType.Registry, store.Location, "Keyboard"))
        {
            InitializeCommands(UserCommands);
            LoadSettings(options);

            UserCommandModifierInput userCommandModifier = UserCommands[UserCommand.DisplayNextWindowTab] as UserCommandModifierInput;

            WindowTabCommandModifier = (userCommandModifier.Alt ? KeyModifiers.Alt : KeyModifiers.None) | (userCommandModifier.Control ? KeyModifiers.Control : KeyModifiers.None) | (userCommandModifier.Shift ? KeyModifiers.Shift : KeyModifiers.None);

            userCommandModifier          = UserCommands[UserCommand.CameraMoveFast] as UserCommandModifierInput;
            CameraMoveFastModifier       = (userCommandModifier.Alt ? KeyModifiers.Alt : KeyModifiers.None) | (userCommandModifier.Control ? KeyModifiers.Control : KeyModifiers.None) | (userCommandModifier.Shift ? KeyModifiers.Shift : KeyModifiers.None);
            userCommandModifier          = UserCommands[UserCommand.CameraMoveSlow] as UserCommandModifierInput;
            CameraMoveSlowModifier       = (userCommandModifier.Alt ? KeyModifiers.Alt : KeyModifiers.None) | (userCommandModifier.Control ? KeyModifiers.Control : KeyModifiers.None) | (userCommandModifier.Shift ? KeyModifiers.Shift : KeyModifiers.None);
            userCommandModifier          = UserCommands[UserCommand.GameSuspendOldPlayer] as UserCommandModifierInput;
            GameSuspendOldPlayerModifier = (userCommandModifier.Alt ? KeyModifiers.Alt : KeyModifiers.None) | (userCommandModifier.Control ? KeyModifiers.Control : KeyModifiers.None) | (userCommandModifier.Shift ? KeyModifiers.Shift : KeyModifiers.None);
            userCommandModifier          = UserCommands[UserCommand.GameSwitchWithMouse] as UserCommandModifierInput;
            GameSwitchWithMouseModifier  = (userCommandModifier.Alt ? KeyModifiers.Alt : KeyModifiers.None) | (userCommandModifier.Control ? KeyModifiers.Control : KeyModifiers.None) | (userCommandModifier.Shift ? KeyModifiers.Shift : KeyModifiers.None);
        }
Пример #25
0
        public void LoadSectionsExcessiveTest()
        {
            int count = 100;

            string[] contentArray = new string[count * 6];
            for (int i = 0; i < 100; i++)
            {
                contentArray[i * 6 + 0] = "[ORTS]";
                contentArray[i * 6 + 1] = "name=value";
                contentArray[i * 6 + 2] = "[End]";
                contentArray[i * 6 + 3] = "name=value";
                contentArray[i * 6 + 4] = "name=value";
                contentArray[i * 6 + 5] = "#[End]";
            }
            string content = string.Join(Environment.NewLine, contentArray);

            using (TestFile file = new TestFile(content))
            {
                SettingsStoreLocalIni store = SettingsStore.GetSettingsStore(StoreType.Ini, file.FileName, null) as SettingsStoreLocalIni;
                string[] sections           = store.GetSectionNames();

                CollectionAssert.AreEqual(contentArray.Where((s) => s.StartsWith("[", StringComparison.OrdinalIgnoreCase)).Select((s) => s.Trim('[', ']')).ToArray(), sections);
            }
        }
Пример #26
0
 public UpdateState(SettingsStore store) :
     base(SettingsStore.GetSettingsStore(store.StoreType, store.Location, "UpdateState"))
 {
     LoadSettings(new string[0]);
 }
Пример #27
0
 public FolderSettings(IEnumerable <string> options, SettingsStore store) :
     base(SettingsStore.GetSettingsStore(store.StoreType, store.Location, "Folders"))
 {
     Folders = new Dictionary <string, string>();
     LoadSettings(options);
 }
Пример #28
0
 internal TrackViewerSettings(IEnumerable <string> options, SettingsStore store) :
     base(SettingsStore.GetSettingsStore(store.StoreType, store.Location, SettingLiteral))
 {
     LoadSettings(options);
     UserSettings = new UserSettings(options, store);
 }
Пример #29
0
 public InputSettings(IEnumerable <string> options, SettingsStore store) :
     base(SettingsStore.GetSettingsStore(store.StoreType, store.Location, "Keyboard"))
 {
     InitializeCommands(Commands);
     LoadSettings(options);
 }
Пример #30
0
 public UserSettings(IEnumerable <string> options) :
     this(options, SettingsStore.GetSettingsStore(SettingsStoreType, Location, null))
 {
 }