private void StoreGet(IFileStorageProvider provider,
                              FileSystemObject file,
                              FileSystemObject localFileSystemSourceFile = null,
                              byte[] sourceBytes = null)
        {
            // Pssshhhh Ahhhhh tssss Push it
            if (sourceBytes != null)
            {
                provider.Store(sourceBytes, file);
            }
            else if (localFileSystemSourceFile != null)
            {
                provider.Store(localFileSystemSourceFile, file);
                sourceBytes = File.ReadAllBytes(localFileSystemSourceFile.FullName);
            }
            else
            {
                throw new Exception("Must include either bytes or a local file reference to StoreGetDelete");
            }

            // Get it
            var getFile = provider.Get(file);

            var getFileHash = getFile.ToSha256HashBytes().ToBase64String();
            var fileHash    = sourceBytes.ToSha256HashBytes().ToBase64String();

            Assert.AreEqual(fileHash, getFileHash);
        }
Esempio n. 2
0
        public override void Move(FileSystemObject sourceFso, FileSystemObject targetFso, IFileStorageProvider targetProvider = null)
        {
            if (TreatAsS3Provider(targetProvider))
            {
                MoveInS3(sourceFso, targetFso);
                return;
            }

            // Moving 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(sourceFso, localFile);

                targetProvider.Store(localFile, targetFso);

                Delete(sourceFso);
            }
            finally
            {
                localFs.Delete(localFile);
            }
        }
        public override void Move(FileSystemObject sourceFso, FileSystemObject targetFso, IFileStorageProvider targetProvider = null)
        {
            var sourceBytes = Get(sourceFso);

            if (sourceBytes == null)
            {
                throw new FileNotFoundException("File does not exist in memory provider", sourceFso.FullName);
            }

            if (TreatAsInMemoryProvider(targetProvider))
            {
                if (sourceFso.Equals(targetFso))
                {
                    return;
                }

                Store(sourceBytes, targetFso);
                Delete(sourceFso);

                return;
            }

            // Moving across providers (from in-memory to some other file provider), so store then delete source
            targetProvider.Store(sourceBytes, targetFso);
            Delete(sourceFso);
        }
Esempio n. 4
0
        public override void Copy(FileSystemObject thisFso, FileSystemObject targetFso, IFileStorageProvider targetProvider = null)
        {   // If targetProvider is null, copying within file system
            if (TreatAsLocalFileSystemProvider(targetProvider))
            {
                CopyInFileSystem(thisFso, targetFso);
                return;
            }

            // Copying across providers (from local file system to some other file provider)
            targetProvider.Store(thisFso, targetFso);
        }
Esempio n. 5
0
        public override void Move(FileSystemObject sourceFso, FileSystemObject targetFso, IFileStorageProvider targetProvider = null)
        {   // If targetProvider is null, copying within file system
            if (TreatAsLocalFileSystemProvider(targetProvider))
            {
                MoveInFileSystem(sourceFso, targetFso);
                return;
            }

            // Moving across providers (from local file system to some other file provider), so store then delete source
            targetProvider.Store(sourceFso, targetFso);
            Delete(sourceFso);
        }
        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);
        }
