private static async Task executeSafe(AhkEvaluationTask evalTask) { var result = new AhkResult(evalTask.ExerciseName); try { await evalTask.Execute(result); if (!evalTask.IsPreProcess) { result.WriteToFile(); } } catch (Exception ex) { AhkOutputWriter.WriteInconclusiveResult(evalTask.ExerciseName, "Unexpected error in evaluation. Nem vart hiba a kiertekeles kozben."); Console.WriteLine("Error in evaluation. Kiertekelesben hiba tortent."); Console.WriteLine(ex); if (evalTask.IsPreProcess) { throw; } } }
public static string FindFileWithCaseInsensitiveNameMatch(string filePath, AhkResult result) { var absolutePath = Path.GetFullPath(filePath); var parentDirPath = Path.GetDirectoryName(absolutePath); if (!Directory.Exists(parentDirPath)) { return(absolutePath); } var matchedFiles = Directory.EnumerateFiles(parentDirPath) .Where(f => f.ToUpperInvariant() == absolutePath.ToUpperInvariant()) .ToList(); if (matchedFiles.Count == 1) { return(matchedFiles[0]); } else if (matchedFiles.Count > 1) { result.AddProblem($"Tobb azonos nevu fajl: {filePath}"); return(matchedFiles[0]); } else { return(absolutePath); } }
public static string ToOutputString(this AhkResult result) { var output = "###ahk#" + formatExerciseName(result.ExerciseName) + "#" + result.Points.ToString(); if (result.Problems.Count > 0) { output += "#" + string.Join("\\\n", result.Problems.Select(formatMultilineOutput).ToArray()); } return(output); }
public static TryResult <T> TryRunOperation <T>(this Func <T> operation, AhkResult ahkResult, string operationNameForError) { try { return(TryResult <T> .Ok(operation())); } catch (Exception ex) { ahkResult.AddProblem(ex, $"{operationNameForError} hibat dob. {operationNameForError} throws error."); return(TryResult <T> .Failed()); } }
public static bool IsScreenshotPresent(string fileDescription, string filePath, AhkResult result) { if (string.IsNullOrEmpty(fileDescription)) { fileDescription = @"Kepernyokep fajl"; } else { fileDescription = fileDescription.Trim(); } filePath = PathsHelper.FindFileWithCaseInsensitiveNameMatch(filePath, result); if (!File.Exists(filePath)) { result.AddProblem($"{fileDescription} hianyzik."); return(false); } using (var fs = File.OpenRead(filePath)) { var hash = md5.ComputeHash(fs); if (BitConverter.ToString(hash).Replace("-", "") == knownHash) { result.AddProblem($"{fileDescription} nem lett felulirva."); return(false); } } result.Log($"{fileDescription} letezik"); return(true); }
public static void WriteToFile(this AhkResult result) { var str = result.ToOutputString(); AppendStringToFile(str); }