Optimization, UI improvements, Run command

This commit is contained in:
2022-02-05 00:04:27 +01:00
parent bca940372a
commit c061f658aa
31 changed files with 579 additions and 212 deletions

View File

@@ -33,6 +33,8 @@ namespace FileTime.Providers.Local
public bool SupportsDirectoryLevelSoftDelete => false;
public bool IsDisposed => false;
public LocalContentProvider(ILogger<LocalContentProvider> logger)
{
_logger = logger;
@@ -100,5 +102,7 @@ namespace FileTime.Providers.Local
public Task Rename(string newName) => throw new NotSupportedException();
public Task<bool> CanOpen() => Task.FromResult(true);
public void Dispose() { }
}
}

View File

@@ -30,6 +30,8 @@ namespace FileTime.Providers.Local
private readonly LocalFolder _parent;
public bool IsDisposed { get; private set; }
public LocalFile(FileInfo file, LocalFolder parent, IContentProvider contentProvider)
{
_parent = parent;
@@ -80,5 +82,10 @@ namespace FileTime.Providers.Local
}
public IContainer? GetParent() => _parent;
public async Task<string> GetContent(CancellationToken token = default) => await System.IO.File.ReadAllTextAsync(File.FullName, token);
public Task<long> GetElementSize(CancellationToken token = default) => Task.FromResult(File.Length);
public void Dispose() => IsDisposed = true;
}
}

View File

@@ -11,7 +11,7 @@ namespace FileTime.Providers.Local
private IReadOnlyList<IItem>? _items;
private IReadOnlyList<IContainer>? _containers;
private IReadOnlyList<IElement>? _elements;
private List<Exception> _exceptions;
private readonly List<Exception> _exceptions;
private readonly IContainer? _parent;
public bool IsHidden => (Directory.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
@@ -34,6 +34,8 @@ namespace FileTime.Providers.Local
public DateTime CreatedAt => Directory.CreationTime;
public IReadOnlyList<Exception> Exceptions { get; }
public bool IsDisposed { get; private set; }
public bool SupportsDirectoryLevelSoftDelete { get; }
public LocalFolder(DirectoryInfo directory, LocalContentProvider contentProvider, IContainer? parent)
@@ -59,8 +61,16 @@ namespace FileTime.Providers.Local
public Task<IContainer> Clone() => Task.FromResult((IContainer)new LocalFolder(Directory, Provider, _parent));
public Task RefreshAsync(CancellationToken token = default)
public async Task RefreshAsync(CancellationToken token = default)
{
if (_items != null)
{
foreach (var item in _items)
{
item.Dispose();
}
}
_containers = new List<IContainer>();
_elements = new List<IElement>();
_items = new List<IItem>();
@@ -68,13 +78,13 @@ namespace FileTime.Providers.Local
try
{
if (token.IsCancellationRequested) return Task.CompletedTask;
if (token.IsCancellationRequested) return;
_containers = Directory.GetDirectories().Select(d => new LocalFolder(d, Provider, this)).OrderBy(d => d.Name).ToList().AsReadOnly();
if (token.IsCancellationRequested) return Task.CompletedTask;
if (token.IsCancellationRequested) return;
_elements = Directory.GetFiles().Select(f => new LocalFile(f, this, Provider)).OrderBy(f => f.Name).ToList().AsReadOnly();
if (token.IsCancellationRequested) return Task.CompletedTask;
if (token.IsCancellationRequested) return;
}
catch (Exception e)
{
@@ -82,9 +92,7 @@ namespace FileTime.Providers.Local
}
_items = _containers.Cast<IItem>().Concat(_elements).ToList().AsReadOnly();
Refreshed?.InvokeAsync(this, AsyncEventArgs.Empty, token);
return Task.CompletedTask;
if (Refreshed != null) await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty, token);
}
public async Task<IReadOnlyList<IItem>?> GetItems(CancellationToken token = default)
@@ -176,5 +184,13 @@ namespace FileTime.Providers.Local
}
}
public Task<bool> CanOpen() => Task.FromResult(true);
public void Dispose()
{
_items = null;
_containers = null;
_elements = null;
IsDisposed = true;
}
}
}

