@@ -662,6 +662,186 @@ await transferManager.StartTransferAsync(
662662 }
663663 }
664664
665+ /// <summary>
666+ /// Test to show pause and resume tests
667+ /// </summary>
668+ [ Test ]
669+ public async Task PauseAndResumeAsync_ManagerDataTransfer ( )
670+ {
671+ string connectionString = ConnectionString ;
672+ string containerName = Randomize ( "sample-container" ) ;
673+
674+ // Create a client that can authenticate with a connection string
675+ BlobContainerClient container = new BlobContainerClient ( connectionString , containerName ) ;
676+ await container . CreateIfNotExistsAsync ( ) ;
677+ try
678+ {
679+ string downloadPath = CreateTempPath ( ) ;
680+ // Get a temporary path on disk where we can download the file
681+ //@@ string downloadPath = "hello.jpg";
682+
683+ // Download the public blob at https://aka.ms/bloburl
684+ BlockBlobClient sourceBlob = new BlockBlobClient ( new Uri ( "https://aka.ms/bloburl" ) ) ;
685+ await sourceBlob . DownloadToAsync ( downloadPath ) ;
686+
687+ // Create transfer manager
688+ TransferManager transferManager = new TransferManager ( new TransferManagerOptions ( ) ) ;
689+
690+ // Create source and destination resource
691+ StorageResource sourceResource = new BlockBlobStorageResource ( sourceBlob ) ;
692+ StorageResource destinationResource = new LocalFileStorageResource ( downloadPath ) ;
693+
694+ // Create simple transfer single blob download job
695+ #region Snippet:TransferManagerTryPause_Async
696+ DataTransfer dataTransfer = await transferManager . StartTransferAsync (
697+ sourceResource : sourceResource ,
698+ destinationResource : destinationResource ) ;
699+
700+ // Pause from the Transfer Manager using the DataTransfer object
701+ bool pauseResult = await transferManager . TryPauseTransferAsync ( dataTransfer ) ;
702+ #endregion Snippet:TransferManagerTryPause_Async
703+
704+ #region Snippet:TransferManagerResume_Async
705+ // Resume from checkpoint id
706+ SingleTransferOptions optionsWithResumeTransferId = new SingleTransferOptions ( )
707+ {
708+ ResumeFromCheckpointId = dataTransfer . Id
709+ } ;
710+
711+ DataTransfer resumedTransfer = await transferManager . StartTransferAsync (
712+ sourceResource : sourceResource ,
713+ destinationResource : destinationResource ,
714+ transferOptions : optionsWithResumeTransferId ) ;
715+ #endregion Snippet:TransferManagerResume_Async
716+
717+ // Wait for download to finish
718+ await resumedTransfer . AwaitCompletion ( ) ;
719+ }
720+ finally
721+ {
722+ await container . DeleteIfExistsAsync ( ) ;
723+ }
724+ }
725+
726+ /// <summary>
727+ /// Test to show pause and resume tests
728+ /// </summary>
729+ [ Test ]
730+ public async Task PauseAndResumeAsync_ManagerId ( )
731+ {
732+ string connectionString = ConnectionString ;
733+ string containerName = Randomize ( "sample-container" ) ;
734+
735+ // Create a client that can authenticate with a connection string
736+ BlobContainerClient container = new BlobContainerClient ( connectionString , containerName ) ;
737+ await container . CreateIfNotExistsAsync ( ) ;
738+ try
739+ {
740+ string downloadPath = CreateTempPath ( ) ;
741+ // Get a temporary path on disk where we can download the file
742+ //@@ string downloadPath = "hello.jpg";
743+
744+ // Download the public blob at https://aka.ms/bloburl
745+ BlockBlobClient sourceBlob = new BlockBlobClient ( new Uri ( "https://aka.ms/bloburl" ) ) ;
746+ await sourceBlob . DownloadToAsync ( downloadPath ) ;
747+
748+ // Create transfer manager
749+ TransferManager transferManager = new TransferManager ( new TransferManagerOptions ( ) ) ;
750+
751+ // Create source and destination resource
752+ StorageResource sourceResource = new BlockBlobStorageResource ( sourceBlob ) ;
753+ StorageResource destinationResource = new LocalFileStorageResource ( downloadPath ) ;
754+
755+ // Create simple transfer single blob download job
756+ #region Snippet:TransferManagerTryPauseId_Async
757+ DataTransfer dataTransfer = await transferManager . StartTransferAsync (
758+ sourceResource : sourceResource ,
759+ destinationResource : destinationResource ) ;
760+ string transferId = dataTransfer . Id ;
761+
762+ // Pause from the Transfer Manager using the Transfer Id
763+ bool pauseResult = await transferManager . TryPauseTransferAsync ( transferId ) ;
764+ #endregion Snippet:TransferManagerTryPauseId_Async
765+
766+ // Resume from checkpoint id
767+ SingleTransferOptions optionsWithResumeTransferId = new SingleTransferOptions ( )
768+ {
769+ ResumeFromCheckpointId = dataTransfer . Id
770+ } ;
771+
772+ DataTransfer resumedTransfer = await transferManager . StartTransferAsync (
773+ sourceResource : sourceResource ,
774+ destinationResource : destinationResource ,
775+ transferOptions : optionsWithResumeTransferId ) ;
776+
777+ // Wait for download to finish
778+ await resumedTransfer . AwaitCompletion ( ) ;
779+ }
780+ finally
781+ {
782+ await container . DeleteIfExistsAsync ( ) ;
783+ }
784+ }
785+
786+ /// <summary>
787+ /// Test to show pause and resume tests
788+ /// </summary>
789+ [ Test ]
790+ public async Task PauseAndResumeAsync_DataTransferPause ( )
791+ {
792+ string connectionString = ConnectionString ;
793+ string containerName = Randomize ( "sample-container" ) ;
794+
795+ // Create a client that can authenticate with a connection string
796+ BlobContainerClient container = new BlobContainerClient ( connectionString , containerName ) ;
797+ await container . CreateIfNotExistsAsync ( ) ;
798+ try
799+ {
800+ string downloadPath = CreateTempPath ( ) ;
801+ // Get a temporary path on disk where we can download the file
802+ //@@ string downloadPath = "hello.jpg";
803+
804+ // Download the public blob at https://aka.ms/bloburl
805+ BlockBlobClient sourceBlob = new BlockBlobClient ( new Uri ( "https://aka.ms/bloburl" ) ) ;
806+ await sourceBlob . DownloadToAsync ( downloadPath ) ;
807+
808+ // Create transfer manager
809+ TransferManager transferManager = new TransferManager ( new TransferManagerOptions ( ) ) ;
810+
811+ // Create source and destination resource
812+ StorageResource sourceResource = new BlockBlobStorageResource ( sourceBlob ) ;
813+ StorageResource destinationResource = new LocalFileStorageResource ( downloadPath ) ;
814+
815+ // Create simple transfer single blob download job
816+ #region Snippet:DataTransferTryPause_Async
817+ DataTransfer dataTransfer = await transferManager . StartTransferAsync (
818+ sourceResource : sourceResource ,
819+ destinationResource : destinationResource ) ;
820+
821+ // Pause from the DataTransfer object
822+ bool pauseResult = await dataTransfer . TryPauseAsync ( ) ;
823+ #endregion Snippet:DataTransferTryPause_Async
824+
825+ // Resume from checkpoint id
826+ SingleTransferOptions optionsWithResumeTransferId = new SingleTransferOptions ( )
827+ {
828+ ResumeFromCheckpointId = dataTransfer . Id
829+ } ;
830+
831+ DataTransfer resumedTransfer = await transferManager . StartTransferAsync (
832+ sourceResource : sourceResource ,
833+ destinationResource : destinationResource ,
834+ transferOptions : optionsWithResumeTransferId ) ;
835+
836+ // Wait for download to finish
837+ await resumedTransfer . AwaitCompletion ( ) ;
838+ }
839+ finally
840+ {
841+ await container . DeleteIfExistsAsync ( ) ;
842+ }
843+ }
844+
665845 public struct StoredCredentials
666846 {
667847 public StorageResourceContainer SourceContainer { get ; set ; }
0 commit comments