/// <summary> /// Merges the result1 with the result2. /// </summary> /// <param name="result1">The first result.</param> /// <param name="result2">The second result.</param> private void MergeResults(ParserResult result1, ParserResult result2) { Interlocked.Increment(ref this.mergeCount); int currentProgress = this.mergeCount; Logger.Info($"Start merge result {currentProgress}"); result1.Merge(result2); Logger.Info($"Finished merge result {currentProgress}"); }
/// <summary> /// Merges the result1 with the result2. /// </summary> /// <param name="result1">The first result.</param> /// <param name="result2">The second result.</param> private void MergeResults(ParserResult result1, ParserResult result2) { Interlocked.Increment(ref this.mergeCount); int currentProgress = this.mergeCount; Logger.DebugFormat(Resources.StartingMergingResult, currentProgress); result1.Merge(result2); Logger.DebugFormat(Resources.FinishedMergingResult, currentProgress); }
/// <summary> /// Tries to initiate the correct parsers for the given reports. /// </summary> /// <param name="reportFiles">The report files to parse.</param> /// <returns> /// The IParser instance. /// </returns> public ParserResult ParseFiles(IReadOnlyCollection <string> reportFiles) { if (reportFiles == null) { throw new ArgumentNullException(nameof(reportFiles)); } var result = new ParserResult(); int counter = 0; try { Parallel.ForEach( reportFiles, new ParallelOptions() { MaxDegreeOfParallelism = this.numberOfReportsParsedInParallel }, reportFile => { int number = Interlocked.Increment(ref counter); Logger.InfoFormat(Resources.LoadingReport, reportFile, number, reportFiles.Count); try { var report = XDocument.Load(reportFile); foreach (var parserResult in this.ParseFile(report)) { lock (this.mergeLock) { result.Merge(parserResult); } } } catch (Exception ex) when(!(ex is UnsupportedParserException)) { Logger.ErrorFormat(" " + Resources.ErrorDuringReadingReport, reportFile, GetHumanReadableFileSize(reportFile), ex.GetExceptionMessageForDisplay()); } }); } catch (AggregateException ae) { foreach (var e in ae.Flatten().InnerExceptions) { if (e is UnsupportedParserException) { throw e; } } throw; } return(result); }