Example #1
0
        public static XmlNode ToXMLNode(XmlNode parent, XMLConfig config)
        {
            XmlNode root = XMLUtil.AddChildNode(parent, config.name, "");

            foreach (string key in config.attrDict.Keys)
            {
                if (key == Config_Path_Key)
                {
                    continue;
                }
                string value = config.attrDict[key];
                XMLUtil.SetNodeAttrValue(root, key, value);
            }

            foreach (string key in config.propDict.Keys)
            {
                string  value = config.propDict[key];
                XmlNode child = XMLUtil.AddChildNode(root, Property_Key, "");
                XMLUtil.SetNodeAttrValue(child, Name_Key, key);
                if (value.Length < 100 && value.IndexOf('\n') == -1 && value.IndexOf('\r') == -1)
                {
                    XMLUtil.SetNodeAttrValue(child, Value_Key, value);
                }
                else
                {
                    XMLUtil.SetNodeValue(child, value);
                }
            }

            for (int i = 0; i < config.configList.Count; i++)
            {
                ToXMLNode(root, (XMLConfig)config.configList[i]);
            }
            return(root);
        }
Example #2
0
        public XMLConfig RemoveConfig(int index)
        {
            XMLConfig config = this.configList[index];

            this.configList.RemoveAt(index);
            return(config);
        }
Example #3
0
        public XMLConfig AddConfig(int index, string tag)
        {
            XMLConfig subConfig = new XMLConfig();

            subConfig.parentConfig = this;
            subConfig.SetName(tag);
            this.configList.Insert(index, subConfig);
            return(subConfig);
        }
Example #4
0
        public XMLConfig AddConfig(string tag)
        {
            XMLConfig subConfig = new XMLConfig();

            subConfig.parentConfig = this;
            subConfig.SetName(tag);
            this.configList.Add(subConfig);
            return(subConfig);
        }
Example #5
0
        public XMLConfig removeConfig(string attrName, string attrValue)
        {
            XMLConfig config = GetConfig(attrName, attrValue);

            if (config != null)
            {
                this.configList.Remove(config);
            }
            return(config);
        }
Example #6
0
        public XMLConfig RemoveConfig(string tag)
        {
            XMLConfig config = GetConfig(tag);

            if (config != null)
            {
                this.configList.Remove(config);
            }
            return(config);
        }
Example #7
0
        public XMLConfig GetConfig(string tag)
        {
            for (int i = 0; i < this.configList.Count; i++)
            {
                XMLConfig config = (XMLConfig)this.configList[i];
                if (tag == config.GetName())
                {
                    return(config);
                }
            }

            return(null);
        }
Example #8
0
        public XMLConfig GetConfig(string attrName, string attrValue)
        {
            for (int i = 0; i < GetConfigCount(); i++)
            {
                XMLConfig config = (XMLConfig)this.configList[i];
                if (config.GetAttribute(attrName) == attrValue)
                {
                    return(config);
                }
            }

            return(null);
        }
Example #9
0
        public bool HasConfig(string tag)
        {
            for (int i = 0; i < this.configList.Count; i++)
            {
                XMLConfig conf = (XMLConfig)this.configList[i];
                if (tag == conf.GetName())
                {
                    return(true);
                }
            }

            return(false);
        }
Example #10
0
        public void Reload()
        {
            if (Reloadable())
            {
                this.configList.Clear();
                this.propDict.Clear();
                this.attrDict.Clear();
                this.parentConfig = null;
                this.name         = null;

                LoadFrom(this.configFile);
                return;
            }

            throw new IOException("无法重新载入配置信息");
        }
Example #11
0
        public XMLConfig[] GetConfigs(string tag)
        {
            List <XMLConfig> configList = new List <XMLConfig>();

            for (int i = 0; i < this.configList.Count; i++)
            {
                XMLConfig config = (XMLConfig)this.configList[i];
                if (tag == config.GetName())
                {
                    configList.Add(config);
                }
            }

            XMLConfig[] configs = new XMLConfig[configList.Count];
            configs = configList.ToArray();
            return(configs);
        }
Example #12
0
        public XMLConfig MatchesConfig(string attrName, string attrValue)
        {
            Regex r = new Regex(attrValue, RegexOptions.IgnoreCase);

            for (int i = 0; i < GetConfigCount(); i++)
            {
                XMLConfig config = (XMLConfig)this.configList[i];
                if (config.HasAttribute(attrName))
                {
                    Match m = r.Match(config.GetAttribute(attrName));
                    if (m.Success)
                    {
                        return(config);
                    }
                }
            }

            return(null);
        }
Example #13
0
 public void AddConfig(int index, XMLConfig subConfig)
 {
     subConfig.parentConfig = this;
     this.configList.Insert(index, subConfig);
 }
Example #14
0
 public void AddConfig(XMLConfig subConfig)
 {
     subConfig.parentConfig = this;
     this.configList.Add(subConfig);
 }
Example #15
0
 public XMLConfig[] GetConfigs()
 {
     XMLConfig[] configs = new XMLConfig[this.configList.Count];
     configs = this.configList.ToArray();
     return(configs);
 }
Example #16
0
        public void LoadFrom(XmlNode node)
        {
            if (this.name == null)
            {
                string name = node.Name;
                if (name != null)
                {
                    this.name = name.Trim();
                }
            }

            Dictionary <string, string> nodeAttrDict = XMLUtil.GetNodeAttrs(node);

            foreach (string key in nodeAttrDict.Keys)
            {
                if (this.attrDict.ContainsKey(key))
                {
                    continue;
                }
                string value = nodeAttrDict.GetOrAddDefault(key, () => "");
                this.attrDict[key] = value;
            }

            XmlNode   child     = node.FirstChild;
            XMLConfig subConfig = null;

            while (child != null)
            {
                if (child.NodeType == XmlNodeType.Element)
                {
                    if (IsPropertyNode(child))
                    {
                        LoadProperty(child);
                    }
                    else
                    {
                        string childNodeName = child.Name;
                        if (childNodeName == null)
                        {
                            continue;
                        }
                        childNodeName = childNodeName.Trim();
                        string parseClassString = XMLUtil.GetNodeAttrValue(child, "parseClass", "");
                        if (parseClassString.Length > 0)
                        {
                            subConfig = (XMLConfig)Activator.CreateInstance(Type.GetType(parseClassString));
                        }
                        else
                        {
                            subConfig = new XMLConfig();
                        }
                        subConfig.parentConfig = this;
                        subConfig.name         = childNodeName;
                        subConfig.LoadFrom(child);                         // 不断循环下一层
                        this.configList.Add(subConfig);
                    }
                }

                child = child.NextSibling;
            }

            string configPath = nodeAttrDict.GetOrAddDefault(Config_Path_Key, () => "");

            if (configPath.Length > 0)
            {
                LoadFrom(configPath);
            }
        }