Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/NETworkManager/ViewModels/IPScannerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public bool CancelScan
}
}

private ObservableCollection<HostInfo> _results = new ObservableCollection<HostInfo>();
private ObservableCollection<HostInfo> _results = new();
public ObservableCollection<HostInfo> Results
{
get => _results;
Expand Down
22 changes: 15 additions & 7 deletions Source/NETworkManager/ViewModels/PortProfilesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using System.ComponentModel;
using System.Windows.Data;
using NETworkManager.Settings;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace NETworkManager.ViewModels
{
Expand Down Expand Up @@ -36,16 +39,16 @@ public string Search

public ICollectionView PortProfiles { get; }

private PortProfileInfo _selectedPortProfile = new PortProfileInfo();
public PortProfileInfo SelectedPortProfile
private IList _selectedPortProfiles = new ArrayList();
public IList SelectedPortProfiles
{
get => _selectedPortProfile;
get => _selectedPortProfiles;
set
{
if (value == _selectedPortProfile)
if (Equals(value, _selectedPortProfiles))
return;

_selectedPortProfile = value;
_selectedPortProfiles = value;
OnPropertyChanged();
}
}
Expand All @@ -64,7 +67,7 @@ public PortProfilesViewModel(Action<PortProfilesViewModel> okCommand, Action<Por
if (string.IsNullOrEmpty(Search))
return true;

if (!(o is PortProfileInfo info))
if (o is not PortProfileInfo info)
return false;

var search = Search.Trim();
Expand All @@ -75,5 +78,10 @@ public PortProfilesViewModel(Action<PortProfilesViewModel> okCommand, Action<Por

_isLoading = false;
}

public List<PortProfileInfo> GetSelectedPortProfiles()
{
return new List<PortProfileInfo>(SelectedPortProfiles.Cast<PortProfileInfo>());
}
}
}
}
20 changes: 10 additions & 10 deletions Source/NETworkManager/ViewModels/PortScannerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@ public bool CancelScan
}
}

private ObservableCollection<PortInfo> _portScanResults = new ObservableCollection<PortInfo>();
public ObservableCollection<PortInfo> PortScanResult
private ObservableCollection<PortInfo> _results = new();
public ObservableCollection<PortInfo> Results
{
get => _portScanResults;
get => _results;
set
{
if (_portScanResults != null && value == _portScanResults)
if (_results != null && value == _results)
return;

_portScanResults = value;
_results = value;
}
}

Expand Down Expand Up @@ -231,7 +231,7 @@ public PortScannerViewModel(IDialogCoordinator instance, int tabId, string host,
PortsHistoryView = CollectionViewSource.GetDefaultView(SettingsManager.Current.PortScanner_PortsHistory);

// Result view
ResultsView = CollectionViewSource.GetDefaultView(PortScanResult);
ResultsView = CollectionViewSource.GetDefaultView(Results);
ResultsView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(PortInfo.IPAddress)));
ResultsView.SortDescriptions.Add(new SortDescription(nameof(PortInfo.IPAddressInt32), ListSortDirection.Descending));

Expand Down Expand Up @@ -358,7 +358,7 @@ private async Task OpenPortProfileSelection()
{
_dialogCoordinator.HideMetroDialogAsync(this, customDialog);

Ports = instance.SelectedPortProfile.Ports;
Ports = string.Join("; " , instance.GetSelectedPortProfiles().Select(x => x.Ports));
}, instance =>
{
_dialogCoordinator.HideMetroDialogAsync(this, customDialog);
Expand All @@ -382,7 +382,7 @@ private async Task StartScan()
IsScanRunning = true;
PreparingScan = true;

PortScanResult.Clear();
Results.Clear();

// Change the tab title (not nice, but it works)
var window = Application.Current.Windows.OfType<Window>().FirstOrDefault(x => x.IsActive);
Expand Down Expand Up @@ -482,7 +482,7 @@ private async Task Export()

try
{
ExportManager.Export(instance.FilePath, instance.FileType, instance.ExportAll ? PortScanResult : new ObservableCollection<PortInfo>(SelectedResults.Cast<PortInfo>().ToArray()));
ExportManager.Export(instance.FilePath, instance.FileType, instance.ExportAll ? Results : new ObservableCollection<PortInfo>(SelectedResults.Cast<PortInfo>().ToArray()));
}
catch (Exception ex)
{
Expand Down Expand Up @@ -582,7 +582,7 @@ private void PortScanned(object sender, PortScannedArgs e)
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate ()
{
//lock (PortScanResult)
PortScanResult.Add(portInfo);
Results.Add(portInfo);
}));
}

