/// <summary> /// Performs all necessary initialization. /// </summary> protected override void Initialize() { base.Initialize(); OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; try { recentContests = Codeforces.getRecentContests(); problems = recentContests.Count > 0 ? Codeforces.getProblems(recentContests[0].id) : new List <Problem>(); // Test problem commands for (uint i = PkgCmdIDList.cmdidTestACommand; i <= PkgCmdIDList.cmdidTestTCommand; i++) { CommandID cmdID = new CommandID(GuidList.guidCF_TesterCmdSet, (int)i); OleMenuCommand mc = new OleMenuCommand(new EventHandler(MenuItemCallback), cmdID); if ((int)(i - PkgCmdIDList.cmdidTestACommand) < problems.Count) { mc.Text = problems[(int)(i - PkgCmdIDList.cmdidTestACommand)].index; } mc.Visible = (int)(i - PkgCmdIDList.cmdidTestACommand) < problems.Count; mcs.AddCommand(mc); } // Set current contest commands for (uint i = PkgCmdIDList.cmdidContestOption1Command; i <= PkgCmdIDList.cmdidContestOption6Command; i++) { CommandID cmdID = new CommandID(GuidList.guidCF_TesterCmdSet, (int)i); OleMenuCommand mc = new OleMenuCommand(new EventHandler(MenuItemCallback), cmdID); mc.Text = "#" + recentContests[(int)(i - PkgCmdIDList.cmdidContestOption1Command)].id.ToString() + " " + recentContests[(int)(i - PkgCmdIDList.cmdidContestOption1Command)].name; mcs.AddCommand(mc); } // Refresh command OleMenuCommand refresh = new OleMenuCommand(new EventHandler(MenuItemCallback), new CommandID(GuidList.guidCF_TesterCmdSet, (int)PkgCmdIDList.cmdidRefreshCommand)); mcs.AddCommand(refresh); // Debug sample test cammands for (uint i = PkgCmdIDList.cmdidDebug1Command; i <= PkgCmdIDList.cmdidDebug9Command; i++) { CommandID cmdID = new CommandID(GuidList.guidCF_TesterCmdSet, (int)i); OleMenuCommand mc = new OleMenuCommand(new EventHandler(MenuItemCallback), cmdID); mc.Visible = tests != null && (int)(i - PkgCmdIDList.cmdidDebug1Command) < tests.Count; mcs.AddCommand(mc); } } catch (FailedRequestException exception) { MessageBox.Show(exception.Message, "Codeforces Tester", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Changes the contest chosen by user. /// </summary> /// <param name="newContest">New contest id (in recentContests).</param> private void ChangeContest(int newContest) { if (newContest > 0) { Contest temp = recentContests[0]; recentContests[0] = recentContests[newContest]; for (; newContest > 1 && recentContests[newContest - 1].id < temp.id; newContest--) { recentContests[newContest] = recentContests[newContest - 1]; } for (; newContest < 5 && recentContests[newContest + 1].id > temp.id; newContest++) { recentContests[newContest] = recentContests[newContest + 1]; } recentContests[newContest] = temp; } OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; for (uint i = PkgCmdIDList.cmdidContestOption1Command; i <= PkgCmdIDList.cmdidContestOption6Command; i++) { CommandID cmdID = new CommandID(GuidList.guidCF_TesterCmdSet, (int)i); OleMenuCommand mc = (OleMenuCommand)mcs.FindCommand(cmdID); mc.Text = "#" + recentContests[(int)(i - PkgCmdIDList.cmdidContestOption1Command)].id.ToString() + " " + recentContests[(int)(i - PkgCmdIDList.cmdidContestOption1Command)].name; } try { this.problems = Codeforces.getProblems(recentContests[0].id); for (uint i = PkgCmdIDList.cmdidTestACommand; i <= PkgCmdIDList.cmdidTestTCommand; i++) { CommandID cmdID = new CommandID(GuidList.guidCF_TesterCmdSet, (int)i); OleMenuCommand mc = (OleMenuCommand)mcs.FindCommand(cmdID); if ((int)(i - PkgCmdIDList.cmdidTestACommand) < problems.Count) { mc.Text = problems[(int)(i - PkgCmdIDList.cmdidTestACommand)].index; } mc.Visible = (int)(i - PkgCmdIDList.cmdidTestACommand) < problems.Count; } } catch (FailedRequestException exception) { MessageBox.Show(exception.Message, "Codeforces Tester", MessageBoxButtons.OK, MessageBoxIcon.Error); } }