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);
        }
예제 #2
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);
            }
        }