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);
        }
Exemplo n.º 2
0
        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();
            }
        }
Exemplo n.º 3
0
        public void DisplayTransferResult(ITransferResult result)
        {
            // The original request can be accessed within the transfer result.
            Console2.WriteLine();
            Console2.WriteLine("Transfer Summary");
            Console2.WriteLine("ModeName: {0}", result.Request.Name);
            Console2.WriteLine("Direction: {0}", result.Request.Direction);
            if (result.Status == TransferStatus.Successful || result.Status == TransferStatus.Canceled)
            {
                Console2.WriteLine("Result: {0}", result.Status);
            }
            else
            {
                Console2.WriteLine(ConsoleColor.Red, "Result: {0}", result.Status);
                if (result.TransferError != null)
                {
                    Console2.WriteLine(ConsoleColor.Red, "Error: {0}", result.TransferError.Message);
                }
                else
                {
                    Console2.WriteLine(ConsoleColor.Red, "Error: Check the error log for more details.");
                }
            }

            Console2.WriteLine("Elapsed time: {0:hh\\:mm\\:ss}", result.Elapsed);
            Console2.WriteLine("Total files: Files: {0:n0}", result.TotalTransferredFiles);
            Console2.WriteLine("Total bytes: Files: {0:n0}", result.TotalTransferredBytes);
            Console2.WriteLine("Total files not found: {0:n0}", result.TotalFilesNotFound);
            Console2.WriteLine("Total bad path errors: {0:n0}", result.TotalBadPathErrors);
            Console2.WriteLine("Data rate: {0:#.##} Mbps", result.TransferRateMbps);
            Console2.WriteLine("Retry count: {0}", result.RetryCount);
        }
        public async Task ChangeDataRateAsync(ITransferJob job, CancellationToken token)
        {
            if (job.IsDataRateChangeSupported)
            {
                Console2.WriteLine("Changing the transfer data rate...");
                await job.ChangeDataRateAsync(0, 10, token).ConfigureAwait(false);

                Console2.WriteLine("Changed the transfer data rate.");
            }
        }
Exemplo n.º 5
0
        public void DisplayFileShare(RelativityFileShare fileShare)
        {
            Console2.WriteLine("Artifact ID: {0}", fileShare.ArtifactId);
            Console2.WriteLine("ModeName: {0}", fileShare.Name);
            Console2.WriteLine("UNC Path: {0}", fileShare.Url);
            Console2.WriteLine("Cloud Instance: {0}", fileShare.CloudInstance);

            // RelativityOne specific properties.
            Console2.WriteLine("Number: {0}", fileShare.Number);
            Console2.WriteLine("Tenant ID: {0}", fileShare.TenantId);
        }
Exemplo n.º 6
0
 public static void WriteTerminateLine(int exitCode)
 {
     Console2.WriteLine();
     Console2.WriteLine(
         exitCode == 0
             ? "The sample successfully completed. Exit code: {0}"
             : "The sample failed to complete. Exit code: {0}",
         exitCode);
     Console2.WriteLine("Press any key to terminate.");
     Console.ReadLine();
 }
