Ejemplo n.º 1
0
        /// <summary>
        /// Initialize the list of root folders.
        /// </summary>
        private void InitializeFolders()
        {
            lock (DataModel.SyncRoot)
            {
                LambdaComparer <FolderTreeNode> folderTreeNodeComparer = new LambdaComparer <FolderTreeNode>((l, r) => l.Entity.Name.CompareTo(r.Entity.Name));
                List <FolderTreeNode>           folders = new List <FolderTreeNode>();
                var entities = DataModel.Entity.Where(row =>
                                                      (row.GetFolderRows().Length > 0 || row.GetBlotterRows().Length > 0));

                foreach (EntityRow entityRow in entities)
                {
                    Boolean topLevel = true;

                    // Determine whether a folder/blotter has any parent folders or blotters.
                    foreach (EntityTreeRow entityTreeRow in entityRow.GetEntityTreeRowsByFK_Entity_EntityTree_ChildId())
                    {
                        EntityRow parent = entityTreeRow.EntityRowByFK_Entity_EntityTree_ParentId;

                        if (parent.GetFolderRows().Length > 0 || parent.GetBlotterRows().Length > 0)
                        {
                            topLevel = false;
                            break;
                        }
                    }

                    // If they don't add them to our list.
                    if (topLevel)
                    {
                        FolderTreeNode folderTreeNode = new FolderTreeNode(entityRow);
                        Int32          index          = folders.BinarySearch(folderTreeNode, folderTreeNodeComparer);

                        if (index < 0)
                        {
                            index = ~index;
                        }

                        folders.Insert(index, folderTreeNode);
                    }
                }

                this.Dispatcher.BeginInvoke(new Action(() => this.Folders = folders), DispatcherPriority.Normal);
            }
        }