Exemplo n.º 1
0
    }//读Json信息

    static public void setUserJson(hduUser user)
    {
        String str = JsonConvert.SerializeObject(user);

        Console.WriteLine(str);
        System.IO.File.WriteAllText(@"user.json", str, Encoding.UTF8);
    }//写Json信息
Exemplo n.º 2
0
 public SubmitWindow(hduUser user, String Id, MainWindow mainWindow)
 {
     this.user = user;
     InitializeComponent();
     this.mainWindow     = mainWindow;
     this.ProblemId.Text = Id;
 }
Exemplo n.º 3
0
    }//获取用户信息

    static async public void getProblemInfo(hduUser user, String problemID, MainWindow mainWindow)
    {
        problemInfomation problem = new problemInfomation();

        problem.problemId = problemID;
        login(user);
        String problemUrl = "http://acm.hdu.edu.cn/showproblem.php?pid=" + problemID;
        HttpResponseMessage response;

        response = await client.GetAsync(new Url(problemUrl));

        var responseString = await response.Content.ReadAsStringAsync();

        var parser      = new HtmlParser();
        var document    = parser.Parse(responseString);
        var problemMain = document.All.Where(m => m.LocalName == "tbody").First().Children[3].Children[0];

        //Console.WriteLine(problemMain.ToHtml());
        problem.problemName  = problemMain.FirstChild.Text();
        problem.problemValue = getTextWithWrap(problemMain.Children[1].FirstChild.FirstChild.ChildNodes);
        problem.Description  = getTextWithWrap(problemMain.Children[5].ChildNodes);
        problem.Input        = getTextWithWrap(problemMain.Children[9].ChildNodes);
        problem.Output       = getTextWithWrap(problemMain.Children[13].ChildNodes);
        problem.sampleInput  = getTextWithWrap(problemMain.Children[17].FirstChild.ChildNodes);
        problem.sampleOutput = getTextWithWrap(problemMain.Children[21].FirstChild.ChildNodes);
        mainWindow.ProblemPage.DataContext = problem;

        //Console.WriteLine(problem.problemValue);
    }//获取题目信息
Exemplo n.º 4
0
    }//检查提交状态

    static public String getSubmitRunId(hduUser user)
    {
        //didn't use login();
        String url        = "http://acm.hdu.edu.cn/status.php?user="******"table_text")[0].Children[0].Children[2];
        var    runId      = submitItem.Children[0].Text();

        return(runId);
    }//获取提交条目的RunId
Exemplo n.º 5
0
    }//初始化client

    static void login(hduUser user)
    {
        client = initClient();
        HttpResponseMessage response;
        List <KeyValuePair <String, String> > form = new List <KeyValuePair <string, string> >();

        form.Add(new KeyValuePair <string, string>("username", user.UserName));
        form.Add(new KeyValuePair <string, string>("userpass", user.Password));
        form.Add(new KeyValuePair <string, string>("login", "Sign In"));
        response = client.PostAsync(new Url(loginUrl), new FormUrlEncodedContent(form)).Result;
        //Console.WriteLine(response);
    }//登录,用于保持用户在线
Exemplo n.º 6
0
    }//登录,用于保持用户在线

    static public void submit(hduUser user, String problemId, String userCode)
    {
        login(user);
        HttpResponseMessage response;
        List <KeyValuePair <String, String> > form = new List <KeyValuePair <string, string> >();

        form.Add(new KeyValuePair <string, string>("check", "0"));
        form.Add(new KeyValuePair <string, string>("problemid", problemId));
        form.Add(new KeyValuePair <string, string>("language", "0"));
        form.Add(new KeyValuePair <string, string>("usercode", userCode));
        response = client.PostAsync(new Url(submitUrl), new FormUrlEncodedContent(form)).Result;
        //Console.WriteLine(response);
    }//模拟http post请求发送代码
Exemplo n.º 7
0
    }//连接封装

    static public submitInfo checkSubmitState(string RunId, hduUser user)
    {
        String     url        = "http://acm.hdu.edu.cn/status.php?first=+" + RunId + "+&user="******"table_text")[0].Children[0].Children[2];
        submitInfo Item       = new submitInfo();

        Item.runId     = RunId;
        Item.ProblemId = submitItem.Children[3].FirstChild.Text();
        Item.Time      = submitItem.Children[4].Text();
        Item.Memory    = submitItem.Children[5].Text();
        Item.State     = submitItem.Children[2].FirstChild.Text();
        return(Item);
    }//检查提交状态
Exemplo n.º 8
0
    static public hduUser readUserJson()
    {
        String str;

        try
        {
            str = System.IO.File.ReadAllText(@"user.json");
        }
        catch (Exception e)
        {
            return(null);
        }

        hduUser user = JsonConvert.DeserializeObject <hduUser>(str);

        return(user);
    }//读Json信息
