public async Task Execute(StoreArtifactsRequest request) { if (request.OutputLocation is FileSystemOutputLocation fileSystemOutputLocation) { // TODO look at clean foreach (var artifact in request.Artifacts) { var filePath = Path.Combine(fileSystemOutputLocation.Path, artifact.Path); var directory = Path.GetDirectoryName(filePath); if (!Directory.Exists(directory)) { // Directory.CreateDirectory(directory); _fileSystem.CreateDirectory(directory); } //_logger.LogDebug($"Writing file: {filePath}"); //_logger.LogDebug($"{file.Contents}"); // await File.WriteAllBytesAsync(filePath, artifact.Contents).ConfigureAwait(false); await _fileSystem.WriteAllBytesAsync(filePath, artifact.Contents).ConfigureAwait(false); } return; } throw new InvalidOperationException(); // foreach (var artifact in request.Artifacts) // { // var index = artifact.Path.LastIndexOf(Path.DirectorySeparatorChar); // var artifactDirectory = artifact.Path.Substring(0, index); // if (!Directory.Exists(artifactDirectory)) // { // Directory.CreateDirectory(artifactDirectory); // } // await File.WriteAllBytesAsync(artifact.Path, artifact.Contents); // } }
public bool ShouldExecute(StoreArtifactsRequest request) => request.OutputLocation is FileSystemOutputLocation;
public async Task Store(StoreArtifactsRequest request) { var storeArtifactsStrategy = _storeArtifactsStrategies.SingleOrDefault(strategy => strategy.ShouldExecute(request)); await storeArtifactsStrategy.Execute(request); }