feat: 完善 PortProxy 图形化管理工具
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<Application x:Class="PortProxyTool.Wpf.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
StartupUri="MainWindow.xaml">
|
||||
StartupUri="/Views/MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
|
@@ -0,0 +1,17 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace PortProxyTool.Wpf.Converters;
|
||||
|
||||
public class NullableUnknownToStringConverter : IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
return value == null ? "未知" : value.ToString();
|
||||
}
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@@ -1,9 +0,0 @@
|
||||
<Window x:Class="PortProxyTool.Wpf.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d"
|
||||
Title="PortProxyTool" Height="450" Width="800">
|
||||
<Grid />
|
||||
</Window>
|
@@ -1,14 +0,0 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace PortProxyTool.Wpf;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
@@ -13,4 +13,13 @@
|
||||
<ProjectReference Include="..\PortProxyTool\PortProxyTool.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Page Update="Views\MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<XamlRuntime>Wpf</XamlRuntime>
|
||||
<SubType>Designer</SubType>
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
14
PortProxyTool.Wpf/Rules/PortValidationRule.cs
Normal file
14
PortProxyTool.Wpf/Rules/PortValidationRule.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace PortProxyTool.Wpf.Rules;
|
||||
|
||||
public class PortValidationRule : ValidationRule
|
||||
{
|
||||
public override ValidationResult Validate(object? value, CultureInfo cultureInfo)
|
||||
{
|
||||
if (value is not string strValue) return new ValidationResult(false, "请输入有效的数字");
|
||||
if (string.IsNullOrEmpty(strValue) || ushort.TryParse(strValue, out _)) return ValidationResult.ValidResult;
|
||||
return new ValidationResult(false, "请输入有效的数字");
|
||||
}
|
||||
}
|
200
PortProxyTool.Wpf/Views/MainWindow.xaml
Normal file
200
PortProxyTool.Wpf/Views/MainWindow.xaml
Normal file
@@ -0,0 +1,200 @@
|
||||
<Window x:Class="PortProxyTool.Wpf.Views.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:converters="clr-namespace:PortProxyTool.Wpf.Converters"
|
||||
mc:Ignorable="d"
|
||||
Title="PortProxyTool GUI" Height="450" Width="800"
|
||||
MinHeight="450" MinWidth="800">
|
||||
<Window.Resources>
|
||||
<converters:NullableUnknownToStringConverter x:Key="NullableUnknownToStringConverter" />
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Grid.Row="0">
|
||||
<Button MinHeight="24"
|
||||
Click="RefreshButton_OnClick">
|
||||
刷新
|
||||
</Button>
|
||||
</StackPanel>
|
||||
<Grid Grid.Row="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid Grid.Column="0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="IPv4 -> IPv4"
|
||||
HorizontalAlignment="Center" />
|
||||
<ListBox Grid.Row="1"
|
||||
Name="V4ToV4ListBox"
|
||||
SelectionChanged="V4ToV4ListBox_OnSelectionChanged">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding ListenAddress}" />
|
||||
<TextBlock Text=":" />
|
||||
<TextBlock Text="{Binding ListenPort}" />
|
||||
<TextBlock Text=" -> " />
|
||||
<TextBlock
|
||||
Text="{Binding TargetAddress, Converter={StaticResource NullableUnknownToStringConverter}}" />
|
||||
<TextBlock Text=":" />
|
||||
<TextBlock
|
||||
Text="{Binding TargetPort, Converter={StaticResource NullableUnknownToStringConverter}}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<Button Grid.Row="2"
|
||||
Name="V4ToV4RemoveButton"
|
||||
Click="RemoveButton_OnClick">
|
||||
删除
|
||||
</Button>
|
||||
<Button Grid.Row="3"
|
||||
Name="V4ToV4SetButton"
|
||||
Click="SetButton_OnClick">
|
||||
编辑
|
||||
</Button>
|
||||
</Grid>
|
||||
<Grid Grid.Column="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="IPv4 -> IPv6"
|
||||
HorizontalAlignment="Center" />
|
||||
<ListBox Grid.Row="1"
|
||||
Name="V4ToV6ListBox"
|
||||
SelectionChanged="V4ToV6ListBox_OnSelectionChanged">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding ListenAddress}" />
|
||||
<TextBlock Text=":" />
|
||||
<TextBlock Text="{Binding ListenPort}" />
|
||||
<TextBlock Text=" -> " />
|
||||
<TextBlock
|
||||
Text="{Binding TargetAddress, Converter={StaticResource NullableUnknownToStringConverter}}" />
|
||||
<TextBlock Text=":" />
|
||||
<TextBlock
|
||||
Text="{Binding TargetPort, Converter={StaticResource NullableUnknownToStringConverter}}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<Button Grid.Row="2"
|
||||
Name="V4ToV6RemoveButton"
|
||||
Click="RemoveButton_OnClick">
|
||||
删除
|
||||
</Button>
|
||||
<Button Grid.Row="3"
|
||||
Name="V4ToV6SetButton"
|
||||
Click="SetButton_OnClick">
|
||||
编辑
|
||||
</Button>
|
||||
</Grid>
|
||||
<Grid Grid.Column="2">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="IPv6 -> IPv6"
|
||||
HorizontalAlignment="Center" />
|
||||
<ListBox Grid.Row="1"
|
||||
Name="V6ToV6ListBox"
|
||||
SelectionChanged="V6ToV6ListBox_OnSelectionChanged">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding ListenAddress}" />
|
||||
<TextBlock Text=":" />
|
||||
<TextBlock Text="{Binding ListenPort}" />
|
||||
<TextBlock Text=" -> " />
|
||||
<TextBlock
|
||||
Text="{Binding TargetAddress, Converter={StaticResource NullableUnknownToStringConverter}}" />
|
||||
<TextBlock Text=":" />
|
||||
<TextBlock
|
||||
Text="{Binding TargetPort, Converter={StaticResource NullableUnknownToStringConverter}}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<Button Grid.Row="2"
|
||||
Name="V6ToV6RemoveButton"
|
||||
Click="RemoveButton_OnClick">
|
||||
删除
|
||||
</Button>
|
||||
<Button Grid.Row="3"
|
||||
Name="V6ToV6SetButton"
|
||||
Click="SetButton_OnClick">
|
||||
编辑
|
||||
</Button>
|
||||
</Grid>
|
||||
<Grid Grid.Column="3">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="IPv6 -> IPv4"
|
||||
HorizontalAlignment="Center" />
|
||||
<ListBox Grid.Row="1"
|
||||
Name="V6ToV4ListBox"
|
||||
SelectionChanged="V6ToV4ListBox_OnSelectionChanged">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding ListenAddress}" />
|
||||
<TextBlock Text=":" />
|
||||
<TextBlock Text="{Binding ListenPort}" />
|
||||
<TextBlock Text=" -> " />
|
||||
<TextBlock
|
||||
Text="{Binding TargetAddress, Converter={StaticResource NullableUnknownToStringConverter}}" />
|
||||
<TextBlock Text=":" />
|
||||
<TextBlock
|
||||
Text="{Binding TargetPort, Converter={StaticResource NullableUnknownToStringConverter}}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<Button Grid.Row="2"
|
||||
Name="V6ToV4RemoveButton"
|
||||
Click="RemoveButton_OnClick">
|
||||
删除
|
||||
</Button>
|
||||
<Button Grid.Row="3"
|
||||
Name="V6ToV4SetButton"
|
||||
Click="SetButton_OnClick">
|
||||
编辑
|
||||
</Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<StackPanel Grid.Row="2">
|
||||
<Button MinHeight="24"
|
||||
Click="AddButton_OnClick">
|
||||
添加
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
201
PortProxyTool.Wpf/Views/MainWindow.xaml.cs
Normal file
201
PortProxyTool.Wpf/Views/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,201 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using PortProxyTool.Wpf.Views.Windows;
|
||||
|
||||
namespace PortProxyTool.Wpf.Views;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private List<PortProxyItem> _portProxies = [];
|
||||
public PortProxyItem? V4ToV4SelectedItem;
|
||||
public PortProxyItem? V4ToV6SelectedItem;
|
||||
public PortProxyItem? V6ToV4SelectedItem;
|
||||
public PortProxyItem? V6ToV6SelectedItem;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void RefreshButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Button) return;
|
||||
RefreshListBox();
|
||||
}
|
||||
|
||||
private void RefreshListBox()
|
||||
{
|
||||
_portProxies = PortProxy.GetPortProxies().ToList();
|
||||
V4ToV4ListBox.ItemsSource = _portProxies.Where(x => x.Type == PortProxyType.V4ToV4);
|
||||
V4ToV6ListBox.ItemsSource = _portProxies.Where(x => x.Type == PortProxyType.V4ToV6);
|
||||
V6ToV6ListBox.ItemsSource = _portProxies.Where(x => x.Type == PortProxyType.V6ToV6);
|
||||
V6ToV4ListBox.ItemsSource = _portProxies.Where(x => x.Type == PortProxyType.V6ToV4);
|
||||
}
|
||||
|
||||
private void V4ToV4ListBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (sender is ListBox listBox)
|
||||
V4ToV4SelectedItem = listBox.SelectedItem as PortProxyItem;
|
||||
}
|
||||
|
||||
private void V4ToV6ListBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (sender is ListBox listBox)
|
||||
V4ToV6SelectedItem = listBox.SelectedItem as PortProxyItem;
|
||||
}
|
||||
|
||||
private void V6ToV6ListBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (sender is ListBox listBox)
|
||||
V6ToV6SelectedItem = listBox.SelectedItem as PortProxyItem;
|
||||
}
|
||||
|
||||
private void V6ToV4ListBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (sender is ListBox listBox)
|
||||
V6ToV4SelectedItem = listBox.SelectedItem as PortProxyItem;
|
||||
}
|
||||
|
||||
private void AddButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Button) return;
|
||||
AddWindow addWindow = new();
|
||||
addWindow.ShowDialog();
|
||||
if (addWindow.DialogResult == true)
|
||||
RefreshListBox();
|
||||
}
|
||||
|
||||
private void RemoveButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Button button) return;
|
||||
switch (button.Name)
|
||||
{
|
||||
case "V4ToV4RemoveButton":
|
||||
if (V4ToV4SelectedItem is null)
|
||||
{
|
||||
MessageBox.Show("请选择要删除的条目", "删除失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = PortProxy.Remove(V4ToV4SelectedItem);
|
||||
if (string.IsNullOrEmpty(result))
|
||||
MessageBox.Show("删除成功", "删除成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
else
|
||||
MessageBox.Show(result, "删除失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
break;
|
||||
case "V4ToV6RemoveButton":
|
||||
if (V4ToV6SelectedItem is null)
|
||||
{
|
||||
MessageBox.Show("请选择要删除的条目", "删除失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = PortProxy.Remove(V4ToV6SelectedItem);
|
||||
if (string.IsNullOrEmpty(result))
|
||||
MessageBox.Show("删除成功", "删除成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
else
|
||||
MessageBox.Show(result, "删除失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
break;
|
||||
case "V6ToV6RemoveButton":
|
||||
if (V6ToV6SelectedItem is null)
|
||||
{
|
||||
MessageBox.Show("请选择要删除的条目", "删除失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = PortProxy.Remove(V6ToV6SelectedItem);
|
||||
if (string.IsNullOrEmpty(result))
|
||||
MessageBox.Show("删除成功", "删除成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
else
|
||||
MessageBox.Show(result, "删除失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
break;
|
||||
case "V6ToV4RemoveButton":
|
||||
if (V6ToV4SelectedItem is null)
|
||||
{
|
||||
MessageBox.Show("请选择要删除的条目", "删除失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = PortProxy.Remove(V6ToV4SelectedItem);
|
||||
if (string.IsNullOrEmpty(result))
|
||||
MessageBox.Show("删除成功", "删除成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
else
|
||||
MessageBox.Show(result, "删除失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
RefreshListBox();
|
||||
}
|
||||
|
||||
private void SetButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Button button) return;
|
||||
SetWindow setWindow;
|
||||
switch (button.Name)
|
||||
{
|
||||
case "V4ToV4SetButton":
|
||||
if (V4ToV4SelectedItem is null)
|
||||
{
|
||||
MessageBox.Show("请选择要编辑的条目", "编辑失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
setWindow = new SetWindow(V4ToV4SelectedItem);
|
||||
setWindow.ShowDialog();
|
||||
RefreshListBox();
|
||||
}
|
||||
|
||||
break;
|
||||
case "V4ToV6SetButton":
|
||||
if (V4ToV6SelectedItem is null)
|
||||
{
|
||||
MessageBox.Show("请选择要编辑的条目", "编辑失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
setWindow = new SetWindow(V4ToV6SelectedItem);
|
||||
setWindow.ShowDialog();
|
||||
RefreshListBox();
|
||||
}
|
||||
|
||||
break;
|
||||
case "V6ToV6SetButton":
|
||||
if (V6ToV6SelectedItem is null)
|
||||
{
|
||||
MessageBox.Show("请选择要编辑的条目", "编辑失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
setWindow = new SetWindow(V6ToV6SelectedItem);
|
||||
setWindow.ShowDialog();
|
||||
RefreshListBox();
|
||||
}
|
||||
|
||||
break;
|
||||
case "V6ToV4SetButton":
|
||||
if (V6ToV4SelectedItem is null)
|
||||
{
|
||||
MessageBox.Show("请选择要编辑的条目", "编辑失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
setWindow = new SetWindow(V6ToV4SelectedItem);
|
||||
setWindow.ShowDialog();
|
||||
RefreshListBox();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
83
PortProxyTool.Wpf/Views/Windows/AddWindow.xaml
Normal file
83
PortProxyTool.Wpf/Views/Windows/AddWindow.xaml
Normal file
@@ -0,0 +1,83 @@
|
||||
<Window x:Class="PortProxyTool.Wpf.Views.Windows.AddWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:rules="clr-namespace:PortProxyTool.Wpf.Rules"
|
||||
mc:Ignorable="d"
|
||||
Title="添加 PortProxy" Height="450" Width="800"
|
||||
MinWidth="400" MinHeight="280">
|
||||
<Grid Margin="16">
|
||||
<StackPanel>
|
||||
<Grid Margin="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0">类型</Label>
|
||||
<ComboBox Grid.Column="1"
|
||||
x:Name="TypeComboBox"
|
||||
SelectedIndex="{Binding TypeIndex}">
|
||||
<ComboBoxItem>IPv4 -> IPv4</ComboBoxItem>
|
||||
<ComboBoxItem>IPv4 -> IPv6</ComboBoxItem>
|
||||
<ComboBoxItem>IPv6 -> IPv6</ComboBoxItem>
|
||||
<ComboBoxItem>IPv6 -> IPv4</ComboBoxItem>
|
||||
</ComboBox>
|
||||
</Grid>
|
||||
<Grid Margin="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0">监听地址</Label>
|
||||
<TextBox Grid.Column="1"
|
||||
Text="{Binding ListenAddress}" />
|
||||
</Grid>
|
||||
<Grid Margin="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0">监听端口</Label>
|
||||
<TextBox Grid.Column="1">
|
||||
<TextBox.Text>
|
||||
<Binding Path="ListenPort" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<rules:PortValidationRule />
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
</Grid>
|
||||
<Grid Margin="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0">目标连接地址</Label>
|
||||
<TextBox Grid.Column="1"
|
||||
Text="{Binding TargetAddress}" />
|
||||
</Grid>
|
||||
<Grid Margin="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0">目标连接端口</Label>
|
||||
<TextBox Grid.Column="1">
|
||||
<TextBox.Text>
|
||||
<Binding Path="TargetPort" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<rules:PortValidationRule />
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
</Grid>
|
||||
<Button Margin="4"
|
||||
Content="添加"
|
||||
MinHeight="24"
|
||||
Click="AddButton_OnClick" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
48
PortProxyTool.Wpf/Views/Windows/AddWindow.xaml.cs
Normal file
48
PortProxyTool.Wpf/Views/Windows/AddWindow.xaml.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace PortProxyTool.Wpf.Views.Windows;
|
||||
|
||||
public partial class AddWindow : Window
|
||||
{
|
||||
public AddWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
public int TypeIndex { get; set; } = 0;
|
||||
public string ListenAddress { get; set; } = "0.0.0.0";
|
||||
public ushort ListenPort { get; set; } = 12345;
|
||||
public string TargetAddress { get; set; } = "127.0.0.1";
|
||||
public ushort TargetPort { get; set; } = 12345;
|
||||
|
||||
private void AddButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var type = TypeIndex switch
|
||||
{
|
||||
0 => PortProxyType.V4ToV4,
|
||||
1 => PortProxyType.V4ToV6,
|
||||
2 => PortProxyType.V6ToV6,
|
||||
3 => PortProxyType.V6ToV4,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
var item = new PortProxyItem
|
||||
{
|
||||
Type = type,
|
||||
ListenAddress = ListenAddress,
|
||||
ListenPort = ListenPort,
|
||||
TargetAddress = TargetAddress,
|
||||
TargetPort = TargetPort
|
||||
};
|
||||
var result = PortProxy.Add(item);
|
||||
if (string.IsNullOrEmpty(result))
|
||||
{
|
||||
DialogResult = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
DialogResult = false;
|
||||
MessageBox.Show(result, "添加失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
68
PortProxyTool.Wpf/Views/Windows/SetWindow.xaml
Normal file
68
PortProxyTool.Wpf/Views/Windows/SetWindow.xaml
Normal file
@@ -0,0 +1,68 @@
|
||||
<Window x:Class="PortProxyTool.Wpf.Views.Windows.SetWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:rules="clr-namespace:PortProxyTool.Wpf.Rules"
|
||||
mc:Ignorable="d"
|
||||
Title="编辑 PortProxy" Height="450" Width="800"
|
||||
MinWidth="400" MinHeight="280">
|
||||
<Grid Margin="16">
|
||||
<StackPanel>
|
||||
<Grid Margin="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0">监听地址</Label>
|
||||
<TextBox Grid.Column="1"
|
||||
Text="{Binding ListenAddress}" />
|
||||
</Grid>
|
||||
<Grid Margin="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0">监听端口</Label>
|
||||
<TextBox Grid.Column="1">
|
||||
<TextBox.Text>
|
||||
<Binding Path="ListenPort" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<rules:PortValidationRule />
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
</Grid>
|
||||
<Grid Margin="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0">目标连接地址</Label>
|
||||
<TextBox Grid.Column="1"
|
||||
Text="{Binding TargetAddress}" />
|
||||
</Grid>
|
||||
<Grid Margin="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0">目标连接端口</Label>
|
||||
<TextBox Grid.Column="1">
|
||||
<TextBox.Text>
|
||||
<Binding Path="TargetPort" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<rules:PortValidationRule />
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
</Grid>
|
||||
<Button Margin="4"
|
||||
Content="编辑"
|
||||
MinHeight="24"
|
||||
Click="SetButton_OnClick" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
42
PortProxyTool.Wpf/Views/Windows/SetWindow.xaml.cs
Normal file
42
PortProxyTool.Wpf/Views/Windows/SetWindow.xaml.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace PortProxyTool.Wpf.Views.Windows;
|
||||
|
||||
public partial class SetWindow : Window
|
||||
{
|
||||
public SetWindow(PortProxyItem item)
|
||||
{
|
||||
Item = item;
|
||||
ListenAddress = item.ListenAddress;
|
||||
ListenPort = item.ListenPort;
|
||||
TargetAddress = item.TargetAddress ?? "127.0.0.1";
|
||||
TargetPort = item.TargetPort ?? 12345;
|
||||
InitializeComponent();
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
public PortProxyItem Item { get; set; }
|
||||
|
||||
public string ListenAddress { get; set; }
|
||||
public ushort ListenPort { get; set; }
|
||||
public string TargetAddress { get; set; }
|
||||
public ushort TargetPort { get; set; }
|
||||
|
||||
private void SetButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Item.ListenAddress = ListenAddress;
|
||||
Item.ListenPort = ListenPort;
|
||||
Item.TargetAddress = TargetAddress;
|
||||
Item.TargetPort = TargetPort;
|
||||
var result = PortProxy.Set(Item);
|
||||
if (string.IsNullOrEmpty(result))
|
||||
{
|
||||
DialogResult = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
DialogResult = false;
|
||||
MessageBox.Show(result, "编辑失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,4 +3,5 @@
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANumber_002Ecs_002Fl_003AC_0021_003FUsers_003FJack_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fe3157c720a4245958cf8a1b12c4b4a27e90928_003Fd9_003F56dcb09d_003FNumber_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANumber_002EParsing_002Ecs_002Fl_003AC_0021_003FUsers_003FJack_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fde8a243f75215d958afa80cf80a41b4981a44efea7db93bffcdaf7bd6ba378c0_003FNumber_002EParsing_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelpers_002Ecs_002Fl_003AC_0021_003FUsers_003FJack_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fe3157c720a4245958cf8a1b12c4b4a27e90928_003Fbb_003Fec9f78bc_003FThrowHelpers_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelper_002Ecs_002Fl_003AC_0021_003FUsers_003FJack_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fc7102cd0ffb8973777e61b1942c3fffac7e14016a511d055c3adf73ff91748_003FThrowHelper_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelper_002Ecs_002Fl_003AC_0021_003FUsers_003FJack_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fc7102cd0ffb8973777e61b1942c3fffac7e14016a511d055c3adf73ff91748_003FThrowHelper_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AXamlReader_002Ecs_002Fl_003AC_0021_003FUsers_003FJack_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F9f3f6ac2973b52b9b246bc900a441bf6a7cc21b73be1a5faf7f363865e61_003FXamlReader_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
Reference in New Issue
Block a user