Async core refactor

This commit is contained in:
2022-01-20 18:16:01 +01:00
parent 016100a565
commit 215503a4e3
33 changed files with 761 additions and 463 deletions

View File

@@ -1,3 +1,4 @@
using AsyncEvent;
using FileTime.Core.Interactions;
using FileTime.Core.Models;
using FileTime.Core.Providers;
@@ -7,16 +8,11 @@ namespace FileTime.Providers.Smb
public class SmbContentProvider : IContentProvider
{
private IContainer _parent;
private readonly List<IContainer> _rootContainers;
private readonly IInputInterface _inputInterface;
public IReadOnlyList<IContainer> RootContainers { get; }
public IReadOnlyList<IItem> Items => RootContainers;
public IReadOnlyList<IContainer> Containers => RootContainers;
public IReadOnlyList<IElement> Elements { get; } = new List<IElement>();
private readonly List<IContainer> _rootContainers;
private readonly IReadOnlyList<IContainer> _rootContainersReadOnly;
private readonly IReadOnlyList<IItem>? _items;
private readonly IReadOnlyList<IElement>? _elements = new List<IElement>().AsReadOnly();
public string Name { get; } = "smb";
@@ -26,16 +22,16 @@ namespace FileTime.Providers.Smb
public IContentProvider Provider => this;
public event EventHandler? Refreshed;
public AsyncEventHandler Refreshed { get; } = new();
public SmbContentProvider(IInputInterface inputInterface)
{
_rootContainers = new List<IContainer>();
RootContainers = _rootContainers.AsReadOnly();
_rootContainersReadOnly = _rootContainers.AsReadOnly();
_inputInterface = inputInterface;
}
public IContainer CreateContainer(string name)
public async Task<IContainer> CreateContainer(string name)
{
var fullName = "\\\\" + name;
var container = _rootContainers.Find(c => c.Name == name);
@@ -46,37 +42,54 @@ namespace FileTime.Providers.Smb
_rootContainers.Add(container);
}
Refresh();
await Refresh();
return container;
}
public IElement CreateElement(string name)
public Task<IElement> CreateElement(string name)
{
throw new NotSupportedException();
}
public void Delete()
public Task Delete()
{
throw new NotSupportedException();
}
public IItem? GetByPath(string path)
public Task<IItem?> GetByPath(string path)
{
throw new NotImplementedException();
}
public IContainer? GetParent() => _parent;
public bool IsExists(string name) => Items.Any(i => i.Name == name);
public async Task<bool> IsExists(string name) => (await GetItems()).Any(i => i.Name == name);
public void Refresh()
public async Task Refresh()
{
Refreshed?.Invoke(this, EventArgs.Empty);
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<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);
}
}
}