Пример #1
0
        static void Main(string[] args)
        {
            ConsoleInfo consoleSettings = ConsoleInfo.CurrentInfo();

            try
            {
                //Create the dependency injection service provider
                serviceProvider = CreateServiceProvider();

                //Parse the arguments from the command line and act in accordance to whether they were parsed
                //successfully or not
                var parseResult = CommandLine.Parser.Default.ParseArguments <CommandLineOptions>(args)
                                  .WithParsed(options =>
                {
                    //Keep track of when the sort operation begins
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();

                    //Sort the integers
                    List <string> intermediateFiles = SortIntegers(options);

                    //If the option to keep the intermediate files was not specified, delete them
                    if (!options.KeepIntermediate)
                    {
                        DeleteIntermediateFiles(intermediateFiles);
                    }

                    //Display the amount of time it took to perform the entire sort operation
                    stopwatch.Stop();

                    DisplayElapsedTime(stopwatch.Elapsed);
                })
                                  .WithNotParsed(errors => Environment.ExitCode = -1);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }
            finally
            {
                ConsoleInfo.RestoreSettings(consoleSettings);
            }
        }
Пример #2
0
        /// <summary>
        /// The main entry point for this program
        /// </summary>
        /// <param name="args">The raw command line arguments</param>
        static void Main(string[] args)
        {
            ConsoleInfo consoleSettings = ConsoleInfo.CurrentInfo();

            try
            {
                //Create the dependency injection service provider
                serviceProvider = CreateServiceProvider();

                //Parse the arguments from the command line and act in accordance to whether they were parsed
                //successfully or not
                var parseResult = CommandLine.Parser.Default.ParseArguments <CommandLineOptions>(args)
                                  .WithParsed(options =>
                {
                    //Keep track of when the integer generation operation begins
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();

                    //Create the progress bar
                    var progressBar = CreateProgressBar(options.Count);

                    //Generate the integers and pass a method that will update the progress bar
                    GenerateIntegers(options, generatedIntegers => UpdateProgressBar(progressBar, generatedIntegers));

                    OnProgressBarCompleted();

                    //Display the amount of time it took to perform the entire integer generation operation
                    stopwatch.Stop();

                    DisplayElapsedTime(stopwatch.Elapsed);
                })
                                  .WithNotParsed(errors => Environment.ExitCode = -1);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }
            finally
            {
                ConsoleInfo.RestoreSettings(consoleSettings);
            }
        }