Exemple #1
0
        /// <summary>
        ///
        /// <para>CopyFile:</para>
        ///
        /// <para>Copy a file from a bucket and relative location to another in File Service, caller thread will be blocked before it is done</para>
        ///
        /// <para>Check <seealso cref="IBFileServiceInterface.CopyFile"/> for detailed documentation</para>
        ///
        /// </summary>
        public bool CopyFile(
            string _SourceBucketName,
            string _SourceKeyInBucket,
            string _DestinationBucketName,
            string _DestinationKeyInBucket,
            EBRemoteFileReadPublicity _RemoteFileReadAccess = EBRemoteFileReadPublicity.AuthenticatedRead,
            Action <string> _ErrorMessageAction             = null)
        {
            if (GSClient == null)
            {
                _ErrorMessageAction?.Invoke("BFileServiceGC->CopyFile: GSClient is null.");
                return(false);
            }

            PredefinedObjectAcl CloudTypePublicity;

            if (_RemoteFileReadAccess == EBRemoteFileReadPublicity.PublicRead)
            {
                CloudTypePublicity = PredefinedObjectAcl.PublicRead;
            }
            else if (_RemoteFileReadAccess == EBRemoteFileReadPublicity.ProjectWideProtectedRead)
            {
                CloudTypePublicity = PredefinedObjectAcl.ProjectPrivate;
            }
            else
            {
                CloudTypePublicity = PredefinedObjectAcl.AuthenticatedRead;
            }

            try
            {
                var CopiedObject = GSClient.CopyObject(_SourceBucketName, _SourceKeyInBucket, _DestinationBucketName, _DestinationKeyInBucket, new CopyObjectOptions
                {
                    DestinationPredefinedAcl = CloudTypePublicity
                });

                if (CopiedObject == null)
                {
                    _ErrorMessageAction?.Invoke("BFileServiceGC->CopyFile: Operation has failed.");
                    return(false);
                }

                CopiedObject.CacheControl = CloudTypePublicity == PredefinedObjectAcl.PublicRead ? "public" : "private";
                GSClient.PatchObject(CopiedObject, null);
            }
            catch (Exception e)
            {
                _ErrorMessageAction?.Invoke("BFileServiceGC->CopyFile: " + e.Message + ", Trace: " + e.StackTrace);
                return(false);
            }
            return(true);
        }
Exemple #2
0
 public void CopyFile(string sourceBucketName, string sourceFileName, string destinationBucketName, string destinationFileName)
 {
     EnsureBucketExist(sourceBucketName);
     EnsureBucketExist(destinationBucketName);
     try
     {
         _storageClient.CopyObject(sourceBucketName, sourceFileName, destinationBucketName, destinationFileName);
     }
     catch (GoogleApiException gex)
     {
         _logger.LogError(-1, gex, gex.Error.Message);
         throw;
     }
 }
Exemple #3
0
        private void ArchiveProcessedFilesFromBucket(string filename, bool isNonMsd1File)
        {
            string filebucket        = _settings.AsciiBucket;
            string destinationBucket = isNonMsd1File ? _settings.PortAsciiBucket : _settings.ArchivedAsciiBucket;

            StorageClient storageClient = StorageClient.Create();

            foreach (var Item in storageClient.ListObjects(filebucket))
            {
                if (filename.Contains(Item.Name))
                {
                    storageClient.CopyObject(filebucket, Item.Name, destinationBucket, Item.Name);
                    storageClient.DeleteObject(filebucket, Item.Name);
                }
            }
            File.Delete(filename);
        }
        public void CopyObject()
        {
            var projectId         = _fixture.ProjectId;
            var sourceBucket      = _fixture.BucketName;
            var destinationBucket = IdGenerator.FromGuid();

            StorageClient.Create().CreateBucket(projectId, destinationBucket);
            StorageSnippetFixture.SleepAfterBucketCreateDelete();
            _fixture.RegisterBucketToDelete(destinationBucket);

            // Snippet: CopyObject
            StorageClient client          = StorageClient.Create();
            string        sourceName      = "greetings/hello.txt";
            string        destinationName = "copy.txt";

            // This method actually uses the "rewrite" API operation, for added reliability
            // when copying large objects across locations, storage classes or encryption keys.
            client.CopyObject(sourceBucket, sourceName, destinationBucket, destinationName);
            // End snippet

            var obj = client.GetObject(destinationBucket, destinationName);

            Assert.Equal((ulong)Encoding.UTF8.GetByteCount(_fixture.HelloWorldContent), obj.Size.Value);
        }