예제 #1
0
        /// <summary>
        ///     Invoked when the child items need to be loaded on demand.
        ///     Subclasses can override this to populate the Children collection.
        /// </summary>
        protected virtual void LoadChildren()
        {
            Children.AddRange(
                new DirectoryInfo(FullPath).EnumerateDirectories()
                .Where(dirInfo => FileSystemUtils.CanReadDirectory(dirInfo.FullName))
                .OrderBy(dirInfo => dirInfo.Name, new StringWithNumericsComparer())
                .Select(dirInfo => new FolderViewModel(new Folder(dirInfo.FullName), this)));

            foreach (var model in Children.OfType <FolderViewModel>())
            {
                var dirInfo = new DirectoryInfo(model.FullPath);

                if (!FileSystemUtils.CanReadDirectory(dirInfo.FullName) || !dirInfo.EnumerateDirectories().Any())
                {
                    model.Children.Clear();
                }
            }
        }