Async core refactor

This commit is contained in:
2022-01-20 18:16:01 +01:00
parent 016100a565
commit 215503a4e3
33 changed files with 761 additions and 463 deletions

View File

@@ -16,38 +16,39 @@ namespace FileTime.Core.Command
throw new NotImplementedException();
}
public void Execute(Action<IAbsolutePath, IAbsolutePath> copy)
public async Task Execute(Action<IAbsolutePath, IAbsolutePath> copy)
{
DoCopy(Sources, Target, TransportMode, copy);
await DoCopy(Sources, Target, TransportMode, copy);
}
private void DoCopy(IEnumerable<IAbsolutePath> sources, IContainer target, TransportMode transportMode, Action<IAbsolutePath, IAbsolutePath> copy)
private async Task DoCopy(IEnumerable<IAbsolutePath> sources, IContainer target, TransportMode transportMode, Action<IAbsolutePath, IAbsolutePath> copy)
{
foreach (var source in sources)
{
var item = source.ContentProvider.GetByPath(source.Path);
var item = await source.ContentProvider.GetByPath(source.Path);
if (item is IContainer container)
{
var targetContainer = target.Containers.FirstOrDefault(d => d.Name == container.Name) ?? (target.CreateContainer(container.Name)!);
var targetContainer = (await target.GetContainers())?.FirstOrDefault(d => d.Name == container.Name) ?? (await target.CreateContainer(container.Name)!);
var childDirectories = container.Containers.Select(d => new AbsolutePath(item.Provider, d.FullName!));
var childFiles = container.Elements.Select(f => new AbsolutePath(item.Provider, f.FullName!));
var childDirectories = (await container.GetContainers())!.Select(d => new AbsolutePath(item.Provider, d.FullName!));
var childFiles = (await container.GetElements())!.Select(f => new AbsolutePath(item.Provider, f.FullName!));
DoCopy(childDirectories.Concat(childFiles), targetContainer, transportMode, copy);
await DoCopy(childDirectories.Concat(childFiles), targetContainer, transportMode, copy);
}
else if (item is IElement element)
{
var targetName = element.Name;
var targetNameExists = await target.IsExists(targetName);
if (transportMode == TransportMode.Merge)
{
for (var i = 0; target.IsExists(targetName); i++)
for (var i = 0; targetNameExists; i++)
{
targetName = element.Name + (i == 0 ? "_" : $"_{i}");
}
}
else if (transportMode == TransportMode.Skip && target.IsExists(targetName))
else if (transportMode == TransportMode.Skip && targetNameExists)
{
continue;
}

View File

@@ -12,29 +12,29 @@ namespace FileTime.Core.Command
throw new NotImplementedException();
}
public void Execute()
public async Task Execute()
{
foreach (var item in ItemsToDelete)
{
DoDelete(item.ContentProvider.GetByPath(item.Path)!);
await DoDelete(await item.ContentProvider.GetByPath(item.Path)!);
}
}
private void DoDelete(IItem item)
private async Task DoDelete(IItem item)
{
if (item is IContainer container)
{
foreach (var child in container.Items)
foreach (var child in await container.GetItems())
{
DoDelete(child);
child.Delete();
await DoDelete(child);
await child.Delete();
}
item.Delete();
await item.Delete();
}
else if(item is IElement element)
{
element.Delete();
await element.Delete();
}
}
}

View File

@@ -2,6 +2,6 @@ namespace FileTime.Core.Command
{
public interface IExecutableCommand : ICommand
{
void Execute();
Task Execute();
}
}