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); }
/// <summary> /// /// </summary> /// <param name="hosting"></param> /// <param name="path"></param> /// <returns>ItemInfo if item exist or null if item is not founded</returns> public static async Task <ItemInfo> TryGetItemInfoAsync(this IHosting hosting, UPath path) { try { return(await hosting.GetItemInfoAsync(path)); } catch (ItemNotFound) { return(null); } }
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)); }
public static async Task <ItemType> GetItemType(this IHosting hosting, UPath path) { try { var info = await hosting.GetItemInfoAsync(path); return(info.Type); } catch (ItemNotFound) { return(ItemType.Unexist); } }
public async Task ReturnInfo_WhenDirectoryExistInAnyHosting() { (await merged.GetItemInfoAsync("adir")).Type.Should().Be(ItemType.Directory); (await merged.GetItemInfoAsync("adir")).Name.Should().Be("adir"); (await merged.GetItemInfoAsync("abdir")).Type.Should().Be(ItemType.Directory); (await merged.GetItemInfoAsync("abdir")).Name.Should().Be("abdir"); (await merged.GetItemInfoAsync("abdir")).Hostings.ShouldBeEquivalentTo(abHostings); }