Exemplo n.º 1
0
        private static void ProcessNode(TreeNode <SystemComponent> currentItem, int width, int maxDepth)
        {
            if (maxDepth == 0)
            {
                return;
            }

            IEnumerable <FileSystemInfo> directoryItems = null;

            try
            {
                var directoryInfo = new DirectoryInfo(currentItem.Data.Path);
                directoryItems = directoryInfo.EnumerateFileSystemInfos("*", SearchOption.TopDirectoryOnly).Take(width).ToList();
            }
            catch (Exception)
            {
                // TODO: Add logging
                return;
            }

            foreach (var item in directoryItems)
            {
                SystemComponent treeComponent = null;
                if (item.Attributes.HasFlag(FileAttributes.Directory))
                {
                    treeComponent = new FolderItem(item.Name, item.FullName, item.CreationTime);
                    var folderNode = currentItem.AddChild(treeComponent);
                    ProcessNode(folderNode, width, maxDepth - 1);
                }
                else
                {
                    treeComponent = new FileItem(item.Name, item.FullName, item.CreationTime, (item as FileInfo).Length);
                    currentItem.AddChild(treeComponent);
                }
            }
        }