Skip to content

Commit 3813746

Browse files
add frontend
1 parent 265f534 commit 3813746

17 files changed

+267
-6
lines changed

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"cSpell.words": [
33
"CXXFLAGS",
4+
"Meng",
5+
"cdgr",
46
"cout",
57
"ctxdl",
68
"endl",

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ This is a backend for grading C++ code in a secure and controlled manner.
99
> docker run -p 8080 --privileged code-grader
1010
```
1111

12+
## API
13+
14+
### Grade Code Request
15+
16+
### Retrieve Grade Result
17+
1218
## Author
1319

1420
Huang Meng \

backend/types/GradeResult.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type GradeResultStatus int
55
const (
66
GradeResultSuccess GradeResultStatus = iota
77
GradeResultWrongAnswer
8+
GradeResultInternalError
89
GradeResultCompilationError
910
GradeResultTimeLimitExceed
1011
GradeResultMemoryExceed

frontend/CdgrFrontend.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using System.Net.Http;
4+
5+
namespace CdgrFrontend
6+
{
7+
public class CodeGraderClient
8+
{
9+
string apiKey;
10+
string url;
11+
12+
CodeGraderClient(string url, string apiKey = "")
13+
{
14+
this.apiKey = apiKey;
15+
this.url = url;
16+
}
17+
18+
async Task<GradeResult> GradeCode(string testcaseName, string userCode)
19+
{
20+
21+
var client = new HttpClient();
22+
var content = new StringContent(userCode);
23+
content.Headers.Add("testcase-name", testcaseName);
24+
25+
var res = await client.PostAsync(url + "/grade", null);
26+
27+
var result = await res.Content.ReadAsStringAsync();
28+
return new GradeResult{};
29+
}
30+
}
31+
32+
public enum GradeResultStatus {
33+
Success,
34+
WrongAnswer,
35+
ErrCompilation,
36+
ErrInternal,
37+
RuntimeExceed,
38+
MemoryLimitExceed
39+
40+
}
41+
42+
public struct GradeResult {
43+
public GradeResultStatus Status;
44+
public string Msg;
45+
46+
}
47+
48+
}

frontend/frontend.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// <autogenerated />
2+
using System;
3+
using System.Reflection;
4+
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v5.0", FrameworkDisplayName = "")]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
// Runtime Version:4.0.30319.42000
5+
//
6+
// Changes to this file may cause incorrect behavior and will be lost if
7+
// the code is regenerated.
8+
// </auto-generated>
9+
//------------------------------------------------------------------------------
10+
11+
using System;
12+
using System.Reflection;
13+
14+
[assembly: System.Reflection.AssemblyCompanyAttribute("frontend")]
15+
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
16+
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
17+
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
18+
[assembly: System.Reflection.AssemblyProductAttribute("frontend")]
19+
[assembly: System.Reflection.AssemblyTitleAttribute("frontend")]
20+
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
21+
22+
// Generated by the MSBuild WriteCodeFragment class.
23+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3855aa4b59b50d42d14cfc63ea8323aafd174f97
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
is_global = true
2+
build_property.TargetFramework = net5.0
3+
build_property.TargetPlatformMinVersion =
4+
build_property.UsingMicrosoftNETSdkWeb =
5+
build_property.ProjectTypeGuids =
6+
build_property.PublishSingleFile =
7+
build_property.IncludeAllContentForSelfExtract =
8+
build_property._SupportedPlatformList = Android,iOS,Linux,macOS,Windows
119 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)