Skip to content
This repository has been archived by the owner on Aug 19, 2021. It is now read-only.

Commit

Permalink
Finish Network Function Making
Browse files Browse the repository at this point in the history
A big milestone. This software is usable now!!!!!
  • Loading branch information
wpcwzy committed Apr 4, 2019
1 parent b9b0c3c commit 032acd4
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 27 deletions.
15 changes: 14 additions & 1 deletion Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 72 additions & 24 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public Form1()
InitializeComponent();
form = this;
engine.init();

}

private void button16_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -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";
}
}


Expand Down Expand Up @@ -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 "";
}
}

Expand Down Expand Up @@ -385,7 +433,7 @@ public bool isLegal(Button lastButton,Button sender)
}
}

private string convertMap()
public string convertMap()
{
int i=0;
string result = "";
Expand Down
4 changes: 2 additions & 2 deletions WER2019Tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<ErrorReportUrl>https://www.github.com/wpcwzy/WER2019Tool</ErrorReportUrl>
<ProductName>WER2019智能分拣规划工具</ProductName>
<PublisherName>王品呈</PublisherName>
<ApplicationRevision>4</ApplicationRevision>
<ApplicationVersion>0.2.7.%2a</ApplicationVersion>
<ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>0.3.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<CreateDesktopShortcut>true</CreateDesktopShortcut>
<PublishWizardCompleted>true</PublishWizardCompleted>
Expand Down

0 comments on commit 032acd4

Please sign in to comment.