示例#1
0
        private async Task UpdateQuestionProcess2Code()
        {
            var questionId = _spush.QuestionId;

            using (var db = new JudgerDbContext())
            {
                var contains = await db.ContainsProcess2Code(questionId);

                bool needUpdate = true;
                if (contains)
                {
                    var item   = (DbHashModel)_lockM.JudgeCode;
                    var dbItem = await db.FindProcess2HashById(questionId);

                    if (dbItem.UpdateTicks == item.UpdateTicks)
                    {
                        needUpdate = false;
                    }
                }

                if (needUpdate)
                {
                    // 数据过期,需要执行更新操作。
                    if (contains)
                    {
                        _log.Info("P2Code expired, updating from server.");
                    }
                    else
                    {
                        _log.Info("P2Code not exist, fetching from server.");
                    }

                    _fullM = await _client.GetProcess2Code(questionId);

                    var toDbItem = (QuestionP2Code)_fullM;
                    await db.DeleteAndCreateProcess2Code(toDbItem);
                }
                else
                {
                    var dbItem = await db.FindProcess2CodeById(questionId);

                    _fullM = (QuestionProcess2FullModel)dbItem;
                }
            }
        }
示例#2
0
        public override async Task ExecuteAsync()
        {
            // 获取并锁定解答的详情。
            _sfull = await _client.Lock(_spush.Id);

            if (_sfull == null)
            {
                _log.InfoExt(() => $"Failed to lock {_spush.Id}, move next.");
                return;
            }
            await UpdateQuestionData();

            var           compiler = CompilerProvider.GetCompiler(_spush.Language);
            CompileResult asm      = compiler.Compile(_sfull.Source);

            if (asm.HasErrors)
            {
                await _client.Update(ClientJudgeModel.CreateCompileError(_spush.Id, asm.Output));

                return;
            }
            else
            {
                await _client.UpdateInLock(_spush.Id, SolutionState.Judging);
            }

            IEnumerable <QuestionData> datas;

            using (var db = new JudgerDbContext())
            {
                var dataIds = _sfull.QuestionDatas
                              .Select(x => x.Id).ToArray();
                datas = await db.FindDatasByIds(dataIds);
            }

            // Judging
            using (compiler)
            {
                await Judge(datas, asm, compiler.GetEncoding());
            }
        }
示例#3
0
        private async Task UpdateQuestionData()
        {
            // 与本地数据库对比时间戳。
            var serverItems = _sfull.QuestionDatas
                              .OrderBy(x => x.Id)
                              .Select(x => (DbHashModel)x)
                              .ToArray();
            var ids = _sfull.QuestionDatas.Select(x => x.Id);

            using (var db = new JudgerDbContext())
            {
                var dbItems = await db.FindDataSummarysByIdsInOrder(ids);

                var except = serverItems.Except(dbItems).ToArray();

                // 将旧数据或者没有的数据更新。
                if (except.Length > 0)
                {
                    _log.InfoFormat("Found dirty datas, try get {0} data from server.", except.Length);
                    var hubDatas = await _client.GetDatas(except.Select(x => x.Id).ToArray());

                    var dbDatas = hubDatas.Select(hubData => new QuestionData
                    {
                        Id            = hubData.Id,
                        Input         = hubData.Input,
                        Output        = hubData.Output,
                        MemoryLimitMb = hubData.MemoryLimitMb,
                        TimeLimit     = hubData.TimeLimit,
                        UpdateTicks   = serverItems.First(x => x.Id == hubData.Id).UpdateTicks
                    }).ToArray();
                    await db.DeleteAndCreateData(dbDatas);

                    _log.Info($"Updated {hubDatas.Length} datas from server.");
                    if (hubDatas.Length != except.Length)
                    {
                        _log.Warn("Server returned less data than excepted.");
                    }
                }
            }
        }