Example #1
0
 public void GetAcceptedTest()
 {
     WebService target = new WebService(); // TODO: 初始化为适当的值
     string name = "changchang"; // TODO: 初始化为适当的值
     ProgressBar progressBar = new ProgressBar(); // TODO: 初始化为适当的值
     List<Problem> expected = new List<Problem>(); // TODO: 初始化为适当的值
     List<Problem> actual;
     Problem problem = new Problem();
     problem.Id = 1003;
     problem.AcTime = Convert.ToDateTime("2012-10-26 00:34:36");
     expected.Add(problem);
     //progressBar.Value += 1;
     actual = target.GetAccepted(name, progressBar);
     Assert.AreEqual(expected[0].AcTime, actual[0].AcTime);
     Assert.AreEqual(expected[0].Id, actual[0].Id);
     //Assert.Inconclusive("验证此测试方法的正确性。");
 }
Example #2
0
        //根据账号获取AC题目信息
        public List<Problem> GetAccepted(String name, ProgressBar progressBar)
        {
            List<Problem> Result = new List<Problem>();
            int ProID = 0;
            String SubmitTime = String.Empty;
            //go

            String temp = String.Empty;
            String url = "http://acm.hdu.edu.cn/status.php?user="******"&pid=0&lang=0&status=5#status";
            Encoding encode = Encoding.GetEncoding("gb2312");
            String Page = String.Empty;
            int head = 0;
            int foot = 0;
            try
            {
                while (true)
                {
                    Page = this.GetWebContent(url, encode);
                    if (!Page.Contains("<font color=red>Accepted</font>"))
                    {
                        break;
                    }
                    head = Page.IndexOf("</center></form></td>");
                    head = Page.IndexOf("<td>", head);
                    while (true)
                    {
                        head += 4;
                        foot = Page.IndexOf("</td>", head);
                        SubmitTime = Page.Substring(head, foot - head);
                        head = Page.IndexOf("<a href=", head);
                        head = Page.IndexOf(">", head);
                        head += 1;
                        foot = Page.IndexOf("</a>", head);
                        ProID = System.Int32.Parse(Page.Substring(head, foot - head));
                        Problem problem = new Problem();
                        problem.Id = ProID;
                        problem.AcTime = Convert.ToDateTime(SubmitTime);
                        Result.Add(problem);
                        progressBar.Value += progressBar.Value == progressBar.Maximum ? 0 : 1;
                        Application.DoEvents();
                        head = Page.IndexOf("</tr>", head);
                        if (Page.Substring(head, 13).Equals("</tr></table>"))
                        {
                            break;
                        }
                        head = Page.IndexOf("<td>", head);
                    }
                    if (!Page.Contains("Next Page"))
                    {
                        break;
                    }
                    head = Page.IndexOf("Prev Page</a>", head);
                    head += 48;
                    foot = Page.IndexOf("Next Page", head);
                    foot -= 2;
                    temp = Page.Substring(head, foot - head);
                    url = "http://acm.hdu.edu.cn" + temp;
                }
                return Result;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
                return null;
            }
        }