コード例 #1
0
        private void SetValue(SettingsPropertyValue propVal)
        {
            XmlElement MachineNode;
            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
            {
                // Its machine specific, store as an element of the machine name node,
                // creating a new machine name node if one doesnt exist.
                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);
            }
        }
コード例 #2
0
		} // End Function


		private static void SetValue(SettingsPropertyValue propVal)
		{
			Xml.XmlElement MachineNode;
			Xml.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 = DirectCast(SettingsXML.SelectSingleNode(SETTINGSROOT & "/" & propVal.Name), XmlElement);
				}
				else
				{
					SettingNode = DirectCast(SettingsXML.SelectSingleNode(SETTINGSROOT & "/" & My.Computer.Name & "/" & propVal.Name), XmlElement);
				} // End If
			}
			catch (Exception ex)
			{
				SettingNode = Nothing;
			} //End Try-Catch

			// 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.
					try
					{
						MachineNode = DirectCast(SettingsXML.SelectSingleNode(SETTINGSROOT & "/" & My.Computer.Name), XmlElement);
					}
					catch (Exception ex)
					{
						MachineNode = SettingsXML.CreateElement(My.Computer.Name);
						SettingsXML.SelectSingleNode(SETTINGSROOT).AppendChild(MachineNode);
					} // End Try-Catch

					if (MachineNode == null)
					{
						MachineNode = SettingsXML.CreateElement(My.Computer.Name);
						SettingsXML.SelectSingleNode(SETTINGSROOT).AppendChild(MachineNode);
					} // End If

					SettingNode = SettingsXML.CreateElement(propVal.Name);
					SettingNode.InnerText = propVal.SerializedValue.ToString;
					MachineNode.AppendChild(SettingNode);
				} //  End If
			} // End If
		} // End Sub
コード例 #3
0
                    private void SetValue(SettingsPropertyValue propVal)
                    {
                        System.Xml.XmlElement MachineNode;
                        System.Xml.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(
                                         System.Convert.ToString(SETTINGSROOT + "/" + propVal.Name)));
                            }
                            else
                            {
                                SettingNode =
                                    (XmlElement)
                                    (SettingsXML.SelectSingleNode(
                                         System.Convert.ToString(SETTINGSROOT + "/" +
                                                                 (new Microsoft.VisualBasic.Devices.Computer()).Name +
                                                                 "/" + propVal.Name)));
                            }
                        }
                        catch (Exception)
                        {
                            SettingNode = null;
                        }

                        //Check to see if the node exists, if so then set its new value
                        if (SettingNode != null)
                        {
                            if (propVal.SerializedValue != 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);
                                if (propVal.SerializedValue != null)
                                {
                                    SettingNode.InnerText = propVal.SerializedValue.ToString();
                                }
                                var selectSingleNode = SettingsXML.SelectSingleNode(SETTINGSROOT);
                                if (selectSingleNode != null)//ToDO: What if Null?
                                {
                                    selectSingleNode.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.
                                try
                                {
                                    MachineNode =
                                        (XmlElement)
                                        (SettingsXML.SelectSingleNode(
                                             System.Convert.ToString(SETTINGSROOT + "/" +
                                                                     (new Microsoft.VisualBasic.Devices.Computer()).Name)));
                                }
                                catch (Exception)
                                {
                                    MachineNode =
                                        SettingsXML.CreateElement((new Microsoft.VisualBasic.Devices.Computer()).Name);
                                    SettingsXML.SelectSingleNode(SETTINGSROOT.ToString()).AppendChild(MachineNode);
                                }

                                if (MachineNode == null)
                                {
                                    MachineNode =
                                        SettingsXML.CreateElement((new Microsoft.VisualBasic.Devices.Computer()).Name);
                                    SettingsXML.SelectSingleNode(SETTINGSROOT.ToString()).AppendChild(MachineNode);
                                }

                                SettingNode = SettingsXML.CreateElement(propVal.Name);
                                if (propVal.SerializedValue != null)
                                {
                                    SettingNode.InnerText = propVal.SerializedValue.ToString();
                                }
                                MachineNode.AppendChild(SettingNode);
                            }
                        }
                    }