Exemple #1
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var tid = Connection.NewProblem();

            _problems.Add(Connection.GetProblem(tid));
            ListView.SelectedIndex = ListView.Items.Count - 1;
        }
Exemple #2
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            if (!(ListView.SelectedItem is Competition t))
            {
                return;
            }
            t.CompetitionName = ComName.Text;
            var tmpSdate = StartDate.SelectedDate ?? DateTime.Now;
            var tmpEdate = EndDate.SelectedDate ?? DateTime.Now;

            t.StartTime = Convert.ToDateTime(
                $"{tmpSdate:yyyy/MM/dd} {(StartHour.Text.Length == 1 ? $"0{StartHour.Text}" : StartHour.Text)}:{(StartMinute.Text.Length == 1 ? $"0{StartMinute.Text}" : StartMinute.Text)}:{(StartSecond.Text.Length == 1 ? $"0{StartSecond.Text}" : StartSecond.Text)}");
            t.EndTime = Convert.ToDateTime(
                $"{tmpEdate:yyyy/MM/dd} {(EndHour.Text.Length == 1 ? $"0{EndHour.Text}" : EndHour.Text)}:{(EndMinute.Text.Length == 1 ? $"0{EndMinute.Text}" : EndMinute.Text)}:{(EndSecond.Text.Length == 1 ? $"0{EndSecond.Text}" : EndSecond.Text)}");
            t.Option = 0;
            if (LimitedSubmit.IsChecked ?? false)
            {
                t.Option |= 1;
            }
            if (LastSubmit.IsChecked ?? false)
            {
                t.Option |= 2;
            }
            if (TimeCount.IsChecked ?? false)
            {
                t.Option |= 4;
            }
            if (IntimeNotify.IsChecked ?? false)
            {
                t.Option |= 8;
            }
            if (HideRank.IsChecked ?? false)
            {
                t.Option |= 16;
            }
            if (HideScore.IsChecked ?? false)
            {
                t.Option |= 32;
            }
            if (StopRank.IsChecked ?? false)
            {
                t.Option |= 64;
            }
            if (SummaryResult.IsChecked ?? false)
            {
                t.Option |= 128;
            }
            if (ToPrivate.IsChecked ?? false)
            {
                t.Option |= 256;
            }
            t.Password    = ComPassword.Text;
            t.SubmitLimit = Convert.ToInt32(LimitedSubmitTime.Text);
            var tmpProId = new List <int>();

            foreach (var i in ComProblems.Text.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries))
            {
                try
                {
                    var x = Convert.ToInt32(i);
                    if (Connection.GetProblem(x).ProblemId == 0)
                    {
                        MessageBox.Show("输入的题目 ID 不合法,无法保存", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                    tmpProId.Add(x);
                }
                catch
                {
                    MessageBox.Show("输入的题目 ID 不合法,无法保存", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            t.ProblemSet  = tmpProId.ToArray();
            t.Description = ComNote.Text;
            Connection.UpdateCompetition(t);
        }
Exemple #3
0
        public Judge(int problemId, int userId, string code, string type, bool isStdIO, string description,
                     string defaultTime, int competitionId, Action <int> idCallBack = null)
        {
            Cancelled = false;
            if (competitionId != 0)
            {
                var comp      = Connection.GetCompetition(competitionId);
                var judgeLogs = Connection.QueryJudgeLogBelongsToCompetition(competitionId, userId);
                if ((comp.Option & 1) != 0 && comp.SubmitLimit != 0)
                {
                    if (judgeLogs.Count(i => i.ProblemId == problemId) >= comp.SubmitLimit)
                    {
                        Connection.CanPostJudgTask = true;
                        Cancelled = true;
                        return;
                    }
                }
            }

            JudgeResult.JudgeId = Connection.NewJudge(description);
            idCallBack?.Invoke(JudgeResult.JudgeId);
            _problem = Connection.GetProblem(problemId);
            _id      = Guid.NewGuid().ToString().Replace("-", string.Empty);
            JudgeResult.JudgeDate     = defaultTime ?? DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
            JudgeResult.ProblemId     = _problem.ProblemId;
            JudgeResult.Code          = code;
            JudgeResult.UserId        = userId;
            JudgeResult.Exitcode      = new int[_problem.DataSets.Length];
            JudgeResult.Result        = new string[_problem.DataSets.Length];
            JudgeResult.Score         = new float[_problem.DataSets.Length];
            JudgeResult.Timeused      = new long[_problem.DataSets.Length];
            JudgeResult.Memoryused    = new long[_problem.DataSets.Length];
            JudgeResult.Type          = type;
            JudgeResult.Description   = description;
            JudgeResult.CompetitionId = competitionId;
            JudgeResult.AdditionInfo  = string.Empty;
            Connection.UpdateJudgeInfo(JudgeResult);

            var textBlock = Connection.UpdateMainPageState(
                $"{DateTime.Now:yyyy/MM/dd HH:mm:ss} 准备评测 #{JudgeResult.JudgeId},题目:{JudgeResult.ProblemName},用户:{JudgeResult.UserName}");

            while (true)
            {
                if (Connection.CurJudgingCnt < (Configuration.Configurations.MutiThreading == 0
                        ? Configuration.ProcessorCount + Connection.IntelligentAdditionWorkingThread
                        : Configuration.Configurations.MutiThreading))
                {
                    lock (Connection.JudgeListCntLock)
                    {
                        Connection.CurJudgingCnt++;
                    }
                    break;
                }
                Thread.Sleep(100);
            }
            Connection.CanPostJudgTask = true;

            JudgeResult.JudgeDate = defaultTime ?? DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
            try
            {
                if (Configuration.Configurations.MutiThreading == 0)
                {
                    while (true)
                    {
                        try
                        {
                            lock (Connection.ResourceLoadingLock)
                            {
                                var cpuCounter = new PerformanceCounter
                                {
                                    CategoryName = "Processor",
                                    CounterName  = "% Processor Time",
                                    InstanceName = "_Total"
                                };
                                var ramCounter      = new PerformanceCounter("Memory", "Available KBytes");
                                var maxMemoryNeeded = _problem.DataSets.Select(i => i.MemoryLimit)
                                                      .Concat(new long[] { 0 })
                                                      .Max();
                                if (cpuCounter.NextValue() <= 70 &&
                                    ramCounter.NextValue() > maxMemoryNeeded + 262144)
                                {
                                    break;
                                }
                            }
                        }
                        catch
                        {
                            //ignored
                        }
                        Thread.Sleep(1000);
                    }
                }

                Connection.UpdateJudgeInfo(JudgeResult);
                _workingdir = Environment.GetEnvironmentVariable("temp") + "\\hjudgeWorkingDir\\Judge_hjudge_" + _id;

                var t = Configuration.Configurations.Compiler.FirstOrDefault(i => i.DisplayName == type);
                if (t == null)
                {
                    for (var i = 0; i < JudgeResult.Result.Length; i++)
                    {
                        JudgeResult.Result[i]     = "Compile Error";
                        JudgeResult.Exitcode[i]   = 0;
                        JudgeResult.Score[i]      = 0;
                        JudgeResult.Timeused[i]   = 0;
                        JudgeResult.Memoryused[i] = 0;
                    }
                    Connection.UpdateJudgeInfo(JudgeResult);

                    lock (Connection.JudgeListCntLock)
                    {
                        Connection.CurJudgingCnt--;
                    }
                    Connection.UpdateMainPageState(
                        $"{DateTime.Now:yyyy/MM/dd HH:mm:ss} 评测完毕 #{JudgeResult.JudgeId},题目:{JudgeResult.ProblemName},用户:{JudgeResult.UserName},结果:{JudgeResult.ResultSummary}",
                        textBlock);
                    return;
                }
                var extList = t.ExtName.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                if (extList.Length == 0)
                {
                    for (var i = 0; i < JudgeResult.Result.Length; i++)
                    {
                        JudgeResult.Result[i]     = "Compile Error";
                        JudgeResult.Exitcode[i]   = 0;
                        JudgeResult.Score[i]      = 0;
                        JudgeResult.Timeused[i]   = 0;
                        JudgeResult.Memoryused[i] = 0;
                    }
                    Connection.UpdateJudgeInfo(JudgeResult);

                    lock (Connection.JudgeListCntLock)
                    {
                        Connection.CurJudgingCnt--;
                    }
                    Connection.UpdateMainPageState(
                        $"{DateTime.Now:yyyy/MM/dd HH:mm:ss} 评测完毕 #{JudgeResult.JudgeId},题目:{JudgeResult.ProblemName},用户:{JudgeResult.UserName},结果:{JudgeResult.ResultSummary}",
                        textBlock);
                    return;
                }

                if (string.IsNullOrEmpty(_problem.CompileCommand))
                {
                    _problem.CompileCommand = t.LinuxComArgs
                        ? GetRealStringWSL(t.CompilerArgs, 0, extList[0])
                        : GetRealString(t.CompilerArgs, 0, extList[0]);
                }
                else
                {
                    var commList = _problem.CompileCommand.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var s in commList)
                    {
                        var comm = s.Split(':');
                        if (comm.Length != 2)
                        {
                            continue;
                        }
                        if (comm[0] == type)
                        {
                            _problem.CompileCommand = t.LinuxComArgs
                                ? GetRealStringWSL(comm[1], 0, extList[0])
                                : GetRealString(comm[1], 0, extList[0]);
                            break;
                        }
                    }
                }

                _problem.SpecialJudge = GetRealString(_problem.SpecialJudge, 0, extList[0]);

                for (var i = 0; i < _problem.ExtraFiles.Length; i++)
                {
                    _problem.ExtraFiles[i] = GetRealString(_problem.ExtraFiles[i], i, extList[0]);
                }
                for (var i = 0; i < _problem.DataSets.Length; i++)
                {
                    _problem.DataSets[i].InputFile  = GetRealString(_problem.DataSets[i].InputFile, i, extList[0]);
                    _problem.DataSets[i].OutputFile = GetRealString(_problem.DataSets[i].OutputFile, i, extList[0]);
                }

                _problem.InputFileName  = isStdIO ? "stdin" : GetRealString(_problem.InputFileName, 0, extList[0]);
                _problem.OutputFileName = GetRealString(_problem.OutputFileName, 0, extList[0]);

                Connection.UpdateMainPageState(
                    $"{DateTime.Now:yyyy/MM/dd HH:mm:ss} 开始评测 #{JudgeResult.JudgeId},题目:{JudgeResult.ProblemName},用户:{JudgeResult.UserName}",
                    textBlock);

                BeginJudge(
                    t.LinuxComExec
                        ? GetRealStringWSL(t.CompilerExec, 0, extList[0])
                        : GetRealString(t.CompilerExec, 0, extList[0]),
                    t.LinuxStaExec
                        ? GetRealStringWSL(t.StaticCheck, 0, extList[0])
                        : GetRealString(t.StaticCheck, 0, extList[0]),
                    t.LinuxStaArgs
                        ? GetRealStringWSL(t.StaticArgs, 0, extList[0])
                        : GetRealString(t.StaticArgs, 0, extList[0]),
                    t.LinuxRunExec
                        ? GetRealStringWSL(t.RunExec, 0, extList[0])
                        : GetRealString(t.RunExec, 0, extList[0]),
                    t.LinuxRunArgs
                        ? GetRealStringWSL(t.RunArgs, 0, extList[0])
                        : GetRealString(t.RunArgs, 0, extList[0]), textBlock);

                Connection.UpdateJudgeInfo(JudgeResult);

                Connection.UpdateMainPageState(
                    $"{DateTime.Now:yyyy/MM/dd HH:mm:ss} 评测完毕 #{JudgeResult.JudgeId},题目:{JudgeResult.ProblemName},用户:{JudgeResult.UserName},结果:{JudgeResult.ResultSummary}",
                    textBlock);

                if (userId > 1)
                {
                    if (JudgeResult.ResultSummary.Contains("Exceeded"))
                    {
                        DeltaCoins      = Connection.RandomNum.Next(4, 16);
                        DeltaExperience = Connection.RandomNum.Next(8, 16);
                    }
                    else if (JudgeResult.ResultSummary.Contains("Accepted"))
                    {
                        DeltaCoins      = Connection.RandomNum.Next(16, 64);
                        DeltaExperience = Connection.RandomNum.Next(32, 64);
                    }
                    else
                    {
                        DeltaExperience = Connection.RandomNum.Next(2, 4);
                    }

                    Connection.UpdateCoins(userId, DeltaCoins);
                    Connection.UpdateExperience(userId, DeltaExperience);
                }
            }
            catch
            {
                //ignored
            }

            try
            {
                DeleteFiles(_workingdir);
            }
            catch
            {
                //ignored
            }
            lock (Connection.JudgeListCntLock)
            {
                Connection.CurJudgingCnt--;
            }
        }