Volume size info for sub content providers
This commit is contained in:
@@ -28,6 +28,6 @@ public interface IContentProvider : IContainer, IOnContainerEnter
|
||||
Task<byte[]?> GetContentAsync(IElement element, int? maxLength = null, CancellationToken cancellationToken = default);
|
||||
Task<bool> CanHandlePathAsync(NativePath path);
|
||||
Task<bool> CanHandlePathAsync(FullName path);
|
||||
VolumeSizeInfo? GetVolumeSizeInfo(FullName path);
|
||||
ValueTask<VolumeSizeInfo?> GetVolumeSizeInfoAsync(FullName path);
|
||||
ValueTask<NativePath?> GetSupportedPathPart(NativePath nativePath);
|
||||
}
|
||||
@@ -176,6 +176,15 @@ public class CopyCommand : CommandBase, ITransportationCommand
|
||||
|
||||
if (item is IContainer container)
|
||||
{
|
||||
try
|
||||
{
|
||||
await container.WaitForLoaded(_cancellationTokenSource.Token);
|
||||
}
|
||||
catch(OperationCanceledException)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (resolvedTarget.Items.All(i => i.Path.GetName() != item.Name))
|
||||
{
|
||||
await copyOperation.CreateContainerAsync(resolvedTarget, container.Name, container.PointInTime);
|
||||
|
||||
@@ -9,6 +9,7 @@ public class DeleteCommand : CommandBase, IExecutableCommand
|
||||
private readonly IContentAccessorFactory _contentAccessorFactory;
|
||||
private readonly ITimelessContentProvider _timelessContentProvider;
|
||||
private readonly ICommandSchedulerNotifier _commandSchedulerNotifier;
|
||||
private readonly CancellationTokenSource _cancellationTokenSource = new();
|
||||
public bool HardDelete { get; set; }
|
||||
public List<FullName> ItemsToDelete { get; } = new();
|
||||
|
||||
@@ -35,10 +36,7 @@ public class DeleteCommand : CommandBase, IExecutableCommand
|
||||
return Task.FromResult(currentTime);
|
||||
}
|
||||
|
||||
public override void Cancel()
|
||||
{
|
||||
//TODO: Implement
|
||||
}
|
||||
public override void Cancel() => _cancellationTokenSource.Cancel();
|
||||
|
||||
public async Task Execute()
|
||||
{
|
||||
@@ -70,6 +68,8 @@ public class DeleteCommand : CommandBase, IExecutableCommand
|
||||
{
|
||||
foreach (var itemToDeleteName in itemsToDelete)
|
||||
{
|
||||
if (_cancellationTokenSource.IsCancellationRequested) return;
|
||||
|
||||
var itemToDelete = await _timelessContentProvider.GetItemByFullNameAsync(itemToDeleteName, currentTime);
|
||||
IItemDeleter? itemDeleter = null;
|
||||
|
||||
@@ -93,6 +93,15 @@ public class DeleteCommand : CommandBase, IExecutableCommand
|
||||
|
||||
if (itemToDelete is IContainer container)
|
||||
{
|
||||
try
|
||||
{
|
||||
await container.WaitForLoaded(_cancellationTokenSource.Token);
|
||||
}
|
||||
catch(OperationCanceledException)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await TraverseTree(
|
||||
currentTime,
|
||||
container.Items.Select(i => i.Path),
|
||||
|
||||
@@ -93,7 +93,7 @@ public abstract class ContentProviderBase : IContentProvider
|
||||
=> path.Path.TrimEnd(Constants.SeparatorChar) == Name
|
||||
|| await CanHandlePathAsync(await GetNativePathAsync(path));
|
||||
|
||||
public abstract VolumeSizeInfo? GetVolumeSizeInfo(FullName path);
|
||||
public abstract ValueTask<VolumeSizeInfo?> GetVolumeSizeInfoAsync(FullName path);
|
||||
|
||||
public IItem WithParent(AbsolutePath parent) => this;
|
||||
public abstract ValueTask<NativePath?> GetSupportedPathPart(NativePath nativePath);
|
||||
|
||||
@@ -6,12 +6,12 @@ internal static class Helper
|
||||
{
|
||||
internal static async Task<ParentElementReaderContext> GetParentElementReaderAsync(
|
||||
IContentAccessorFactory contentAccessorFactory,
|
||||
IElement element,
|
||||
IItem item,
|
||||
IContentProvider parentContentProvider)
|
||||
{
|
||||
var elementNativePath = element.NativePath!;
|
||||
var elementNativePath = item.NativePath!;
|
||||
var supportedPath = (await parentContentProvider.GetSupportedPathPart(elementNativePath))!;
|
||||
var parentElement = (IElement) await parentContentProvider.GetItemByNativePathAsync(supportedPath, element.PointInTime);
|
||||
var parentElement = (IElement) await parentContentProvider.GetItemByNativePathAsync(supportedPath, item.PointInTime);
|
||||
|
||||
var contentReaderFactory = contentAccessorFactory.GetContentReaderFactory(parentElement.Provider);
|
||||
var reader = await contentReaderFactory.CreateContentReaderAsync(parentElement);
|
||||
@@ -19,4 +19,15 @@ internal static class Helper
|
||||
|
||||
return new ParentElementReaderContext(reader, subPath);
|
||||
}
|
||||
|
||||
internal static async Task<IElement> GetParentElementAsync(
|
||||
IItem item,
|
||||
IContentProvider parentContentProvider)
|
||||
{
|
||||
var elementNativePath = item.NativePath!;
|
||||
var supportedPath = (await parentContentProvider.GetSupportedPathPart(elementNativePath))!;
|
||||
var parentElement = (IElement) await parentContentProvider.GetItemByNativePathAsync(supportedPath, item.PointInTime);
|
||||
|
||||
return parentElement;
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public class RootContentProvider : IRootContentProvider
|
||||
public Task<bool> CanHandlePathAsync(NativePath path) => throw new NotImplementedException();
|
||||
|
||||
public Task<bool> CanHandlePathAsync(FullName path) => throw new NotImplementedException();
|
||||
public VolumeSizeInfo? GetVolumeSizeInfo(FullName path) => null;
|
||||
public ValueTask<VolumeSizeInfo?> GetVolumeSizeInfoAsync(FullName path) => ValueTask.FromResult<VolumeSizeInfo?>(null);
|
||||
public ValueTask<NativePath?> GetSupportedPathPart(NativePath nativePath) => throw new NotImplementedException();
|
||||
|
||||
public IItem WithParent(AbsolutePath parent) => this;
|
||||
|
||||
@@ -46,6 +46,9 @@ public abstract class SubContentProviderBase : ContentProviderBase
|
||||
public override async ValueTask<NativePath?> GetSupportedPathPart(NativePath nativePath)
|
||||
=> await ParentContentProvider.GetSupportedPathPart(nativePath);
|
||||
|
||||
protected async Task<ParentElementReaderContext> GetParentElementReaderAsync(IElement element)
|
||||
=> await Helper.GetParentElementReaderAsync(_contentAccessorFactory, element, ParentContentProvider);
|
||||
protected async Task<ParentElementReaderContext> GetParentElementReaderAsync(IItem item)
|
||||
=> await Helper.GetParentElementReaderAsync(_contentAccessorFactory, item, ParentContentProvider);
|
||||
|
||||
protected async Task<IElement> GetParentElementAsync(IItem item)
|
||||
=> await Helper.GetParentElementAsync(item, ParentContentProvider);
|
||||
}
|
||||
@@ -13,6 +13,9 @@ public abstract class SubContentReaderBase<TContentProvider> : IContentReaderFac
|
||||
|
||||
public abstract Task<IContentReader> CreateContentReaderAsync(IElement element);
|
||||
|
||||
protected async Task<ParentElementReaderContext> GetParentElementReaderAsync(IElement element, SubContentProviderBase provider)
|
||||
=> await Helper.GetParentElementReaderAsync(_contentAccessorFactory, element, provider.ParentContentProvider);
|
||||
protected async Task<ParentElementReaderContext> GetParentElementReaderAsync(IItem item, SubContentProviderBase provider)
|
||||
=> await Helper.GetParentElementReaderAsync(_contentAccessorFactory, item, provider.ParentContentProvider);
|
||||
|
||||
protected async Task<IElement> GetParentElementAsync(IItem item, SubContentProviderBase provider)
|
||||
=> await Helper.GetParentElementAsync(item, provider.ParentContentProvider);
|
||||
}
|
||||
Reference in New Issue
Block a user