Frequency navigation WIP

This commit is contained in:
2023-02-24 22:05:13 +01:00
parent 188b9593ce
commit 3d057f947a
34 changed files with 576 additions and 42 deletions

View File

@@ -76,11 +76,11 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
{
if ((path?.Length ?? 0) == 0)
{
return Task.FromResult((IItem)this);
return Task.FromResult((IItem) this);
}
else if (Directory.Exists(path))
{
return Task.FromResult((IItem)DirectoryToContainer(
return Task.FromResult((IItem) DirectoryToContainer(
new DirectoryInfo(path!.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar),
pointInTime,
!itemInitializationSettings.SkipChildInitialization)
@@ -88,7 +88,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
}
else if (File.Exists(path))
{
return Task.FromResult((IItem)FileToElement(new FileInfo(path), pointInTime));
return Task.FromResult((IItem) FileToElement(new FileInfo(path), pointInTime));
}
var type = forceResolvePathType switch
@@ -120,10 +120,10 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
return forceResolvePathType switch
{
AbsolutePathType.Container => Task.FromResult(
(IItem)CreateEmptyContainer(
(IItem) CreateEmptyContainer(
nativePath,
pointInTime,
Observable.Return(new List<Exception>() { innerException })
new List<Exception>() {innerException}
)
),
AbsolutePathType.Element => Task.FromResult(CreateEmptyElement(nativePath)),
@@ -135,9 +135,14 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
private Container CreateEmptyContainer(NativePath nativePath,
PointInTime pointInTime,
IObservable<IEnumerable<Exception>>? exceptions = null)
IEnumerable<Exception>? initialExceptions = null)
{
var nonNullExceptions = exceptions ?? Observable.Return(Enumerable.Empty<Exception>());
var exceptions = new SourceList<Exception>();
if (initialExceptions is not null)
{
exceptions.AddRange(initialExceptions);
}
var name = nativePath.Path.Split(Path.DirectorySeparatorChar).LastOrDefault() ?? "???";
var fullName = GetFullName(nativePath);
@@ -166,7 +171,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
this,
true,
pointInTime,
nonNullExceptions,
exceptions.Connect(),
new ExtensionCollection().AsReadOnly(),
Observable.Return<IObservable<IChangeSet<AbsolutePath, string>>?>(null)
);
@@ -202,7 +207,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
pointInTime,
parentFullName,
AbsolutePathType.Container);
var exceptions = new BehaviorSubject<IEnumerable<Exception>>(Enumerable.Empty<Exception>());
var exceptions = new SourceList<Exception>();
var children = new SourceCache<AbsolutePath, string>(i => i.Path.Path);
@@ -221,14 +226,14 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
this,
true,
pointInTime,
exceptions,
exceptions.Connect(),
new ExtensionCollection().AsReadOnly(),
//Observable.FromAsync(async () => await Task.Run(InitChildrenHelper)
//Observable.Return(InitChildren())
Observable.Return(children.Connect())
);
Task.Run(() => LoadChildren(container, directoryInfo, children, pointInTime));
Task.Run(() => LoadChildren(container, directoryInfo, children, pointInTime, exceptions));
return container;
@@ -241,25 +246,25 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
var items = GetItemsByContainer(directoryInfo, pointInTime);
var result = new SourceCache<AbsolutePath, string>(i => i.Path.Path);
if (items.Count == 0) return (IObservable<IChangeSet<AbsolutePath, string>>?)result.Connect().StartWithEmpty();
if (items.Count == 0) return (IObservable<IChangeSet<AbsolutePath, string>>?) result.Connect().StartWithEmpty();
result.AddOrUpdate(items);
return (IObservable<IChangeSet<AbsolutePath, string>>?)result.Connect();
return (IObservable<IChangeSet<AbsolutePath, string>>?) result.Connect();
}
catch (Exception e)
{
exceptions.OnNext(new List<Exception> { e });
exceptions.Add(e);
}
return null;
}
}
private void LoadChildren(
Container container,
private void LoadChildren(Container container,
DirectoryInfo directoryInfo,
SourceCache<AbsolutePath, string> children,
PointInTime pointInTime)
PointInTime pointInTime,
SourceList<Exception> exceptions)
{
var lockobj = new object();
var loadingIndicatorCancellation = new CancellationTokenSource();
@@ -275,18 +280,25 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
void LoadChildren()
{
foreach (var directory in directoryInfo.EnumerateDirectories())
try
{
if (container.LoadingCancellationToken.IsCancellationRequested) break;
var absolutePath = DirectoryToAbsolutePath(directory, pointInTime);
children.AddOrUpdate(absolutePath);
}
foreach (var directory in directoryInfo.EnumerateDirectories())
{
if (container.LoadingCancellationToken.IsCancellationRequested) break;
var absolutePath = DirectoryToAbsolutePath(directory, pointInTime);
children.AddOrUpdate(absolutePath);
}
foreach (var file in directoryInfo.EnumerateFiles())
foreach (var file in directoryInfo.EnumerateFiles())
{
if (container.LoadingCancellationToken.IsCancellationRequested) break;
var absolutePath = FileToAbsolutePath(file, pointInTime);
children.AddOrUpdate(absolutePath);
}
}
catch (Exception e)
{
if (container.LoadingCancellationToken.IsCancellationRequested) break;
var absolutePath = FileToAbsolutePath(file, pointInTime);
children.AddOrUpdate(absolutePath);
exceptions.Add(e);
}
}
@@ -297,7 +309,9 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
{
await Task.Delay(500, token);
}
catch { }
catch
{
}
lock (lockobj)
{
@@ -345,7 +359,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
GetFileAttributes(fileInfo),
this,
pointInTime,
Observable.Return(Enumerable.Empty<Exception>()),
new SourceList<Exception>().Connect(),
extensions.AsReadOnly()
);
}
@@ -357,8 +371,8 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
private FullName GetFullName(string nativePath) =>
FullName.CreateSafe((Name + Constants.SeparatorChar +
string.Join(Constants.SeparatorChar,
nativePath.TrimStart(Constants.SeparatorChar).Split(Path.DirectorySeparatorChar)))
string.Join(Constants.SeparatorChar,
nativePath.TrimStart(Constants.SeparatorChar).Split(Path.DirectorySeparatorChar)))
.TrimEnd(Constants.SeparatorChar))!;
public override NativePath GetNativePath(FullName fullName)
@@ -385,7 +399,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
var size = maxLength ?? realFileSize switch
{
> int.MaxValue => int.MaxValue,
_ => (int)realFileSize
_ => (int) realFileSize
};
var buffer = new byte[size];
await reader.ReadAsync(buffer.AsMemory(0, size), cancellationToken);