public async Task <IFile> CopyFromAsync(IFile file, string targetPath) { Guard.ArgumentNotNull(file, nameof(file)); if (!file.Exists) { throw new ArgumentException("要从中复制内容的源文件不存在。", nameof(file)); } Guard.ArgumentIsRelativePath(targetPath, nameof(targetPath)); string fullPath = _fileMapping.GetFilePath(targetPath, _scope); using (var fs = await file.CreateReadStreamAsync()) { return(await CreateFileAsync(fullPath, fs)); } }
public PhysicalFile(string scope, string filePath, IFileRequestMapping fileRequestMapping) { Guard.ArgumentNotNull(fileRequestMapping, nameof(fileRequestMapping)); Guard.ArgumentIsRelativePath(filePath, nameof(filePath)); _filePath = filePath; _fullPath = fileRequestMapping.GetFilePath(filePath, scope); _mapping = fileRequestMapping; }
public Task <IFile> SaveChangesAsync() { string fullPath = _fileMapping.GetFilePath(_relativePath, _scope); string directory = Path.GetDirectoryName(fullPath); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } File.Copy(_tempFilePath, fullPath, true); return(Task.FromResult <IFile>(new PhysicalFile(_scope, _relativePath, _fileMapping))); }