Skip to content

Commit ce661b1

Browse files
BornToBeRootclaude
andcommitted
Refactor: Profile target and enabled check in ProfileInfo
ProfileInfo.IsEnabled(application) and GetTarget(application) (the tool's host, IP range, domain, URL, ...) replace the IsProfileEnabled and GetSearchableField overrides of 16 view models. The profile panel and the run command use the same mappings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent f5a0b1e commit ce661b1

18 files changed

Lines changed: 31 additions & 68 deletions

‎Source/NETworkManager.Profiles/ProfileInfo.cs‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,4 +534,32 @@ public bool IsEnabled(ApplicationName application)
534534
_ => false
535535
};
536536
}
537+
538+
/// <summary>
539+
/// Gets the target of the profile in an application, e.g. the host, IP range, domain, URL or MAC address.
540+
/// </summary>
541+
/// <param name="application">Application to get the target for.</param>
542+
/// <returns>Target, or null if the application has none.</returns>
543+
public string GetTarget(ApplicationName application)
544+
{
545+
return application switch
546+
{
547+
ApplicationName.IPScanner => IPScanner_HostOrIPRange,
548+
ApplicationName.PortScanner => PortScanner_Host,
549+
ApplicationName.PingMonitor => PingMonitor_Host,
550+
ApplicationName.Traceroute => Traceroute_Host,
551+
ApplicationName.DNSLookup => DNSLookup_Host,
552+
ApplicationName.RemoteDesktop => RemoteDesktop_Host,
553+
ApplicationName.PowerShell => PowerShell_Host,
554+
ApplicationName.PuTTY => PuTTY_HostOrSerialLine,
555+
ApplicationName.TigerVNC => TigerVNC_Host,
556+
ApplicationName.WebConsole => WebConsole_Url,
557+
ApplicationName.SNMP => SNMP_Host,
558+
ApplicationName.WakeOnLAN => WakeOnLAN_MACAddress,
559+
ApplicationName.RDAP => RDAP_Query,
560+
ApplicationName.Whois => Whois_Domain,
561+
ApplicationName.IPGeolocation => IPGeolocation_Host,
562+
_ => null
563+
};
564+
}
537565
}

‎Source/NETworkManager/ViewModels/DNSLookupHostViewModel.cs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ public DNSLookupHostViewModel()
9090

9191
protected override ApplicationName ApplicationName => ApplicationName.DNSLookup;
9292

93-
protected override bool IsProfileEnabled(ProfileInfo profile) => profile.DNSLookup_Enabled;
94-
95-
protected override string GetSearchableField(ProfileInfo profile) => profile.DNSLookup_Host;
96-
9793
#endregion
9894

9995
#region ICommand & Actions

‎Source/NETworkManager/ViewModels/IPGeolocationHostViewModel.cs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ public IPGeolocationHostViewModel()
8888

8989
protected override ApplicationName ApplicationName => ApplicationName.IPGeolocation;
9090

91-
protected override bool IsProfileEnabled(ProfileInfo profile) => profile.IPGeolocation_Enabled;
92-
93-
protected override string GetSearchableField(ProfileInfo profile) => profile.IPGeolocation_Host;
94-
9591
#endregion
9692

9793
#region ICommand & Actions

‎Source/NETworkManager/ViewModels/IPScannerHostViewModel.cs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ public IPScannerHostViewModel()
8888

8989
protected override ApplicationName ApplicationName => ApplicationName.IPScanner;
9090

91-
protected override bool IsProfileEnabled(ProfileInfo profile) => profile.IPScanner_Enabled;
92-
93-
protected override string GetSearchableField(ProfileInfo profile) => profile.IPScanner_HostOrIPRange;
94-
9591
#endregion
9692

9793
#region ICommand & Actions

‎Source/NETworkManager/ViewModels/NetworkInterfaceViewModel.cs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -732,11 +732,6 @@ private async Task LoadNetworkInterfaces()
732732

