コード例 #1
0
        public ActionResult Tests(string id)
        {
            var problem        = _archiveClientService.GetFull(id);
            var problemArchive = _archiveClientService.GetArchive(id);
            var tests          = _testsFetcher.FetchTests(problemArchive, id, problem.TestGroups.SelectMany(x => x.Tests).ToArray());

            return(View(new TestsViewModel(id, problem.TestGroups, tests)));
        }
        private void UpdateProblemInfo(Bacs.Problem.Problem internalProblem, Entities.Problem problem,
                                       ProblemsDbContext problemsDbContext, ITestsFetcher testsFetcher, IArchiveClient archiveClient)
        {
            var name        = internalProblem.Info.Name.First().Value;
            var maintainers = string.Join(", ", internalProblem.Info.Maintainer);
            var revision    = internalProblem.System.Revision.Value.ToBase64();

            var extensionValue = internalProblem.Profile.First().Extension.Value;
            var testsCount     = ProfileExtension.Parser.ParseFrom(extensionValue)
                                 .TestGroup
                                 .Sum(x => x.Tests.Query.Count);

            var statement = $"http://bacs.cs.istu.ru/problem/{problem.InternalId}";

            problem.Maintainers = maintainers;
            problem.Name        = name;
            problem.Revision    = revision;
            problem.Statement   = statement;
            problem.TestsCount  = testsCount;

            var testGroups = problemsDbContext.TestGroups
                             .Where(x => string.Equals(x.ProblemId, problem.InternalId))
                             .ToArray();

            problemsDbContext.TestGroups.RemoveRange(testGroups);


            var internalTestGroups = ProfileExtension.Parser.ParseFrom(extensionValue).TestGroup;
            var tests = internalTestGroups
                        .SelectMany(x => x.Tests.Query.Select(y => y.Id))
                        .ToArray();

            var testInfos = testsFetcher
                            .FetchTests(archiveClient, problem.InternalId, tests)
                            .DistinctBy(x => x.Id)
                            .ToDictionary(x => x.Id);


            var newTestGroups = internalTestGroups.Select(x => new TestGroup
            {
                InternalId        = x.Id,
                Score             = x.Score,
                ProblemId         = problem.InternalId,
                ContinueCondition = x.Tests.ContinueCondition.ToString(),
                Tests             = x.Tests.Query.OrderBy(y => y.Id).Select(y => testInfos[y.Id])
                                    .Select(y => new Test {
                    Input = y.Input, Output = y.Output, InternalId = y.Id
                }).ToArray()
            }).OrderBy(y => y.Id);

            problemsDbContext.TestGroups.AddRange(newTestGroups);
        }