Beispiel #1
0
        public async Task <List <TestCase> > UpdateProblemTestCasesAsync(int id, IFormFile file)
        {
            await EnsureProblemExists(id);

            var problem = await Context.Problems.FindAsync(id);

            switch (problem.Type)
            {
            case ProblemType.Ordinary:
                await OrdinaryProblemArchive.ExtractTestCasesAsync(problem, file, _options, prefix : "");

                break;

            case ProblemType.TestKitLab:
                await TestKitLabProblemArchive.ExtractTestKitAsync(problem, file, _options, prefix : "");

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            await Context.SaveChangesAsync();

            await LogInformation($"UpdateProblemTestCases Id={problem.Id}" +
                                 $" Type={problem.Type} Count={problem.TestCases.Count}");

            return(problem.TestCases);
        }
Beispiel #2
0
        public async Task <byte[]> ExportProblemAsync(int id)
        {
            await EnsureProblemExists(id);

            var problem = await Context.Problems.FindAsync(id);

            return(problem.Type switch
            {
                ProblemType.Ordinary
                => await OrdinaryProblemArchive.CreateAsync(problem, _options),
                ProblemType.TestKitLab
                => await TestKitLabProblemArchive.CreateAsync(problem, _options),
                _ => throw new ArgumentOutOfRangeException()
            });
Beispiel #3
0
        public async Task <ProblemEditDto> ImportProblemAsync(int contestId, IFormFile file)
        {
            if (!await Context.Contests.AnyAsync(c => c.Id == contestId))
            {
                throw new ValidationException("Invalid Contest ID.");
            }

            Problem problem;
            var     type = await ProblemConfig.PeekProblemTypeAsync(file);

            switch (type)
            {
            case ProblemType.Ordinary:
                problem = await OrdinaryProblemArchive.ParseAsync(contestId, file, _options);

                await Context.Problems.AddAsync(problem);

                await Context.SaveChangesAsync();

                await OrdinaryProblemArchive.ExtractTestCasesAsync(problem, file, _options);

                await Context.SaveChangesAsync();

                break;

            case ProblemType.TestKitLab:
                problem = await TestKitLabProblemArchive.ParseAsync(contestId, file, _options);

                await Context.Problems.AddAsync(problem);

                await Context.SaveChangesAsync();

                await TestKitLabProblemArchive.ExtractTestKitAsync(problem, file, _options);

                await Context.SaveChangesAsync();

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(new ProblemEditDto(problem));
        }