Command execution, CreateContainer command WIP

This commit is contained in:
2022-05-23 18:12:22 +02:00
parent 6b3a8f7127
commit d4bd9d3ba1
29 changed files with 499 additions and 26 deletions

View File

@@ -1,21 +1,76 @@
using FileTime.Core.Enums;
using FileTime.Core.Extensions;
using FileTime.Core.Models;
using FileTime.Core.Timeline;
namespace FileTime.Core.Command.CreateContainer;
public class CreateContainerCommand : IExecutableCommand
{
public Task<CanCommandRun> CanRun(PointInTime currentTime)
private readonly ITimelessContentProvider _timelessContentProvider;
public FullName Parent { get; }
public string NewContainerName { get; }
public CreateContainerCommand(
FullName parent,
string newContainerName,
ITimelessContentProvider timelessContentProvider)
{
throw new NotImplementedException();
_timelessContentProvider = timelessContentProvider;
Parent = parent;
NewContainerName = newContainerName;
}
public Task<PointInTime?> SimulateCommand(PointInTime? currentTime)
public async Task<CanCommandRun> CanRun(PointInTime currentTime)
{
throw new NotImplementedException();
try
{
var parent = await ResolveParentAsync();
if (parent is not IContainer parentContainer) return CanCommandRun.False;
var items = await parentContainer.Items.GetItemsAsync();
if (items is null) return CanCommandRun.Forcable;
var existingItem = items.FirstOrDefault(i => i.Path.GetName() == NewContainerName);
return existingItem switch
{
null => CanCommandRun.True,
{ Type: AbsolutePathType.Container } => CanCommandRun.Forcable,
_ => CanCommandRun.False
};
}
catch
{
}
return CanCommandRun.False;
}
public Task Execute(ICommandScheduler commandScheduler)
public Task<PointInTime> SimulateCommand(PointInTime currentTime)
{
throw new NotImplementedException();
return Task.FromResult(
currentTime.WithDifferences(newPointInTime =>
new List<Difference>()
{
new(
DifferenceActionType.Create,
new AbsolutePath(_timelessContentProvider,
newPointInTime,
Parent.GetChild(NewContainerName),
AbsolutePathType.Container
)
)
}
)
);
}
public Task Execute()
{
return Task.CompletedTask;
}
private async Task<IItem> ResolveParentAsync()
=> await _timelessContentProvider.GetItemByFullNameAsync(Parent, PointInTime.Present);
}