Esempio n. 1
0
        private static int ExecSubCommand(string[] args)
        {
            var consoleLogListener = new ConsoleLogListener();
            var replayListener     = new ReplayLogListener();

            replayListener.AddListener(consoleLogListener);
            Logger.RegisterListener(replayListener);

            CommandController controller = null;
            ISubCommand       command;

            try
            {
                controller = ArgsParser.Instance.Parse(args);
                command    = controller.Create();
            }
            catch (System.IO.FileNotFoundException fe)
            {
                Logger.LogError(fe.Message);
                return(1);
            }
            catch (Exception e) when(e is OptionParserException || e is InvalidOptionException)
            {
                Logger.LogError(e.Message);
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return(1);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.ToString());
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return(1);
            }

            replayListener.Replay = command.AllowReplay;

            var context = new SubCommandRunningContext();

            try
            {
                ThreadPool.SetMinThreads(4, 4);
                using (new PerformanceScope("executing", LogLevel.Info))
                {
                    command.Exec(context);
                }

                return(0);
            }
            catch (DocumentException de)
            {
                Logger.LogError(de.Message);
                return(1);
            }
            catch (DocfxException de)
            {
                Logger.LogError(de.Message);
                return(1);
            }
            catch (Exception e)
            {
                Logger.LogError(e.ToString());
                return(1);
            }
        }
Esempio n. 2
0
        internal static int ExecSubCommand(string[] args)
        {
            EnvironmentContext.SetVersion(typeof(Program).Assembly.GetName().Version.ToString());

            var consoleLogListener    = new ConsoleLogListener();
            var aggregatedLogListener = new AggregatedLogListener();

            Logger.RegisterListener(consoleLogListener);
            Logger.RegisterListener(aggregatedLogListener);

            CommandController controller = null;
            ISubCommand       command;

            try
            {
                controller = ArgsParser.Instance.Parse(args);
                command    = controller.Create();
            }
            catch (Exception e) when(e is System.IO.FileNotFoundException fe || e is DocfxException || e is JsonSerializationException)
            {
                Logger.LogError(e.Message);
                return(1);
            }
            catch (Exception e) when(e is OptionParserException || e is InvalidOptionException)
            {
                Logger.LogError(e.Message);
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return(1);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.ToString());
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return(1);
            }

            if (command.AllowReplay)
            {
                Logger.RegisterAsyncListener(new AggregatedLogListener(aggregatedLogListener));
            }

            Logger.UnregisterListener(aggregatedLogListener);

            var context            = new SubCommandRunningContext();
            PerformanceScope scope = null;

            try
            {
                // TODO: For now reuse AllowReplay for overall elapsed time statistics
                if (command.AllowReplay)
                {
                    scope = new PerformanceScope(string.Empty, LogLevel.Info);
                }

                command.Exec(context);
                return(0);
            }
            catch (Exception e) when(e is DocumentException || e is DocfxException)
            {
                Logger.LogError(e.Message);
                return(1);
            }
            catch (Exception e)
            {
                Logger.LogError(e.ToString());
                return(1);
            }
            finally
            {
                scope?.Dispose();
            }
        }
Esempio n. 3
0
        private static int ExecSubCommand(string[] args)
        {
            var consoleLogListener = new ConsoleLogListener();
            var replayListener     = new ReplayLogListener();

            replayListener.AddListener(consoleLogListener);
            Logger.RegisterListener(replayListener);

            CommandController controller = null;
            ISubCommand       command;

            try
            {
                controller = ArgsParser.Instance.Parse(args);
                command    = controller.Create();
            }
            catch (System.IO.FileNotFoundException fe)
            {
                Logger.LogError(fe.Message);
                return(1);
            }
            catch (OptionParserException e)
            {
                Logger.LogError(e.Message);
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return(1);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.ToString());
                if (controller != null)
                {
                    Console.WriteLine(controller.GetHelpText());
                }
                return(1);
            }

            if (!(command is ILoggable))
            {
                replayListener.Replay = false;
            }

            var context = new SubCommandRunningContext();

            try
            {
                command.Exec(context);
                return(0);
            }
            catch (DocfxException de)
            {
                Logger.LogError(de.Message);
                return(1);
            }
            catch (Exception e)
            {
                Logger.LogError(e.ToString());
                return(1);
            }
        }