private bool SavePendingSettings() { bool allSaved = true; foreach (KeyValuePair <string, string> kvp in pendingSettings) { if (XmlConfig.GetConfigString(kvp.Key) == null) { string keyAlternate = null; if (kvp.Key.Contains("/Enabled:")) { // the entry may exist in the xml config as Disabled ... keyAlternate = kvp.Key.Replace("/Enabled:", "/Disabled:"); } else if (kvp.Key.Contains("/Disabled:")) { // as may the opposite occur ... keyAlternate = kvp.Key.Replace("/Disabled:", "/Enabled:"); } NaiveConfigWriter writer = new NaiveConfigWriter(XmlConfig.Path); if (keyAlternate != null) { if (XmlConfig.GetConfigString(keyAlternate) != null) { // remove keyAlternate and continue writer.RemoveXmlPropertyWithPath(keyAlternate); } } // this config entry doesn't exist (i.e. a new imported filter) // add new entry to config file before proceeding. int idx = kvp.Key.LastIndexOf('/'); // this code should be tested later string xmlPropertyPath = kvp.Key.Substring(0, idx); string xmlPropertyName = kvp.Key.Substring(idx + 1); writer.AddXmlPropertyAtPath(xmlPropertyPath, xmlPropertyName, kvp.Value); // then update config if (!XmlConfig.RefreshConfig()) { ShowConfigLoadError(); return(false); } } else { if (!XmlConfig.SetConfigString(kvp.Key, kvp.Value)) { allSaved = false; } } } pendingSettings.Clear(); return(allSaved); }
bool UpdateUIFromConfig() { if (!XmlConfig.RefreshConfig()) { return(false); } XmlConfig.NameValuePair[] nvpArray = XmlConfig.GetNameValuePairArray("configuration/connectFilters/property/"); if (nvpArray != null) { lbConnEnabledFilters.Items.Clear(); lbConnEnabledFilters.BeginUpdate(); lbConnEnabledFilters.HorizontalScrollbar = true; foreach (XmlConfig.NameValuePair nvpair in nvpArray) { string name = XmlConfig.GetNameFromPath(nvpair.Name); if (name.StartsWith("Enabled:", true, null)) { lbConnEnabledFilters.Items.Add(name.Substring(8) + " => " + nvpair.Value); } else if (name.StartsWith("Disabled:", true, null)) { lbConnDisabledFilters.Items.Add(name.Substring(9) + " => " + nvpair.Value); } } lbConnEnabledFilters.EndUpdate(); } nvpArray = XmlConfig.GetNameValuePairArray("configuration/requestFilters/property/"); if (nvpArray != null) { lbOutEnabledFilters.Items.Clear(); lbOutEnabledFilters.BeginUpdate(); lbOutEnabledFilters.HorizontalScrollbar = true; foreach (XmlConfig.NameValuePair nvpair in nvpArray) { string name = XmlConfig.GetNameFromPath(nvpair.Name); if (name.StartsWith("Enabled:", true, null)) { lbOutEnabledFilters.Items.Add(name.Substring(8) + " => " + nvpair.Value); } else if (name.StartsWith("Disabled:", true, null)) { lbOutDisabledFilters.Items.Add(name.Substring(9) + " => " + nvpair.Value); } } lbOutEnabledFilters.EndUpdate(); } nvpArray = XmlConfig.GetNameValuePairArray("configuration/responseFilters/property/"); if (nvpArray != null) { lbInEnabledFilters.Items.Clear(); lbInEnabledFilters.BeginUpdate(); lbInEnabledFilters.HorizontalScrollbar = true; foreach (XmlConfig.NameValuePair nvpair in nvpArray) { string name = XmlConfig.GetNameFromPath(nvpair.Name); if (name.StartsWith("Enabled:", true, null)) { lbInEnabledFilters.Items.Add(name.Substring(8) + " => " + nvpair.Value); } else if (name.StartsWith("Disabled:", true, null)) { lbInDisabledFilters.Items.Add(name.Substring(9) + " => " + nvpair.Value); } } lbInEnabledFilters.EndUpdate(); } return(true); }