Пример #1
0
        private static async Task <int> Main()
        {
            try
            {
                var toolsDirectory = GetToolsDirectory();

                foreach (DirectoryInfo dir in toolsDirectory.EnumerateDirectories())
                {
                    dir.Delete(true);
                }

                var cancellationTokenSource = new CancellationTokenSource();
                Console.CancelKeyPress += (_, eventArgs) =>
                {
                    // Try to cancel gracefully the first time, then abort the process the second time Ctrl+C is pressed
                    eventArgs.Cancel = !cancellationTokenSource.IsCancellationRequested;
                    cancellationTokenSource.Cancel();
                };
                var archiveExtractor = new ArchiveExtractor("mongod", "mongoexport", "mongoimport");
                var downloader       = new MongoDbDownloader(archiveExtractor, new Options());
                await downloader.RunAsync(toolsDirectory, cancellationTokenSource.Token);

                Console.WriteLine();
                Console.WriteLine($"✅ Downloaded and extracted MongoDB archives into {toolsDirectory.FullName}");
                return(0);
            }
            catch (Exception exception)
            {
                if (!(exception is OperationCanceledException))
                {
                    Console.Error.WriteLine(exception);
                }
                return(1);
            }
        }
Пример #2
0
        private static async Task <int> Main()
        {
            try
            {
                var toolsDirectory = GetToolsDirectory();

                foreach (DirectoryInfo dir in toolsDirectory.EnumerateDirectories())
                {
                    dir.Delete(true);
                }

                var cancellationTokenSource = new CancellationTokenSource();
                Console.CancelKeyPress += (_, eventArgs) =>
                {
                    // Try to cancel gracefully the first time, then abort the process the second time Ctrl+C is pressed
                    eventArgs.Cancel = !cancellationTokenSource.IsCancellationRequested;
                    cancellationTokenSource.Cancel();
                };
                var options          = new Options();
                var archiveExtractor = new ArchiveExtractor(options);
                var downloader       = new MongoDbDownloader(archiveExtractor, options);
                await downloader.RunAsync(toolsDirectory, cancellationTokenSource.Token);

                return(0);
            }
            catch (Exception exception)
            {
                if (exception is not OperationCanceledException)
                {
                    AnsiConsole.WriteException(exception, ExceptionFormats.ShortenPaths);
                }
                return(1);
            }
        }