/// <include file='IniConfigSource.xml' path='//Method[@name="Save"]/docs/*' /> public override void Save() { if (!IsSavable()) { throw new ArgumentException("Source cannot be saved in this state"); } MergeConfigsIntoDocument(); iniDocument.Save(this.savePath); base.Save(); }
public void SaveAsPythonStyle() { const string filePath = "Save.ini"; var stream = new FileStream(filePath, FileMode.Create); // Create a new document and save to stream var doc = new IniDocument { FileType = IniFileType.PythonStyle }; var section = new IniSection("Pets"); section.Set("my comment"); section.Set("dog", "rover"); doc.Sections.Add(section); doc.Save(stream); stream.Close(); var writer = new StringWriter(); writer.WriteLine("[Pets]"); writer.WriteLine("# my comment"); writer.WriteLine("dog : rover"); var reader = new StreamReader(filePath); Assert.AreEqual(writer.ToString(), reader.ReadToEnd()); reader.Close(); File.Delete(filePath); }
public void SambaLoadAsStandard() { IniDocument doc = new IniDocument(); Assert.Throws <IniException>(() => { var filePath = "Save.ini"; var stream = new FileStream(filePath, FileMode.Create); // Create a new document and save to stream doc.FileType = IniFileType.SambaStyle; var section = new IniSection("Pets"); section.Set("my comment"); section.Set("dog", "rover"); doc.Sections.Add(section); doc.Save(stream); stream.Close(); var iniDoc = new IniDocument { FileType = IniFileType.Standard }; iniDoc.Load(filePath); File.Delete(filePath); }); }
public void SaveDocumentWithComments() { StringWriter writer = new StringWriter(); writer.WriteLine("; some comment"); writer.WriteLine(""); // empty line writer.WriteLine("[new section]"); writer.WriteLine(" dog = rover"); writer.WriteLine(""); // Empty line writer.WriteLine("; a comment"); writer.WriteLine(" cat = muffy"); IniDocument doc = new IniDocument(new StringReader(writer.ToString())); StringWriter newWriter = new StringWriter(); doc.Save(newWriter); StringReader reader = new StringReader(newWriter.ToString()); Assert.AreEqual("; some comment", reader.ReadLine()); Assert.AreEqual("", reader.ReadLine()); Assert.AreEqual("[new section]", reader.ReadLine()); Assert.AreEqual("dog = rover", reader.ReadLine()); Assert.AreEqual("", reader.ReadLine()); Assert.AreEqual("; a comment", reader.ReadLine()); Assert.AreEqual("cat = muffy", reader.ReadLine()); writer.Close(); }
public void SaveToStream() { const string filePath = "SaveToStream.ini"; var stream = new FileStream(filePath, FileMode.Create); // Create a new document and save to stream var doc = new IniDocument(); var section = new IniSection("Pets"); section.Set("dog", "rover"); section.Set("cat", "muffy"); doc.Sections.Add(section); doc.Save(stream); stream.Close(); var 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 SaveAsMysqlStyle() { 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.MysqlStyle; 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(); IniDocument iniDoc = new IniDocument(); iniDoc.FileType = IniFileType.MysqlStyle; iniDoc.Load(filePath); File.Delete(filePath); }
static void Main(string[] args) { // Create a new instance of IniDocument IniDocument document = new IniDocument(); document.Load("Sample.ini"); // Make some changes document.Sections["First"].Parameters.Add( new IniParameter("Property3", 512) ); // Change syntax and formatting settings document.SyntaxDefinition = new IniSyntaxDefinition() { CommentStartChar = '#' }; // Write out document.Save(Console.Out, new IniWriterFormattingSettings { SortParameters = true }); // Wait for a key Console.ReadLine(); }
/// <summary> /// Update config file value /// </summary> /// <param name="fileName"></param> /// <param name="section"></param> /// <param name="item"></param> /// <param name="value"></param> void UpdatePOSConfigValue(string fileName, string section, string item, string value) { string configFilePath = Path.Combine(m_posConfigFolder, fileName); IniDocument doc = new IniDocument(configFilePath); doc.Sections[section.Trim()].Set(item.Trim(), value); doc.Save(configFilePath); }
/// <summary> /// Создаёт файл конфигурации в папке с программой. /// </summary> /// <param name="Server">Имя сервера</param> /// <param name="Port">Номер порта, связанный с адресом, или любой доступный порт</param> public void Create() { IniDocument INI = new IniDocument( new IniSection("TcpConfig", new IniKey("Server", Environment.CurrentDirectory), new IniKey("Port", "900")), new IniSection("Design", new IniKey("Theme", "Light"), new IniKey("IconTheme", "Classic"), new IniKey("FontRegister", "True")), new IniSection("Statistics", new IniKey("GeneralStatistics", "True"))); INI.Save(Environment.CurrentDirectory + @"\config.ini"); }
//[Test] public void CanParseFailed() { string iniContent = @"F:\Dev\Workshops\knowledgedrink\src\Tests\CommonLibrary.WebModules.Tests\Workshops\Import\FileDiverse_failed_small.txt"; IniDocument document = new IniDocument(iniContent, true, false); Assert.IsTrue(document.Contains("globalsettings")); Assert.AreEqual(document["globalsettings", "category"], "Art,Sculpture"); document.Save(@"F:\Dev\Workshops\knowledgedrink\src\Tests\failureTest.txt"); }
/// <summary> /// Saves application configuration. /// </summary> public static void Save() { try { Ini.Set("Default", "FontSize", AppConfig.FontInfo.Size); Ini.Set("Default", "Font", AppConfig.FontInfo.Name); Ini.Set("Default", "WindowWidth", AppConfig.WindowSize.Width); Ini.Set("Default", "WindowHeight", AppConfig.WindowSize.Height); Ini.Set("Default", "WindowMaximized", AppConfig.WindowMaximized); Ini.Set("Default", "TabPanelEnabled", AppConfig.TabPanelEnabled); Ini.Set("Default", "UseScreenLineNumber", AppConfig.UseScreenLineNumber); Ini.Set("Default", "DrawsEolCode", AppConfig.DrawsEolCode); Ini.Set("Default", "DrawsFullWidthSpace", AppConfig.DrawsFullWidthSpace); Ini.Set("Default", "DrawsSpace", AppConfig.DrawsSpace); Ini.Set("Default", "DrawsTab", AppConfig.DrawsTab); Ini.Set("Default", "DrawsEofMark", AppConfig.DrawsEofMark); Ini.Set("Default", "HighlightsCurrentLine", AppConfig.HighlightsCurrentLine); Ini.Set("Default", "HighlightsMatchedBracket", AppConfig.HighlightsMatchedBracket); Ini.Set("Default", "ShowsLineNumber", AppConfig.ShowsLineNumber); Ini.Set("Default", "ShowsHRuler", AppConfig.ShowsHRuler); Ini.Set("Default", "ShowsDirtBar", AppConfig.ShowsDirtBar); Ini.Set("Default", "TabWidth", AppConfig.TabWidth); Ini.Set("Default", "LinePadding", AppConfig.LinePadding); Ini.Set("Default", "LeftMargin", AppConfig.LeftMargin); Ini.Set("Default", "TopMargin", AppConfig.TopMargin); Ini.Set("Default", "ViewType", AppConfig.ViewType); Ini.Set("Default", "UsesTabForIndent", AppConfig.UsesTabForIndent); Ini.Set("Default", "UnindentsWithBackspace", AppConfig.UnindentsWithBackspace); Ini.Set("Default", "ConvertsFullWidthSpaceToSpace", AppConfig.ConvertsFullWidthSpaceToSpace); Ini.Set("Default", "HRulerIndicatorType", AppConfig.HRulerIndicatorType); Ini.Set("Default", "ScrollsBeyondLastLine", AppConfig.ScrollsBeyondLastLine); Ini.Set("Default", "Mru", AppConfig.MruFiles.ToString()); Ini.Set("Default", "Antialias", UserPref.Antialias); using (var file = new StreamWriter(IniFilePath, false, Encoding.UTF8)) { file.NewLine = "\r\n"; Ini.Save(file); } } catch {} }
/// <include file='IConfigSource.xml' path='//Method[@name="Save"]/docs/*' /> public void Save() { if (this.IsReadOnly) { throw new Exception("Source is read only"); } foreach (IConfig config in this.Configs) { string[] keys = config.GetKeys(); for (int i = 0; i < keys.Length; i++) { iniDocument.Sections[config.Name].Set(keys[i], config.Get(keys[i])); } } iniDocument.Save(this.filePath); }
static void Main(string[] args) { // Create a new instance of IniDocument IniDocument document = new IniDocument(); document.Load("Sample.ini"); // Make some changes document.Sections["First"].Parameters.Add( new IniParameter("Property3", 512) ); // Change syntax and formatting settings document.SyntaxDefinition = new IniSyntaxDefinition() { CommentStartChar = '#' }; // Write out document.Save(Console.Out); // Wait for a key Console.ReadLine(); }
public void Save() { Trace.Call(); #if LOG4NET _Logger.Debug("Saving config"); #endif // update values in backend foreach (string key in m_Preferences.Keys) { object obj = m_Preferences[key]; _Set(key, obj); } #if CONFIG_GCONF _GConf.SuggestSync(); #elif CONFIG_NINI // StreamWriter sr = File.CreateText(m_IniFilename); // m_IniDocument.Save(sr); m_IniDocument.Save(m_IniFilename); #endif }
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); }
public void Save() { var document = new IniDocument(); var sectionOptions = new IniSection("OPTIONS"); sectionOptions.Set("Compatibility", compatibility); sectionOptions.Set("Compiled file", compiledFile); sectionOptions.Set("Display compile progress", displayCompileProgress ? "Yes" : "No"); sectionOptions.Set("Auto Index", createIndexAutomatical ? "Yes" : "No"); sectionOptions.Set("Full-text search", createFullTextSearch ? "Yes" : "No"); sectionOptions.Set("Language", language); sectionOptions.Set("Default topic", defaultTopicFile); if (!string.IsNullOrEmpty(contentsFile))//hhc file { sectionOptions.Set("Contents file", contentsFile); } if (!string.IsNullOrEmpty(indexFile))//hhk file { sectionOptions.Set("Index file", indexFile); } document.Sections.Add(sectionOptions); var sectionFiles = new IniSection("FILES"); foreach (var file in files) { sectionFiles.Set(file, null); } document.Sections.Add(sectionFiles); document.Save(FilePath); }