Exemple #1
0
        public void ProcessLine(string line)
        {
            line = line.Trim();

            if (IsSection(line))
            {
                _currentSection = ProcessSection(line, _iniFile);
                _currentSection.Comments.AddRange(_currentComments);
                _currentComments.Clear();
            }
            else if (IsKeyValue(line))
            {
                if (_currentSection == null)
                {
                    _currentSection = new IniSection(string.Empty);
                    _iniFile.Sections.Add(_currentSection);
                }

                _currentKeyValue = ProcessKeyValue(line, _currentSection);
                _currentKeyValue.Comments.AddRange(_currentComments);
                _currentComments.Clear();
            }
            else if (IsComment(line))
            {
                string comment = ProcessComment(line, _currentKeyValue);
                _currentComments.Add(comment);
            }
            else
            {
                // Blank (or junk) line. Ignore.
            }
        }
Exemple #2
0
		private static async Task<bool> GetChangeLog(String fileUrl)
		{
			UpdateLog.Clear();
			String filePath;
			IniDocument document = null;
			try
			{
                filePath = await Request.HttpDownload(fileUrl);
				document = new IniDocument(filePath);
				if(document != null)
				{

					IniKeyValue pair = document["setting"]["slogan"];
					String str = pair == null ? "" : pair.Value;
					UpdateLog.Add("slogan", str);
					pair = pair = document["setting"]["content"];
					str = pair == null ? "" : pair.Value;
					UpdateLog.Add("content", str);
					pair = document["update"]["sjh"];
					str = pair == null ? "" : pair.Value;
					UpdateLog.Add("sjhs", str);
				}
				return true;
			}
			catch
			{
				return false;
			}
		}
Exemple #3
0
        public void ProcessLine(string line)
        {
            line = line.Trim();

            if (IsSection(line))
            {
                _currentSection = ProcessSection(line, _iniFile);
                _currentSection.Comments.AddRange(_currentComments);
                _currentComments.Clear();
            }
            else if (IsKeyValue(line))
            {
                if (_currentSection == null)
                {
                    _currentSection = new IniSection(string.Empty);
                    _iniFile.Sections.Add(_currentSection);
                }

                _currentKeyValue = ProcessKeyValue(line, _currentSection);
                _currentKeyValue.Comments.AddRange(_currentComments);
                _currentComments.Clear();
            }
            else if (IsComment(line))
            {
                string comment = ProcessComment(line, _currentKeyValue);
                _currentComments.Add(comment);
            }
            else
            {
                // Blank (or junk) line. Ignore.
            }
        }
Exemple #4
0
        public void FromLine_Variable_Variable(string input, string expectedKey, string expectedValue)
        {
            IniKeyValue kv = IniKeyValue.FromLine(input);

            Assert.Equal(expectedKey, kv.Key);
            Assert.Equal(expectedValue, kv.Value);
        }
Exemple #5
0
 public IniLineProcessor(IniFile iniFile)
 {
     _iniFile         = iniFile;
     _currentSection  = null;
     _currentKeyValue = null;
     _currentComments = new List <string>();
 }
Exemple #6
0
 public IniLineProcessor(IniFile iniFile)
 {
     _iniFile = iniFile;
     _currentSection = null;
     _currentKeyValue = null;
     _currentComments = new List<string>();
 }
Exemple #7
0
        public void FromLine_IgnoringInlineComments(string input, string expectedKey, string expectedValue)
        {
            IniKeyValue kv = IniKeyValue.FromLine(input, false);

            Assert.Equal(expectedKey, kv.Key);
            Assert.Equal(expectedValue, kv.Value);
        }
Exemple #8
0
        private IniKeyValue ProcessKeyValue(string line, IniSection section)
        {
            string[]    split    = line.Split('=');
            IniKeyValue keyValue = new IniKeyValue(split[0].Trim(), split[1].Trim());

            section.KeyValues.Add(keyValue);
            return(keyValue);
        }
Exemple #9
0
        public void AddKeyValue_KeyExists_OldReferenceIsDiscarded()
        {
            // Arrange
            IniSection  section     = new IniSection("testSection");
            IniKeyValue oldKeyValue = new IniKeyValue("testKey", "oldValue");
            IniKeyValue newKeyValue = new IniKeyValue("testKey", "newValue");

            // Act
            section.KeyValues.Add(oldKeyValue);
            section.KeyValues.Add(newKeyValue);

            // Assert
            Assert.AreEqual(1, section.KeyValues.Count);
            Assert.AreNotSame(oldKeyValue, section.KeyValues["testKey"]);
            Assert.AreSame(newKeyValue, section.KeyValues["testKey"]);
        }
Exemple #10
0
        public void RemoveKeyValue_ByKeyDoesNotExist_ReturnsNull()
        {
            // Arrange
            IniSection section = new IniSection("testSection");

            section.KeyValues.Add("testKey1", "testValue1");
            section.KeyValues.Add("testKey2", "testValue2");

            // Act
            IniKeyValue removedKeyValue = section.KeyValues.Remove("otherKey");

            // Assert
            Assert.AreEqual(2, section.KeyValues.Count);
            Assert.IsNull(removedKeyValue);
            Assert.IsNull(section["otherKey"]);
        }
