public void BuildDocument() { var sponsor = new ClientSponsor(); EnvironmentContext.SetBaseDirectory(_baseDirectory); EnvironmentContext.SetGitFeaturesDisabled(_disableGitFeatures); EnvironmentContext.SetVersion(_version); if (_listener != null) { Logger.LogLevelThreshold = _logLevel; Logger.RegisterListener(_listener); sponsor.Register(_listener); } try { try { BuildDocument(_config, _manager, _baseDirectory, _outputDirectory, _pluginDirectory, _templateDirectory); } catch (AggregateException agg) when(agg.InnerException is DocfxException) { throw new DocfxException(agg.InnerException.Message); } catch (AggregateException agg) when(agg.InnerException is DocumentException) { throw new DocumentException(agg.InnerException.Message); } catch (DocfxException e) { throw new DocfxException(e.Message); } catch (DocumentException) { throw; } catch (Exception e) { throw new DocfxException(e.ToString()); } } finally { sponsor.Close(); } }
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(); } }