/// <summary> /// Writes the given section into the config. /// If the section already exists it will be overwritten. If not /// the new section will be added. /// </summary> public void SetSection( ConfigSection section ) { var sections = ReadConfig(); AddOrOverwrite( sections, section ); WriteConfig( sections ); }
private ConfigSection GetOrCreateSection( IList<ConfigSection> sections, string sectionName ) { var section = sections.SingleOrDefault( sec => sec.Name == sectionName ); if ( section == null ) { section = new ConfigSection( sectionName ); sections.Add( section ); } return section; }
private void AddOrOverwrite( IList<ConfigSection> sections, ConfigSection section ) { var existingSection = sections.SingleOrDefault( sec => sec.Name == section.Name ); if ( existingSection != null ) { existingSection.Properties.Clear(); existingSection.Properties.AddRange( section.Properties ); } else { sections.Add( section ); } }
public override void SetUp() { base.SetUp(); var file = Path.GetTempFileName(); mySheet = new CsvWorksheet( new CsvWorkbook( Path.GetDirectoryName( file ) ), file, ";" ); myConfig = new WorkbookConfig( mySheet ); // set a default section var section = new ConfigSection( "Test1" ); section.SetProperty( "a", "2" ); section.SetProperty( "blub", "hiho" ); myConfig.SetSection( section ); }
/// <summary/> public void Activate() { var config = myPluginContext.ActiveWorkbook.Config.GetSection( "ExcelPlugins" ); if ( config == null ) { config = new ConfigSection( "ExcelPlugins" ); myPluginContext.ActiveWorkbook.Config.SetSection( config ); return; } foreach ( var pair in config.Properties ) { var sheetName = pair.Key; var sheetFile = pair.Value; var sheet = LoadSheetTask( sheetName, sheetFile ); CreateAndRegisterPlugin( sheet ); } }
private ConfigSection GetOrCreatePluginConfig( string pluginName ) { var config = myPluginContext.ActiveWorkbook.Config.GetSection( pluginName ); if ( config == null ) { config = new ConfigSection( pluginName ); config.SetProperty( "Excel.Caption", pluginName ); config.SetProperty( "Excel.FaceId", 16.ToString() ); myPluginContext.ActiveWorkbook.Config.SetSection( config ); } return config; }
private void WriteSection( ref int row, ConfigSection section ) { ClearRow( row ); mySheet.SetCell( "A" + row, "[" + section.Name + "]" ); row++; foreach ( var pair in section.Properties ) { WriteProperty( row++, pair ); } }