Make_WirelessThroughput.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. using DevExpress.Utils.Drawing.Helpers;
  2. using DevExpress.XtraReports;
  3. using NPOI.SS.Formula.Functions;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Diagnostics;
  9. using System.Drawing;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Net;
  13. using System.Net.Sockets;
  14. using System.Text;
  15. using System.Text.RegularExpressions;
  16. using System.Threading;
  17. using System.Web.Services.Description;
  18. using System.Web.UI.WebControls.WebParts;
  19. using System.Windows.Forms;
  20. using UAS_MES_NEW.DataOperate;
  21. using UAS_MES_NEW.Entity;
  22. using UAS_MES_NEW.PublicMethod;
  23. namespace UAS_MES_NEW.Make
  24. {
  25. public partial class Make_WirelessThroughput : Form
  26. {
  27. public Make_WirelessThroughput()
  28. {
  29. InitializeComponent();
  30. }
  31. StringBuilder SQL = new StringBuilder();
  32. DataTable dt;
  33. DataHelper dh;
  34. string telnetPort;
  35. private void Make_WirelessThroughput_Load(object sender, EventArgs e)
  36. {
  37. dh = SystemInf.dh;
  38. try
  39. {
  40. string hostName = Dns.GetHostName();
  41. IPHostEntry hostEntry = Dns.GetHostEntry(hostName);
  42. foreach (IPAddress ip in hostEntry.AddressList)
  43. {
  44. if (ip.AddressFamily == AddressFamily.InterNetwork)
  45. {
  46. IPList.Text = ip.ToString();
  47. }
  48. }
  49. }
  50. catch (Exception ex)
  51. {
  52. ShowMsg(0, $"获取iperf服务器地址失败,{ex.Message}");
  53. }
  54. if (!IPList.Text.Contains(":"))
  55. {
  56. IPList.Text = IPList.Text + ":5021";
  57. }
  58. telnetPort = "23";
  59. //if (!ProductList.Text.Contains(":"))
  60. //{
  61. // ProductList.Text = ProductList.Text + ":23";
  62. //}
  63. Locat1.Visible = false;
  64. Locat2.Visible = false;
  65. Locat3.Visible = false;
  66. Radio1.Visible = false;
  67. Radio2.Visible = false;
  68. }
  69. private void SN_KeyDown(object sender, KeyEventArgs e)
  70. {
  71. if (e.KeyCode != Keys.Enter) return;
  72. if (IPList.Text.IndexOf(':') > 0) IPList.Text = IPList.Text.Replace(":", ":");
  73. else IPList.Text = IPList.Text.Trim();
  74. SN.Text = SN.Text.Trim().Replace(";", ";");
  75. string sn = SN.Text.Trim();
  76. SQL.Clear();
  77. //SQL.Append($"SELECT pr_test_account,pr_test_password FROM makeserial,product WHERE ms_sncode = '{sn}' AND ms_prodcode = pr_code");
  78. SQL.Append($"SELECT * FROM (SELECT pr_test_account,pr_test_password FROM makeserial,product WHERE ms_sncode = '{sn}' AND ms_prodcode = pr_code ORDER BY ms_indate DESC) WHERE ROWNUM = 1");
  79. dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
  80. if (dt.Rows.Count == 0)
  81. {
  82. ShowMsg(0, $"序列号:{sn}未维护吞吐量测试账户密码");
  83. }
  84. else
  85. {
  86. Account.Text = dt.Rows[0]["pr_test_account"].ToString();
  87. Password.Text = dt.Rows[0]["pr_test_password"].ToString();
  88. }
  89. if (IsCheckSet()) return;
  90. UpdateSN("L", SN.Text.Trim());
  91. ShowMsg(1, $"开始测试");
  92. int iSPort = Convert.ToInt32(IPList.Text.Trim().Split(':')[1]);
  93. var tester = new CameraIperfTester(
  94. timeOut: TestTime.Text.Trim(),
  95. cameraIp: ProductList.Text.Trim().Split(':')[0],
  96. cameraPort: Convert.ToInt32(telnetPort),
  97. username: Account.Text.Trim(),
  98. password: Password.Text.Trim(),
  99. iperfServerIp: IPList.Text.Trim().Split(':')[0],
  100. iperfServerPort: iSPort
  101. );
  102. string parentPath = Path.GetDirectoryName(ExePath.Text.Trim());
  103. string logsPath = Path.Combine(parentPath, "iperf_logs");
  104. if (!Directory.Exists(logsPath))
  105. {
  106. Directory.CreateDirectory(logsPath);
  107. }
  108. string Msg = tester.TestStart(SN.Text.Trim(), ExePath.Text.Trim(), logsPath);
  109. if (Msg.StartsWith("NG"))
  110. {
  111. ShowMsg(0, Msg);
  112. return;
  113. }
  114. string upRate = Msg.Split('|')[0].Split(',')[1];
  115. string downRate = Msg.Split('|')[1];
  116. ShowMsg(1, $"OK,上行速率: {upRate},下行速率: {downRate}");
  117. ResMax.Text = upRate;
  118. ResMin.Text = downRate;
  119. string tDetail = $"upRate/{upRate};downRate/{downRate}";
  120. CheckPassStation(SN.Text, "PASS", tDetail);
  121. }
  122. private void CheckPassStation(string sn, string testRes,string testDetail)
  123. {
  124. List<string> param = new List<string>() { };
  125. string outMsg = "";
  126. param.Add(workOrder.Text);
  127. param.Add(sn);
  128. param.Add(User.UserSourceCode);
  129. param.Add(testRes);
  130. param.Add("");
  131. param.Add("");
  132. param.Add("Thruput");
  133. param.Add(testDetail);
  134. param.Add(outMsg);
  135. string[] paramList = param.ToArray();
  136. dh.CallProcedure("cs_insert_testrejects", ref paramList);
  137. if (paramList[8].Substring(0, 2) == "OK")
  138. {
  139. ShowMsg(1, $"序列号{sn}采集成功:测试结果为{testRes}");
  140. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, workOrder.Text, User.UserLineCode, User.UserSourceCode, "无线吞吐量", "无线吞吐量过站成功", sn, "");
  141. }
  142. dt = (DataTable)dh.ExecuteSql($"SELECT mp_id FROM makeprocess WHERE mp_sncode = '{sn}' AND instr(mp_stepname, '吞吐量') > 0", "select");
  143. if (dt.Rows.Count > 0)
  144. {
  145. ShowMsg(1, $"序列号:{sn}已经过站记录");
  146. return;
  147. }
  148. string oWO, oWOId, oErrMsg = "";
  149. if (LogicHandler.CheckStepSNAndMacode(workOrder.Text, User.UserSourceCode, sn, User.UserCode, out oWO, out oWOId, out oErrMsg))
  150. {
  151. if (LogicHandler.SetStepResult(oWO, User.UserSourceCode, sn, "无线吞吐量", "OK", User.UserCode, out oErrMsg))
  152. {
  153. ShowMsg(0, $"序列号{sn},过站记录成功");
  154. }
  155. else
  156. {
  157. ShowMsg(0, $"序列号{sn},处理过站NG:{oErrMsg}");
  158. }
  159. }
  160. else
  161. {
  162. ShowMsg(0, $"序列号{sn},过站核对NG:{oErrMsg}");
  163. }
  164. }
  165. private bool IsCheckSet()
  166. {
  167. if (string.IsNullOrEmpty(IPList.Text))
  168. {
  169. ShowMsg(0, "请选择本地iperf 服务IP地址");
  170. return true;
  171. }
  172. if (string.IsNullOrEmpty(ProductList.Text))
  173. {
  174. ShowMsg(0, "请选择产品固定IP地址");
  175. return true;
  176. }
  177. if (string.IsNullOrEmpty(Account.Text))
  178. {
  179. ShowMsg(0, "请输入Telnet登录账号");
  180. return true;
  181. }
  182. if (string.IsNullOrEmpty(Password.Text))
  183. {
  184. ShowMsg(0, "请输入Telnet登录密码");
  185. return true;
  186. }
  187. if (string.IsNullOrEmpty(ExePath.Text))
  188. {
  189. ShowMsg(0, "请输入启动iperf3文件");
  190. return true;
  191. }
  192. if (!File.Exists(ExePath.Text))
  193. {
  194. Console.WriteLine("iperf3启动文件不存在");
  195. }
  196. if (string.IsNullOrEmpty(TestTime.Text))
  197. {
  198. ShowMsg(0, "请输入测试时长");
  199. return true;
  200. }
  201. //if (Locat1.Checked == false || Locat2.Checked == false || Locat3.Checked == false)
  202. //{
  203. // ShowMsg(0, "请选择固件位置");
  204. // return true;
  205. //}
  206. //if (Radio1.Checked == false || Radio1.Checked == false )
  207. //{
  208. // ShowMsg(0, "请选择测试类型");
  209. // return true;
  210. //}
  211. return false;
  212. }
  213. private void UpdateSN(string type, string sn)
  214. {
  215. if (type == "C")
  216. {
  217. serialNumber.Text = "";
  218. workOrder.Text = "";
  219. productCode.Text = "";
  220. productName.Text = "";
  221. }
  222. else if (type == "L")
  223. {
  224. SQL.Clear();
  225. SQL.Append($@"SELECT ms_sncode,ma_code,pr_code,pr_spec FROM makeserial,make,product
  226. WHERE ms_sncode = '{sn}' AND ms_makecode = ma_code AND ms_prodcode = pr_code");
  227. dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
  228. if (dt.Rows.Count > 0)
  229. {
  230. serialNumber.Text = dt.Rows[0]["ms_sncode"].ToString();
  231. workOrder.Text = dt.Rows[0]["ma_code"].ToString();
  232. productCode.Text = dt.Rows[0]["pr_code"].ToString();
  233. productName.Text = dt.Rows[0]["pr_spec"].ToString();
  234. }
  235. else
  236. {
  237. UpdateSN("C", sn);
  238. }
  239. }
  240. }
  241. public class CameraIperfTester
  242. {
  243. int timeOut;
  244. string cameraIp, iperfServerIp, username, password;
  245. int cameraPort, iperfServerPort;
  246. string SN, iperfPath, logDirectory;
  247. private TcpClient _telnetClient;
  248. private NetworkStream _telnetStream;
  249. string sVal1, sVal2, rVal1, rVal2;
  250. public CameraIperfTester(string timeOut, string cameraIp, int cameraPort, string username, string password, string iperfServerIp, int iperfServerPort)
  251. {
  252. this.timeOut = Convert.ToInt32(timeOut) * 1000;
  253. this.cameraIp = cameraIp;
  254. this.cameraPort = cameraPort;
  255. this.username = username;
  256. this.password = password;
  257. this.iperfServerIp = iperfServerIp;
  258. this.iperfServerPort = iperfServerPort;
  259. }
  260. public string TestStart(string sn, string iP, string lD)
  261. {
  262. StringBuilder Msg = new StringBuilder();
  263. Msg.Append(TelnetConnect());
  264. if (Msg.ToString().StartsWith("NG")) return Msg.ToString();
  265. SN = sn;
  266. iperfPath = iP;
  267. logDirectory = lD;
  268. Msg.Clear();
  269. Msg.Append(StartIperfTest());
  270. if (Msg.ToString().StartsWith("NG")) return Msg.ToString();
  271. return Msg.ToString();
  272. }
  273. public string TelnetConnect()
  274. {
  275. try
  276. {
  277. _telnetClient = new TcpClient();
  278. IAsyncResult connectResult = _telnetClient.BeginConnect(cameraIp, cameraPort, null, null);
  279. bool connected = connectResult.AsyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds(timeOut));
  280. if (!connected)
  281. {
  282. _telnetClient.Close();
  283. return "NG,连接超时";
  284. }
  285. try
  286. {
  287. _telnetClient.EndConnect(connectResult);
  288. }
  289. catch (SocketException ex)
  290. {
  291. return $"NG,连接失败: {ex.Message}";
  292. }
  293. _telnetStream = _telnetClient.GetStream();
  294. _telnetStream.ReadTimeout = timeOut;
  295. StringBuilder fullResponse = new StringBuilder();
  296. string welcomeResponse = ReadStream(_telnetStream);
  297. if (welcomeResponse.StartsWith("NG")) return welcomeResponse;
  298. fullResponse.Append(welcomeResponse);
  299. WriteStream(_telnetStream, username);
  300. string usernameResponse = ReadStream(_telnetStream);
  301. if (usernameResponse.StartsWith("NG")) return usernameResponse;
  302. fullResponse.Append(usernameResponse);
  303. WriteStream(_telnetStream, password);
  304. string loginResponse = ReadStream(_telnetStream);
  305. if (loginResponse.StartsWith("NG")) return loginResponse;
  306. fullResponse.Append(loginResponse);
  307. return $"OK,{fullResponse.ToString()}";
  308. }
  309. catch (Exception ex)
  310. {
  311. Close();
  312. return $"NG,{ex.Message}";
  313. }
  314. }
  315. public string StartIperfTest()
  316. {
  317. try
  318. {
  319. StringBuilder streamTxt = new StringBuilder();
  320. string upRate, downRate, cmdLog, upLog, downLog;
  321. if (username.ToUpper() == "ROOT")
  322. {
  323. WriteStream(_telnetStream, "killall iperf3");
  324. streamTxt.Append(ReadStream(_telnetStream));
  325. Thread.Sleep(500);
  326. WriteStream(_telnetStream, $"iperf3 -s -p {iperfServerPort} -i 1&");
  327. streamTxt.Append(ReadStream(_telnetStream));
  328. Thread.Sleep(500);
  329. cmdLog = Path.Combine(logDirectory, $"{SN}_CMD.log");
  330. File.WriteAllText(cmdLog, streamTxt.ToString());
  331. upLog = Path.Combine(logDirectory, $"{SN}_up.log");
  332. downLog = Path.Combine(logDirectory, $"{SN}_down.log");
  333. RunIperfClient($"-c {cameraIp} -p {iperfServerPort} -t 10 -w 1M -i 1 -P 8 -R", iperfPath, upLog);
  334. RunIperfClient($"-c {cameraIp} -p {iperfServerPort} -t 10 -w 1M -i 1 -P 8", iperfPath, downLog);
  335. upRate = ParseIperfBitrate(upLog);
  336. downRate = ParseIperfBitrate(downLog);
  337. Close();
  338. return $"OK,{upRate}|{downRate}";
  339. }
  340. else
  341. {
  342. WriteStream(_telnetStream, "killall iperf3_mstar");
  343. streamTxt.Append(ReadStream(_telnetStream));
  344. Thread.Sleep(500);
  345. WriteStream(_telnetStream, "cp /mnt/tf/usb1_1/iperf3_mstar /var/tmp/ -f");
  346. streamTxt.Append(ReadStream(_telnetStream));
  347. Thread.Sleep(500);
  348. WriteStream(_telnetStream, "chmod a+x /var/tmp/iperf3_mstar");
  349. streamTxt.Append(ReadStream(_telnetStream));
  350. Thread.Sleep(500);
  351. WriteStream(_telnetStream, $"/var/tmp/iperf3_mstar -s -p {iperfServerPort} -i 1 &");
  352. streamTxt.Append(ReadStream(_telnetStream));
  353. cmdLog = Path.Combine(logDirectory, $"{SN}_CMD.log");
  354. File.WriteAllText(cmdLog, streamTxt.ToString());
  355. upLog = Path.Combine(logDirectory, $"{SN}_up.log");
  356. downLog = Path.Combine(logDirectory, $"{SN}_down.log");
  357. RunIperfClient($"/var/tmp/iperf3 -c {cameraIp} -p {iperfServerPort} -t 6 -w 1M -i 1 -l 1518 -P 8 -R", iperfPath, upLog);
  358. RunIperfClient($"/var/tmp/iperf3 -c {cameraIp} -p {iperfServerPort} -t 6 -w 1M -i 1 -l 1518 -P 8", iperfPath, downLog);
  359. upRate = ParseIperfBitrate(upLog);
  360. downRate = ParseIperfBitrate(downLog);
  361. Close();
  362. return $"OK,{upRate}|{downRate}";
  363. }
  364. }
  365. catch (Exception ex)
  366. {
  367. return $"NG,{ex.Message}";
  368. }
  369. }
  370. private void RunIperfClient(string args, string path, string logPath)
  371. {
  372. var psi = new ProcessStartInfo
  373. {
  374. FileName = path,
  375. Arguments = args,
  376. RedirectStandardOutput = true,
  377. RedirectStandardError = true,
  378. UseShellExecute = false,
  379. CreateNoWindow = true,
  380. WorkingDirectory = Path.GetDirectoryName(path)
  381. };
  382. using (var process = Process.Start(psi))
  383. {
  384. StringBuilder outputBuilder = new StringBuilder();
  385. StringBuilder errorBuilder = new StringBuilder();
  386. process.OutputDataReceived += (sender, e) =>
  387. {
  388. if (!string.IsNullOrEmpty(e.Data))
  389. {
  390. outputBuilder.AppendLine(e.Data);
  391. }
  392. };
  393. process.ErrorDataReceived += (sender, e) =>
  394. {
  395. if (!string.IsNullOrEmpty(e.Data))
  396. {
  397. errorBuilder.AppendLine(e.Data);
  398. }
  399. };
  400. process.BeginOutputReadLine();
  401. process.BeginErrorReadLine();
  402. process.WaitForExit();
  403. File.WriteAllText(logPath, outputBuilder.ToString() + errorBuilder.ToString());
  404. }
  405. }
  406. public string ParseIperfBitrate(string logPath)
  407. {
  408. if (!File.Exists(logPath)) return "0.0";
  409. var lines = File.ReadAllLines(logPath);
  410. List<string> logItem = new List<string> { };
  411. foreach (var line in lines)
  412. {
  413. if (line.Trim().StartsWith("[SUM]"))
  414. {
  415. logItem.Add(line);
  416. }
  417. }
  418. if (logItem.Count > 0 && logItem[logItem.Count - 2].Contains("sender"))
  419. {
  420. var match = Regex.Match(logItem[logItem.Count - 2], @"(\d+\.\d+\s+MBytes).*?(\d+\.\d+\s+Mbits/sec)");
  421. if (match.Success)
  422. {
  423. sVal1 = match.Groups[1].Value;
  424. sVal2 = match.Groups[2].Value;
  425. }
  426. }
  427. if (logItem.Count > 0 && logItem[logItem.Count -1].Contains("receiver"))
  428. {
  429. var match = Regex.Match(logItem[logItem.Count - 1], @"(\d+\.\d+\s+MBytes).*?(\d+\.\d+\s+Mbits/sec)");
  430. if (match.Success)
  431. {
  432. rVal1 = match.Groups[1].Value;
  433. rVal2 = match.Groups[2].Value;
  434. }
  435. }
  436. //double num1 = (double.Parse(sVal1.Split(' ')[0]) + double.Parse(rVal1.Split(' ')[0])) / 2;
  437. //double num2 = (double.Parse(sVal2.Split(' ')[0]) + double.Parse(rVal2.Split(' ')[0])) / 2;
  438. return rVal2;
  439. }
  440. private string WriteStream(NetworkStream stream, string data)
  441. {
  442. try
  443. {
  444. byte[] dataBytes = Encoding.UTF8.GetBytes(data + "\r\n");
  445. stream.Write(dataBytes, 0, dataBytes.Length);
  446. stream.Flush();
  447. return $"OK";
  448. }
  449. catch (Exception ex)
  450. {
  451. Close();
  452. return $"NG,写入数据时发生错误: {ex.Message}";
  453. }
  454. }
  455. private string ReadStream(NetworkStream stream)
  456. {
  457. try
  458. {
  459. StringBuilder response = new StringBuilder();
  460. byte[] buffer = new byte[1024];
  461. int bytesRead;
  462. while (stream.DataAvailable || response.Length == 0)
  463. {
  464. bytesRead = stream.Read(buffer, 0, buffer.Length);
  465. if (bytesRead > 0)
  466. {
  467. response.Append(Encoding.UTF8.GetString(buffer, 0, bytesRead));
  468. }
  469. else
  470. {
  471. break;
  472. }
  473. Thread.Sleep(100);
  474. }
  475. return response.ToString();
  476. }
  477. catch (IOException ioEx) when (ioEx.InnerException is SocketException socketEx && socketEx.SocketErrorCode == SocketError.TimedOut)
  478. {
  479. Close();
  480. return "NG,读取数据超时";
  481. }
  482. catch (Exception ex)
  483. {
  484. Close();
  485. return $"NG,读取数据时发生错误: {ex.Message}";
  486. }
  487. }
  488. private void Close()
  489. {
  490. _telnetClient?.Close();
  491. _telnetStream?.Close();
  492. }
  493. }
  494. private void ShowMsg(int type, string msg)
  495. {
  496. msg = msg.Replace("\r", "").Replace("\n", "");
  497. string msgTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  498. string showMsg = $"{msgTime}: {msg}\n";
  499. if (type == 0)
  500. {
  501. OperatResult.AppendText(showMsg, Color.Red);
  502. }
  503. else if (type == 1)
  504. {
  505. OperatResult.AppendText(showMsg, Color.Green);
  506. }
  507. }
  508. private void Radio1_Click(object sender, EventArgs e)
  509. {
  510. if (Radio1.Checked)
  511. {
  512. Radio2.Checked = false;
  513. }
  514. }
  515. private void Radio2_Click(object sender, EventArgs e)
  516. {
  517. if (Radio2.Checked)
  518. {
  519. Radio1.Checked = false;
  520. }
  521. }
  522. private void Locat1_Click(object sender, EventArgs e)
  523. {
  524. if (Locat1.Checked)
  525. {
  526. Locat2.Checked = false;
  527. Locat3.Checked = false;
  528. }
  529. }
  530. private void Locat2_Click(object sender, EventArgs e)
  531. {
  532. if (Locat2.Checked)
  533. {
  534. Locat1.Checked = false;
  535. Locat3.Checked = false;
  536. }
  537. }
  538. private void Locat3_Click(object sender, EventArgs e)
  539. {
  540. if (Locat3.Checked)
  541. {
  542. Locat1.Checked = false;
  543. Locat2.Checked = false;
  544. }
  545. }
  546. private void Account_KeyDown(object sender, KeyEventArgs e)
  547. {
  548. if (e.KeyCode != Keys.Enter) return;
  549. Password.Focus();
  550. Password.SelectAll();
  551. }
  552. private void Password_KeyDown(object sender, KeyEventArgs e)
  553. {
  554. if (e.KeyCode != Keys.Enter) return;
  555. TestTime.Focus();
  556. TestTime.SelectAll();
  557. }
  558. private void ExePath_Click(object sender, EventArgs e)
  559. {
  560. using (OpenFileDialog openFileDialog = new OpenFileDialog())
  561. {
  562. openFileDialog.Title = "选择iperf3启动文件";
  563. openFileDialog.Filter = "可执行文件 (*.exe)|*.exe|所有文件 (*.*)|*.*";
  564. openFileDialog.FilterIndex = 1;
  565. openFileDialog.RestoreDirectory = true;
  566. // 设置初始目录(可选)
  567. if (!string.IsNullOrEmpty(ExePath.Text) && System.IO.File.Exists(ExePath.Text))
  568. {
  569. openFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(ExePath.Text);
  570. }
  571. else
  572. {
  573. openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
  574. }
  575. if (openFileDialog.ShowDialog() == DialogResult.OK)
  576. {
  577. ExePath.Text = openFileDialog.FileName;
  578. ShowMsg(1, $"已成功选择iperf3启动文件");
  579. }
  580. }
  581. }
  582. private void Clear_Click(object sender, EventArgs e)
  583. {
  584. OperatResult.Clear();
  585. }
  586. }
  587. }