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

Commit

Permalink
feat: 增加复制结果,重新运行
Browse files Browse the repository at this point in the history
chore: 变量名错误更改
  • Loading branch information
Forgot-Dream committed Dec 9, 2023
1 parent d5b0e24 commit 6e356a2
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 9 deletions.
12 changes: 6 additions & 6 deletions SduNetCheckTool.Core/Tests/CommonWebsiteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class CommonWebsiteTest : ITest
{
public Tuple<TestResult, string, IRepair> Test()
{
var sduWebsites = new Dictionary<string, string>
var commonWebsites = new Dictionary<string, string>
{
{
"必应", "https://cn.bing.com"
Expand All @@ -35,20 +35,20 @@ public Tuple<TestResult, string, IRepair> Test()
var retList = new List<string>();
var result = TestResult.Success;

foreach (var sduWebsite in sduWebsites)
foreach (var commonWebsite in commonWebsites)
{
var domain = new Uri(sduWebsite.Value).Host;
var domain = new Uri(commonWebsite.Value).Host;
var ping = new Ping();
var reply = ping.Send(domain, 2000);

var response = HttpUtil.GetHttpResponse(sduWebsite.Value);
var response = HttpUtil.GetHttpResponse(commonWebsite.Value);

if (reply.Status == IPStatus.Success && response != null)
{
retList.Add($"[ {response.StatusCode} ] {sduWebsite.Key} ( {sduWebsite.Value} ) {reply.Address} - {reply.RoundtripTime} ms");
retList.Add($"[ {response.StatusCode} ] {commonWebsite.Key} ( {commonWebsite.Value} ) {reply.Address} - {reply.RoundtripTime} ms");
continue;
}
retList.Add($"{sduWebsite.Key} ( {sduWebsite.Value} ) - 无法访问");
retList.Add($"{commonWebsite.Key} ( {commonWebsite.Value} ) - 无法访问");
result = TestResult.Failed;
}

Expand Down
15 changes: 13 additions & 2 deletions SduNetCheckTool.GUI/ViewModels/TestViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Toolkit.Uwp.Notifications;
using SduNetCheckTool.Core.Repairs;
using SduNetCheckTool.Core.Tests;
using SduNetCheckTool.GUI.Common;
using SduNetCheckTool.GUI.Utils;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using SduNetCheckTool.GUI.Utils;
using Microsoft.Toolkit.Uwp.Notifications;

namespace SduNetCheckTool.GUI.ViewModels
{
Expand All @@ -21,6 +21,7 @@ public TestViewModel()
StartCommand = new RelayCommand(StartDetect);
RepairCommand = new RelayCommand(Repair);
ExportReportCommand = new RelayCommand(ExportReport);
SingleReRunCommand = new RelayCommand<DetectionTask>(SingleReRun);
}

private void Init()
Expand Down Expand Up @@ -56,6 +57,8 @@ public ObservableCollection<DetectionTask> Tasks

public ICommand ExportReportCommand { get; }

public ICommand SingleReRunCommand { get; }

private async void Repair()
{
if (_repairs == null || _repairs.Count == 0)
Expand Down Expand Up @@ -120,5 +123,13 @@ private void ExportReport()
}
}
}

private async void SingleReRun(DetectionTask task)
{
await Task.Run(() =>
{
task.RunTask();
});
}
}
}
48 changes: 47 additions & 1 deletion SduNetCheckTool.GUI/Views/TestView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<StackPanel Orientation="Horizontal">
<Expander>
<Expander.Header>
<StackPanel Orientation="Horizontal">
<StackPanel HorizontalAlignment="Stretch" Orientation="Horizontal">
<ui:SymbolIcon
Margin="5,0"
Symbol="{Binding TaskStatusEnum, Converter={StaticResource SymbolConverter}}"
Expand All @@ -50,7 +50,53 @@
</Expander.Header>
<Expander.Content>
<Grid Margin="5,8,5,0">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="20" />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<Button
Margin="5,0"
Command="{x:Static viewModels:Commands.Copy}"
CommandParameter="{Binding Tips}">
<StackPanel Orientation="Horizontal">
<ui:SymbolIcon
Width="20"
Height="20"
Margin="3,0"
Symbol="Copy" />
<TextBlock
VerticalAlignment="Center"
FontSize="15"
Text="复制结果" />
</StackPanel>
</Button>
<Button
Margin="5,0"
Command="{Binding DataContext.SingleReRunCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ui:Page}}}"
CommandParameter="{Binding}">
<StackPanel Orientation="Horizontal">
<ui:SymbolIcon
Width="20"
Height="20"
Margin="3,0"
Symbol="Refresh" />
<TextBlock
VerticalAlignment="Center"
FontSize="15"
Text="重新运行" />
</StackPanel>
</Button>
</StackPanel>
<Border
Grid.Row="1"
Margin="0,8"
Background="DarkGray"
CornerRadius="1"
Opacity="0.5" />
<TextBlock
Grid.Row="2"
Text="{Binding Tips}"
TextTrimming="CharacterEllipsis"
TextWrapping="Wrap" />
Expand Down

0 comments on commit 6e356a2

Please sign in to comment.