void setValue(SettingsPropertyValue propVal) { var settingNode = getSettingsNode(propVal.Property, propVal.Name) as XmlElement; if (settingNode != null) { settingNode.InnerText = propVal.SerializedValue.ToString(); } else if (isRoaming(propVal.Property)) { settingNode = SettingsXml.CreateElement(propVal.Name); settingNode.InnerText = propVal.SerializedValue.ToString(); SettingsXml.SelectSingleNode(SettingsRoot).AppendChild(settingNode); } else { // it's machine specific, store as an element of the machine name node. var machineNode = SettingsXml.SelectSingleNode(SettingsRoot + '/' + Environment.MachineName) as XmlElement; if (machineNode == null) { machineNode = SettingsXml.CreateElement(Environment.MachineName); SettingsXml.SelectSingleNode(SettingsRoot).AppendChild(machineNode); } settingNode = SettingsXml.CreateElement(propVal.Name); settingNode.InnerText = propVal.SerializedValue.ToString(); machineNode.AppendChild(settingNode); } }
/// <summary> /// Its machine specific, store as an element of the machine name node, /// creating a new machine name node if one doesnt exist. /// </summary> private void CreateLocalValue(SettingsPropertyValue propVal) { XmlElement machineNode; try { machineNode = (XmlElement)SettingsXml.SelectSingleNode( SettingsRootName + "/" + Environment.MachineName); } catch (Exception) { machineNode = SettingsXml.CreateElement(Environment.MachineName); SettingsRootNode.AppendChild(machineNode); } if (machineNode == null) { machineNode = SettingsXml.CreateElement(Environment.MachineName); SettingsRootNode.AppendChild(machineNode); } var settingNode = SettingsXml.CreateElement(propVal.Name); settingNode.InnerText = propVal.SerializedValue.ToString(); machineNode.AppendChild(settingNode); }
public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection) { lock (LockObject) { //Iterate through the settings to be stored, only dirty settings for this provider are in collection foreach (SettingsPropertyValue propval in collection) { var groupName = context["GroupName"].ToString(); var groupNode = SettingsXml.SelectSingleNode("/configuration/userSettings/" + context["GroupName"]); if (groupNode == null) { var parentNode = SettingsXml.SelectSingleNode("/configuration/userSettings"); groupNode = SettingsXml.CreateElement(groupName); parentNode.AppendChild(groupNode); } var section = (XmlElement)SettingsXml.SelectSingleNode("/configuration/configSections/sectionGroup/section"); if (section == null) { var parentNode = SettingsXml.SelectSingleNode("/configuration/configSections/sectionGroup"); section = SettingsXml.CreateElement("section"); section.SetAttribute("name", groupName); section.SetAttribute("type", String.Format("{0}, {1}", typeof(ClientSettingsSection), Assembly.GetAssembly(typeof(ClientSettingsSection)))); parentNode.AppendChild(section); } SetValue(groupNode, propval); } Directory.CreateDirectory(UserConfigLocation); SettingsXml.Save(Path.Combine(UserConfigLocation, "user.config")); } }
private void SetValue(SettingsPropertyValue propVal) { if (propVal == null) { throw new ArgumentNullException(nameof(propVal)); } if (propVal.SerializedValue == null) { throw new ArgumentNullException(nameof(propVal.SerializedValue)); } XmlElement settingNode; //Determine if the setting is roaming. //If roaming then the value is stored as an element under the root //Otherwise it is stored under a machine name node try { if (IsRoaming(propVal.Property)) { settingNode = (XmlElement)SettingsXml.SelectSingleNode( SettingsRootName + "/" + propVal.Name); } else { settingNode = (XmlElement)SettingsXml.SelectSingleNode( SettingsRootName + "/" + Environment.MachineName + "/" + propVal.Name); } } catch (Exception) { settingNode = null; } if (settingNode != null) { settingNode.InnerText = propVal.SerializedValue.ToString(); } else { if (IsRoaming(propVal.Property)) { CreateRoamingValue(propVal); } else { CreateLocalValue(propVal); } } }
private string GetValue(SettingsProperty setting) { try { if (IsRoaming(setting)) { return(SettingsXml.SelectSingleNode(SettingsRootName + "/" + setting.Name)?.InnerText ?? GetDefaultValue(setting)); } return(SettingsXml.SelectSingleNode(SettingsRootName + "/" + Environment.MachineName + "/" + setting.Name)?.InnerText ?? GetDefaultValue(setting)); } catch (Exception) { return(GetDefaultValue(setting)); } }
private string GetValue(SettingsProperty setting) { string ret = ""; try { if (IsRoaming(setting)) { ret = SettingsXml.SelectSingleNode(SettingsRootNode + "/" + setting.Name).InnerText; } else { ret = SettingsXml.SelectSingleNode(SettingsRootNode + "/" + Environment.MachineName + "/" + setting.Name).InnerText; } } catch (Exception) { ret = (setting.DefaultValue != null) ? setting.DefaultValue.ToString() : ""; } return(ret); }
public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection) { lock (LockObject) { // We need to forget any cached version of the XML. Otherwise, when more than one lot of settings // is saved in the same file, the provider that is doing the save for one of them may have stale // (or missing) settings for the other. We want to write the dirty properties over a current // version of everything else that has been saved in the file. _settingsXml = null; //Iterate through the settings to be stored, only dirty settings for this provider are in collection foreach (SettingsPropertyValue propval in collection) { var groupName = context["GroupName"].ToString(); var groupNode = SettingsXml.SelectSingleNode("/configuration/userSettings/" + context["GroupName"]); if (groupNode == null) { var parentNode = SettingsXml.SelectSingleNode("/configuration/userSettings"); groupNode = SettingsXml.CreateElement(groupName); parentNode.AppendChild(groupNode); } var section = (XmlElement)SettingsXml.SelectSingleNode("/configuration/configSections/sectionGroup/section"); if (section == null) { var parentNode = SettingsXml.SelectSingleNode("/configuration/configSections/sectionGroup"); section = SettingsXml.CreateElement("section"); section.SetAttribute("name", groupName); section.SetAttribute("type", String.Format("{0}, {1}", typeof(ClientSettingsSection), Assembly.GetAssembly(typeof(ClientSettingsSection)))); parentNode.AppendChild(section); } SetValue(groupNode, propval); } Directory.CreateDirectory(UserConfigLocation); RobustIO.SaveXml(SettingsXml, Path.Combine(UserConfigLocation, UserConfigFileName)); } }
XmlNode getSettingsNode(SettingsProperty setting, string name) { return(isRoaming(setting) ? SettingsXml.SelectSingleNode(SettingsRoot + '/' + name) : SettingsXml.SelectSingleNode(SettingsRoot + '/' + Environment.MachineName + '/' + name)); }
private void SetValue(SettingsPropertyValue propVal) { XmlElement settingNode; //Determine if the setting is roaming. //If roaming then the value is stored as an element under the root //Otherwise it is stored under a machine name node try { if (IsRoaming(propVal.Property)) { settingNode = (XmlElement)SettingsXml.SelectSingleNode(SettingsRootNode + "/" + propVal.Name); } else { settingNode = (XmlElement)SettingsXml.SelectSingleNode(SettingsRootNode + "/" + Environment.MachineName + "/" + propVal.Name); } } catch (Exception) { settingNode = null; } //Check to see if the node exists, if so then set its new value if ((settingNode != null)) { settingNode.InnerText = propVal.SerializedValue.ToString(); } else { if (IsRoaming(propVal.Property)) { //Store the value as an element of the Settings Root Node settingNode = SettingsXml.CreateElement(propVal.Name); settingNode.InnerText = propVal.SerializedValue.ToString(); SettingsXml.SelectSingleNode(SettingsRootNode).AppendChild(settingNode); } else { // It's machine specific, store as an element of the machine name node, // creating a new machine name node if one doesnt exist. XmlElement machineNode; try { machineNode = (XmlElement)SettingsXml.SelectSingleNode(SettingsRootNode + "/" + Environment.MachineName); } catch (Exception) { machineNode = SettingsXml.CreateElement(Environment.MachineName); SettingsXml.SelectSingleNode(SettingsRootNode).AppendChild(machineNode); } if (machineNode == null) { machineNode = SettingsXml.CreateElement(Environment.MachineName); SettingsXml.SelectSingleNode(SettingsRootNode).AppendChild(machineNode); } settingNode = SettingsXml.CreateElement(propVal.Name); settingNode.InnerText = propVal.SerializedValue.ToString(); machineNode.AppendChild(settingNode); } } }