Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
feat: 增加更多检测网站,增加一键复制功能 (#5)
Browse files Browse the repository at this point in the history
- 增加检测网站
- 增加导出文件自动打开以及一键复制
  • Loading branch information
ICONQUESTION authored Dec 7, 2023
1 parent a763b63 commit edc9433
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 11 deletions.
23 changes: 19 additions & 4 deletions SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,24 @@ public Tuple<TestResult, string, IRepair> Test()
{
var sduWebsites = new Dictionary<string, string>
{
{ "哔哩哔哩" , "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<string>();
Expand All @@ -30,7 +45,7 @@ public Tuple<TestResult, string, IRepair> 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} ) - 无法访问");
Expand Down
2 changes: 1 addition & 1 deletion SduNetCheckTool.Core/Tests/SduWebsiteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Tuple<TestResult, string, IRepair> 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} ) - 无法访问");
Expand Down
4 changes: 3 additions & 1 deletion SduNetCheckTool.Core/Tests/SystemGatewayTest.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -36,9 +37,10 @@ public Tuple<TestResult, string, IRepair> 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;
Expand Down
5 changes: 4 additions & 1 deletion SduNetCheckTool.GUI/SduNetCheckTool.GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection">
<Version>7.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications">
<Version>7.1.3</Version>
</PackageReference>
<PackageReference Include="ModernWpfUI">
<Version>0.9.6</Version>
</PackageReference>
Expand Down Expand Up @@ -196,4 +199,4 @@
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
28 changes: 26 additions & 2 deletions SduNetCheckTool.GUI/Utils/FileUtil.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SduNetCheckTool.GUI.Common;
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
Expand All @@ -14,17 +15,40 @@ public static string ExportReport(ObservableCollection<DetectionTask> 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";
}
}
}
30 changes: 28 additions & 2 deletions SduNetCheckTool.GUI/ViewModels/TestViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Windows;
using System.Windows.Input;
using SduNetCheckTool.GUI.Utils;
using Microsoft.Toolkit.Uwp.Notifications;

namespace SduNetCheckTool.GUI.ViewModels
{
Expand Down Expand Up @@ -52,7 +53,7 @@ public ObservableCollection<DetectionTask> Tasks
public ICommand StartCommand { get; }

public ICommand RepairCommand { get; }

public ICommand ExportReportCommand { get; }

private async void Repair()
Expand Down Expand Up @@ -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();
}
}
}
}
}

0 comments on commit edc9433

Please sign in to comment.