Esempio n. 1
0
        private static async Task MainAsync(VirtualJudgeMetadata metadata, VirtualJudgeAccount account)
        {
            var token = await GetOnlineJudgeLoginToken(account);

            await GetCredantial(token);

            var csrf = await GetCsrfToken(metadata.ProblemId);

            var statusId = await SendToJudge(metadata, csrf);

            if (statusId.Item1 == -1)
            {
                WriteResultFile(new VirtualJudgeResult
                {
                    Hint   = statusId.Item2,
                    Result = "CompileError"
                });
            }
            else
            {
                var result = await PollResult(statusId.Item1);

                WriteResultFile(result);
            }
        }
Esempio n. 2
0
        private static async Task <string> GetOnlineJudgeLoginToken(VirtualJudgeAccount account)
        {
            using (var client = new HttpClient()
            {
                BaseAddress = new Uri(LoginBaseUrl)
            })
            {
                var content = new StringContent(JsonConvert.SerializeObject(new { account.username, account.password }), Encoding.UTF8, "application/json");
                using (var response = await client.PostAsync(FirstLoginEndpoint, content))
                {
                    var text = await response.Content.ReadAsStringAsync();

                    var jwt = JsonConvert.DeserializeObject <dynamic>(text).jwt;
                    client.DefaultRequestHeaders.Add("Authorization", "JWT " + jwt);
                    using (var response2 = await client.GetAsync(SecondLoginEndpoint))
                    {
                        return(JsonConvert.DeserializeObject <dynamic>(await response2.Content.ReadAsStringAsync()).token);
                    }
                }
            }
        }