Copy progress
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
using System.Reactive.Linq;
|
||||||
|
using System.Reactive.Subjects;
|
||||||
using FileTime.Core.Enums;
|
using FileTime.Core.Enums;
|
||||||
using FileTime.Core.Models;
|
using FileTime.Core.Models;
|
||||||
using FileTime.Core.Timeline;
|
using FileTime.Core.Timeline;
|
||||||
@@ -10,13 +12,14 @@ public class CopyCommand : CommandBase, ITransportationCommand
|
|||||||
private readonly ICommandSchedulerNotifier _commandSchedulerNotifier;
|
private readonly ICommandSchedulerNotifier _commandSchedulerNotifier;
|
||||||
|
|
||||||
private readonly List<OperationProgress> _operationProgresses = new();
|
private readonly List<OperationProgress> _operationProgresses = new();
|
||||||
|
private readonly BehaviorSubject<OperationProgress?> _currentOperationProgress = new(null);
|
||||||
|
|
||||||
public IList<FullName> Sources { get; } = new List<FullName>();
|
public IList<FullName> Sources { get; } = new List<FullName>();
|
||||||
|
|
||||||
public FullName? Target { get; set; }
|
public FullName? Target { get; set; }
|
||||||
|
|
||||||
public TransportMode? TransportMode { get; set; } = Command.TransportMode.Merge;
|
public TransportMode? TransportMode { get; set; } = Command.TransportMode.Merge;
|
||||||
public OperationProgress? CurrentOperationProgress { get; private set; }
|
public IObservable<OperationProgress?> CurrentOperationProgress { get; }
|
||||||
|
|
||||||
public CopyCommand(
|
public CopyCommand(
|
||||||
ITimelessContentProvider timelessContentProvider,
|
ITimelessContentProvider timelessContentProvider,
|
||||||
@@ -25,6 +28,7 @@ public class CopyCommand : CommandBase, ITransportationCommand
|
|||||||
{
|
{
|
||||||
_timelessContentProvider = timelessContentProvider;
|
_timelessContentProvider = timelessContentProvider;
|
||||||
_commandSchedulerNotifier = commandSchedulerNotifier;
|
_commandSchedulerNotifier = commandSchedulerNotifier;
|
||||||
|
CurrentOperationProgress = _currentOperationProgress.AsObservable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Task<CanCommandRun> CanRun(PointInTime currentTime)
|
public override Task<CanCommandRun> CanRun(PointInTime currentTime)
|
||||||
@@ -93,6 +97,17 @@ public class CopyCommand : CommandBase, ITransportationCommand
|
|||||||
|
|
||||||
_operationProgresses.Clear();
|
_operationProgresses.Clear();
|
||||||
_operationProgresses.AddRange(calculateOperation.OperationStatuses);
|
_operationProgresses.AddRange(calculateOperation.OperationStatuses);
|
||||||
|
|
||||||
|
_operationProgresses
|
||||||
|
.Select(op => op.Progress.Select(p => (Progress: p, TotalProgress: op.TotalCount)))
|
||||||
|
.CombineLatest()
|
||||||
|
.Select(data =>
|
||||||
|
{
|
||||||
|
var total = data.Sum(d => d.TotalProgress);
|
||||||
|
if (total == 0) return 0;
|
||||||
|
return (int) (data.Sum(d => d.Progress) * 100 / total);
|
||||||
|
})
|
||||||
|
.Subscribe(SetTotalProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task TraverseTree(
|
private async Task TraverseTree(
|
||||||
@@ -128,16 +143,15 @@ public class CopyCommand : CommandBase, ITransportationCommand
|
|||||||
var newElementPath = target.GetChild(newElementName, AbsolutePathType.Element);
|
var newElementPath = target.GetChild(newElementName, AbsolutePathType.Element);
|
||||||
|
|
||||||
var currentProgress = _operationProgresses.Find(o => o.Key == element.FullName!.Path);
|
var currentProgress = _operationProgresses.Find(o => o.Key == element.FullName!.Path);
|
||||||
CurrentOperationProgress = currentProgress;
|
_currentOperationProgress.OnNext(currentProgress);
|
||||||
|
|
||||||
await copyOperation.CopyAsync(new AbsolutePath(_timelessContentProvider, element), newElementPath, new CopyCommandContext(UpdateProgress, currentProgress));
|
await copyOperation.CopyAsync(new AbsolutePath(_timelessContentProvider, element), newElementPath, new CopyCommandContext(UpdateProgress, currentProgress));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task UpdateProgress()
|
private Task UpdateProgress() =>
|
||||||
{
|
//Not used, progress is reactive in this command
|
||||||
//TODO
|
//Note: Maybe this should be removed altogether, and every command should use reactive progress
|
||||||
return Task.CompletedTask;
|
Task.CompletedTask;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ public class StreamCopyCommandHandler : ICommandHandler
|
|||||||
using var writer = await _contentAccessorFactory.GetContentWriterFactory(target.Provider).CreateContentWriterAsync(target);
|
using var writer = await _contentAccessorFactory.GetContentWriterFactory(target.Provider).CreateContentWriterAsync(target);
|
||||||
|
|
||||||
byte[] dataRead;
|
byte[] dataRead;
|
||||||
var currentProgress = 0L;
|
long currentProgress = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user