diff --git a/src/Ilmhub.Judge.Wrapper/Exceptions/JudgeProcessFailedException.cs b/src/Ilmhub.Judge.Wrapper/Exceptions/JudgeProcessFailedException.cs index cc3b8bc..75644de 100644 --- a/src/Ilmhub.Judge.Wrapper/Exceptions/JudgeProcessFailedException.cs +++ b/src/Ilmhub.Judge.Wrapper/Exceptions/JudgeProcessFailedException.cs @@ -4,4 +4,4 @@ public class JudgeProcessFailedException : Exception { public JudgeProcessFailedException(string message, Exception innerException) : base(message, innerException: innerException) { } -} +} \ No newline at end of file diff --git a/src/Ilmhub.Judge.Wrapper/Exceptions/LinuxCommandFailedException.cs b/src/Ilmhub.Judge.Wrapper/Exceptions/LinuxCommandFailedException.cs index d78bc85..fd3ac0d 100644 --- a/src/Ilmhub.Judge.Wrapper/Exceptions/LinuxCommandFailedException.cs +++ b/src/Ilmhub.Judge.Wrapper/Exceptions/LinuxCommandFailedException.cs @@ -4,4 +4,4 @@ public class LinuxCommandFailedException : Exception { public LinuxCommandFailedException(string command, string arguments, string output, string error) : base($"Linux command failed. Command: {command}, Arguments: {arguments}, Output: {output}, Error: {error}") { } -} +} \ No newline at end of file diff --git a/src/Ilmhub.Judge.Wrapper/JudgeWrapper.cs b/src/Ilmhub.Judge.Wrapper/JudgeWrapper.cs index dd56214..23ea1a9 100644 --- a/src/Ilmhub.Judge.Wrapper/JudgeWrapper.cs +++ b/src/Ilmhub.Judge.Wrapper/JudgeWrapper.cs @@ -19,7 +19,7 @@ public class JudgeWrapper : IJudgeWrapper private readonly ILinuxCommandLine cli; public JudgeWrapper(ILogger logger, ILinuxCommandLine cli) - { + { this.logger = logger; this.cli = cli; } @@ -47,7 +47,7 @@ public async ValueTask ExecuteJudgerAsync(IExecutionRequest re var output = process.StandardOutput.ReadToEnd(); var error = process.StandardError.ReadToEnd(); logger.LogInformation( - "Libjudger.so process finished. Exit code: {exitCode}, Output: {output}, Error: {error}.", + "Libjudger.so process finished. Exit code: {exitCode}, Output: {output}, Error: {error}.", process.ExitCode, output, error); @@ -57,12 +57,12 @@ public async ValueTask ExecuteJudgerAsync(IExecutionRequest re resultObject.Output = output; return resultObject; } - catch(JsonException jsonException) + catch (JsonException jsonException) { logger.LogError(jsonException, "Failed to deserialize Libjudger.so output."); throw; } - catch(Exception ex) + catch (Exception ex) { logger.LogWarning(ex, "Libjudger.so process faild while executing {executable}.", request.ExecutablePath); throw new JudgeProcessFailedException($"Libjudger.so process faild while executing {request.ExecutablePath}", ex); @@ -78,7 +78,7 @@ private string BuildArguments(IExecutionRequest request) AppendSingleArgument(builder, "error_path", request.ErrorPath); AppendSingleArgument(builder, "log_path", request.LogPath); AppendSingleArgument(builder, "seccomp_rule_name", request.SeccompRuleName); - + // below values have defualt value so we dont need to null-check builder.Append($" --max_cpu_time={request.CpuTime}"); builder.Append($" --max_real_time={request.RealTime}"); @@ -92,22 +92,22 @@ private string BuildArguments(IExecutionRequest request) builder.Append($" --env=\"PATH={Environment.GetEnvironmentVariable("PATH")}\""); - if(request.Environments?.Any() is true) - foreach(var env in request.Environments) + if (request.Environments?.Any() is true) + foreach (var env in request.Environments) AppendSingleArgument(builder, "env", env); - if(request.Arguments?.Any() is true) - foreach(var arg in request.Arguments) + if (request.Arguments?.Any() is true) + foreach (var arg in request.Arguments) AppendSingleArgument(builder, "args", arg); - + logger.LogInformation("Libjudger arguments: {arguments}", builder.ToString()); return builder.ToString(); } - private void AppendSingleArgument(StringBuilder builder, string key, string value) + private void AppendSingleArgument(StringBuilder builder, string key, string value) { - if(string.IsNullOrWhiteSpace(value) is false) + if (string.IsNullOrWhiteSpace(value) is false) builder.Append($" --{key}={value}"); } } \ No newline at end of file diff --git a/src/Ilmhub.Judge.Wrapper/LinuxCommandLine.cs b/src/Ilmhub.Judge.Wrapper/LinuxCommandLine.cs index 20a8bfd..9a2d28d 100644 --- a/src/Ilmhub.Judge.Wrapper/LinuxCommandLine.cs +++ b/src/Ilmhub.Judge.Wrapper/LinuxCommandLine.cs @@ -20,7 +20,7 @@ public ValueTask ChangePathModeAsync(string mode, string path, bool recursive = public ValueTask AddPathOwnerAsync(string owner, string path, bool recursive = false, CancellationToken cancellationToken = default) => RunCommandAsync("chown", $"{(recursive ? "-R " : "")}{owner} {path}"); - + // TODO: People assume this method never throws. Add try catch in the method body here public async ValueTask<(bool IsSuccess, string Output, string ErrorMessage)> TryRunAsync( string command, @@ -49,7 +49,7 @@ public ValueTask AddPathOwnerAsync(string owner, string path, bool recursive = f public async ValueTask RunCommandAsync(string command, string arguments, CancellationToken cancellationToken = default) { var processResult = await TryRunAsync(command, arguments, cancellationToken); - if(processResult.IsSuccess is false) + if (processResult.IsSuccess is false) throw new LinuxCommandFailedException(command, arguments, processResult.Output, processResult.ErrorMessage); } @@ -69,4 +69,4 @@ public IEnumerable SplitCommand(string command) return arguments; } -} +} \ No newline at end of file diff --git a/src/Ilmhub.Judge.Wrapper/Models/ExecutionResult.cs b/src/Ilmhub.Judge.Wrapper/Models/ExecutionResult.cs index 3c60bed..9feb52d 100644 --- a/src/Ilmhub.Judge.Wrapper/Models/ExecutionResult.cs +++ b/src/Ilmhub.Judge.Wrapper/Models/ExecutionResult.cs @@ -22,4 +22,4 @@ public class ExecutionResult : IExecutionResult public EExecutionError Error { get; set; } public string Output { get; set; } public string ErrorMessage { get; set; } -} +} \ No newline at end of file diff --git a/src/Ilmhub.Judge.Wrapper/ServiceCollectionExtensions.cs b/src/Ilmhub.Judge.Wrapper/ServiceCollectionExtensions.cs index d580b40..c3dd198 100644 --- a/src/Ilmhub.Judge.Wrapper/ServiceCollectionExtensions.cs +++ b/src/Ilmhub.Judge.Wrapper/ServiceCollectionExtensions.cs @@ -11,4 +11,4 @@ public static IServiceCollection AddIlmhubJudgeWrapper(this IServiceCollection s services.AddTransient(); return services; } -} +} \ No newline at end of file