/// <summary> /// Generates a report using given configuration. /// </summary> /// <param name="reportConfiguration">The report configuration.</param> /// <returns><c>true</c> if report was generated successfully; otherwise <c>false</c>.</returns> public bool GenerateReport(IReportConfiguration reportConfiguration) { if (reportConfiguration == null) { throw new ArgumentNullException(nameof(reportConfiguration)); } try { var configuration = this.GetConfiguration(); var settings = new Settings(); configuration.GetSection("settings").Bind(settings); var riskHotspotsAnalysisThresholds = new RiskHotspotsAnalysisThresholds(); configuration.GetSection("riskHotspotsAnalysisThresholds").Bind(riskHotspotsAnalysisThresholds); return(this.GenerateReport(reportConfiguration, settings, riskHotspotsAnalysisThresholds)); } catch (Exception ex) { Logger.Error(ex.GetExceptionMessageForDisplay()); Logger.Error(ex.StackTrace); #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { Console.ReadKey(); } #endif return(false); } }
/// <summary> /// Executes the report generation. /// </summary> /// <param name="reportConfiguration">The report configuration.</param> /// <param name="parserResult">The parser result generated by <see cref="CoverageReportParser"/>.</param> public void GenerateReport( IReportConfiguration reportConfiguration, ParserResult parserResult) { if (reportConfiguration == null) { throw new ArgumentNullException(nameof(reportConfiguration)); } if (parserResult == null) { throw new ArgumentNullException(nameof(parserResult)); } var configuration = this.GetConfiguration(); var settings = new Settings(); configuration.GetSection("settings").Bind(settings); var riskHotspotsAnalysisThresholds = new RiskHotspotsAnalysisThresholds(); configuration.GetSection("riskHotspotsAnalysisThresholds").Bind(riskHotspotsAnalysisThresholds); this.GenerateReport(reportConfiguration, settings, riskHotspotsAnalysisThresholds, parserResult); }
/// <summary> /// Executes the report generation. /// </summary> /// <param name="reportConfiguration">The report configuration.</param> /// <param name="settings">The settings.</param> /// <param name="riskHotspotsAnalysisThresholds">The risk hotspots analysis thresholds.</param> /// <param name="parserResult">The parser result generated by <see cref="CoverageReportParser"/>.</param> public void GenerateReport( IReportConfiguration reportConfiguration, Settings settings, RiskHotspotsAnalysisThresholds riskHotspotsAnalysisThresholds, ParserResult parserResult) { if (reportConfiguration == null) { throw new ArgumentNullException(nameof(reportConfiguration)); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (riskHotspotsAnalysisThresholds == null) { throw new ArgumentNullException(nameof(riskHotspotsAnalysisThresholds)); } if (parserResult == null) { throw new ArgumentNullException(nameof(parserResult)); } var reportContext = new ReportContext(reportConfiguration, settings); var pluginLoader = new ReflectionPluginLoader(reportConfiguration.Plugins); IReportBuilderFactory reportBuilderFactory = new ReportBuilderFactory(pluginLoader); reportContext.RiskHotspotAnalysisResult = new RiskHotspotsAnalyzer(riskHotspotsAnalysisThresholds, settings.DisableRiskHotspots) .PerformRiskHotspotAnalysis(parserResult.Assemblies); var overallHistoricCoverages = new List <Parser.Analysis.HistoricCoverage>(); var historyStorage = new HistoryStorageFactory(pluginLoader).GetHistoryStorage(reportConfiguration); if (historyStorage != null) { new HistoryParser(historyStorage, settings.MaximumNumberOfHistoricCoverageFiles, settings.NumberOfReportsParsedInParallel) .ApplyHistoricCoverage(parserResult.Assemblies, overallHistoricCoverages); reportContext.OverallHistoricCoverages = overallHistoricCoverages; } DateTime executionTime = DateTime.Now; new Reporting.ReportGenerator( new CachingFileReader(new LocalFileReader(reportConfiguration.SourceDirectories), settings.CachingDurationOfRemoteFilesInMinutes), parserResult, reportBuilderFactory.GetReportBuilders(reportContext)) .CreateReport(reportConfiguration.HistoryDirectory != null, overallHistoricCoverages, executionTime, reportConfiguration.Tag); if (historyStorage != null) { new HistoryReportGenerator(historyStorage) .CreateReport(parserResult.Assemblies, executionTime, reportConfiguration.Tag); } }
/// <summary> /// Executes the report generation. /// </summary> /// <param name="reportConfiguration">The report configuration.</param> /// <returns><c>true</c> if report was generated successfully; otherwise <c>false</c>.</returns> public bool GenerateReport(IReportConfiguration reportConfiguration) { if (reportConfiguration == null) { throw new ArgumentNullException(nameof(reportConfiguration)); } try { var configuration = this.GetConfiguration(); var reportContext = new ReportContext(reportConfiguration); configuration.GetSection("settings").Bind(reportContext.Settings); var pluginLoader = new ReflectionPluginLoader(reportConfiguration.Plugins); IReportBuilderFactory reportBuilderFactory = new ReportBuilderFactory(pluginLoader); // Set log level before validation is performed LoggerFactory.VerbosityLevel = reportContext.ReportConfiguration.VerbosityLevel; if (!new ReportConfigurationValidator(reportBuilderFactory).Validate(reportContext.ReportConfiguration)) { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { Console.ReadKey(); } #endif return(false); } var stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); DateTime executionTime = DateTime.Now; var parserResult = new CoverageReportParser( reportContext.Settings.NumberOfReportsParsedInParallel, reportConfiguration.SourceDirectories, new DefaultFilter(reportContext.ReportConfiguration.AssemblyFilters), new DefaultFilter(reportContext.ReportConfiguration.ClassFilters), new DefaultFilter(reportContext.ReportConfiguration.FileFilters)) .ParseFiles(reportContext.ReportConfiguration.ReportFiles); Logger.DebugFormat(Resources.ReportParsingTook, stopWatch.ElapsedMilliseconds / 1000d); var riskHotspotsAnalysisThresholds = new RiskHotspotsAnalysisThresholds(); configuration.GetSection("riskHotspotsAnalysisThresholds").Bind(riskHotspotsAnalysisThresholds); reportContext.RiskHotspotAnalysisResult = new RiskHotspotsAnalyzer(riskHotspotsAnalysisThresholds) .PerformRiskHotspotAnalysis(parserResult.Assemblies); var overallHistoricCoverages = new System.Collections.Generic.List <Parser.Analysis.HistoricCoverage>(); var historyStorage = new HistoryStorageFactory(pluginLoader).GetHistoryStorage(reportContext.ReportConfiguration); if (historyStorage != null) { new HistoryParser(historyStorage, reportContext.Settings.MaximumNumberOfHistoricCoverageFiles) .ApplyHistoricCoverage(parserResult.Assemblies, overallHistoricCoverages); reportContext.OverallHistoricCoverages = overallHistoricCoverages; } new Reporting.ReportGenerator( parserResult, reportBuilderFactory.GetReportBuilders(reportContext)) .CreateReport(reportContext.ReportConfiguration.HistoryDirectory != null, overallHistoricCoverages, executionTime, reportContext.ReportConfiguration.Tag); if (historyStorage != null) { new HistoryReportGenerator(historyStorage) .CreateReport(parserResult.Assemblies, executionTime, reportContext.ReportConfiguration.Tag); } stopWatch.Stop(); Logger.InfoFormat(Resources.ReportGenerationTook, stopWatch.ElapsedMilliseconds / 1000d); return(true); } catch (Exception ex) { Logger.Error(ex.GetExceptionMessageForDisplay()); Logger.Error(ex.StackTrace); #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { Console.ReadKey(); } #endif return(false); } }
/// <summary> /// Generates a report using given configuration. /// </summary> /// <param name="reportConfiguration">The report configuration.</param> /// <param name="settings">The settings.</param> /// <param name="riskHotspotsAnalysisThresholds">The risk hotspots analysis thresholds.</param> /// <returns><c>true</c> if report was generated successfully; otherwise <c>false</c>.</returns> public bool GenerateReport( IReportConfiguration reportConfiguration, Settings settings, RiskHotspotsAnalysisThresholds riskHotspotsAnalysisThresholds) { if (reportConfiguration == null) { throw new ArgumentNullException(nameof(reportConfiguration)); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (riskHotspotsAnalysisThresholds == null) { throw new ArgumentNullException(nameof(riskHotspotsAnalysisThresholds)); } try { var pluginLoader = new ReflectionPluginLoader(reportConfiguration.Plugins); IReportBuilderFactory reportBuilderFactory = new ReportBuilderFactory(pluginLoader); // Set log level before validation is performed LoggerFactory.VerbosityLevel = reportConfiguration.VerbosityLevel; Logger.Info($"{Resources.Executable}: {typeof(Program).Assembly.Location}"); Logger.Info($"{Resources.WorkingDirectory}: {Directory.GetCurrentDirectory()}"); if (!new ReportConfigurationValidator(reportBuilderFactory).Validate(reportConfiguration)) { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { Console.ReadKey(); } #endif return(false); } Logger.Debug(Resources.Settings); Logger.Debug(" " + JsonSerializer.ToJsonString(settings)); Logger.Debug(" " + JsonSerializer.ToJsonString(riskHotspotsAnalysisThresholds)); var stopWatch = Stopwatch.StartNew(); var parserResult = new CoverageReportParser( settings.NumberOfReportsParsedInParallel, settings.NumberOfReportsMergedInParallel, reportConfiguration.SourceDirectories, new DefaultFilter(reportConfiguration.AssemblyFilters), new DefaultFilter(reportConfiguration.ClassFilters), new DefaultFilter(reportConfiguration.FileFilters)) .ParseFiles(reportConfiguration.ReportFiles); Logger.DebugFormat(Resources.ReportParsingTook, stopWatch.ElapsedMilliseconds / 1000d); this.GenerateReport( reportConfiguration, settings, riskHotspotsAnalysisThresholds, parserResult); stopWatch.Stop(); Logger.InfoFormat(Resources.ReportGenerationTook, stopWatch.ElapsedMilliseconds / 1000d); return(true); } catch (Exception ex) { Logger.Error(ex.GetExceptionMessageForDisplay()); Logger.Error(ex.StackTrace); #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { Console.ReadKey(); } #endif return(false); } }