private static async Task Upload(
            ITransferClient client,
            TransferContext context,
            IList <TransferPath> localSourcePaths,
            string uploadTargetPath,
            SampleRunner sampleRunner,
            CancellationToken token)
        {
            // Create a job-based upload transfer request.
            Console2.WriteStartHeader("Transfer - Upload");
            TransferRequest uploadJobRequest = TransferRequest.ForUploadJob(uploadTargetPath, context);

            uploadJobRequest.Application = "Github Sample";
            uploadJobRequest.Name        = "Upload Sample";

            // Create a transfer job to upload the local sample dataset to the target remote path.
            using (ITransferJob job = await client.CreateJobAsync(uploadJobRequest, token).ConfigureAwait(false))
            {
                Console2.WriteLine("Upload started.");

                // Paths added to the async job are transferred immediately.
                await job.AddPathsAsync(localSourcePaths, token).ConfigureAwait(false);

                // Await completion of the job.
                ITransferResult result = await job.CompleteAsync(token).ConfigureAwait(false);

                Console2.WriteLine("Upload completed.");
                sampleRunner.DisplayTransferResult(result);
                Console2.WriteEndHeader();
            }
        }
        private static async Task Download(
            ITransferClient client,
            AutoDeleteDirectory directory,
            TransferContext context,
            IList <TransferPath> localSourcePaths,
            string uploadTargetPath,
            SampleRunner sampleRunner,
            CancellationToken token)
        {
            // Create a job-based download transfer request.
            Console2.WriteStartHeader("Transfer - Download");
            string          downloadTargetPath = directory.Path;
            TransferRequest downloadJobRequest = TransferRequest.ForDownloadJob(downloadTargetPath, context);

            downloadJobRequest.Application = "Github Sample";
            downloadJobRequest.Name        = "Download Sample";
            Console2.WriteLine("Download started.");

            // Create a transfer job to download the sample dataset to the target local path.
            using (ITransferJob job = await client.CreateJobAsync(downloadJobRequest, token).ConfigureAwait(false))
            {
                IEnumerable <TransferPath> remotePaths = localSourcePaths.Select(
                    localPath => new TransferPath
                {
                    SourcePath     = uploadTargetPath + "\\" + Path.GetFileName(localPath.SourcePath),
                    PathAttributes = TransferPathAttributes.File,
                    TargetPath     = downloadTargetPath
                });

                await job.AddPathsAsync(remotePaths, token).ConfigureAwait(false);

                await sampleRunner.ChangeDataRateAsync(job, token).ConfigureAwait(false);

                // Await completion of the job.
                ITransferResult result = await job.CompleteAsync(token).ConfigureAwait(false);

                Console2.WriteLine("Download completed.");
                sampleRunner.DisplayTransferResult(result);
                Console2.WriteEndHeader();
            }
        }
Example #3
0
            private async Task UploadMultipleDocumentsAsync(IRelativityTransferHost relativityTransferHost, CancellationToken cancellationToken)
            {
                // Search for the first logical file share.
                const int           logicalFileShareNumber = 1;
                RelativityFileShare fileShare = await GetFileShareAsync(relativityTransferHost, logicalFileShareNumber, cancellationToken).ConfigureAwait(false);

                // Configure an Aspera specific transfer.
                AsperaClientConfiguration configuration = CreateAsperaClientConfiguration();

                // Assigning the file share bypasses auto-configuration that will normally use the default workspace repository.
                configuration.TargetFileShare = fileShare;
                using (ITransferClient client = await CreateClientAsync(relativityTransferHost, configuration, cancellationToken).ConfigureAwait(false))
                    using (AutoDeleteDirectory directory = new AutoDeleteDirectory())
                    {
                        // Create a job-based upload transfer request.
                        Console2.WriteTapiStartHeader("Advanced Transfer - Upload");
                        string uploadTargetPath = GetUniqueRemoteTargetPath(fileShare);
                        IList <TransferPath> localSourcePaths = await SearchLocalSourcePathsAsync(client, uploadTargetPath, cancellationToken).ConfigureAwait(false);

                        TransferContext context          = CreateTransferContext();
                        TransferRequest uploadJobRequest = TransferRequest.ForUploadJob(uploadTargetPath, context);
                        uploadJobRequest.Application = "Github Sample";
                        uploadJobRequest.Name        = "Advanced Upload Sample";

                        // Create a transfer job to upload the local sample data set to the target remote path.
                        using (ITransferJob job = await client.CreateJobAsync(uploadJobRequest, cancellationToken).ConfigureAwait(false))
                        {
                            Console2.WriteDebugLine("Advanced upload started.");

                            // Paths added to the async job are transferred immediately.
                            await job.AddPathsAsync(localSourcePaths, cancellationToken).ConfigureAwait(false);

                            // Await completion of the job.
                            ITransferResult result = await job.CompleteAsync(cancellationToken).ConfigureAwait(false);

                            Console2.WriteDebugLine("Advanced upload completed.");
                            DisplayTransferResult(result);
                            Console2.WriteTapiEndHeader();
                        }

                        // Create a job-based download transfer request.
                        Console2.WriteTapiStartHeader("Advanced Transfer - Download");
                        string          downloadTargetPath = directory.Path;
                        TransferRequest downloadJobRequest = TransferRequest.ForDownloadJob(downloadTargetPath, context);
                        downloadJobRequest.Application = "Github Sample";
                        downloadJobRequest.Name        = "Advanced Download Sample";
                        Console2.WriteDebugLine("Advanced download started.");

                        // Create a transfer job to download the sample data set to the target local path.
                        using (ITransferJob job = await client.CreateJobAsync(downloadJobRequest, cancellationToken).ConfigureAwait(false))
                        {
                            IEnumerable <TransferPath> remotePaths = localSourcePaths.Select(localPath => new TransferPath
                            {
                                SourcePath     = uploadTargetPath + "\\" + Path.GetFileName(localPath.SourcePath),
                                PathAttributes = TransferPathAttributes.File,
                                TargetPath     = downloadTargetPath
                            });

                            await job.AddPathsAsync(remotePaths, cancellationToken).ConfigureAwait(false);
                            await ChangeDataRateAsync(job, cancellationToken).ConfigureAwait(false);

                            // Await completion of the job.
                            ITransferResult result = await job.CompleteAsync(cancellationToken).ConfigureAwait(false);

                            Console2.WriteDebugLine("Advanced download completed.");
                            DisplayTransferResult(result);
                            Console2.WriteTapiEndHeader();
                        }
                    }
            }