示例#1
0
        private void RepoManagementForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (addRepoButton.Enabled && MessageBox.Show(Resources.UnsavedChangesQ, Resources.UnsavedChanges, MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                btnAddRepository_Click(addRepoButton, null);
            }

            ConfigIni.Instance.repos = repoList.Items.Cast <ListViewItem>().Select(i => (RepositoryInfo)(i.Tag)).ToArray();
            ConfigIni.Save();
            MainForm.StaticRef.populateRepos();
        }
            public void When_FetchingUncachedConfigFromFilledCache(string platform, string category, ConfigHierarchyLevel level)
            {
                var hierarchy   = new MockFileConfigHierarchy(@".\MyProject\", @".\Engine\");
                var dummyConfig = new ConfigIni();

                hierarchy.Exposed_CacheConfig("OtherPlatform", category, level, dummyConfig);
                hierarchy.Exposed_CacheConfig(platform, "OtherCategory", level, dummyConfig);
                var gotConfig = hierarchy.Exposed_GetCachedConfig(platform, category, level);

                Assert.That(gotConfig, Is.Null);
            }
示例#3
0
        public void When_ConstructedWithNameAndSections()
        {
            string    name     = "Engine/Config/Base.ini";
            ConfigIni config   = null;
            var       sectionA = new ConfigIniSection("A");
            var       sectionB = new ConfigIniSection("B");

            Assert.That(() => { config = new ConfigIni(name, new[] { sectionA, sectionB }); }, Throws.Nothing);
            Assert.That(config.Name, Is.EqualTo(name));
            Assert.That(config.Sections, Is.EquivalentTo(new[] { sectionA, sectionB }));
        }
示例#4
0
 IniToken AssertNAddedTokenToSection(ConfigIni configIni, ConfigIniSection expectedSection, int expectedTokens)
 {
     Assert.That(configIni.Sections, Has.Count.EqualTo(1));
     Assert.That(configIni.Sections[0], Is.SameAs(expectedSection));
     Assert.That(configIni.Sections[0].Tokens, Has.Count.EqualTo(expectedTokens));
     for (int tokenI = 0; tokenI < expectedTokens; tokenI++)
     {
         Assert.That(configIni.Sections[0].Tokens[tokenI], Is.Not.Null);
     }
     return(configIni.Sections[0].Tokens[expectedTokens - 1]);
 }
示例#5
0
            public void When_Unmodified_DoesRetainEverything(string original)
            {
                var config = new ConfigIni();

                config.Read(new StringReader(original));
                var writer = new StringWriter();

                config.Write(writer);

                Assert.That(writer.ToString(), Is.EqualTo(original));
            }
            public void When_CachingConfigAgain(string platform, string category, ConfigHierarchyLevel level)
            {
                var hierarchy    = new MockFileConfigHierarchy(@".\MyProject\", @".\Engine\");
                var dummyConfig1 = new ConfigIni();
                var dummyConfig2 = new ConfigIni();

                hierarchy.Exposed_CacheConfig(platform, category, level, dummyConfig1);
                hierarchy.Exposed_CacheConfig(platform, category, level, dummyConfig2);
                var gotConfig = hierarchy.Exposed_GetCachedConfig(platform, category, level);

                Assert.That(gotConfig, Is.SameAs(dummyConfig2));
            }
示例#7
0
            public void When_Has2DuplicateWithin2DistinctSections()
            {
                var sectionA1 = new ConfigIniSection("A");
                var tokenA1_1 = new TextToken();
                var tokenA1_2 = new TextToken();
                var tokenA1_3 = new TextToken();

                sectionA1.Tokens.Add(tokenA1_1);
                sectionA1.Tokens.Add(tokenA1_2);
                sectionA1.Tokens.Add(tokenA1_3);

                var sectionB1 = new ConfigIniSection("B");
                var tokenB1_1 = new TextToken();
                var tokenB1_2 = new TextToken();
                var tokenB1_3 = new TextToken();

                sectionB1.Tokens.Add(tokenB1_1);
                sectionB1.Tokens.Add(tokenB1_2);
                sectionB1.Tokens.Add(tokenB1_3);

                var sectionB2 = new ConfigIniSection("B");
                var tokenB2_1 = new TextToken();
                var tokenB2_2 = new TextToken();
                var tokenB2_3 = new TextToken();

                sectionB2.Tokens.Add(tokenB2_1);
                sectionB2.Tokens.Add(tokenB2_2);
                sectionB2.Tokens.Add(tokenB2_3);

                var sectionC1 = new ConfigIniSection("C");
                var tokenC1_1 = new TextToken();
                var tokenC1_2 = new TextToken();
                var tokenC1_3 = new TextToken();

                sectionC1.Tokens.Add(tokenC1_1);
                sectionC1.Tokens.Add(tokenC1_2);
                sectionC1.Tokens.Add(tokenC1_3);

                var config = new ConfigIni();

                config.Sections.Add(sectionA1);
                config.Sections.Add(sectionB1);
                config.Sections.Add(sectionB2);
                config.Sections.Add(sectionC1);

                config.MergeDuplicateSections();

                Assert.That(config.Sections, Is.EquivalentTo(new[] { sectionA1, sectionB1, sectionC1 }));
                Assert.That(sectionA1.Tokens, Is.EquivalentTo(new[] { tokenA1_1, tokenA1_2, tokenA1_3 }));
                Assert.That(sectionB1.Tokens, Is.EquivalentTo(new[] { tokenB1_1, tokenB1_2, tokenB1_3, tokenB2_1, tokenB2_2, tokenB2_3 }));
                Assert.That(sectionC1.Tokens, Is.EquivalentTo(new[] { tokenC1_1, tokenC1_2, tokenC1_3 }));
            }
示例#8
0
            public void When_LineIsInvalid_TreatsAsText(string line)
            {
                var configIni      = new ConfigIni();
                var currentSection = new ConfigIniSection();

                configIni.Sections.Add(currentSection);

                Assert.That(() => configIni.ReadLineWithoutLineEnding(line, ref currentSection), Throws.Nothing);

                var tokenT = AssertSingleAddedTokenToSection <TextToken>(configIni, currentSection);

                Assert.That(tokenT.Text, Is.EqualTo(line));
            }
示例#9
0
            public void When_LineIsNull_DoesNothing(string line)
            {
                var configIni      = new ConfigIni();
                var currentSection = new ConfigIniSection();

                configIni.Sections.Add(currentSection);

                Assert.That(() => configIni.ReadLineWithoutLineEnding(line, ref currentSection), Throws.Nothing);

                Assert.That(configIni.Sections, Has.Count.EqualTo(1));
                Assert.That(configIni.Sections[0], Is.SameAs(currentSection));
                Assert.That(configIni.Sections[0].Tokens, Is.Empty);
            }
示例#10
0
 /// <summary>
 /// 获取自动更新数据
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 private string AutoUpdate(HttpContext context)
 {
     try
     {
         string    configFile = HttpContext.Current.Server.MapPath("~/Version/VersionConfig.ini");
         ConfigIni conIni     = new ConfigIni(configFile);
         return("{\"appid\":\"" + conIni.GetStringValue("appid") + "\",\"title\":\"" + conIni.GetStringValue("title") + "\",\"note\":\"" + conIni.GetStringValue("note") + "\",\"version\":\"" + conIni.GetStringValue("version") + "\",\"url\":\"" + conIni.GetStringValue("url") + "\"}");
     }
     catch (Exception ex)
     {
         SystemErrorPlug.ErrorRecord(ex.ToString());
         return(JsonHelper <Messaging <string> > .EntityToJson(new Messaging <string>("500", ex.Message)));
     }
 }
示例#11
0
            public void When_LineIsComment(string line)
            {
                var configIni      = new ConfigIni();
                var currentSection = new ConfigIniSection();

                configIni.Sections.Add(currentSection);

                Assert.That(() => configIni.ReadLineWithoutLineEnding(line, ref currentSection), Throws.Nothing);

                var tokenT = AssertSingleAddedTokenToSection <CommentToken>(configIni, currentSection);

                Assert.That(tokenT.Lines, Has.Count.EqualTo(1));
                Assert.That(tokenT.Lines[0].ToString(), Is.EqualTo(line));
            }
示例#12
0
            public void When_ReaderHasMultipleEmptyLines()
            {
                var configIni        = new ConfigIni();
                var textStringReader = new StringReader("\n\n\n\n");

                Assert.That(() => configIni.Read(textStringReader), Throws.Nothing);

                Assert.That(configIni.Sections, Has.Count.EqualTo(1));
                Assert.That(configIni.Sections[0].Name, Is.Null);
                Assert.That(configIni.Sections[0].Tokens, Has.Count.EqualTo(1));
                Assert.That(configIni.Sections[0].Tokens[0], Is.TypeOf <WhitespaceToken>());
                var whitespaceToken = configIni.Sections[0].Tokens[0] as WhitespaceToken;

                Assert.That(whitespaceToken.Lines, Has.Count.EqualTo(4));
            }
示例#13
0
            public void When_LineIsRemoveAll(string line, string expectedKey)
            {
                var configIni      = new ConfigIni();
                var currentSection = new ConfigIniSection();

                configIni.Sections.Add(currentSection);

                Assert.That(() => configIni.ReadLineWithoutLineEnding(line, ref currentSection), Throws.Nothing);

                var tokenT = AssertSingleAddedTokenToSection <InstructionToken>(configIni, currentSection);

                Assert.That(tokenT.InstructionType, Is.EqualTo(InstructionType.RemoveAll));
                Assert.That(tokenT.Key, Is.EqualTo(expectedKey));
                Assert.That(tokenT.Value, Is.Null);
            }
示例#14
0
        /// <summary>
        /// Gets the configs for the given platform & category in order of ascending levels (<see cref="ConfigHierarchyLevel.Base"/> being the first)
        /// </summary>
        public void GetConfigs(string platform, string category, ConfigHierarchyLevelRange range, IList <ConfigIni> configs)
        {
            var levels = ConfigHierarchyLevelExtensions.GetLevelsAscending();

            foreach (var level in levels)
            {
                if (range.Includes(level))
                {
                    ConfigIni config = GetConfig(platform, category, level);
                    if (config != null)
                    {
                        configs.Add(config);
                    }
                }
            }
        }
示例#15
0
        public override ConfigIni GetConfig(string platform, string category, ConfigHierarchyLevel level)
        {
            ConfigIni config = null;

            if (!IsConfigCached(platform, category, level))
            {
                config = LoadConfig(platform, category, level);
                CacheConfig(platform, category, level, config);
            }
            else
            {
                config = GetCachedConfig(platform, category, level);
            }

            return(config);
        }
示例#16
0
        public void When_ReadConfig_DefaultGame()
        {
            //Create a new config with a name for identification
            var config = new ConfigIni("DefaultGame");

            //Load the configs contents from a file
            config.Read(File.OpenText(TestUtils.GetTestDataPath("MockProject/Config/DefaultGame.ini")));

            //Evaluate the values and put them into a list. Should the property only have a single value, the list will have a single element.
            //Should the property not exist or should all its values have been deleted via config, the list will be empty.
            var values = new List <string>();

            config.EvaluatePropertyValues("/Script/EngineSettings.GeneralProjectSettings", "ProjectID", values);

            Assert.That(values, Is.EquivalentTo(new[] { "3F9D696D4363312194B0ECB2671E899F" }));
        }
示例#17
0
        /// <summary>
        /// Reads a second set of attributes for a control's child controls.
        /// Enables linking controls to controls that are defined after them.
        /// </summary>
        private void ReadLateAttributesForControl(XNAControl control)
        {
            var section = ConfigIni.GetSection(control.Name);

            if (section == null)
            {
                return;
            }

            var children = Children.ToList();

            foreach (var child in children)
            {
                // This logic should also be enabled for other types in the future,
                // but it requires changes in XNAUI
                if (!(child is XNATextBox))
                {
                    continue;
                }

                var childSection = ConfigIni.GetSection(child.Name);
                if (childSection == null)
                {
                    continue;
                }

                string nextControl = childSection.GetStringValue("NextControl", null);
                if (!string.IsNullOrWhiteSpace(nextControl))
                {
                    var otherChild = children.Find(c => c.Name == nextControl);
                    if (otherChild != null)
                    {
                        ((XNATextBox)child).NextControl = otherChild;
                    }
                }

                string previousControl = childSection.GetStringValue("PreviousControl", null);
                if (!string.IsNullOrWhiteSpace(previousControl))
                {
                    var otherChild = children.Find(c => c.Name == previousControl);
                    if (otherChild != null)
                    {
                        ((XNATextBox)child).PreviousControl = otherChild;
                    }
                }
            }
        }
示例#18
0
            public void When_UnmodifiedFile_IsUnchanged(string file)
            {
                var filePath = TestUtils.GetTestDataPath(file);
                var reader   = File.OpenText(filePath);
                var config   = new ConfigIni();

                config.Read(reader);
                reader.Close();

                var fileContent = File.ReadAllText(filePath);
                var writer      = new StringWriter();

                config.Write(writer);
                var writerContent = writer.ToString();

                Assert.That(writerContent, Is.EqualTo(fileContent));
            }
示例#19
0
            public void When_LineIsRepeatedComment(string[] lines)
            {
                var configIni      = new ConfigIni();
                var currentSection = new ConfigIniSection();

                configIni.Sections.Add(currentSection);

                foreach (var line in lines)
                {
                    Assert.That(() => configIni.ReadLineWithoutLineEnding(line, ref currentSection), Throws.Nothing);
                }

                var tokenT = AssertSingleAddedTokenToSection <CommentToken>(configIni, currentSection);

                Assert.That(tokenT.Lines, Has.Count.EqualTo(lines.Length));
                Assert.That(tokenT.GetStringLines(), Is.EquivalentTo(lines));
            }
示例#20
0
 private void btnGuardar_Click(object sender, EventArgs e)
 {
     if (txtServidor.Text != string.Empty && txtBd.Text != string.Empty && txtUsuario.Text != string.Empty && txtClave.Text != string.Empty)
     {
         string    path   = Path.GetFullPath("Conexion.ini");
         ConfigIni config = new Clases.ConfigIni(path);
         config.EscribirValores("Dynamic", "Host", txtServidor.Text.Trim());
         config.EscribirValores("Dynamic", "Bd", txtBd.Text.Trim());
         config.EscribirValores("Dynamic", "Id", txtUsuario.Text.Trim());
         config.EscribirValores("Dynamic", "Password", txtClave.Text.Trim());
         ConfigIni PropiedadesConexion = new ConfigIni(path);
         this.Close();
     }
     else
     {
         Dialogs.Show("Debes rellenar todos los campos", DialogsType.Info);
     }
 }
示例#21
0
            public void When_ReadingRepeatedly()
            {
                var configIni = new ConfigIni();

                var textStringReaderA = new StringReader(";CommentA\n;CommentB");
                var textStringReaderB = new StringReader(";CommentC\n;CommentD");

                Assert.That(() => configIni.Read(textStringReaderA), Throws.Nothing);
                Assert.That(() => configIni.Read(textStringReaderB), Throws.Nothing);

                Assert.That(configIni.Sections, Has.Count.EqualTo(1));
                Assert.That(configIni.Sections[0].Name, Is.Null);
                Assert.That(configIni.Sections[0].Tokens, Has.Count.EqualTo(1));
                Assert.That(configIni.Sections[0].Tokens[0], Is.TypeOf <CommentToken>());
                var commentToken = configIni.Sections[0].Tokens[0] as CommentToken;

                Assert.That(commentToken.Lines, Has.Count.EqualTo(4));
            }
示例#22
0
            public void When_LineIsSectionHeader(string line, string expectedName, string expectedWastePrefix = null, string expectedWasteSuffix = null)
            {
                var configIni      = new ConfigIni();
                var initialSection = new ConfigIniSection();

                configIni.Sections.Add(initialSection);
                var currentSection = initialSection;

                Assert.That(() => configIni.ReadLineWithoutLineEnding(line, ref currentSection), Throws.Nothing);

                Assert.That(initialSection, Is.Not.SameAs(currentSection));
                Assert.That(currentSection, Is.Not.Null);
                Assert.That(configIni.Sections, Has.Count.EqualTo(2));
                Assert.That(configIni.Sections[0], Is.SameAs(initialSection));
                Assert.That(configIni.Sections[1], Is.SameAs(currentSection));
                Assert.That(currentSection.Name, Is.EqualTo(expectedName));
                Assert.That(currentSection.LineWastePrefix, Is.EqualTo(expectedWastePrefix));
                Assert.That(currentSection.LineWasteSuffix, Is.EqualTo(expectedWasteSuffix));
            }
示例#23
0
            public void When_HasSingleSection()
            {
                var sectionA1 = new ConfigIniSection("A");
                var tokenA1_1 = new TextToken();
                var tokenA1_2 = new TextToken();
                var tokenA1_3 = new TextToken();

                sectionA1.Tokens.Add(tokenA1_1);
                sectionA1.Tokens.Add(tokenA1_2);
                sectionA1.Tokens.Add(tokenA1_3);

                var config = new ConfigIni();

                config.Sections.Add(sectionA1);

                config.MergeDuplicateSections();

                Assert.That(config.Sections, Is.EquivalentTo(new[] { sectionA1 }));
                Assert.That(sectionA1.Tokens, Is.EquivalentTo(new[] { tokenA1_1, tokenA1_2, tokenA1_3 }));
            }
            public void When_CalledTwice_SkipsLoadConfig(string platform, string category, ConfigHierarchyLevel level)
            {
                var hierarchy        = new MockFileConfigHierarchy(@".\MyProject\", @".\Engine\");
                var fakeLoadedConfig = new ConfigIni();

                int countCallLoadConfig = 0;

                hierarchy.OnLoadConfig += (loadPlatform, loadCategory, loadHierarchyLevel) =>
                {
                    countCallLoadConfig++;
                    return(fakeLoadedConfig);
                };

                var gotConfig1 = hierarchy.GetConfig(platform, category, level);
                var gotConfig2 = hierarchy.GetConfig(platform, category, level);

                Assert.That(gotConfig2, Is.SameAs(gotConfig1));
                Assert.That(gotConfig2, Is.SameAs(fakeLoadedConfig));
                Assert.That(countCallLoadConfig, Is.EqualTo(1));
            }
示例#25
0
            public void When_HasSections_RelaysCallsToSections()
            {
                var callLog     = new List <ConfigIniSection>();
                var config      = new ConfigIni();
                var spySectionA = new SpyConfigIniSection("A")
                {
                    Write_CallLog = callLog
                };
                var spySectionB = new SpyConfigIniSection("B")
                {
                    Write_CallLog = callLog
                };

                config.Sections.Add(spySectionA);
                config.Sections.Add(spySectionB);

                var writer = new StringWriter();

                config.Write(writer);
                Assert.That(callLog, Is.EquivalentTo(new[] { spySectionA, spySectionB }));
            }
            public void When_CalledOnce_CallsLoadConfig(string platform, string category, ConfigHierarchyLevel level)
            {
                var hierarchy        = new MockFileConfigHierarchy(@".\MyProject\", @".\Engine\");
                var fakeLoadedConfig = new ConfigIni();

                bool didCallLoadConfig = false;

                hierarchy.OnLoadConfig += (loadPlatform, loadCategory, loadHierarchyLevel) =>
                {
                    Assert.That(loadPlatform, Is.EqualTo(platform));
                    Assert.That(loadCategory, Is.EqualTo(category));
                    Assert.That(loadHierarchyLevel, Is.EqualTo(level));
                    didCallLoadConfig = true;
                    return(fakeLoadedConfig);
                };

                var gotConfig = hierarchy.GetConfig(platform, category, level);

                Assert.That(didCallLoadConfig, Is.True);
                Assert.That(gotConfig, Is.SameAs(fakeLoadedConfig));
            }
示例#27
0
            public void When_ReaderHasMultipleValidLines()
            {
                var    configIni  = new ConfigIni();
                string textString = String.Join("\n", new[] {
                    ";Comment",
                    "",
                    "[Header]",
                    "Key=Value"
                });
                var textStringReader = new StringReader(textString);

                Assert.That(() => configIni.Read(textStringReader), Throws.Nothing);

                Assert.That(configIni.Sections, Has.Count.EqualTo(2));
                Assert.That(configIni.Sections[0].Name, Is.Null);
                Assert.That(configIni.Sections[0].Tokens, Has.Count.EqualTo(2));
                Assert.That(configIni.Sections[0].Tokens[0], Is.TypeOf <CommentToken>());
                Assert.That(configIni.Sections[0].Tokens[1], Is.TypeOf <WhitespaceToken>());
                Assert.That(configIni.Sections[1].Tokens, Has.Count.EqualTo(1));
                Assert.That(configIni.Sections[1].Tokens[0], Is.TypeOf <InstructionToken>());
            }
示例#28
0
 private void LoadConfig()
 {
     if (File.Exists(ConfigIni.Path))
     {
         KeepOldversion = ConfigIni.Read("KeepLastVersion", "Updater") == "1";
         KeepInstaller  = ConfigIni.Read("KeepInstaller", "Updater") == "1";
         var lastpath = ConfigIni.Read("LastPath", "Updater");
         if (!string.IsNullOrEmpty(lastpath))
         {
             var bk = Path.GetFullPath(lastpath);
             if (Directory.Exists(bk))
             {
                 SelectedPath = bk;
             }
             return;
         }
     }
     if (TryGetCurrChromeExePath(out string path))
     {
         SelectedPath = Path.GetDirectoryName(path);
     }
 }
示例#29
0
            public void When_CalledWithoutPlatform_RelaysToDefaultPlatform()
            {
                int spyCount = 0;

                var expectedConfig = new ConfigIni("MyConfig");

                var hierarchy = new MockConfigHierarchy()
                {
                    OnSpyGetConfig = (platform, category, level) =>
                    {
                        spyCount++;
                        Assert.That(level, Is.EqualTo(ConfigHierarchyLevel.BaseCategory));
                        Assert.That(category, Is.EqualTo("MyCategory"));
                        Assert.That(platform, Is.EqualTo("Default"));
                        return(expectedConfig);
                    }
                };

                var config = hierarchy.GetConfig("MyCategory", ConfigHierarchyLevel.BaseCategory);

                Assert.That(spyCount, Is.EqualTo(1));
                Assert.That(config, Is.SameAs(expectedConfig));
            }
示例#30
0
            public void When_HasNullSections_DoesSkipNull()
            {
                var callLog     = new List <ConfigIniSection>();
                var config      = new ConfigIni();
                var spySectionA = new SpyConfigIniSection("A")
                {
                    Write_CallLog = callLog
                };
                var spySectionB = new SpyConfigIniSection("B")
                {
                    Write_CallLog = callLog
                };

                config.Sections.Add(spySectionA);
                config.Sections.Add(null);
                config.Sections.Add(spySectionB);

                var writer = new StringWriter();

                config.Write(writer);
                Assert.That(config.Sections, Has.Count.EqualTo(3));
                Assert.That(callLog, Is.EquivalentTo(new[] { spySectionA, spySectionB }));
            }