GUI async refactor
This commit is contained in:
@@ -64,8 +64,7 @@ namespace FileTime.Providers.Local
|
||||
return await rootContainer.GetByPath(string.Join(Constants.SeparatorChar, pathParts.Skip(1)));
|
||||
}
|
||||
|
||||
public Task Refresh() => Task.CompletedTask;
|
||||
|
||||
public async Task Refresh() => await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty);
|
||||
|
||||
public IContainer? GetParent() => _parent;
|
||||
public Task<IContainer> CreateContainer(string name) => throw new NotSupportedException();
|
||||
@@ -78,26 +77,11 @@ namespace FileTime.Providers.Local
|
||||
|
||||
public bool CanHandlePath(string path) => _rootContainers.Any(r => path.StartsWith(r.Name));
|
||||
|
||||
public void SetParent(IContainer container)
|
||||
{
|
||||
_parent = container;
|
||||
}
|
||||
public Task<IReadOnlyList<IContainer>?> GetRootContainers(CancellationToken token = default)
|
||||
{
|
||||
return Task.FromResult(_rootContainers);
|
||||
}
|
||||
public void SetParent(IContainer container) => _parent = container;
|
||||
public Task<IReadOnlyList<IContainer>> GetRootContainers(CancellationToken token = default) => Task.FromResult(_rootContainers);
|
||||
|
||||
public Task<IReadOnlyList<IItem>?> GetItems(CancellationToken token = default)
|
||||
{
|
||||
return Task.FromResult(_items);
|
||||
}
|
||||
public Task<IReadOnlyList<IContainer>?> GetContainers(CancellationToken token = default)
|
||||
{
|
||||
return Task.FromResult(_rootContainers);
|
||||
}
|
||||
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>?)_rootContainers);
|
||||
public Task<IReadOnlyList<IElement>?> GetElements(CancellationToken token = default) => Task.FromResult(_elements);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user