Sftp, fullname+nativepath refactor
This commit is contained in:
@@ -61,7 +61,6 @@ namespace FileTime.Core.Components
|
||||
{
|
||||
if (_currentlySelecting) return false;
|
||||
|
||||
if (_currentSelectedItem == value) return false;
|
||||
IItem? itemToSelect = null;
|
||||
if (value != null)
|
||||
{
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace FileTime.Core.Models
|
||||
Task RefreshAsync(CancellationToken token = default);
|
||||
async Task<IItem?> GetByPath(string path, bool acceptDeepestMatch = false)
|
||||
{
|
||||
if (path == null) return this;
|
||||
var paths = path.Split(Constants.SeparatorChar);
|
||||
|
||||
var item = (await GetItems())?.FirstOrDefault(i => i.Name == paths[0]);
|
||||
|
||||
134
src/Core/FileTime.Core/Providers/AbstractContainer.cs
Normal file
134
src/Core/FileTime.Core/Providers/AbstractContainer.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using AsyncEvent;
|
||||
using FileTime.Core.Models;
|
||||
|
||||
namespace FileTime.Core.Providers
|
||||
{
|
||||
public abstract class AbstractContainer<TProvider> : IContainer where TProvider : IContentProvider
|
||||
{
|
||||
private readonly IContainer _parent;
|
||||
private readonly List<Exception> _exceptions = new();
|
||||
private IReadOnlyList<IContainer>? _containers;
|
||||
private IReadOnlyList<IItem>? _items;
|
||||
private IReadOnlyList<IElement>? _elements;
|
||||
|
||||
public IReadOnlyList<Exception> Exceptions { get; }
|
||||
|
||||
public bool IsLoaded { get; protected set; }
|
||||
|
||||
public bool SupportsDirectoryLevelSoftDelete { get; protected set; }
|
||||
|
||||
public AsyncEventHandler Refreshed { get; protected set; } = new();
|
||||
|
||||
public string Name { get; protected set; }
|
||||
|
||||
public string? FullName { get; protected set; }
|
||||
|
||||
public string? NativePath { get; protected set; }
|
||||
|
||||
public virtual bool IsHidden { get; protected set; }
|
||||
|
||||
public bool IsDestroyed { get; protected set; }
|
||||
|
||||
public virtual SupportsDelete CanDelete { get; protected set; }
|
||||
|
||||
public virtual bool CanRename { get; protected set; }
|
||||
|
||||
public TProvider Provider { get; }
|
||||
|
||||
IContentProvider IItem.Provider => Provider;
|
||||
|
||||
protected AbstractContainer(TProvider provider, IContainer parent, string name)
|
||||
{
|
||||
_parent = parent;
|
||||
Provider = provider;
|
||||
Name = name;
|
||||
FullName = (parent?.FullName ?? Name) + Constants.SeparatorChar + Name;
|
||||
Exceptions = _exceptions.AsReadOnly();
|
||||
}
|
||||
|
||||
public abstract Task<bool> CanOpenAsync();
|
||||
|
||||
public abstract Task<IContainer> CloneAsync();
|
||||
|
||||
public abstract Task<IContainer> CreateContainerAsync(string name);
|
||||
|
||||
public abstract Task<IElement> CreateElementAsync(string name);
|
||||
|
||||
public abstract Task Delete(bool hardDelete = false);
|
||||
|
||||
public virtual void Destroy()
|
||||
{
|
||||
_items = null;
|
||||
_containers = null;
|
||||
_elements = null;
|
||||
IsDestroyed = true;
|
||||
Refreshed = new AsyncEventHandler();
|
||||
}
|
||||
|
||||
public virtual async Task<IReadOnlyList<IContainer>?> GetContainers(CancellationToken token = default)
|
||||
{
|
||||
if (_containers == null) await RefreshAsync(token);
|
||||
return _containers;
|
||||
}
|
||||
|
||||
public virtual async Task<IReadOnlyList<IElement>?> GetElements(CancellationToken token = default)
|
||||
{
|
||||
if (_elements == null) await RefreshAsync(token);
|
||||
return _elements;
|
||||
}
|
||||
|
||||
public virtual async Task<IReadOnlyList<IItem>?> GetItems(CancellationToken token = default)
|
||||
{
|
||||
if (_items == null) await RefreshAsync(token);
|
||||
return _items;
|
||||
}
|
||||
|
||||
public virtual IContainer? GetParent() => _parent;
|
||||
|
||||
public virtual async Task<bool> IsExistsAsync(string name)
|
||||
{
|
||||
var items = await GetItems();
|
||||
return items?.Any(i => i.Name == name) ?? false;
|
||||
}
|
||||
|
||||
public virtual async Task RefreshAsync(CancellationToken token = default)
|
||||
{
|
||||
var containers = new List<IContainer>();
|
||||
var elements = new List<IElement>();
|
||||
foreach (var item in await RefreshItems(token))
|
||||
{
|
||||
if (item is IContainer container)
|
||||
{
|
||||
containers.Add(container);
|
||||
}
|
||||
else if (item is IElement element)
|
||||
{
|
||||
elements.Add(element);
|
||||
}
|
||||
}
|
||||
|
||||
if (_items != null)
|
||||
{
|
||||
foreach (var item in _items)
|
||||
{
|
||||
item.Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
_containers = containers.OrderBy(c => c.Name).ToList().AsReadOnly();
|
||||
_elements = elements.OrderBy(e => e.Name).ToList().AsReadOnly();
|
||||
_items = _containers.Cast<IItem>().Concat(_elements).ToList().AsReadOnly();
|
||||
if (Refreshed != null) await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty, token);
|
||||
}
|
||||
public abstract Task<IEnumerable<IItem>> RefreshItems(CancellationToken token = default);
|
||||
|
||||
public abstract Task Rename(string newName);
|
||||
|
||||
public virtual void Unload()
|
||||
{
|
||||
_items = null;
|
||||
_containers = null;
|
||||
_elements = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace FileTime.Core.Providers
|
||||
public interface IContentProvider : IContainer
|
||||
{
|
||||
bool SupportsContentStreams { get; }
|
||||
string Protocol { get; }
|
||||
|
||||
Task<IReadOnlyList<IContainer>> GetRootContainers(CancellationToken token = default);
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ namespace FileTime.Core.Timeline
|
||||
public bool IsDestroyed => false;
|
||||
public bool SupportsContentStreams => false;
|
||||
|
||||
public string Protocol => "time2://";
|
||||
|
||||
public TimeProvider(PointInTime pointInTime)
|
||||
{
|
||||
_pointInTime = pointInTime;
|
||||
|
||||
Reference in New Issue
Block a user