public static async Task <Node <ItemInfo> > GetItemsTreeAsync(this IHosting hosting, UPath path) { if (!await hosting.IsExistAsync(path)) { throw new ItemNotFound(); } if (await hosting.IsFileAsync(path)) { return(new Node <ItemInfo>(await hosting.GetItemInfoAsync(path))); } return(await hosting.GetDirectoryItemsTreeAsync(path)); }
private static async Task <Node <ItemInfo> > GetDirectoryItemsTreeAsync(this IHosting hosting, UPath path) { var nested = (await hosting.GetDirectoryListAsync(path)) .Select(async i => { return(i.IsDirectory ? await hosting.GetDirectoryItemsTreeAsync(i.Path) : new Node <ItemInfo>(await hosting.GetItemInfoAsync(i.Path))); }).ToList(); await Task.WhenAll(nested); var node = new Node <ItemInfo>(await hosting.GetItemInfoAsync(path)); node.Nested.AddRange(nested.Select(n => n.Result)); return(node); }