733733
protected override ApplicationName ApplicationName => ApplicationName.NetworkInterface;
734734

735-
protected override bool IsProfileEnabled(ProfileInfo profile) => profile.NetworkInterface_Enabled;
736-
737-
// Unlike other tools, profile search here only matches the profile name (no secondary field).
738-
protected override string GetSearchableField(ProfileInfo profile) => string.Empty;
739-
740735
#endregion
741736

742737
#region ICommands & Actions

‎Source/NETworkManager/ViewModels/PingMonitorHostViewModel.cs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,6 @@ public PingMonitorHostViewModel()
185185

186186
protected override ApplicationName ApplicationName => ApplicationName.PingMonitor;
187187

188-
protected override bool IsProfileEnabled(ProfileInfo profile) => profile.PingMonitor_Enabled;
189-
190-
protected override string GetSearchableField(ProfileInfo profile) => profile.PingMonitor_Host;
191-
192188
#endregion
193189

194190
#region ICommands & Actions

‎Source/NETworkManager/ViewModels/PortScannerHostViewModel.cs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ public PortScannerHostViewModel()
8888

8989
protected override ApplicationName ApplicationName => ApplicationName.PortScanner;
9090

91-
protected override bool IsProfileEnabled(ProfileInfo profile) => profile.PortScanner_Enabled;
92-
93-
protected override string GetSearchableField(ProfileInfo profile) => profile.PortScanner_Host;
94-
9591
#endregion
9692

9793
#region ICommand & Actions

‎Source/NETworkManager/ViewModels/PowerShellHostViewModel.cs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ public PowerShellHostViewModel()
135135

136136
protected override ApplicationName ApplicationName => ApplicationName.PowerShell;
137137

138-
protected override bool IsProfileEnabled(ProfileInfo profile) => profile.PowerShell_Enabled;
139-
140-
protected override string GetSearchableField(ProfileInfo profile) => profile.PowerShell_Host;
141-
142138
/// <summary>
143139
/// Also mirrors the popup state into <see cref="ConfigurationManager"/> so the main window can suppress
144140
/// global focus-stealing behavior (e.g. re-focusing the embedded terminal) while the filter popup is open.

‎Source/NETworkManager/ViewModels/ProfileHostViewModelBase.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ public abstract class ProfileHostViewModelBase : ViewModelBase, IProfileHostView
3636
/// <summary>
3737
/// Determines whether the given profile is enabled for this tool.
3838
/// </summary>
39-
protected abstract bool IsProfileEnabled(ProfileInfo profile);
39+
private bool IsProfileEnabled(ProfileInfo profile) => profile.IsEnabled(ApplicationName);
4040

4141
/// <summary>
42-
/// Gets the tool-specific field of the given profile that should also be matched against the search text
42+
/// Gets the tool-specific field of the given profile (e.g. host) that is also matched against the search text
4343
/// (in addition to the profile name).
4444
/// </summary>
45-
protected abstract string GetSearchableField(ProfileInfo profile);
45+
private string GetSearchableField(ProfileInfo profile) => profile.GetTarget(ApplicationName) ?? string.Empty;
4646

4747
/// <summary>
4848
/// Gets the view for the profiles.

‎Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ public PuTTYHostViewModel()
135135

136136
protected override ApplicationName ApplicationName => ApplicationName.PuTTY;
137137

138-
protected override bool IsProfileEnabled(ProfileInfo profile) => profile.PuTTY_Enabled;
139-
140-
protected override string GetSearchableField(ProfileInfo profile) => profile.PuTTY_HostOrSerialLine;
141-
142138
/// <summary>
143139
/// Also mirrors the popup state into <see cref="ConfigurationManager"/> so the main window can suppress
144140
/// global focus-stealing behavior (e.g. re-focusing the embedded terminal) while the filter popup is open.

0 commit comments

Comments
 (0)