Пример #1
0
        public bool Visit(string func, Func <ConfItem, int, bool> executor, ConfItem item = null)
        {
            if (item == null)
            {
                RunningTag = new TagRecorder();
                _depth     = 0;
                item       = this;
            }

            var tree = item as ConfTree;

            if (tree != null)
            {
                var fastQuit = VisitTree(func, executor, tree);
                if (fastQuit)
                {
                    return(true);
                }
            }
            else
            {
                _vlog.Debug($"Visit({func}) ConfItem: {item.Name}({item.Value})");
                if (executor(item, _depth))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
        private static bool IsFiltered(ConfTree conf, ConfItem item, int level)
        {
            if (FilterLevel >= 0 && level > 0)//jiangbo: 这个level是相对level?
            {
                return(true);
            }
            else
            {
                if (item.Attributes.ContainsKey("show-only"))
                {
                    var filter = item.Attributes["show-only"].Split('=').Select(x => x.Trim()).ToList();
                    if (!IsMatch(conf, filter[0], filter[1]))
                    {
                        FilterLevel = level;
                        return(true);
                    }
                    else
                    {
                        FilterLevel = -1;
                        return(false);
                    }
                }
            }

            FilterLevel = -1;
            return(false);
        }
Пример #3
0
            public List <string> Unregister(ConfItem item)
            {
                if (Tags.Contains(item.Tag))
                {
                    Tags.Remove(item.Tag);
                }

                return(Tags);
            }
Пример #4
0
        public void RemoveNode(ConfItem item)
        {
            Sons.Remove(item);

            if (XmlDoc != null)
            {
                XmlDoc.RemoveNode(item.SelfPath);
                Save();
            }
        }
Пример #5
0
        public void AddNode(ConfItem item)
        {
            item.Parent = this;
            Sons.Add(item);

            if (XmlDoc != null)
            {
                XmlDoc.AddNode(item.Path, item);
                Save();
            }
        }
Пример #6
0
        public virtual ConfItem Clone(string tag = null)
        {
            var item = new ConfItem(Name, Value)
            {
                Tag = tag == null ? Tag : tag,
            };

            item.Attributes = Attributes;

            return(item);
        }
Пример #7
0
        public static XmlNode CreateNode(XmlDocument xmlDoc, ConfItem conf)
        {
            var current = xmlDoc.CreateElement(conf.Name, null);

            AddTag(xmlDoc, current, conf.Tag);

            if (conf is ConfTree)
            {
                foreach (var attr in conf.Attributes)
                {
                    if (attr.Key != "tag")
                    {
                        var ele = xmlDoc.CreateAttribute(attr.Key);
                        ele.Value = attr.Value;
                        current.Attributes.Append(ele);
                    }
                }

                foreach (var son in (conf as ConfTree).Sons)
                {
                    if (son is ConfTree)
                    {
                        current.AppendChild(CreateNode(xmlDoc, son));
                    }
                    else
                    {
                        var temp = CreateNode(xmlDoc, son);
                        temp.InnerText = son.Value;
                        current.AppendChild(temp);
                    }
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(conf.Value))
                {
                    current.InnerText = conf.Value;
                }

                foreach (var attr in conf.Attributes)
                {
                    if (attr.Key != "tag")
                    {
                        var ele = xmlDoc.CreateAttribute(attr.Key);
                        ele.Value = attr.Value;
                        current.Attributes.Append(ele);
                    }
                }
            }

            return(current);
        }
Пример #8
0
            public List <string> Register(ConfItem item)
            {
                if (Tags.Contains(item.Tag))
                {
                    _log.Warn($"Tag conflict detected: Tag({item.Tag}) already exists in TagRecorder");
                }

                if (!string.IsNullOrEmpty(item.Tag))
                {
                    Tags.Add(item.Tag);
                }

                return(Tags);
            }
Пример #9
0
        private static int ChangeOpLevel(ConfItem item, int level)
        {
            if (CurrentLevels.Count > 0 && level <= CurrentLevels.Last().Value)
            {
                CurrentLevels.RemoveAt(CurrentLevels.Count - 1);
            }

            if ((CurrentLevels.Count == 0) || (item.OpLevel > CurrentLevels.Last().Key))
            {
                CurrentLevels.Add(new KeyValuePair <int, int>(item.OpLevel, level));
            }

            return(CurrentLevels.Last().Key);
        }
Пример #10
0
        public static ConfItem ToItem(XmlNode node)
        {
            if (node.ChildNodes.Count == 0)
            {
                var item = new ConfItem(node.Name, "");

                foreach (XmlAttribute attr in (node as XmlElement).Attributes)
                {
                    item.Attributes[attr.Name] = attr.Value;
                }

                return(item);
            }
            else
            {
                var item = new ConfItem(node.Name, node.FirstChild.InnerText);
                foreach (XmlAttribute attr in (node as XmlElement).Attributes)
                {
                    item.Attributes[attr.Name] = attr.Value;
                }
                return(item);
            }
        }
Пример #11
0
        public override bool Equals(ConfItem tree)
        {
            var target = tree as ConfTree;

            if (target != null)
            {
                bool result = true;
                foreach (var son in Sons)
                {
                    var subtree = son as ConfTree;
                    var path    = son.Path.Substring(target.Path == null ? 1 : target.Path.Length + 1);
                    if (subtree != null)
                    {
                        result &= subtree.Equals(target.Find($"{path}/{subtree.Name}"));
                    }
                    else
                    {
                        var item = target.Find($"{path}/{son.Name}");
                        if (item != null)
                        {
                            result &= son.Equals(item);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }

                return(result);
            }
            else
            {
                return(false);
            }
        }
Пример #12
0
 //添加节点
 public void AddNode(string parentPath, ConfItem item)
 {
     parentPath = parentPath.Substring(0, 1) == @"/" ? parentPath.Substring(1) : parentPath;
     var nodes = Find(parentPath.Split('/'));
     nodes[nodes.Length - 1].AppendChild(XmlConf.CreateNode(this, item));
 }
Пример #13
0
 public void Add(ConfItem item)
 {
     item.Parent = this;
     Sons.Add(item);
 }
Пример #14
0
 public static string DisplayName(ConfItem item)
 {
     return(item.Name + (!item.Attributes.ContainsKey("comment") ? "" : CommentLabel)
            + (string.IsNullOrEmpty(item.Tag) ? "" : $"(tag: {item.Tag})"));
 }
Пример #15
0
 public virtual bool Equals(ConfItem item)
 {
     return((Name == item.Name) && (Value == item.Value));
 }