From d13cf29eb3efca3a8b4950929e9c1ebdcfe16713 Mon Sep 17 00:00:00 2001 From: BornToBeRoot <16019165+BornToBeRoot@users.noreply.github.com> Date: Tue, 12 Sep 2023 00:10:06 +0200 Subject: [PATCH] Chore: Refactoring & Cleanup & Docs --- .../Resources/StaticStrings.Designer.cs | 187 +++++++++--------- .../Resources/StaticStrings.resx | 4 +- .../NETworkManager.Utilities/RegexHelper.cs | 4 +- .../SNMPOIDValidator.cs | 25 ++- Source/NETworkManager.sln.DotSettings | 1 + .../Resources/ContextMenu/ContextMenu.xaml | 3 +- .../ViewModels/BitCalculatorViewModel.cs | 47 ++--- .../ViewModels/DNSLookupViewModel.cs | 66 ++++--- .../ViewModels/LookupOUILookupViewModel.cs | 32 +-- .../ViewModels/LookupPortViewModel.cs | 36 ++-- .../ViewModels/PingMonitorHostViewModel.cs | 77 ++++---- .../SubnetCalculatorCalculatorViewModel.cs | 24 +-- .../SubnetCalculatorSubnettingViewModel.cs | 68 ++++--- .../SubnetCalculatorWideSubnetViewModel.cs | 26 ++- .../ViewModels/WakeOnLANViewModel.cs | 61 +++--- .../ViewModels/WhoisViewModel.cs | 40 ++-- .../Views/BitCalculatorView.xaml | 17 +- .../Views/BitCalculatorView.xaml.cs | 2 +- .../NETworkManager/Views/DNSLookupView.xaml | 22 ++- Source/NETworkManager/Views/GroupDialog.xaml | 12 +- .../Views/LookupOUILookupView.xaml | 17 +- .../Views/LookupPortLookupView.xaml | 18 +- .../Views/PingMonitorHostView.xaml | 13 +- .../Views/PingMonitorHostView.xaml.cs | 2 +- .../NETworkManager/Views/PortScannerView.xaml | 24 ++- .../NETworkManager/Views/ProfileDialog.xaml | 12 +- .../Views/SNMPOIDProfileDialog.xaml | 12 +- Source/NETworkManager/Views/SNMPView.xaml | 109 ++++++---- .../Views/SubnetCalculatorCalculatorView.xaml | 15 +- .../Views/SubnetCalculatorHostView.xaml | 8 +- .../Views/SubnetCalculatorSubnettingView.xaml | 46 +++-- .../Views/SubnetCalculatorWideSubnetView.xaml | 41 ++-- .../SubnetCalculatorWideSubnetView.xaml.cs | 5 +- .../NETworkManager/Views/TracerouteView.xaml | 12 +- .../NETworkManager/Views/WakeOnLANView.xaml | 29 ++- Source/NETworkManager/Views/WhoisView.xaml | 17 +- docs/Changelog/next-release.md | 2 + 37 files changed, 652 insertions(+), 484 deletions(-) diff --git a/Source/NETworkManager.Localization/Resources/StaticStrings.Designer.cs b/Source/NETworkManager.Localization/Resources/StaticStrings.Designer.cs index a95fc0efe4..be6e6ea2df 100644 --- a/Source/NETworkManager.Localization/Resources/StaticStrings.Designer.cs +++ b/Source/NETworkManager.Localization/Resources/StaticStrings.Designer.cs @@ -1,10 +1,9 @@ //------------------------------------------------------------------------------ // -// Dieser Code wurde von einem Tool generiert. -// Laufzeitversion:4.0.30319.42000 +// This code was generated by a tool. // -// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -// der Code erneut generiert wird. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. // //------------------------------------------------------------------------------ @@ -13,12 +12,12 @@ namespace NETworkManager.Localization.Resources { /// - /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// A strongly-typed resource class, for looking up localized strings, etc. /// - // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert - // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. - // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen - // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] @@ -33,7 +32,7 @@ internal StaticStrings() { } /// - /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] public static global::System.Resources.ResourceManager ResourceManager { @@ -47,8 +46,8 @@ internal StaticStrings() { } /// - /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle - /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] public static global::System.Globalization.CultureInfo Culture { @@ -61,7 +60,7 @@ internal StaticStrings() { } /// - /// Sucht eine lokalisierte Zeichenfolge, die CSV ähnelt. + /// Looks up a localized string similar to CSV. /// public static string CSV { get { @@ -70,7 +69,7 @@ public static string CSV { } /// - /// Sucht eine lokalisierte Zeichenfolge, die i-0b22a22eec53b9321 ähnelt. + /// Looks up a localized string similar to i-0b22a22eec53b9321. /// public static string ExampleAWSInstanceId { get { @@ -79,7 +78,7 @@ public static string ExampleAWSInstanceId { } /// - /// Sucht eine lokalisierte Zeichenfolge, die default ähnelt. + /// Looks up a localized string similar to default. /// public static string ExampleAWSProfile { get { @@ -88,7 +87,7 @@ public static string ExampleAWSProfile { } /// - /// Sucht eine lokalisierte Zeichenfolge, die eu-central-1 ähnelt. + /// Looks up a localized string similar to eu-central-1. /// public static string ExampleAWSRegion { get { @@ -97,7 +96,7 @@ public static string ExampleAWSRegion { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 9600 ähnelt. + /// Looks up a localized string similar to 9600. /// public static string ExampleBaud9600 { get { @@ -106,7 +105,7 @@ public static string ExampleBaud9600 { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 1024 ähnelt. + /// Looks up a localized string similar to 1024. /// public static string ExampleBits { get { @@ -115,7 +114,7 @@ public static string ExampleBits { } /// - /// Sucht eine lokalisierte Zeichenfolge, die Windows-Testuser ähnelt. + /// Looks up a localized string similar to Windows-Testuser. /// public static string ExampleCredentialName { get { @@ -124,7 +123,7 @@ public static string ExampleCredentialName { } /// - /// Sucht eine lokalisierte Zeichenfolge, die https://$$HOSTNAME$$/ ähnelt. + /// Looks up a localized string similar to https://$$HOSTNAME$$/. /// public static string ExampleCustomCommandVariableHostname { get { @@ -133,7 +132,7 @@ public static string ExampleCustomCommandVariableHostname { } /// - /// Sucht eine lokalisierte Zeichenfolge, die example.com ähnelt. + /// Looks up a localized string similar to example.com. /// public static string ExampleDomain { get { @@ -142,7 +141,7 @@ public static string ExampleDomain { } /// - /// Sucht eine lokalisierte Zeichenfolge, die gw.example.com ähnelt. + /// Looks up a localized string similar to gw.example.com. /// public static string ExampleGatewayDomain { get { @@ -151,7 +150,7 @@ public static string ExampleGatewayDomain { } /// - /// Sucht eine lokalisierte Zeichenfolge, die Servers ähnelt. + /// Looks up a localized string similar to Servers. /// public static string ExampleGroupServers { get { @@ -160,7 +159,7 @@ public static string ExampleGroupServers { } /// - /// Sucht eine lokalisierte Zeichenfolge, die Switche ähnelt. + /// Looks up a localized string similar to Switche. /// public static string ExampleGroupSwitche { get { @@ -169,7 +168,7 @@ public static string ExampleGroupSwitche { } /// - /// Sucht eine lokalisierte Zeichenfolge, die server-01.example.com ähnelt. + /// Looks up a localized string similar to server-01.example.com. /// public static string ExampleHostFQDN { get { @@ -178,7 +177,7 @@ public static string ExampleHostFQDN { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 71:b8:f2:6e..., 13:59:a7... ähnelt. + /// Looks up a localized string similar to 71:b8:f2:6e..., 13:59:a7.... /// public static string ExampleHostkey { get { @@ -187,7 +186,7 @@ public static string ExampleHostkey { } /// - /// Sucht eine lokalisierte Zeichenfolge, die SERVER-01 ähnelt. + /// Looks up a localized string similar to SERVER-01. /// public static string ExampleHostname { get { @@ -196,7 +195,7 @@ public static string ExampleHostname { } /// - /// Sucht eine lokalisierte Zeichenfolge, die SERVER-01; 172.16.0.100 ähnelt. + /// Looks up a localized string similar to SERVER-01; 172.16.0.100. /// public static string ExampleHostnameAndOrIPAddress { get { @@ -205,7 +204,7 @@ public static string ExampleHostnameAndOrIPAddress { } /// - /// Sucht eine lokalisierte Zeichenfolge, die SERVER-01 or 172.16.0.100 ähnelt. + /// Looks up a localized string similar to SERVER-01 or 172.16.0.100. /// public static string ExampleHostnameOrIPAddress { get { @@ -214,7 +213,7 @@ public static string ExampleHostnameOrIPAddress { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 192.168.1.0/24; 192.168.178.1 - 192.168.178.128; 192.168.[178-179].[1,100,150-200]; example.com/24 ähnelt. + /// Looks up a localized string similar to 192.168.1.0/24; 192.168.178.1 - 192.168.178.128; 192.168.[178-179].[1,100,150-200]; example.com/24. /// public static string ExampleHostRange { get { @@ -223,7 +222,7 @@ public static string ExampleHostRange { } /// - /// Sucht eine lokalisierte Zeichenfolge, die server-01.example.com:3389 ähnelt. + /// Looks up a localized string similar to server-01.example.com:3389. /// public static string ExampleHostWithRDPPort { get { @@ -232,7 +231,7 @@ public static string ExampleHostWithRDPPort { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 192.168.178.55 ähnelt. + /// Looks up a localized string similar to 192.168.178.55. /// public static string ExampleIPv4Address { get { @@ -241,7 +240,7 @@ public static string ExampleIPv4Address { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 192.168.178.255 ähnelt. + /// Looks up a localized string similar to 192.168.178.255. /// public static string ExampleIPv4Broadcast { get { @@ -250,7 +249,7 @@ public static string ExampleIPv4Broadcast { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 1.1.1.1 ähnelt. + /// Looks up a localized string similar to 1.1.1.1. /// public static string ExampleIPv4DNSServer { get { @@ -259,7 +258,7 @@ public static string ExampleIPv4DNSServer { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 192.168.178.1; 1.1.1.1; 1.0.0.1 ähnelt. + /// Looks up a localized string similar to 192.168.178.1; 1.1.1.1; 1.0.0.1. /// public static string ExampleIPv4DNSServers { get { @@ -268,7 +267,7 @@ public static string ExampleIPv4DNSServers { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 192.168.178.1 ähnelt. + /// Looks up a localized string similar to 192.168.178.1. /// public static string ExampleIPv4Gateway { get { @@ -277,7 +276,7 @@ public static string ExampleIPv4Gateway { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 192.168.178.133/255.255.255.0 or 2001:0db8::/64 ähnelt. + /// Looks up a localized string similar to 192.168.178.133/255.255.255.0 or 2001:0db8::/64. /// public static string ExampleIPv4IPv6Subnet { get { @@ -286,7 +285,7 @@ public static string ExampleIPv4IPv6Subnet { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 192.168.178.134/255.255.255.0 or 2001:0db9::/64 ähnelt. + /// Looks up a localized string similar to 192.168.178.134/255.255.255.0 or 2001:0db9::/64. /// public static string ExampleIPv4IPv6Subnet2 { get { @@ -295,7 +294,7 @@ public static string ExampleIPv4IPv6Subnet2 { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 192.168.180.0/24 or 2001:0db9::/54 ähnelt. + /// Looks up a localized string similar to 192.168.180.0/24 or 2001:0db9::/54. /// public static string ExampleIPv4IPv6Subnet3 { get { @@ -304,7 +303,7 @@ public static string ExampleIPv4IPv6Subnet3 { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 192.168.178.0/24 or 192.168.178.0/255.255.255.0 ähnelt. + /// Looks up a localized string similar to 192.168.178.0/24 or 192.168.178.0/255.255.255.0. /// public static string ExampleIPv4Subnet { get { @@ -313,7 +312,7 @@ public static string ExampleIPv4Subnet { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 192.168.179.0/24 or 192.168.179.0/255.255.255.0 ähnelt. + /// Looks up a localized string similar to 192.168.179.0/24 or 192.168.179.0/255.255.255.0. /// public static string ExampleIPv4Subnet2 { get { @@ -322,7 +321,7 @@ public static string ExampleIPv4Subnet2 { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 255.255.255.0 ähnelt. + /// Looks up a localized string similar to 255.255.255.0. /// public static string ExampleIPv4Subnetmask { get { @@ -331,7 +330,7 @@ public static string ExampleIPv4Subnetmask { } /// - /// Sucht eine lokalisierte Zeichenfolge, die /24 or 255.255.255.0 ähnelt. + /// Looks up a localized string similar to /24 or 255.255.255.0. /// public static string ExampleIPv4SubnetmaskIPv4CIDR { get { @@ -340,7 +339,7 @@ public static string ExampleIPv4SubnetmaskIPv4CIDR { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 255.255.255.0 or /64 ähnelt. + /// Looks up a localized string similar to 255.255.255.0 or /64. /// public static string ExampleIPv4SubnetmaskIPv6CIDR { get { @@ -349,7 +348,7 @@ public static string ExampleIPv4SubnetmaskIPv6CIDR { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 192.168.100.0/24 ähnelt. + /// Looks up a localized string similar to 192.168.100.0/24. /// public static string ExampleIPv4SubnetWithCIDR { get { @@ -358,7 +357,7 @@ public static string ExampleIPv4SubnetWithCIDR { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 2606:4700:4700::1111 ähnelt. + /// Looks up a localized string similar to 2606:4700:4700::1111. /// public static string ExampleIPv6Address { get { @@ -367,7 +366,7 @@ public static string ExampleIPv6Address { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 00:F1:21:AB:0B:35 ähnelt. + /// Looks up a localized string similar to 00:F1:21:AB:0B:35. /// public static string ExampleMACAddress { get { @@ -376,7 +375,7 @@ public static string ExampleMACAddress { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 01:23:45:67:89:AB; 01-23-45; AA11BB; 00F1A2C3D4E5; Intel Corp; Asus ähnelt. + /// Looks up a localized string similar to 01:23:45:67:89:AB; 01-23-45; AA11BB; 00F1A2C3D4E5; Intel Corp; Asus. /// public static string ExampleMACAddressesOrVendor { get { @@ -385,7 +384,7 @@ public static string ExampleMACAddressesOrVendor { } /// - /// Sucht eine lokalisierte Zeichenfolge, die S3cr3t_P4ssw0rd% ähnelt. + /// Looks up a localized string similar to S3cr3t_P4ssw0rd%. /// public static string ExamplePassword { get { @@ -394,7 +393,7 @@ public static string ExamplePassword { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 161 ähnelt. + /// Looks up a localized string similar to 161. /// public static string ExamplePort161 { get { @@ -403,7 +402,7 @@ public static string ExamplePort161 { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 22 ähnelt. + /// Looks up a localized string similar to 22. /// public static string ExamplePort22 { get { @@ -412,7 +411,7 @@ public static string ExamplePort22 { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 23 ähnelt. + /// Looks up a localized string similar to 23. /// public static string ExamplePort23 { get { @@ -421,7 +420,7 @@ public static string ExamplePort23 { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 3389 ähnelt. + /// Looks up a localized string similar to 3389. /// public static string ExamplePort3389 { get { @@ -430,7 +429,7 @@ public static string ExamplePort3389 { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 513 ähnelt. + /// Looks up a localized string similar to 513. /// public static string ExamplePort513 { get { @@ -439,7 +438,7 @@ public static string ExamplePort513 { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 53 ähnelt. + /// Looks up a localized string similar to 53. /// public static string ExamplePort53 { get { @@ -448,7 +447,7 @@ public static string ExamplePort53 { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 5900 ähnelt. + /// Looks up a localized string similar to 5900. /// public static string ExamplePort5900 { get { @@ -457,7 +456,7 @@ public static string ExamplePort5900 { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 7 ähnelt. + /// Looks up a localized string similar to 7. /// public static string ExamplePort7 { get { @@ -466,7 +465,7 @@ public static string ExamplePort7 { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 22; 80; https; ldaps; 777 - 999; 8080 ähnelt. + /// Looks up a localized string similar to 22; 80; https; ldaps; 777 - 999; 8080. /// public static string ExamplePortPortRangeOrService { get { @@ -475,7 +474,7 @@ public static string ExamplePortPortRangeOrService { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 22; 80; 443 ähnelt. + /// Looks up a localized string similar to 22; 80; 443. /// public static string ExamplePorts { get { @@ -484,7 +483,7 @@ public static string ExamplePorts { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 22; 80; 443; 500 - 999; 8080 ähnelt. + /// Looks up a localized string similar to 22; 80; 443; 500 - 999; 8080. /// public static string ExamplePortScanRange { get { @@ -493,7 +492,7 @@ public static string ExamplePortScanRange { } /// - /// Sucht eine lokalisierte Zeichenfolge, die C:\Program Files\PowerShell\7\pwsh.exe ähnelt. + /// Looks up a localized string similar to C:\Program Files\PowerShell\7\pwsh.exe. /// public static string ExamplePowerShellPath { get { @@ -502,7 +501,7 @@ public static string ExamplePowerShellPath { } /// - /// Sucht eine lokalisierte Zeichenfolge, die https://api.ipify.org ähnelt. + /// Looks up a localized string similar to https://api.ipify.org. /// public static string ExamplePublicIPv4AddressAPI { get { @@ -511,7 +510,7 @@ public static string ExamplePublicIPv4AddressAPI { } /// - /// Sucht eine lokalisierte Zeichenfolge, die https://api6.ipify.org ähnelt. + /// Looks up a localized string similar to https://api6.ipify.org. /// public static string ExamplePublicIPv6AddressAPI { get { @@ -520,7 +519,7 @@ public static string ExamplePublicIPv6AddressAPI { } /// - /// Sucht eine lokalisierte Zeichenfolge, die C:\Program Files\PuTTY\putty.exe ähnelt. + /// Looks up a localized string similar to C:\Program Files\PuTTY\putty.exe. /// public static string ExamplePuTTYPath { get { @@ -529,7 +528,7 @@ public static string ExamplePuTTYPath { } /// - /// Sucht eine lokalisierte Zeichenfolge, die NETworkManager ähnelt. + /// Looks up a localized string similar to NETworkManager. /// public static string ExamplePuTTYProfile { get { @@ -538,7 +537,7 @@ public static string ExamplePuTTYProfile { } /// - /// Sucht eine lokalisierte Zeichenfolge, die Webserver ähnelt. + /// Looks up a localized string similar to Webserver. /// public static string ExampleRemoteDesktopProfileName { get { @@ -547,7 +546,7 @@ public static string ExampleRemoteDesktopProfileName { } /// - /// Sucht eine lokalisierte Zeichenfolge, die COM5 ähnelt. + /// Looks up a localized string similar to COM5. /// public static string ExampleSerialLine { get { @@ -556,7 +555,7 @@ public static string ExampleSerialLine { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 4uth_S3cr3t! ähnelt. + /// Looks up a localized string similar to 4uth_S3cr3t!. /// public static string ExampleSNMPAuthSecret { get { @@ -565,7 +564,7 @@ public static string ExampleSNMPAuthSecret { } /// - /// Sucht eine lokalisierte Zeichenfolge, die public ähnelt. + /// Looks up a localized string similar to public. /// public static string ExampleSNMPCommunity { get { @@ -574,7 +573,7 @@ public static string ExampleSNMPCommunity { } /// - /// Sucht eine lokalisierte Zeichenfolge, die system ähnelt. + /// Looks up a localized string similar to system. /// public static string ExampleSNMPMIB { get { @@ -583,25 +582,25 @@ public static string ExampleSNMPMIB { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 1.3.6.1.2.1.1 ähnelt. + /// Looks up a localized string similar to 1.3.6.1.2.1.1. /// - public static string ExampleSNMPOID { + public static string ExampleSnmpOid { get { - return ResourceManager.GetString("ExampleSNMPOID", resourceCulture); + return ResourceManager.GetString("ExampleSnmpOid", resourceCulture); } } /// - /// Sucht eine lokalisierte Zeichenfolge, die 1.3.6.1.2.1.1; 1.3.6.1.2.1.2 ähnelt. + /// Looks up a localized string similar to 1.3.6.1.2.1.1; 1.3.6.1.2.1.2. /// - public static string ExampleSNMPOIDS { + public static string ExampleSnmpOids { get { - return ResourceManager.GetString("ExampleSNMPOIDS", resourceCulture); + return ResourceManager.GetString("ExampleSnmpOids", resourceCulture); } } /// - /// Sucht eine lokalisierte Zeichenfolge, die Pr1v_S3cr3t% ähnelt. + /// Looks up a localized string similar to Pr1v_S3cr3t%. /// public static string ExampleSNMPPrivSecret { get { @@ -610,7 +609,7 @@ public static string ExampleSNMPPrivSecret { } /// - /// Sucht eine lokalisierte Zeichenfolge, die snmp-user ähnelt. + /// Looks up a localized string similar to snmp-user. /// public static string ExampleSNMPUsername { get { @@ -619,7 +618,7 @@ public static string ExampleSNMPUsername { } /// - /// Sucht eine lokalisierte Zeichenfolge, die IoT-Devices ähnelt. + /// Looks up a localized string similar to IoT-Devices. /// public static string ExampleSsid { get { @@ -628,7 +627,7 @@ public static string ExampleSsid { } /// - /// Sucht eine lokalisierte Zeichenfolge, die example.com ähnelt. + /// Looks up a localized string similar to example.com. /// public static string ExampleSuffix { get { @@ -637,7 +636,7 @@ public static string ExampleSuffix { } /// - /// Sucht eine lokalisierte Zeichenfolge, die server; dmz ähnelt. + /// Looks up a localized string similar to server; dmz. /// public static string ExampleTags { get { @@ -646,7 +645,7 @@ public static string ExampleTags { } /// - /// Sucht eine lokalisierte Zeichenfolge, die C:\Tools\TigerVNC\vncviewer64-1.12.0.exe ähnelt. + /// Looks up a localized string similar to C:\Tools\TigerVNC\vncviewer64-1.12.0.exe. /// public static string ExampleTigerVNCPath { get { @@ -655,7 +654,7 @@ public static string ExampleTigerVNCPath { } /// - /// Sucht eine lokalisierte Zeichenfolge, die Admin ähnelt. + /// Looks up a localized string similar to Admin. /// public static string ExampleUsername { get { @@ -664,7 +663,7 @@ public static string ExampleUsername { } /// - /// Sucht eine lokalisierte Zeichenfolge, die 80; 443; 8080; 8443 ähnelt. + /// Looks up a localized string similar to 80; 443; 8080; 8443. /// public static string ExampleWebserverPorts { get { @@ -673,7 +672,7 @@ public static string ExampleWebserverPorts { } /// - /// Sucht eine lokalisierte Zeichenfolge, die http(s)://example.com/index.html ähnelt. + /// Looks up a localized string similar to http(s)://example.com/index.html. /// public static string ExampleWebsiteUri { get { @@ -682,7 +681,7 @@ public static string ExampleWebsiteUri { } /// - /// Sucht eine lokalisierte Zeichenfolge, die GitHub ähnelt. + /// Looks up a localized string similar to GitHub. /// public static string GitHub { get { @@ -691,7 +690,7 @@ public static string GitHub { } /// - /// Sucht eine lokalisierte Zeichenfolge, die •••••••••••• ähnelt. + /// Looks up a localized string similar to ••••••••••••. /// public static string HiddenPassword { get { @@ -700,7 +699,7 @@ public static string HiddenPassword { } /// - /// Sucht eine lokalisierte Zeichenfolge, die iexplore.exe ähnelt. + /// Looks up a localized string similar to iexplore.exe. /// public static string IExploreExe { get { @@ -709,7 +708,7 @@ public static string IExploreExe { } /// - /// Sucht eine lokalisierte Zeichenfolge, die Internet Explorer ähnelt. + /// Looks up a localized string similar to Internet Explorer. /// public static string InternetExplorer { get { @@ -718,7 +717,7 @@ public static string InternetExplorer { } /// - /// Sucht eine lokalisierte Zeichenfolge, die JSON ähnelt. + /// Looks up a localized string similar to JSON. /// public static string JSON { get { @@ -727,7 +726,7 @@ public static string JSON { } /// - /// Sucht eine lokalisierte Zeichenfolge, die C:\Data\Keys\private_ssh.ppk ähnelt. + /// Looks up a localized string similar to C:\Data\Keys\private_ssh.ppk. /// public static string PrivateKeyFileLocationDots { get { @@ -736,7 +735,7 @@ public static string PrivateKeyFileLocationDots { } /// - /// Sucht eine lokalisierte Zeichenfolge, die NETworkManager ähnelt. + /// Looks up a localized string similar to NETworkManager. /// public static string ProductName { get { @@ -745,7 +744,7 @@ public static string ProductName { } /// - /// Sucht eine lokalisierte Zeichenfolge, die TXT ähnelt. + /// Looks up a localized string similar to TXT. /// public static string TXT { get { @@ -754,7 +753,7 @@ public static string TXT { } /// - /// Sucht eine lokalisierte Zeichenfolge, die XML ähnelt. + /// Looks up a localized string similar to XML. /// public static string XML { get { diff --git a/Source/NETworkManager.Localization/Resources/StaticStrings.resx b/Source/NETworkManager.Localization/Resources/StaticStrings.resx index 484fc54c6e..7cd9f9e1ec 100644 --- a/Source/NETworkManager.Localization/Resources/StaticStrings.resx +++ b/Source/NETworkManager.Localization/Resources/StaticStrings.resx @@ -234,7 +234,7 @@ public - + 1.3.6.1.2.1.1 @@ -339,7 +339,7 @@ system - + 1.3.6.1.2.1.1; 1.3.6.1.2.1.2 diff --git a/Source/NETworkManager.Utilities/RegexHelper.cs b/Source/NETworkManager.Utilities/RegexHelper.cs index 4007ef223f..c40b1a7aa0 100644 --- a/Source/NETworkManager.Utilities/RegexHelper.cs +++ b/Source/NETworkManager.Utilities/RegexHelper.cs @@ -84,6 +84,6 @@ public static class RegexHelper // Match a number (like 12, 12.4, 12,3) public const string NumberRegex = @"^\d+((\.|,)\d+)?$"; - // Match an SNMP OID (like 1.3.6.1) - public const string SNMOIODRegex = @"^[012]\.(?:[0-9]|[1-3][0-9])(\.\d+)*$"; + // Match an SNMP OID (like 1.3.6.1 or .1.3.6.2) + public const string SnmpOidRegex = @"^\.?[012]\.(?:[0-9]|[1-3][0-9])(\.\d+)*$"; } diff --git a/Source/NETworkManager.Validators/SNMPOIDValidator.cs b/Source/NETworkManager.Validators/SNMPOIDValidator.cs index 044e9ddf9e..64c9af7c34 100644 --- a/Source/NETworkManager.Validators/SNMPOIDValidator.cs +++ b/Source/NETworkManager.Validators/SNMPOIDValidator.cs @@ -1,29 +1,26 @@ using NETworkManager.Utilities; using System.Globalization; +using System.Linq; using System.Text.RegularExpressions; using System.Windows.Controls; namespace NETworkManager.Validators; -public class SNMPOIDValidator : ValidationRule +public class SnmpOidValidator : ValidationRule { public SNMPOIDDependencyObjectWrapper Wrapper { get; set; } public override ValidationResult Validate(object value, CultureInfo cultureInfo) { - var oidValue = (value as string).Replace(" ", ""); + var oidValue = (value as string)!.Replace(" ", ""); - if (Wrapper.Mode == Models.Network.SNMPMode.Get && oidValue.Contains(';')) - { - foreach (var oid in oidValue.Split(';')) - { - if (!Regex.IsMatch(oid, RegexHelper.SNMOIODRegex)) - return new ValidationResult(false, Localization.Resources.Strings.EnterValidOID); - } - - return ValidationResult.ValidResult; - } - - return Regex.IsMatch(oidValue, RegexHelper.SNMOIODRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidOID); + if (Wrapper.Mode != Models.Network.SNMPMode.Get || !oidValue.Contains(';')) + return Regex.IsMatch(oidValue, RegexHelper.SnmpOidRegex) + ? ValidationResult.ValidResult + : new ValidationResult(false, Localization.Resources.Strings.EnterValidOID); + + return oidValue.Split(';').Any(oid => !Regex.IsMatch(oid, RegexHelper.SnmpOidRegex)) ? + new ValidationResult(false, Localization.Resources.Strings.EnterValidOID) : + ValidationResult.ValidResult; } } diff --git a/Source/NETworkManager.sln.DotSettings b/Source/NETworkManager.sln.DotSettings index 3482c319e9..8665c17158 100644 --- a/Source/NETworkManager.sln.DotSettings +++ b/Source/NETworkManager.sln.DotSettings @@ -58,6 +58,7 @@ True True True + True True True diff --git a/Source/NETworkManager/Resources/ContextMenu/ContextMenu.xaml b/Source/NETworkManager/Resources/ContextMenu/ContextMenu.xaml index feb27e9c1e..28d5eff38d 100644 --- a/Source/NETworkManager/Resources/ContextMenu/ContextMenu.xaml +++ b/Source/NETworkManager/Resources/ContextMenu/ContextMenu.xaml @@ -1,7 +1,8 @@  + xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization" + > diff --git a/Source/NETworkManager/ViewModels/BitCalculatorViewModel.cs b/Source/NETworkManager/ViewModels/BitCalculatorViewModel.cs index b31213c238..42d046423e 100644 --- a/Source/NETworkManager/ViewModels/BitCalculatorViewModel.cs +++ b/Source/NETworkManager/ViewModels/BitCalculatorViewModel.cs @@ -1,5 +1,4 @@ using NETworkManager.Settings; -using MahApps.Metro.Controls.Dialogs; using System; using NETworkManager.Models.Network; using System.ComponentModel; @@ -18,10 +17,8 @@ public class BitCalculatorViewModel : ViewModelBase { #region Variables private static readonly ILog Log = LogManager.GetLogger(typeof(BitCalculatorViewModel)); - private readonly IDialogCoordinator _dialogCoordinator; - - private readonly bool _isLoading = true; - private bool _isViewActive = true; + + private readonly bool _isLoading; private string _input; public string Input @@ -39,11 +36,11 @@ public string Input public ICollectionView InputHistoryView { get; } - private List _units = new(); + private readonly List _units = new(); public List Units { get => _units; - set + private init { if (value == _units) return; @@ -70,16 +67,16 @@ public BitCaluclatorUnit Unit } } - private bool _isCalculationRunning; - public bool IsCalculationRunning + private bool _isRunning; + public bool IsRunning { - get => _isCalculationRunning; + get => _isRunning; set { - if (value == _isCalculationRunning) + if (value == _isRunning) return; - _isCalculationRunning = value; + _isRunning = value; OnPropertyChanged(); } } @@ -103,7 +100,7 @@ public bool IsResultVisible public BitCaluclatorInfo Result { get => _result; - set + private set { if (value == _result) return; @@ -115,9 +112,9 @@ public BitCaluclatorInfo Result #endregion #region Constructor, load settings - public BitCalculatorViewModel(IDialogCoordinator instance) + public BitCalculatorViewModel() { - _dialogCoordinator = instance; + _isLoading = true; InputHistoryView = CollectionViewSource.GetDefaultView(SettingsManager.Current.BitCalculator_InputHistory); @@ -137,11 +134,11 @@ private void LoadSettings() #endregion #region ICommands & Actions - public ICommand CalculateCommand => new RelayCommand(p => CalcualateAction(), Calculate_CanExecute); + public ICommand CalculateCommand => new RelayCommand(_ => CalculateAction(), Calculate_CanExecute); - private bool Calculate_CanExecute(object paramter) => Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen; + private bool Calculate_CanExecute(object parameter) => Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen; - private void CalcualateAction() + private void CalculateAction() { Calculate(); } @@ -151,9 +148,9 @@ private void CalcualateAction() private async void Calculate() { IsResultVisible = false; - IsCalculationRunning = true; + IsRunning = true; - if (double.TryParse(Input.Replace('.', ','), out double input)) + if (double.TryParse(Input.Replace('.', ','), out var input)) { Result = await BitCaluclator.CalculateAsync(input, Unit, SettingsManager.Current.BitCalculator_Notation); } @@ -166,7 +163,7 @@ private async void Calculate() AddInputToHistory(Input); - IsCalculationRunning = false; + IsRunning = false; } private void AddInputToHistory(string input) @@ -184,18 +181,14 @@ private void AddInputToHistory(string input) public void OnViewVisible() { - _isViewActive = true; + } public void OnViewHide() { - _isViewActive = false; + } - #endregion - - #region Event - #endregion } diff --git a/Source/NETworkManager/ViewModels/DNSLookupViewModel.cs b/Source/NETworkManager/ViewModels/DNSLookupViewModel.cs index 2c45b22206..79a7456b87 100644 --- a/Source/NETworkManager/ViewModels/DNSLookupViewModel.cs +++ b/Source/NETworkManager/ViewModels/DNSLookupViewModel.cs @@ -77,7 +77,7 @@ public DNSServerConnectionInfoProfile DNSServer public List QueryTypes { get => _queryTypes; - set + private set { if (value == _queryTypes) return; @@ -105,36 +105,36 @@ public QueryType QueryType } } - private bool _isLookupRunning; + private bool _isRunning; - public bool IsLookupRunning + public bool IsRunning { - get => _isLookupRunning; + get => _isRunning; set { - if (value == _isLookupRunning) + if (value == _isRunning) return; - _isLookupRunning = value; + _isRunning = value; OnPropertyChanged(); } } - private ObservableCollection _lookupResults = new ObservableCollection(); + private ObservableCollection _results = new(); - public ObservableCollection LookupResults + public ObservableCollection Results { - get => _lookupResults; + get => _results; set { - if (Equals(value, _lookupResults)) + if (Equals(value, _results)) return; - _lookupResults = value; + _results = value; } } - public ICollectionView LookupResultsView { get; } + public ICollectionView ResultsView { get; } private DNSLookupRecordInfo _selectedLookupResult; @@ -186,7 +186,7 @@ public bool IsStatusMessageDisplayed public string StatusMessage { get => _statusMessage; - set + private set { if (value == _statusMessage) return; @@ -220,9 +220,9 @@ public DNSLookupViewModel(IDialogCoordinator instance, int tabId, string host) .FirstOrDefault(x => x.Name == SettingsManager.Current.DNSLookup_SelectedDNSServer_v2.Name) ?? DNSServers.SourceCollection.Cast().First(); - LookupResultsView = CollectionViewSource.GetDefaultView(LookupResults); - LookupResultsView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(DNSLookupRecordInfo.Server))); - LookupResultsView.SortDescriptions.Add(new SortDescription(nameof(DNSLookupRecordInfo.Server), + ResultsView = CollectionViewSource.GetDefaultView(Results); + ResultsView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(DNSLookupRecordInfo.Server))); + ResultsView.SortDescriptions.Add(new SortDescription(nameof(DNSLookupRecordInfo.Server), ListSortDirection.Descending)); LoadSettings(); @@ -268,14 +268,14 @@ x is QueryType.A or QueryType.AAAA or QueryType.ANY or QueryType.CNAME or QueryT #region ICommands & Actions - public ICommand LookupCommand => new RelayCommand(p => LookupAction(), Lookup_CanExecute); + public ICommand LookupCommand => new RelayCommand(_ => LookupAction(), Lookup_CanExecute); private bool Lookup_CanExecute(object parameter) => Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen; private void LookupAction() { - if (!IsLookupRunning) + if (!IsRunning) StartLookup(); } @@ -314,7 +314,7 @@ private void CopySelectedResultAction() ClipboardHelper.SetClipboard(SelectedLookupResult.Result); } - public ICommand ExportCommand => new RelayCommand(_ => ExportAction()); + public ICommand ExportCommand => new RelayCommand(_ => ExportAction().ConfigureAwait(false)); private async Task ExportAction() { @@ -331,7 +331,7 @@ private async Task ExportAction() { ExportManager.Export(instance.FilePath, instance.FileType, instance.ExportAll - ? LookupResults + ? Results : new ObservableCollection(SelectedLookupResults .Cast().ToArray())); } @@ -347,8 +347,14 @@ await _dialogCoordinator.ShowMessageAsync(this, Localization.Resources.Strings.E SettingsManager.Current.DNSLookup_ExportFileType = instance.FileType; SettingsManager.Current.DNSLookup_ExportFilePath = instance.FilePath; - }, instance => { _dialogCoordinator.HideMetroDialogAsync(this, customDialog); }, - new ExportFileType[] { ExportFileType.Csv, ExportFileType.Xml, ExportFileType.Json }, true, + }, _ => + { + _dialogCoordinator.HideMetroDialogAsync(this, customDialog); + }, + new[] + { + ExportFileType.Csv, ExportFileType.Xml, ExportFileType.Json + }, true, SettingsManager.Current.DNSLookup_ExportFileType, SettingsManager.Current.DNSLookup_ExportFilePath); customDialog.Content = new ExportDialog @@ -368,10 +374,10 @@ private void StartLookup() IsStatusMessageDisplayed = false; StatusMessage = string.Empty; - IsLookupRunning = true; + IsRunning = true; // Reset the latest results - LookupResults.Clear(); + Results.Clear(); // Change the tab title (not nice, but it works) var window = Application.Current.Windows.OfType().FirstOrDefault(x => x.IsActive); @@ -439,18 +445,18 @@ private void AddHostToHistory(string host) public void SortResultByPropertyName(string sortDescription) { - LookupResultsView.SortDescriptions.Clear(); - LookupResultsView.SortDescriptions.Add(new SortDescription(nameof(DNSLookupRecordInfo.Server), + ResultsView.SortDescriptions.Clear(); + ResultsView.SortDescriptions.Add(new SortDescription(nameof(DNSLookupRecordInfo.Server), ListSortDirection.Descending)); if (_lastSortDescriptionAscending.Equals(sortDescription)) { - LookupResultsView.SortDescriptions.Add(new SortDescription(sortDescription, ListSortDirection.Descending)); + ResultsView.SortDescriptions.Add(new SortDescription(sortDescription, ListSortDirection.Descending)); _lastSortDescriptionAscending = string.Empty; } else { - LookupResultsView.SortDescriptions.Add(new SortDescription(sortDescription, ListSortDirection.Ascending)); + ResultsView.SortDescriptions.Add(new SortDescription(sortDescription, ListSortDirection.Ascending)); _lastSortDescriptionAscending = sortDescription; } } @@ -462,7 +468,7 @@ public void SortResultByPropertyName(string sortDescription) private void DNSLookup_RecordReceived(object sender, DNSLookupRecordReceivedArgs e) { Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, - new Action(delegate { LookupResults.Add(e.Args); })); + new Action(delegate { Results.Add(e.Args); })); } private void DNSLookup_LookupError(object sender, DNSLookupErrorArgs e) @@ -488,7 +494,7 @@ private void DNSLookup_LookupError(object sender, DNSLookupErrorArgs e) private void DNSLookup_LookupComplete(object sender, EventArgs e) { - IsLookupRunning = false; + IsRunning = false; } private void SettingsManager_PropertyChanged(object sender, PropertyChangedEventArgs e) diff --git a/Source/NETworkManager/ViewModels/LookupOUILookupViewModel.cs b/Source/NETworkManager/ViewModels/LookupOUILookupViewModel.cs index 8ed228bcb5..37b68a7500 100644 --- a/Source/NETworkManager/ViewModels/LookupOUILookupViewModel.cs +++ b/Source/NETworkManager/ViewModels/LookupOUILookupViewModel.cs @@ -54,21 +54,21 @@ public bool MACAddressOrVendorHasError public ICollectionView MACAddressOrVendorHistoryView { get; } - private bool _isLookupRunning; - public bool IsLookupRunning + private bool _isRunning; + public bool IsRunning { - get => _isLookupRunning; + get => _isRunning; set { - if (value == _isLookupRunning) + if (value == _isRunning) return; - _isLookupRunning = value; + _isRunning = value; OnPropertyChanged(); } } - private ObservableCollection _ouiLookupResults = new ObservableCollection(); + private ObservableCollection _ouiLookupResults = new(); public ObservableCollection OUILookupResults { get => _ouiLookupResults; @@ -138,13 +138,13 @@ public LookupOUILookupViewModel(IDialogCoordinator instance) #endregion #region ICommands & Actions - public ICommand OUILookupCommand => new RelayCommand(p => OUILookupAction(), OUILookup_CanExecute); + public ICommand OUILookupCommand => new RelayCommand(_ => OUILookupAction(), OUILookup_CanExecute); private bool OUILookup_CanExecute(object parameter) => Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen && !MACAddressOrVendorHasError; private async void OUILookupAction() { - IsLookupRunning = true; + IsRunning = true; OUILookupResults.Clear(); @@ -182,24 +182,24 @@ private async void OUILookupAction() NoVendorFound = false; } - IsLookupRunning = false; + IsRunning = false; } - public ICommand CopySelectedMACAddressCommand => new RelayCommand(p => CopySelectedMACAddressAction()); + public ICommand CopySelectedMACAddressCommand => new RelayCommand(_ => CopySelectedMACAddressAction()); private void CopySelectedMACAddressAction() { ClipboardHelper.SetClipboard(SelectedOUILookupResult.MACAddress); } - public ICommand CopySelectedVendorCommand => new RelayCommand(p => CopySelectedVendorAction()); + public ICommand CopySelectedVendorCommand => new RelayCommand(_ => CopySelectedVendorAction()); private void CopySelectedVendorAction() { ClipboardHelper.SetClipboard(SelectedOUILookupResult.Vendor); } - public ICommand ExportCommand => new RelayCommand(p => ExportAction()); + public ICommand ExportCommand => new RelayCommand(_ => ExportAction().ConfigureAwait(false)); private async Task ExportAction() { @@ -226,7 +226,13 @@ private async Task ExportAction() SettingsManager.Current.Lookup_OUI_ExportFileType = instance.FileType; SettingsManager.Current.Lookup_OUI_ExportFilePath = instance.FilePath; - }, instance => { _dialogCoordinator.HideMetroDialogAsync(this, customDialog); }, new ExportFileType[] { ExportFileType.Csv, ExportFileType.Xml, ExportFileType.Json }, true, SettingsManager.Current.Lookup_OUI_ExportFileType, SettingsManager.Current.Lookup_OUI_ExportFilePath); + }, _ => + { + _dialogCoordinator.HideMetroDialogAsync(this, customDialog); + }, new[] + { + ExportFileType.Csv, ExportFileType.Xml, ExportFileType.Json + }, true, SettingsManager.Current.Lookup_OUI_ExportFileType, SettingsManager.Current.Lookup_OUI_ExportFilePath); customDialog.Content = new ExportDialog { diff --git a/Source/NETworkManager/ViewModels/LookupPortViewModel.cs b/Source/NETworkManager/ViewModels/LookupPortViewModel.cs index 06a92db31b..fd12db6702 100644 --- a/Source/NETworkManager/ViewModels/LookupPortViewModel.cs +++ b/Source/NETworkManager/ViewModels/LookupPortViewModel.cs @@ -52,21 +52,21 @@ public bool PortOrServiceHasError public ICollectionView PortsOrServicesHistoryView { get; } - private bool _isLookupRunning; - public bool IsLookupRunning + private bool _isRunning; + public bool IsRunning { - get => _isLookupRunning; + get => _isRunning; set { - if (value == _isLookupRunning) + if (value == _isRunning) return; - _isLookupRunning = value; + _isRunning = value; OnPropertyChanged(); } } - private ObservableCollection _portLookupResults = new ObservableCollection(); + private ObservableCollection _portLookupResults = new(); public ObservableCollection PortLookupResults { get => _portLookupResults; @@ -136,13 +136,13 @@ public LookupPortLookupViewModel(IDialogCoordinator instance) #endregion #region ICommands & Actions - public ICommand PortLookupCommand => new RelayCommand(p => PortLookupAction(), PortLookup_CanExecute); + public ICommand PortLookupCommand => new RelayCommand(_ => PortLookupAction(), PortLookup_CanExecute); private bool PortLookup_CanExecute(object parameter) => Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen && !PortOrServiceHasError; private async Task PortLookupAction() { - IsLookupRunning = true; + IsRunning = true; PortLookupResults.Clear(); @@ -220,38 +220,38 @@ private async Task PortLookupAction() NoPortsFound = false; } - IsLookupRunning = false; + IsRunning = false; } - public ICommand CopySelectedPortCommand => new RelayCommand(p => CopySelectedPortAction()); + public ICommand CopySelectedPortCommand => new RelayCommand(_ => CopySelectedPortAction()); private void CopySelectedPortAction() { ClipboardHelper.SetClipboard(SelectedPortLookupResult.Number.ToString()); } - public ICommand CopySelectedProtocolCommand => new RelayCommand(p => CopySelectedProtocolAction()); + public ICommand CopySelectedProtocolCommand => new RelayCommand(_ => CopySelectedProtocolAction()); private void CopySelectedProtocolAction() { ClipboardHelper.SetClipboard(SelectedPortLookupResult.Protocol.ToString()); } - public ICommand CopySelectedServiceCommand => new RelayCommand(p => CopySelectedServiceAction()); + public ICommand CopySelectedServiceCommand => new RelayCommand(_ => CopySelectedServiceAction()); private void CopySelectedServiceAction() { ClipboardHelper.SetClipboard(SelectedPortLookupResult.Service); } - public ICommand CopySelectedDescriptionCommand => new RelayCommand(p => CopySelectedDescriptionAction()); + public ICommand CopySelectedDescriptionCommand => new RelayCommand(_ => CopySelectedDescriptionAction()); private void CopySelectedDescriptionAction() { ClipboardHelper.SetClipboard(SelectedPortLookupResult.Description); } - public ICommand ExportCommand => new RelayCommand(p => ExportAction()); + public ICommand ExportCommand => new RelayCommand(_ => ExportAction().ConfigureAwait(false)); private async Task ExportAction() { @@ -278,7 +278,13 @@ private async Task ExportAction() SettingsManager.Current.Lookup_Port_ExportFileType = instance.FileType; SettingsManager.Current.Lookup_Port_ExportFilePath = instance.FilePath; - }, instance => { _dialogCoordinator.HideMetroDialogAsync(this, customDialog); }, new ExportFileType[] { ExportFileType.Csv, ExportFileType.Xml, ExportFileType.Json }, true, SettingsManager.Current.Lookup_Port_ExportFileType, SettingsManager.Current.Lookup_Port_ExportFilePath); + }, _ => + { + _dialogCoordinator.HideMetroDialogAsync(this, customDialog); + }, new[] + { + ExportFileType.Csv, ExportFileType.Xml, ExportFileType.Json + }, true, SettingsManager.Current.Lookup_Port_ExportFileType, SettingsManager.Current.Lookup_Port_ExportFilePath); customDialog.Content = new ExportDialog { diff --git a/Source/NETworkManager/ViewModels/PingMonitorHostViewModel.cs b/Source/NETworkManager/ViewModels/PingMonitorHostViewModel.cs index b144f0c645..f6f38ae96a 100644 --- a/Source/NETworkManager/ViewModels/PingMonitorHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/PingMonitorHostViewModel.cs @@ -25,7 +25,7 @@ public class PingMonitorHostViewModel : ViewModelBase, IProfileManager private readonly IDialogCoordinator _dialogCoordinator; private readonly DispatcherTimer _searchDispatcherTimer = new(); - private readonly bool _isLoading = true; + private readonly bool _isLoading; private bool _isViewActive = true; private string _host; @@ -76,7 +76,7 @@ public bool IsStatusMessageDisplayed public string StatusMessage { get => _statusMessage; - set + private set { if (value == _statusMessage) return; @@ -116,11 +116,12 @@ public PingMonitorView SelectedHost } #region Profiles - public ICollectionView _profiles; + + private ICollectionView _profiles; public ICollectionView Profiles { get => _profiles; - set + private set { if (value == _profiles) return; @@ -227,6 +228,8 @@ public GridLength ProfileWidth #region Constructor, load settings public PingMonitorHostViewModel(IDialogCoordinator instance) { + _isLoading = true; + _dialogCoordinator = instance; // Host history @@ -259,27 +262,21 @@ private void LoadSettings() #endregion #region ICommands & Actions - public ICommand AddHostCommand => new RelayCommand(p => AddHostAction()); + public ICommand AddHostCommand => new RelayCommand(_ => AddHostAction()); private void AddHostAction() { - AddHost(Host); - - // Add the hostname or ip address to the history - AddHostToHistory(Host); - - Host = ""; + AddHost(Host).ConfigureAwait(false); } - public ICommand ExportCommand => new RelayCommand(p => ExportAction()); + public ICommand ExportCommand => new RelayCommand(_ => ExportAction()); private void ExportAction() { - if (SelectedHost != null) - SelectedHost.Export(); + SelectedHost?.Export(); } - public ICommand AddHostProfileCommand => new RelayCommand(p => AddHostProfileAction(), AddHostProfile_CanExecute); + public ICommand AddHostProfileCommand => new RelayCommand(_ => AddHostProfileAction(), AddHostProfile_CanExecute); private bool AddHostProfile_CanExecute(object obj) { @@ -288,47 +285,47 @@ private bool AddHostProfile_CanExecute(object obj) private void AddHostProfileAction() { - AddHost(SelectedProfile.PingMonitor_Host); + AddHost(SelectedProfile.PingMonitor_Host).ConfigureAwait(false); } - public ICommand AddProfileCommand => new RelayCommand(p => AddProfileAction()); + public ICommand AddProfileCommand => new RelayCommand(_ => AddProfileAction()); private void AddProfileAction() { - ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.PingMonitor); + ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.PingMonitor).ConfigureAwait(false); } - private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic; + private bool ModifyProfile_CanExecute(object obj) => SelectedProfile is { IsDynamic: false }; - public ICommand EditProfileCommand => new RelayCommand(p => EditProfileAction(), ModifyProfile_CanExecute); + public ICommand EditProfileCommand => new RelayCommand(_ => EditProfileAction(), ModifyProfile_CanExecute); private void EditProfileAction() { - ProfileDialogManager.ShowEditProfileDialog(this, _dialogCoordinator, SelectedProfile); + ProfileDialogManager.ShowEditProfileDialog(this, _dialogCoordinator, SelectedProfile).ConfigureAwait(false); } - public ICommand CopyAsProfileCommand => new RelayCommand(p => CopyAsProfileAction(), ModifyProfile_CanExecute); + public ICommand CopyAsProfileCommand => new RelayCommand(_ => CopyAsProfileAction(), ModifyProfile_CanExecute); private void CopyAsProfileAction() { - ProfileDialogManager.ShowCopyAsProfileDialog(this, _dialogCoordinator, SelectedProfile); + ProfileDialogManager.ShowCopyAsProfileDialog(this, _dialogCoordinator, SelectedProfile).ConfigureAwait(false); } - public ICommand DeleteProfileCommand => new RelayCommand(p => DeleteProfileAction(), ModifyProfile_CanExecute); + public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute); private void DeleteProfileAction() { - ProfileDialogManager.ShowDeleteProfileDialog(this, _dialogCoordinator, new List { SelectedProfile }); + ProfileDialogManager.ShowDeleteProfileDialog(this, _dialogCoordinator, new List { SelectedProfile }).ConfigureAwait(false); } public ICommand EditGroupCommand => new RelayCommand(EditGroupAction); private void EditGroupAction(object group) { - ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())); + ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())).ConfigureAwait(false); } - public ICommand ClearSearchCommand => new RelayCommand(p => ClearSearchAction()); + public ICommand ClearSearchCommand => new RelayCommand(_ => ClearSearchAction()); private void ClearSearchAction() { @@ -337,19 +334,19 @@ private void ClearSearchAction() #endregion #region Methods - public void AddHost(string hosts) + public async Task AddHost(string hosts) { IsStatusMessageDisplayed = false; StatusMessage = string.Empty; IsRunning = true; - Task.Run(() => + await Task.Run(() => { Parallel.ForEach(hosts.Split(';'), currentHost => { var host = currentHost.Trim(); - string hostname = string.Empty; + var hostname = string.Empty; // Resolve ip address from hostname if (!IPAddress.TryParse(host, out var ipAddress)) @@ -388,9 +385,13 @@ public void AddHost(string hosts) Hosts.Add(new PingMonitorView(Guid.NewGuid(), RemoveHost, new PingMonitorOptions(hostname, ipAddress))); })); }); - + + Host = string.Empty; IsRunning = false; - }); + }).ConfigureAwait(true); + + // Add the hostname or ip address to the history + AddHostToHistory(Host); } private void RemoveHost(Guid hostId) @@ -403,11 +404,11 @@ private void RemoveHost(Guid hostId) index = Hosts.IndexOf(host); } - if (index != -1) - { - Hosts[index].CloseView(); - Hosts.RemoveAt(index); - } + if (index == -1) + return; + + Hosts[index].CloseView(); + Hosts.RemoveAt(index); } private void AddHostToHistory(string host) @@ -495,7 +496,7 @@ private void SetProfilesView(ProfileInfo profile = null) SelectedProfile = Profiles.Cast().FirstOrDefault(); } - public void RefreshProfiles() + private void RefreshProfiles() { if (!_isViewActive) return; diff --git a/Source/NETworkManager/ViewModels/SubnetCalculatorCalculatorViewModel.cs b/Source/NETworkManager/ViewModels/SubnetCalculatorCalculatorViewModel.cs index 7b7e4092c7..c15d342129 100644 --- a/Source/NETworkManager/ViewModels/SubnetCalculatorCalculatorViewModel.cs +++ b/Source/NETworkManager/ViewModels/SubnetCalculatorCalculatorViewModel.cs @@ -30,16 +30,16 @@ public string Subnet public ICollectionView SubnetHistoryView { get; } - private bool _isCalculationRunning; - public bool IsCalculationRunning + private bool _isRunning; + public bool IsRunning { - get => _isCalculationRunning; + get => _isRunning; set { - if (value == _isCalculationRunning) + if (value == _isRunning) return; - _isCalculationRunning = value; + _isRunning = value; OnPropertyChanged(); } } @@ -62,8 +62,8 @@ public bool IsResultVisible private IPNetworkInfo _result; public IPNetworkInfo Result { - get => _result; - set + get => _result; + private set { if(value== _result) return; @@ -82,11 +82,11 @@ public SubnetCalculatorCalculatorViewModel() #endregion #region ICommands - public ICommand CalculateCommand => new RelayCommand(p => CalcualateAction(), Calculate_CanExecute); + public ICommand CalculateCommand => new RelayCommand(_ => CalculateAction(), Calculate_CanExecute); - private bool Calculate_CanExecute(object paramter) => Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen; + private bool Calculate_CanExecute(object parameter) => Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen; - private void CalcualateAction() + private void CalculateAction() { Calculate(); } @@ -95,7 +95,7 @@ private void CalcualateAction() #region Methods private void Calculate() { - IsCalculationRunning = true; + IsRunning = true; var subnet = Subnet.Trim(); @@ -105,7 +105,7 @@ private void Calculate() AddSubnetToHistory(subnet); - IsCalculationRunning = false; + IsRunning = false; } private void AddSubnetToHistory(string subnet) diff --git a/Source/NETworkManager/ViewModels/SubnetCalculatorSubnettingViewModel.cs b/Source/NETworkManager/ViewModels/SubnetCalculatorSubnettingViewModel.cs index 3aa3373a6c..d3e57b4d37 100644 --- a/Source/NETworkManager/ViewModels/SubnetCalculatorSubnettingViewModel.cs +++ b/Source/NETworkManager/ViewModels/SubnetCalculatorSubnettingViewModel.cs @@ -57,16 +57,16 @@ public string NewSubnetmask public ICollectionView NewSubnetmaskHistoryView { get; } - private bool _isCalculationRunning; - public bool IsCalculationRunning + private bool _isRunning; + public bool IsRunning { - get => _isCalculationRunning; + get => _isRunning; set { - if (value == _isCalculationRunning) + if (value == _isRunning) return; - _isCalculationRunning = value; + _isRunning = value; OnPropertyChanged(); } } @@ -147,72 +147,72 @@ public SubnetCalculatorSubnettingViewModel(IDialogCoordinator instance) #endregion #region ICommands & Actions - public ICommand CalculateCommand => new RelayCommand(p => CalculateAction(), Calculate_CanExecute); + public ICommand CalculateCommand => new RelayCommand(_ => CalculateAction(), Calculate_CanExecute); - private bool Calculate_CanExecute(object paramter) => Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen; + private bool Calculate_CanExecute(object parameter) => Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen; private void CalculateAction() { - Calculate(); + Calculate().ConfigureAwait(false); } - public ICommand CopySelectedNetworkAddressCommand => new RelayCommand(p => CopySelectedNetworkAddressAction()); + public ICommand CopySelectedNetworkAddressCommand => new RelayCommand(_ => CopySelectedNetworkAddressAction()); private void CopySelectedNetworkAddressAction() { ClipboardHelper.SetClipboard(SelectedSubnetResult.Network.ToString()); } - public ICommand CopySelectedBroadcastCommand => new RelayCommand(p => CopySelectedBroadcastAction()); + public ICommand CopySelectedBroadcastCommand => new RelayCommand(_ => CopySelectedBroadcastAction()); private void CopySelectedBroadcastAction() { ClipboardHelper.SetClipboard(SelectedSubnetResult.Broadcast.ToString()); } - public ICommand CopySelectedIPAddressesCommand => new RelayCommand(p => CopySelectedIPAddressesAction()); + public ICommand CopySelectedIPAddressesCommand => new RelayCommand(_ => CopySelectedIPAddressesAction()); private void CopySelectedIPAddressesAction() { ClipboardHelper.SetClipboard(SelectedSubnetResult.Total.ToString()); } - public ICommand CopySelectedSubnetmaskCommand => new RelayCommand(p => CopySelectedSubnetmaskAction()); + public ICommand CopySelectedSubnetmaskCommand => new RelayCommand(_ => CopySelectedSubnetmaskAction()); private void CopySelectedSubnetmaskAction() { ClipboardHelper.SetClipboard(SelectedSubnetResult.Netmask.ToString()); } - public ICommand CopySelectedCIDRCommand => new RelayCommand(p => CopySelectedCIDRAction()); + public ICommand CopySelectedCidrCommand => new RelayCommand(_ => CopySelectedCidrAction()); - private void CopySelectedCIDRAction() + private void CopySelectedCidrAction() { ClipboardHelper.SetClipboard(SelectedSubnetResult.Cidr.ToString()); } - public ICommand CopySelectedFirstIPAddressCommand => new RelayCommand(p => CopySelectedFirstIPAddressAction()); + public ICommand CopySelectedFirstIPAddressCommand => new RelayCommand(_ => CopySelectedFirstIPAddressAction()); private void CopySelectedFirstIPAddressAction() { ClipboardHelper.SetClipboard(SelectedSubnetResult.FirstUsable.ToString()); } - public ICommand CopySelectedLastIPAddressCommand => new RelayCommand(p => CopySelectedLastIPAddressAction()); + public ICommand CopySelectedLastIPAddressCommand => new RelayCommand(_ => CopySelectedLastIPAddressAction()); private void CopySelectedLastIPAddressAction() { ClipboardHelper.SetClipboard(SelectedSubnetResult.LastUsable.ToString()); } - public ICommand CopySelectedHostCommand => new RelayCommand(p => CopySelectedHostAction()); + public ICommand CopySelectedHostCommand => new RelayCommand(_ => CopySelectedHostAction()); private void CopySelectedHostAction() { ClipboardHelper.SetClipboard(SelectedSubnetResult.Usable.ToString()); } - public ICommand ExportCommand => new RelayCommand(p => ExportAction()); + public ICommand ExportCommand => new RelayCommand(_ => ExportAction().ConfigureAwait(false)); private async Task ExportAction() { @@ -239,7 +239,13 @@ private async Task ExportAction() SettingsManager.Current.SubnetCalculator_Subnetting_ExportFileType = instance.FileType; SettingsManager.Current.SubnetCalculator_Subnetting_ExportFilePath = instance.FilePath; - }, instance => { _dialogCoordinator.HideMetroDialogAsync(this, customDialog); }, new ExportFileType[] { ExportFileType.Csv, ExportFileType.Xml, ExportFileType.Json }, true, SettingsManager.Current.SubnetCalculator_Subnetting_ExportFileType, SettingsManager.Current.SubnetCalculator_Subnetting_ExportFilePath); + }, _ => + { + _dialogCoordinator.HideMetroDialogAsync(this, customDialog); + }, new[] + { + ExportFileType.Csv, ExportFileType.Xml, ExportFileType.Json + }, true, SettingsManager.Current.SubnetCalculator_Subnetting_ExportFileType, SettingsManager.Current.SubnetCalculator_Subnetting_ExportFilePath); customDialog.Content = new ExportDialog { @@ -253,7 +259,7 @@ private async Task ExportAction() #region Methods private async Task Calculate() { - IsCalculationRunning = true; + IsRunning = true; SubnetsResult.Clear(); @@ -262,13 +268,11 @@ private async Task Calculate() var ipNetwork = IPNetwork.Parse(Subnet.Trim()); - byte newCidr = 0; - - // Support subnetmask like 255.255.255.0 - if (Regex.IsMatch(newSubnetmaskOrCidr, RegexHelper.SubnetmaskRegex)) - newCidr = Convert.ToByte(Subnetmask.ConvertSubnetmaskToCidr(IPAddress.Parse(newSubnetmaskOrCidr))); - else - newCidr = Convert.ToByte(newSubnetmaskOrCidr.TrimStart('/')); + var newCidr = + // Support subnetmask like 255.255.255.0 + Regex.IsMatch(newSubnetmaskOrCidr, RegexHelper.SubnetmaskRegex) ? + Convert.ToByte(Subnetmask.ConvertSubnetmaskToCidr(IPAddress.Parse(newSubnetmaskOrCidr))) : + Convert.ToByte(newSubnetmaskOrCidr.TrimStart('/')); // Ask the user if there is a large calculation... var baseCidr = ipNetwork.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork ? 32 : 128; @@ -284,7 +288,7 @@ private async Task Calculate() if (await _dialogCoordinator.ShowMessageAsync(this, Localization.Resources.Strings.AreYouSure, Localization.Resources.Strings.TheProcessCanTakeUpSomeTimeAndResources, MessageDialogStyle.AffirmativeAndNegative, settings) != MessageDialogResult.Affirmative) { - IsCalculationRunning = false; + IsRunning = false; return; } @@ -305,9 +309,9 @@ await Task.Run(() => IsResultVisible = true; AddSubnetToHistory(subnet); - AddNewSubnetmaskOrCIDRToHistory(newSubnetmaskOrCidr); + AddNewSubnetmaskOrCidrToHistory(newSubnetmaskOrCidr); - IsCalculationRunning = false; + IsRunning = false; } private void AddSubnetToHistory(string subnet) @@ -323,10 +327,10 @@ private void AddSubnetToHistory(string subnet) list.ForEach(x => SettingsManager.Current.SubnetCalculator_Subnetting_SubnetHistory.Add(x)); } - private void AddNewSubnetmaskOrCIDRToHistory(string newSubnetmaskOrCIDR) + private void AddNewSubnetmaskOrCidrToHistory(string newSubnetmaskOrCidr) { // Create the new list - var list = ListHelper.Modify(SettingsManager.Current.SubnetCalculator_Subnetting_NewSubnetmaskHistory.ToList(), newSubnetmaskOrCIDR, SettingsManager.Current.General_HistoryListEntries); + var list = ListHelper.Modify(SettingsManager.Current.SubnetCalculator_Subnetting_NewSubnetmaskHistory.ToList(), newSubnetmaskOrCidr, SettingsManager.Current.General_HistoryListEntries); // Clear the old items SettingsManager.Current.SubnetCalculator_Subnetting_NewSubnetmaskHistory.Clear(); diff --git a/Source/NETworkManager/ViewModels/SubnetCalculatorWideSubnetViewModel.cs b/Source/NETworkManager/ViewModels/SubnetCalculatorWideSubnetViewModel.cs index 2f3c5ee75c..7d7ea5d7aa 100644 --- a/Source/NETworkManager/ViewModels/SubnetCalculatorWideSubnetViewModel.cs +++ b/Source/NETworkManager/ViewModels/SubnetCalculatorWideSubnetViewModel.cs @@ -15,8 +15,6 @@ namespace NETworkManager.ViewModels; public class SubnetCalculatorWideSubnetViewModel : ViewModelBase { #region Variables - private readonly IDialogCoordinator _dialogCoordinator; - private string _subnet1; public string Subnet1 { @@ -49,16 +47,16 @@ public string Subnet2 public ICollectionView Subnet2HistoryView { get; } - private bool _isCalculationRunning; - public bool IsCalculationRunning + private bool _isRunning; + public bool IsRunning { - get => _isCalculationRunning; + get => _isRunning; set { - if (value == _isCalculationRunning) + if (value == _isRunning) return; - _isCalculationRunning = value; + _isRunning = value; OnPropertyChanged(); } } @@ -82,7 +80,7 @@ public bool IsResultVisible public IPNetworkInfo Result { get => _result; - set + private set { if (value == _result) return; @@ -94,10 +92,8 @@ public IPNetworkInfo Result #endregion #region Constructor, load settings - public SubnetCalculatorWideSubnetViewModel(IDialogCoordinator instance) + public SubnetCalculatorWideSubnetViewModel() { - _dialogCoordinator = instance; - // Set collection view Subnet1HistoryView = CollectionViewSource.GetDefaultView(SettingsManager.Current.SubnetCalculator_WideSubnet_Subnet1); Subnet2HistoryView = CollectionViewSource.GetDefaultView(SettingsManager.Current.SubnetCalculator_WideSubnet_Subnet2); @@ -105,9 +101,9 @@ public SubnetCalculatorWideSubnetViewModel(IDialogCoordinator instance) #endregion #region ICommands & Actions - public ICommand CalculateCommand => new RelayCommand(p => CalculateAction(), Calculate_CanExecute); + public ICommand CalculateCommand => new RelayCommand(_ => CalculateAction(), Calculate_CanExecute); - private bool Calculate_CanExecute(object paramter) => Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen; + private bool Calculate_CanExecute(object parameter) => Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen; private void CalculateAction() { @@ -118,7 +114,7 @@ private void CalculateAction() #region Methods private void Calculate() { - IsCalculationRunning = true; + IsRunning = true; var subnet1 = Subnet1.Trim(); var subnet2 = Subnet2.Trim(); @@ -133,7 +129,7 @@ private void Calculate() AddSubnet1ToHistory(subnet1); AddSubnet2ToHistory(subnet2); - IsCalculationRunning = false; + IsRunning = false; } private void AddSubnet1ToHistory(string subnet) diff --git a/Source/NETworkManager/ViewModels/WakeOnLANViewModel.cs b/Source/NETworkManager/ViewModels/WakeOnLANViewModel.cs index 42f50edbcc..a76ad7faf8 100644 --- a/Source/NETworkManager/ViewModels/WakeOnLANViewModel.cs +++ b/Source/NETworkManager/ViewModels/WakeOnLANViewModel.cs @@ -25,19 +25,19 @@ public class WakeOnLANViewModel : ViewModelBase, IProfileManager private readonly IDialogCoordinator _dialogCoordinator; private readonly DispatcherTimer _searchDispatcherTimer = new(); - private readonly bool _isLoading = true; + private readonly bool _isLoading; private bool _isViewActive = true; - private bool _isSending; - public bool IsSending + private bool _isRunning; + public bool IsRunning { - get => _isSending; + get => _isRunning; set { - if (value == _isSending) + if (value == _isRunning) return; - _isSending = value; + _isRunning = value; OnPropertyChanged(); } } @@ -91,7 +91,7 @@ public bool IsStatusMessageDisplayed public string StatusMessage { get => _statusMessage; - set + private set { if (value == _statusMessage) return; @@ -102,11 +102,12 @@ public string StatusMessage } #region Profiles - public ICollectionView _profiles; + + private ICollectionView _profiles; public ICollectionView Profiles { get => _profiles; - set + private set { if (value == _profiles) return; @@ -125,7 +126,7 @@ public ProfileInfo SelectedProfile if (value == _selectedProfile) return; - if (value != null && !IsSending) + if (value != null && !IsRunning) { MACAddress = value.WakeOnLAN_MACAddress; Broadcast = value.WakeOnLAN_Broadcast; @@ -219,6 +220,8 @@ public GridLength ProfileWidth #region Constructor, load settings public WakeOnLANViewModel(IDialogCoordinator instance) { + _isLoading = true; + _dialogCoordinator = instance; MACAddressHistoryView = CollectionViewSource.GetDefaultView(SettingsManager.Current.WakeOnLan_MACAddressHistory); @@ -248,7 +251,7 @@ private void LoadSettings() #endregion #region ICommands & Actions - public ICommand WakeUpCommand => new RelayCommand(p => WakeUpAction(), WakeUpAction_CanExecute); + public ICommand WakeUpCommand => new RelayCommand(_ => WakeUpAction(), WakeUpAction_CanExecute); private bool WakeUpAction_CanExecute(object parameter) => Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen; @@ -264,54 +267,54 @@ private void WakeUpAction() AddMACAddressToHistory(MACAddress); AddBroadcastToHistory(Broadcast); - WakeUp(info); + WakeUp(info).ConfigureAwait(false); } - public ICommand WakeUpProfileCommand => new RelayCommand(p => WakeUpProfileAction()); + public ICommand WakeUpProfileCommand => new RelayCommand(_ => WakeUpProfileAction()); private void WakeUpProfileAction() { - WakeUp(NETworkManager.Profiles.Application.WakeOnLAN.CreateInfo(SelectedProfile)); + WakeUp(NETworkManager.Profiles.Application.WakeOnLAN.CreateInfo(SelectedProfile)).ConfigureAwait(false); } - public ICommand AddProfileCommand => new RelayCommand(p => AddProfileAction()); + public ICommand AddProfileCommand => new RelayCommand(_ => AddProfileAction()); private void AddProfileAction() { - ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.WakeOnLAN); + ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.WakeOnLAN).ConfigureAwait(false); } - private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic; + private bool ModifyProfile_CanExecute(object obj) => SelectedProfile is { IsDynamic: false }; - public ICommand EditProfileCommand => new RelayCommand(p => EditProfileAction(), ModifyProfile_CanExecute); + public ICommand EditProfileCommand => new RelayCommand(_ => EditProfileAction(), ModifyProfile_CanExecute); private void EditProfileAction() { - ProfileDialogManager.ShowEditProfileDialog(this, _dialogCoordinator, SelectedProfile); + ProfileDialogManager.ShowEditProfileDialog(this, _dialogCoordinator, SelectedProfile).ConfigureAwait(false); } - public ICommand CopyAsProfileCommand => new RelayCommand(p => CopyAsProfileAction(), ModifyProfile_CanExecute); + public ICommand CopyAsProfileCommand => new RelayCommand(_ => CopyAsProfileAction(), ModifyProfile_CanExecute); private void CopyAsProfileAction() { - ProfileDialogManager.ShowCopyAsProfileDialog(this, _dialogCoordinator, SelectedProfile); + ProfileDialogManager.ShowCopyAsProfileDialog(this, _dialogCoordinator, SelectedProfile).ConfigureAwait(false); } - public ICommand DeleteProfileCommand => new RelayCommand(p => DeleteProfileAction(), ModifyProfile_CanExecute); + public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute); private void DeleteProfileAction() { - ProfileDialogManager.ShowDeleteProfileDialog(this, _dialogCoordinator, new List { SelectedProfile }); + ProfileDialogManager.ShowDeleteProfileDialog(this, _dialogCoordinator, new List { SelectedProfile }).ConfigureAwait(false); } public ICommand EditGroupCommand => new RelayCommand(EditGroupAction); private void EditGroupAction(object group) { - ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())); + ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())).ConfigureAwait(false); } - public ICommand ClearSearchCommand => new RelayCommand(p => ClearSearchAction()); + public ICommand ClearSearchCommand => new RelayCommand(_ => ClearSearchAction()); private void ClearSearchAction() { @@ -323,7 +326,7 @@ private void ClearSearchAction() private async Task WakeUp(WakeOnLANInfo info) { IsStatusMessageDisplayed = false; - IsSending = true; + IsRunning = true; try { @@ -341,9 +344,7 @@ private async Task WakeUp(WakeOnLANInfo info) IsStatusMessageDisplayed = true; } - - - IsSending = false; + IsRunning = false; } private void AddMACAddressToHistory(string macAddress) @@ -444,7 +445,7 @@ private void SetProfilesView(ProfileInfo profile = null) SelectedProfile = Profiles.Cast().FirstOrDefault(); } - public void RefreshProfiles() + private void RefreshProfiles() { if (!_isViewActive) return; diff --git a/Source/NETworkManager/ViewModels/WhoisViewModel.cs b/Source/NETworkManager/ViewModels/WhoisViewModel.cs index d6329d2451..b279b5a6f4 100644 --- a/Source/NETworkManager/ViewModels/WhoisViewModel.cs +++ b/Source/NETworkManager/ViewModels/WhoisViewModel.cs @@ -26,8 +26,6 @@ public class WhoisViewModel : ViewModelBase private readonly int _tabId; private bool _firstLoad = true; - private readonly bool _isLoading; - private string _domain; public string Domain { @@ -44,16 +42,16 @@ public string Domain public ICollectionView WebsiteUriHistoryView { get; } - private bool _isWhoisRunning; - public bool IsWhoisRunning + private bool _isRunning; + public bool IsRunning { - get => _isWhoisRunning; + get => _isRunning; set { - if (value == _isWhoisRunning) + if (value == _isRunning) return; - _isWhoisRunning = value; + _isRunning = value; OnPropertyChanged(); } } @@ -90,7 +88,7 @@ public bool IsStatusMessageDisplayed public string StatusMessage { get => _statusMessage; - set + private set { if (value == _statusMessage) return; @@ -104,8 +102,6 @@ public string StatusMessage #region Contructor, load settings public WhoisViewModel(IDialogCoordinator instance ,int tabId, string domain) { - _isLoading = true; - _dialogCoordinator = instance; _tabId = tabId; @@ -115,8 +111,6 @@ public WhoisViewModel(IDialogCoordinator instance ,int tabId, string domain) WebsiteUriHistoryView = CollectionViewSource.GetDefaultView(SettingsManager.Current.Whois_DomainHistory); LoadSettings(); - - _isLoading = false; } public void OnLoaded() @@ -125,7 +119,7 @@ public void OnLoaded() return; if (!string.IsNullOrEmpty(Domain)) - Query(); + Query().ConfigureAwait(false); _firstLoad = false; } @@ -137,16 +131,16 @@ private void LoadSettings() #endregion #region ICommands & Actions - public ICommand QueryCommand => new RelayCommand(p => QueryAction(), Query_CanExecute); + public ICommand QueryCommand => new RelayCommand(_ => QueryAction(), Query_CanExecute); - private bool Query_CanExecute(object paramter) => Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen; + private bool Query_CanExecute(object parameter) => Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen; private void QueryAction() { - Query(); + Query().ConfigureAwait(false); } - public ICommand ExportCommand => new RelayCommand(p => ExportAction()); + public ICommand ExportCommand => new RelayCommand(_ => ExportAction().ConfigureAwait(false)); private async Task ExportAction() { @@ -173,7 +167,13 @@ private async Task ExportAction() SettingsManager.Current.Whois_ExportFileType = instance.FileType; SettingsManager.Current.Whois_ExportFilePath = instance.FilePath; - }, instance => { _dialogCoordinator.HideMetroDialogAsync(this, customDialog); }, new ExportFileType[] { ExportFileType.Txt}, false, SettingsManager.Current.Whois_ExportFileType, SettingsManager.Current.Whois_ExportFilePath); + }, _ => + { + _dialogCoordinator.HideMetroDialogAsync(this, customDialog); + }, new[] + { + ExportFileType.Txt + }, false, SettingsManager.Current.Whois_ExportFileType, SettingsManager.Current.Whois_ExportFilePath); customDialog.Content = new ExportDialog { @@ -188,7 +188,7 @@ private async Task ExportAction() private async Task Query() { IsStatusMessageDisplayed = false; - IsWhoisRunning = true; + IsRunning = true; WhoisResult = null; @@ -225,7 +225,7 @@ private async Task Query() IsStatusMessageDisplayed = true; } - IsWhoisRunning = false; + IsRunning = false; } public void OnClose() diff --git a/Source/NETworkManager/Views/BitCalculatorView.xaml b/Source/NETworkManager/Views/BitCalculatorView.xaml index 437adb71ef..897941860a 100644 --- a/Source/NETworkManager/Views/BitCalculatorView.xaml +++ b/Source/NETworkManager/Views/BitCalculatorView.xaml @@ -8,17 +8,15 @@ xmlns:mahAppsControls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" xmlns:validators="clr-namespace:NETworkManager.Validators;assembly=NETworkManager.Validators" xmlns:converters="clr-namespace:NETworkManager.Converters;assembly=NETworkManager.Converters" - xmlns:dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro" xmlns:viewModels="clr-namespace:NETworkManager.ViewModels" xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization" - dialogs:DialogParticipation.Register="{Binding}" mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:BitCalculatorViewModel}"> - + @@ -45,7 +43,12 @@ - + @@ -57,7 +60,7 @@ -