示例#1
0
        public override void AddOrChangePropertyValueElement(XmlNode parent, string propertyName, string value,
                                                             bool changeValueIfExists = true)
        {
            if (parent == null)
            {
                throw new SettingsManagerException("Could not add PropertyValue to settings storage");
            }

            foreach (XmlNode node in parent.ChildNodes)
            {
                if (node.Attributes?["name"] == null || !node.Attributes["name"].Value
                    .Equals(propertyName, StringComparison.CurrentCultureIgnoreCase))
                {
                    continue;
                }
                if (changeValueIfExists)
                {
                    node.InnerText = value;
                }
                return;
            }
            var element = SettingsStorage.CreateElement("PropertyValue", value,
                                                        new KeyValuePair <string, string>("name", propertyName));

            parent.AppendChild(element);
        }
示例#2
0
        public override void AddCategoryElement(ISettingsCategory category)
        {
            foreach (var settingsCategory in category.Path)
            {
                if (GetSingleNode(settingsCategory.Name) != null)
                {
                    continue;
                }
                XmlNode parentNode;
                if (settingsCategory.Parent == null)
                {
                    if (settingsCategory.CategoryType == SettingsCategoryType.ToolsOption)
                    {
                        parentNode = GetSingleNode("ToolsOptions", false) ??
                                     SettingsStorage.DocumentElement?.AppendChild(
                            CreateToolsOptionsElement(SettingsStorage));
                    }
                    else
                    {
                        parentNode = GetSingleNode(string.Empty, false);
                    }
                }
                else
                {
                    AddCategoryElement(settingsCategory.Parent);
                    parentNode = GetSingleNode(settingsCategory.Parent.Name);
                }

                XmlElement element;
                switch (settingsCategory.CategoryType)
                {
                case SettingsCategoryType.ToolsOption:
                    element = SettingsStorage.CreateElement("ToolsOptionsCategory", string.Empty,
                                                            new KeyValuePair <string, string>("name", settingsCategory.Name));
                    break;

                case SettingsCategoryType.ToolsOptionSub:
                    element = SettingsStorage.CreateElement("ToolsOptionsSubCategory", string.Empty,
                                                            new KeyValuePair <string, string>("name", settingsCategory.Name));
                    break;

                case SettingsCategoryType.Normal:
                    element = SettingsStorage.CreateElement("Category", null,
                                                            new KeyValuePair <string, string>("name", settingsCategory.Name),
                                                            new KeyValuePair <string, string>("RegisteredName", settingsCategory.Name));
                    if (!settingsCategory.HasChildren)
                    {
                        element.SetAttribute("Category", settingsCategory.Id.ToString("B"));
                    }
                    break;

                default:
                    throw new NotSupportedException();
                }
                lock (_lockObk)
                    parentNode?.AppendChild(element);
            }
        }
示例#3
0
        public override void AddToolsOptionsModelElement(string settingsModelName, string categoryName)
        {
            var node = GetSingleNode(categoryName);

            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            lock (_lockObk)
            {
                var element = SettingsStorage.CreateElement("ToolsOptionsCategory", string.Empty,
                                                            new KeyValuePair <string, string>("name", settingsModelName));
                node.AppendChild(element);
            }
        }