diff --git a/Source/NETworkManager/ViewModels/IPScannerViewModel.cs b/Source/NETworkManager/ViewModels/IPScannerViewModel.cs index 6cf498c5f2..7f8e6cfabf 100644 --- a/Source/NETworkManager/ViewModels/IPScannerViewModel.cs +++ b/Source/NETworkManager/ViewModels/IPScannerViewModel.cs @@ -100,7 +100,7 @@ public bool CancelScan } } - private ObservableCollection _results = new ObservableCollection(); + private ObservableCollection _results = new(); public ObservableCollection Results { get => _results; diff --git a/Source/NETworkManager/ViewModels/PortProfilesViewModel.cs b/Source/NETworkManager/ViewModels/PortProfilesViewModel.cs index 4c29e56389..0aa0ea8664 100644 --- a/Source/NETworkManager/ViewModels/PortProfilesViewModel.cs +++ b/Source/NETworkManager/ViewModels/PortProfilesViewModel.cs @@ -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 { @@ -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(); } } @@ -64,7 +67,7 @@ public PortProfilesViewModel(Action okCommand, Action okCommand, Action GetSelectedPortProfiles() + { + return new List(SelectedPortProfiles.Cast()); + } } -} \ No newline at end of file +} diff --git a/Source/NETworkManager/ViewModels/PortScannerViewModel.cs b/Source/NETworkManager/ViewModels/PortScannerViewModel.cs index ac76a49102..e6f6c5c602 100644 --- a/Source/NETworkManager/ViewModels/PortScannerViewModel.cs +++ b/Source/NETworkManager/ViewModels/PortScannerViewModel.cs @@ -99,16 +99,16 @@ public bool CancelScan } } - private ObservableCollection _portScanResults = new ObservableCollection(); - public ObservableCollection PortScanResult + private ObservableCollection _results = new(); + public ObservableCollection Results { - get => _portScanResults; + get => _results; set { - if (_portScanResults != null && value == _portScanResults) + if (_results != null && value == _results) return; - _portScanResults = value; + _results = value; } } @@ -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)); @@ -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); @@ -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().FirstOrDefault(x => x.IsActive); @@ -482,7 +482,7 @@ private async Task Export() try { - ExportManager.Export(instance.FilePath, instance.FileType, instance.ExportAll ? PortScanResult : new ObservableCollection(SelectedResults.Cast().ToArray())); + ExportManager.Export(instance.FilePath, instance.FileType, instance.ExportAll ? Results : new ObservableCollection(SelectedResults.Cast().ToArray())); } catch (Exception ex) { @@ -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); })); } diff --git a/Source/NETworkManager/Views/PortProfilesDialog.xaml b/Source/NETworkManager/Views/PortProfilesDialog.xaml index e3c10d05ed..48550d68a8 100644 --- a/Source/NETworkManager/Views/PortProfilesDialog.xaml +++ b/Source/NETworkManager/Views/PortProfilesDialog.xaml @@ -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}"> @@ -17,33 +18,33 @@ - - + + - - + + - - + + - - + + - +