ContentProvider more async

This commit is contained in:
2023-08-24 15:50:11 +02:00
parent f1daca788e
commit ff1f6e1c3e
31 changed files with 136 additions and 69 deletions

View File

@@ -11,4 +11,8 @@
<ProjectReference Include="..\FileTime.Core.Command\FileTime.Core.Command.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>
</Project>

View File

@@ -18,25 +18,30 @@ public class StreamCopyCommandHandler : ICommandHandler
_contentAccessorFactory = contentAccessorFactory;
}
public bool CanHandle(ICommand command)
public async Task<bool> CanHandleAsync(ICommand command)
{
if (command is not CopyCommand copyCommand) return false;
var targetSupportsContentStream =
_contentProviderRegistry
(await _contentProviderRegistry
.ContentProviders
.FirstOrDefault(p => p.CanHandlePath(copyCommand.Target!))
?.SupportsContentStreams ?? false;
.ToAsyncEnumerable()
.FirstOrDefaultAwaitAsync(async p => await p.CanHandlePathAsync(copyCommand.Target))
)?.SupportsContentStreams ?? false;
var allSourcesSupportsContentStream =
copyCommand
(await copyCommand
.Sources
.Select(s =>
.ToAsyncEnumerable()
.SelectAwait(s =>
_contentProviderRegistry
.ContentProviders
.FirstOrDefault(p => p.CanHandlePath(s))
.ToAsyncEnumerable()
.FirstOrDefaultAwaitAsync(async p => await p.CanHandlePathAsync(s))
)
.All(p => p?.SupportsContentStreams ?? false);
.ToListAsync()
)
.All(p => p?.SupportsContentStreams ?? false);
return targetSupportsContentStream && allSourcesSupportsContentStream;
}