Showing the changes to Source/Tools/ConfigTest/Program.cs (1 of 13 files). Show all
Unified · Split
| @@ -0,0 +1,47 @@ | |||
| 1 | using System; | ||
| 2 | using GSF.Configuration; | ||
| 3 | |||
| 4 | namespace ConfigTest | ||
| 5 | { | ||
| 6 | class Program | ||
| 7 | { | ||
| 8 | static void Main(string[] args) | ||
| 9 | { | ||
| 10 | ConfigurationFile config = ConfigurationFile.Current; | ||
| 11 | CategorizedSettingsElementCollection settings = config.Settings["systemSettings"]; | ||
| 12 | CategorizedSettingsElementCollection examples = config.Settings["examples"]; | ||
| 13 | |||
| 14 | settings.Add("connectionString", "abc=123", "My device connection string"); | ||
| 15 | settings.Add("property2", "clever", "Smack, smack!"); | ||
| 16 | examples.Add("newProperty", "test", "New property description"); | ||
| 17 | examples.Add("areWeThereYet", "never", "Why?"); | ||
| 18 | |||
| 19 | string connectionString = settings["connectionString"].ValueAs("default"); | ||
| 20 | string property2 = settings["property2"].ValueAs("default2"); | ||
| 21 | string newProperty = examples["newProperty"].ValueAs("default3"); | ||
| 22 | string areWeThereYet = examples["areWeThereYet"].ValueAs("default4"); | ||
| 23 | |||
| 24 | Console.WriteLine(); | ||
| 25 | Console.WriteLine("systemSettings.connectionString setting = " + connectionString); | ||
| 26 | Console.WriteLine("systemSettings.property2 setting = " + property2); | ||
| 27 | Console.WriteLine("examples.newProperty = " + newProperty); | ||
| 28 | Console.WriteLine("examples.areWeThereYet = " + areWeThereYet); | ||
| 29 | |||
| 30 | Console.WriteLine(); | ||
| 31 | Console.WriteLine("Updating setting to new random value..."); | ||
| 32 | settings["connectionString", true].Value = Guid.NewGuid().ToString(); | ||
| 33 | |||
| 34 | Console.WriteLine(); | ||
| 35 | Console.WriteLine("New setting: " + settings["connectionString"].Value); | ||
| 36 | |||
| 37 | Console.WriteLine(); | ||
| 38 | Console.WriteLine("Saving updated configuration settings..."); | ||
| 39 | |||
| 40 | config.Save(); | ||
| 41 | |||
| 42 | Console.WriteLine(); | ||
| 43 | Console.WriteLine("Press any key to continue..."); | ||
| 44 | Console.ReadKey(); | ||
| 45 | } | ||
| 46 | } | ||
| 47 | } | ||