private static async Task <ITransferClient> CreateClientAsync(IRelativityTransferHost relativityTransferHost, ClientConfiguration clientConfiguration, CancellationToken cancellationToken) { Console2.WriteTapiStartHeader("Create Client"); ITransferClient client; if (clientConfiguration.Client == WellKnownTransferClient.Unassigned) { // The CreateClientAsync method chooses the best client at runtime. Console2.WriteDebugLine("TAPI is choosing the best transfer client..."); client = await relativityTransferHost.CreateClientAsync(clientConfiguration, cancellationToken).ConfigureAwait(false); } else { // The CreateClient method creates the specified client. Console2.WriteDebugLine("The API caller specified the {0} transfer client.", clientConfiguration.Client); client = relativityTransferHost.CreateClient(clientConfiguration); } if (client == null) { throw new InvalidOperationException("This operation cannot be performed because a transfer client could not be created."); } Console2.WriteDebugLine("TAPI created the {0} transfer client.", client.DisplayName); Console2.WriteTapiEndHeader(); return(client); }
private async Task <IList <TransferPath> > SearchLocalSourcePathsAsync(ITransferClient transferClient, string uploadTargetPath, CancellationToken cancellationToken) { Console2.WriteTapiStartHeader("Search Paths"); string searchLocalPath = GetLocalDocumentsFolderPath(); const bool local = true; PathEnumeratorContext pathEnumeratorContext = new PathEnumeratorContext(transferClient.Configuration, new[] { searchLocalPath }, uploadTargetPath) { PreserveFolders = false }; IPathEnumerator pathEnumerator = transferClient.CreatePathEnumerator(local); EnumeratedPathsResult result = await pathEnumerator.EnumerateAsync(pathEnumeratorContext, cancellationToken).ConfigureAwait(false); Console2.WriteDebugLine("Local Paths: {0}", result.LocalPaths); Console2.WriteDebugLine("Elapsed time: {0:hh\\:mm\\:ss}", result.Elapsed); Console2.WriteDebugLine("Total files: {0:n0}", result.TotalFileCount); Console2.WriteDebugLine("Total bytes: {0:n0}", result.TotalByteCount); Console2.WriteTapiEndHeader(); return(result.Paths.ToList()); }
private static void InitializeGlobalSettings() { Console2.WriteTapiStartHeader("Initialize GlobalSettings"); // A meaningful application name is encoded within monitoring data. GlobalSettings.Instance.ApplicationName = "sample-app"; // Configure for a console-based application. GlobalSettings.Instance.CommandLineModeEnabled = true; Console2.WriteDebugLine("Configured console settings."); // This will automatically write real-time entries into the transfer log. GlobalSettings.Instance.StatisticsLogEnabled = true; GlobalSettings.Instance.StatisticsLogIntervalSeconds = .5; Console2.WriteDebugLine("Configured statistics settings."); // Limit the max target rate and throw exceptions when invalid paths are specified. GlobalSettings.Instance.MaxAllowedTargetDataRateMbps = 10; Console2.WriteDebugLine("Configured miscellaneous settings."); Console2.WriteTapiEndHeader(); }
private async Task <RelativityFileShare> GetFileShareAsync(IRelativityTransferHost relativityTransferHost, int number, CancellationToken cancellationToken) { Console2.WriteTapiStartHeader("Get Specified File Share"); IFileStorageSearch fileStorageSearch = relativityTransferHost.CreateFileStorageSearch(); // Admin rights are required but this allows searching for all possible file shares within the instance. FileStorageSearchContext context = new FileStorageSearchContext { WorkspaceId = Workspace.AdminWorkspaceId }; FileStorageSearchResults results = await fileStorageSearch.SearchAsync(context, cancellationToken).ConfigureAwait(false); // Specify the cloud-based logical file share number - or just the 1st file share when all else fails. RelativityFileShare fileShare = results.GetRelativityFileShare(number) ?? results.FileShares.FirstOrDefault(); if (fileShare == null) { throw new InvalidOperationException("This operation cannot be performed because there are no file shares available."); } DisplayFileShare(fileShare); Console2.WriteTapiEndHeader(); return(fileShare); }
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(); } } }