48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
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);
|
|
}
|
|
}
|
|
} |