public string GetValue(string section, string entry, SettingScope scope)
        {
            if (document == null) return null;

              XmlElement root = document.DocumentElement;
              if (root == null) return null;
              XmlNode entryNode;
              if (scope == SettingScope.User)
            entryNode =
              root.SelectSingleNode(GetSectionPath(section) + "/" + GetScopePath(scope.ToString()) + "/" +
                                GetUserPath(Environment.UserName) + "/" + GetEntryPath(entry));
              else
            entryNode =
              root.SelectSingleNode(GetSectionPath(section) + "/" + GetScopePath(scope.ToString()) + "/" +
                                GetEntryPath(entry));
              if (entryNode == null) return null;
              return entryNode.InnerText;
        }
Esempio n. 2
0
        public string GetValue(string section, string entry, SettingScope scope)
        {
            var root = _document?.DocumentElement;

            if (root == null)
            {
                return(null);
            }
            XmlNode entryNode;

            if (scope == SettingScope.User)
            {
                entryNode =
                    root.SelectSingleNode(GetSectionPath(section) + "/" + GetScopePath(scope.ToString()) + "/" +
                                          GetUserPath() + "/" + GetEntryPath(entry));
            }
            else
            {
                entryNode =
                    root.SelectSingleNode(GetSectionPath(section) + "/" + GetScopePath(scope.ToString()) + "/" +
                                          GetEntryPath(entry));
            }
            return(entryNode?.InnerText);
        }
Esempio n. 3
0
        public void SetValue(string section, string entry, string value, SettingScope scope)
        {
            // If the value is null, remove the entry
            if (value == null)
            {
                RemoveEntry(section, entry);
                return;
            }

            string valueString = value;

            if (_document.DocumentElement == null)
            {
                var node = _document.CreateElement("Configuration");
                _document.AppendChild(node);
            }
            var root = _document.DocumentElement;

            // Get the section element and add it if it's not there
            if (root != null)
            {
                var sectionNode = root.SelectSingleNode("Section[@name=\"" + section + "\"]");
                if (sectionNode == null)
                {
                    var element   = _document.CreateElement("Section");
                    var attribute = _document.CreateAttribute("name");
                    attribute.Value = section;
                    element.Attributes.Append(attribute);
                    sectionNode = root.AppendChild(element);
                }
                // Get the section element and add it if it's not there
                var scopeSectionNode = sectionNode.SelectSingleNode("Scope[@value=\"" + scope + "\"]");
                if (scopeSectionNode == null)
                {
                    var element   = _document.CreateElement("Scope");
                    var attribute = _document.CreateAttribute("value");
                    attribute.Value = scope.ToString();
                    element.Attributes.Append(attribute);
                    scopeSectionNode = sectionNode.AppendChild(element);
                }
                if (scope == SettingScope.User)
                {
                    var userNode = scopeSectionNode.SelectSingleNode("User[@name=\"" + Environment.UserName + "\"]");
                    if (userNode == null)
                    {
                        var element   = _document.CreateElement("User");
                        var attribute = _document.CreateAttribute("name");
                        attribute.Value = Environment.UserName;
                        element.Attributes.Append(attribute);
                        userNode = scopeSectionNode.AppendChild(element);
                    }
                }
                // Get the entry element and add it if it's not there
                XmlNode entryNode = null;
                if (scope == SettingScope.User)
                {
                    var userNode = scopeSectionNode.SelectSingleNode("User[@name=\"" + Environment.UserName + "\"]");
                    if (userNode != null)
                    {
                        entryNode = userNode.SelectSingleNode("Setting[@name=\"" + entry + "\"]");
                    }
                }
                else
                {
                    entryNode = scopeSectionNode.SelectSingleNode("Setting[@name=\"" + entry + "\"]");
                }

                if (entryNode == null)
                {
                    XmlElement   element   = _document.CreateElement("Setting");
                    XmlAttribute attribute = _document.CreateAttribute("name");
                    attribute.Value = entry;
                    element.Attributes.Append(attribute);
                    if (scope == SettingScope.Global)
                    {
                        entryNode = scopeSectionNode.AppendChild(element);
                    }
                    else
                    {
                        var userNode = scopeSectionNode.SelectSingleNode("User[@name=\"" + Environment.UserName + "\"]");
                        if (userNode != null)
                        {
                            entryNode = userNode.AppendChild(element);
                        }
                    }
                }
                if (entryNode != null)
                {
                    entryNode.InnerText = valueString;
                }
            }
            _modified = true;
        }
        public void SetValue(string section, string entry, string value, SettingScope scope)
        {
            // If the value is null, remove the entry
              if (value == null)
              {
            RemoveEntry(section, entry);
            return;
              }

              string valueString = value;

              if (document.DocumentElement == null)
              {
            XmlElement node = document.CreateElement("Configuration");
            document.AppendChild(node);
              }
              XmlElement root = document.DocumentElement;
              // Get the section element and add it if it's not there
              XmlNode sectionNode = root.SelectSingleNode("Section[@name=\"" + section + "\"]");
              if (sectionNode == null)
              {
            XmlElement element = document.CreateElement("Section");
            XmlAttribute attribute = document.CreateAttribute("name");
            attribute.Value = section;
            element.Attributes.Append(attribute);
            sectionNode = root.AppendChild(element);
              }
              // Get the section element and add it if it's not there
              XmlNode scopeSectionNode = sectionNode.SelectSingleNode("Scope[@value=\"" + scope + "\"]");
              if (scopeSectionNode == null)
              {
            XmlElement element = document.CreateElement("Scope");
            XmlAttribute attribute = document.CreateAttribute("value");
            attribute.Value = scope.ToString();
            element.Attributes.Append(attribute);
            scopeSectionNode = sectionNode.AppendChild(element);
              }
              if (scope == SettingScope.User)
              {
            XmlNode userNode = scopeSectionNode.SelectSingleNode("User[@name=\"" + Environment.UserName + "\"]");
            if (userNode == null)
            {
              XmlElement element = document.CreateElement("User");
              XmlAttribute attribute = document.CreateAttribute("name");
              attribute.Value = Environment.UserName;
              element.Attributes.Append(attribute);
              userNode = scopeSectionNode.AppendChild(element);
            }
              }
              // Get the entry element and add it if it's not there
              XmlNode entryNode;
              if (scope == SettingScope.User)
              {
            XmlNode userNode = scopeSectionNode.SelectSingleNode("User[@name=\"" + Environment.UserName + "\"]");
            entryNode = userNode.SelectSingleNode("Setting[@name=\"" + entry + "\"]");
              }
              else entryNode = scopeSectionNode.SelectSingleNode("Setting[@name=\"" + entry + "\"]");

              if (entryNode == null)
              {
            XmlElement element = document.CreateElement("Setting");
            XmlAttribute attribute = document.CreateAttribute("name");
            attribute.Value = entry;
            element.Attributes.Append(attribute);
            if (scope == SettingScope.Global) entryNode = scopeSectionNode.AppendChild(element);
            else
            {
              XmlNode userNode = scopeSectionNode.SelectSingleNode("User[@name=\"" + Environment.UserName + "\"]");
              entryNode = userNode.AppendChild(element);
            }
              }
              entryNode.InnerText = valueString;
              modified = true;
        }