GUI async refactor

This commit is contained in:
2022-01-20 23:31:57 +01:00
parent 215503a4e3
commit 031d07613b
12 changed files with 204 additions and 200 deletions

View File

@@ -7,7 +7,7 @@ namespace FileTime.Providers.Smb
{
public class SmbContentProvider : IContentProvider
{
private IContainer _parent;
private IContainer? _parent;
private readonly IInputInterface _inputInterface;
private readonly List<IContainer> _rootContainers;
private readonly IReadOnlyList<IContainer> _rootContainersReadOnly;
@@ -64,32 +64,17 @@ namespace FileTime.Providers.Smb
public IContainer? GetParent() => _parent;
public async Task<bool> IsExists(string name) => (await GetItems()).Any(i => i.Name == name);
public async Task<bool> IsExists(string name) => (await GetItems())?.Any(i => i.Name == name) ?? false;
public async Task Refresh()
{
await Refreshed?.InvokeAsync(this, AsyncEventArgs.Empty);
}
public async Task Refresh() => await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty);
public bool CanHandlePath(string path) => path.StartsWith("smb://") || path.StartsWith(@"\\");
public void SetParent(IContainer container) => _parent = container;
public Task<IReadOnlyList<IContainer>?> GetRootContainers(CancellationToken token = default)
{
return Task.FromResult(_rootContainersReadOnly);
}
public Task<IReadOnlyList<IContainer>> GetRootContainers(CancellationToken token = default) => Task.FromResult(_rootContainersReadOnly);
public Task<IReadOnlyList<IItem>?> GetItems(CancellationToken token = default)
{
return Task.FromResult(_items);
}
public Task<IReadOnlyList<IContainer>?> GetContainers(CancellationToken token = default)
{
return Task.FromResult(_rootContainersReadOnly);
}
public Task<IReadOnlyList<IElement>?> GetElements(CancellationToken token = default)
{
return Task.FromResult(_elements);
}
public Task<IReadOnlyList<IItem>?> GetItems(CancellationToken token = default) => Task.FromResult(_items);
public Task<IReadOnlyList<IContainer>?> GetContainers(CancellationToken token = default) => Task.FromResult((IReadOnlyList<IContainer>?)_rootContainersReadOnly);
public Task<IReadOnlyList<IElement>?> GetElements(CancellationToken token = default) => Task.FromResult(_elements);
}
}

View File

@@ -92,7 +92,7 @@ namespace FileTime.Providers.Smb
_elements = elements.AsReadOnly();
_items = _containers.Cast<IItem>().Concat(_elements).ToList().AsReadOnly();
await Refreshed?.InvokeAsync(this, AsyncEventArgs.Empty);
await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty);
}
public async Task<IReadOnlyList<IItem>?> GetItems(CancellationToken token = default)

View File

@@ -89,7 +89,7 @@ namespace FileTime.Providers.Smb
_shares = shares.ConvertAll(s => new SmbShare(s, Provider, this, GetSmbClient)).AsReadOnly();
_items = _shares.Cast<IItem>().ToList().AsReadOnly();
await Refreshed?.InvokeAsync(this, AsyncEventArgs.Empty);
await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty);
}
private async Task<ISMBClient> GetSmbClient()

View File

@@ -108,7 +108,7 @@ namespace FileTime.Providers.Smb
_elements = elements.AsReadOnly();
_items = _containers.Cast<IItem>().Concat(_elements).ToList().AsReadOnly();
await Refreshed?.InvokeAsync(this, AsyncEventArgs.Empty);
await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty);
}
public async Task<(List<IContainer> containers, List<IElement> elements)> ListFolder(IContainer parent, string shareName, string folderName)