Make_WirelessThroughput.cs 24 KB

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