protected override void RefreshAndValidateSections(IDictionary <string, string> localSectionsToRefresh, IDictionary <string, string> externalSectionsToRefresh, out ICollection <string> sectionsToNotify, out IDictionary <string, string> sectionsWithChangedConfigSource) { UpdateCache(); sectionsToNotify = new List <string>(); sectionsWithChangedConfigSource = new Dictionary <string, string>(); // refresh local sections and determine what to do. foreach (KeyValuePair <string, string> sectionMapping in localSectionsToRefresh) { System.Configuration.ConfigurationSection section = cachedConfiguration.GetSection(sectionMapping.Key) as System.Configuration.ConfigurationSection; string refreshedConfigSource = section != null ? section.SectionInformation.ConfigSource : NullConfigSource; if (!sectionMapping.Value.Equals(refreshedConfigSource)) { sectionsWithChangedConfigSource.Add(sectionMapping.Key, refreshedConfigSource); } // notify anyway, since it might have been updated. sectionsToNotify.Add(sectionMapping.Key); } // refresh external sections and determine what to do. foreach (KeyValuePair <string, string> sectionMapping in externalSectionsToRefresh) { System.Configuration.ConfigurationSection section = cachedConfiguration.GetSection(sectionMapping.Key) as System.Configuration.ConfigurationSection; string refreshedConfigSource = section != null ? section.SectionInformation.ConfigSource : NullConfigSource; if (!sectionMapping.Value.Equals(refreshedConfigSource)) { sectionsWithChangedConfigSource.Add(sectionMapping.Key, refreshedConfigSource); // notify only if che config source changed sectionsToNotify.Add(sectionMapping.Key); } } }
private void InternalSave(string fileName, string section, System.Configuration.ConfigurationSection configurationSection, string protectionProvider) { System.Configuration.ExeConfigurationFileMap fileMap = new System.Configuration.ExeConfigurationFileMap(); fileMap.ExeConfigFilename = fileName; System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(fileMap, System.Configuration.ConfigurationUserLevel.None); if (typeof(System.Configuration.ConnectionStringsSection) == configurationSection.GetType()) { config.Sections.Remove(section); UpdateConnectionStrings(section, configurationSection, config, protectionProvider); } else if (typeof(System.Configuration.AppSettingsSection) == configurationSection.GetType()) { UpdateApplicationSettings(section, configurationSection, config, protectionProvider); } else { config.Sections.Remove(section); config.Sections.Add(section, configurationSection); ProtectConfigurationSection(configurationSection, protectionProvider); } config.Save(); UpdateImplementation(fileName); }
public void Save(string fileName, string section, System.Configuration.ConfigurationSection configurationSection, string protectionProvider) { ValidateArgumentsAndFileExists(fileName, section, configurationSection); if (string.IsNullOrEmpty(protectionProvider)) { throw new ArgumentNullException("protectionProvider"); } InternalSave(fileName, section, configurationSection, protectionProvider); }
public override System.Configuration.ConfigurationSection GetSection(string sectionName) { System.Configuration.Configuration configuration = GetConfiguration(); System.Configuration.ConfigurationSection configurationSection = configuration.GetSection(sectionName) as System.Configuration.ConfigurationSection; SetConfigurationWatchers(sectionName, configurationSection); return(configurationSection); }
/// <summary> /// Generates an encrypted section in the app.config file. This should only be used once before deployment. /// </summary> /// <param name="sectionKey">The section to encrypt.</param> public static void EncryptConfig(string sectionKey = "configuration") { System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None); System.Configuration.ConfigurationSection section = config.GetSection(sectionKey); if (section != null && !section.SectionInformation.IsProtected && !section.ElementInformation.IsLocked) { section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider"); section.SectionInformation.ForceSave = true; config.Save(System.Configuration.ConfigurationSaveMode.Full); } }
/// <summary> /// Gets the app settings section entry. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="sectionName">Name of the section.</param> /// <param name="keyName">Name of the key.</param> /// <returns></returns> public static string GetAppSettingsSectionEntry(System.Configuration.Configuration configuration, string sectionName, string keyName) { string result = string.Empty; System.Configuration.ConfigurationSection configSection = configuration.GetSection(sectionName); if (configSection != null) { System.Configuration.AppSettingsSection section = (System.Configuration.AppSettingsSection)configuration.GetSection(sectionName); if (section?.Settings?[keyName] != null) { var item = section.Settings[keyName]; result = item.Value; } } return(result); }
private static void ProtectConfigurationSection(System.Configuration.ConfigurationSection configurationSection, string protectionProvider) { if (!string.IsNullOrEmpty(protectionProvider)) { if (configurationSection.SectionInformation.ProtectionProvider == null || configurationSection.SectionInformation.ProtectionProvider.Name != protectionProvider) { configurationSection.SectionInformation.ProtectSection(protectionProvider); } } else { if (configurationSection.SectionInformation.ProtectionProvider != null) { configurationSection.SectionInformation.UnprotectSection(); } } }
private void UpdateApplicationSettings(string section, System.Configuration.ConfigurationSection configurationSection, System.Configuration.Configuration config, string protectionProvider) { System.Configuration.AppSettingsSection current = config.AppSettings; if (current == null) { config.Sections.Add(section, configurationSection); ProtectConfigurationSection(configurationSection, protectionProvider); } else { System.Configuration.AppSettingsSection newApplicationSettings = configurationSection as System.Configuration.AppSettingsSection; if (current.File != newApplicationSettings.File) { current.File = newApplicationSettings.File; } List <string> newKeys = new List <string>(newApplicationSettings.Settings.AllKeys); List <string> currentKeys = new List <string>(current.Settings.AllKeys); foreach (string keyInCurrent in currentKeys) { if (!newKeys.Contains(keyInCurrent)) { current.Settings.Remove(keyInCurrent); } } foreach (string newKey in newKeys) { if (!currentKeys.Contains(newKey)) { current.Settings.Add(newKey, newApplicationSettings.Settings[newKey].Value); } else { if (current.Settings[newKey].Value != newApplicationSettings.Settings[newKey].Value) { current.Settings[newKey].Value = newApplicationSettings.Settings[newKey].Value; } } } ProtectConfigurationSection(current, protectionProvider); } }
private void UpdateConnectionStrings(string section, System.Configuration.ConfigurationSection configurationSection, System.Configuration.Configuration config, string protectionProvider) { System.Configuration.ConnectionStringsSection current = config.ConnectionStrings; if (current == null) { config.Sections.Add(section, configurationSection); ProtectConfigurationSection(configurationSection, protectionProvider); } else { System.Configuration.ConnectionStringsSection newConnectionStrings = (System.Configuration.ConnectionStringsSection)configurationSection; foreach (System.Configuration.ConnectionStringSettings connectionString in newConnectionStrings.ConnectionStrings) { if (current.ConnectionStrings[connectionString.Name] == null) { current.ConnectionStrings.Add(connectionString); } } ProtectConfigurationSection(current, protectionProvider); } }
static void Main() { try { DataPhilosophiaeSection dps = cm.GetSection("DataPhilosophiaeSection") as DataPhilosophiaeSection; if (dps != null) { System.Console.WriteLine(dps.Stage.PathDir); foreach (DataStoreElement ds in dps.DataStores) { System.Console.WriteLine(ds.Name); System.Console.WriteLine(ds.LoadDefaultDatabaseOnly); System.Console.WriteLine(ds.LoadSystemObjects); System.Console.WriteLine(ds.WithFields); if (string.IsNullOrWhiteSpace(ds.PathDir)) { ds.PathDir = System.IO.Path.Combine(dps.Stage.PathDir, ds.Name); cm.Save(System.Configuration.ConfigurationSaveMode.Minimal, true); } System.Console.WriteLine(ds.PathDir); } } //DataStoreElement dse = new DataStoreElement( ); //cm.Save( System.Configuration.ConfigurationSaveMode.Minimal, false ); } catch (System.Configuration.ConfigurationErrorsException ex) { System.Console.WriteLine(ex.Message); } try { System.Configuration.ConnectionStringSettingsCollection settings = System.Configuration.ConfigurationManager.ConnectionStrings; if (settings != null) { foreach (System.Configuration.ConnectionStringSettings cs in settings) { System.Console.WriteLine(" Name:" + cs.Name); System.Console.WriteLine(" ProviderName:" + cs.ProviderName); System.Console.WriteLine("ConnectionString:" + cs.ConnectionString); } } } catch (System.Configuration.ConfigurationErrorsException ex) { System.Console.WriteLine(ex.Message); } { DataPhilosophiaeSection dps = cm.GetSection("DataPhilosophiaeSection") as DataPhilosophiaeSection; DataStoreElement ds = dps.DataStores[0]; System.Configuration.ConnectionStringSettingsCollection settings = System.Configuration.ConfigurationManager.ConnectionStrings; System.Configuration.ConnectionStringSettings cs = settings[ds.ConnectionStringName]; // ActiveQueryBuilder.Core.SyntaxProviderList syntaxProviderList = new ActiveQueryBuilder.Core.SyntaxProviderList( ); ActiveQueryBuilder.Core.SQLContext sc = new ActiveQueryBuilder.Core.SQLContext( ) { SyntaxProvider = new ActiveQueryBuilder.Core.AutoSyntaxProvider( ), MetadataProvider = new ActiveQueryBuilder.Core.OLEDBMetadataProvider { Connection = new System.Data.OleDb.OleDbConnection( ) { ConnectionString = cs.ConnectionString } } }; } { DataPhilosophiaeSection dps = cm.GetSection("DataPhilosophiaeSection") as DataPhilosophiaeSection; DataStoreElement ds = dps.DataStores[0]; System.Configuration.ConnectionStringSettingsCollection settings = System.Configuration.ConfigurationManager.ConnectionStrings; System.Configuration.ConnectionStringSettings cs = settings[ds.ConnectionStringName]; // ActiveQueryBuilder.Core.SyntaxProviderList syntaxProviderList = new ActiveQueryBuilder.Core.SyntaxProviderList( ); ActiveQueryBuilder.Core.SQLContext sc = new ActiveQueryBuilder.Core.SQLContext( ) { SyntaxProvider = new ActiveQueryBuilder.Core.SQLiteSyntaxProvider( ), MetadataProvider = new ActiveQueryBuilder.Core.SQLiteMetadataProvider( ) { Connection = new System.Data.SQLite.SQLiteConnection( ) { ConnectionString = cs.ConnectionString } } }; ActiveQueryBuilder.Core.MetadataLoadingOptions loadingOptions = sc.MetadataContainer.LoadingOptions; loadingOptions.LoadDefaultDatabaseOnly = ds.LoadDefaultDatabaseOnly == 1 ? true : false; loadingOptions.LoadSystemObjects = ds.LoadSystemObjects == 1 ? true : false; //loadingOptions.IncludeFilter.Types = MetadataType.Field; //loadingOptions.ExcludeFilter.Schemas.Add(“dbo”); sc.MetadataContainer.LoadAll(ds.WithFields == 1 ? true : false); } //TunnelSection ts = System.Configuration.ConfigurationManager.GetSection( "TunnelSection" ) as TunnelSection; TunnelSection ts = cm.GetSection("TunnelSection") as TunnelSection; int count1 = ts.Tunnels.Count; HostConfigElement hc = ts.Tunnels[0]; string sSHServerHostname = hc.SSHServerHostname; string username = hc.Username; TunnelCollection tunnels = hc.Tunnels; int count2 = tunnels.Count; TunnelConfigElement tce = tunnels[0]; string name = tce.Name; int localPort = tce.LocalPort; //ProductSettings productSettings = System.Configuration.ConfigurationManager.GetSection( "ProductSettings" ) as ProductSettings; //ConfigurationClassLoader x = System.Configuration.ConfigurationManager.GetSection( "Plugins" ) as ConfigurationClassLoader; // System.Configuration.ConfigurationSectionGroup a = cm.GetSectionGroup("DataStoreGroup"); System.Configuration.ConfigurationSectionCollection sections = a.Sections; int count = sections.Count; System.Configuration.ConfigurationSection get = sections.Get(0); // NewMethod( ); // System.Windows.Forms.Application.EnableVisualStyles( ); System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); System.Windows.Forms.Application.Run(new Form1( )); }
public void Save(string fileName, string section, System.Configuration.ConfigurationSection configurationSection) { ValidateArgumentsAndFileExists(fileName, section, configurationSection); InternalSave(fileName, section, configurationSection, string.Empty); }
private static void ValidateArgumentsAndFileExists(string fileName, string section, System.Configuration.ConfigurationSection configurationSection) { if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException("fileName"); } if (string.IsNullOrEmpty(section)) { throw new ArgumentNullException("section"); } if (null == configurationSection) { throw new ArgumentNullException("configurationSection"); } if (!C1File.Exists(fileName)) { throw new FileNotFoundException(string.Format("", "Resources.ExceptionConfigurationFileNotFound", section), fileName); } }
public override void Add(string sectionName, System.Configuration.ConfigurationSection configurationSection, string protectionProviderName) { ProtectedAddCallCount++; protectionProviderNameOnLastCall = protectionProviderName; }
public void AddLocalSection(string sectionName, System.Configuration.ConfigurationSection section) { Add(sectionName, section); }
public void Add(Microsoft.Practices.EnterpriseLibrary.Common.Configuration.IConfigurationParameter saveParameter, string sectionName, System.Configuration.ConfigurationSection configurationSection, string protectionProviderName) { Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationParameter parameter = saveParameter as Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationParameter; if (null == parameter) { throw new ArgumentNullException("saveParameter"); } Save(parameter.FileName, sectionName, configurationSection, protectionProviderName); }
public virtual void Add(string sectionName, System.Configuration.ConfigurationSection configurationSection, string protectionProviderName) { Add(sectionName, configurationSection); }
public void Add(string sectionName, System.Configuration.ConfigurationSection configurationSection) { }