コード例 #1
0
ファイル: Form1.cs プロジェクト: Baekjoon/contest-client
 private void button1_Click(object sender, EventArgs e)
 {
     if (usernameTextBox.Text.Length == 0)
     {
         MessageBox.Show("아이디를 입력해 주세요.");
         usernameTextBox.Focus();
     }
     else if (passwordTextBox.Text.Length == 0)
     {
         MessageBox.Show("비밀번호를 입력해 주세요.");
         passwordTextBox.Focus();
     }
     else
     {
         resultLabel.ForeColor = Color.Black;
         resultLabel.Text = "로그인 중";
         MyWebRequest loginRequest = new MyWebRequest("https://www.acmicpc.net/client/login", "POST", String.Format("username={0}&password={1}", usernameTextBox.Text, passwordTextBox.Text));
         string response = loginRequest.GetResponse();
         var dict = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(response);
         if ((bool)dict["error"] == true)
         {
             resultLabel.ForeColor = Color.Red;
             resultLabel.Text = (string)dict["error_text"];
         }
         else
         {
             Info.login_key = (string)dict["login_key"];
             Info.user_id = (string)dict["user_id"];
             resultLabel.Text = "";
             problem_form_showing = true;
             this.Close();
             new ProblemForm().Show();
         }
     }
 }
コード例 #2
0
 void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     Dictionary<string, object> d = (Dictionary<string, object>)e.Argument;
     int what = (int)d["what"];
     if (what == CONTEST_INFO)
     {
         MyWebRequest loginRequest = new MyWebRequest("https://www.acmicpc.net/client/contest", "POST", String.Format("login_key={0}", Info.login_key));
         string response = loginRequest.GetResponse();
         Console.WriteLine(response);
         var dict = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(response);
         dict["what"] = what;
         e.Result = dict;
     }
     else if (what == CONTEST_SUBMIT)
     {
         MyWebRequest loginRequest = new MyWebRequest("https://www.acmicpc.net/client/submit", "POST", String.Format("login_key={0}&contest_id={1}&contest_number={2}&language={3}&source={4}", Info.login_key,d["contest_id"],d["contest_number"],d["language"],d["source"]));
         string response = loginRequest.GetResponse();
         Console.WriteLine(response);
         var dict = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(response);
         dict["what"] = what;
         dict["problem_title"] = d["problem_title"];
         dict["language_name"] = d["language_name"];
         e.Result = dict;
     }
     else if (what == CONTEST_STATUS)
     {
         updating = true;
         MyWebRequest loginRequest = new MyWebRequest("https://www.acmicpc.net/client/status", "POST", String.Format("login_key={0}&solution_id={1}&key={2}", Info.login_key,d["solution_id"],d["key"]));
         string response = loginRequest.GetResponse();
         Console.WriteLine(response);
         var dict = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(response);
         dict["what"] = what;
         dict["solution_id"] = d["solution_id"];
         e.Result = dict;
     }
     else if (what == CONTEST_SUBMISSION)
     {
         MyWebRequest loginRequest = new MyWebRequest("https://www.acmicpc.net/client/submission", "POST", String.Format("login_key={0}&contest_id={1}", Info.login_key, d["contest_id"]));
         string response = loginRequest.GetResponse();
         Console.WriteLine(response);
         var dict = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(response);
         dict["what"] = what;
         e.Result = dict;
     }
 }