private async Task HandleDiffAnalysis(PerformDiffAnalysisMessage input) { _logger.LogInformation($"Processing Analysis Id: {input.Id}"); using (var scope = _scopeFactory.CreateScope()) { var analysisRepo = scope.ServiceProvider.GetRequiredService <IDiffAnalysisRepository>(); var analizer = scope.ServiceProvider.GetRequiredService <IDiffAnalyzer>(); var analysis = await analysisRepo.GetAnalysis(input.Id); //If analysis doesnt exists in the DB if (analysis == null) { _logger.LogWarning($"Analysis Not Found: {input.Id}"); return; } // if analysis already analyzed we discard the input if (analysis.Analyzed) { _logger.LogWarning($"Analysis already processed: {input.Id}"); return; } // if we have both left and right arguments we publish a perform Diff Analysis message if (analysis.Left != null && analysis.Right != null) { _logger.LogInformation($"Performing Analysis: {input.Id}"); // Generate the diff for this analysis var result = analizer.GenerateDiff(analysis.Left, analysis.Right); _logger.LogInformation($"Found {result.Segments.Count} diff segments"); // Map analized Diff Segments to the existing Analysis DB model result.Segments.ForEach(s => analysis.Segments.Add( new Data.Models.DiffSegment() { Offset = s.Offset, Length = s.Length })); // Mark the analysis as completed. analysis.Analyzed = true; // Save the resulting analysis entity to the DB. await analysisRepo.SaveAll(); _logger.LogInformation($"Analysis completed: {input.Id}"); } } }
private async Task HandleIngestionInput(AddDiffInputMessage input) { _logger.LogInformation($"Processing Input: {input.Id}"); using (var scope = _scopeFactory.CreateScope()) { var analysisRepo = scope.ServiceProvider.GetRequiredService <IDiffAnalysisRepository>(); //var mapper = scope.ServiceProvider.GetRequiredService<IMapper>(); var analysis = await analysisRepo.GetAnalysis(input.Id); var persistChanges = false; //If analysis doesnt exists in the DB if (analysis == null) { _logger.LogInformation($"Analysis Not Found: {input.Id}"); analysis = new DiffAnalysis() { Id = input.Id }; analysisRepo.Add(analysis); persistChanges = true; } // if analysis already analyzed we discard the input if (analysis.Analyzed) { _logger.LogInformation($"Analysis already analyzed: {input.Id}. Discarding..."); return; } // If input is left argument and doesnt already exist if (input.IsLeft && analysis.Left == null) { _logger.LogInformation($"Persisting Left Argument: {input.Id}"); analysis.Left = input.Input; persistChanges = true; } // If input is right argument and doesnt already exist if (!input.IsLeft && analysis.Right == null) { _logger.LogInformation($"Persisting Right Argument: {input.Id}"); analysis.Right = input.Input; persistChanges = true; } if (persistChanges) { await analysisRepo.SaveAll(); } // if we have both left and right arguments we publish a perform Diff Analysis message if (analysis.Left != null && analysis.Right != null) { _logger.LogInformation($"Analysis ready to be analyzed: {input.Id}. Publishing PerformDiffAnalysisMessage to bus."); var message = new PerformDiffAnalysisMessage(analysis.Id); await _serviceBus.PublishAsync(message); } } }