示例#1
0
        private void BuildFromList(ObjectTypeTree parent, Queue <ObjectTypeEntry> entries, int level)
        {
            if (entries.Count == 0)
            {
                return;
            }

            var first = entries.Dequeue();

            if (first.Level != level)
            {
                throw new ArgumentException($"Invalid Object Type level {first.Level} at level {level}");
            }

            ObjectType = first.ObjectType;
            Name       = first.Name ?? string.Empty;
            Parent     = parent;
            while (entries.Count > 0)
            {
                var next = entries.Peek();
                if (next.Level <= level)
                {
                    return;
                }

                var entry = new ObjectTypeTree();
                entry.BuildFromList(this, entries, level + 1);
                _nodes.Add(entry);
            }
        }
示例#2
0
        /// <summary>
        /// Add a new object type to the tree.
        /// </summary>
        /// <param name="object_type">The object type.</param>
        /// <returns>The added tree object.</returns>
        public ObjectTypeTree AddNode(Guid object_type)
        {
            ObjectTypeTree ret = new ObjectTypeTree(object_type);

            AddNode(ret);
            return(ret);
        }
        /// <summary>
        /// Add a new object type to the tree.
        /// </summary>
        /// <param name="object_type">The object type.</param>
        /// <returns>The added tree object.</returns>
        public ObjectTypeTree AddObjectType(Guid object_type)
        {
            ObjectTypeTree ret = new ObjectTypeTree(object_type);

            Nodes.Add(ret);
            return(ret);
        }
        /// <summary>
        /// Split the tree up to reduce the maximum number of entries.
        /// </summary>
        /// <remarks>This will try and keep whole branches together if at all possible,
        /// but might split them up. This could result in incorrect access checking.</remarks>
        /// <param name="max_entry">The maximum number of entries per tree.</param>
        /// <returns>One or more split trees.</returns>
        public IEnumerable <ObjectTypeTree> Split(int max_entry)
        {
            if (max_entry < 1)
            {
                throw new ArgumentException("Max entry can't be less than 1", nameof(max_entry));
            }
            if (Count < max_entry)
            {
                return new[] { this }
            }
            ;

            List <ObjectTypeTree> ret      = new List <ObjectTypeTree>();
            ObjectTypeTree        new_tree = new ObjectTypeTree(ObjectType, Name);

            ret.Add(new_tree);
            int remaining = max_entry - 1;

            foreach (var node in Nodes.SelectMany(n => n.Split(max_entry - 1)).OrderBy(n => n.Count))
            {
                int count = node.Count;

                if (count > remaining)
                {
                    new_tree  = new ObjectTypeTree(ObjectType, Name);
                    remaining = max_entry - 1;
                    ret.Add(new_tree);
                }
                new_tree.AddNode(node.Clone());
                remaining -= count;
            }
            return(ret.ToArray());
        }
示例#5
0
 /// <summary>
 /// Removes all object types from the tree.
 /// </summary>
 /// <param name="object_type">The object type.</param>
 /// <returns>The removed tree object.</returns>
 public void RemoveNode(ObjectTypeTree object_type)
 {
     _nodes.Remove(object_type);
 }
示例#6
0
 /// <summary>
 /// Add an existing node to the tree.
 /// </summary>
 /// <param name="node">The node to add.</param>
 public void AddNode(ObjectTypeTree node)
 {
     node.Parent = this;
     _nodes.Add(node);
 }