Exemplo n.º 7
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();
        }
        public TransferContext CreateTransferContext()
        {
            // The context object is used to decouple operations such as progress from other TAPI objects.
            TransferContext context = new TransferContext {
                StatisticsRateSeconds = 0.5, StatisticsEnabled = true
            };

            context.TransferPathIssue += (sender, args) =>
            {
                Console2.WriteLine("Event=TransferPathIssue, Attributes={0}", args.Issue.Attributes);
            };

            context.TransferRequest += (sender, args) =>
            {
                Console2.WriteLine("Event=TransferRequest, Status={0}", args.Status);
            };

            context.TransferPathProgress += (sender, args) =>
            {
                Console2.WriteLine(
                    "Event=TransferPathProgress, Filename={0}, Status={1}",
                    Path.GetFileName(args.Path.SourcePath),
                    args.Status);
            };

            context.TransferJobRetry += (sender, args) =>
            {
                Console2.WriteLine("Event=TransferJobRetry, Retry={0}", args.Count);
            };

            context.TransferStatistics += (sender, args) =>
            {
                // Progress has already factored in file-level vs byte-level progress.
                Console2.WriteLine(
                    "Event=TransferStatistics, Progress: {0:00.00}%, Transfer rate: {1:00.00} Mbps, Remaining: {2:hh\\:mm\\:ss}",
                    args.Statistics.Progress,
                    args.Statistics.TransferRateMbps,
                    args.Statistics.RemainingTime);
            };

            return(context);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing">
        /// <c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.
        /// </param>
        private void Dispose(bool disposing)
        {
            if (this.disposed)
            {
                return;
            }

            if (disposing)
            {
                if (!string.IsNullOrEmpty(this.Path) && Directory.Exists(this.Path))
                {
                    try
                    {
                        string[] files = Directory.GetFiles(this.Path, "*", SearchOption.AllDirectories);
                        foreach (string file in files)
                        {
                            FileAttributes attributes = File.GetAttributes(file);
                            File.SetAttributes(file, attributes & ~FileAttributes.ReadOnly);
                            File.Delete(file);
                        }

                        Directory.Delete(this.Path, true);
                    }
                    catch (IOException e)
                    {
                        Console2.WriteLine(
                            ConsoleColor.Red,
                            $"Failed to tear down the '{this.Path}' temp directory due to an I/O issue. Exception: "
                            + e);
                    }
                    catch (UnauthorizedAccessException e)
                    {
                        Console2.WriteLine(
                            ConsoleColor.Red,
                            $"Failed to tear down the '{this.Path}' temp directory due to unauthorized access. Exception: "
                            + e);
                    }
                }
            }

            this.disposed = true;
        }
Exemplo n.º 11
0
        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();
            }
        }
Exemplo n.º 12
0
        public static void Main(string[] args)
        {
            ClientConfigurationFactory clientConfigurationFactory = new ClientConfigurationFactory();

            Console2.Initialize();

            int exitCode = 1;

            try
            {
                //Create specific ClientConfiguration based on TransferMode in app.config
                ClientConfiguration clientConfiguration = clientConfigurationFactory.Create();

                SampleRunner sampleRunner = new SampleRunner(clientConfiguration);

                sampleRunner.InitializeGlobalSettings();

                Console2.WriteLine($"Relativity {sampleRunner.TransferModeName} Transfer Sample");

                Task.Run(
                    async() =>
                {
                    // Note: the RelativityTransferLog demonstrates how to create an ITransferLog implementation for Relativity Logging.
                    using (ITransferLog transferLog = sampleRunner.CreateTransferLog())
                        using (IRelativityTransferHost host = sampleRunner.CreateRelativityTransferHost(transferLog)
                               )
                            using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource())
                            {
                                CancellationToken token = cancellationTokenSource.Token;
                                await DemoTransferAsync(host, token, sampleRunner).ConfigureAwait(false);
                                exitCode = 0;
                            }
                }).GetAwaiter().GetResult();
            }
            catch (TransferException e)
            {
                if (e.Fatal)
                {
                    Console2.WriteLine(ConsoleColor.Red, "A fatal transfer failure has occurred. Error: " + e);
                }
                else
                {
                    Console2.WriteLine(ConsoleColor.Red, "A non-fatal transfer failure has occurred. Error: " + e);
                }
            }
            catch (ApplicationException e)
            {
                // No need to include the stacktrace.
                Console2.WriteLine(ConsoleColor.Red, e.Message);
            }
            catch (ConfigurationValueInvalidException e)
            {
                // No need to include the stacktrace.
                Console2.WriteLine(ConsoleColor.Red, e.Message);
            }
            catch (Exception e)
            {
                Console2.WriteLine(ConsoleColor.Red, "An unexpected error has occurred. Error: " + e);
            }
            finally
            {
                Console2.WriteTerminateLine(exitCode);
                Environment.Exit(exitCode);
            }
        }