public async Task <IUnixFileSystemEntry> MoveAsync(IUnixDirectoryEntry parent, IUnixFileSystemEntry source, IUnixDirectoryEntry target, string fileName, CancellationToken cancellationToken)
        {
            var targetDirEntry = (GcsDirectoryEntry)target;
            var targetName     = string.Join("/", new string[] { targetDirEntry.FullName.Trim('/'), fileName }).Trim('/');

            if (source is GcsFileEntry sourceFileEntry)
            {
                var sourceDirEntry = (GcsDirectoryEntry)parent;
                var sourceName     = string.Join("/", new string[] { sourceDirEntry.FullName.Trim('/'), sourceFileEntry.Name }).Trim('/');
                try
                {
                    var newObj = await _storageClient.CopyObjectAsync(_bucketName, sourceName,
                                                                      _bucketName, targetName,
                                                                      null, cancellationToken);

                    if (newObj != null)
                    {
                        await _storageClient.DeleteObjectAsync(_bucketName, sourceName, null, cancellationToken);
                    }
                }
                catch { }
            }
            else
            {
                throw new NotSupportedException();
            }

            return(new GcsDirectoryEntry(this)
            {
                Name = targetName
            });
        }
Exemplo n.º 2
0
        public async Task CopyAsync(string name, string id, long version, string suffix, CancellationToken ct = default(CancellationToken))
        {
            var objectName = GetObjectName(id, version, suffix);

            try
            {
                await storageClient.CopyObjectAsync(bucketName, name, bucketName, objectName, cancellationToken : ct);
            }
            catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound)
            {
                throw new AssetNotFoundException($"Asset {name} not found.", ex);
            }
        }
Exemplo n.º 3
0
        public async Task <IFileInformation> CopyFileToSameServiceType(string identifier, IStorageService destinationService)
        {
            var destination = (GoogleStorageService)destinationService;

            var uniqueName = Guid.NewGuid().ToString();

            await _googleClient.CopyObjectAsync(GoogleSettings.Bucket, identifier, destinationBucket : destination.GoogleSettings.Bucket, destinationObjectName : uniqueName);

            var info = new GoogleFileInformation {
                StorageIdentifier = uniqueName
            };

            return(info);
        }
Exemplo n.º 4
0
        public async Task CopyAsync(string sourceFileName, string id, long version, string suffix, CancellationToken ct = default(CancellationToken))
        {
            var objectName = GetObjectName(id, version, suffix);

            try
            {
                await storageClient.CopyObjectAsync(bucketName, sourceFileName, bucketName, objectName, IfNotExistsCopy, ct);
            }
            catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound)
            {
                throw new AssetNotFoundException(sourceFileName, ex);
            }
            catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.PreconditionFailed)
            {
                throw new AssetAlreadyExistsException(objectName);
            }
        }
Exemplo n.º 5
0
        public async Task CopyAsync(string sourceFileName, string targetFileName, CancellationToken ct = default)
        {
            Guard.NotNullOrEmpty(sourceFileName);
            Guard.NotNullOrEmpty(targetFileName);

            try
            {
                await storageClient.CopyObjectAsync(bucketName, sourceFileName, bucketName, targetFileName, IfNotExistsCopy, ct);
            }
            catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound)
            {
                throw new AssetNotFoundException(sourceFileName, ex);
            }
            catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.PreconditionFailed)
            {
                throw new AssetAlreadyExistsException(targetFileName);
            }
        }
Exemplo n.º 6
0
 public async Task CopyAsync(string source, string dest)
 {
     await _googleStorageClient.CopyObjectAsync(_bucket, source, _bucket, dest);
 }
Exemplo n.º 7
0
 public Task CopyBlobAsync(string sourceContainerName, string sourceBlobName, string destinationContainerName,
                           string destinationBlobName = null)
 {
     return(_client.CopyObjectAsync(_bucket, ObjectName(sourceContainerName, sourceBlobName),
                                    _bucket, ObjectName(destinationContainerName, destinationBlobName ?? sourceBlobName)));
 }