Пример #1
0
        /// <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 );
        }
Пример #2
0
        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;
        }
Пример #3
0
 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 );
     }
 }
Пример #4
0
        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 );
        }
Пример #5
0
        /// <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 );
            }
        }
Пример #6
0
        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;
        }
Пример #7
0
        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 );
            }
        }