Skip to content

Commit 35848a3

Browse files
committed
add if ports was not selected add random ports
1 parent da828c4 commit 35848a3

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

fast cf ip scanner/ViewModels/IpOptionViewModel.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,18 @@ protected override void OnPropertyChanged(PropertyChangedEventArgs e)
5454
async void Save()
5555
{
5656
Saved = true;
57-
58-
//IpOptions.Ports = Ports;
57+
IpOptions.Ports.Clear();
58+
foreach (var portForShow in Ports)
59+
{
60+
if (portForShow.IsChecked)
61+
{
62+
IpOptions.Ports.Add(portForShow.Port);
63+
}
64+
}
65+
if (IpOptions.Ports.Count == 0)
66+
{
67+
IpOptions.Ports.AddRange(GetRandomPort());
68+
}
5969
if (MinimumCountOfValidIp > 0)
6070
{
6171
IpOptions.MinimumCountOfValidIp = MinimumCountOfValidIp;
@@ -84,7 +94,19 @@ async void Save()
8494

8595
await Shell.Current.GoToAsync("../");
8696
}
97+
public string[] GetRandomPort(int count = 3)
98+
{
99+
Random random = new Random();
100+
string[] randomPorts = new string[count];
101+
var allPorts = Constants.HttpPorts.Concat(Constants.HttpsPorts).ToList();
102+
103+
for (int i = 0; i < count; i++)
104+
{
105+
int randomIndex = random.Next(allPorts.Count);
106+
randomPorts[i] = allPorts[randomIndex];
107+
}
108+
return randomPorts;
109+
}
87110

88111

89-
90112
}

fast cf ip scanner/Views/IpOptionsPage.xaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@
1616
</CollectionView.ItemsLayout>
1717
<CollectionView.ItemTemplate>
1818
<DataTemplate x:DataType="viewmodel:PortForShow">
19-
<StackLayout Orientation="Horizontal" Spacing="10">
19+
<StackLayout Orientation="Horizontal" Spacing="10" Padding="5">
2020
<Label Text="{Binding Port}"
21-
VerticalOptions="Center"/>
21+
VerticalOptions="CenterAndExpand"
22+
FontSize="Small"
23+
TextColor="White"/>
2224
<CheckBox IsChecked="{Binding IsChecked}"
23-
VerticalOptions="Center"
24-
/>
25+
VerticalOptions="CenterAndExpand"
26+
Color="DodgerBlue"/>
2527
</StackLayout>
2628
</DataTemplate>
2729
</CollectionView.ItemTemplate>
2830
</CollectionView>
2931

32+
3033
<Label Text="Max Ping of IP:"/>
3134
<Entry x:Name="MaxPingEntry" Text="{Binding MaxPingOfIP}"/>
3235

0 commit comments

Comments
 (0)