protected override void OnFormClosed(FormClosedEventArgs e) { if (Config.Saved) { Config.Save(); // Saves TabSettings. } base.OnFormClosed(e); }
void SaveConfig_Click(object sender, EventArgs e) { Config.Save(); SaveConfig.Enabled = false; // Can't save again until new changes made and applied. }
public void TestXmlSerialization() { //var serializer = new XmlSerializer(Config.GetType()); //using (var writer = new StreamWriter(Config.ConfigFile)) //{ // serializer.Serialize(writer, Config); //} Config.Save(); //LuiConfig testConfig = null; //using (var reader = new StreamReader(ConfigFile)) //{ // testConfig = (LuiConfig)serializer.Deserialize(reader); //} LuiConfig testConfig = LuiConfig.FromFile(ConfigFile); Assert.AreEqual(testConfig.ConfigFile, Config.ConfigFile); Assert.AreEqual(testConfig.LogFile, Config.LogFile); Assert.AreEqual(testConfig.LogLevel, Config.LogLevel); foreach (KeyValuePair <Type, Dictionary <LuiObjectParameters, ILuiObject> > kvp in Config.LuiObjectTableIndex) { IList <LuiObjectParameters> list = (IList <LuiObjectParameters>)kvp.Value.Keys.ToList(); for (int i = 0; i < list.Count; i++) { Assert.AreEqual(list[i], ((IList <LuiObjectParameters>)testConfig.LuiObjectTableIndex[kvp.Key].Keys.ToList())[i]); } } GpibProviderParameters dependency = null; GpibProviderParameters testParameters = null; foreach (var kvp in testConfig.LuiObjectTableIndex[ddgParameters.GetType()]) { if (kvp.Key.Name == ddgParameters.Name) { dependency = ((DelayGeneratorParameters)kvp.Key).GpibProvider; } } foreach (var kvp in testConfig.LuiObjectTableIndex[gpibParameters1.GetType()]) { if (kvp.Key.Name == gpibParameters1.Name) { testParameters = (GpibProviderParameters)kvp.Key; } } Assert.AreEqual(dependency, testParameters); Assert.IsTrue( testConfig.LuiObjectTableIndex[dependency.GetType()][dependency] == testConfig.LuiObjectTableIndex[testParameters.GetType()][testParameters] ); Assert.IsTrue(Object.ReferenceEquals( testConfig.LuiObjectTableIndex[dependency.GetType()][dependency], testConfig.LuiObjectTableIndex[testParameters.GetType()][testParameters] )); var dummy = new DummyGpibProvider(); testConfig.LuiObjectTableIndex[dependency.GetType()][dependency] = dummy; Assert.IsTrue(Object.ReferenceEquals(testConfig.LuiObjectTableIndex[testParameters.GetType()][testParameters], dummy)); }