public Task ProcessAsync(FileSystemOssObjectContext context) { context.SetContent(context.OssObject.Content); return(Task.CompletedTask); }
public virtual async Task <OssObject> GetObjectAsync(GetOssObjectRequest request) { var objectPath = !request.Path.IsNullOrWhiteSpace() ? request.Path.EnsureEndsWith('/') : ""; var objectName = objectPath.IsNullOrWhiteSpace() ? request.Object : objectPath + request.Object; var filePath = CalculateFilePath(request.Bucket, objectName); if (!File.Exists(filePath)) { if (!Directory.Exists(filePath)) { throw new BusinessException(code: OssManagementErrorCodes.ObjectNotFound); // throw new ContainerNotFoundException($"Can't not found object {objectName} in container {request.Bucket} with file system"); } var directoryInfo = new DirectoryInfo(filePath); var ossObject = new OssObject( directoryInfo.Name.EnsureEndsWith('/'), objectPath, directoryInfo.CreationTime, 0L, directoryInfo.LastWriteTime, new Dictionary <string, string> { { "LastAccessTime", directoryInfo.LastAccessTime.ToString("yyyy-MM-dd HH:mm:ss") } }, true) { FullName = directoryInfo.FullName.Replace(Environment.ContentRootPath, "") }; return(ossObject); } else { var fileInfo = new FileInfo(filePath); var ossObject = new OssObject( fileInfo.Name, objectPath, fileInfo.CreationTime, fileInfo.Length, fileInfo.LastWriteTime, new Dictionary <string, string> { { "IsReadOnly", fileInfo.IsReadOnly.ToString() }, { "LastAccessTime", fileInfo.LastAccessTime.ToString("yyyy-MM-dd HH:mm:ss") } }) { FullName = fileInfo.FullName.Replace(Environment.ContentRootPath, "") }; using (var fileStream = File.OpenRead(filePath)) { var memoryStream = new MemoryStream(); await fileStream.CopyToAsync(memoryStream); ossObject.SetContent(memoryStream); if (!request.Process.IsNullOrWhiteSpace()) { using var serviceScope = ServiceProvider.CreateScope(); var context = new FileSystemOssObjectContext(request.Process, ossObject, serviceScope.ServiceProvider); foreach (var processer in Options.Processers) { await processer.ProcessAsync(context); if (context.Handled) { ossObject.SetContent(context.Content); break; } } } } return(ossObject); } }