public async Task <ITransferClient> CreateClientAsync(IRelativityTransferHost host, CancellationToken token)
        {
            Console2.WriteStartHeader("Create Client");
            ITransferClient client;

            if (this._clientConfiguration.Client == WellKnownTransferClient.Unassigned)
            {
                // The CreateClientAsync method chooses the best client at runtime.
                Console2.WriteLine("TAPI is choosing the best transfer client...");
                client = await host.CreateClientAsync(this._clientConfiguration, token).ConfigureAwait(false);
            }
            else
            {
                // The CreateClient method creates the specified client.
                Console2.WriteLine("The API caller specified the {0} transfer client.", this._clientConfiguration.Client);
                client = host.CreateClient(this._clientConfiguration);
            }

            if (client == null)
            {
                throw new InvalidOperationException("This operation cannot be performed because a transfer client could not be created.");
            }

            Console2.WriteLine("TAPI created the {0} transfer client.", client.DisplayName);
            Console2.WriteEndHeader();
            return(client);
        }
        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();
            }
        }
Exemple #3
0
 public void DisplaySearchSummary(
     IDirectory sourceNode,
     Stopwatch stopWatch,
     long totalFileCount,
     long totalByteCount)
 {
     Console2.WriteLine("Local Path: {0}", sourceNode.AbsolutePath);
     Console2.WriteLine("Elapsed time: {0:hh\\:mm\\:ss}", stopWatch.Elapsed);
     Console2.WriteLine("Total files: {0:n0}", totalFileCount);
     Console2.WriteLine("Total bytes: {0:n0}", totalByteCount);
     Console2.WriteEndHeader();
 }
        public void InitializeGlobalSettings()
        {
            Console2.WriteStartHeader("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.WriteLine("Configured console settings.");

            // This will automatically write real-time entries into the transfer log.
            GlobalSettings.Instance.StatisticsLogEnabled         = true;
            GlobalSettings.Instance.StatisticsLogIntervalSeconds = .5;
            Console2.WriteLine("Configured statistics settings.");

            Console2.WriteLine("Configured miscellaneous settings.");
            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();
            }
        }
        public async Task <RelativityFileShare> GetFileShareAsync(IRelativityTransferHost host, int number, CancellationToken token)
        {
            Console2.WriteStartHeader("Get Specified file share");
            IFileStorageSearch fileStorageSearch = host.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, token).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.");
            }

            this._consolePrinter.DisplayFileShare(fileShare);
            Console2.WriteEndHeader();
            return(fileShare);
        }