/// <include file='IniSectionCollection.xml' path='//Method[@name="Add"]/docs/*' /> public void Add(IniSection section) { if (list.Contains (section)) { throw new ArgumentException ("IniSection already exists"); } list.Add (section.Name, section); }
public static void CreateClient(IniSection settings) { CreateClient( settings.GetValue( "server" ), Int32.Parse( settings.GetValue( "port" ) ), settings.GetValue( "address" ), settings.GetValue( "username" ), settings.GetValue( "password" ), Boolean.Parse( settings.GetValue("ssl"))); }
public void SetKey () { IniDocument doc = new IniDocument (); IniSection section = new IniSection ("new section"); doc.Sections.Add (section); section.Set ("new key", "some value"); Assert.IsTrue (section.Contains ("new key")); Assert.AreEqual ("some value", section.GetValue ("new key")); }
public void SetSection () { IniDocument doc = new IniDocument (); IniSection section = new IniSection ("new section"); doc.Sections.Add (section); Assert.AreEqual ("new section", doc.Sections[0].Name); Assert.AreEqual ("new section", doc.Sections["new section"].Name); section = new IniSection ("a section", "a comment"); doc.Sections.Add (section); Assert.AreEqual ("a comment", doc.Sections[1].Comment); }
public static void Initialize(IniSection ini) { _sPages = new Dictionary<string, Page>(); _sContent = new Dictionary<string, BinaryFile>(); _sIncludes = new Dictionary<string, MethodInfo>(); _sContentDirectory = FormatPath(Path.GetFullPath(ini.GetValue("pagesdir") ?? "res")); _sAllowedExtensions = (ini.GetValue("allowedext") ?? "").Split(',').ToList(); for (int i = 0; i < _sAllowedExtensions.Count; ++i) _sAllowedExtensions[i] = _sAllowedExtensions[i].Trim().ToLower(); if (!Path.IsPathRooted(_sContentDirectory)) _sContentDirectory = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, _sContentDirectory); Console.WriteLine("Initializing content..."); InitializeDirectory(_sContentDirectory); _watcher = new FileSystemWatcher(_sContentDirectory); _watcher.Created += (sender, e) => { Console.WriteLine("Content created"); UpdateFile(e.FullPath); }; _watcher.Changed += (sender, e) => { Console.WriteLine("Content updated"); UpdateFile(e.FullPath); }; _watcher.Renamed += (sender, e) => { Console.WriteLine("Content renamed"); UpdateFile(e.OldFullPath); UpdateFile(e.FullPath); }; _watcher.Deleted += (sender, e) => { Console.WriteLine("Content removed"); UpdateFile(e.FullPath); }; _watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; _watcher.IncludeSubdirectories = true; _watcher.EnableRaisingEvents = true; }
/// <summary> /// Create an application shortcut from the ini section provided. /// </summary> /// <param name="sect">The section to create it from.</param> public ApplicationShortcut(IniSection sect) { Name = sect.GetValue("name"); if (sect.Contains("icon")) { String ipath = sect.GetValue("icon"); try { Icon = Image.FromFile(Program.cfg.PathRelativeToConfiguration(ipath)); } catch (Exception) { Icon = SystemIcons.Error.ToBitmap(); } } else { Icon = SystemIcons.Application.ToBitmap(); } Exec = sect.GetValue("exec"); if (sect.Contains("opts")) { Opts = sect.GetValue("opts"); } Metadata = new Dictionary<string,string>(); foreach (String k in sect.GetKeys()) { if (k[0] == '_') { // It's metadata, 'jo. Metadata.Add(k.Substring(1), sect.GetValue(k)); } } if (sect.Contains("desc")) { Desc = sect.GetValue("desc").Replace("|", "\r\n"); } }
/// <summary> /// Loads the file not saving comments. /// </summary> private void Load(IniReader reader) { reader.IgnoreComments = false; bool sectionFound = false; IniSection section = null; while (reader.Read()) { switch (reader.Type) { case IniType.Empty: if (!sectionFound) { initialComment.Add(reader.Comment); } else { section.Set(reader.Comment); } break; case IniType.Section: sectionFound = true; section = new IniSection(reader.Name, reader.Comment); sections.Add(section); break; case IniType.Key: section.Set(reader.Name, reader.Value, reader.Comment); break; } } reader.Close(); }
/// <include file='IniSectionCollection.xml' path='//Method[@name="CopyToStrong"]/docs/*' /> public void CopyTo(IniSection[] array, int index) { ((ICollection)list).CopyTo (array, index); }
/// <summary> /// Merges all of the configs from the config collection into the /// IniDocument before it is saved. /// </summary> private void MergeConfigsIntoDocument () { RemoveSections (); foreach (IConfig config in this.Configs) { string[] keys = config.GetKeys (); // Create a new section if one doesn't exist if (iniDocument.Sections[config.Name] == null) { IniSection section = new IniSection (config.Name); iniDocument.Sections.Add (section); } RemoveKeys (config.Name); for (int i = 0; i < keys.Length; i++) { iniDocument.Sections[config.Name].Set (keys[i], config.Get (keys[i])); } } }
public void SaveToStream() { string filePath = "SaveToStream.ini"; FileStream stream = new FileStream (filePath, FileMode.Create); // Create a new document and save to stream IniDocument doc = new IniDocument (); IniSection section = new IniSection ("Pets"); section.Set ("dog", "rover"); section.Set ("cat", "muffy"); doc.Sections.Add (section); doc.Save (stream); stream.Close (); IniDocument newDoc = new IniDocument (new FileStream (filePath, FileMode.Open)); section = newDoc.Sections["Pets"]; Assert.IsNotNull (section); Assert.AreEqual (2, section.GetKeys ().Length); Assert.AreEqual ("rover", section.GetValue ("dog")); Assert.AreEqual ("muffy", section.GetValue ("cat")); stream.Close (); File.Delete (filePath); }
public void SaveAsPythonStyle() { string filePath = "Save.ini"; FileStream stream = new FileStream (filePath, FileMode.Create); // Create a new document and save to stream IniDocument doc = new IniDocument (); doc.FileType = IniFileType.PythonStyle; IniSection section = new IniSection ("Pets"); section.Set ("my comment"); section.Set ("dog", "rover"); doc.Sections.Add (section); doc.Save (stream); stream.Close (); StringWriter writer = new StringWriter (); writer.WriteLine ("[Pets]"); writer.WriteLine ("# my comment"); writer.WriteLine ("dog : rover"); StreamReader reader = new StreamReader (filePath); Assert.AreEqual (writer.ToString (), reader.ReadToEnd ()); reader.Close (); File.Delete (filePath); }
public void SambaLoadAsStandard() { string filePath = "Save.ini"; FileStream stream = new FileStream (filePath, FileMode.Create); // Create a new document and save to stream IniDocument doc = new IniDocument (); doc.FileType = IniFileType.SambaStyle; IniSection section = new IniSection ("Pets"); section.Set ("my comment"); section.Set ("dog", "rover"); doc.Sections.Add (section); doc.Save (stream); stream.Close (); IniDocument iniDoc = new IniDocument (); iniDoc.FileType = IniFileType.Standard; iniDoc.Load (filePath); File.Delete (filePath); }
/// <summary> /// Loads the file not saving comments. /// </summary> private void LoadReader(IniReader reader) { reader.IgnoreComments = false; bool sectionFound = false; IniSection section = null; try { while (reader.Read ()) { switch (reader.Type) { case IniType.Empty: if (!sectionFound) { initialComment.Add (reader.Comment); } else { section.Set (reader.Comment); } break; case IniType.Section: sectionFound = true; // If section already exists then overwrite it if (sections[reader.Name] != null) { sections.RemoveSection (reader.Name); } section = new IniSection (reader.Name, reader.Comment); sections.Add (section); break; case IniType.Key: if (section.GetValue (reader.Name) == null) { section.Set (reader.Name, reader.Value, reader.Comment); } break; } } } catch (Exception ex) { throw ex; } finally { // Always close the file reader.Close (); } }
//added by hatton for Chorus public IniSection GetOrCreate(string name) { if (_sectionNames.Contains(name)) return (IniSection)_sectionNames[name]; var s = new IniSection(name); Add(s); return s; }
/// <include file='IniSectionCollection.xml' path='//Method[@name="CopyToStrong"]/docs/*' /> public void CopyTo(IniSection[] array, int index) { ((ICollection)_sectionNames).CopyTo (array, index); }
/// <summary> /// Loads the file not saving comments. /// </summary> private void Load(IniReader reader) { reader.IgnoreComments = false; bool sectionFound = false; IniSection section = null; while (reader.Read ()) { switch (reader.Type) { case IniType.Empty: if (!sectionFound) { initialComment.Add (reader.Comment); } else { section.Set (reader.Comment); } break; case IniType.Section: sectionFound = true; section = new IniSection (reader.Name, reader.Comment); sections.Add (section); break; case IniType.Key: section.Set (reader.Name, reader.Value, reader.Comment); break; } } reader.Close (); }