Command execution, CreateContainer command WIP
This commit is contained in:
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user