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(SETTINGSROOT + "/" + propVal.Name);
else
settingNode = (XmlElement)SettingsXML.SelectSingleNode(SETTINGSROOT + "/" + Environment.MachineName + "/" + propVal.Name);
}
catch (Exception ex)
{
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(SETTINGSROOT).AppendChild(settingNode);
}
else
{
//Its 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(SETTINGSROOT + "/" + Environment.MachineName);
}
catch (Exception ex)
{
machineNode = SettingsXML.CreateElement(Environment.MachineName);
SettingsXML.SelectSingleNode(SETTINGSROOT).AppendChild(machineNode);
}
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);
}
}
}