Exemplo n.º 9
0
        private async void Tab_SelectionChangedAsync(object sender, SelectionChangedEventArgs e)
        {
            TabControl x = sender as TabControl;

            switch (x.SelectedIndex)
            {
            case 0:
            {
                if (user == null)
                {
                    LoginDialogData result = await this.ShowLoginAsync("请先登录hdu账号", "输入账号与密码", new LoginDialogSettings { ColorScheme = this.MetroDialogOptions.ColorScheme, InitialUsername = "******" });

                    String username = result.Username;
                    String password = result.Password;
                    user = new hduUser(username, password);
                    hduUser.setUserJson(user);
                }
                hduHttpHelper.getPersonalInfo(user, this);
            }
            break;

            case 1:
            {
                SetProblemListPage(0);
            }
            break;

            case 2:
            {
                if (user == null)
                {
                    Console.WriteLine("no user error!");
                    return;
                }
            }
            break;
            }
        }//Tab切换事件,完成各Tab页的生成操作
Exemplo n.º 10
0
    }//模拟http post请求发送代码

    static async public void getPersonalInfo(hduUser user, MainWindow mainWindow)
    {
        login(user);
        String userUrl = userStateUrl + user.UserName;
        HttpResponseMessage response;

        response = await client.GetAsync(new Url(userUrl));

        var responseString = await response.Content.ReadAsStringAsync();

        var            parser   = new HtmlParser();
        var            document = parser.Parse(responseString);
        var            tables   = document.All.Where(m => m.LocalName == "table" && m.GetAttribute("width") == "90%");
        var            table    = tables.First();
        var            td       = table.GetElementsByTagName("td").First();
        var            elements = td.Children;
        userInfomation nowUser  = new userInfomation();

        nowUser          = new userInfomation();
        nowUser.nickName = elements[0].Text();
        Regex  schoolRex = new Regex(@"^.*registered");
        String temp      = schoolRex.Match(elements[1].Text()).Value;

        nowUser.School       = temp.Substring(6, temp.Length - 20);
        temp                 = elements[1].Text().Substring(elements[1].Text().Length - 10);
        nowUser.regData      = new userInfomation.Date(temp);
        nowUser.registerDate = nowUser.regData.ToString();
        //Console.WriteLine(nowUser.regData.ToString());
        nowUser.Motto = elements[3].Text();
        var valueTable = elements[5].Children.First().Children;
        var rk         = Int32.Parse(valueTable[1].LastElementChild.Text());
        var sub        = Int32.Parse(valueTable[2].LastElementChild.Text());
        var sov        = Int32.Parse(valueTable[3].LastElementChild.Text());

        nowUser.setSubmitValue(rk, sub, sov);
        mainWindow.DataBinding.DataContext = nowUser;
    }//获取用户信息
Exemplo n.º 11
0
 XmlNodeList ProblemNodeList;                   //题目列表
 public MainWindow()                            //主窗体初始化
 {
     problemHistoryArray = new List <string>();
     user = hduUser.readUserJson();                            //导入用户文件,因为第一屏需要用户信息,所以在前端初始化之前
     InitializeComponent();                                    //前端初始化
     loadProblemXml();                                         //导入XML文件
     ProblemHistorySelector.ItemsSource = problemHistoryArray; //数据源设定
     tab.SelectionChanged  += Tab_SelectionChangedAsync;       //绑定Tab切换事件
     submitQueryQueue       = new Queue <string>();
     queueSubmitStateThread = new Thread(new ThreadStart(() =>
     {
         while (true)
         {
             lock (submitQueryQueue)
             {
                 if (submitQueryQueue.Count == 0)
                 {
                     break;
                 }
                 Console.WriteLine(submitQueryQueue.Count);
                 String nowId    = submitQueryQueue.Dequeue();
                 submitInfo Item = hduHttpHelper.checkSubmitState(nowId, user);
                 if (Item.State != "Queuing" && Item.State != "Compiling" && Item.State != "Running")
                 {
                     if (Item.State == "Accepted")
                     {
                         this.Invoke(new Action(() =>
                         {
                             judgeStateToast toast = new judgeStateToast();
                             toast.Accepted(Item.ProblemId + '\t' + Item.Time + '\t' + Item.Memory);
                         }));
                     }
                     else if (Item.State == "Presentation Error")
                     {
                         this.Invoke(new Action(() =>
                         {
                             judgeStateToast toast = new judgeStateToast();
                             toast.Warning(Item.ProblemId + '\t' + Item.Time + '\t' + Item.Memory);
                         }));
                     }
                     else
                     {
                         this.Invoke(new Action(() =>
                         {
                             judgeStateToast toast = new judgeStateToast();
                             toast.Error(Item.ProblemId + '\t' + Item.Time + '\t' + Item.Memory);
                         }));
                     }
                     Console.WriteLine(Item.State);
                 }
                 else
                 {
                     submitQueryQueue.Enqueue(nowId);
                 }
             }
             Thread.Sleep(500);
         }
     }))//申明线程及其运行时匿名函数
     {
         IsBackground = true
     };
 }