Expand Down
25 changes: 13 additions & 12 deletions Source/NETworkManager/Views/PortProfilesDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:network="clr-namespace:NETworkManager.Models.Network;assembly=NETworkManager.Models"
xmlns:viewModels="clr-namespace:NETworkManager.ViewModels"
xmlns:controls="clr-namespace:NETworkManager.Controls;assembly=NETworkManager.Controls"
xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization"
mc:Ignorable="d" Loaded="UserControl_Loaded" d:DataContext="{d:DesignInstance viewModels:PortProfilesViewModel}">
<Grid Margin="0,20">
Expand All @@ -17,33 +18,33 @@
</Grid.RowDefinitions>
<TextBox x:Name="TextBoxSearch" Grid.Column="0" VerticalAlignment="Center" Text="{Binding Search, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource SearchTextBox}" />
<Grid Grid.Row="2">
<DataGrid x:Name="DataGridPortProfiles" Style="{StaticResource DefaultDataGrid}" ItemsSource="{Binding PortProfiles}" SelectionMode="Single" SelectedItem="{Binding SelectedPortProfile}">
<DataGrid.Columns>
<controls:MultiSelectDataGrid x:Name="DataGridPortProfiles" Style="{StaticResource DefaultDataGrid}" ItemsSource="{Binding PortProfiles}" SelectedItemsList="{Binding SelectedPortProfiles, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<controls:MultiSelectDataGrid.Columns>
<DataGridTextColumn Header="{x:Static localization:Strings.Name}" Binding="{Binding (network:PortProfileInfo.Name)}" Width="1*" />
<DataGridTextColumn Header="{x:Static localization:Strings.Ports}" Binding="{Binding (network:PortProfileInfo.Ports)}" Width="2*" />
</DataGrid.Columns>
<DataGrid.InputBindings>
</controls:MultiSelectDataGrid.Columns>
<controls:MultiSelectDataGrid.InputBindings>
<KeyBinding Command="{Binding OKCommand}" Key="Return" />
</DataGrid.InputBindings>
<DataGrid.RowStyle>
</controls:MultiSelectDataGrid.InputBindings>
<controls:MultiSelectDataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource MahApps.Styles.DataGridRow}">
<EventSetter Event="MouseDoubleClick" Handler="DataGridRow_MouseDoubleClick" />
</Style>
</DataGrid.RowStyle>
</DataGrid>
</controls:MultiSelectDataGrid.RowStyle>
</controls:MultiSelectDataGrid>
</Grid>
<StackPanel Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Right">
<StackPanel Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Content="{x:Static localization:Strings.OK}" Command="{Binding OKCommand}" IsDefault="True" Margin="0,0,10,0">
<Button.Style>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource HighlightedButton}">
<Setter Property="IsEnabled" Value="False" />
<Setter Property="IsEnabled" Value="True" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding ElementName=DataGridPortProfiles, Path=SelectedItems.Count}" Value="1" />
<Condition Binding="{Binding ElementName=DataGridPortProfiles, Path=SelectedItems.Count}" Value="0" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.Setters>
<Setter Property="IsEnabled" Value="True"/>
<Setter Property="IsEnabled" Value="False"/>
</MultiDataTrigger.Setters>
</MultiDataTrigger>
</Style.Triggers>
Expand Down
1 change: 1 addition & 0 deletions docs/Changelog/next-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ New Feature
- New Port state "Timed out" if the timelimit is reached. [#1969](https://github.com/BornToBeRoot/NETworkManager/pull/1969){:target="\_blank"}
- **Port Scanner**
- Add new port profiles / improve existing ones [#1909](https://github.com/BornToBeRoot/NETworkManager/pull/1909){:target="\_blank"}
- Select multiple port profiles with `Ctrl` or holding left mouse button [#1979](https://github.com/BornToBeRoot/NETworkManager/pull/1979){:target="\_blank"}
- Max host threads changed to to 256 [#1927](https://github.com/BornToBeRoot/NETworkManager/pull/1927){:target="\_blank"}
- Max port threads changed to to 1024 [#1927](https://github.com/BornToBeRoot/NETworkManager/pull/1927){:target="\_blank"}
- **Ping**
Expand Down