Skip to content

StardustDL/judge0-dotnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

judge0-dotnet

CI CD License Judge0

Client SDK for Judge0 RESTful API.

Features

  • Authentication
  • Authorization
  • Submissions
  • Statuses and Languages
  • System and Configuration
  • Statistics
  • Health Check
  • Information

Versions

Judge0 version supported status:

  • 1.9.0
  • 1.8.0
  • 1.7.1
  • 1.7.0
  • 1.6.0

Install

dotnet add package Judge0

Usage

Create Service

var client = new HttpClient
{
    BaseAddress = new Uri("apiUri")
};
IJudge0Service service = new Judge0Service(client);

Authentication & Authorization

public async Task AuthenticateAndAuthorize()
{
    var result = await service.AuthenticationService.Authenticate("token");
    Assert.IsTrue(result.IsSuccessStatusCode);

    result = await service.AuthenticationService.Authorize("user");
    Assert.IsTrue(result.IsSuccessStatusCode);
}

Submission

public async Task CreateGetAndDelete()
{
    var result = await service.SubmissionsService.Create(new Submission
    {
        source_code = "#include <stdio.h>\n\nint main(void) {\n  char name[10];\n  scanf(\"%s\", name);\n  printf(\"hello, %s\\n\", name);\n  return 0;\n}",
        stdin = "world",
        language_id = 50,
    });
    Assert.IsTrue(result.IsSuccessStatusCode);
    string token = result.Result.token;

    while (true)
    {
        await Task.Delay(TimeSpan.FromSeconds(1));
        var res = await service.SubmissionsService.Get(token);
        Assert.IsTrue(res.IsSuccessStatusCode);
        if(res.Result.status?.id > 2)
        {
            Assert.IsNotNull(res.Result.stdout);
            StringAssert.StartsWith(res.Result.stdout, "hello, world");
            break;
        }
    }

    var del = await service.SubmissionsService.Delete(token);
    Assert.IsTrue(del.IsSuccessStatusCode);
}

public async Task CreateWaitGetAndDelete()
{
    var result = await service.SubmissionsService.CreateAndWait(new Submission
    {
        source_code = "#include <stdio.h>\n\nint main(void) {\n  char name[10];\n  scanf(\"%s\", name);\n  printf(\"hello, %s\\n\", name);\n  return 0;\n}",
        stdin = "world",
        language_id = 50,
    });
    Assert.IsTrue(result.IsSuccessStatusCode);
    string token = result.Result.token;

    Assert.IsNotNull(result.Result.stdout);
    StringAssert.StartsWith(result.Result.stdout, "hello, world");

    var del = await service.SubmissionsService.Delete(token);
    Assert.IsTrue(del.IsSuccessStatusCode);
}

public async Task GetPaging()
{
    var result = await service.SubmissionsService.GetPaging();
    Assert.IsTrue(result.IsSuccessStatusCode);
}

public async Task Batch()
{
    var result = await service.SubmissionsService.BatchCreate(new SubmissionBatch
    {
        submissions = new[]{
            new Submission
    {
        source_code = "#include <stdio.h>\n\nint main(void) {\n  char name[10];\n  scanf(\"%s\", name);\n  printf(\"hello, %s\\n\", name);\n  return 0;\n}",
        stdin = "world",
        language_id = 50,
    },
            new Submission
    {
        source_code = "#include <stdio.h>\n\nint main(void) {\n  char name[10];\n  scanf(\"%s\", name);\n  printf(\"hello, %s\\n\", name);\n  return 0;\n}",
        stdin = "world",
        language_id = 50,
    }
            }
    });
    Assert.IsTrue(result.IsSuccessStatusCode);
    var getres = await service.SubmissionsService.BatchGet(result.Result.Select(x => x.token));
    Assert.IsTrue(getres.IsSuccessStatusCode);
}

Language

public async Task Get()
{
    var result = await service.LanguagesService.Get();
    Assert.IsTrue(result.IsSuccessStatusCode);
}

public async Task GetById()
{
    var result = await service.LanguagesService.Get(50);
    Assert.IsTrue(result.IsSuccessStatusCode);
}

public async Task GetAll()
{
    var result = await service.LanguagesService.GetAll();
    Assert.IsTrue(result.IsSuccessStatusCode);
}

Status

public async Task Get()
{
    var result = await service.StatusesService.Get();
    Assert.IsTrue(result.IsSuccessStatusCode);
}

System & Configuration & Statistics & Health Check & Information

public async Task GetSystemInfo()
{
    var result = await service.SystemService.GetSystemInfo();
    Assert.IsTrue(result.IsSuccessStatusCode);
}

public async Task GetAbout()
{
    var result = await service.SystemService.GetAbout();
    Assert.IsTrue(result.IsSuccessStatusCode);
}

public async Task GetConfigInfo()
{
    var result = await service.SystemService.GetConfigInfo();
    Assert.IsTrue(result.IsSuccessStatusCode);
}

public async Task GetIsolate()
{
    var result = await service.SystemService.GetIsolate();
    Assert.IsTrue(result.IsSuccessStatusCode);
}

public async Task GetLicense()
{
    var result = await service.SystemService.GetLicense();
    Assert.IsTrue(result.IsSuccessStatusCode);
}

public async Task GetStatistics()
{
    var result = await service.SystemService.GetStatistics();
    Assert.IsTrue(result.IsSuccessStatusCode);
}

public async Task GetWorkerHealthCheck()
{
    var result = await service.SystemService.GetWorkerHealthCheck();
    Assert.IsTrue(result.IsSuccessStatusCode);
}

public async Task GetVersion()
{
    var result = await service.SystemService.GetVersion();
    Assert.IsTrue(result.IsSuccessStatusCode);
}

Status