Copy
This commit is contained in:
@@ -10,8 +10,8 @@ using FileTime.Core.Interactions;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Timeline;
|
||||
using InitableService;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using CopyCommand = FileTime.Core.Command.Copy.CopyCommand;
|
||||
|
||||
namespace FileTime.App.Core.Services.UserCommandHandler;
|
||||
|
||||
@@ -21,7 +21,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
||||
private IItemViewModel? _currentSelectedItem;
|
||||
private readonly IUserCommandHandlerService _userCommandHandlerService;
|
||||
private readonly IClipboardService _clipboardService;
|
||||
private readonly IInputInterface _inputInterface;
|
||||
private readonly IUserCommunicationService _userCommunicationService;
|
||||
private readonly ILogger<ItemManipulationUserCommandHandlerService> _logger;
|
||||
private readonly ICommandScheduler _commandScheduler;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
@@ -32,7 +32,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
||||
IAppState appState,
|
||||
IUserCommandHandlerService userCommandHandlerService,
|
||||
IClipboardService clipboardService,
|
||||
IInputInterface inputInterface,
|
||||
IUserCommunicationService userCommunicationService,
|
||||
ILogger<ItemManipulationUserCommandHandlerService> logger,
|
||||
ITimelessContentProvider timelessContentProvider,
|
||||
ICommandScheduler commandScheduler,
|
||||
@@ -40,7 +40,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
||||
{
|
||||
_userCommandHandlerService = userCommandHandlerService;
|
||||
_clipboardService = clipboardService;
|
||||
_inputInterface = inputInterface;
|
||||
_userCommunicationService = userCommunicationService;
|
||||
_logger = logger;
|
||||
_commandScheduler = commandScheduler;
|
||||
_serviceProvider = serviceProvider;
|
||||
@@ -72,7 +72,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
||||
private Task Copy()
|
||||
{
|
||||
_clipboardService.Clear();
|
||||
_clipboardService.SetCommand<CopyCommand>();
|
||||
_clipboardService.SetCommand<FileTime.Core.Command.Copy.CopyCommand>();
|
||||
|
||||
if ((_markedItems?.Collection?.Count ?? 0) > 0)
|
||||
{
|
||||
@@ -120,17 +120,38 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
||||
await Paste(TransportMode.Skip);
|
||||
}
|
||||
|
||||
private Task Paste(TransportMode skip)
|
||||
private async Task Paste(TransportMode mode)
|
||||
{
|
||||
if (_clipboardService.CommandType is null) return Task.CompletedTask;
|
||||
return Task.CompletedTask;
|
||||
if (_clipboardService.CommandType is null)
|
||||
{
|
||||
_userCommunicationService.ShowToastMessage("Clipboard is empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
var command = (ITransportationCommand) _serviceProvider.GetRequiredService(_clipboardService.CommandType);
|
||||
command.TransportMode = mode;
|
||||
|
||||
command.Sources.Clear();
|
||||
|
||||
foreach (var item in _clipboardService.Content)
|
||||
{
|
||||
command.Sources.Add(item);
|
||||
}
|
||||
|
||||
command.Target = _currentLocation?.FullName;
|
||||
|
||||
_clipboardService.Clear();
|
||||
|
||||
if (command is IRequireInputCommand requireInput) await requireInput.ReadInputs();
|
||||
|
||||
await AddCommand(command);
|
||||
}
|
||||
|
||||
private async Task CreateContainer()
|
||||
{
|
||||
var containerNameInput = new TextInputElement("Container name");
|
||||
|
||||
await _inputInterface.ReadInputs(containerNameInput);
|
||||
await _userCommunicationService.ReadInputs(containerNameInput);
|
||||
|
||||
//TODO: message on empty result
|
||||
var newContainerName = containerNameInput.Value;
|
||||
@@ -140,14 +161,14 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
||||
var command = _serviceProvider
|
||||
.GetInitableResolver(_currentLocation.FullName, newContainerName)
|
||||
.GetRequiredService<CreateContainerCommand>();
|
||||
await _commandScheduler.AddCommand(command);
|
||||
await AddCommand(command);
|
||||
}
|
||||
|
||||
private async Task CreateElement()
|
||||
{
|
||||
var containerNameInput = new TextInputElement("Element name");
|
||||
|
||||
await _inputInterface.ReadInputs(containerNameInput);
|
||||
await _userCommunicationService.ReadInputs(containerNameInput);
|
||||
|
||||
//TODO: message on empty result
|
||||
var newContainerName = containerNameInput.Value;
|
||||
@@ -157,6 +178,11 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
||||
var command = _serviceProvider
|
||||
.GetInitableResolver(_currentLocation.FullName, newContainerName)
|
||||
.GetRequiredService<CreateElementCommand>();
|
||||
await AddCommand(command);
|
||||
}
|
||||
|
||||
private async Task AddCommand(ICommand command)
|
||||
{
|
||||
await _commandScheduler.AddCommand(command);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
private readonly ILocalContentProvider _localContentProvider;
|
||||
private readonly IUserCommandHandlerService _userCommandHandlerService;
|
||||
private readonly ITimelessContentProvider _timelessContentProvider;
|
||||
private readonly IInputInterface _inputInterface;
|
||||
private readonly IUserCommunicationService _userCommunicationService;
|
||||
private ITabViewModel? _selectedTab;
|
||||
private IContainer? _currentLocation;
|
||||
private IItemViewModel? _currentSelectedItem;
|
||||
@@ -32,14 +32,14 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
ILocalContentProvider localContentProvider,
|
||||
IUserCommandHandlerService userCommandHandlerService,
|
||||
ITimelessContentProvider timelessContentProvider,
|
||||
IInputInterface inputInterface) : base(appState)
|
||||
IUserCommunicationService userCommunicationService) : base(appState)
|
||||
{
|
||||
_appState = appState;
|
||||
_serviceProvider = serviceProvider;
|
||||
_localContentProvider = localContentProvider;
|
||||
_userCommandHandlerService = userCommandHandlerService;
|
||||
_timelessContentProvider = timelessContentProvider;
|
||||
_inputInterface = inputInterface;
|
||||
_userCommunicationService = userCommunicationService;
|
||||
|
||||
SaveSelectedTab(t => _selectedTab = t);
|
||||
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
|
||||
@@ -74,7 +74,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
private async Task GoToPath()
|
||||
{
|
||||
var pathInput = new TextInputElement("Path");
|
||||
await _inputInterface.ReadInputs(pathInput);
|
||||
await _userCommunicationService.ReadInputs(pathInput);
|
||||
|
||||
//TODO: message on empty result and on null pathInput.Value
|
||||
var resolvedPath = await _timelessContentProvider.GetItemByNativePathAsync(new NativePath(pathInput.Value));
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using DynamicData;
|
||||
using FileTime.App.Core.Models.Enums;
|
||||
using FileTime.Core.Timeline;
|
||||
using MvvmGen;
|
||||
using MoreLinq;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using FileTime.App.Core.Models;
|
||||
using FileTime.App.Core.Models.Enums;
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Models.Extensions;
|
||||
using MvvmGen;
|
||||
|
||||
namespace FileTime.App.Core.ViewModels;
|
||||
|
||||
@@ -4,11 +4,10 @@ using FileTime.App.Core.Extensions;
|
||||
using FileTime.App.Core.Models;
|
||||
using FileTime.App.Core.Models.Enums;
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.App.Core.ViewModels.ItemPreview;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Models.Extensions;
|
||||
using FileTime.Core.Services;
|
||||
using InitableService;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using MvvmGen;
|
||||
|
||||
namespace FileTime.App.Core.ViewModels;
|
||||
|
||||
@@ -3,6 +3,7 @@ using FileTime.App.Core.Models;
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.App.Core.Services.Persistence;
|
||||
using FileTime.Core.Command;
|
||||
using FileTime.Core.Command.Copy;
|
||||
using FileTime.Core.Command.CreateContainer;
|
||||
using FileTime.Core.Command.CreateElement;
|
||||
using FileTime.Core.CommandHandlers;
|
||||
@@ -25,7 +26,11 @@ public static class DependencyInjection
|
||||
serviceCollection.TryAddSingleton<ITimelessContentProvider, TimelessContentProvider>();
|
||||
serviceCollection.TryAddSingleton<ICommandRunner, CommandRunner>();
|
||||
serviceCollection.TryAddSingleton<IContentAccessorFactory, ContentAccessorFactory>();
|
||||
serviceCollection.TryAddSingleton<IContentProviderRegistry, ContentProviderRegistry>();
|
||||
//TODO: check local/remote context
|
||||
serviceCollection.TryAddSingleton<ILocalCommandExecutor, LocalCommandExecutor>();
|
||||
serviceCollection.TryAddSingleton<ICommandSchedulerNotifier, LocalCommandSchedulerNotifier>();
|
||||
|
||||
serviceCollection.TryAddSingleton<IApplicationSettings, ApplicationSettings>();
|
||||
serviceCollection.TryAddSingleton<ITabPersistenceService, TabPersistenceService>();
|
||||
serviceCollection.TryAddTransient<ITab, Tab>();
|
||||
@@ -43,6 +48,7 @@ public static class DependencyInjection
|
||||
{
|
||||
return serviceCollection
|
||||
.AddTransient<CreateContainerCommand>()
|
||||
.AddTransient<CreateElementCommand>();
|
||||
.AddTransient<CreateElementCommand>()
|
||||
.AddTransient<CopyCommand>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace FileTime.Core.Command;
|
||||
|
||||
public interface IRequireInputCommand
|
||||
{
|
||||
Task ReadInputs();
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace FileTime.Core.Interactions;
|
||||
|
||||
public interface IInputInterface
|
||||
public interface IUserCommunicationService
|
||||
{
|
||||
Task<bool> ReadInputs(params IInputElement[] fields);
|
||||
void ShowToastMessage(string text);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using FileTime.Core.Models;
|
||||
|
||||
namespace FileTime.Core.Timeline;
|
||||
|
||||
public interface ICommandSchedulerNotifier
|
||||
{
|
||||
Task RefreshContainer(FullName container);
|
||||
}
|
||||
@@ -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,7 +96,7 @@ public class CopyCommand : ITransportationCommand
|
||||
}
|
||||
|
||||
private async Task TraverseTree(
|
||||
PointInTime curretnTime,
|
||||
PointInTime currentTime,
|
||||
IEnumerable<FullName> sources,
|
||||
AbsolutePath target,
|
||||
TransportMode transportMode,
|
||||
@@ -102,7 +106,7 @@ public class CopyCommand : ITransportationCommand
|
||||
|
||||
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)
|
||||
|
||||
@@ -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++)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,8 @@ using FileTime.GuiApp.ViewModels;
|
||||
|
||||
namespace FileTime.GuiApp.Services;
|
||||
|
||||
public interface IDialogService : IInputInterface
|
||||
public interface IDialogService : IUserCommunicationService
|
||||
{
|
||||
IObservable<ReadInputsViewModel?> ReadInput { get; }
|
||||
void ReadInputs(IEnumerable<IInputElement> inputs, Action inputHandler, Action? cancelHandler = null);
|
||||
void ShowToastMessage(string text);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public static class Startup
|
||||
serviceCollection.TryAddSingleton<IDialogService, DialogService>();
|
||||
serviceCollection.TryAddSingleton<ISystemClipboardService, SystemClipboardService>();
|
||||
serviceCollection.TryAddSingleton<ToastMessageSink>();
|
||||
serviceCollection.TryAddSingleton<IInputInterface>(s => s.GetRequiredService<IDialogService>());
|
||||
serviceCollection.TryAddSingleton<IUserCommunicationService>(s => s.GetRequiredService<IDialogService>());
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@ using FileTime.Core.Models.Extensions;
|
||||
using FileTime.Core.Timeline;
|
||||
|
||||
namespace FileTime.Providers.Local;
|
||||
|
||||
public sealed partial class LocalContentProvider : ContentProviderBase, ILocalContentProvider
|
||||
{
|
||||
private readonly ITimelessContentProvider _timelessContentProvider;
|
||||
@@ -234,14 +235,17 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
|
||||
|
||||
Task<IObservable<IChangeSet<AbsolutePath, string>>?> InitChildren()
|
||||
{
|
||||
SourceCache<AbsolutePath, string>? result = null;
|
||||
try
|
||||
{
|
||||
var items = initializeChildren ? (List<AbsolutePath>?) GetItemsByContainer(directoryInfo, pointInTime) : null;
|
||||
if (items != null)
|
||||
{
|
||||
result = new SourceCache<AbsolutePath, string>(i => i.Path.Path);
|
||||
var result = new SourceCache<AbsolutePath, string>(i => i.Path.Path);
|
||||
|
||||
if (items.Count == 0) return Task.FromResult((IObservable<IChangeSet<AbsolutePath, string>>?) result.Connect().StartWithEmpty());
|
||||
|
||||
result.AddOrUpdate(items);
|
||||
return Task.FromResult((IObservable<IChangeSet<AbsolutePath, string>>?) result.Connect());
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -249,7 +253,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
|
||||
exceptions.OnNext(new List<Exception>() {e});
|
||||
}
|
||||
|
||||
return Task.FromResult(result?.Connect());
|
||||
return Task.FromResult((IObservable<IChangeSet<AbsolutePath, string>>?) null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,5 +6,5 @@ namespace FileTime.Providers.Local;
|
||||
public class LocalContentWriterFactory : IContentWriterFactory<ILocalContentProvider>
|
||||
{
|
||||
public Task<IContentWriter> CreateContentWriterAsync(IElement element)
|
||||
=> Task.FromResult((IContentWriter)new LocalContentWriter(File.OpenRead(element.NativePath!.Path)));
|
||||
=> Task.FromResult((IContentWriter)new LocalContentWriter(File.OpenWrite(element.NativePath!.Path)));
|
||||
}
|
||||
Reference in New Issue
Block a user