/// <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);
        }
示例#2
0
        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);
            }
        }
示例#3
0
        /// <summary>
        /// Store the value as an element of the Settings Root Node
        /// </summary>
        private void CreateRoamingValue(SettingsPropertyValue propVal)
        {
            var settingNode = SettingsXml.CreateElement(propVal.Name);

            settingNode.InnerText = propVal.SerializedValue.ToString();
            SettingsRootNode.AppendChild(settingNode);
        }
        private void SetValue(XmlNode groupNode, SettingsPropertyValue propVal)
        {
            XmlElement settingNode;

            try
            {
                settingNode = (XmlElement)groupNode.SelectSingleNode("setting[@name='" + propVal.Name + "']");
            }
            catch (Exception ex)
            {
                settingNode = null;
            }

            //Check to see if the node exists, if so then set its new value
            if (settingNode != null)
            {
                var valueNode = (XmlElement)settingNode.SelectSingleNode("value");
                SetValueNodeContentsFromProp(propVal, valueNode);
            }
            else
            {
                settingNode = SettingsXml.CreateElement("setting");
                settingNode.SetAttribute("name", propVal.Name);
                settingNode.SetAttribute("serializeAs", propVal.Property.SerializeAs.ToString());
                var valueNode = SettingsXml.CreateElement("value");
                SetValueNodeContentsFromProp(propVal, valueNode);
                settingNode.AppendChild(valueNode);
                groupNode.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"));
     }
 }
示例#6
0
        /// <summary>
        /// Store the value as an element of the Settings Root Node
        /// </summary>
        private void CreateRoamingValue(SettingsPropertyValue propVal)
        {
            var serializedValue = propVal.SerializedValue;

            if (serializedValue != null)
            {
                if (SettingsRootNode == null)
                {
                    throw new ArgumentNullException(nameof(SettingsRootNode));
                }
                if (SettingsXml == null)
                {
                    throw new ArgumentNullException(nameof(SettingsXml));
                }
                var settingNode = SettingsXml.CreateElement(propVal.Name);
                settingNode.InnerText = serializedValue.ToString();
                SettingsRootNode.AppendChild(settingNode);
            }
        }
示例#7
0
        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));
            }
        }
示例#8
0
        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);
                }
            }
        }