Пример #1
0
        public async Task CopyFileAsync(
            string sourcePath,
            string targetPath,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var sourceFile = _share.GetFileReference(sourcePath);
            var targetFile = _share.GetFileReference(targetPath);

            // Ensure that the target directory exists, used if we're copying a
            // file to a new sub-directory.
            await EnsureParentDirectoriesExistAsync(targetFile, cancellationToken);

            // The following only initiates a copy. There does not appear a way
            // to wait until the copy is complete without monitoring the copy
            // status of the target file.
            await targetFile.StartCopyAsync(sourceFile);

            // However, for a file copy operation within the same storage
            // account, we can assume that the copy operation has completed
            // when `StartCopyAsync` completes. Here we check this assumption.
            if (targetFile.CopyState.Status != CopyStatus.Success)
            {
                // TODO Consider if we can handle this case better.
                throw new NotSupportedException();
            }
        }