private async Task <IDEProjectResult> AnalyzeProjectFiles(string projectPath, string fileContent, string filePath, List <string> preportReferences, List <string> currentReferences) { try { var configuration = new AnalyzerConfiguration(LanguageOptions.CSharp) { MetaDataSettings = { LiteralExpressions = true, MethodInvocations = true, ReferenceData = true, Annotations = true, DeclarationNodes = true, LoadBuildData = true, LocationData = true, InterfaceDeclarations = true } }; CodeAnalyzerByLanguage analyzerByLanguage = new CodeAnalyzerByLanguage(configuration, _logger); var analyzer = analyzerByLanguage.GetLanguageAnalyzerByFileType(Path.GetExtension(filePath)); var ideProjectResult = await analyzer.AnalyzeFile(projectPath, filePath, fileContent, preportReferences, currentReferences); return(ideProjectResult); } catch (Exception ex) { _logger.LogError(ex, "Error while analyzing files"); } finally { CommonUtils.RunGarbageCollection(_logger, "PortingAssistantAnalysisHandler.AnalyzeFileIncremental"); } return(null); }
private async Task <List <AnalyzerResult> > RunCoderlyzerAnalysis(string solutionFilename, List <string> projects) { MemoryUtils.LogSystemInfo(_logger); MemoryUtils.LogSolutiontSize(_logger, solutionFilename); _logger.LogInformation("Memory usage before RunCoderlyzerAnalysis: "); MemoryUtils.LogMemoryConsumption(_logger); var configuration = GetAnalyzerConfiguration(projects); CodeAnalyzerByLanguage analyzer = new CodeAnalyzerByLanguage(configuration, _logger); var analyzerResults = await analyzer.AnalyzeSolution(solutionFilename); _logger.LogInformation("Memory usage after RunCoderlyzerAnalysis: "); MemoryUtils.LogMemoryConsumption(_logger); return(analyzerResults); }
public async IAsyncEnumerable <ProjectAnalysisResult> AnalyzeSolutionGeneratorAsync(string solutionFilename, List <string> projects, string targetFramework = "net6.0") { var configuration = GetAnalyzerConfiguration(projects); CodeAnalyzerByLanguage analyzer = new CodeAnalyzerByLanguage(configuration, _logger); var resultEnumerator = analyzer.AnalyzeSolutionGeneratorAsync(solutionFilename).GetAsyncEnumerator(); try { SolutionPort solutionPort = new SolutionPort(solutionFilename); while (await resultEnumerator.MoveNextAsync().ConfigureAwait(false)) { var result = resultEnumerator.Current; var projectPath = result?.ProjectResult?.ProjectFilePath; PortCoreConfiguration projectConfiguration = new PortCoreConfiguration() { ProjectPath = projectPath, UseDefaultRules = true, TargetVersions = new List <string> { targetFramework }, PortCode = false, PortProject = false }; var projectResult = solutionPort.RunProject(result, projectConfiguration); var analysisActions = AnalyzeActions(new List <string> { projectPath }, targetFramework, new List <AnalyzerResult> { result }, solutionFilename); var analysisResult = AnalyzeProject(projectPath, solutionFilename, new List <AnalyzerResult> { result }, analysisActions, isIncremental: false, targetFramework); result.Dispose(); yield return(analysisResult); } } finally { await resultEnumerator.DisposeAsync(); } }