Command execution, CreateContainer command WIP
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
namespace FileTime.Core.Command;
|
||||
|
||||
public enum ExecutionState
|
||||
{
|
||||
Waiting,
|
||||
Running,
|
||||
Finished
|
||||
}
|
||||
@@ -5,5 +5,5 @@ namespace FileTime.Core.Command;
|
||||
public interface ICommand
|
||||
{
|
||||
Task<CanCommandRun> CanRun(PointInTime currentTime);
|
||||
Task<PointInTime?> SimulateCommand(PointInTime? currentTime);
|
||||
Task<PointInTime> SimulateCommand(PointInTime currentTime);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using FileTime.Core.Timeline;
|
||||
|
||||
namespace FileTime.Core.Command;
|
||||
|
||||
public interface ICommandHandler
|
||||
{
|
||||
bool CanHandle(ICommand command);
|
||||
Task ExecuteAsync(ICommand command);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using FileTime.Core.Timeline;
|
||||
|
||||
namespace FileTime.Core.Command;
|
||||
|
||||
public interface ICommandRunner
|
||||
{
|
||||
Task RunCommandAsync(ICommand command);
|
||||
}
|
||||
@@ -4,5 +4,5 @@ namespace FileTime.Core.Command;
|
||||
|
||||
public interface IExecutableCommand : ICommand
|
||||
{
|
||||
Task Execute(ICommandScheduler commandScheduler);
|
||||
Task Execute();
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using System.Reactive.Linq;
|
||||
using DynamicData;
|
||||
using FileTime.Core.Models;
|
||||
|
||||
namespace FileTime.Core.Extensions;
|
||||
|
||||
public static class DynamicDataExtensions
|
||||
{
|
||||
private class DisposableContext<TParam, TTaskResult>
|
||||
{
|
||||
private readonly Func<TParam, TTaskResult> _transformResult;
|
||||
private readonly TaskCompletionSource<TTaskResult?> _taskCompletionSource;
|
||||
public IDisposable? Disposable { get; set; }
|
||||
|
||||
public DisposableContext(Func<TParam, TTaskResult> transformResult,
|
||||
TaskCompletionSource<TTaskResult?> taskCompletionSource, IDisposable? disposable = null)
|
||||
{
|
||||
_transformResult = transformResult;
|
||||
_taskCompletionSource = taskCompletionSource;
|
||||
Disposable = disposable;
|
||||
}
|
||||
|
||||
public void OnNext(TParam param)
|
||||
{
|
||||
Disposable?.Dispose();
|
||||
var result = _transformResult(param);
|
||||
_taskCompletionSource.SetResult(result);
|
||||
}
|
||||
|
||||
public void OnError(Exception ex)
|
||||
{
|
||||
Disposable?.Dispose();
|
||||
_taskCompletionSource.SetException(ex);
|
||||
}
|
||||
|
||||
public void OnCompleted()
|
||||
{
|
||||
Disposable?.Dispose();
|
||||
_taskCompletionSource.SetResult(default(TTaskResult));
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<IEnumerable<AbsolutePath>?> GetItemsAsync(
|
||||
this IObservable<IObservable<IChangeSet<AbsolutePath>>?> stream)
|
||||
=> await GetItemsAsync(stream
|
||||
.Select(s =>
|
||||
s is null
|
||||
? new SourceList<AbsolutePath>().Connect().StartWithEmpty().ToCollection()
|
||||
: s.ToCollection())
|
||||
.Switch());
|
||||
|
||||
public static async Task<IEnumerable<AbsolutePath>?> GetItemsAsync(
|
||||
this IObservable<IChangeSet<AbsolutePath>> stream)
|
||||
=> await GetItemsAsync(stream.ToCollection());
|
||||
|
||||
private static Task<IEnumerable<AbsolutePath>?> GetItemsAsync(
|
||||
this IObservable<IReadOnlyCollection<AbsolutePath>> stream)
|
||||
{
|
||||
var taskCompletionSource = new TaskCompletionSource<IEnumerable<AbsolutePath>?>();
|
||||
var context = new DisposableContext<IReadOnlyCollection<AbsolutePath>, IEnumerable<AbsolutePath>?>(r => r,
|
||||
taskCompletionSource);
|
||||
|
||||
var disposable = stream
|
||||
.Subscribe(
|
||||
context.OnNext,
|
||||
context.OnError,
|
||||
context.OnCompleted
|
||||
);
|
||||
context.Disposable = disposable;
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
}
|
||||
@@ -24,4 +24,8 @@
|
||||
<ProjectReference Include="..\..\Library\InitableService\InitableService.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="ContentAccess" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -4,8 +4,6 @@ public record FullName(string Path)
|
||||
{
|
||||
public FullName? GetParent()
|
||||
{
|
||||
if (Path is null) return null;
|
||||
|
||||
var pathParts = Path.TrimEnd(Constants.SeparatorChar).Split(Constants.SeparatorChar);
|
||||
return pathParts.Length switch
|
||||
{
|
||||
@@ -13,4 +11,10 @@ public record FullName(string Path)
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
public string GetName()
|
||||
=> Path.Split(Constants.SeparatorChar).Last();
|
||||
|
||||
public FullName GetChild(string childName)
|
||||
=> new FullName(Path + Constants.SeparatorChar + childName);
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using InitableService;
|
||||
|
||||
namespace FileTime.Core.Services;
|
||||
|
||||
public interface ITab : IInitable<IContainer>
|
||||
public interface ITab : IInitable<IContainer>, IDisposable
|
||||
{
|
||||
IObservable<IContainer?> CurrentLocation { get; }
|
||||
IObservable<AbsolutePath?> CurrentSelectedItem { get; }
|
||||
|
||||
@@ -7,6 +7,7 @@ public class CommandTimeState
|
||||
public ICommand Command { get; }
|
||||
public CanCommandRun CanRun { get; private set; } = CanCommandRun.False;
|
||||
public bool ForceRun { get; set; }
|
||||
public ExecutionState ExecutionState { get; set; }
|
||||
|
||||
public CommandTimeState(ICommand command, PointInTime? startTime)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
using FileTime.Core.Command;
|
||||
|
||||
namespace FileTime.Core.Timeline;
|
||||
|
||||
public interface ICommandExecutor
|
||||
{
|
||||
void ExecuteCommand(ICommand command);
|
||||
event EventHandler<ICommand> CommandFinished;
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using FileTime.Core.Command;
|
||||
|
||||
namespace FileTime.Core.Timeline;
|
||||
|
||||
public interface ICommandScheduler
|
||||
{
|
||||
|
||||
Task AddCommand(ICommand command, int? batchId = null, bool toNewBatch = false);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace FileTime.Core.Timeline;
|
||||
|
||||
public interface ILocalCommandExecutor : ICommandExecutor
|
||||
{
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace FileTime.Core.Timeline;
|
||||
public class ParallelCommands
|
||||
{
|
||||
private static ushort _idCounter;
|
||||
public List<CommandTimeState> _commands;
|
||||
private List<CommandTimeState> _commands;
|
||||
public ushort Id { get; }
|
||||
public IReadOnlyList<CommandTimeState> Commands { get; }
|
||||
public PointInTime? Result { get; private set; }
|
||||
|
||||
@@ -2,10 +2,11 @@ namespace FileTime.Core.Timeline;
|
||||
|
||||
public class PointInTime
|
||||
{
|
||||
private readonly List<Difference> _differences;
|
||||
public static readonly PointInTime Eternal = new PointInTime();
|
||||
public static readonly PointInTime Present = new PointInTime();
|
||||
|
||||
private readonly List<Difference> _differences;
|
||||
|
||||
public IReadOnlyList<Difference> Differences { get; }
|
||||
|
||||
private PointInTime() : this(new List<Difference>())
|
||||
@@ -26,6 +27,14 @@ public class PointInTime
|
||||
public PointInTime WithDifferences(IEnumerable<Difference> differences) =>
|
||||
new(this, differences);
|
||||
|
||||
public PointInTime WithDifferences(Func<PointInTime, IEnumerable<Difference>> differenceGenerator)
|
||||
{
|
||||
var newPointInTime = new PointInTime();
|
||||
newPointInTime._differences.AddRange(differenceGenerator(newPointInTime));
|
||||
|
||||
return newPointInTime;
|
||||
}
|
||||
|
||||
private static List<Difference> MergeDifferences(IEnumerable<Difference> previouses,
|
||||
IEnumerable<Difference> differences)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user