예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
        }
예제 #4
0
        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;
            }
        }
예제 #5
0
        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;
            }
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
 public abstract void Move(FileSystemObject sourceFso, FileSystemObject targetFso, IFileStorageProvider targetProvider = null);
예제 #8
0
 public abstract void Delete(FileSystemObject fso);
예제 #9
0
 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);
 }
예제 #12
0
 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);
 }
예제 #13
0
 public S3BucketKeyInfo(FileSystemObject fso) : this(fso.FullName)
 {
 }
예제 #14
0
 public override byte[] Get(FileSystemObject fso)
 {
     return(Exists(fso.FullName)
         ? File.ReadAllBytes(fso.FullName)
         : null);
 }
예제 #15
0
 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);
 }
예제 #16
0
 public override Stream GetStream(FileSystemObject fso)
 {
     return(Exists(fso.FullName)
         ? new FileStream(fso.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)
         : null);
 }
예제 #17
0
 public override void Download(FileSystemObject thisFso, FileSystemObject downloadToFso)
 {   // Download on FileSystem is just a copy operation
     Copy(thisFso, downloadToFso);
 }
예제 #18
0
 public override bool Exists(FileSystemObject fso)
 {
     return(File.Exists(fso.FullName));
 }
예제 #19
0
 public abstract bool Exists(FileSystemObject fso);
예제 #20
0
 public abstract byte[] Get(FileSystemObject fso);
예제 #21
0
 public abstract void Download(FileSystemObject thisFso, FileSystemObject localFileSystemFso);
예제 #22
0
 public override void Download(FileSystemObject thisFso, FileSystemObject downloadToFso)
 {
     GetToLocalFile(thisFso, downloadToFso);
 }
예제 #23
0
        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);
 }
예제 #26
0
 public abstract void Store(Stream stream, FileSystemObject fso);
예제 #27
0
 public abstract Stream GetStream(FileSystemObject fso);
 public override void Delete(FileSystemObject fso)
 {
     fileMap.TryRemove(fso.FullName, out _);
 }
예제 #29
0
 public abstract void Store(byte[] bytes, FileSystemObject fso);
 public override bool Exists(FileSystemObject fso)
 {
     return(fileMap.ContainsKey(fso.FullName));
 }