private async Task RunBattery(SolutionModel solution, BatteryModel battery)
        {
            // Verificam daca exista deja rezultate pentru bateria si solutia data si daca exista le suprascriem
            VerifyIfResultExists(solution.Id, battery.Id);
            var result = new ResultModel
            {
                SolutionId = solution.Id,
                BatteryId  = battery.Id
            };

            _context.Results.Add(result);
            await _context.SaveChangesAsync();

            foreach (var test in battery.Tests)
            {
                var testResult = CodeRunner.RunCode(solution.Code, test, solution.ProgrammingLanguage.LanguageCode);
                testResult.ResultId = result.Id;
                testResult.TestId   = test.Id;
                var expectedOutput = test.ExpectedOutput.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace("\n", "").Replace(" ", "");
                var resultedOutput = testResult.ResultedOutput.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace("\t", "").Replace("\n", "").Replace(" ", "");
                var pointsGiven    = expectedOutput.Equals(resultedOutput) ? test.Points : 0;
                testResult.PointsGiven = pointsGiven;
                if (testResult.ExecutionTime <= solution.Challenge.ExecutionTimeLimit && testResult.Memory <= solution.Challenge.MemoryLimit)
                {
                    // inserare in tabelul de rezultate ale testelor
                    _context.TestResults.Add(testResult);
                    _context.SaveChanges();
                }
            }
        }
        // Actiune apelata in momentul in care se face un submit Code pentru a verica codul
        // si a-l putea redirectiona pe utilizator la clasamentul problemei
        public async Task <IActionResult> VerifySubmit(int id)
        {
            var solution = _context.Solutions
                           .Include(s => s.ProgrammingLanguage)
                           .Include(s => s.Challenge)
                           .FirstOrDefault(s => s.Id == id);
            var batteries = _context.Batteries
                            .Where(s => s.ChallengeId == solution.ChallengeId)
                            .Include(s => s.Tests)
                            .ToList();

            foreach (var battery in batteries)
            {
                var result = new ResultModel
                {
                    SolutionId = solution.Id,
                    BatteryId  = battery.Id
                };
                _context.Results.Add(result);
                _context.SaveChanges();
                foreach (var test in battery.Tests)
                {
                    var testResult = CodeRunner.RunCode(solution.Code, test, solution.ProgrammingLanguage.LanguageCode);
                    testResult.ResultId = result.Id;
                    testResult.TestId   = test.Id;
                    // eliminam caracterele de editare a output-ului
                    var expectedOutput = test.ExpectedOutput.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace("\n", "").Replace(" ", "");
                    var resultedOutput = testResult.ResultedOutput.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace("\t", "").Replace("\n", "").Replace(" ", "");
                    var pointsGiven    = expectedOutput.Equals(resultedOutput) ? test.Points : 0;
                    // primeste punctele doar daca respecta cerintele de performanta
                    if (pointsGiven > 0)
                    {
                        if (testResult.ExecutionTime <= solution.Challenge.ExecutionTimeLimit && testResult.Memory <= solution.Challenge.MemoryLimit)
                        {
                            testResult.PointsGiven = pointsGiven;
                        }
                    }

                    // inserare in tabelul de rezultate ale testelor
                    _context.TestResults.Add(testResult);
                    await _context.SaveChangesAsync();
                }
            }
            CalculatePerformance(solution);
            //await UpdateScoreAndGrade(solution);
            return(RedirectToAction("Ranking", "Challenge", new { id = solution.ChallengeId }));
        }
예제 #3
0
 public void RunCode() => CodeRunner.RunCode(playerAppDomain, PlayerData, ConsoleStream);