Browse Source

Update API, samples and BCL impl

pull/10603/head
Max Katz 3 years ago
parent
commit
5968830296
  1. 4
      samples/ControlCatalog/Pages/DialogsPage.xaml.cs
  2. 8
      samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs
  3. 12
      src/Avalonia.Base/Platform/Storage/FileIO/BclStorageFolder.cs
  4. 2
      src/Avalonia.Base/Platform/Storage/IStorageFolder.cs

4
samples/ControlCatalog/Pages/DialogsPage.xaml.cs

@ -324,9 +324,9 @@ namespace ControlCatalog.Pages
mappedResults.Add("+> " + FullPathOrName(selectedItem));
if (selectedItem is IStorageFolder folder)
{
foreach (var innerItems in await folder.GetItemsAsync())
await foreach (var innerItem in folder.GetItemsAsync())
{
mappedResults.Add("++> " + FullPathOrName(innerItems));
mappedResults.Add("++> " + FullPathOrName(innerItem));
}
}
}

8
samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs

@ -104,8 +104,12 @@ namespace ControlCatalog.Pages
}
else if (item is IStorageFolder folder)
{
var items = await folder.GetItemsAsync();
contentStr += $"Folder {item.Name}: items {items.Count}{Environment.NewLine}{Environment.NewLine}";
var childrenCount = 0;
await foreach (var _ in folder.GetItemsAsync())
{
childrenCount++;
}
contentStr += $"Folder {item.Name}: items {childrenCount}{Environment.NewLine}{Environment.NewLine}";
}
}

12
src/Avalonia.Base/Platform/Storage/FileIO/BclStorageFolder.cs

@ -57,14 +57,16 @@ internal class BclStorageFolder : IStorageBookmarkFolder
return Task.FromResult<IStorageFolder?>(null);
}
public Task<IReadOnlyList<IStorageItem>> GetItemsAsync()
public async IAsyncEnumerable<IStorageItem> GetItemsAsync()
{
var items = DirectoryInfo.GetDirectories()
var items = DirectoryInfo.EnumerateDirectories()
.Select(d => (IStorageItem)new BclStorageFolder(d))
.Concat(DirectoryInfo.GetFiles().Select(f => new BclStorageFile(f)))
.ToArray();
.Concat(DirectoryInfo.EnumerateFiles().Select(f => new BclStorageFile(f)));
return Task.FromResult<IReadOnlyList<IStorageItem>>(items);
foreach (var item in items)
{
yield return item;
}
}
public virtual Task<string?> SaveBookmarkAsync()

2
src/Avalonia.Base/Platform/Storage/IStorageFolder.cs

@ -16,5 +16,5 @@ public interface IStorageFolder : IStorageItem
/// <returns>
/// When this method completes successfully, it returns a list of the files and folders in the current folder. Each item in the list is represented by an <see cref="IStorageItem"/> implementation object.
/// </returns>
Task<IReadOnlyList<IStorageItem>> GetItemsAsync();
IAsyncEnumerable<IStorageItem> GetItemsAsync();
}

Loading…
Cancel
Save