/// <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); } }
public void SaveLoadData() { ISearchHistoryStorage storage = HistoryStorageFactory.getFileHistoryStorage(StorageType.File); /**********************/ /* FIRST SET */ /**********************/ ISearchHistoryData searchData = SearchHistoryDataFacory.createSearchHistoryData(SearchType.People); DateTime timeStamp = DateTime.Now; /* Generate random search IDs */ Random rnd = new Random(); List <string> searchIds = new List <string>(); for (int i = 0; i < 100; i++) { searchIds.Add(rnd.Next(2000, 3000).ToString()); } string coreId = "55555"; searchData.CoreId = coreId; searchData.SearchIds = searchIds; searchData.SearchTimestamp = timeStamp; storage.saveSearchHistoryData(searchData); /**********************/ /* SECOND SET */ /**********************/ ISearchHistoryData s_searchData = SearchHistoryDataFacory.createSearchHistoryData(SearchType.People); DateTime s_timeStamp = DateTime.Now; /* Generate random search IDs */ Random s_rnd = new Random(); List <string> s_searchIds = new List <string>(); for (int s_i = 0; s_i < 533; s_i++) { s_searchIds.Add(s_rnd.Next(2000, 3000).ToString()); } string s_coreId = "666666"; s_searchData.CoreId = s_coreId; s_searchData.SearchIds = s_searchIds; s_searchData.SearchTimestamp = s_timeStamp; storage.saveSearchHistoryData(s_searchData); /**********************/ /* THIRD SET */ /**********************/ ISearchHistoryData t_searchData = SearchHistoryDataFacory.createSearchHistoryData(SearchType.People); DateTime t_timeStamp = new DateTime(2012, 01, 01); /* Generate random search IDs */ Random t_rnd = new Random(); List <string> t_searchIds = new List <string>(); for (int t_i = 0; t_i < 781; t_i++) { t_searchIds.Add(t_rnd.Next(2000, 3000).ToString()); } string t_coreId = "666666"; t_searchData.CoreId = t_coreId; t_searchData.SearchIds = t_searchIds; t_searchData.SearchTimestamp = t_timeStamp; storage.saveSearchHistoryData(t_searchData); /**********************/ /* FIRST RESULT */ /**********************/ ISearchHistoryData loadedData = storage.loadSearchHistoryData(coreId, SearchType.People); Assert.AreEqual(loadedData.CoreId, coreId); Assert.AreEqual(loadedData.SearchDataType, SearchType.People); Assert.AreEqual(loadedData.SearchIds.Count, searchIds.Count); for (int f_r = 0; f_r < searchIds.Count; f_r++) { Assert.AreEqual(loadedData.SearchIds[f_r], searchIds[f_r]); } /**********************/ /* SECOND RESULT */ /**********************/ ISearchHistoryData s_loadedData = storage.loadSearchHistoryData(s_coreId, SearchType.People); Assert.AreEqual(s_loadedData.CoreId, s_coreId); Assert.AreEqual(s_loadedData.SearchDataType, SearchType.People); Assert.AreEqual(s_loadedData.SearchIds.Count, (s_searchIds.Count + t_searchIds.Count)); }