/// <summary> /// Loads the ini file and stores all settings within the global PlatformSettings instance. /// </summary> private static void LoadIniFile() { string procName = System.Diagnostics.Process.GetCurrentProcess().ProcessName; string iniName = $"{procName}.ini".ToLowerInvariant(); string currentDirectoryPath = Directory.GetCurrentDirectory(); DirectoryInfo directoryInfo = new DirectoryInfo(currentDirectoryPath); FileInfo iniFile = directoryInfo.GetFiles(iniName).FirstOrDefault(); if (iniFile == null) { throw new InvalidOperationException(string.Format("No ini file '{1}' could be found within the current working dir '{0}'", currentDirectoryPath, iniName)); } IniDocumentParser iniDocumentParser = new IniDocumentParser(iniFile); IPlainTextDocument document = iniDocumentParser.Parse(); PlatformSettings platformSettings = PlatformSettings.Instance; using (IEnumerator <KeyValuePair <string, string[]> > itr = document.GetEnumerator()) { while (itr.MoveNext()) { KeyValuePair <string, string[]> pair = itr.Current; string key = pair.Key; string[] values = pair.Value; string value = (values.Length == 0 ? string.Empty : values[0]); platformSettings.Add(key, value); // Make settings for all components available Environment.SetEnvironmentVariable($"motoi:{key}", value, EnvironmentVariableTarget.Process); } } }
public void Parse_StringManifestStream() { string manifest = "Vendor: Arian Storch;\r\n" + "Name: TestPlugin;\r\n" + "Version: 1.0.0;\r\n" + "Dependencies: org.demo.1, org.demo.2;"; IPlainTextDocument document = PlainTextParser.Instance. Parse(new MemoryStream(Encoding.Default.GetBytes(manifest)), new string[0], new[] { ";" }, new[] { "/" }, new[] { "," }); string vendorValue = document.SelectValue("vendor"); string nameValue = document.SelectValue("name"); string versionValue = document.SelectValue("version"); string[] dependenciesValue = document.SelectValues("dependencies"); Assert.AreEqual("Arian Storch", vendorValue, "Vendor value is wrong"); Assert.AreEqual("TestPlugin", nameValue, "Name value is wrong"); Assert.AreEqual("1.0.0", versionValue, "Version value is wrong"); Assert.AreEqual(2, dependenciesValue.Length, "Unexpected count of depencendies value"); Assert.AreEqual("org.demo.1", dependenciesValue[0], "Dependency value 1 is wrong"); Assert.AreEqual("org.demo.2", dependenciesValue[1], "Dependency value 2 is wrong"); }
/// <summary> Parses the given file with the given splitter tokens. </summary> /// <param name="fileInfo">File to parse</param> /// <param name="blockSplitter">Splitter tokens for a block unit</param> /// <param name="chunkSplitter">Splitter tokens for a chunk unit</param> /// <param name="nlNoBlock">Tokens that mark an ignorable newline character</param> /// <param name="inlineSplitter">Splitter tokens for inline value enumerations</param> /// <returns>Instance of IPlainTextDocument with the parsed values</returns> public IPlainTextDocument Parse(FileInfo fileInfo, string[] blockSplitter, string[] chunkSplitter, string[] nlNoBlock, string[] inlineSplitter) { IPlainTextDocument document = Parse(fileInfo.OpenRead(), blockSplitter, chunkSplitter, nlNoBlock, inlineSplitter); return(document); }
/// <summary> /// Parses the given file and returns an instance of <see cref="IPlainTextDocument"/>. /// </summary> /// <returns>Instance of IPlainTextDocument</returns> public virtual IPlainTextDocument Parse() { if (Stream == null) { throw new NullReferenceException("File stream is null!"); } IPlainTextDocument document = PlainTextParser.Instance.Parse(Stream, BlockSplitter, ChunkSplitter, NLNoBlock, InlineSplitter); return(document); }
public void Parse() { const string fileContent = "application: motoi.test\r\n" + "nl: de"; MemoryStream stream = new MemoryStream(Encoding.Default.GetBytes(fileContent)); IniDocumentParser parser = new IniDocumentParser(stream); IPlainTextDocument document = parser.Parse(); stream.Dispose(); string applicationValue = document.SelectValue("application"); string nlValue = document.SelectValue("nl"); Assert.AreEqual("motoi.test", applicationValue, "Wrong application value"); Assert.AreEqual("de", nlValue, "Wrong nl value"); }
/// <summary> /// Creates an instance of <see cref="IPluginSignature"/> from the given /// signature file stream. /// </summary> /// <param name="signatureFileStream">Stream to read from</param> /// <returns>Instance of ISignature</returns> public IPluginSignature CreateSignature(Stream signatureFileStream) { ManifestDocumentParser parser = new ManifestDocumentParser(signatureFileStream); IPlainTextDocument document = parser.Parse(); string nameValue = document.SelectValue("name"); string symbolicValue = document.SelectValue("symbolicName"); string versionValue = document.SelectValue("version"); string activatorValue = document.SelectValue("activator"); string vendorValue = document.SelectValue("vendor"); string[] dependenciesValue = document.SelectValues("dependencies"); PluginSignatureImpl pluginSignature = new PluginSignatureImpl { Name = nameValue, SymbolicName = symbolicValue, Vendor = vendorValue, Dependencies = dependenciesValue, Version = new Version(versionValue), PluginActivatorType = activatorValue }; return(pluginSignature); }
public void Parse() { FileInfo fileInfo = new FileInfo("./Additionals/signatur_simple.mf"); ManifestDocumentParser parser = new ManifestDocumentParser(fileInfo); IPlainTextDocument document = parser.Parse(); string nameValue = document.SelectValue("name"); string symbolicValue = document.SelectValue("symbolicName"); string versionValue = document.SelectValue("version"); string activatorValue = document.SelectValue("activator"); string vendorValue = document.SelectValue("vendor"); string[] dependenciesValue = document.SelectValues("dependencies"); Assert.AreEqual("TestBundle", nameValue, "Name value is wrong"); Assert.AreEqual("org.ptp4net.testbundle", symbolicValue, "Symbolic value is wrong"); Assert.AreEqual("0.0.1", versionValue, "Version value is wrong"); Assert.AreEqual("-", activatorValue, "Activator value is wrong"); Assert.AreEqual("PTP dev team", vendorValue, "Vendor value is wrong"); Assert.AreEqual("-", dependenciesValue[0], "Dependencies value is wrong"); }
public void Parse_ManifestFile() { FileInfo fileInfo = new FileInfo("./Additionals/signatur_test.mf"); IPlainTextDocument document = PlainTextParser.Instance. Parse(fileInfo, new string[0], new[] { ";" }, new[] { "/" }, new[] { "," }); string vendorValue = document.SelectValue("vendor"); string nameValue = document.SelectValue("name"); string versionValue = document.SelectValue("version"); string[] dependenciesValue = document.SelectValues("dependencies"); Assert.AreEqual("Arian Storch", vendorValue, "Vendor value is wrong"); Assert.AreEqual("TestPlugin", nameValue, "Name value is wrong"); Assert.AreEqual("1.0.0", versionValue, "Version value is wrong"); Assert.AreEqual(2, dependenciesValue.Length, "Unexpected count of depencendies value"); Assert.AreEqual("org.demo.1", dependenciesValue[0], "Dependency value 1 is wrong"); Assert.AreEqual("org.demo.2", dependenciesValue[1], "Dependency value 2 is wrong"); }