private void cmdAddnew_Click(object sender, System.EventArgs e) { // Add a new item to the collection try { if (this.txtSettingKey.Text == string.Empty) { MessageBox.Show("You must enter a value for the key.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.txtSettingKey.Select(); return; } if (this.txtSettingValue.Text == string.Empty) { MessageBox.Show("You must enter a value for the value field.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.txtSettingValue.Select(); return; } mcustAppSet = new AppSetting(this.txtSettingKey.Text, this.txtSettingValue.Text); mcustAppSettings.Add(mcustAppSet); this.ListCustomSettings(); MessageBox.Show("new setting added.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception exp) { MessageBox.Show(exp.Message, exp.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Add an app setting /// </summary> /// <param name="key">Key/name of setting</param> /// <param name="value">Value of setting</param> public void AddAppSetting(string key, string value) { if (AppSettings == null) { AppSettings = new List <AzureNameValuePair>(); } AppSettings.Add(new AzureNameValuePair(key, value)); }
public AppDbContext() { if (!Database.EnsureCreated()) { return; } AppSettings.Add(new AppSetting { SettingName = "CurrentLang", Value = "en-Us", IsEditable = false, DefaultValue = "en-Us" }); AppSettings.Add(new AppSetting { SettingName = "IsAppConfigured", Value = "0", IsEditable = false, DefaultValue = "0" }); AppSettings.Add(new AppSetting { SettingName = "DesktopRandomWallpaperResolution", Value = "1920x1080", IsEditable = true, DefaultValue = "1920x1080" }); AppSettings.Add(new AppSetting { SettingName = "DesktopLastestWallpaperResolution", Value = "1920x1080", IsEditable = true, DefaultValue = "1920x1080" }); AppSettings.Add(new AppSetting { SettingName = "MobileRandomWallpaperResolution", Value = "1080x1920", IsEditable = true, DefaultValue = "1080x1920" }); AppSettings.Add(new AppSetting { SettingName = "MobileLatestWallpaperResolution", Value = "1080x1920", IsEditable = true, DefaultValue = "1080x1920" }); SaveChangesAsync(); }
public void AddOrSet(string key, string value) { if (AppSettings.ContainsKey(key)) { AppSettings[key] = value; } else { AppSettings.Add(key, value); } }
/// <summary> /// Constructor that accepts AppSettings and ConnectionStrings XML data in array form /// This method is to support ConfigurationManagerFull() construction /// </summary> /// <param name="appSettings">ConfigurationManager.AppSettings.ToArraySafe()</param> /// <param name="connectionStrings">ConfigurationManager.ConnectionStrings.ToArraySafe()</param> public ConfigurationManagerSafe(string[,] appSettings, string[,] connectionStrings) : this() { connectionStrings = connectionStrings ?? new string[0, 2]; for (var itemCount = 0; itemCount < connectionStrings.GetLength(0); itemCount++) { ConnectionStrings.Add(connectionStrings[itemCount, 0], connectionStrings[itemCount, 1]); } appSettings = appSettings ?? new string[0, 2]; for (var itemCount = 0; itemCount < appSettings.GetLength(0); itemCount++) { AppSettings.Add(appSettings[itemCount, 0], appSettings[itemCount, 1]); } }
public void LoadAppSettings() { DefaultConfiguration.AppSettings = DefaultConfiguration.AppSettings ?? new Dictionary <string, string>(); if (AppSettings.Any()) { throw new ConfigurationErrorsException("AppSettings are already loaded"); } foreach (var key in ConfigurationManager.AppSettings.AllKeys) { AppSettings.Add(key, ConfigurationManager.AppSettings[key]); } }
public AppDbContext() { if (!Database.EnsureCreated()) { return; } // save default settings AppSettings.Add(new AppSetting { SettingName = "IconsSource", Value = "https://materialdesignicons.com/api", IsEditable = true, DefaultValue = "https://materialdesignicons.com/api" }); AppSettings.Add(new AppSetting { SettingName = "IconsGUID", Value = "38EF63D0-4744-11E4-B3CF-842B2B6CFE1B", IsEditable = true, DefaultValue = "38EF63D0-4744-11E4-B3CF-842B2B6CFE1B" }); AppSettings.Add(new AppSetting { SettingName = "IconsLastUpdate", Value = "12.12.2012 12:12:12", IsEditable = false, DefaultValue = "12.12.2012 12:12:12" }); AppSettings.Add(new AppSetting { SettingName = "ColorPaletteSource", Value = "https://raw.githubusercontent.com/Jam3/nice-color-palettes/master/1000.json", IsEditable = true, DefaultValue = "https://raw.githubusercontent.com/Jam3/nice-color-palettes/master/1000.json" }); SaveChangesAsync(); }
/// <summary> /// Loads from JSON data /// Use: Configuration["subsection:suboption1"] /// </summary> public void Load() { IConfigurationRoot configuration; IConfigurationBuilder configBuilder; var currentEnvironment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development"; configBuilder = new ConfigurationBuilder() .AddJsonFile($@"{RootPath.AddLast(@"\")}{FileNames.AppSettingsJson}", optional: true) .AddJsonFile($@"{RootPath.AddLast(@"\")}{string.Format(FileNames.AppSettingsEnvironmentJson, currentEnvironment)}"); configuration = configBuilder.Build(); foreach (var Item in configuration?.GetSection("AppSettings").GetChildren()) { AppSettings.Add(new AppSettingSafe(Item.Key, Item.Value)); } foreach (var Item in configuration.GetSection("ConnectionStrings").GetChildren()) { ConnectionStrings.Add(new ConnectionStringSafe(Item.Key, Item.Value)); } }
/// <summary> /// Gets configuration from the server and invokes a callback when completed /// </summary> /// <param name="callback"></param> public void LoadConfiguration(Action callback) { // invoke service call base.Channel.BeginGetConfiguration( (asyncResult) => { // get server configuration by ending async call Shared.ServerConfiguration serverConfiguration = base.Channel.EndGetConfiguration(asyncResult); if (serverConfiguration != null) { // load app settings if (serverConfiguration.AppSettings != null) { serverConfiguration.AppSettings.ForEach(appSetting => AppSettings.Add(appSetting.Key, appSetting.Value)); } // load configuration sections if (serverConfiguration.SectionSettings != null) { serverConfiguration.SectionSettings.ForEach(sectionData => { // check that the type is recognized Type sectionType = DataContractUtility.GetType(sectionData.TypeAssemblyQualifiedName, sectionData.TypeFullName, false); if (sectionType != null) { // deserialize to object and store in configuration section object section = serverConfiguration.ReadSection(sectionType, EncryptionKey); if (section != null) { ConfigurationSections.Add(sectionData.Name, section); } } }); } } callback(); }, null); }
public void ReadConfigFile() { string executingApp = System.Reflection.Assembly.GetExecutingAssembly().CodeBase; executingApp = executingApp.Replace("file:///", String.Empty); ConfigFile = new FileInfo($"{executingApp}.ini"); if (ConfigFile.Exists) { string line; using (StreamReader fileStream = new StreamReader(ConfigFile.FullName)) { while ((line = fileStream.ReadLine()) != null) { var keyValue = line.Split(":"); string key = keyValue.FirstOrDefault(); string value = keyValue.LastOrDefault(); bool b; int i; if (Boolean.TryParse(value, out b)) { AppSettings.Add(key, b); } else if (int.TryParse(value, out i)) { AppSettings.Add(key, i); } else { AppSettings.Add(key, value); } } } } else { using (FileStream fileStream = new FileStream(ConfigFile.FullName, FileMode.CreateNew, FileAccess.Write)); } }
/// <summary> /// Loads from JSON data /// Use: Configuration["subsection:suboption1"] /// </summary> private void Load(IEnumerable <string> configFiles) { IConfigurationRoot configuration; IConfigurationBuilder configBuilder = new ConfigurationBuilder(); // Load files foreach (var file in configFiles) { configBuilder.AddJsonFile(file, optional: true); } configuration = configBuilder.Build(); // Add AppSettings node foreach (var Item in configuration?.GetSection("AppSettings").GetChildren()) { AppSettings.Add(new AppSettingSafe(Item.Key, Item.Value)); } // Add ConnectionStrings node foreach (var Item in configuration.GetSection("ConnectionStrings").GetChildren()) { ConnectionStrings.Add(new ConnectionStringSafe(Item.Key, Item.Value)); } }