Ejemplo n.º 1
0
        private async Task Submit(string code)
        {
            var submitChallenge = new ChallengeModel
            {
                Solution = code,
                Tests    = AppState.ActiveChallenge.Tests
            };
            var output = await PublicClient.SubmitChallenge(submitChallenge);

            foreach (string result in output.Outputs.Select(x => x.Codeout))
            {
                AppState.AddLineToOutput(result);
            }
            foreach (var result in output.Outputs)
            {
                System.Console.WriteLine($"test: {result.TestIndex}, result: {result.TestResult}, against: {result.Test.TestAgainst}, output: {result.Codeout}");
            }
            bool challengeSucceed = output.Outputs.All(x => x.TestResult);

            _testResult = challengeSucceed ? TestResult.Pass : TestResult.Fail;
            //var debugString = challengeSucceed ? "True" : "False";
            //System.Console.WriteLine($"isChallengeSucceed = {debugString}");
            //_isChallengeFail = !challengeSucceed;
            //System.Console.WriteLine($"isChallengeFail = {_isChallengeFail}");
            _isWorking = false;
            results    = output;
            await InvokeAsync(StateHasChanged);
        }
 private void UpdatePropertyState(object sender, PropertyChangedEventArgs args)
 {
     if (args.PropertyName != "CodeOutput")
     {
         return;
     }
     CodeOutput = AppState.CodeOutput;
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> RunSubmitChallenge(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "challenge")] HttpRequest req,
            ILogger log)
        {
            var    executableReferences = CompileResources.PortableExecutableReferences;
            string requestBody          = await new StreamReader(req.Body).ReadToEndAsync();
            var    codeInput            = JsonConvert.DeserializeObject <CodeInputModel>(requestBody);
            var    testCode             = codeInput.Solution;
            var    outputs = new CodeOutputModel {
                Outputs = new List <Output>()
            };
            int index = 1;

            if (testCode == "TestPing")
            {
                _ = CompilerService.SubmitCode("return -1;", executableReferences).Result;
                return(new OkObjectResult("PingBack"));
            }
            var swTot = new Stopwatch();

            log.LogInformation("start all tasks");
            swTot.Start();
            await Task.Run(() =>
            {
                foreach (var snip in codeInput.Tests)
                {
                    var sw = new Stopwatch();

                    var output = new Output {
                        TestIndex = index, Test = snip
                    };
                    string code     = $"{testCode}\n{snip.Append}";
                    string expected = snip.TestAgainst;

                    log.LogInformation("Start task 1");
                    sw.Start();

                    output.Codeout = CompilerService.SubmitCode(code, executableReferences).Result;
                    sw.Stop();
                    log.LogInformation($"Complete task 1 in {sw.ElapsedMilliseconds}ms");
                    log.LogInformation("\nStart task 2");
                    sw.Restart();
                    output.TestResult = CompilerService.SubmitSolution(code, executableReferences, expected).Result;
                    sw.Stop();
                    log.LogInformation($"Complete task 2 in {sw.ElapsedMilliseconds}ms");
                    index++;
                    outputs.Outputs.Add(output);
                }
            });

            swTot.Stop();
            log.LogInformation($"Completed all tasks in {swTot.ElapsedMilliseconds}ms");
            return(new OkObjectResult(outputs));
        }
 protected override Task OnInitializedAsync()
 {
     CodeOutput = AppState.CodeOutput;
     AppState.PropertyChanged += UpdatePropertyState;
     return(base.OnInitializedAsync());
 }