public bool SetCompetition(Competition competition, Frame frame, Grid grid) { _competition = competition; if (string.IsNullOrEmpty(_competition.Description)) { _competition.Description = "此比赛暂无描述"; } if ((_competition.Option & 64) != 0) { _competition.Description += "\n注意:比赛结束前 1 小时封榜"; } _mainCompetitionFrame = frame; _mainCompetitionGrid = grid; if (_competition == null) { return(false); } _baseTime[0] = Connection.GetCurrentDateTime(); _baseTime[1] = DateTime.Now; if (GetNowDateTime() < _competition.StartTime) { MessageBox.Show("比赛未开始", "提示", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } if (!string.IsNullOrEmpty(_competition.Password)) { var pass = new InputPassword(); pass.SetRecallFun(VerifyPassword); pass.ShowDialog(); if (!_verifyPasswordResult) { return(false); } } ComName.Content = $"({_competition.CompetitionId}) {_competition.CompetitionName}"; if ((_competition.Option & 1) != 0) { ComMode.Text = $"限制提交赛:{(_competition.SubmitLimit == 0 ? "无限" : _competition.SubmitLimit.ToString())} 次"; } if ((_competition.Option & 2) != 0) { ComMode.Text = "最后提交赛"; } if ((_competition.Option & 4) != 0) { ComMode.Text = "罚时计时赛"; } ListView.ItemsSource = _curJudgeInfo; MyProblemList.ItemsSource = _problems; ProblemFilter.ItemsSource = _problemFilter; UserFilter.ItemsSource = _userFilter; Description.Text = _competition.Description; var rtf = new RotateTransform { CenterX = Loading.Width * 0.5, CenterY = Loading.Height * 0.5 }; var daV = new DoubleAnimation(0, 360, new Duration(TimeSpan.FromSeconds(1))) { RepeatBehavior = RepeatBehavior.Forever }; Loading.RenderTransform = rtf; rtf.BeginAnimation(RotateTransform.AngleProperty, daV); return(true); }
private void Load() { lock (_loadLock) { Dispatcher.Invoke(() => { Loading.Visibility = Visibility.Visible; RefreshButton.IsEnabled = false; }); var now = Connection.GetCurrentDateTime(); var problems = Connection.QueryProblemsForCompetition(_competition.CompetitionId); Dispatcher.Invoke(() => _problems.Clear()); foreach (var i in problems) { Dispatcher.Invoke(() => _problems.Add(i)); } var languages = Connection.QueryLanguagesForCompetition(); Dispatcher.Invoke(() => LangBox.Items.Clear()); foreach (var m in languages) { Dispatcher.Invoke(() => LangBox.Items.Add(new RadioButton { Content = m.DisplayName })); } Dispatcher.Invoke(() => { for (var i = CompetitionStateColumn.Columns.Count - 1; i >= 0; i--) { if (CompetitionStateColumn.Columns[i] is GridViewColumn t && t.Header is StackPanel) { CompetitionStateColumn.Columns.RemoveAt(i); } } }); for (var i = 0; i < (_competition.ProblemSet?.Length ?? 0); i++) { var t = Properties.Resources.CompetitionDetailsProblemInfoControl.Replace("${index}", $"{i}").Replace("${ProblemName}", problems.Where(j => j.ProblemId == _competition.ProblemSet[i]).Select(j => j.ProblemIndex) .FirstOrDefault() ?? string.Empty); var strreader = new StringReader(t); var xmlreader = new XmlTextReader(strreader); Dispatcher.Invoke(() => { var obj = XamlReader.Load(xmlreader); CompetitionStateColumn.Columns.Add(obj as GridViewColumn); }); } Dispatcher.Invoke(() => CompetitionState.ItemsSource = _competitionInfo); var x = Connection.QueryJudgeLogBelongsToCompetition(_competition.CompetitionId); foreach (var j in problems) { if (x.Any(k => k.ProblemId == j.ProblemId && k.UserName == Connection.CurrentUserName && k.ResultSummary == "Accepted")) { j.ProblemName = "√ " + j.ProblemName; } else if (x.Any(k => k.ProblemId == j.ProblemId && k.UserName == Connection.CurrentUserName)) { j.ProblemName = "- " + j.ProblemName; } } for (var i = x.Count - 1; i >= 0; i--) { if ((_competition.Option & 128) != 0) { x[i].AdditionInfo = string.Empty; x[i].Score = new float[0]; x[i].Result = new string[0]; x[i].Timeused = new long[0]; x[i].Memoryused = new long[0]; } if ((_competition.Option & 32) != 0) { if (x[i].ResultSummary != "Accepted") { for (var j = 0; j < x[i].Score.Length; j++) { x[i].Score[j] = 0; } } } if ((_competition.Option & 64) != 0) { if ((_competition.EndTime - Convert.ToDateTime(x[i].JudgeDate)).TotalHours <= 1) { x.RemoveAt(i); } } } Dispatcher.Invoke(() => { _curJudgeInfo.Clear(); _competitionInfo.Clear(); }); if ((_competition.Option & 8) != 0 || now > _competition.EndTime) { for (var i = x.Count - 1; i >= 0; i--) { Dispatcher.Invoke(() => _curJudgeInfo.Add(x[i])); Thread.Sleep(1); } } if (!((_competition.Option & 8) == 0 && GetNowDateTime() < _competition.EndTime)) { Dispatcher.Invoke(() => { foreach (var i in CompetitionStateColumn.Columns) { if (i.Header is StackPanel j) { foreach (var k in j.Children) { if (k is TextBlock l && l.Name.Contains("ProblemColumn")) { var m = Convert.ToInt32(l.Name.Substring(13)); l.Text = $"{x.Count(p => p.ProblemId == _competition.ProblemSet[m] && p.ResultSummary == "Accepted")}/{x.Count(p => p.ProblemId == _competition.ProblemSet[m])}"; } } } } }); } var tmpList = new List <CompetitionUserInfo>(); Dispatcher.Invoke(() => _competitionInfo.Clear()); var user = x.Select(p => p.UserName).Distinct(); foreach (var i in user) { if (_competition.ProblemSet == null) { continue; } var tmp = new CompetitionUserInfo { UserName = i, ProblemInfo = new CompetitionProblemInfo[_competition.ProblemSet.Length] }; float score = 0; var totTime = new TimeSpan(0); for (var j = 0; j < _competition.ProblemSet.Length; j++) { tmp.ProblemInfo[j] = new CompetitionProblemInfo(); if ((_competition.Option & 8) == 0 && GetNowDateTime() < _competition.EndTime) { continue; } var ac = x.Count(p => p.UserName == i && p.ResultSummary == "Accepted" && p.ProblemId == _competition.ProblemSet[j]); var all = x.Count(p => p.UserName == i && p.ProblemId == _competition.ProblemSet[j]); tmp.ProblemInfo[j].Color = ac != 0 ? Brushes.LightGreen : Brushes.LightPink; var time = new TimeSpan(0); var cnt = 0; var tmpScoreBase = x.Where(p => p.UserName == i && p.ProblemId == _competition.ProblemSet[j]) .ToList(); var noAccepted = !x.Any(p => p.UserName == i && p.ProblemId == _competition.ProblemSet[j] && p.ResultSummary == "Accepted"); if ((_competition.Option & 2) == 0) { if ((_competition.Option & 32) == 0) { if (tmpScoreBase.Any()) { score += tmpScoreBase.Max(p => p.FullScore); } } tmp.ProblemInfo[j].State = $"{ac}/{all}"; foreach (var k in x.Where(p => p.UserName == i && p.ProblemId == _competition.ProblemSet[j])) { var tmpTime = Convert.ToDateTime(k.JudgeDate) - _competition.StartTime; time += tmpTime; totTime += tmpTime; if (k.ResultSummary == "Accepted") { if ((_competition.Option & 32) != 0) { score += k.FullScore; } break; } if ((_competition.Option & 4) != 0) { if (!noAccepted) { time += new TimeSpan(0, 20, 0); totTime += new TimeSpan(0, 20, 0); } cnt++; } } } else { if ((_competition.Option & 32) == 0) { if (tmpScoreBase.Any()) { score += tmpScoreBase.LastOrDefault()?.FullScore ?? 0; } } var y = x.LastOrDefault(p => p.UserName == i && p.ProblemId == _competition.ProblemSet[j]); if (y != null && y.ResultSummary == "Accepted") { if ((_competition.Option & 32) != 0) { score += y.FullScore; } tmp.ProblemInfo[j].State = "Solved"; } else { tmp.ProblemInfo[j].Color = Brushes.LightPink; tmp.ProblemInfo[j].State = "Unsolved"; } if (y != null) { var tmpTime = Convert.ToDateTime(y.JudgeDate) - _competition.StartTime; if (!noAccepted) { time += tmpTime; totTime += tmpTime; } } } if ((_competition.Option & 4) != 0 && cnt != 0) { tmp.ProblemInfo[j].State += $" (-{cnt})"; } tmp.ProblemInfo[j].Time = $"{time.Days * 24 + time.Hours}:{time.Minutes}:{time.Seconds}"; } tmp.Score = score; tmp.TotTime = totTime; tmpList.Add(tmp); } tmpList.Sort((x1, x2) => { if (Math.Abs(x1.Score - x2.Score) > 0.00001) { return(x2.Score.CompareTo(x1.Score)); } return(x1.TotTime.CompareTo(x2.TotTime)); }); for (var i = 0; i < tmpList.Count; i++) { tmpList[i].Rank = i + 1; if ((_competition.Option & 16) == 0) { Dispatcher.Invoke(() => _competitionInfo.Add(tmpList[i])); } } Dispatcher.Invoke(() => { _problemFilter.Clear(); _userFilter.Clear(); }); var problemList = x.Select(i => i.ProblemName).Distinct().OrderBy(j => j); var userList = x.Select(i => i.UserName).Distinct().OrderBy(j => j); foreach (var j in problemList) { Dispatcher.Invoke(() => _problemFilter.Add(j)); Thread.Sleep(1); } foreach (var j in userList) { Dispatcher.Invoke(() => _userFilter.Add(j)); Thread.Sleep(1); } if (GetNowDateTime() < _competition.EndTime) { _hasRefreshWhenFinished = false; } Dispatcher.Invoke(() => { Loading.Visibility = Visibility.Hidden; RefreshButton.IsEnabled = true; }); } }