Exemplo n.º 1
0
        /// <summary>
        /// Begins an operation to start copying source block blob's contents, properties, and metadata to the destination block blob.
        /// </summary>
        /// <param name="sourceBlobName">Name of the source blob.</param>
        /// <param name="destBlobName">Name of the destination blob.</param>
        /// <param name="destContainer">The destination container.</param>
        /// <returns>The copy ID associated with the copy operation; empty if source blob does not exist.</returns>
        public string StartCopyBlockBlob(string sourceBlobName, string destBlobName, BlobContainer destContainer = null)
        {
            sourceBlobName.ValidateBlobName();
            destBlobName.ValidateBlobName();

            var sourceBlob = this._cloudBlobContainer.GetBlockBlobReference(sourceBlobName);

            if (sourceBlob.Exists())
            {
                var destBlob = (destContainer ?? this).GetBlockBlob(destBlobName);

                return(destBlob.StartCopy(sourceBlob));
            }
            else
            {
                return(string.Empty);
            }
        }
        /// <summary>
        /// Begins an operation to start copying source block blob's contents, properties, and metadata to the destination block blob.
        /// </summary>
        /// <param name="sourceBlobName">Name of the source blob.</param>
        /// <param name="destBlobName">Name of the destination blob.</param>
        /// <param name="destContainer">The destination container.</param>
        /// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for a task to complete.</param>
        /// <returns>The copy ID associated with the copy operation; empty if source blob does not exist.</returns>
        public Task <string> StartCopyBlockBlobAsync(string sourceBlobName, string destBlobName, BlobContainer destContainer = null, CancellationToken?cancellationToken = null)
        {
            sourceBlobName.ValidateBlobName();
            destBlobName.ValidateBlobName();

            return(Task.Run(() =>
            {
                var sourceBlob = this.GetBlockBlob(sourceBlobName);

                if (sourceBlob.Exists())
                {
                    var destBlob = (destContainer ?? this).GetBlockBlob(destBlobName);

                    return destBlob.StartCopyAsync(sourceBlob, cancellationToken ?? CancellationToken.None);
                }
                else
                {
                    return Task.FromResult(string.Empty);
                }
            },
                            cancellationToken ?? CancellationToken.None));
        }