Beispiel #1
0
            /// <summary>
            /// 一次性递归加载所有树节点。
            /// </summary>
            /// <param name="method">
            /// 是使用 TreeIndex 一次性加载所有节点,还是使用 TreePId 递归加载子节点(强关系,但是性能较差)。
            /// </param>
            /// <param name="forceOwnerTreeIndex">
            /// 如果当前节点的状态还没有保存到数据库,那么此方法会使用数据库中的 TreeIndex 值来加载子节点。
            /// 此时,可以通过此参数来强制使用内存中 TreeIndex。
            /// </param>
            /// <exception cref="InvalidProgramException">还没有存储到数据库中的节点,它的 IsFullLoaded 属性应该返回 true。</exception>
            /// <exception cref="System.InvalidProgramException">还没有存储到数据库中的节点,它的 IsFullLoaded 属性应该返回 true。</exception>
            public void LoadAllNodes(LoadAllNodesMethod method, bool forceOwnerTreeIndex)
            {
                if (!this.IsFullLoaded)
                {
                    var repo = _owner.GetRepository();

                    if (method == LoadAllNodesMethod.ByTreeIndex)
                    {
                        var treeIndex = _owner.TreeIndex;

                        if (!forceOwnerTreeIndex && _owner.PersistenceStatus != PersistenceStatus.Unchanged)
                        {
                            var dbOwner = repo.GetById(_owner.Id);
                            if (dbOwner == null)
                            {
                                throw new InvalidProgramException("还没有存储到数据库中的节点,它的 IsFullLoaded 属性应该返回 true。");
                            }

                            treeIndex = dbOwner.TreeIndex;
                        }

                        var children = repo.GetByTreeParentIndex(treeIndex);
                        this.MergeFullTree(children.ToList());
                    }
                    else
                    {
                        this.Load();
                        (this as ITreeComponent).EachNode(n =>
                        {
                            n.TreeChildren.Load();
                            return(false);
                        });
                    }
                }
            }
Beispiel #2
0
 void ITreeComponent.LoadAllNodes(LoadAllNodesMethod method)
 {
     if (!this.IsTreeLeafSure)
     {
         this.TreeChildren.LoadAllNodes(method);
     }
 }
Beispiel #3
0
        void ITreeComponent.LoadAllNodes(LoadAllNodesMethod method)
        {
            if (this.Count > 0)
            {
                if (method == LoadAllNodesMethod.ByTreeIndex)
                {
                    if (!this.IsTreeRootList)
                    {
                        throw new InvalidOperationException("只有根节点的集合,才能调用本方法。");
                    }

                    var all = this.GetRepository().GetAll();
                    for (int i = 0, c = this.Count; i < c; i++)
                    {
                        var item = this[i];
                        if (!item.IsTreeLeafSure && !item.TreeChildren.IsFullLoaded)
                        {
                            var dbItem = all.Find(item.Id);
                            var field  = dbItem.TreeChildrenField;
                            if (field != null)
                            {
                                item.TreeChildren.MergeFullTree(field.Cast <Entity>().ToList());
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0, c = this.Count; i < c; i++)
                    {
                        var item = this[i] as ITreeComponent;
                        item.LoadAllNodes(method);
                    }
                }
            }
        }
Beispiel #4
0
 /// <summary>
 /// 一次性加载所有节点。
 /// </summary>
 public void LoadAllNodes(LoadAllNodesMethod method)
 {
     this.LoadAllNodes(method, false);
 }