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