private void GetToLocalFile(FileSystemObject fso, FileSystemObject downloadToFso) { var bki = new S3BucketKeyInfo(fso.FullName); var request = new GetObjectRequest { BucketName = bki.BucketName, Key = bki.Key }; localFs.CreateFolder(downloadToFso.FolderName); localFs.Delete(downloadToFso); using (var response = S3Client.GetObject(request)) { response.WriteResponseStreamToFile(downloadToFso.FullName, append: false); } }
private void CopyInS3(FileSystemObject sourceFso, FileSystemObject targetFso) { if (sourceFso.Equals(targetFso)) { return; } var sourceBki = new S3BucketKeyInfo(sourceFso); var targetBki = new S3BucketKeyInfo(targetFso); var request = new CopyObjectRequest { SourceBucket = sourceBki.BucketName, SourceKey = sourceBki.Key, DestinationBucket = targetBki.BucketName, DestinationKey = targetBki.Key }; S3Client.CopyObject(request); }
public override void Copy(FileSystemObject thisFso, FileSystemObject targetFso, IFileStorageProvider targetProvider = null) { var bytes = Get(thisFso); if (bytes == null) { throw new FileNotFoundException("File does not exist in memory provider", thisFso.FullName); } if (TreatAsInMemoryProvider(targetProvider)) { if (thisFso.Equals(targetFso)) { return; } Store(bytes, targetFso); return; } targetProvider.Store(bytes, targetFso); }
public override bool Exists(FileSystemObject fso) { var bki = new S3BucketKeyInfo(fso.FullName); try { var response = S3Client.GetObjectMetadata(new GetObjectMetadataRequest { BucketName = bki.BucketName, Key = bki.Key }); return(true); } catch (AmazonS3Exception ex) { if (ex.StatusCode == System.Net.HttpStatusCode.NotFound) { return(false); } //status wasn't not found, so throw the exception throw; } }
public override Stream GetStream(FileSystemObject fso) { var bki = new S3BucketKeyInfo(fso.FullName); var request = new GetObjectRequest { BucketName = bki.BucketName, Key = bki.Key }; try { return(S3Client.GetObject(request).ResponseStream); } catch (AmazonS3Exception s3x) { if (IsMissingObjectException(s3x)) { return(null); } throw; } }
public override void Copy(FileSystemObject thisFso, FileSystemObject targetFso, IFileStorageProvider targetProvider = null) { // If targetProvider is null or is an S3 provider, we are copying within S3, otherwise we // are copying across providers if (TreatAsS3Provider(targetProvider)) { CopyInS3(thisFso, targetFso); return; } // Copying across providers. With S3 in this case, need to basically download the file // to the local file system first, then copy from there to the target provder var localFile = new FileSystemObject(Path.Combine(Path.GetTempPath(), targetFso.FileNameAndExtension)); try { GetToLocalFile(thisFso, localFile); targetProvider.Store(localFile, targetFso); } finally { localFs.Delete(localFile); } }
public abstract void Move(FileSystemObject sourceFso, FileSystemObject targetFso, IFileStorageProvider targetProvider = null);
public abstract void Delete(FileSystemObject fso);
public abstract void Store(FileSystemObject localFileSystemFso, FileSystemObject targetFso);
public override void Store(FileSystemObject localFileSystemFso, FileSystemObject targetFso) { SaveToMap(localFs.Get(localFileSystemFso), targetFso); }
public override void Store(byte[] bytes, FileSystemObject fso) { SaveToMap(bytes, fso); }
public override void Delete(FileSystemObject fso) { // File system doesn't throw exception on missing file during delete, no need for a guard File.Delete(fso.FullName); }
public S3BucketKeyInfo(FileSystemObject fso) : this(fso.FullName) { }
public override byte[] Get(FileSystemObject fso) { return(Exists(fso.FullName) ? File.ReadAllBytes(fso.FullName) : null); }
public override void Store(FileSystemObject localFileSystemFso, FileSystemObject targetFso) { // Store from local file system object to another file is just a copy on the file system CopyInFileSystem(localFileSystemFso, targetFso); }
public override Stream GetStream(FileSystemObject fso) { return(Exists(fso.FullName) ? new FileStream(fso.FullName, FileMode.Open, FileAccess.Read, FileShare.Read) : null); }
public override void Download(FileSystemObject thisFso, FileSystemObject downloadToFso) { // Download on FileSystem is just a copy operation Copy(thisFso, downloadToFso); }
public override bool Exists(FileSystemObject fso) { return(File.Exists(fso.FullName)); }
public abstract bool Exists(FileSystemObject fso);
public abstract byte[] Get(FileSystemObject fso);
public abstract void Download(FileSystemObject thisFso, FileSystemObject localFileSystemFso);
public override void Download(FileSystemObject thisFso, FileSystemObject downloadToFso) { GetToLocalFile(thisFso, downloadToFso); }
public override void Delete(FileSystemObject fso) { var bki = new S3BucketKeyInfo(fso); Delete(bki); }
public override byte[] Get(FileSystemObject fso) { var map = TryGetMap(fso.FullName); return(map?.Bytes); }
public override void Store(Stream stream, FileSystemObject fso) { SaveToMap(stream.ToBytes(), fso); }
public abstract void Store(Stream stream, FileSystemObject fso);
public abstract Stream GetStream(FileSystemObject fso);
public override void Delete(FileSystemObject fso) { fileMap.TryRemove(fso.FullName, out _); }
public abstract void Store(byte[] bytes, FileSystemObject fso);
public override bool Exists(FileSystemObject fso) { return(fileMap.ContainsKey(fso.FullName)); }