View File

@@ -31,6 +31,8 @@ namespace FileTime.Providers.Smb
public bool SupportsDirectoryLevelSoftDelete => false;
public bool IsDisposed => false;
public SmbContentProvider(IInputInterface inputInterface)
{
_rootContainers = new List<IContainer>();
@@ -102,5 +104,7 @@ namespace FileTime.Providers.Smb
public Task Rename(string newName) => throw new NotSupportedException();
public Task<bool> CanOpen() => Task.FromResult(true);
public void Dispose() { }
}
}

View File

@@ -19,6 +19,8 @@ namespace FileTime.Providers.Smb
public IContentProvider Provider { get; }
private IContainer _parent;
public bool IsDisposed { get; private set; }
public SmbFile(string name, SmbContentProvider provider, IContainer parent)
{
Name = name;
@@ -43,5 +45,9 @@ namespace FileTime.Providers.Smb
}
public IContainer? GetParent() => _parent;
public Task<string> GetContent(CancellationToken token = default) => Task.FromResult("NotImplemented");
public Task<long> GetElementSize(CancellationToken token = default) => Task.FromResult(-1L);
public void Dispose() => IsDisposed = true;
}
}

View File

@@ -29,6 +29,8 @@ namespace FileTime.Providers.Smb
public AsyncEventHandler Refreshed { get; } = new();
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
public bool IsDisposed { get; private set; }
public bool SupportsDirectoryLevelSoftDelete => false;
public SmbFolder(string name, SmbContentProvider contentProvider, SmbShare smbShare, IContainer parent)
@@ -103,6 +105,14 @@ namespace FileTime.Providers.Smb
_containers = containers.AsReadOnly();
_elements = elements.AsReadOnly();
if (_items != null)
{
foreach (var item in _items)
{
item.Dispose();
}
}
_items = _containers.Cast<IItem>().Concat(_elements).ToList().AsReadOnly();
await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty, token);
}
@@ -123,5 +133,7 @@ namespace FileTime.Providers.Smb
return _elements;
}
public Task<bool> CanOpen() => Task.FromResult(true);
public void Dispose() => IsDisposed = true;
}
}

View File

@@ -40,6 +40,8 @@ namespace FileTime.Providers.Smb
public bool SupportsDirectoryLevelSoftDelete => false;
public bool IsDisposed => false;
public SmbServer(string path, SmbContentProvider contentProvider, IInputInterface inputInterface)
{
_inputInterface = inputInterface;
@@ -97,7 +99,7 @@ namespace FileTime.Providers.Smb
_shares = shares.ConvertAll(s => new SmbShare(s, Provider, this, _smbClientContext)).AsReadOnly();
_items = _shares.Cast<IItem>().ToList().AsReadOnly();
await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty);
await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty, token);
}
public Task<IContainer> Clone() => Task.FromResult((IContainer)this);
@@ -190,5 +192,7 @@ namespace FileTime.Providers.Smb
public Task Rename(string newName) => throw new NotSupportedException();
public Task<bool> CanOpen() => Task.FromResult(true);
public void Dispose() { }
}
}

View File

@@ -29,6 +29,8 @@ namespace FileTime.Providers.Smb
public AsyncEventHandler Refreshed { get; } = new();
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
public bool IsDisposed => false;
public bool SupportsDirectoryLevelSoftDelete => false;
public SmbShare(string name, SmbContentProvider contentProvider, IContainer parent, SmbClientContext smbClientContext)
@@ -111,6 +113,14 @@ namespace FileTime.Providers.Smb
}
catch { }
if (_items != null)
{
foreach (var item in _items)
{
item.Dispose();
}
}
_containers = containers.AsReadOnly();
_elements = elements.AsReadOnly();
@@ -160,5 +170,7 @@ namespace FileTime.Providers.Smb
public Task Rename(string newName) => throw new NotSupportedException();
public Task<bool> CanOpen() => Task.FromResult(true);
public void Dispose() { }
}
}