2
2
3
3
![ CI] ( https://github.com/StardustDL/judge0-dotnet/workflows/CI/badge.svg ) ![ CD] ( https://github.com/StardustDL/judge0-dotnet/workflows/CD/badge.svg ) ![ License] ( https://img.shields.io/github/license/StardustDL/judge0-dotnet.svg ) ![ downloads] ( https://img.shields.io/nuget/dt/Judge0 )
4
4
5
- Client SDK for Judge0 RESTful API.
5
+ Client SDK for [ Judge0] ( https://github.com/judge0/api ) RESTful API.
6
+
7
+ ## Features
8
+
9
+ - Authentication
10
+ - Authorization
11
+ - Submissions
12
+ - Statuses and Languages
13
+ - System and Configuration
14
+ - Statistics
15
+ - Health Check
16
+ - Information
17
+
18
+ ## Versions
6
19
7
20
Judge0 version supported status:
8
21
@@ -11,7 +24,6 @@ Judge0 version supported status:
11
24
- [x] 1.7.1
12
25
- [x] 1.7.0
13
26
- [x] 1.6.0
14
- - [x] 1.5.0 (partially)
15
27
16
28
## Install
17
29
@@ -21,16 +33,190 @@ dotnet add package Judge0
21
33
22
34
## Usage
23
35
36
+ ### Create Service
37
+
24
38
``` csharp
25
39
var client = new HttpClient
26
40
{
27
41
BaseAddress = new Uri (" apiUri" )
28
42
};
29
43
IJudge0Service service = new Judge0Service (client );
44
+ ```
45
+
46
+ ### Authentication & Authorization
47
+
48
+ ``` csharp
49
+ public async Task AuthenticateAndAuthorize ()
50
+ {
51
+ var result = await service .AuthenticationService .Authenticate (" token" );
52
+ Assert .IsTrue (result .IsSuccessStatusCode );
53
+
54
+ result = await service .AuthenticationService .Authorize (" user" );
55
+ Assert .IsTrue (result .IsSuccessStatusCode );
56
+ }
57
+ ```
58
+
59
+
60
+ ### Submission
61
+
62
+ ``` csharp
63
+ public async Task CreateGetAndDelete ()
64
+ {
65
+ var result = await service .SubmissionsService .Create (new Submission
66
+ {
67
+ source_code = " #include <stdio.h>\n\n int main(void) {\n char name[10];\n scanf(\" %s\" , name);\n printf(\" hello, %s\\ n\" , name);\n return 0;\n }" ,
68
+ stdin = " world" ,
69
+ language_id = 50 ,
70
+ });
71
+ Assert .IsTrue (result .IsSuccessStatusCode );
72
+ string token = result .Result .token ;
73
+
74
+ while (true )
75
+ {
76
+ await Task .Delay (TimeSpan .FromSeconds (1 ));
77
+ var res = await service .SubmissionsService .Get (token );
78
+ Assert .IsTrue (res .IsSuccessStatusCode );
79
+ if (res .Result .status ? .id > 2 )
80
+ {
81
+ Assert .IsNotNull (res .Result .stdout );
82
+ StringAssert .StartsWith (res .Result .stdout , " hello, world" );
83
+ break ;
84
+ }
85
+ }
86
+
87
+ var del = await service .SubmissionsService .Delete (token );
88
+ Assert .IsTrue (del .IsSuccessStatusCode );
89
+ }
90
+
91
+ public async Task CreateWaitGetAndDelete ()
92
+ {
93
+ var result = await service .SubmissionsService .CreateAndWait (new Submission
94
+ {
95
+ source_code = " #include <stdio.h>\n\n int main(void) {\n char name[10];\n scanf(\" %s\" , name);\n printf(\" hello, %s\\ n\" , name);\n return 0;\n }" ,
96
+ stdin = " world" ,
97
+ language_id = 50 ,
98
+ });
99
+ Assert .IsTrue (result .IsSuccessStatusCode );
100
+ string token = result .Result .token ;
101
+
102
+ Assert .IsNotNull (result .Result .stdout );
103
+ StringAssert .StartsWith (result .Result .stdout , " hello, world" );
104
+
105
+ var del = await service .SubmissionsService .Delete (token );
106
+ Assert .IsTrue (del .IsSuccessStatusCode );
107
+ }
108
+
109
+ public async Task GetPaging ()
110
+ {
111
+ var result = await service .SubmissionsService .GetPaging ();
112
+ Assert .IsTrue (result .IsSuccessStatusCode );
113
+ }
114
+
115
+ public async Task Batch ()
116
+ {
117
+ var result = await service .SubmissionsService .BatchCreate (new SubmissionBatch
118
+ {
119
+ submissions = new []{
120
+ new Submission
121
+ {
122
+ source_code = " #include <stdio.h>\n\n int main(void) {\n char name[10];\n scanf(\" %s\" , name);\n printf(\" hello, %s\\ n\" , name);\n return 0;\n }" ,
123
+ stdin = " world" ,
124
+ language_id = 50 ,
125
+ },
126
+ new Submission
127
+ {
128
+ source_code = " #include <stdio.h>\n\n int main(void) {\n char name[10];\n scanf(\" %s\" , name);\n printf(\" hello, %s\\ n\" , name);\n return 0;\n }" ,
129
+ stdin = " world" ,
130
+ language_id = 50 ,
131
+ }
132
+ }
133
+ });
134
+ Assert .IsTrue (result .IsSuccessStatusCode );
135
+ var getres = await service .SubmissionsService .BatchGet (result .Result .Select (x => x .token ));
136
+ Assert .IsTrue (getres .IsSuccessStatusCode );
137
+ }
138
+ ```
139
+
140
+ ### Language
141
+
142
+ ``` csharp
143
+ public async Task Get ()
144
+ {
145
+ var result = await service .LanguagesService .Get ();
146
+ Assert .IsTrue (result .IsSuccessStatusCode );
147
+ }
148
+
149
+ public async Task GetById ()
150
+ {
151
+ var result = await service .LanguagesService .Get (50 );
152
+ Assert .IsTrue (result .IsSuccessStatusCode );
153
+ }
154
+
155
+ public async Task GetAll ()
156
+ {
157
+ var result = await service .LanguagesService .GetAll ();
158
+ Assert .IsTrue (result .IsSuccessStatusCode );
159
+ }
160
+ ```
161
+
162
+ ### Status
30
163
31
- var result = await service . LanguagesService . Get ();
32
- foreach ( Language lang in result . Result )
164
+ ``` csharp
165
+ public async Task Get ( )
33
166
{
34
- Console .WriteLine (lang .name );
167
+ var result = await service .StatusesService .Get ();
168
+ Assert .IsTrue (result .IsSuccessStatusCode );
35
169
}
36
170
```
171
+
172
+ ### System & Configuration & Statistics & Health Check & Information
173
+
174
+ ``` csharp
175
+ public async Task GetSystemInfo ()
176
+ {
177
+ var result = await service .SystemService .GetSystemInfo ();
178
+ Assert .IsTrue (result .IsSuccessStatusCode );
179
+ }
180
+
181
+ public async Task GetAbout ()
182
+ {
183
+ var result = await service .SystemService .GetAbout ();
184
+ Assert .IsTrue (result .IsSuccessStatusCode );
185
+ }
186
+
187
+ public async Task GetConfigInfo ()
188
+ {
189
+ var result = await service .SystemService .GetConfigInfo ();
190
+ Assert .IsTrue (result .IsSuccessStatusCode );
191
+ }
192
+
193
+ public async Task GetIsolate ()
194
+ {
195
+ var result = await service .SystemService .GetIsolate ();
196
+ Assert .IsTrue (result .IsSuccessStatusCode );
197
+ }
198
+
199
+ public async Task GetLicense ()
200
+ {
201
+ var result = await service .SystemService .GetLicense ();
202
+ Assert .IsTrue (result .IsSuccessStatusCode );
203
+ }
204
+
205
+ public async Task GetStatistics ()
206
+ {
207
+ var result = await service .SystemService .GetStatistics ();
208
+ Assert .IsTrue (result .IsSuccessStatusCode );
209
+ }
210
+
211
+ public async Task GetWorkerHealthCheck ()
212
+ {
213
+ var result = await service .SystemService .GetWorkerHealthCheck ();
214
+ Assert .IsTrue (result .IsSuccessStatusCode );
215
+ }
216
+
217
+ public async Task GetVersion ()
218
+ {
219
+ var result = await service .SystemService .GetVersion ();
220
+ Assert .IsTrue (result .IsSuccessStatusCode );
221
+ }
222
+ ```
0 commit comments