Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 /// <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);
     }
 }
Esempio n. 3
0
 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));
 }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        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);
        }