コード例 #1
0
        public ProblemFull GetFull(string id)
        {
            var importResult = _archiveClient.ImportResult(id)[id];
            var statusResult = _archiveClient.Status(id)[id];

            if (statusResult.Error?.Code == Error.Types.Code.NotFound)
            {
                return(null);
            }
            var flags = statusResult.Status.Flags.Flag.ToList();

            var containsFlag = new Func <Flag.Types.Reserved, bool>(x => flags.Any(y => y.Reserved == x));

            var reservedFlags = Enum.GetValues(typeof(Flag.Types.Reserved))
                                .Cast <Flag.Types.Reserved>()
                                .Where(x => x != Flag.Types.Reserved.None)
                                .Select(x => new ProblemFull.ReservedFlag(x, containsFlag(x)))
                                .ToList();

            var customFlags = flags
                              .Where(x => x.FlagCase == Flag.FlagOneofCase.Custom)
                              .Select(x => new ProblemFull.CustomFlag(x.Custom))
                              .ToList();

            var name        = importResult.Problem.Info.Name.First().Value;
            var maintainers = string.Join(", ", importResult.Problem.Info.Maintainer);
            var revision    = importResult.Problem.System.Revision.Value.ToBase64();

            var extensionValue   = importResult.Problem.Profile.First().Extension.Value;
            var profileExtension = ProfileExtension.Parser.ParseFrom(extensionValue);
            var testGroups       = profileExtension.TestGroup.Select(x => new TestGroup
            {
                Id      = x.Id,
                Score   = x.Score,
                Tests   = x.Tests.Query.Select(y => y.Id),
                WhileOk = x.Tests.ContinueCondition == TestSequence.Types.ContinueCondition.WhileOk,
            });

            const string pretestsPrefix = "pre";
            var          hasPretests    = profileExtension.TestGroup.Any(x => x.Id == pretestsPrefix);
            var          pretestsCount  = !hasPretests ? 0 : profileExtension
                                          .TestGroup
                                          .FirstOrDefault(x => x.Id != pretestsPrefix)
                                          .Tests.Query.Count;

            return(new ProblemFull(
                       id,
                       name,
                       maintainers,
                       revision,
                       reservedFlags,
                       customFlags,
                       testGroups,
                       pretestsCount,
                       $"http://bacs.cs.istu.ru/problem/{id}?key={_bacsStatementsKey}"));
        }
        private static bool TryGetInternalProblem(IArchiveClient archiveClient, string problemId,
                                                  out Bacs.Problem.Problem problem)
        {
            var importResults = archiveClient.ImportResult(problemId);
            var success       = importResults.ContainsKey(problemId) &&
                                importResults[problemId].ResultCase == ImportResult.ResultOneofCase.Problem;

            problem = success ? importResults[problemId].Problem : null;
            return(success);
        }