Exemple #11
0
        public void RemoveKeyValue_ByKeyExists_KeyValueIsRemoved()
        {
            // Arrange
            IniSection section = new IniSection("testSection");

            section.KeyValues.Add("testKey1", "testValue1");
            section.KeyValues.Add("testKey2", "testValue2");

            // Act
            IniKeyValue removedKeyValue = section.KeyValues.Remove("testKey1");

            // Assert
            Assert.AreEqual(1, section.KeyValues.Count);
            Assert.AreEqual("testKey1", removedKeyValue.Key);
            Assert.AreEqual("testValue1", removedKeyValue.Value);
            Assert.IsNull(section["testKey1"]);
        }
Exemple #12
0
        public void AddKeyValue_AddMultipleKeyValues_KeyValuesAreAdded()
        {
            // Arrange
            IniSection  section   = new IniSection("testSection");
            IniKeyValue keyValue1 = new IniKeyValue("testKey1", "testValue1");
            IniKeyValue keyValue2 = new IniKeyValue("testKey2", "testValue2");
            IniKeyValue keyValue3 = new IniKeyValue("testKey3", "testValue3");

            // Act
            section.KeyValues.Add(keyValue1);
            section.KeyValues.Add(keyValue2);
            section.KeyValues.Add(keyValue3);

            // Assert
            Assert.AreEqual(3, section.KeyValues.Count);
            Assert.AreSame(keyValue1, section.KeyValues.First());
            Assert.AreSame(keyValue3, section.KeyValues.Last());
        }
Exemple #13
0
        public void RemoveKeyValue_ByReferenceExists_KeyValueIsRemoved()
        {
            // Arrange
            IniSection  section   = new IniSection("testSection");
            IniKeyValue keyValue1 = new IniKeyValue("testKey1", "testValue1");
            IniKeyValue keyValue2 = new IniKeyValue("testKey2", "testValue2");

            section.KeyValues.Add(keyValue1);
            section.KeyValues.Add(keyValue2);

            // Act
            bool success = section.KeyValues.Remove(keyValue1);

            // Assert
            Assert.IsTrue(success);
            Assert.IsNull(section["testKey1"]);
            Assert.AreEqual(1, section.KeyValues.Count);
        }
Exemple #14
0
        public void RemoveKeyValue_ByReferenceDoesNotExist_NotSuccess()
        {
            // Arrange
            IniSection  section   = new IniSection("testSection");
            IniKeyValue keyValue1 = new IniKeyValue("testKey1", "testValue1");
            IniKeyValue keyValue2 = new IniKeyValue("testKey2", "testValue2");

            section.KeyValues.Add(keyValue1);
            section.KeyValues.Add(keyValue2);

            // Act
            IniKeyValue keyValueOther = new IniKeyValue("testKeyOther", "testValueOther");
            bool        success       = section.KeyValues.Remove(keyValueOther);

            // Assert
            Assert.IsFalse(success);
            Assert.IsNull(section["testKeyOther"]);
            Assert.AreEqual(2, section.KeyValues.Count);
        }
Exemple #15
0
        public void KeyValuesIndexerGet_IndexKeys_KeyValuesAreIndexed()
        {
            // Arrange
            IniSection section = new IniSection("testSection");

            section.KeyValues.Add("testKey1", "testValue1");
            section.KeyValues.Add("testKey2", "testValue2");
            section.KeyValues.Add("testKey3", "testValue3");

            // Act
            IniKeyValue indexedKeyValue1 = section.KeyValues["testKey1"];
            IniKeyValue indexedKeyValue2 = section.KeyValues["testKey2"];
            IniKeyValue indexedKeyValue3 = section.KeyValues["testKey3"];

            // Assert
            Assert.AreSame("testKey1", indexedKeyValue1.Key);
            Assert.AreSame("testKey2", indexedKeyValue2.Key);
            Assert.AreSame("testKey3", indexedKeyValue3.Key);
            Assert.AreSame("testValue1", indexedKeyValue1.Value);
            Assert.AreSame("testValue2", indexedKeyValue2.Value);
            Assert.AreSame("testValue3", indexedKeyValue3.Value);
        }
Exemple #16
0
        private string ProcessComment(string line, IniKeyValue keyValue)
        {
            string comment = line.Remove(0, 1).Trim();

            return(comment);
        }
Exemple #17
0
 private IniKeyValue ProcessKeyValue(string line, IniSection section)
 {
     string[] split = line.Split('=');
     IniKeyValue keyValue = new IniKeyValue(split[0].Trim(), split[1].Trim());
     section.KeyValues.Add(keyValue);
     return keyValue;
 }
Exemple #18
0
 private string ProcessComment(string line, IniKeyValue keyValue)
 {
     string comment = line.Remove(0, 1).Trim();
     return comment;
 }