public static bool SetConfigString(string xmlPath, string value) { NameValuePair nvpEntry = null; foreach (NameValuePair nvpair in configNameValuePairs) { if (String.Compare(nvpair.Name, xmlPath, true) == 0) { nvpEntry = nvpair; break; } } if (nvpEntry == null) { return(false); } try { NaiveConfigWriter writer = new NaiveConfigWriter(configFilePath); if (!writer.SetExistingPathValue(xmlPath, value)) { return(false); } // update our config setting only if writer was successful nvpEntry.Value = value; } catch { return(false); } return(true); }
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); }
private bool AddFilterModule(string filterFile) { // ensure DLL file // // pinvoke: BOOL filter!QueryFilters( // char ***pppszConnectExports, int *pnConnectExports, // char ***pppszRequestExports, int *pnRequestExports, // char ***pppszResponseExports, int *pnResponseExports // ); // // if(BOOL result == true) add exports to XML config, update UI (and update options dialog UI) // // return BOOL result string[] connectFilters = null, requestFilters = null, responseFilters = null; bool result = FilterNativeMethods.QueryFilters(filterFile, out connectFilters, out requestFilters, out responseFilters ); if (!result) { return(false); } // we can add the filters NaiveConfigWriter writer = new NaiveConfigWriter(XmlConfig.Path); if (connectFilters != null) { foreach (string filter in connectFilters) { if (XmlConfig.GetConfigString("configuration/connectFilters/property/Enabled:" + filter) == null) { writer.AddXmlPropertyAtPath("configuration/connectFilters/property", "Enabled:" + filter, filterFile); } else { XmlConfig.SetConfigString("configuration/connectFilters/property/Enabled:" + filter, filterFile); } if (XmlConfig.GetConfigString("configuration/connectFilters/property/Disabled:" + filter) != null) { writer.RemoveXmlPropertyWithPath("configuration/connectFilters/property/Disabled:" + filter); } } } if (requestFilters != null) { foreach (string filter in requestFilters) { if (XmlConfig.GetConfigString("configuration/requestFilters/property/Enabled:" + filter) == null) { writer.AddXmlPropertyAtPath("configuration/requestFilters/property", "Enabled:" + filter, filterFile); } else { XmlConfig.SetConfigString("configuration/requestFilters/property/Enabled:" + filter, filterFile); } if (XmlConfig.GetConfigString("configuration/requestFilters/property/Disabled:" + filter) != null) { writer.RemoveXmlPropertyWithPath("configuration/requestFilters/property/Disabled:" + filter); } } } if (responseFilters != null) { foreach (string filter in responseFilters) { if (XmlConfig.GetConfigString("configuration/responseFilters/property/Enabled:" + filter) == null) { writer.AddXmlPropertyAtPath("configuration/responseFilters/property", "Enabled:" + filter, filterFile); } else { XmlConfig.SetConfigString("configuration/responseFilters/property/Enabled:" + filter, filterFile); } if (XmlConfig.GetConfigString("configuration/responseFilters/property/Disabled:" + filter) != null) { writer.RemoveXmlPropertyWithPath("configuration/responseFilters/property/Disabled:" + filter); } } } return(true); }