Commit 8c704171 authored by 潘栩锋's avatar 潘栩锋 🚴

1. 修复 当服务地址输入域名 会出错。修改后 域名不能转为 IPv4 才会出错。

parent 73d23337
......@@ -20,9 +20,9 @@
<RowDefinition Height="auto" />
<RowDefinition Height="496*" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Background="{StaticResource Brush_theme_bar}" >
<StackPanel Orientation="Horizontal" Background="{StaticResource Brushes.TitleBar.Background}" >
<Button Style="{StaticResource Styles.TitleBar.BackButton2}" Command="BrowseBack"/>
<TextBlock Style="{StaticResource TextBlockStyle_Title}" Text="服务器地址"/>
<TextBlock Style="{StaticResource Styles.TitleBar.Text}" Text="服务器地址"/>
</StackPanel>
<DataGrid AlternationCount ="2" AlternatingRowBackground="LightGray" AutoGenerateColumns="False" CanUserAddRows="False" Margin="{StaticResource ControlMargin}"
Grid.Row="1" ItemsSource="{Binding ConnAddrs}" >
......@@ -52,7 +52,7 @@
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
<Button Style="{StaticResource ButtonStyle_apply}" VerticalAlignment="Bottom" Margin="0,0,20,-45"
<Button Style="{StaticResource Styles.Button.Apply}" VerticalAlignment="Bottom" Margin="0,0,20,-45"
Command="{Binding ApplyCmd}"/>
</Grid>
</Page>
......@@ -70,27 +70,36 @@ namespace FLY.Thick.Base.UI
if (!WdPassword.Authorize("Address"))
return;
Regex regex = new Regex(@"(\d+)\.(\d+)\.(\d+)\.(\d+)\:(\d+)");
Regex regex_hostname = new Regex(@"(\S+)\:(\d+)");
Regex regex_ip = new Regex(@"(\d+)\.(\d+)\.(\d+)\.(\d+)\:(\d+)");
//检测地址格式
foreach(var ca in ConnAddrs)
foreach (var ca in ConnAddrs)
{
Match m = regex.Match(ca.Address);
if (!m.Success)
//把地址的 : 替换为 :
ca.Address = ca.Address.Replace(":", ":");
Match m_hostname = regex_hostname.Match(ca.Address);
Match m_ip = regex_ip.Match(ca.Address);
if (!m_hostname.Success)
{
//格式错误
FLY.ControlLibrary.Window_WarningTip.Show(
"格式错误",
$"{ca.ConnName} 地址格式错误! 正确为 IP地址:端口号, 请检查");
$"{ca.ConnName} 地址格式错误! 正确为 IP地址:端口号 或 域名:端口号 , 请检查");
return;
}
if (m_ip.Success)
{
//这个IP
for (int i = 0; i < 4; i++)
{
if (!int.TryParse(m.Groups[1 + i].Value, out int num))
if (!int.TryParse(m_ip.Groups[1 + i].Value, out int num))
{
//格式错误
FLY.ControlLibrary.Window_WarningTip.Show(
"格式错误",
$"{ca.ConnName} 地址格式错误! 第{i+1} 位IP段 出错");
$"{ca.ConnName} 地址格式错误! 第{i + 1} 位IP段 出错");
return;
}
if (num < 0 || num > 255)
......@@ -102,8 +111,12 @@ namespace FLY.Thick.Base.UI
return;
}
}
}
{
if (!int.TryParse(m.Groups[5].Value, out int port))
if (!int.TryParse(m_hostname.Groups[2].Value, out int port))
{
//格式错误
FLY.ControlLibrary.Window_WarningTip.Show(
......@@ -120,6 +133,15 @@ namespace FLY.Thick.Base.UI
return;
}
}
var ep = Misc.StringConverter.ToIPEndPoint(ca.Address);
if (ep == null) {
//不能转为ep
FLY.ControlLibrary.Window_WarningTip.Show(
"地址出错",
$"{ca.ConnName} 不能有效转换IPv4");
return;
}
}
int modifyCnt = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment