Copy
This commit is contained in:
@@ -10,8 +10,8 @@ using FileTime.Core.Interactions;
|
|||||||
using FileTime.Core.Models;
|
using FileTime.Core.Models;
|
||||||
using FileTime.Core.Timeline;
|
using FileTime.Core.Timeline;
|
||||||
using InitableService;
|
using InitableService;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using CopyCommand = FileTime.Core.Command.Copy.CopyCommand;
|
|
||||||
|
|
||||||
namespace FileTime.App.Core.Services.UserCommandHandler;
|
namespace FileTime.App.Core.Services.UserCommandHandler;
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
|||||||
private IItemViewModel? _currentSelectedItem;
|
private IItemViewModel? _currentSelectedItem;
|
||||||
private readonly IUserCommandHandlerService _userCommandHandlerService;
|
private readonly IUserCommandHandlerService _userCommandHandlerService;
|
||||||
private readonly IClipboardService _clipboardService;
|
private readonly IClipboardService _clipboardService;
|
||||||
private readonly IInputInterface _inputInterface;
|
private readonly IUserCommunicationService _userCommunicationService;
|
||||||
private readonly ILogger<ItemManipulationUserCommandHandlerService> _logger;
|
private readonly ILogger<ItemManipulationUserCommandHandlerService> _logger;
|
||||||
private readonly ICommandScheduler _commandScheduler;
|
private readonly ICommandScheduler _commandScheduler;
|
||||||
private readonly IServiceProvider _serviceProvider;
|
private readonly IServiceProvider _serviceProvider;
|
||||||
@@ -32,7 +32,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
|||||||
IAppState appState,
|
IAppState appState,
|
||||||
IUserCommandHandlerService userCommandHandlerService,
|
IUserCommandHandlerService userCommandHandlerService,
|
||||||
IClipboardService clipboardService,
|
IClipboardService clipboardService,
|
||||||
IInputInterface inputInterface,
|
IUserCommunicationService userCommunicationService,
|
||||||
ILogger<ItemManipulationUserCommandHandlerService> logger,
|
ILogger<ItemManipulationUserCommandHandlerService> logger,
|
||||||
ITimelessContentProvider timelessContentProvider,
|
ITimelessContentProvider timelessContentProvider,
|
||||||
ICommandScheduler commandScheduler,
|
ICommandScheduler commandScheduler,
|
||||||
@@ -40,7 +40,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
|||||||
{
|
{
|
||||||
_userCommandHandlerService = userCommandHandlerService;
|
_userCommandHandlerService = userCommandHandlerService;
|
||||||
_clipboardService = clipboardService;
|
_clipboardService = clipboardService;
|
||||||
_inputInterface = inputInterface;
|
_userCommunicationService = userCommunicationService;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_commandScheduler = commandScheduler;
|
_commandScheduler = commandScheduler;
|
||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
@@ -72,7 +72,7 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
|||||||
private Task Copy()
|
private Task Copy()
|
||||||
{
|
{
|
||||||
_clipboardService.Clear();
|
_clipboardService.Clear();
|
||||||
_clipboardService.SetCommand<CopyCommand>();
|
_clipboardService.SetCommand<FileTime.Core.Command.Copy.CopyCommand>();
|
||||||
|
|
||||||
if ((_markedItems?.Collection?.Count ?? 0) > 0)
|
if ((_markedItems?.Collection?.Count ?? 0) > 0)
|
||||||
{
|
{
|
||||||
@@ -120,17 +120,38 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
|||||||
await Paste(TransportMode.Skip);
|
await Paste(TransportMode.Skip);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task Paste(TransportMode skip)
|
private async Task Paste(TransportMode mode)
|
||||||
{
|
{
|
||||||
if (_clipboardService.CommandType is null) return Task.CompletedTask;
|
if (_clipboardService.CommandType is null)
|
||||||
return Task.CompletedTask;
|
{
|
||||||
|
_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()
|
private async Task CreateContainer()
|
||||||
{
|
{
|
||||||
var containerNameInput = new TextInputElement("Container name");
|
var containerNameInput = new TextInputElement("Container name");
|
||||||
|
|
||||||
await _inputInterface.ReadInputs(containerNameInput);
|
await _userCommunicationService.ReadInputs(containerNameInput);
|
||||||
|
|
||||||
//TODO: message on empty result
|
//TODO: message on empty result
|
||||||
var newContainerName = containerNameInput.Value;
|
var newContainerName = containerNameInput.Value;
|
||||||
@@ -140,14 +161,14 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
|||||||
var command = _serviceProvider
|
var command = _serviceProvider
|
||||||
.GetInitableResolver(_currentLocation.FullName, newContainerName)
|
.GetInitableResolver(_currentLocation.FullName, newContainerName)
|
||||||
.GetRequiredService<CreateContainerCommand>();
|
.GetRequiredService<CreateContainerCommand>();
|
||||||
await _commandScheduler.AddCommand(command);
|
await AddCommand(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CreateElement()
|
private async Task CreateElement()
|
||||||
{
|
{
|
||||||
var containerNameInput = new TextInputElement("Element name");
|
var containerNameInput = new TextInputElement("Element name");
|
||||||
|
|
||||||
await _inputInterface.ReadInputs(containerNameInput);
|
await _userCommunicationService.ReadInputs(containerNameInput);
|
||||||
|
|
||||||
//TODO: message on empty result
|
//TODO: message on empty result
|
||||||
var newContainerName = containerNameInput.Value;
|
var newContainerName = containerNameInput.Value;
|
||||||
@@ -157,6 +178,11 @@ public class ItemManipulationUserCommandHandlerService : UserCommandHandlerServi
|
|||||||
var command = _serviceProvider
|
var command = _serviceProvider
|
||||||
.GetInitableResolver(_currentLocation.FullName, newContainerName)
|
.GetInitableResolver(_currentLocation.FullName, newContainerName)
|
||||||
.GetRequiredService<CreateElementCommand>();
|
.GetRequiredService<CreateElementCommand>();
|
||||||
|
await AddCommand(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task AddCommand(ICommand command)
|
||||||
|
{
|
||||||
await _commandScheduler.AddCommand(command);
|
await _commandScheduler.AddCommand(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
|
|||||||
private readonly ILocalContentProvider _localContentProvider;
|
private readonly ILocalContentProvider _localContentProvider;
|
||||||
private readonly IUserCommandHandlerService _userCommandHandlerService;
|
private readonly IUserCommandHandlerService _userCommandHandlerService;
|
||||||
private readonly ITimelessContentProvider _timelessContentProvider;
|
private readonly ITimelessContentProvider _timelessContentProvider;
|
||||||
private readonly IInputInterface _inputInterface;
|
private readonly IUserCommunicationService _userCommunicationService;
|
||||||
private ITabViewModel? _selectedTab;
|
private ITabViewModel? _selectedTab;
|
||||||
private IContainer? _currentLocation;
|
private IContainer? _currentLocation;
|
||||||
private IItemViewModel? _currentSelectedItem;
|
private IItemViewModel? _currentSelectedItem;
|
||||||
@@ -32,14 +32,14 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
|
|||||||
ILocalContentProvider localContentProvider,
|
ILocalContentProvider localContentProvider,
|
||||||
IUserCommandHandlerService userCommandHandlerService,
|
IUserCommandHandlerService userCommandHandlerService,
|
||||||
ITimelessContentProvider timelessContentProvider,
|
ITimelessContentProvider timelessContentProvider,
|
||||||
IInputInterface inputInterface) : base(appState)
|
IUserCommunicationService userCommunicationService) : base(appState)
|
||||||
{
|
{
|
||||||
_appState = appState;
|
_appState = appState;
|
||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
_localContentProvider = localContentProvider;
|
_localContentProvider = localContentProvider;
|
||||||
_userCommandHandlerService = userCommandHandlerService;
|
_userCommandHandlerService = userCommandHandlerService;
|
||||||
_timelessContentProvider = timelessContentProvider;
|
_timelessContentProvider = timelessContentProvider;
|
||||||
_inputInterface = inputInterface;
|
_userCommunicationService = userCommunicationService;
|
||||||
|
|
||||||
SaveSelectedTab(t => _selectedTab = t);
|
SaveSelectedTab(t => _selectedTab = t);
|
||||||
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
|
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
|
||||||
@@ -74,7 +74,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
|
|||||||
private async Task GoToPath()
|
private async Task GoToPath()
|
||||||
{
|
{
|
||||||
var pathInput = new TextInputElement("Path");
|
var pathInput = new TextInputElement("Path");
|
||||||
await _inputInterface.ReadInputs(pathInput);
|
await _userCommunicationService.ReadInputs(pathInput);
|
||||||
|
|
||||||
//TODO: message on empty result and on null pathInput.Value
|
//TODO: message on empty result and on null pathInput.Value
|
||||||
var resolvedPath = await _timelessContentProvider.GetItemByNativePathAsync(new NativePath(pathInput.Value));
|
var resolvedPath = await _timelessContentProvider.GetItemByNativePathAsync(new NativePath(pathInput.Value));
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using System.Reactive.Linq;
|
|||||||
using System.Reactive.Subjects;
|
using System.Reactive.Subjects;
|
||||||
using DynamicData;
|
using DynamicData;
|
||||||
using FileTime.App.Core.Models.Enums;
|
using FileTime.App.Core.Models.Enums;
|
||||||
using FileTime.Core.Timeline;
|
|
||||||
using MvvmGen;
|
using MvvmGen;
|
||||||
using MoreLinq;
|
using MoreLinq;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using FileTime.App.Core.Models;
|
|
||||||
using FileTime.App.Core.Models.Enums;
|
using FileTime.App.Core.Models.Enums;
|
||||||
using FileTime.App.Core.Services;
|
using FileTime.App.Core.Services;
|
||||||
using FileTime.Core.Models;
|
using FileTime.Core.Models;
|
||||||
|
using FileTime.Core.Models.Extensions;
|
||||||
using MvvmGen;
|
using MvvmGen;
|
||||||
|
|
||||||
namespace FileTime.App.Core.ViewModels;
|
namespace FileTime.App.Core.ViewModels;
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ using FileTime.App.Core.Extensions;
|
|||||||
using FileTime.App.Core.Models;
|
using FileTime.App.Core.Models;
|
||||||
using FileTime.App.Core.Models.Enums;
|
using FileTime.App.Core.Models.Enums;
|
||||||
using FileTime.App.Core.Services;
|
using FileTime.App.Core.Services;
|
||||||
using FileTime.App.Core.ViewModels.ItemPreview;
|
|
||||||
using FileTime.Core.Models;
|
using FileTime.Core.Models;
|
||||||
|
using FileTime.Core.Models.Extensions;
|
||||||
using FileTime.Core.Services;
|
using FileTime.Core.Services;
|
||||||
using InitableService;
|
using InitableService;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using MvvmGen;
|
using MvvmGen;
|
||||||
|
|
||||||
namespace FileTime.App.Core.ViewModels;
|
namespace FileTime.App.Core.ViewModels;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using FileTime.App.Core.Models;
|
|||||||
using FileTime.App.Core.Services;
|
using FileTime.App.Core.Services;
|
||||||
using FileTime.App.Core.Services.Persistence;
|
using FileTime.App.Core.Services.Persistence;
|
||||||
using FileTime.Core.Command;
|
using FileTime.Core.Command;
|
||||||
|
using FileTime.Core.Command.Copy;
|
||||||
using FileTime.Core.Command.CreateContainer;
|
using FileTime.Core.Command.CreateContainer;
|
||||||
using FileTime.Core.Command.CreateElement;
|
using FileTime.Core.Command.CreateElement;
|
||||||
using FileTime.Core.CommandHandlers;
|
using FileTime.Core.CommandHandlers;
|
||||||
@@ -25,7 +26,11 @@ public static class DependencyInjection
|
|||||||
serviceCollection.TryAddSingleton<ITimelessContentProvider, TimelessContentProvider>();
|
serviceCollection.TryAddSingleton<ITimelessContentProvider, TimelessContentProvider>();
|
||||||
serviceCollection.TryAddSingleton<ICommandRunner, CommandRunner>();
|
serviceCollection.TryAddSingleton<ICommandRunner, CommandRunner>();
|
||||||
serviceCollection.TryAddSingleton<IContentAccessorFactory, ContentAccessorFactory>();
|
serviceCollection.TryAddSingleton<IContentAccessorFactory, ContentAccessorFactory>();
|
||||||
|
serviceCollection.TryAddSingleton<IContentProviderRegistry, ContentProviderRegistry>();
|
||||||
|
//TODO: check local/remote context
|
||||||
serviceCollection.TryAddSingleton<ILocalCommandExecutor, LocalCommandExecutor>();
|
serviceCollection.TryAddSingleton<ILocalCommandExecutor, LocalCommandExecutor>();
|
||||||
|
serviceCollection.TryAddSingleton<ICommandSchedulerNotifier, LocalCommandSchedulerNotifier>();
|
||||||
|
|
||||||
serviceCollection.TryAddSingleton<IApplicationSettings, ApplicationSettings>();
|
serviceCollection.TryAddSingleton<IApplicationSettings, ApplicationSettings>();
|
||||||
serviceCollection.TryAddSingleton<ITabPersistenceService, TabPersistenceService>();
|
serviceCollection.TryAddSingleton<ITabPersistenceService, TabPersistenceService>();
|
||||||
serviceCollection.TryAddTransient<ITab, Tab>();
|
serviceCollection.TryAddTransient<ITab, Tab>();
|
||||||
@@ -43,6 +48,7 @@ public static class DependencyInjection
|
|||||||
{
|
{
|
||||||
return serviceCollection
|
return serviceCollection
|
||||||
.AddTransient<CreateContainerCommand>()
|
.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;
|
namespace FileTime.Core.Command;
|
||||||
|
|
||||||
public interface ITransportationCommand : ICommand
|
public interface ITransportationCommand : ICommand
|
||||||
{
|
{
|
||||||
|
TransportMode? TransportMode { get; set; }
|
||||||
|
IList<FullName> Sources { get; }
|
||||||
|
FullName? Target { get; set; }
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
namespace FileTime.Core.Interactions;
|
namespace FileTime.Core.Interactions;
|
||||||
|
|
||||||
public interface IInputInterface
|
public interface IUserCommunicationService
|
||||||
{
|
{
|
||||||
Task<bool> ReadInputs(params IInputElement[] fields);
|
Task<bool> ReadInputs(params IInputElement[] fields);
|
||||||
|
void ShowToastMessage(string text);
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
using FileTime.Core.Command;
|
using FileTime.Core.Command;
|
||||||
|
using FileTime.Core.Models;
|
||||||
|
|
||||||
namespace FileTime.Core.Timeline;
|
namespace FileTime.Core.Timeline;
|
||||||
|
|
||||||
public interface ICommandScheduler
|
public interface ICommandScheduler
|
||||||
{
|
{
|
||||||
Task AddCommand(ICommand command, int? batchId = null, bool toNewBatch = false);
|
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
|
public class CopyCommand : ITransportationCommand
|
||||||
{
|
{
|
||||||
private readonly ITimelessContentProvider _timelessContentProvider;
|
private readonly ITimelessContentProvider _timelessContentProvider;
|
||||||
|
private readonly ICommandSchedulerNotifier _commandSchedulerNotifier;
|
||||||
|
|
||||||
private readonly List<OperationProgress> _operationProgresses = new();
|
private readonly List<OperationProgress> _operationProgresses = new();
|
||||||
|
|
||||||
@@ -18,9 +19,12 @@ public class CopyCommand : ITransportationCommand
|
|||||||
public TransportMode? TransportMode { get; set; } = Command.TransportMode.Merge;
|
public TransportMode? TransportMode { get; set; } = Command.TransportMode.Merge;
|
||||||
public OperationProgress? CurrentOperationProgress { get; private set; }
|
public OperationProgress? CurrentOperationProgress { get; private set; }
|
||||||
|
|
||||||
public CopyCommand(ITimelessContentProvider timelessContentProvider)
|
public CopyCommand(
|
||||||
|
ITimelessContentProvider timelessContentProvider,
|
||||||
|
ICommandSchedulerNotifier commandSchedulerNotifier)
|
||||||
{
|
{
|
||||||
_timelessContentProvider = timelessContentProvider;
|
_timelessContentProvider = timelessContentProvider;
|
||||||
|
_commandSchedulerNotifier = commandSchedulerNotifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<CanCommandRun> CanRun(PointInTime currentTime)
|
public Task<CanCommandRun> CanRun(PointInTime currentTime)
|
||||||
@@ -58,7 +62,7 @@ public class CopyCommand : ITransportationCommand
|
|||||||
|
|
||||||
await CalculateProgressAsync(currentTime);
|
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);
|
var resolvedTarget = await _timelessContentProvider.GetItemByFullNameAsync(Target, currentTime);
|
||||||
|
|
||||||
@@ -92,17 +96,17 @@ public class CopyCommand : ITransportationCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async Task TraverseTree(
|
private async Task TraverseTree(
|
||||||
PointInTime curretnTime,
|
PointInTime currentTime,
|
||||||
IEnumerable<FullName> sources,
|
IEnumerable<FullName> sources,
|
||||||
AbsolutePath target,
|
AbsolutePath target,
|
||||||
TransportMode transportMode,
|
TransportMode transportMode,
|
||||||
ICopyStrategy copyOperation)
|
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)
|
foreach (var source in sources)
|
||||||
{
|
{
|
||||||
var item = await _timelessContentProvider.GetItemByFullNameAsync(source, curretnTime);
|
var item = await _timelessContentProvider.GetItemByFullNameAsync(source, currentTime);
|
||||||
|
|
||||||
if (item is IContainer container)
|
if (item is IContainer container)
|
||||||
{
|
{
|
||||||
@@ -114,7 +118,7 @@ public class CopyCommand : ITransportationCommand
|
|||||||
var children = await container.Items.GetItemsAsync();
|
var children = await container.Items.GetItemsAsync();
|
||||||
if (children is null) continue;
|
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));
|
await copyOperation.ContainerCopyDoneAsync(new AbsolutePath(_timelessContentProvider, container));
|
||||||
}
|
}
|
||||||
else if (item is IElement element)
|
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)
|
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 newName = name;
|
||||||
var targetNameExists = resolvedTarget != null && items.Any(i => i.Path.GetName() == newName);
|
var targetNameExists = items.Any(i => i.Path.GetName() == newName);
|
||||||
if (transportMode == TransportMode.Merge && resolvedTarget != null)
|
if (transportMode == TransportMode.Merge)
|
||||||
{
|
{
|
||||||
for (var i = 0; targetNameExists; i++)
|
for (var i = 0; targetNameExists; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
|
using System.Reactive.Linq;
|
||||||
|
using System.Reactive.Subjects;
|
||||||
using DynamicData;
|
using DynamicData;
|
||||||
using FileTime.Core.Command;
|
using FileTime.Core.Command;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using FileTime.Core.Models;
|
||||||
|
|
||||||
namespace FileTime.Core.Timeline;
|
namespace FileTime.Core.Timeline;
|
||||||
|
|
||||||
public class CommandScheduler : ICommandScheduler
|
public class CommandScheduler : ICommandScheduler
|
||||||
{
|
{
|
||||||
private readonly IServiceProvider _serviceProvider;
|
|
||||||
private readonly SourceList<ParallelCommands> _commandsToRun = new();
|
private readonly SourceList<ParallelCommands> _commandsToRun = new();
|
||||||
private readonly List<ICommandExecutor> _commandExecutors = new();
|
private readonly List<ICommandExecutor> _commandExecutors = new();
|
||||||
|
private readonly Subject<FullName> _containerToRefresh = new();
|
||||||
|
|
||||||
private readonly object _guard = new();
|
private readonly object _guard = new();
|
||||||
private bool _enableRunning = true;
|
private bool _enableRunning = true;
|
||||||
private bool _resourceIsInUse;
|
private bool _resourceIsInUse;
|
||||||
|
|
||||||
|
public IObservable<FullName> ContainerToRefresh { get; }
|
||||||
|
|
||||||
public bool EnableRunning
|
public bool EnableRunning
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -26,10 +30,10 @@ public class CommandScheduler : ICommandScheduler
|
|||||||
set { RunWithLock(() => _enableRunning = value); }
|
set { RunWithLock(() => _enableRunning = value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandScheduler(IServiceProvider serviceProvider)
|
public CommandScheduler(ILocalCommandExecutor localExecutor)
|
||||||
{
|
{
|
||||||
_serviceProvider = serviceProvider;
|
ContainerToRefresh = _containerToRefresh.AsObservable();
|
||||||
var localExecutor = serviceProvider.GetRequiredService<ILocalCommandExecutor>();
|
|
||||||
localExecutor.CommandFinished += LocalExecutorOnCommandFinished;
|
localExecutor.CommandFinished += LocalExecutorOnCommandFinished;
|
||||||
_commandExecutors.Add(localExecutor);
|
_commandExecutors.Add(localExecutor);
|
||||||
}
|
}
|
||||||
@@ -74,6 +78,8 @@ public class CommandScheduler : ICommandScheduler
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RefreshContainer(FullName container) => _containerToRefresh.OnNext(container);
|
||||||
|
|
||||||
private void ExecuteCommands()
|
private void ExecuteCommands()
|
||||||
{
|
{
|
||||||
if (!_enableRunning) return;
|
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;
|
namespace FileTime.GuiApp.Services;
|
||||||
|
|
||||||
public interface IDialogService : IInputInterface
|
public interface IDialogService : IUserCommunicationService
|
||||||
{
|
{
|
||||||
IObservable<ReadInputsViewModel?> ReadInput { get; }
|
IObservable<ReadInputsViewModel?> ReadInput { get; }
|
||||||
void ReadInputs(IEnumerable<IInputElement> inputs, Action inputHandler, Action? cancelHandler = null);
|
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<IDialogService, DialogService>();
|
||||||
serviceCollection.TryAddSingleton<ISystemClipboardService, SystemClipboardService>();
|
serviceCollection.TryAddSingleton<ISystemClipboardService, SystemClipboardService>();
|
||||||
serviceCollection.TryAddSingleton<ToastMessageSink>();
|
serviceCollection.TryAddSingleton<ToastMessageSink>();
|
||||||
serviceCollection.TryAddSingleton<IInputInterface>(s => s.GetRequiredService<IDialogService>());
|
serviceCollection.TryAddSingleton<IUserCommunicationService>(s => s.GetRequiredService<IDialogService>());
|
||||||
|
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using FileTime.Core.Models.Extensions;
|
|||||||
using FileTime.Core.Timeline;
|
using FileTime.Core.Timeline;
|
||||||
|
|
||||||
namespace FileTime.Providers.Local;
|
namespace FileTime.Providers.Local;
|
||||||
|
|
||||||
public sealed partial class LocalContentProvider : ContentProviderBase, ILocalContentProvider
|
public sealed partial class LocalContentProvider : ContentProviderBase, ILocalContentProvider
|
||||||
{
|
{
|
||||||
private readonly ITimelessContentProvider _timelessContentProvider;
|
private readonly ITimelessContentProvider _timelessContentProvider;
|
||||||
@@ -75,11 +76,11 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
|
|||||||
{
|
{
|
||||||
if ((path?.Length ?? 0) == 0)
|
if ((path?.Length ?? 0) == 0)
|
||||||
{
|
{
|
||||||
return Task.FromResult((IItem)this);
|
return Task.FromResult((IItem) this);
|
||||||
}
|
}
|
||||||
else if (Directory.Exists(path))
|
else if (Directory.Exists(path))
|
||||||
{
|
{
|
||||||
return Task.FromResult((IItem)DirectoryToContainer(
|
return Task.FromResult((IItem) DirectoryToContainer(
|
||||||
new DirectoryInfo(path!.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar),
|
new DirectoryInfo(path!.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar),
|
||||||
pointInTime,
|
pointInTime,
|
||||||
!itemInitializationSettings.SkipChildInitialization)
|
!itemInitializationSettings.SkipChildInitialization)
|
||||||
@@ -87,7 +88,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
|
|||||||
}
|
}
|
||||||
else if (File.Exists(path))
|
else if (File.Exists(path))
|
||||||
{
|
{
|
||||||
return Task.FromResult((IItem)FileToElement(new FileInfo(path), pointInTime));
|
return Task.FromResult((IItem) FileToElement(new FileInfo(path), pointInTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
var type = forceResolvePathType switch
|
var type = forceResolvePathType switch
|
||||||
@@ -119,10 +120,10 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
|
|||||||
return forceResolvePathType switch
|
return forceResolvePathType switch
|
||||||
{
|
{
|
||||||
AbsolutePathType.Container => Task.FromResult(
|
AbsolutePathType.Container => Task.FromResult(
|
||||||
(IItem)CreateEmptyContainer(
|
(IItem) CreateEmptyContainer(
|
||||||
nativePath,
|
nativePath,
|
||||||
pointInTime,
|
pointInTime,
|
||||||
Observable.Return(new List<Exception>() { innerException })
|
Observable.Return(new List<Exception>() {innerException})
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
AbsolutePathType.Element => Task.FromResult(CreateEmptyElement(nativePath)),
|
AbsolutePathType.Element => Task.FromResult(CreateEmptyElement(nativePath)),
|
||||||
@@ -234,22 +235,25 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
|
|||||||
|
|
||||||
Task<IObservable<IChangeSet<AbsolutePath, string>>?> InitChildren()
|
Task<IObservable<IChangeSet<AbsolutePath, string>>?> InitChildren()
|
||||||
{
|
{
|
||||||
SourceCache<AbsolutePath, string>? result = null;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var items = initializeChildren ? (List<AbsolutePath>?)GetItemsByContainer(directoryInfo, pointInTime) : null;
|
var items = initializeChildren ? (List<AbsolutePath>?) GetItemsByContainer(directoryInfo, pointInTime) : null;
|
||||||
if (items != 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);
|
result.AddOrUpdate(items);
|
||||||
|
return Task.FromResult((IObservable<IChangeSet<AbsolutePath, string>>?) result.Connect());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
exceptions.OnNext(new List<Exception>() { e });
|
exceptions.OnNext(new List<Exception>() {e});
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.FromResult(result?.Connect());
|
return Task.FromResult((IObservable<IChangeSet<AbsolutePath, string>>?) null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,7 +324,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
|
|||||||
var size = maxLength ?? realFileSize switch
|
var size = maxLength ?? realFileSize switch
|
||||||
{
|
{
|
||||||
> int.MaxValue => int.MaxValue,
|
> int.MaxValue => int.MaxValue,
|
||||||
_ => (int)realFileSize
|
_ => (int) realFileSize
|
||||||
};
|
};
|
||||||
var buffer = new byte[size];
|
var buffer = new byte[size];
|
||||||
await reader.ReadAsync(buffer.AsMemory(0, size), cancellationToken);
|
await reader.ReadAsync(buffer.AsMemory(0, size), cancellationToken);
|
||||||
|
|||||||
@@ -6,5 +6,5 @@ namespace FileTime.Providers.Local;
|
|||||||
public class LocalContentWriterFactory : IContentWriterFactory<ILocalContentProvider>
|
public class LocalContentWriterFactory : IContentWriterFactory<ILocalContentProvider>
|
||||||
{
|
{
|
||||||
public Task<IContentWriter> CreateContentWriterAsync(IElement element)
|
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