protected override CodeAnalysisResult AnalyseOutput(ContainerExecutionResult containerExecutionResult) { AnalysisResult GetError(string output) { var message = output .Replace(PhpError, string.Empty) .Trim() .FirstCharToUpper() .Split("on line", StringSplitOptions.RemoveEmptyEntries); return(new AnalysisResult { Level = Level.Error, Message = message.FirstOrDefault(), Line = message.LastOrDefault()?.ToIntOrDefault() ?? 0 }); } if (containerExecutionResult.Result != ExecutionResult.Success) { return(new CodeAnalysisResult { IsSuccessful = false }); } var strings = containerExecutionResult.StandardOutputSplit; var errors = strings.Where(output => output.Contains(PhpError)).Select(GetError).ToArray(); return(GetCodeAnalysisResult(errors, Enumerable.Empty <AnalysisResult>())); }
protected override CodeAnalysisResult AnalyseOutput(ContainerExecutionResult containerExecutionResult) { IEnumerable <string[]> gccOutputSplit = containerExecutionResult.StandardOutputSplit.Select(output => output.Split(GccSeparator, StringSplitOptions.RemoveEmptyEntries).Select(gccOtput => gccOtput.Trim()).ToArray()); Func <string[], AnalysisResult> GetAnalysisResultFunction(Level level) => gccOutput => new AnalysisResult { Level = level, Message = gccOutput[GccMessage].FirstCharToUpper(), Column = gccOutput[GccColumn].ToIntOrDefault(), Line = gccOutput[GccLine].ToIntOrDefault() }; var validGccOutput = gccOutputSplit .Where(message => message.Length >= GccMessage) .ToList(); var errors = validGccOutput .Where(message => message[GccLevel] == GccError) .Select(GetAnalysisResultFunction(Level.Error)) .ToArray(); var warnings = validGccOutput .Where(message => message[GccLevel] == GccWarning) .Select(GetAnalysisResultFunction(Level.Warning)); return(GetCodeAnalysisResult(errors, warnings)); }
public async Task <CodeAnalysisResult> Analyse(TestingCode code) { var tempFolder = Path.Combine(Configuration.TempFolderPath, Guid.NewGuid().ToString()); await CreateDirectoryForAnalysis(code, tempFolder); ExecutableCode executableCode = _codeFactory.GetExecutableCode(code); Command executionCommand = GetCompilationCommand(executableCode, tempFolder); Command analysisCommand = ModifyCommandForAnalysis(executionCommand); ContainerExecutionResult containerExecutionResult = await _executor.ExecuteAsync(analysisCommand); CodeAnalysisResult codeAnalysis = new CodeAnalysisResult(); if (containerExecutionResult.Result == ExecutionResult.Success) { codeAnalysis = AnalyseOutput(containerExecutionResult); } Directory.Delete(tempFolder, true); return(codeAnalysis); }
protected override CodeAnalysisResult AnalyseOutput(ContainerExecutionResult containerExecutionResult) { var output = JsonConvert.DeserializeObject <Output[]>(containerExecutionResult.StandardOutput); var currentFile = output.FirstOrDefault(); var analysisResults = _mapper.Map <AnalysisResult[]>(currentFile?.Messages); var codeAnalysisResult = new CodeAnalysisResult { AnalysisResults = analysisResults }; if (currentFile?.ErrorCount == 0) { codeAnalysisResult.IsSuccessful = true; } return(codeAnalysisResult); }
protected override CodeAnalysisResult AnalyseOutput(ContainerExecutionResult containerExecutionResult) { var freePascalOutput = containerExecutionResult.StandardOutputSplit.Skip(PascalHeadersCount).ToArray(); Func <string, AnalysisResult> GetAnalysisResultFunction(Level level, string splitBy) => pascalOutput => { var pascalOutputWithoutLevel = pascalOutput.Split(splitBy, StringSplitOptions.RemoveEmptyEntries) .Select(output => output.Trim()) .ToArray(); var nameWithPosition = pascalOutputWithoutLevel.FirstOrDefault(); var lineAndColumn = nameWithPosition? .Split('(') .LastOrDefault()? .Split(')') .FirstOrDefault()? .Split(',') .ToArray(); var message = pascalOutputWithoutLevel.LastOrDefault().FirstCharToUpper(); return(new AnalysisResult { Level = level, Message = message, Line = lineAndColumn?.FirstOrDefault()?.ToIntOrDefault() ?? 0, Column = lineAndColumn?.LastOrDefault()?.ToIntOrDefault() ?? 0 }); }; var errors = freePascalOutput.Where(output => output.Contains(PascalError)).Select(GetAnalysisResultFunction(Level.Error, PascalError)); var warnings = freePascalOutput.Where(output => output.Contains(PascalWarning)) .Select(GetAnalysisResultFunction(Level.Warning, PascalWarning)); return(GetCodeAnalysisResult(errors, warnings)); }
private static async Task <string> GetUserOutput(string outputFile, ContainerExecutionResult containerExecutionResult) => File.Exists(outputFile) ? await File.ReadAllTextAsync(outputFile) : containerExecutionResult.StandardOutput;
protected abstract CodeAnalysisResult AnalyseOutput(ContainerExecutionResult containerExecutionResult);