IconProvider, container exceptions, refactor

This commit is contained in:
2022-02-02 11:02:37 +01:00
parent c4bf417ba3
commit 3e553dd448
31 changed files with 597 additions and 132 deletions

View File

@@ -29,6 +29,7 @@ namespace FileTime.Providers.Local
public bool IsCaseInsensitive { get; }
public bool CanDelete => false;
public bool CanRename => false;
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
public LocalContentProvider(ILogger<LocalContentProvider> logger)
{
@@ -93,5 +94,6 @@ namespace FileTime.Providers.Local
public Task<IReadOnlyList<IElement>?> GetElements(CancellationToken token = default) => Task.FromResult(_elements);
public Task Rename(string newName) => throw new NotSupportedException();
public Task<bool> CanOpen() => Task.FromResult(true);
}
}

View File

@@ -10,6 +10,7 @@ namespace FileTime.Providers.Local
private IReadOnlyList<IItem>? _items;
private IReadOnlyList<IContainer>? _containers;
private IReadOnlyList<IElement>? _elements;
private List<Exception> _exceptions;
private readonly IContainer? _parent;
public bool IsHidden => (Directory.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden;
@@ -30,12 +31,16 @@ namespace FileTime.Providers.Local
public string Attributes => GetAttributes();
public DateTime CreatedAt => Directory.CreationTime;
public IReadOnlyList<Exception> Exceptions { get; }
public LocalFolder(DirectoryInfo directory, LocalContentProvider contentProvider, IContainer? parent)
{
Directory = directory;
_parent = parent;
_exceptions = new List<Exception>();
Exceptions = _exceptions.AsReadOnly();
Name = directory.Name.TrimEnd(Path.DirectorySeparatorChar);
FullName = parent?.FullName == null ? Name : parent.FullName + Constants.SeparatorChar + Name;
Provider = contentProvider;
@@ -49,13 +54,17 @@ namespace FileTime.Providers.Local
{
_containers = new List<IContainer>();
_elements = new List<IElement>();
_exceptions.Clear();
try
{
_containers = Directory.GetDirectories().Select(d => new LocalFolder(d, Provider, this)).OrderBy(d => d.Name).ToList().AsReadOnly();
_elements = Directory.GetFiles().Select(f => new LocalFile(f, this, Provider)).OrderBy(f => f.Name).ToList().AsReadOnly();
}
catch { }
catch (Exception e)
{
_exceptions.Add(e);
}
_items = _containers.Cast<IItem>().Concat(_elements).ToList().AsReadOnly();
Refreshed?.InvokeAsync(this, AsyncEventArgs.Empty);
@@ -144,5 +153,6 @@ namespace FileTime.Providers.Local
+ ((Directory.Attributes & FileAttributes.System) == FileAttributes.System ? "s" : "-");
}
}
public Task<bool> CanOpen() => Task.FromResult(true);
}
}

View File

@@ -25,6 +25,7 @@ namespace FileTime.Providers.Smb
public IContentProvider Provider => this;
public bool CanDelete => false;
public bool CanRename => false;
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
public AsyncEventHandler Refreshed { get; } = new();
@@ -98,5 +99,6 @@ namespace FileTime.Providers.Smb
public Task<IReadOnlyList<IElement>?> GetElements(CancellationToken token = default) => Task.FromResult(_elements);
public Task Rename(string newName) => throw new NotSupportedException();
public Task<bool> CanOpen() => Task.FromResult(true);
}
}

View File

@@ -27,6 +27,7 @@ namespace FileTime.Providers.Smb
public bool CanRename => true;
public AsyncEventHandler Refreshed { get; } = new();
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
public SmbFolder(string name, SmbContentProvider contentProvider, SmbShare smbShare, IContainer parent)
{
@@ -119,5 +120,6 @@ namespace FileTime.Providers.Smb
if (_elements == null) await Refresh();
return _elements;
}
public Task<bool> CanOpen() => Task.FromResult(true);
}
}

View File

@@ -32,8 +32,9 @@ namespace FileTime.Providers.Smb
public SmbContentProvider Provider { get; }
IContentProvider IItem.Provider => Provider;
public bool CanDelete => false;
public bool CanDelete => true;
public bool CanRename => false;
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
public AsyncEventHandler Refreshed { get; } = new();
@@ -186,5 +187,6 @@ namespace FileTime.Providers.Smb
}
public Task Rename(string newName) => throw new NotSupportedException();
public Task<bool> CanOpen() => Task.FromResult(true);
}
}

View File

@@ -27,6 +27,7 @@ namespace FileTime.Providers.Smb
public bool CanRename => false;
public AsyncEventHandler Refreshed { get; } = new();
public IReadOnlyList<Exception> Exceptions { get; } = new List<Exception>().AsReadOnly();
public SmbShare(string name, SmbContentProvider contentProvider, IContainer parent, SmbClientContext smbClientContext)
{
@@ -156,5 +157,6 @@ namespace FileTime.Providers.Smb
}
public Task Rename(string newName) => throw new NotSupportedException();
public Task<bool> CanOpen() => Task.FromResult(true);
}
}