Esempio n. 1
0
        /// <summary>
        /// Adds a setting item or attribute item into the group
        /// </summary>
        /// <param name="child">Item to add</param>
        public override void Add(SettingItemBase child)
        {
            if (child == null)
            {
                return;
            }

            if (child is SettingAttributeItem)
            {
                var attr = this.GetAttribute(child.Name);
                if (attr == null)
                {
                    this.attributes.Add(child);
                }
                else
                {
                    attr.Value = child.Value;
                }
            }
            else if (child is SettingItemGroup)
            {
                SettingItemBase uniqueKeyAttr            = null;
                IEnumerable <SettingItemBase> attributes = null;

                SettingItemGroup itemGroup = child as SettingItemGroup;
                uniqueKeyAttr = itemGroup.GetAttribute(CONST.SETTING_UNIQUE_KEY_ATTRIBUTE);
                attributes    = itemGroup.Attributes;


                SettingItemBase foundChild = uniqueKeyAttr != null
                    ? this.GetChild(child.Name, uniqueKeyAttr.Value)
                    : this.GetChild(child.Name);

                if (foundChild == null)
                {
                    this.children.Add(child);
                }
                else
                {
                    foundChild.Value = child.Value;
                    if (attributes != null)
                    {
                        foreach (var attr in attributes)
                        {
                            foundChild.Add(attr);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Reads and fills setting information into setting object
        /// </summary>
        /// <param name="setting">Object to be filled setting information</param>
        /// <param name="document">Document to read setting informatino</param>
        /// <returns></returns>
        protected virtual bool FillToObject(AppSetting setting, System.Xml.Linq.XDocument document)
        {
            if (setting.SettingItem == null)
            {
                setting.SettingItem = new SettingItemGroup(document.Root.Name.LocalName);
            }

            foreach (var elm in document.Root.Elements())
            {
                var item = new SettingItemGroup(elm.Name.LocalName, elm.HasElements ? string.Empty : elm.Value);
                this.ReadRecursively(item, elm);

                setting.SettingItem.Add(item);
            }
            return(true);
        }
Esempio n. 3
0
        private void ReadRecursive(SettingItemGroup settingItem, System.Xml.Linq.XElement element)
        {
            if (element.HasAttributes)
            {
                foreach (var attr in element.Attributes())
                {
                    settingItem.Add(new SettingAttributeItem(attr.Name.LocalName, attr.Value));
                }
            }

            if (element.HasElements)
            {
                foreach (var elm in element.Elements())
                {
                    var item = new SettingItemGroup(elm.Name.LocalName, elm.HasElements ? string.Empty : elm.Value);
                    this.ReadRecursive(item, elm);
                    settingItem.Add(item);
                }
            }
        }