From edc9433a0cf49f370acd577e72e75a2c841bbbb1 Mon Sep 17 00:00:00 2001 From: Application Date: Thu, 7 Dec 2023 20:31:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E7=BD=91=E7=AB=99=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=80=E9=94=AE=E5=A4=8D=E5=88=B6=E5=8A=9F=E8=83=BD=20(#5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 增加检测网站 - 增加导出文件自动打开以及一键复制 --- .../Tests/CommonWebsiteTest.cs | 23 +++++++++++--- SduNetCheckTool.Core/Tests/SduWebsiteTest.cs | 2 +- .../Tests/SystemGatewayTest.cs | 4 ++- .../SduNetCheckTool.GUI.csproj | 5 +++- SduNetCheckTool.GUI/Utils/FileUtil.cs | 28 +++++++++++++++-- .../ViewModels/TestViewModel.cs | 30 +++++++++++++++++-- 6 files changed, 81 insertions(+), 11 deletions(-) diff --git a/SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs b/SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs index 72ee77a..bffa47e 100644 --- a/SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs +++ b/SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs @@ -12,9 +12,24 @@ public Tuple Test() { var sduWebsites = new Dictionary { - { "哔哩哔哩" , "https://www.bilibili.com" }, - { "知乎" , "https://www.zhihu.com" }, - { "知网" , "https://www.cnki.net" } + { + "必应", "https://cn.bing.com" + }, + { + "知网", "https://www.cnki.net" + }, + { + "知乎", "https://www.zhihu.com" + }, + { + "百度", "https://www.baidu.com" + }, + { + "哔哩哔哩", "https://www.bilibili.com" + }, + { + "中国大学MOOC", "https://www.icourse163.org" + }, }; var retList = new List(); @@ -30,7 +45,7 @@ public Tuple Test() if (reply.Status == IPStatus.Success && response != null) { - retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - {response.StatusCode} - {reply.RoundtripTime} ms"); + retList.Add($"[ {response.StatusCode} ] {sduWebsite.Key} ( {sduWebsite.Value} ) {reply.Address} - {reply.RoundtripTime} ms"); continue; } retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - 无法访问"); diff --git a/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs b/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs index ae6c88c..be3befc 100644 --- a/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs +++ b/SduNetCheckTool.Core/Tests/SduWebsiteTest.cs @@ -29,7 +29,7 @@ public Tuple Test() if (reply.Status == IPStatus.Success && response != null) { - retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - {response.StatusCode} - {reply.RoundtripTime} ms"); + retList.Add($"[ {response.StatusCode} ] {sduWebsite.Key} ( {sduWebsite.Value} ) {reply.Address} - {reply.RoundtripTime} ms"); continue; } retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - 无法访问"); diff --git a/SduNetCheckTool.Core/Tests/SystemGatewayTest.cs b/SduNetCheckTool.Core/Tests/SystemGatewayTest.cs index 51af0ef..a5944f2 100644 --- a/SduNetCheckTool.Core/Tests/SystemGatewayTest.cs +++ b/SduNetCheckTool.Core/Tests/SystemGatewayTest.cs @@ -1,6 +1,7 @@ using SduNetCheckTool.Core.Repairs; using System; using System.Collections.Generic; +using System.Linq; using System.Net; using System.Net.NetworkInformation; using System.Threading; @@ -36,9 +37,10 @@ public Tuple Test() { foreach (IPAddress address in addresses) { - data.Add($"DHCP服务器: {address}\n"); + data.Add($"DHCP服务器: {address}"); } } + data[data.Count - 1] = data.Last() + "\n"; } } result = TestResult.Success; diff --git a/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj b/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj index 8219bce..5ad2866 100644 --- a/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj +++ b/SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj @@ -168,6 +168,9 @@ 7.0.0 + + 7.1.3 + 0.9.6 @@ -196,4 +199,4 @@ - + \ No newline at end of file diff --git a/SduNetCheckTool.GUI/Utils/FileUtil.cs b/SduNetCheckTool.GUI/Utils/FileUtil.cs index cdd3097..7c01b8e 100644 --- a/SduNetCheckTool.GUI/Utils/FileUtil.cs +++ b/SduNetCheckTool.GUI/Utils/FileUtil.cs @@ -1,4 +1,5 @@ using SduNetCheckTool.GUI.Common; +using System; using System.Collections.ObjectModel; using System.IO; using System.Linq; @@ -14,17 +15,40 @@ public static string ExportReport(ObservableCollection tasks) var exportFilePath = ExportPath + "\\" + System.DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + ".txt"; if (tasks.Any(i => i.TaskStatusEnum == TaskStatusEnum.Waiting)) - return "请先运行测试"; + return "NoRecords"; if (!Directory.Exists(ExportPath)) Directory.CreateDirectory(ExportPath); foreach (var detectionTask in tasks) { - File.AppendAllText(exportFilePath, detectionTask.Tips + '\n', Encoding.UTF8); + File.AppendAllText(exportFilePath, detectionTask.Tips + '\n' + '\n', Encoding.UTF8); } return exportFilePath; } + + public static string ReadFile(string filePath) + { + if (!File.Exists(filePath)) return "FileNotExists"; + + try + { + StreamReader sr = new StreamReader(filePath); + string data = "", line = ""; + + while ((line = sr.ReadLine()) != null) + { + data += line + "\n"; + } + + return data; + } + catch (Exception e) + { + // + } + return "-1"; + } } } diff --git a/SduNetCheckTool.GUI/ViewModels/TestViewModel.cs b/SduNetCheckTool.GUI/ViewModels/TestViewModel.cs index b7f4253..9fd3e5a 100644 --- a/SduNetCheckTool.GUI/ViewModels/TestViewModel.cs +++ b/SduNetCheckTool.GUI/ViewModels/TestViewModel.cs @@ -9,6 +9,7 @@ using System.Windows; using System.Windows.Input; using SduNetCheckTool.GUI.Utils; +using Microsoft.Toolkit.Uwp.Notifications; namespace SduNetCheckTool.GUI.ViewModels { @@ -52,7 +53,7 @@ public ObservableCollection Tasks public ICommand StartCommand { get; } public ICommand RepairCommand { get; } - + public ICommand ExportReportCommand { get; } private async void Repair() @@ -92,7 +93,32 @@ await Task.Run(() => private void ExportReport() { - MessageBox.Show("日志文件导出:" + FileUtil.ExportReport(Tasks)); + var output = FileUtil.ExportReport(Tasks); + if (output == "NoRecords") + { + MessageBox.Show("请先点击'开始检测'运行测试! >_<", "提示"); + } + else + { + MessageBoxResult result = MessageBox.Show("日志文件已生成! (⑅•ᴗ•⑅) \n路径: " + output + "\n点击'确定'打开日志并自动复制到剪贴板!", "提示"); + if (result == MessageBoxResult.OK) + { + System.Diagnostics.Process.Start(output); + string data = FileUtil.ReadFile(output); + if (data == "FileNotExists" || data == "-1") + { + MessageBox.Show("出现了一点小错误..."); + return; + } + Clipboard.SetText(data); + new ToastContentBuilder() + .AddArgument("action", "viewConversation") + .AddArgument("conversationId", 9813) + .AddText("已经成功复制内容到剪贴板啦! ๐•ᴗ•๐") + .AddText("可以直接分享给同学哦~") + .Show(); + } + } } } }