WIP CommandScheduler UI

This commit is contained in:
2023-01-31 23:26:36 +01:00
parent 06a9fc27d7
commit 30ecc6e515
37 changed files with 553 additions and 181 deletions

View File

@@ -0,0 +1,36 @@
using System.Reactive.Linq;
using System.Reactive.Subjects;
using FileTime.Core.Timeline;
namespace FileTime.Core.Command;
public abstract class CommandBase : ICommand
{
private readonly BehaviorSubject<string> _displayLabel;
private readonly BehaviorSubject<int> _totalProgress;
private readonly BehaviorSubject<int> _currentProgress;
public IObservable<string> DisplayLabel { get; }
public IObservable<int> TotalProgress { get; }
public IObservable<int> CurrentProgress { get; }
protected CommandBase(string displayLabel = "", int totalProgress = 0, int currentProgress = 0)
{
_displayLabel = new(displayLabel);
_totalProgress = new(totalProgress);
_currentProgress = new(currentProgress);
DisplayLabel = _displayLabel.AsObservable();
TotalProgress = _totalProgress.AsObservable();
CurrentProgress = _currentProgress.AsObservable();
}
public abstract Task<CanCommandRun> CanRun(PointInTime currentTime);
public abstract Task<PointInTime> SimulateCommand(PointInTime currentTime);
protected void SetDisplayLabel(string displayLabel) => _displayLabel.OnNext(displayLabel);
protected void SetTotalProgress(int totalProgress) => _totalProgress.OnNext(totalProgress);
protected void SetCurrentProgress(int currentProgress) => _currentProgress.OnNext(currentProgress);
}

View File

@@ -5,7 +5,7 @@ using FileTime.Core.Timeline;
namespace FileTime.Core.Command.Copy;
public class CopyCommand : ITransportationCommand
public class CopyCommand : CommandBase, ITransportationCommand
{
private readonly ITimelessContentProvider _timelessContentProvider;
private readonly ICommandSchedulerNotifier _commandSchedulerNotifier;
@@ -22,18 +22,19 @@ public class CopyCommand : ITransportationCommand
public CopyCommand(
ITimelessContentProvider timelessContentProvider,
ICommandSchedulerNotifier commandSchedulerNotifier)
: base("Copy")
{
_timelessContentProvider = timelessContentProvider;
_commandSchedulerNotifier = commandSchedulerNotifier;
}
public Task<CanCommandRun> CanRun(PointInTime currentTime)
public override Task<CanCommandRun> CanRun(PointInTime currentTime)
{
//TODO:
return Task.FromResult(CanCommandRun.True);
}
public async Task<PointInTime> SimulateCommand(PointInTime currentTime)
public override async Task<PointInTime> SimulateCommand(PointInTime currentTime)
{
if (Sources == null) throw new ArgumentException(nameof(Sources) + " can not be null");
if (Target == null) throw new ArgumentException(nameof(Target) + " can not be null");

View File

@@ -7,7 +7,7 @@ using InitableService;
namespace FileTime.Core.Command.Create;
public abstract class CreateItemBase : IExecutableCommand, IInitable<FullName, string>
public abstract class CreateItemBase : CommandBase, IExecutableCommand, IInitable<FullName, string>
{
private readonly ITimelessContentProvider _timelessContentProvider;
private readonly IContentAccessorFactory _contentAccessorFactory;
@@ -17,12 +17,13 @@ public abstract class CreateItemBase : IExecutableCommand, IInitable<FullName, s
protected CreateItemBase(
ITimelessContentProvider timelessContentProvider,
IContentAccessorFactory contentAccessorFactory)
: base("Create")
{
_timelessContentProvider = timelessContentProvider;
_contentAccessorFactory = contentAccessorFactory;
}
public async Task<CanCommandRun> CanRun(PointInTime currentTime)
public override async Task<CanCommandRun> CanRun(PointInTime currentTime)
{
if (Parent is null)
{
@@ -49,7 +50,7 @@ public abstract class CreateItemBase : IExecutableCommand, IInitable<FullName, s
return existingItem switch
{
null => CanCommandRun.True,
{ Type: AbsolutePathType.Container } => CanCommandRun.Forcable,
{Type: AbsolutePathType.Container} => CanCommandRun.Forcable,
_ => CanCommandRun.False
};
}
@@ -60,7 +61,7 @@ public abstract class CreateItemBase : IExecutableCommand, IInitable<FullName, s
return CanCommandRun.False;
}
public Task<PointInTime> SimulateCommand(PointInTime currentTime)
public override Task<PointInTime> SimulateCommand(PointInTime currentTime)
{
if (Parent is null)
{

View File

@@ -5,7 +5,7 @@ using FileTime.Core.Timeline;
namespace FileTime.Core.Command.Delete;
public class DeleteCommand : IExecutableCommand
public class DeleteCommand : CommandBase, IExecutableCommand
{
private readonly IContentAccessorFactory _contentAccessorFactory;
private readonly ITimelessContentProvider _timelessContentProvider;
@@ -15,18 +15,19 @@ public class DeleteCommand : IExecutableCommand
public DeleteCommand(
IContentAccessorFactory contentAccessorFactory,
ITimelessContentProvider timelessContentProvider)
: base("Delete")
{
_contentAccessorFactory = contentAccessorFactory;
_timelessContentProvider = timelessContentProvider;
}
public Task<CanCommandRun> CanRun(PointInTime currentTime)
public override Task<CanCommandRun> CanRun(PointInTime currentTime)
{
//TODO
return Task.FromResult(CanCommandRun.True);
}
public Task<PointInTime> SimulateCommand(PointInTime currentTime)
public override Task<PointInTime> SimulateCommand(PointInTime currentTime)
{
//TODO
return Task.FromResult(currentTime);
@@ -38,8 +39,8 @@ public class DeleteCommand : IExecutableCommand
//Delete
await TraverseTree(
PointInTime.Present,
ItemsToDelete,
PointInTime.Present,
ItemsToDelete,
new Dictionary<string, IItemDeleter>(),
new DeleteStrategy()
);
@@ -69,9 +70,9 @@ public class DeleteCommand : IExecutableCommand
if (itemToDelete is IContainer container)
{
await TraverseTree(
currentTime,
(await container.Items.GetItemsAsync())?.Select(i => i.Path) ?? Enumerable.Empty<FullName>(),
itemDeleters,
currentTime,
(await container.Items.GetItemsAsync())?.Select(i => i.Path) ?? Enumerable.Empty<FullName>(),
itemDeleters,
deleteStrategy
);
}