feat: 完善 PortProxy 图形化管理工具
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user