Ejemplo n.º 1
0
        public INode GetTree(string rootPath)
        {
            var directoryInfo = new DirectoryInfo(rootPath);
            if (directoryInfo.Attributes != FileAttributes.Directory)
            {
                var file = new FileInfo(rootPath);
                return new Node
                {
                    Id = file.FullName,
                    Name = file.Name,
                    NodeType = NodeType.File,
                    Children = new INode[0],
                };
            }

            var result = new Node
            {
                Id = directoryInfo.FullName,
                Name = directoryInfo.Name,
                NodeType = NodeType.Folder
            };

            result.Children = directoryInfo.EnumerateFileSystemInfos().Select(fileSystemInfo => new Node { Id = fileSystemInfo.FullName, Name = fileSystemInfo.Name, Children = new INode[0] }).ToList();

            return result;
        }
Ejemplo n.º 2
0
        public INode GetTree(string rootPath)
        {
            var requestResult = GetAllChildren(rootPath);

            var infoResult = GetFileInfo(rootPath);

            var asyncChildren = requestResult.Select(async (child) => new {Id = child.Id, Name = await GetFileInfoAsync(child.Id)}).ToArray();
            Task.WaitAll(asyncChildren.Select(x => (Task)x).ToArray());

            var result = new Node
            {
                Id = infoResult.Id,
                Name = infoResult.Title,
                NodeType = GetNodeType(infoResult),
                // I want children to be populated either by user request or in some background thread as this is very time-consuming operation
                Children = asyncChildren.Select(x => x.Result).Select(x => new Node {Id = x.Id, Name = x.Name.Title}).ToArray(),
            };

            return result;
        }