This commit is contained in:
2022-06-09 08:27:51 +02:00
parent 6d9bf7ab32
commit 94e71954ee
21 changed files with 135 additions and 52 deletions

View File

@@ -0,0 +1,6 @@
namespace FileTime.Core.Command;
public interface IRequireInputCommand
{
Task ReadInputs();
}

View File

@@ -1,6 +1,10 @@
using FileTime.Core.Models;
namespace FileTime.Core.Command;
public interface ITransportationCommand : ICommand
{
TransportMode? TransportMode { get; set; }
IList<FullName> Sources { get; }
FullName? Target { get; set; }
}

View File

@@ -1,6 +1,7 @@
namespace FileTime.Core.Interactions;
public interface IInputInterface
public interface IUserCommunicationService
{
Task<bool> ReadInputs(params IInputElement[] fields);
void ShowToastMessage(string text);
}

View File

@@ -1,8 +1,11 @@
using FileTime.Core.Command;
using FileTime.Core.Models;
namespace FileTime.Core.Timeline;
public interface ICommandScheduler
{
Task AddCommand(ICommand command, int? batchId = null, bool toNewBatch = false);
IObservable<FullName> ContainerToRefresh { get; }
void RefreshContainer(FullName container);
}

View File

@@ -0,0 +1,8 @@
using FileTime.Core.Models;
namespace FileTime.Core.Timeline;
public interface ICommandSchedulerNotifier
{
Task RefreshContainer(FullName container);
}

View File

@@ -8,6 +8,7 @@ namespace FileTime.Core.Command.Copy;
public class CopyCommand : ITransportationCommand
{
private readonly ITimelessContentProvider _timelessContentProvider;
private readonly ICommandSchedulerNotifier _commandSchedulerNotifier;
private readonly List<OperationProgress> _operationProgresses = new();
@@ -18,9 +19,12 @@ public class CopyCommand : ITransportationCommand
public TransportMode? TransportMode { get; set; } = Command.TransportMode.Merge;
public OperationProgress? CurrentOperationProgress { get; private set; }
public CopyCommand(ITimelessContentProvider timelessContentProvider)
public CopyCommand(
ITimelessContentProvider timelessContentProvider,
ICommandSchedulerNotifier commandSchedulerNotifier)
{
_timelessContentProvider = timelessContentProvider;
_commandSchedulerNotifier = commandSchedulerNotifier;
}
public Task<CanCommandRun> CanRun(PointInTime currentTime)
@@ -58,7 +62,7 @@ public class CopyCommand : ITransportationCommand
await CalculateProgressAsync(currentTime);
var copyOperation = new CopyStrategy(copy, new CopyStrategyParam(_operationProgresses));
var copyOperation = new CopyStrategy(copy, new CopyStrategyParam(_operationProgresses, _commandSchedulerNotifier.RefreshContainer));
var resolvedTarget = await _timelessContentProvider.GetItemByFullNameAsync(Target, currentTime);
@@ -92,17 +96,17 @@ public class CopyCommand : ITransportationCommand
}
private async Task TraverseTree(
PointInTime curretnTime,
PointInTime currentTime,
IEnumerable<FullName> sources,
AbsolutePath target,
TransportMode transportMode,
ICopyStrategy copyOperation)
{
var resolvedTarget = ((IContainer)await target.ResolveAsync()) ?? throw new Exception();
var resolvedTarget = ((IContainer) await target.ResolveAsync()) ?? throw new Exception();
foreach (var source in sources)
{
var item = await _timelessContentProvider.GetItemByFullNameAsync(source, curretnTime);
var item = await _timelessContentProvider.GetItemByFullNameAsync(source, currentTime);
if (item is IContainer container)
{
@@ -114,7 +118,7 @@ public class CopyCommand : ITransportationCommand
var children = await container.Items.GetItemsAsync();
if (children is null) continue;
await TraverseTree(curretnTime, children.Select(c => c.Path).ToList(), target.GetChild(item.Name, AbsolutePathType.Container), transportMode, copyOperation);
await TraverseTree(currentTime, children.Select(c => c.Path).ToList(), target.GetChild(item.Name, AbsolutePathType.Container), transportMode, copyOperation);
await copyOperation.ContainerCopyDoneAsync(new AbsolutePath(_timelessContentProvider, container));
}
else if (item is IElement element)

View File

@@ -7,10 +7,10 @@ public static class Helper
{
public static async Task<string?> GetNewNameAsync(IContainer resolvedTarget, string name, TransportMode transportMode)
{
var items = await resolvedTarget.Items.GetItemsAsync() ?? throw new NullReferenceException();
var items = (await resolvedTarget.Items.GetItemsAsync() ?? throw new NullReferenceException()).ToList();
var newName = name;
var targetNameExists = resolvedTarget != null && items.Any(i => i.Path.GetName() == newName);
if (transportMode == TransportMode.Merge && resolvedTarget != null)
var targetNameExists = items.Any(i => i.Path.GetName() == newName);
if (transportMode == TransportMode.Merge)
{
for (var i = 0; targetNameExists; i++)
{

View File

@@ -1,19 +1,23 @@
using System.Reactive.Linq;
using System.Reactive.Subjects;
using DynamicData;
using FileTime.Core.Command;
using Microsoft.Extensions.DependencyInjection;
using FileTime.Core.Models;
namespace FileTime.Core.Timeline;
public class CommandScheduler : ICommandScheduler
{
private readonly IServiceProvider _serviceProvider;
private readonly SourceList<ParallelCommands> _commandsToRun = new();
private readonly List<ICommandExecutor> _commandExecutors = new();
private readonly Subject<FullName> _containerToRefresh = new();
private readonly object _guard = new();
private bool _enableRunning = true;
private bool _resourceIsInUse;
public IObservable<FullName> ContainerToRefresh { get; }
public bool EnableRunning
{
get
@@ -26,10 +30,10 @@ public class CommandScheduler : ICommandScheduler
set { RunWithLock(() => _enableRunning = value); }
}
public CommandScheduler(IServiceProvider serviceProvider)
public CommandScheduler(ILocalCommandExecutor localExecutor)
{
_serviceProvider = serviceProvider;
var localExecutor = serviceProvider.GetRequiredService<ILocalCommandExecutor>();
ContainerToRefresh = _containerToRefresh.AsObservable();
localExecutor.CommandFinished += LocalExecutorOnCommandFinished;
_commandExecutors.Add(localExecutor);
}
@@ -74,6 +78,8 @@ public class CommandScheduler : ICommandScheduler
});
}
public void RefreshContainer(FullName container) => _containerToRefresh.OnNext(container);
private void ExecuteCommands()
{
if (!_enableRunning) return;

View File

@@ -0,0 +1,18 @@
using FileTime.Core.Models;
namespace FileTime.Core.Timeline;
public class LocalCommandSchedulerNotifier : ICommandSchedulerNotifier
{
private readonly ICommandScheduler _commandRunner;
public LocalCommandSchedulerNotifier(ICommandScheduler commandRunner)
{
_commandRunner = commandRunner;
}
public Task RefreshContainer(FullName container)
{
_commandRunner.RefreshContainer(container);
return Task.CompletedTask;
}
}