diff --git a/Form1.Designer.cs b/Form1.Designer.cs
index 298bd02..8778574 100644
--- a/Form1.Designer.cs
+++ b/Form1.Designer.cs
@@ -56,6 +56,7 @@ private void InitializeComponent()
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.natureMode = new System.Windows.Forms.RadioButton();
this.codeMode = new System.Windows.Forms.RadioButton();
+ this.download = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
@@ -260,7 +261,7 @@ private void InitializeComponent()
//
// button16
//
- this.button16.Location = new System.Drawing.Point(12, 105);
+ this.button16.Location = new System.Drawing.Point(12, 23);
this.button16.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.button16.Name = "button16";
this.button16.Size = new System.Drawing.Size(140, 72);
@@ -403,11 +404,22 @@ private void InitializeComponent()
this.codeMode.UseVisualStyleBackColor = true;
this.codeMode.CheckedChanged += new System.EventHandler(this.codeMode_CheckedChanged);
//
+ // download
+ //
+ this.download.Location = new System.Drawing.Point(12, 105);
+ this.download.Name = "download";
+ this.download.Size = new System.Drawing.Size(140, 72);
+ this.download.TabIndex = 26;
+ this.download.Text = "下载当前参考解题思路";
+ this.download.UseVisualStyleBackColor = true;
+ this.download.Click += new System.EventHandler(this.download_Click);
+ //
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 554);
+ this.Controls.Add(this.download);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.load);
this.Controls.Add(this.help);
@@ -473,6 +485,7 @@ private void InitializeComponent()
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RadioButton natureMode;
private System.Windows.Forms.RadioButton codeMode;
+ private System.Windows.Forms.Button download;
}
}
diff --git a/Form1.cs b/Form1.cs
index 8d8bd10..a060168 100644
--- a/Form1.cs
+++ b/Form1.cs
@@ -32,7 +32,6 @@ public Form1()
InitializeComponent();
form = this;
engine.init();
-
}
private void button16_Click(object sender, EventArgs e)
@@ -165,6 +164,17 @@ private void codeMode_CheckedChanged(object sender, EventArgs e)
}
textBox1.Text = engine.code;
}
+ private void download_Click(object sender, EventArgs e)
+ {
+ string downloadCode;
+ network network = new network();
+ textBox1.Text += "=======开始下载=======\r\n";
+ downloadCode =network.downloadMap(engine.convertMap());
+ textBox1.Text += downloadCode;
+ engine.code += downloadCode;
+ textBox1.Text += "\r\n";
+ textBox1.Text += "=======下载结束=======\r\n";
+ }
}
@@ -242,32 +252,70 @@ public partial class network
{
public void upload(string map,string input)
{
- try
- {
- input = System.Text.RegularExpressions.Regex.Replace(input, "[\r\n\t]", "");
- string postString = "map=" + map + "&" + "code=" + input;//这里即为传递的参数,可以用工具抓包分析,也可以自己分析,主要是form里面每一个name都要加进来
- byte[] postData = Encoding.UTF8.GetBytes(postString);//编码,尤其是汉字,事先要看下抓取网页的编码方式
- string url = "http://wpcwzy.top/data/process.php";//地址
- WebClientEx webClient = new WebClientEx();
- webClient.Timeout = 5500;
- MessageBox.Show("恭喜您成功解题!程序将上传您的解题思路至服务器进行统计研究,期间程序将会假死5秒,属正常现象\n若您有什么意见可以在帮助窗口中进行反馈,感谢您的合作。");
- webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");//采取POST方式必须加的header,如果改为GET方式的话就去掉这句话即可
- byte[] responseData = webClient.UploadData(url, "POST", postData);//得到返回字符流
- string srcString = Encoding.UTF8.GetString(responseData);//解码
- Console.WriteLine(srcString);
-
- }
- catch (WebException)
+ int redo = 0;
+ while(redo<=3)
{
- Console.WriteLine("Upload success with error.");
+ try
+ {
+ //input = System.Text.RegularExpressions.Regex.Replace(input, "[\r\n\t]", "");
+ string postString = "?map=" + map + "&" + "code=" + input;//这里即为传递的参数,可以用工具抓包分析,也可以自己分析,主要是form里面每一个name都要加进来
+ byte[] postData = Encoding.UTF8.GetBytes(postString);//编码,尤其是汉字,事先要看下抓取网页的编码方式
+ string url = "http://wpcwzy.top/data/process.php" + postString;//地址
+ Console.WriteLine("Server URL:{0}", url);
+ WebClientEx webClient = new WebClientEx();
+ webClient.Timeout = 7000;
+ MessageBox.Show("恭喜您成功解题!程序将上传您的解题思路至服务器进行统计研究\n若您有什么意见可以在帮助窗口中进行反馈,感谢您的合作。");
+ byte[] responseData = webClient.DownloadData(url);//得到返回字符流
+ string srcString = Encoding.UTF8.GetString(responseData);//解码
+ Console.WriteLine(srcString);
+ break;
+ }
+ catch(WebException)
+ {
+ redo++;
+ Console.WriteLine("Retry:{0} Time(s)", redo);
+ continue;
+ }
+ catch (Exception ex)
+ {
+ var notice = Form1.form.airbrake.BuildNotice(ex);
+ var response = Form1.form.airbrake.NotifyAsync(notice).Result;
+ Console.WriteLine("Status: {0}, Id: {1}, Url: {2}", response.Status, response.Id, response.Url);
+ throw ex;
+ }
}
- catch (Exception ex)
+ }
+ public string downloadMap(string map)
+ {
+ int redo = 0;
+ while (redo<=3)
{
- var notice = Form1.form.airbrake.BuildNotice(ex);
- var response = Form1.form.airbrake.NotifyAsync(notice).Result;
- Console.WriteLine("Status: {0}, Id: {1}, Url: {2}", response.Status, response.Id, response.Url);
- throw ex;
+ try
+ {
+ string url = "http://wpcwzy.top/data/" + map;//地址
+ Console.WriteLine("Server URL:{0}", url);
+ WebClientEx webClient = new WebClientEx();
+ webClient.Timeout = 7000;
+ byte[] responseData = webClient.DownloadData(url);//得到返回字符流
+ string srcString = Encoding.UTF8.GetString(responseData);//解码
+ Console.WriteLine(srcString.Substring(16, srcString.Length - 16));
+ return srcString.Substring(16, srcString.Length - 16);
+ }
+ catch (WebException)
+ {
+ redo++;
+ Console.WriteLine("Retry:{0} Time(s)", redo);
+ continue;
+ }
+ catch (Exception ex)
+ {
+ var notice = Form1.form.airbrake.BuildNotice(ex);
+ var response = Form1.form.airbrake.NotifyAsync(notice).Result;
+ Console.WriteLine("Status: {0}, Id: {1}, Url: {2}", response.Status, response.Id, response.Url);
+ throw ex;
+ }
}
+ return "";
}
}
@@ -385,7 +433,7 @@ public bool isLegal(Button lastButton,Button sender)
}
}
- private string convertMap()
+ public string convertMap()
{
int i=0;
string result = "";
diff --git a/WER2019Tool.csproj b/WER2019Tool.csproj
index ec19a19..65522dd 100644
--- a/WER2019Tool.csproj
+++ b/WER2019Tool.csproj
@@ -28,8 +28,8 @@
https://www.github.com/wpcwzy/WER2019Tool
WER2019智能分拣规划工具
王品呈
- 4
- 0.2.7.%2a
+ 1
+ 0.3.0.%2a
false
true
true