Esempio n. 7
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);
            }
        }
        private void CreateAndFillPathForTesting(string testSubFolder, IFileStorageProvider provider)
        {
            var testFolder = Path.Combine(baseFolderName, testSubFolder);

            provider.DeleteFolder(testFolder, recursive: true);

            // Put some files in each of the paths
            var subFolderList = new List <string>
            {
                Path.Combine(testSubFolder, "nested-folder2a", "nested-folder3"),
                Path.Combine(testSubFolder, "nested-folder2a"),
                Path.Combine(testSubFolder, "nested-folder2b"),
                testSubFolder
            };

            foreach (var subFolder in subFolderList)
            {
                for (var x = 1; x <= 3; x++)
                {
                    var file = GetTestFso(subFolder);
                    provider.Store(GetTestFileBytes(file.FullName), file);
                }
            }
        }
        private void CreateAndFillPathForTesting(string testSubFolder, IFileStorageProvider provider)
        {
            var testFolder = Path.Combine(baseFolderName, testSubFolder);

            provider.DeleteFolder(testFolder, recursive: true);

            // Put some files in each of the paths
            var subFolderList = new List<string>
                                {
                                    Path.Combine(testSubFolder, "nested-folder2a", "nested-folder3"),
                                    Path.Combine(testSubFolder, "nested-folder2a"),
                                    Path.Combine(testSubFolder, "nested-folder2b"),
                                    testSubFolder
                                };

            foreach (var subFolder in subFolderList)
            {
                for (var x = 1; x <= 3; x++)
                {
                    var file = GetTestFso(subFolder);
                    provider.Store(GetTestFileBytes(file.FullName), file);
                }
            }
        }
        public override void Move(FileSystemObject sourceFso, FileSystemObject targetFso, IFileStorageProvider targetProvider = null)
        {
            if (TreatAsS3Provider(targetProvider))
            {
                MoveInS3(sourceFso, targetFso);
                return;
            }

            // Moving 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(sourceFso, localFile);

                targetProvider.Store(localFile, targetFso);

                Delete(sourceFso);
            }
            finally
            {
                localFs.Delete(localFile);
            }

        }
        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 override void Copy(FileSystemObject thisFso, FileSystemObject targetFso, IFileStorageProvider targetProvider = null)
 {   // If targetProvider is null, copying within file system
     if (TreatAsLocalFileSystemProvider(targetProvider))
     {
         CopyInFileSystem(thisFso, targetFso);
         return;
     }
     
     // Copying across providers (from local file system to some other file provider)
     targetProvider.Store(thisFso, targetFso);
 }
 public override void Move(FileSystemObject sourceFso, FileSystemObject targetFso, IFileStorageProvider targetProvider = null)
 {   // If targetProvider is null, copying within file system
     if (TreatAsLocalFileSystemProvider(targetProvider))
     {
         MoveInFileSystem(sourceFso, targetFso);
         return;
     }
     
     // Moving across providers (from local file system to some other file provider), so store then delete source
     targetProvider.Store(sourceFso, targetFso);
     Delete(sourceFso);
 }
        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 void Move(FileSystemObject sourceFso, FileSystemObject targetFso, IFileStorageProvider targetProvider = null)
        {
            var sourceBytes = Get(sourceFso);

            if (sourceBytes == null)
            {
                throw new FileNotFoundException("File does not exist in memory provider", sourceFso.FullName);
            }

            if (TreatAsInMemoryProvider(targetProvider))
            {
                if (sourceFso.Equals(targetFso))
                {
                    return;
                }

                Store(sourceBytes, targetFso);
                Delete(sourceFso);
                
                return;
            }

            // Moving across providers (from in-memory to some other file provider), so store then delete source
            targetProvider.Store(sourceBytes, targetFso);
            Delete(sourceFso);
        }
        private void StoreGet(IFileStorageProvider provider,
                              FileSystemObject file,
                              FileSystemObject localFileSystemSourceFile = null,
                              byte[] sourceBytes = null)
        {
            // Pssshhhh Ahhhhh tssss Push it
            if (sourceBytes != null)
            {
                provider.Store(sourceBytes, file);
            }
            else if (localFileSystemSourceFile != null)
            {
                provider.Store(localFileSystemSourceFile, file);
                sourceBytes = File.ReadAllBytes(localFileSystemSourceFile.FullName);
            }
            else
            {
                throw new Exception("Must include either bytes or a local file reference to StoreGetDelete");
            }

            // Get it
            var getFile = provider.Get(file);

            var getFileHash = getFile.ToSha256ByteHash().ToBase64String();
            var fileHash = sourceBytes.ToSha256ByteHash().ToBase64String();

            Assert.AreEqual(fileHash, getFileHash);
        }