示例#1
0
        /// <summary>
        /// Main entry point
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            ILogger logger = new ConsoleLogger();

            try
            {
                var parser = new CommandLineParser.CommandLineParser {
                    ShowUsageOnEmptyCommandline = true
                };
                var appArgs = new ApplicationArguments();
                parser.ExtractArgumentAttributes(appArgs);
                parser.ParseCommandLine(args);
                parser.Dispose();

                if (args.Length > 0 && !HelpWanted(args))
                {
                    var processor = new ApplicationArgumentProcessor
                    {
                        Logger            = logger,
                        ProgressIndicator = new ConsoleProgressIndicator()
                    };
                    processor.Process(appArgs);
                }
            }
            catch (Exception e)
            {
                logger.Log(e.Message);
            }
        }
示例#2
0
        public static int Main(string[] args)
        {
            ExtendLogConfigurationWithTableTarget();
            LogManager.ConfigurationReloaded += LogManager_ConfigurationReloaded;
            LogManager.ConfigurationChanged  += LogManager_ConfigurationChanged;

            SetCulture();

            var commandLineParser     = new CommandLineParser.CommandLineParser();
            var commandLineParameters = new CommandLineParameters();

            commandLineParser.ExtractArgumentAttributes(commandLineParameters);
            commandLineParser.ShowUsageOnEmptyCommandline = true;
            var version = Assembly.GetExecutingAssembly().GetName().Version;

            commandLineParser.ShowUsageHeader = $"QueryMultiDb {version} usage :";
            commandLineParser.ShowUsageFooter = "Because you're worth it.";

            try
            {
                Logger.Info($"Initialized QueryMultiDb {version}");
                Logger.Info($"Home : {HomeUrl}");
                Logger.Info($"Argument count : {args.Length}");

                foreach (var s in args)
                {
                    Logger.Trace($"Argument : '{s}'");
                }

                commandLineParser.ParseCommandLine(args);

                if (!commandLineParser.ParsingSucceeded)
                {
                    Logger.Fatal("Command line arguments analysis gracefully failed.");
                    return(-1);
                }

                // This must be set very early to be usable at any time.
                Parameters.Instance = new Parameters(commandLineParameters);

                if (Parameters.Instance.StartKeyPress)
                {
                    Console.WriteLine("Press a key to start...");
                    Console.ReadKey();
                }

                DoIt();

                return(0);
            }
            catch (CommandLineException exp)
            {
                Logger.Fatal(exp, $"Command line arguments analysis catastrophically failed. {exp.Message} ({exp.GetType().FullName})");
                //commandLineParser.ShowUsage();

                return(-2);
            }
            catch (Exception exp)
            {
                Logger.Fatal(exp, "Fatal error.");
                Logger.Fatal($"{exp}");

                return(-3);
            }
            finally
            {
                if (Parameters.IsInitialized && Parameters.Instance.StopKeyPress)
                {
                    Console.WriteLine("Press a key to stop...");
                    Console.ReadKey();
                }

                commandLineParser.Dispose();
                LogManager.Flush();
                LogManager.ConfigurationReloaded -= LogManager_ConfigurationReloaded;
                LogManager.ConfigurationChanged  -= LogManager_ConfigurationChanged;
            }
        }