From b42aae41eba3831a1c154113bcc1325fa98ce953 Mon Sep 17 00:00:00 2001
From: BornToBeRoot <16019165+BornToBeRoot@users.noreply.github.com>
Date: Mon, 6 Mar 2023 20:16:31 +0100
Subject: [PATCH 01/11] Chore: Use .NET 7 syntax
---
.../BaudValidator.cs | 37 +++---
.../ContainsTextValidator.cs | 11 +-
...ryPathWithEnvironmentVariablesValidator.cs | 25 ++--
.../DomainValidator.cs | 11 +-
.../EmptyOrAWSRegionExistsValidator.cs | 24 ++--
.../EmptyOrFileExistsValidator.cs | 15 ++-
.../EmptyOrIPv4AddressValidator.cs | 15 ++-
.../EmptyOrPortRangeValidator.cs | 61 +++++----
.../EmptyValidator.cs | 11 +-
.../FileExistsValidator.cs | 11 +-
.../FileNameValidator.cs | 29 +++--
.../FilePathValidator.cs | 23 ++--
.../FolderInPathExistsValidator.cs | 33 +++--
.../GroupNameValidator.cs | 17 ++-
.../HttpAndHttpsUriValidator.cs | 11 +-
.../IPAddressOrHostnameAsRangeValidator.cs | 39 +++---
.../IPAddressOrHostnameValidator.cs | 35 +++---
.../IPv4AddressValidator.cs | 17 ++-
.../IPv4IPv6SubnetValidator.cs | 36 +++---
.../IPv4IPv6SubnetmaskOrCIDRValidator.cs | 39 +++---
.../IPv4SubnetValidator.cs | 25 ++--
.../IPv4SubnetmaskOrCIDRValidator.cs | 31 +++--
.../IPv6AddressValidator.cs | 19 ++-
.../Int32Validator.cs | 11 +-
.../NETworkManager.Validators/IsNameUnique.cs | 17 ++-
.../IsNameUniqueDependencyObjectWrapper.cs | 21 ++--
.../MACAddressValidator.cs | 11 +-
.../MultipleHostsRangeValidator.cs | 117 +++++++++---------
.../MultipleIPAddressesValidator.cs | 27 ++--
.../NoSpacesValidator.cs | 15 ++-
.../NotEndWithSemicolonValidator.cs | 11 +-
.../NumberValidator.cs | 11 +-
.../NETworkManager.Validators/OIDValidator.cs | 27 ++--
.../PortRangeValidator.cs | 57 +++++----
.../PortValidator.cs | 19 ++-
.../PowerShellPathValidator.cs | 15 ++-
.../ProfileFileUniqueValidator.cs | 11 +-
.../PuTTYPathValidator.cs | 15 ++-
.../RemoteDesktopHostnameAndPortValidator.cs | 33 +++--
.../ServerDependencyObjectWrapper.cs | 21 ++--
.../ServerValidator.cs | 43 ++++---
.../SubnetmaskValidator.cs | 11 +-
.../TigerVNCPathValidator.cs | 21 ++--
43 files changed, 524 insertions(+), 565 deletions(-)
diff --git a/Source/NETworkManager.Validators/BaudValidator.cs b/Source/NETworkManager.Validators/BaudValidator.cs
index ae83515ca0..46b400b444 100644
--- a/Source/NETworkManager.Validators/BaudValidator.cs
+++ b/Source/NETworkManager.Validators/BaudValidator.cs
@@ -2,27 +2,26 @@
using System.Linq;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class BaudValidator : ValidationRule
{
- public class BaudValidator : ValidationRule
- {
- ///
- /// Possible baud rates.
- ///
- private readonly int[] _bauds = { 75, 300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200 };
+ ///
+ /// Possible baud rates.
+ ///
+ private readonly int[] _bauds = { 75, 300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200 };
- ///
- /// Check if the int is a valid baud rate.
- ///
- /// Baud like 9600.
- /// Culture to use for validation.
- /// True if the value is a valid baut rate.
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- if (!int.TryParse(value as string, out var baud))
- return new ValidationResult(false, Localization.Resources.Strings.EnterValidBaud);
+ ///
+ /// Check if the int is a valid baud rate.
+ ///
+ /// Baud like 9600.
+ /// Culture to use for validation.
+ /// True if the value is a valid baut rate.
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
+ {
+ if (!int.TryParse(value as string, out var baud))
+ return new ValidationResult(false, Localization.Resources.Strings.EnterValidBaud);
- return _bauds.Contains(baud) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidBaud);
- }
+ return _bauds.Contains(baud) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidBaud);
}
}
\ No newline at end of file
diff --git a/Source/NETworkManager.Validators/ContainsTextValidator.cs b/Source/NETworkManager.Validators/ContainsTextValidator.cs
index d9f30bc7f7..8e8f9b381c 100644
--- a/Source/NETworkManager.Validators/ContainsTextValidator.cs
+++ b/Source/NETworkManager.Validators/ContainsTextValidator.cs
@@ -3,13 +3,12 @@
using System.Windows.Controls;
using NETworkManager.Localization.Resources;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class ContainsTextValidator : ValidationRule
{
- public class ContainsTextValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- return ((string)value).All(char.IsWhiteSpace) ? new ValidationResult(false, Strings.InputDoesNotContainAnyText) : ValidationResult.ValidResult;
- }
+ return ((string)value).All(char.IsWhiteSpace) ? new ValidationResult(false, Strings.InputDoesNotContainAnyText) : ValidationResult.ValidResult;
}
}
diff --git a/Source/NETworkManager.Validators/DirectoryPathWithEnvironmentVariablesValidator.cs b/Source/NETworkManager.Validators/DirectoryPathWithEnvironmentVariablesValidator.cs
index b04bc999e7..abc56340a0 100644
--- a/Source/NETworkManager.Validators/DirectoryPathWithEnvironmentVariablesValidator.cs
+++ b/Source/NETworkManager.Validators/DirectoryPathWithEnvironmentVariablesValidator.cs
@@ -5,24 +5,23 @@
using NETworkManager.Utilities;
using System;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+///
+/// Check if the string is a valid directory path (like "C:\Temp\" or "%AppData%\Temp"). The directory path does not have to exist on the local system.
+///
+public class DirectoryPathWithEnvironmentVariablesValidator : ValidationRule
{
///
/// Check if the string is a valid directory path (like "C:\Temp\" or "%AppData%\Temp"). The directory path does not have to exist on the local system.
///
- public class DirectoryPathWithEnvironmentVariablesValidator : ValidationRule
+ /// Directory path like "C:\test" or "%AppData%\test".
+ /// Culture to use for validation.
+ /// True if the directory path is valid.
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- ///
- /// Check if the string is a valid directory path (like "C:\Temp\" or "%AppData%\Temp"). The directory path does not have to exist on the local system.
- ///
- /// Directory path like "C:\test" or "%AppData%\test".
- /// Culture to use for validation.
- /// True if the directory path is valid.
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- var path = Environment.ExpandEnvironmentVariables((string)value);
+ var path = Environment.ExpandEnvironmentVariables((string)value);
- return new Regex(RegexHelper.FilePathRegex, RegexOptions.IgnoreCase).IsMatch(path) ? ValidationResult.ValidResult : new ValidationResult(false, Strings.EnterValidFilePath);
- }
+ return new Regex(RegexHelper.FilePathRegex, RegexOptions.IgnoreCase).IsMatch(path) ? ValidationResult.ValidResult : new ValidationResult(false, Strings.EnterValidFilePath);
}
}
\ No newline at end of file
diff --git a/Source/NETworkManager.Validators/DomainValidator.cs b/Source/NETworkManager.Validators/DomainValidator.cs
index 4bee9747b0..2e8ef5d6e6 100644
--- a/Source/NETworkManager.Validators/DomainValidator.cs
+++ b/Source/NETworkManager.Validators/DomainValidator.cs
@@ -4,13 +4,12 @@
using NETworkManager.Localization.Resources;
using NETworkManager.Utilities;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class DomainValidator : ValidationRule
{
- public class DomainValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- return Regex.IsMatch((string) value, RegexHelper.DomainRegex) ? ValidationResult.ValidResult : new ValidationResult(false,Strings.EnterValidDomain);
- }
+ return Regex.IsMatch((string) value, RegexHelper.DomainRegex) ? ValidationResult.ValidResult : new ValidationResult(false,Strings.EnterValidDomain);
}
}
diff --git a/Source/NETworkManager.Validators/EmptyOrAWSRegionExistsValidator.cs b/Source/NETworkManager.Validators/EmptyOrAWSRegionExistsValidator.cs
index a0e5c65218..df175bdd4f 100644
--- a/Source/NETworkManager.Validators/EmptyOrAWSRegionExistsValidator.cs
+++ b/Source/NETworkManager.Validators/EmptyOrAWSRegionExistsValidator.cs
@@ -2,21 +2,21 @@
using System.Globalization;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+namespace NETworkManager.Validators;
+
+public class EmptyOrAWSRegionExistsValidator : ValidationRule
{
- public class EmptyOrAWSRegionExistsValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- var region = value as string;
+ var region = value as string;
- if (string.IsNullOrEmpty(region))
- return ValidationResult.ValidResult;
-
- if (AWSRegion.GetInstance().RegionExists(region))
- return ValidationResult.ValidResult;
+ if (string.IsNullOrEmpty(region))
+ return ValidationResult.ValidResult;
+
+ if (AWSRegion.GetInstance().RegionExists(region))
+ return ValidationResult.ValidResult;
- return new ValidationResult(false, string.Format(Localization.Resources.Strings.AnAWSRegionNamedXDoesNotExist, region));
- }
+ return new ValidationResult(false, string.Format(Localization.Resources.Strings.AnAWSRegionNamedXDoesNotExist, region));
}
}
diff --git a/Source/NETworkManager.Validators/EmptyOrFileExistsValidator.cs b/Source/NETworkManager.Validators/EmptyOrFileExistsValidator.cs
index 1c043ef3b5..71c5900faa 100644
--- a/Source/NETworkManager.Validators/EmptyOrFileExistsValidator.cs
+++ b/Source/NETworkManager.Validators/EmptyOrFileExistsValidator.cs
@@ -2,16 +2,15 @@
using System.IO;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class EmptyOrFileExistsValidator : ValidationRule
{
- public class EmptyOrFileExistsValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- if (string.IsNullOrEmpty(value as string))
- return ValidationResult.ValidResult;
+ if (string.IsNullOrEmpty(value as string))
+ return ValidationResult.ValidResult;
- return File.Exists((string)value) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.FileDoesNotExist);
- }
+ return File.Exists((string)value) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.FileDoesNotExist);
}
}
\ No newline at end of file
diff --git a/Source/NETworkManager.Validators/EmptyOrIPv4AddressValidator.cs b/Source/NETworkManager.Validators/EmptyOrIPv4AddressValidator.cs
index 9a02dbe4e5..434c0819e4 100644
--- a/Source/NETworkManager.Validators/EmptyOrIPv4AddressValidator.cs
+++ b/Source/NETworkManager.Validators/EmptyOrIPv4AddressValidator.cs
@@ -3,16 +3,15 @@
using System.Text.RegularExpressions;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class EmptyOrIPv4AddressValidator : ValidationRule
{
- public class EmptyOrIPv4AddressValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- if (string.IsNullOrEmpty(value as string))
- return ValidationResult.ValidResult;
+ if (string.IsNullOrEmpty(value as string))
+ return ValidationResult.ValidResult;
- return Regex.IsMatch((string)value, RegexHelper.IPv4AddressRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidIPv4Address);
- }
+ return Regex.IsMatch((string)value, RegexHelper.IPv4AddressRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidIPv4Address);
}
}
diff --git a/Source/NETworkManager.Validators/EmptyOrPortRangeValidator.cs b/Source/NETworkManager.Validators/EmptyOrPortRangeValidator.cs
index 8b14275a69..a07b786d66 100644
--- a/Source/NETworkManager.Validators/EmptyOrPortRangeValidator.cs
+++ b/Source/NETworkManager.Validators/EmptyOrPortRangeValidator.cs
@@ -1,51 +1,50 @@
using System.Globalization;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class EmptyOrPortRangeValidator : ValidationRule
{
- public class EmptyOrPortRangeValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- if (string.IsNullOrEmpty(value as string))
- return ValidationResult.ValidResult;
+ if (string.IsNullOrEmpty(value as string))
+ return ValidationResult.ValidResult;
- var isValid = true;
+ var isValid = true;
- if (value == null)
- return new ValidationResult(false, Localization.Resources.Strings.EnterValidPortOrPortRange);
+ if (value == null)
+ return new ValidationResult(false, Localization.Resources.Strings.EnterValidPortOrPortRange);
- foreach (var portOrRange in ((string)value).Replace(" ", "").Split(';'))
+ foreach (var portOrRange in ((string)value).Replace(" ", "").Split(';'))
+ {
+ if (portOrRange.Contains('-'))
{
- if (portOrRange.Contains('-'))
- {
- var portRange = portOrRange.Split('-');
+ var portRange = portOrRange.Split('-');
- if (int.TryParse(portRange[0], out var startPort) && int.TryParse(portRange[1], out var endPort))
- {
- if (!((startPort > 0) && (startPort < 65536) && (endPort > 0) && (endPort < 65536) && (startPort < endPort)))
- isValid = false;
- }
- else
- {
+ if (int.TryParse(portRange[0], out var startPort) && int.TryParse(portRange[1], out var endPort))
+ {
+ if (!((startPort > 0) && (startPort < 65536) && (endPort > 0) && (endPort < 65536) && (startPort < endPort)))
isValid = false;
- }
}
else
{
- if (int.TryParse(portOrRange, out var portNumber))
- {
- if (!((portNumber > 0) && (portNumber < 65536)))
- isValid = false;
- }
- else
- {
+ isValid = false;
+ }
+ }
+ else
+ {
+ if (int.TryParse(portOrRange, out var portNumber))
+ {
+ if (!((portNumber > 0) && (portNumber < 65536)))
isValid = false;
- }
+ }
+ else
+ {
+ isValid = false;
}
}
-
- return isValid ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidPortOrPortRange);
}
+
+ return isValid ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidPortOrPortRange);
}
}
\ No newline at end of file
diff --git a/Source/NETworkManager.Validators/EmptyValidator.cs b/Source/NETworkManager.Validators/EmptyValidator.cs
index f3fa89a0db..2ef2591de8 100644
--- a/Source/NETworkManager.Validators/EmptyValidator.cs
+++ b/Source/NETworkManager.Validators/EmptyValidator.cs
@@ -1,13 +1,12 @@
using System.Globalization;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class EmptyValidator : ValidationRule
{
- public class EmptyValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- return string.IsNullOrEmpty((string)value) ? new ValidationResult(false, Localization.Resources.Strings.FieldCannotBeEmpty) : ValidationResult.ValidResult;
- }
+ return string.IsNullOrEmpty((string)value) ? new ValidationResult(false, Localization.Resources.Strings.FieldCannotBeEmpty) : ValidationResult.ValidResult;
}
}
diff --git a/Source/NETworkManager.Validators/FileExistsValidator.cs b/Source/NETworkManager.Validators/FileExistsValidator.cs
index 4ae9a14618..f875e1aa80 100644
--- a/Source/NETworkManager.Validators/FileExistsValidator.cs
+++ b/Source/NETworkManager.Validators/FileExistsValidator.cs
@@ -2,13 +2,12 @@
using System.IO;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class FileExistsValidator : ValidationRule
{
- public class FileExistsValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- return File.Exists((string)value) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.FileDoesNotExist);
- }
+ return File.Exists((string)value) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.FileDoesNotExist);
}
}
diff --git a/Source/NETworkManager.Validators/FileNameValidator.cs b/Source/NETworkManager.Validators/FileNameValidator.cs
index 5a5888c66b..683cb4631d 100644
--- a/Source/NETworkManager.Validators/FileNameValidator.cs
+++ b/Source/NETworkManager.Validators/FileNameValidator.cs
@@ -4,25 +4,24 @@
using System.Windows.Controls;
using NETworkManager.Localization.Resources;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+///
+/// Check if the filename is a valid file name (like "text.txt"). The file name does not have to exist on the local system.
+///
+public class FileNameValidator : ValidationRule
{
///
- /// Check if the filename is a valid file name (like "text.txt"). The file name does not have to exist on the local system.
+ /// Check if the filename is a valid file name (like "text.txt"). The filen ame does not have to exist on the local system.
///
- public class FileNameValidator : ValidationRule
+ /// File name like "test.txt" or "README.md".
+ /// Culture to use for validation.
+ /// True if the file name is valid.
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- ///
- /// Check if the filename is a valid file name (like "text.txt"). The filen ame does not have to exist on the local system.
- ///
- /// File name like "test.txt" or "README.md".
- /// Culture to use for validation.
- /// True if the file name is valid.
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- var filename = (string)value;
+ var filename = (string)value;
- // Check if the filename has valid chars and a dot.
- return filename.IndexOfAny(Path.GetInvalidFileNameChars()) < 0 && new Regex(@"^.+\..+$").IsMatch(filename) ? ValidationResult.ValidResult : new ValidationResult(false, Strings.EnterValidFileName);
- }
+ // Check if the filename has valid chars and a dot.
+ return filename.IndexOfAny(Path.GetInvalidFileNameChars()) < 0 && new Regex(@"^.+\..+$").IsMatch(filename) ? ValidationResult.ValidResult : new ValidationResult(false, Strings.EnterValidFileName);
}
}
\ No newline at end of file
diff --git a/Source/NETworkManager.Validators/FilePathValidator.cs b/Source/NETworkManager.Validators/FilePathValidator.cs
index 8126cc7a1c..cb91bc346d 100644
--- a/Source/NETworkManager.Validators/FilePathValidator.cs
+++ b/Source/NETworkManager.Validators/FilePathValidator.cs
@@ -4,22 +4,21 @@
using NETworkManager.Localization.Resources;
using NETworkManager.Utilities;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+///
+/// Check if the string is a valid file path (like "C:\Temp\Test.txt"). The file path does not have to exist on the local system.
+///
+public class FilePathValidator : ValidationRule
{
///
/// Check if the string is a valid file path (like "C:\Temp\Test.txt"). The file path does not have to exist on the local system.
///
- public class FilePathValidator : ValidationRule
+ /// File path like "C:\Temp\Test.txt"".
+ /// Culture to use for validation.
+ /// True if the file path is valid.
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- ///
- /// Check if the string is a valid file path (like "C:\Temp\Test.txt"). The file path does not have to exist on the local system.
- ///
- /// File path like "C:\Temp\Test.txt"".
- /// Culture to use for validation.
- /// True if the file path is valid.
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- return new Regex(RegexHelper.FullNameRegex, RegexOptions.IgnoreCase).IsMatch((string)value) ? ValidationResult.ValidResult : new ValidationResult(false, Strings.EnterValidFilePath);
- }
+ return new Regex(RegexHelper.FullNameRegex, RegexOptions.IgnoreCase).IsMatch((string)value) ? ValidationResult.ValidResult : new ValidationResult(false, Strings.EnterValidFilePath);
}
}
\ No newline at end of file
diff --git a/Source/NETworkManager.Validators/FolderInPathExistsValidator.cs b/Source/NETworkManager.Validators/FolderInPathExistsValidator.cs
index d22c9ed7a0..0cabd43b0b 100644
--- a/Source/NETworkManager.Validators/FolderInPathExistsValidator.cs
+++ b/Source/NETworkManager.Validators/FolderInPathExistsValidator.cs
@@ -3,27 +3,26 @@
using System.Windows.Controls;
using NETworkManager.Localization.Resources;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+///
+/// Check if the folder in the full path exists on the system (like "C:\Temp" from "C:\Temp\export.json").
+///
+public class FolderInPathExistsValidator : ValidationRule
{
///
- /// Check if the folder in the full path exists on the system (like "C:\Temp" from "C:\Temp\export.json").
+ /// Check if the string is a valid file path (like "C:\Temp\Test.txt"). The file path does not have to exist on the local system.
///
- public class FolderInPathExistsValidator : ValidationRule
+ /// File path like "C:\Temp\Test.txt"".
+ /// Culture to use for validation.
+ /// True if the folder exists.
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- ///
- /// Check if the string is a valid file path (like "C:\Temp\Test.txt"). The file path does not have to exist on the local system.
- ///
- /// File path like "C:\Temp\Test.txt"".
- /// Culture to use for validation.
- /// True if the folder exists.
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- string path = Path.GetDirectoryName((string)value);
+ string path = Path.GetDirectoryName((string)value);
- if (Directory.Exists(path))
- return ValidationResult.ValidResult;
- else
- return new ValidationResult(false, Strings.FolderDoesNotExist);
- }
+ if (Directory.Exists(path))
+ return ValidationResult.ValidResult;
+ else
+ return new ValidationResult(false, Strings.FolderDoesNotExist);
}
}
\ No newline at end of file
diff --git a/Source/NETworkManager.Validators/GroupNameValidator.cs b/Source/NETworkManager.Validators/GroupNameValidator.cs
index 13cfa05736..c8a295d86c 100644
--- a/Source/NETworkManager.Validators/GroupNameValidator.cs
+++ b/Source/NETworkManager.Validators/GroupNameValidator.cs
@@ -1,18 +1,17 @@
using System.Globalization;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class GroupNameValidator : ValidationRule
{
- public class GroupNameValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- var groupName = value as string;
+ var groupName = value as string;
- if (groupName.StartsWith("~"))
- return new ValidationResult(false, string.Format(Localization.Resources.Strings.GroupNameCannotStartWithX, "~"));
+ if (groupName.StartsWith("~"))
+ return new ValidationResult(false, string.Format(Localization.Resources.Strings.GroupNameCannotStartWithX, "~"));
- return ValidationResult.ValidResult;
- }
+ return ValidationResult.ValidResult;
}
}
diff --git a/Source/NETworkManager.Validators/HttpAndHttpsUriValidator.cs b/Source/NETworkManager.Validators/HttpAndHttpsUriValidator.cs
index bd8d4821b5..27cbf99cb2 100644
--- a/Source/NETworkManager.Validators/HttpAndHttpsUriValidator.cs
+++ b/Source/NETworkManager.Validators/HttpAndHttpsUriValidator.cs
@@ -2,13 +2,12 @@
using System.Globalization;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class HttpAndHttpsUriValidator : ValidationRule
{
- public class HttpAndHttpsUriValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- return Uri.TryCreate(value as string, UriKind.Absolute, out var uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidWebsiteUri);
- }
+ return Uri.TryCreate(value as string, UriKind.Absolute, out var uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidWebsiteUri);
}
}
diff --git a/Source/NETworkManager.Validators/IPAddressOrHostnameAsRangeValidator.cs b/Source/NETworkManager.Validators/IPAddressOrHostnameAsRangeValidator.cs
index 0473a1690a..c490880601 100644
--- a/Source/NETworkManager.Validators/IPAddressOrHostnameAsRangeValidator.cs
+++ b/Source/NETworkManager.Validators/IPAddressOrHostnameAsRangeValidator.cs
@@ -4,31 +4,30 @@
using NETworkManager.Localization.Resources;
using NETworkManager.Utilities;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class IPAddressOrHostnameAsRangeValidator : ValidationRule
{
- public class IPAddressOrHostnameAsRangeValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- var input = (value as string)?.Trim();
-
- if (string.IsNullOrEmpty(input))
- return new ValidationResult(false, Strings.EnterValidHostnameOrIPAddress);
+ var input = (value as string)?.Trim();
- foreach (var item in input.Split(";"))
- {
- var localItem = item.Trim();
+ if (string.IsNullOrEmpty(input))
+ return new ValidationResult(false, Strings.EnterValidHostnameOrIPAddress);
- // Check if it is a valid IPv4 address like 192.168.0.1, a valid IPv6 address like ::1 or a valid hostname like server-01 or server-01.example.com
- var isValid = Regex.IsMatch(localItem, RegexHelper.IPv4AddressRegex) ||
- Regex.IsMatch(localItem, RegexHelper.IPv6AddressRegex) ||
- Regex.IsMatch(localItem, RegexHelper.HostnameRegex);
-
- if (!isValid)
- return new ValidationResult(false, Strings.EnterValidHostnameOrIPAddress);
- }
+ foreach (var item in input.Split(";"))
+ {
+ var localItem = item.Trim();
- return ValidationResult.ValidResult;
+ // Check if it is a valid IPv4 address like 192.168.0.1, a valid IPv6 address like ::1 or a valid hostname like server-01 or server-01.example.com
+ var isValid = Regex.IsMatch(localItem, RegexHelper.IPv4AddressRegex) ||
+ Regex.IsMatch(localItem, RegexHelper.IPv6AddressRegex) ||
+ Regex.IsMatch(localItem, RegexHelper.HostnameRegex);
+
+ if (!isValid)
+ return new ValidationResult(false, Strings.EnterValidHostnameOrIPAddress);
}
+
+ return ValidationResult.ValidResult;
}
}
diff --git a/Source/NETworkManager.Validators/IPAddressOrHostnameValidator.cs b/Source/NETworkManager.Validators/IPAddressOrHostnameValidator.cs
index 6bc6109649..984f2de21d 100644
--- a/Source/NETworkManager.Validators/IPAddressOrHostnameValidator.cs
+++ b/Source/NETworkManager.Validators/IPAddressOrHostnameValidator.cs
@@ -4,30 +4,29 @@
using NETworkManager.Localization.Resources;
using NETworkManager.Utilities;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class IPAddressOrHostnameValidator : ValidationRule
{
- public class IPAddressOrHostnameValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- var input = (value as string)?.Trim();
+ var input = (value as string)?.Trim();
- if(string.IsNullOrEmpty(input))
- return new ValidationResult(false, Strings.EnterValidHostnameOrIPAddress);
+ if(string.IsNullOrEmpty(input))
+ return new ValidationResult(false, Strings.EnterValidHostnameOrIPAddress);
- // Check if it is a valid IPv4 address like 192.168.0.1
- if (Regex.IsMatch(input, RegexHelper.IPv4AddressRegex))
- return ValidationResult.ValidResult;
+ // Check if it is a valid IPv4 address like 192.168.0.1
+ if (Regex.IsMatch(input, RegexHelper.IPv4AddressRegex))
+ return ValidationResult.ValidResult;
- // Check if it is a valid IPv6 address like ::1
- if (Regex.IsMatch(input, RegexHelper.IPv6AddressRegex))
- return ValidationResult.ValidResult;
+ // Check if it is a valid IPv6 address like ::1
+ if (Regex.IsMatch(input, RegexHelper.IPv6AddressRegex))
+ return ValidationResult.ValidResult;
- // Check if it is a valid hostname like server-01 or server-01.example.com
- if (Regex.IsMatch(input, RegexHelper.HostnameRegex))
- return ValidationResult.ValidResult;
+ // Check if it is a valid hostname like server-01 or server-01.example.com
+ if (Regex.IsMatch(input, RegexHelper.HostnameRegex))
+ return ValidationResult.ValidResult;
- return new ValidationResult(false, Strings.EnterValidHostnameOrIPAddress);
- }
+ return new ValidationResult(false, Strings.EnterValidHostnameOrIPAddress);
}
}
diff --git a/Source/NETworkManager.Validators/IPv4AddressValidator.cs b/Source/NETworkManager.Validators/IPv4AddressValidator.cs
index cfe024ff5d..83a7ad59dd 100644
--- a/Source/NETworkManager.Validators/IPv4AddressValidator.cs
+++ b/Source/NETworkManager.Validators/IPv4AddressValidator.cs
@@ -3,18 +3,17 @@
using System.Text.RegularExpressions;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class IPv4AddressValidator : ValidationRule
{
- public class IPv4AddressValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- var ipAddress = (value as string)?.Trim();
+ var ipAddress = (value as string)?.Trim();
- if (string.IsNullOrEmpty(ipAddress))
- return new ValidationResult(false, Localization.Resources.Strings.EnterValidIPv4Address);
+ if (string.IsNullOrEmpty(ipAddress))
+ return new ValidationResult(false, Localization.Resources.Strings.EnterValidIPv4Address);
- return Regex.IsMatch(ipAddress, RegexHelper.IPv4AddressRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidIPv4Address);
- }
+ return Regex.IsMatch(ipAddress, RegexHelper.IPv4AddressRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidIPv4Address);
}
}
diff --git a/Source/NETworkManager.Validators/IPv4IPv6SubnetValidator.cs b/Source/NETworkManager.Validators/IPv4IPv6SubnetValidator.cs
index a4083712ab..2f88a97b9a 100644
--- a/Source/NETworkManager.Validators/IPv4IPv6SubnetValidator.cs
+++ b/Source/NETworkManager.Validators/IPv4IPv6SubnetValidator.cs
@@ -2,30 +2,30 @@
using System.Text.RegularExpressions;
using System.Windows.Controls;
using NETworkManager.Utilities;
-namespace NETworkManager.Validators
+
+namespace NETworkManager.Validators;
+
+public class IPv4IPv6SubnetValidator : ValidationRule
{
- public class IPv4IPv6SubnetValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- var subnet = (value as string)?.Trim();
+ var subnet = (value as string)?.Trim();
- if (string.IsNullOrEmpty(subnet))
- return new ValidationResult(false, Localization.Resources.Strings.EnterValidSubnet);
+ if (string.IsNullOrEmpty(subnet))
+ return new ValidationResult(false, Localization.Resources.Strings.EnterValidSubnet);
- // Check if it is a IPv4 address with a cidr like 192.168.0.0/24
- if (Regex.IsMatch(subnet, RegexHelper.IPv4AddressCidrRegex))
- return ValidationResult.ValidResult;
+ // Check if it is a IPv4 address with a cidr like 192.168.0.0/24
+ if (Regex.IsMatch(subnet, RegexHelper.IPv4AddressCidrRegex))
+ return ValidationResult.ValidResult;
- // Check if it is a IPv4 address with a subnetmask like 255.255.255.0
- if (Regex.IsMatch(subnet, RegexHelper.IPv4AddressSubnetmaskRegex))
- return ValidationResult.ValidResult;
+ // Check if it is a IPv4 address with a subnetmask like 255.255.255.0
+ if (Regex.IsMatch(subnet, RegexHelper.IPv4AddressSubnetmaskRegex))
+ return ValidationResult.ValidResult;
- // check if it is a IPv6 address with a cidr like ::1/64
- if (Regex.IsMatch(subnet, RegexHelper.IPv6AddressCidrRegex))
- return ValidationResult.ValidResult;
+ // check if it is a IPv6 address with a cidr like ::1/64
+ if (Regex.IsMatch(subnet, RegexHelper.IPv6AddressCidrRegex))
+ return ValidationResult.ValidResult;
- return new ValidationResult(false, Localization.Resources.Strings.EnterValidSubnet);
- }
+ return new ValidationResult(false, Localization.Resources.Strings.EnterValidSubnet);
}
}
diff --git a/Source/NETworkManager.Validators/IPv4IPv6SubnetmaskOrCIDRValidator.cs b/Source/NETworkManager.Validators/IPv4IPv6SubnetmaskOrCIDRValidator.cs
index f4100c6ad8..2223e9ff06 100644
--- a/Source/NETworkManager.Validators/IPv4IPv6SubnetmaskOrCIDRValidator.cs
+++ b/Source/NETworkManager.Validators/IPv4IPv6SubnetmaskOrCIDRValidator.cs
@@ -3,29 +3,28 @@
using System.Windows.Controls;
using NETworkManager.Utilities;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class IPv4IPv6SubnetmaskOrCIDRValidator : ValidationRule
{
- public class IPv4IPv6SubnetmaskOrCIDRValidator : ValidationRule
- {
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- var subnetmaskOrCidr = (value as string)?.Trim();
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
+ {
+ var subnetmaskOrCidr = (value as string)?.Trim();
- if(string.IsNullOrEmpty(subnetmaskOrCidr))
- return new ValidationResult(false, Localization.Resources.Strings.EnterValidSubnetmaskOrCIDR);
+ if(string.IsNullOrEmpty(subnetmaskOrCidr))
+ return new ValidationResult(false, Localization.Resources.Strings.EnterValidSubnetmaskOrCIDR);
- // Check if it is a subnetmask like 255.255.255.0
- if (Regex.IsMatch(subnetmaskOrCidr, RegexHelper.SubnetmaskRegex))
- return ValidationResult.ValidResult;
+ // Check if it is a subnetmask like 255.255.255.0
+ if (Regex.IsMatch(subnetmaskOrCidr, RegexHelper.SubnetmaskRegex))
+ return ValidationResult.ValidResult;
- // Check if it is a CIDR like /24
- if (int.TryParse(subnetmaskOrCidr.TrimStart('/'), out var cidr))
- {
- if (cidr >= 0 && cidr < 129)
- return ValidationResult.ValidResult;
- }
-
- return new ValidationResult(false, Localization.Resources.Strings.EnterValidSubnetmaskOrCIDR);
- }
+ // Check if it is a CIDR like /24
+ if (int.TryParse(subnetmaskOrCidr.TrimStart('/'), out var cidr))
+ {
+ if (cidr >= 0 && cidr < 129)
+ return ValidationResult.ValidResult;
+ }
+
+ return new ValidationResult(false, Localization.Resources.Strings.EnterValidSubnetmaskOrCIDR);
}
}
diff --git a/Source/NETworkManager.Validators/IPv4SubnetValidator.cs b/Source/NETworkManager.Validators/IPv4SubnetValidator.cs
index 84782ebf28..1f51d679a4 100644
--- a/Source/NETworkManager.Validators/IPv4SubnetValidator.cs
+++ b/Source/NETworkManager.Validators/IPv4SubnetValidator.cs
@@ -3,24 +3,23 @@
using System.Windows.Controls;
using NETworkManager.Utilities;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class IPv4SubnetValidator : ValidationRule
{
- public class IPv4SubnetValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- var subnet = (value as string)?.Trim();
+ var subnet = (value as string)?.Trim();
- if(string.IsNullOrEmpty(subnet))
- return new ValidationResult(false, Localization.Resources.Strings.EnterValidSubnet);
+ if(string.IsNullOrEmpty(subnet))
+ return new ValidationResult(false, Localization.Resources.Strings.EnterValidSubnet);
- if (Regex.IsMatch(subnet, RegexHelper.IPv4AddressCidrRegex))
- return ValidationResult.ValidResult;
+ if (Regex.IsMatch(subnet, RegexHelper.IPv4AddressCidrRegex))
+ return ValidationResult.ValidResult;
- if (Regex.IsMatch(subnet, RegexHelper.IPv4AddressSubnetmaskRegex))
- return ValidationResult.ValidResult;
+ if (Regex.IsMatch(subnet, RegexHelper.IPv4AddressSubnetmaskRegex))
+ return ValidationResult.ValidResult;
- return new ValidationResult(false, Localization.Resources.Strings.EnterValidSubnet);
- }
+ return new ValidationResult(false, Localization.Resources.Strings.EnterValidSubnet);
}
}
diff --git a/Source/NETworkManager.Validators/IPv4SubnetmaskOrCIDRValidator.cs b/Source/NETworkManager.Validators/IPv4SubnetmaskOrCIDRValidator.cs
index 76e69b588c..34568b9fd9 100644
--- a/Source/NETworkManager.Validators/IPv4SubnetmaskOrCIDRValidator.cs
+++ b/Source/NETworkManager.Validators/IPv4SubnetmaskOrCIDRValidator.cs
@@ -3,28 +3,27 @@
using System.Windows.Controls;
using NETworkManager.Utilities;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class IPv4SubnetmaskOrCIDRValidator : ValidationRule
{
- public class IPv4SubnetmaskOrCIDRValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- var subnetmaskOrCidr = (value as string)?.Trim();
-
- if(string.IsNullOrEmpty(subnetmaskOrCidr))
- return new ValidationResult(false, Localization.Resources.Strings.EnterValidSubnetmaskOrCIDR);
+ var subnetmaskOrCidr = (value as string)?.Trim();
+ if(string.IsNullOrEmpty(subnetmaskOrCidr))
+ return new ValidationResult(false, Localization.Resources.Strings.EnterValidSubnetmaskOrCIDR);
- if (Regex.IsMatch(subnetmaskOrCidr, RegexHelper.SubnetmaskRegex))
- return ValidationResult.ValidResult;
- if (int.TryParse(subnetmaskOrCidr.TrimStart('/'), out var cidr))
- {
- if (cidr >= 0 && cidr < 33)
- return ValidationResult.ValidResult;
- }
+ if (Regex.IsMatch(subnetmaskOrCidr, RegexHelper.SubnetmaskRegex))
+ return ValidationResult.ValidResult;
- return new ValidationResult(false, Localization.Resources.Strings.EnterValidSubnetmaskOrCIDR);
+ if (int.TryParse(subnetmaskOrCidr.TrimStart('/'), out var cidr))
+ {
+ if (cidr >= 0 && cidr < 33)
+ return ValidationResult.ValidResult;
}
+
+ return new ValidationResult(false, Localization.Resources.Strings.EnterValidSubnetmaskOrCIDR);
}
}
diff --git a/Source/NETworkManager.Validators/IPv6AddressValidator.cs b/Source/NETworkManager.Validators/IPv6AddressValidator.cs
index a3afdc095c..f5ddc6b13e 100644
--- a/Source/NETworkManager.Validators/IPv6AddressValidator.cs
+++ b/Source/NETworkManager.Validators/IPv6AddressValidator.cs
@@ -3,18 +3,17 @@
using System.Text.RegularExpressions;
using System.Windows.Controls;
-namespace NETworkManager.Validators
-{
- public class IPv6AddressValidator : ValidationRule
+namespace NETworkManager.Validators;
+
+public class IPv6AddressValidator : ValidationRule
+{
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- var ipAddress = (value as string)?.Trim();
+ var ipAddress = (value as string)?.Trim();
- if (string.IsNullOrEmpty(ipAddress))
- return new ValidationResult(false, Localization.Resources.Strings.EnterValidIPv6Address);
+ if (string.IsNullOrEmpty(ipAddress))
+ return new ValidationResult(false, Localization.Resources.Strings.EnterValidIPv6Address);
- return Regex.IsMatch(ipAddress, RegexHelper.IPv6AddressRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidIPv6Address);
- }
+ return Regex.IsMatch(ipAddress, RegexHelper.IPv6AddressRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidIPv6Address);
}
}
diff --git a/Source/NETworkManager.Validators/Int32Validator.cs b/Source/NETworkManager.Validators/Int32Validator.cs
index 6d720a1994..d2f9c04513 100644
--- a/Source/NETworkManager.Validators/Int32Validator.cs
+++ b/Source/NETworkManager.Validators/Int32Validator.cs
@@ -1,13 +1,12 @@
using System.Globalization;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class Int32Validator : ValidationRule
{
- public class Int32Validator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- return int.TryParse(value as string, out var x) && x > 0 ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidNumber);
- }
+ return int.TryParse(value as string, out var x) && x > 0 ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidNumber);
}
}
diff --git a/Source/NETworkManager.Validators/IsNameUnique.cs b/Source/NETworkManager.Validators/IsNameUnique.cs
index 15b6042d74..f62a930ee1 100644
--- a/Source/NETworkManager.Validators/IsNameUnique.cs
+++ b/Source/NETworkManager.Validators/IsNameUnique.cs
@@ -3,16 +3,15 @@
using System.Linq;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class IsNameUnique : ValidationRule
{
- public class IsNameUnique : ValidationRule
- {
- public IsNameUniqueDependencyObjectWrapper Wrapper { get; set; }
+ public IsNameUniqueDependencyObjectWrapper Wrapper { get; set; }
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- return Wrapper.UsedNames.Any(x => x.Equals(value as string, StringComparison.OrdinalIgnoreCase)) ?
- new ValidationResult(false, Localization.Resources.Strings.ErrorMessage_NameIsAlreadyUsed) : ValidationResult.ValidResult;
- }
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
+ {
+ return Wrapper.UsedNames.Any(x => x.Equals(value as string, StringComparison.OrdinalIgnoreCase)) ?
+ new ValidationResult(false, Localization.Resources.Strings.ErrorMessage_NameIsAlreadyUsed) : ValidationResult.ValidResult;
}
}
diff --git a/Source/NETworkManager.Validators/IsNameUniqueDependencyObjectWrapper.cs b/Source/NETworkManager.Validators/IsNameUniqueDependencyObjectWrapper.cs
index e06f1a6061..675b8a15be 100644
--- a/Source/NETworkManager.Validators/IsNameUniqueDependencyObjectWrapper.cs
+++ b/Source/NETworkManager.Validators/IsNameUniqueDependencyObjectWrapper.cs
@@ -1,18 +1,17 @@
using System.Collections.Generic;
using System.Windows;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class IsNameUniqueDependencyObjectWrapper : DependencyObject
{
- public class IsNameUniqueDependencyObjectWrapper : DependencyObject
- {
- public static readonly DependencyProperty UsedNamesProperty = DependencyProperty.Register("UsedNames",
- typeof(List),
- typeof(IsNameUniqueDependencyObjectWrapper));
+ public static readonly DependencyProperty UsedNamesProperty = DependencyProperty.Register("UsedNames",
+ typeof(List),
+ typeof(IsNameUniqueDependencyObjectWrapper));
- public List UsedNames
- {
- get { return GetValue(UsedNamesProperty) as List; }
- set { SetValue(UsedNamesProperty, value); }
- }
+ public List UsedNames
+ {
+ get { return GetValue(UsedNamesProperty) as List; }
+ set { SetValue(UsedNamesProperty, value); }
}
}
diff --git a/Source/NETworkManager.Validators/MACAddressValidator.cs b/Source/NETworkManager.Validators/MACAddressValidator.cs
index 2691bc196d..f6e2889037 100644
--- a/Source/NETworkManager.Validators/MACAddressValidator.cs
+++ b/Source/NETworkManager.Validators/MACAddressValidator.cs
@@ -3,13 +3,12 @@
using System.Text.RegularExpressions;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class MACAddressValidator : ValidationRule
{
- public class MACAddressValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- return value != null && Regex.IsMatch((string) value, RegexHelper.MACAddressRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidMACAddress);
- }
+ return value != null && Regex.IsMatch((string) value, RegexHelper.MACAddressRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidMACAddress);
}
}
\ No newline at end of file
diff --git a/Source/NETworkManager.Validators/MultipleHostsRangeValidator.cs b/Source/NETworkManager.Validators/MultipleHostsRangeValidator.cs
index df01589f35..ee7e09b86d 100644
--- a/Source/NETworkManager.Validators/MultipleHostsRangeValidator.cs
+++ b/Source/NETworkManager.Validators/MultipleHostsRangeValidator.cs
@@ -5,89 +5,88 @@
using System.Net;
using NETworkManager.Models.Network;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class MultipleHostsRangeValidator : ValidationRule
{
- public class MultipleHostsRangeValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- var isValid = true;
+ var isValid = true;
- if (value == null)
- return new ValidationResult(false, Localization.Resources.Strings.EnterValidIPScanRange);
+ if (value == null)
+ return new ValidationResult(false, Localization.Resources.Strings.EnterValidIPScanRange);
- foreach (var ipHostOrRange in ((string)value).Replace(" ", "").Split(';'))
- {
- // 192.168.0.1
- if (Regex.IsMatch(ipHostOrRange, RegexHelper.IPv4AddressRegex))
- continue;
+ foreach (var ipHostOrRange in ((string)value).Replace(" ", "").Split(';'))
+ {
+ // 192.168.0.1
+ if (Regex.IsMatch(ipHostOrRange, RegexHelper.IPv4AddressRegex))
+ continue;
- // 192.168.0.0/24
- if (Regex.IsMatch(ipHostOrRange, RegexHelper.IPv4AddressCidrRegex))
- continue;
+ // 192.168.0.0/24
+ if (Regex.IsMatch(ipHostOrRange, RegexHelper.IPv4AddressCidrRegex))
+ continue;
- // 192.168.0.0/255.255.255.0
- if (Regex.IsMatch(ipHostOrRange, RegexHelper.IPv4AddressSubnetmaskRegex))
- continue;
+ // 192.168.0.0/255.255.255.0
+ if (Regex.IsMatch(ipHostOrRange, RegexHelper.IPv4AddressSubnetmaskRegex))
+ continue;
- // 192.168.0.0 - 192.168.0.100
- if (Regex.IsMatch(ipHostOrRange, RegexHelper.IPv4AddressRangeRegex))
- {
- var range = ipHostOrRange.Split('-');
+ // 192.168.0.0 - 192.168.0.100
+ if (Regex.IsMatch(ipHostOrRange, RegexHelper.IPv4AddressRangeRegex))
+ {
+ var range = ipHostOrRange.Split('-');
- if (IPv4Address.ToInt32(IPAddress.Parse(range[0])) > IPv4Address.ToInt32(IPAddress.Parse(range[1])))
- isValid = false;
+ if (IPv4Address.ToInt32(IPAddress.Parse(range[0])) > IPv4Address.ToInt32(IPAddress.Parse(range[1])))
+ isValid = false;
- continue;
- }
+ continue;
+ }
- // 192.168.[50-100].1
- if (Regex.IsMatch(ipHostOrRange, RegexHelper.IPv4AddressSpecialRangeRegex))
+ // 192.168.[50-100].1
+ if (Regex.IsMatch(ipHostOrRange, RegexHelper.IPv4AddressSpecialRangeRegex))
+ {
+ var octets = ipHostOrRange.Split('.');
+
+ foreach (var octet in octets)
{
- var octets = ipHostOrRange.Split('.');
+ // Match [50-100]
+ if (!Regex.IsMatch(octet, RegexHelper.SpecialRangeRegex))
+ continue;
- foreach (var octet in octets)
+ foreach (var numberOrRange in octet.Substring(1, octet.Length - 2).Split(','))
{
- // Match [50-100]
- if (!Regex.IsMatch(octet, RegexHelper.SpecialRangeRegex))
+ if (!numberOrRange.Contains("-"))
continue;
- foreach (var numberOrRange in octet.Substring(1, octet.Length - 2).Split(','))
- {
- if (!numberOrRange.Contains("-"))
- continue;
+ // 50-100 --> {50, 100}
+ var rangeNumber = numberOrRange.Split('-');
- // 50-100 --> {50, 100}
- var rangeNumber = numberOrRange.Split('-');
-
- if (int.Parse(rangeNumber[0]) > int.Parse(rangeNumber[1]))
- isValid = false;
- }
+ if (int.Parse(rangeNumber[0]) > int.Parse(rangeNumber[1]))
+ isValid = false;
}
-
- continue;
}
- // 2001:db8:85a3::8a2e:370:7334
- if (Regex.IsMatch(ipHostOrRange, RegexHelper.IPv6AddressRegex))
- continue;
+ continue;
+ }
- // server-01.example.com
- if (Regex.IsMatch(ipHostOrRange, RegexHelper.HostnameRegex))
- continue;
+ // 2001:db8:85a3::8a2e:370:7334
+ if (Regex.IsMatch(ipHostOrRange, RegexHelper.IPv6AddressRegex))
+ continue;
- // server-01.example.com/24
- if (Regex.IsMatch(ipHostOrRange, RegexHelper.HostnameCidrRegex))
- continue;
+ // server-01.example.com
+ if (Regex.IsMatch(ipHostOrRange, RegexHelper.HostnameRegex))
+ continue;
- // server-01.example.com/255.255.255.0
- if (Regex.IsMatch(ipHostOrRange, RegexHelper.HostnameSubnetmaskRegex))
- continue;
+ // server-01.example.com/24
+ if (Regex.IsMatch(ipHostOrRange, RegexHelper.HostnameCidrRegex))
+ continue;
- isValid = false;
- }
+ // server-01.example.com/255.255.255.0
+ if (Regex.IsMatch(ipHostOrRange, RegexHelper.HostnameSubnetmaskRegex))
+ continue;
- return isValid ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidIPScanRange);
+ isValid = false;
}
+
+ return isValid ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidIPScanRange);
}
}
diff --git a/Source/NETworkManager.Validators/MultipleIPAddressesValidator.cs b/Source/NETworkManager.Validators/MultipleIPAddressesValidator.cs
index a0a93ff50b..be333a77f8 100644
--- a/Source/NETworkManager.Validators/MultipleIPAddressesValidator.cs
+++ b/Source/NETworkManager.Validators/MultipleIPAddressesValidator.cs
@@ -3,24 +3,23 @@
using System.Text.RegularExpressions;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class MultipleIPAddressesValidator : ValidationRule
{
- public class MultipleIPAddressesValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- if (value == null)
- return ValidationResult.ValidResult;
-
- for (var index = 0; index < ((string)value).Split(';').Length; index++)
- {
- var ipAddress = ((string)value).Split(';')[index];
+ if (value == null)
+ return ValidationResult.ValidResult;
- if (!Regex.IsMatch(ipAddress.Trim(), RegexHelper.IPv4AddressRegex) && !Regex.IsMatch(ipAddress.Trim(), RegexHelper.IPv6AddressRegex))
- return new ValidationResult(false, Localization.Resources.Strings.EnterOneOrMoreValidIPAddresses);
- }
+ for (var index = 0; index < ((string)value).Split(';').Length; index++)
+ {
+ var ipAddress = ((string)value).Split(';')[index];
- return ValidationResult.ValidResult;
+ if (!Regex.IsMatch(ipAddress.Trim(), RegexHelper.IPv4AddressRegex) && !Regex.IsMatch(ipAddress.Trim(), RegexHelper.IPv6AddressRegex))
+ return new ValidationResult(false, Localization.Resources.Strings.EnterOneOrMoreValidIPAddresses);
}
+
+ return ValidationResult.ValidResult;
}
}
diff --git a/Source/NETworkManager.Validators/NoSpacesValidator.cs b/Source/NETworkManager.Validators/NoSpacesValidator.cs
index 2c75c4911c..2f29a44c5b 100644
--- a/Source/NETworkManager.Validators/NoSpacesValidator.cs
+++ b/Source/NETworkManager.Validators/NoSpacesValidator.cs
@@ -2,16 +2,15 @@
using System.Linq;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class NoSpacesValidator : ValidationRule
{
- public class NoSpacesValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- if (string.IsNullOrEmpty(value as string) || !((string) value).Any(char.IsWhiteSpace))
- return ValidationResult.ValidResult;
+ if (string.IsNullOrEmpty(value as string) || !((string) value).Any(char.IsWhiteSpace))
+ return ValidationResult.ValidResult;
- return new ValidationResult(false, Localization.Resources.Strings.SpacesAreNotAllowed);
- }
+ return new ValidationResult(false, Localization.Resources.Strings.SpacesAreNotAllowed);
}
}
\ No newline at end of file
diff --git a/Source/NETworkManager.Validators/NotEndWithSemicolonValidator.cs b/Source/NETworkManager.Validators/NotEndWithSemicolonValidator.cs
index c573573361..4d40022def 100644
--- a/Source/NETworkManager.Validators/NotEndWithSemicolonValidator.cs
+++ b/Source/NETworkManager.Validators/NotEndWithSemicolonValidator.cs
@@ -4,13 +4,12 @@
using NETworkManager.Localization.Resources;
using NETworkManager.Utilities;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class NotEndWithSemicolonValidator : ValidationRule
{
- public class NotEndWithSemicolonValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- return Regex.IsMatch(((string) value).Trim(), RegexHelper.StringNotEndWithSemicolonRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Strings.InputCannotEndWithSemicolon);
- }
+ return Regex.IsMatch(((string) value).Trim(), RegexHelper.StringNotEndWithSemicolonRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Strings.InputCannotEndWithSemicolon);
}
}
diff --git a/Source/NETworkManager.Validators/NumberValidator.cs b/Source/NETworkManager.Validators/NumberValidator.cs
index 6220b680d0..7f6cff1dee 100644
--- a/Source/NETworkManager.Validators/NumberValidator.cs
+++ b/Source/NETworkManager.Validators/NumberValidator.cs
@@ -4,13 +4,12 @@
using System.Text.RegularExpressions;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class NumberValidator : ValidationRule
{
- public class NumberValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- return Regex.IsMatch(((string)value).Trim(), RegexHelper.NumberRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Strings.OnlyNumbersCanBeEntered);
- }
+ return Regex.IsMatch(((string)value).Trim(), RegexHelper.NumberRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Strings.OnlyNumbersCanBeEntered);
}
}
diff --git a/Source/NETworkManager.Validators/OIDValidator.cs b/Source/NETworkManager.Validators/OIDValidator.cs
index 8dd5f0ad74..47b136bda8 100644
--- a/Source/NETworkManager.Validators/OIDValidator.cs
+++ b/Source/NETworkManager.Validators/OIDValidator.cs
@@ -2,23 +2,22 @@
using System.Globalization;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class OIDValidator : ValidationRule
{
- public class OIDValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
+ // Use SharpSNMP new ObjectIdentifiert to validate oid
+ try
{
- // Use SharpSNMP new ObjectIdentifiert to validate oid
- try
- {
- var oid = new ObjectIdentifier(value as string);
- }
- catch (System.ArgumentException)
- {
- return new ValidationResult(false, Localization.Resources.Strings.EnterValidOID);
- }
-
- return ValidationResult.ValidResult;
+ var oid = new ObjectIdentifier(value as string);
}
+ catch (System.ArgumentException)
+ {
+ return new ValidationResult(false, Localization.Resources.Strings.EnterValidOID);
+ }
+
+ return ValidationResult.ValidResult;
}
}
diff --git a/Source/NETworkManager.Validators/PortRangeValidator.cs b/Source/NETworkManager.Validators/PortRangeValidator.cs
index 25f0ba5252..d2297cb77d 100644
--- a/Source/NETworkManager.Validators/PortRangeValidator.cs
+++ b/Source/NETworkManager.Validators/PortRangeValidator.cs
@@ -1,48 +1,47 @@
using System.Globalization;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class PortRangeValidator : ValidationRule
{
- public class PortRangeValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- var isValid = true;
+ var isValid = true;
- if (value == null)
- return new ValidationResult(false, Localization.Resources.Strings.EnterValidPortOrPortRange);
+ if (value == null)
+ return new ValidationResult(false, Localization.Resources.Strings.EnterValidPortOrPortRange);
- foreach (var portOrRange in ((string)value).Replace(" ", "").Split(';'))
+ foreach (var portOrRange in ((string)value).Replace(" ", "").Split(';'))
+ {
+ if (portOrRange.Contains("-"))
{
- if (portOrRange.Contains("-"))
- {
- var portRange = portOrRange.Split('-');
+ var portRange = portOrRange.Split('-');
- if (int.TryParse(portRange[0], out var startPort) && int.TryParse(portRange[1], out var endPort))
- {
- if (!((startPort > 0) && (startPort < 65536) && (endPort > 0) && (endPort < 65536) && (startPort < endPort)))
- isValid = false;
- }
- else
- {
+ if (int.TryParse(portRange[0], out var startPort) && int.TryParse(portRange[1], out var endPort))
+ {
+ if (!((startPort > 0) && (startPort < 65536) && (endPort > 0) && (endPort < 65536) && (startPort < endPort)))
isValid = false;
- }
}
else
{
- if (int.TryParse(portOrRange, out var portNumber))
- {
- if (!((portNumber > 0) && (portNumber < 65536)))
- isValid = false;
- }
- else
- {
+ isValid = false;
+ }
+ }
+ else
+ {
+ if (int.TryParse(portOrRange, out var portNumber))
+ {
+ if (!((portNumber > 0) && (portNumber < 65536)))
isValid = false;
- }
+ }
+ else
+ {
+ isValid = false;
}
}
-
- return isValid ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidPortOrPortRange);
}
+
+ return isValid ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidPortOrPortRange);
}
}
\ No newline at end of file
diff --git a/Source/NETworkManager.Validators/PortValidator.cs b/Source/NETworkManager.Validators/PortValidator.cs
index 75c4b9c194..de53ae6fd6 100644
--- a/Source/NETworkManager.Validators/PortValidator.cs
+++ b/Source/NETworkManager.Validators/PortValidator.cs
@@ -1,19 +1,18 @@
using System.Globalization;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class PortValidator : ValidationRule
{
- public class PortValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- if (!int.TryParse(value as string, out var portNumber))
- return new ValidationResult(false, Localization.Resources.Strings.EnterValidPort);
+ if (!int.TryParse(value as string, out var portNumber))
+ return new ValidationResult(false, Localization.Resources.Strings.EnterValidPort);
- if (portNumber > 0 && (portNumber < 65536))
- return ValidationResult.ValidResult;
+ if (portNumber > 0 && (portNumber < 65536))
+ return ValidationResult.ValidResult;
- return new ValidationResult(false, Localization.Resources.Strings.EnterValidPort);
- }
+ return new ValidationResult(false, Localization.Resources.Strings.EnterValidPort);
}
}
\ No newline at end of file
diff --git a/Source/NETworkManager.Validators/PowerShellPathValidator.cs b/Source/NETworkManager.Validators/PowerShellPathValidator.cs
index f79fe57f89..fc6fe9af35 100644
--- a/Source/NETworkManager.Validators/PowerShellPathValidator.cs
+++ b/Source/NETworkManager.Validators/PowerShellPathValidator.cs
@@ -3,15 +3,14 @@
using System.Linq;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class PowerShellPathValidator : ValidationRule
{
- public class PowerShellPathValidator : ValidationRule
- {
- private static string[] fileNames = new[] { "powershell.exe", "pwsh.exe" };
+ private static string[] fileNames = new[] { "powershell.exe", "pwsh.exe" };
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- return fileNames.Contains(Path.GetFileName((string)value).ToLower()) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.NoValidPowerShellPath);
- }
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
+ {
+ return fileNames.Contains(Path.GetFileName((string)value).ToLower()) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.NoValidPowerShellPath);
}
}
diff --git a/Source/NETworkManager.Validators/ProfileFileUniqueValidator.cs b/Source/NETworkManager.Validators/ProfileFileUniqueValidator.cs
index 0611bfdd4d..d698662861 100644
--- a/Source/NETworkManager.Validators/ProfileFileUniqueValidator.cs
+++ b/Source/NETworkManager.Validators/ProfileFileUniqueValidator.cs
@@ -3,13 +3,12 @@
using System.Windows.Controls;
using System.Linq;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class ProfileFileUniqueValidator : ValidationRule
{
- public class ProfileFileUniqueValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- return ProfileManager.ProfileFiles.Any(x => x.Name == value as string) ? new ValidationResult(false, Localization.Resources.Strings.ProfileNameAlreadyExists) : ValidationResult.ValidResult;
- }
+ return ProfileManager.ProfileFiles.Any(x => x.Name == value as string) ? new ValidationResult(false, Localization.Resources.Strings.ProfileNameAlreadyExists) : ValidationResult.ValidResult;
}
}
diff --git a/Source/NETworkManager.Validators/PuTTYPathValidator.cs b/Source/NETworkManager.Validators/PuTTYPathValidator.cs
index f747810b5c..ca810c33a1 100644
--- a/Source/NETworkManager.Validators/PuTTYPathValidator.cs
+++ b/Source/NETworkManager.Validators/PuTTYPathValidator.cs
@@ -3,15 +3,14 @@
using System.Linq;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class PuTTYPathValidator : ValidationRule
{
- public class PuTTYPathValidator : ValidationRule
- {
- private static string[] fileNames = new[] { "putty.exe" };
+ private static string[] fileNames = new[] { "putty.exe" };
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- return fileNames.Contains(Path.GetFileName((string)value).ToLower()) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.NoValidPuTTYPath);
- }
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
+ {
+ return fileNames.Contains(Path.GetFileName((string)value).ToLower()) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.NoValidPuTTYPath);
}
}
diff --git a/Source/NETworkManager.Validators/RemoteDesktopHostnameAndPortValidator.cs b/Source/NETworkManager.Validators/RemoteDesktopHostnameAndPortValidator.cs
index 6acfde7a70..bcac86f26b 100644
--- a/Source/NETworkManager.Validators/RemoteDesktopHostnameAndPortValidator.cs
+++ b/Source/NETworkManager.Validators/RemoteDesktopHostnameAndPortValidator.cs
@@ -4,27 +4,26 @@
using NETworkManager.Localization.Resources;
using NETworkManager.Utilities;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class RemoteDesktopHostnameAndPortValidator : ValidationRule
{
- public class RemoteDesktopHostnameAndPortValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- string hostnameAndPort = (string)value;
+ string hostnameAndPort = (string)value;
- if(hostnameAndPort.Contains(":"))
- {
- string[] hostnameAndPortValues = hostnameAndPort.Split(':');
+ if(hostnameAndPort.Contains(":"))
+ {
+ string[] hostnameAndPortValues = hostnameAndPort.Split(':');
- if (Regex.IsMatch(hostnameAndPortValues[0], RegexHelper.HostnameRegex) && !string.IsNullOrEmpty(hostnameAndPortValues[1]) && Regex.IsMatch(hostnameAndPortValues[1], RegexHelper.PortRegex))
- return ValidationResult.ValidResult;
-
- return new ValidationResult(false, Strings.EnterValidHostnameAndPort);
- }
- else
- {
- return Regex.IsMatch((string)value, RegexHelper.HostnameRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Strings.EnterValidHostname);
- }
+ if (Regex.IsMatch(hostnameAndPortValues[0], RegexHelper.HostnameRegex) && !string.IsNullOrEmpty(hostnameAndPortValues[1]) && Regex.IsMatch(hostnameAndPortValues[1], RegexHelper.PortRegex))
+ return ValidationResult.ValidResult;
+
+ return new ValidationResult(false, Strings.EnterValidHostnameAndPort);
+ }
+ else
+ {
+ return Regex.IsMatch((string)value, RegexHelper.HostnameRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Strings.EnterValidHostname);
}
}
}
diff --git a/Source/NETworkManager.Validators/ServerDependencyObjectWrapper.cs b/Source/NETworkManager.Validators/ServerDependencyObjectWrapper.cs
index 2cc7a5f92b..a01e339425 100644
--- a/Source/NETworkManager.Validators/ServerDependencyObjectWrapper.cs
+++ b/Source/NETworkManager.Validators/ServerDependencyObjectWrapper.cs
@@ -1,17 +1,16 @@
using System.Windows;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class ServerDependencyObjectWrapper : DependencyObject
{
- public class ServerDependencyObjectWrapper : DependencyObject
- {
- public static readonly DependencyProperty AllowOnlyIPAddressProperty = DependencyProperty.Register("AllowOnlyIPAddress",
- typeof(bool),
- typeof(ServerDependencyObjectWrapper));
+ public static readonly DependencyProperty AllowOnlyIPAddressProperty = DependencyProperty.Register("AllowOnlyIPAddress",
+ typeof(bool),
+ typeof(ServerDependencyObjectWrapper));
- public bool AllowOnlyIPAddress
- {
- get { return (bool)GetValue(AllowOnlyIPAddressProperty); }
- set { SetValue(AllowOnlyIPAddressProperty, value); }
- }
+ public bool AllowOnlyIPAddress
+ {
+ get { return (bool)GetValue(AllowOnlyIPAddressProperty); }
+ set { SetValue(AllowOnlyIPAddressProperty, value); }
}
}
diff --git a/Source/NETworkManager.Validators/ServerValidator.cs b/Source/NETworkManager.Validators/ServerValidator.cs
index 9fcb9c22ea..facd9ff1be 100644
--- a/Source/NETworkManager.Validators/ServerValidator.cs
+++ b/Source/NETworkManager.Validators/ServerValidator.cs
@@ -4,35 +4,34 @@
using NETworkManager.Localization.Resources;
using NETworkManager.Utilities;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class ServerValidator : ValidationRule
{
- public class ServerValidator : ValidationRule
+ public ServerDependencyObjectWrapper Wrapper { get; set; }
+
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public ServerDependencyObjectWrapper Wrapper { get; set; }
-
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- bool allowOnlyIPAddress = Wrapper.AllowOnlyIPAddress;
- var genericErrorResult = allowOnlyIPAddress ? Strings.EnterValidIPAddress : Strings.EnterValidHostnameOrIPAddress;
+ bool allowOnlyIPAddress = Wrapper.AllowOnlyIPAddress;
+ var genericErrorResult = allowOnlyIPAddress ? Strings.EnterValidIPAddress : Strings.EnterValidHostnameOrIPAddress;
- var input = (value as string)?.Trim();
+ var input = (value as string)?.Trim();
- if(string.IsNullOrEmpty(input))
- return new ValidationResult(false, genericErrorResult);
+ if(string.IsNullOrEmpty(input))
+ return new ValidationResult(false, genericErrorResult);
- // Check if it is a valid IPv4 address like 192.168.0.1
- if (Regex.IsMatch(input, RegexHelper.IPv4AddressRegex))
- return ValidationResult.ValidResult;
+ // Check if it is a valid IPv4 address like 192.168.0.1
+ if (Regex.IsMatch(input, RegexHelper.IPv4AddressRegex))
+ return ValidationResult.ValidResult;
- // Check if it is a valid IPv6 address like ::1
- if (Regex.IsMatch(input, RegexHelper.IPv6AddressRegex))
- return ValidationResult.ValidResult;
+ // Check if it is a valid IPv6 address like ::1
+ if (Regex.IsMatch(input, RegexHelper.IPv6AddressRegex))
+ return ValidationResult.ValidResult;
- // Check if it is a valid hostname like server-01 or server-01.example.com
- if (Regex.IsMatch(input, RegexHelper.HostnameRegex) && !allowOnlyIPAddress)
- return ValidationResult.ValidResult;
+ // Check if it is a valid hostname like server-01 or server-01.example.com
+ if (Regex.IsMatch(input, RegexHelper.HostnameRegex) && !allowOnlyIPAddress)
+ return ValidationResult.ValidResult;
- return new ValidationResult(false, genericErrorResult);
- }
+ return new ValidationResult(false, genericErrorResult);
}
}
diff --git a/Source/NETworkManager.Validators/SubnetmaskValidator.cs b/Source/NETworkManager.Validators/SubnetmaskValidator.cs
index 06cce5674d..bf6cf3f086 100644
--- a/Source/NETworkManager.Validators/SubnetmaskValidator.cs
+++ b/Source/NETworkManager.Validators/SubnetmaskValidator.cs
@@ -3,13 +3,12 @@
using System.Text.RegularExpressions;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class SubnetmaskValidator : ValidationRule
{
- public class SubnetmaskValidator : ValidationRule
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- return value != null && Regex.IsMatch((string) value, RegexHelper.SubnetmaskRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidSubnetmask);
- }
+ return value != null && Regex.IsMatch((string) value, RegexHelper.SubnetmaskRegex) ? ValidationResult.ValidResult : new ValidationResult(false, Localization.Resources.Strings.EnterValidSubnetmask);
}
}
diff --git a/Source/NETworkManager.Validators/TigerVNCPathValidator.cs b/Source/NETworkManager.Validators/TigerVNCPathValidator.cs
index 1d8647f643..9cda6ab8ca 100644
--- a/Source/NETworkManager.Validators/TigerVNCPathValidator.cs
+++ b/Source/NETworkManager.Validators/TigerVNCPathValidator.cs
@@ -3,20 +3,19 @@
using System.Linq;
using System.Windows.Controls;
-namespace NETworkManager.Validators
+namespace NETworkManager.Validators;
+
+public class TigerVNCPathValidator : ValidationRule
{
- public class TigerVNCPathValidator : ValidationRule
- {
- private static string[] fileNames = new[] { "vncviewer-", "vncviewer64-" };
+ private static string[] fileNames = new[] { "vncviewer-", "vncviewer64-" };
- public override ValidationResult Validate(object value, CultureInfo cultureInfo)
- {
- string fileName = Path.GetFileName((string)value).ToLower();
+ public override ValidationResult Validate(object value, CultureInfo cultureInfo)
+ {
+ string fileName = Path.GetFileName((string)value).ToLower();
- if (fileNames.Any(x => fileName.StartsWith(x) && fileName.EndsWith(".exe")))
- return ValidationResult.ValidResult;
+ if (fileNames.Any(x => fileName.StartsWith(x) && fileName.EndsWith(".exe")))
+ return ValidationResult.ValidResult;
- return new ValidationResult(false, Localization.Resources.Strings.NoValidTigerVNCPath);
- }
+ return new ValidationResult(false, Localization.Resources.Strings.NoValidTigerVNCPath);
}
}
From 3c38309d4c10a9600344796a85b73c6e2f740941 Mon Sep 17 00:00:00 2001
From: BornToBeRoot <16019165+BornToBeRoot@users.noreply.github.com>
Date: Mon, 6 Mar 2023 20:17:28 +0100
Subject: [PATCH 02/11] Chore: Make readonly
---
Source/NETworkManager.Validators/PowerShellPathValidator.cs | 2 +-
Source/NETworkManager.Validators/PuTTYPathValidator.cs | 2 +-
Source/NETworkManager.Validators/TigerVNCPathValidator.cs | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/Source/NETworkManager.Validators/PowerShellPathValidator.cs b/Source/NETworkManager.Validators/PowerShellPathValidator.cs
index fc6fe9af35..e8f65fa583 100644
--- a/Source/NETworkManager.Validators/PowerShellPathValidator.cs
+++ b/Source/NETworkManager.Validators/PowerShellPathValidator.cs
@@ -7,7 +7,7 @@ namespace NETworkManager.Validators;
public class PowerShellPathValidator : ValidationRule
{
- private static string[] fileNames = new[] { "powershell.exe", "pwsh.exe" };
+ private static readonly string[] fileNames = new[] { "powershell.exe", "pwsh.exe" };
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
diff --git a/Source/NETworkManager.Validators/PuTTYPathValidator.cs b/Source/NETworkManager.Validators/PuTTYPathValidator.cs
index ca810c33a1..87fb3eb1ad 100644
--- a/Source/NETworkManager.Validators/PuTTYPathValidator.cs
+++ b/Source/NETworkManager.Validators/PuTTYPathValidator.cs
@@ -7,7 +7,7 @@ namespace NETworkManager.Validators;
public class PuTTYPathValidator : ValidationRule
{
- private static string[] fileNames = new[] { "putty.exe" };
+ private static readonly string[] fileNames = new[] { "putty.exe" };
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
diff --git a/Source/NETworkManager.Validators/TigerVNCPathValidator.cs b/Source/NETworkManager.Validators/TigerVNCPathValidator.cs
index 9cda6ab8ca..753901139e 100644
--- a/Source/NETworkManager.Validators/TigerVNCPathValidator.cs
+++ b/Source/NETworkManager.Validators/TigerVNCPathValidator.cs
@@ -7,7 +7,7 @@ namespace NETworkManager.Validators;
public class TigerVNCPathValidator : ValidationRule
{
- private static string[] fileNames = new[] { "vncviewer-", "vncviewer64-" };
+ private static readonly string[] fileNames = new[] { "vncviewer-", "vncviewer64-" };
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
From eb3160e3e9384bba8091ddfba3c8621c384fe410 Mon Sep 17 00:00:00 2001
From: BornToBeRoot <16019165+BornToBeRoot@users.noreply.github.com>
Date: Mon, 6 Mar 2023 20:20:56 +0100
Subject: [PATCH 03/11] Chore: Use .NET 7 syntax
---
Source/NETworkManager.Update/Updater.cs | 139 ++++++++--------
.../NETworkManager.Utilities/ArrayHelper.cs | 33 ++--
.../AutoRefreshTime.cs | 73 +++++----
.../AutoRefreshTimeInfo.cs | 59 ++++---
.../ClipboardHelper.cs | 21 ++-
.../NETworkManager.Utilities/CryptoHelper.cs | 111 +++++++------
.../NETworkManager.Utilities/CustomCommand.cs | 23 ++-
.../CustomCommandInfo.cs | 115 +++++++-------
.../ExternalProcessStarter.cs | 63 ++++----
.../FileSizeConverter.cs | 131 ++++++++-------
Source/NETworkManager.Utilities/HotKeys.cs | 149 +++++++++---------
Source/NETworkManager.Utilities/ListHelper.cs | 43 +++--
.../LvlChartsDefaultInfo.cs | 20 +--
.../MACAddressHelper.cs | 87 +++++-----
.../NETworkManager.Utilities/NativeMethods.cs | 145 +++++++++--------
.../PortRangeHelper.cs | 45 +++---
.../NETworkManager.Utilities/RegexHelper.cs | 121 +++++++-------
.../NETworkManager.Utilities/RelayCommand.cs | 77 +++++----
.../SecureStringHelper.cs | 45 +++---
.../SingleInstance.cs | 21 ++-
.../NETworkManager.Utilities/SingletonBase.cs | 35 ++--
.../NETworkManager.Utilities/StringHelper.cs | 21 ++-
Source/NETworkManager.Utilities/TimeUnit.cs | 41 +++--
.../TimestampHelper.cs | 11 +-
.../VisualTreeHelper.cs | 31 ++--
25 files changed, 818 insertions(+), 842 deletions(-)
diff --git a/Source/NETworkManager.Update/Updater.cs b/Source/NETworkManager.Update/Updater.cs
index 5478fe93f2..564c78e619 100644
--- a/Source/NETworkManager.Update/Updater.cs
+++ b/Source/NETworkManager.Update/Updater.cs
@@ -2,89 +2,88 @@
using System.Threading.Tasks;
using Octokit;
-namespace NETworkManager.Update
+namespace NETworkManager.Update;
+
+///
+/// Updater to check if a new program version is available.
+///
+public class Updater
{
+ #region Events
///
- /// Updater to check if a new program version is available.
+ /// Is triggered when update check is complete and an update is available.
///
- public class Updater
- {
- #region Events
- ///
- /// Is triggered when update check is complete and an update is available.
- ///
- public event EventHandler UpdateAvailable;
+ public event EventHandler UpdateAvailable;
- ///
- /// Triggers the event.
- ///
- /// Passes to the event.
- protected virtual void OnUpdateAvailable(UpdateAvailableArgs e)
- {
- UpdateAvailable?.Invoke(this, e);
- }
+ ///
+ /// Triggers the event.
+ ///
+ /// Passes to the event.
+ protected virtual void OnUpdateAvailable(UpdateAvailableArgs e)
+ {
+ UpdateAvailable?.Invoke(this, e);
+ }
- ///
- /// Is triggered when update check is complete and no update is available.
- ///
- public event EventHandler NoUpdateAvailable;
+ ///
+ /// Is triggered when update check is complete and no update is available.
+ ///
+ public event EventHandler NoUpdateAvailable;
- ///
- /// Triggers the event.
- ///
- protected virtual void OnNoUpdateAvailable()
- {
- NoUpdateAvailable?.Invoke(this, EventArgs.Empty);
- }
+ ///
+ /// Triggers the event.
+ ///
+ protected virtual void OnNoUpdateAvailable()
+ {
+ NoUpdateAvailable?.Invoke(this, EventArgs.Empty);
+ }
- ///
- /// Is triggered when an error occurs during the update check.
- ///
- public event EventHandler Error;
+ ///
+ /// Is triggered when an error occurs during the update check.
+ ///
+ public event EventHandler Error;
- ///
- /// Triggers the event.
- ///
- protected virtual void OnError()
- {
- Error?.Invoke(this, EventArgs.Empty);
- }
- #endregion
+ ///
+ /// Triggers the event.
+ ///
+ protected virtual void OnError()
+ {
+ Error?.Invoke(this, EventArgs.Empty);
+ }
+ #endregion
- #region Methods
- ///
- /// Checks on GitHub whether a new version of the program is available
- ///
- /// GitHub username like "BornToBeRoot".
- /// GitHub repository like "NETworkManager".
- /// Version like 1.2.0.0.
- public void CheckOnGitHub(string userName, string projectName, Version currentVersion, bool includePreRelease)
+ #region Methods
+ ///
+ /// Checks on GitHub whether a new version of the program is available
+ ///
+ /// GitHub username like "BornToBeRoot".
+ /// GitHub repository like "NETworkManager".
+ /// Version like 1.2.0.0.
+ public void CheckOnGitHub(string userName, string projectName, Version currentVersion, bool includePreRelease)
+ {
+ Task.Run(() =>
{
- Task.Run(() =>
+ try
{
- try
- {
- var client = new GitHubClient(new ProductHeaderValue(userName + "_" + projectName));
+ var client = new GitHubClient(new ProductHeaderValue(userName + "_" + projectName));
- Release release = null;
+ Release release = null;
- if (includePreRelease)
- release = client.Repository.Release.GetAll(userName, projectName).Result[0];
- else
- release = client.Repository.Release.GetLatest(userName, projectName).Result;
+ if (includePreRelease)
+ release = client.Repository.Release.GetAll(userName, projectName).Result[0];
+ else
+ release = client.Repository.Release.GetLatest(userName, projectName).Result;
- // Compare versions (tag=2021.2.15.0, version=2021.2.15.0)
- if (new Version(release.TagName) > currentVersion)
- OnUpdateAvailable(new UpdateAvailableArgs(release));
- else
- OnNoUpdateAvailable();
- }
- catch
- {
- OnError();
- }
- });
- }
- #endregion
+ // Compare versions (tag=2021.2.15.0, version=2021.2.15.0)
+ if (new Version(release.TagName) > currentVersion)
+ OnUpdateAvailable(new UpdateAvailableArgs(release));
+ else
+ OnNoUpdateAvailable();
+ }
+ catch
+ {
+ OnError();
+ }
+ });
}
+ #endregion
}
diff --git a/Source/NETworkManager.Utilities/ArrayHelper.cs b/Source/NETworkManager.Utilities/ArrayHelper.cs
index 418cb3ced3..e07cacf6ec 100644
--- a/Source/NETworkManager.Utilities/ArrayHelper.cs
+++ b/Source/NETworkManager.Utilities/ArrayHelper.cs
@@ -1,25 +1,24 @@
using System;
-namespace NETworkManager.Utilities
+namespace NETworkManager.Utilities;
+
+///
+/// Collection of useful methods to interact with an array.
+///
+public static class ArrayHelper
{
///
- /// Collection of useful methods to interact with an array.
+ /// Create a sub array from an array.
///
- public static class ArrayHelper
+ /// Object array.
+ /// Any array.
+ /// Start index.
+ /// Length of the new array.
+ /// Sub array of the array.
+ public static T[] SubArray(this T[] data, int index, int length)
{
- ///
- /// Create a sub array from an array.
- ///
- /// Object array.
- /// Any array.
- /// Start index.
- /// Length of the new array.
- /// Sub array of the array.
- public static T[] SubArray(this T[] data, int index, int length)
- {
- var result = new T[length];
- Array.Copy(data, index, result, 0, length);
- return result;
- }
+ var result = new T[length];
+ Array.Copy(data, index, result, 0, length);
+ return result;
}
}
diff --git a/Source/NETworkManager.Utilities/AutoRefreshTime.cs b/Source/NETworkManager.Utilities/AutoRefreshTime.cs
index f42018f3dc..5c69125bb1 100644
--- a/Source/NETworkManager.Utilities/AutoRefreshTime.cs
+++ b/Source/NETworkManager.Utilities/AutoRefreshTime.cs
@@ -1,47 +1,46 @@
using System;
using System.Collections.Generic;
-namespace NETworkManager.Utilities
+namespace NETworkManager.Utilities;
+
+///
+/// Class provides static methods to manage auto refresh time.
+///
+public static class AutoRefreshTime
{
///
- /// Class provides static methods to manage auto refresh time.
+ /// Method returns a list with default s.
///
- public static class AutoRefreshTime
+ public static IEnumerable GetDefaults => new List
{
- ///
- /// Method returns a list with default s.
- ///
- public static IEnumerable GetDefaults => new List
- {
- new AutoRefreshTimeInfo(5, TimeUnit.Second),
- new AutoRefreshTimeInfo(15, TimeUnit.Second),
- new AutoRefreshTimeInfo(30, TimeUnit.Second),
- new AutoRefreshTimeInfo(1, TimeUnit.Minute),
- new AutoRefreshTimeInfo(5, TimeUnit.Minute),
- };
+ new AutoRefreshTimeInfo(5, TimeUnit.Second),
+ new AutoRefreshTimeInfo(15, TimeUnit.Second),
+ new AutoRefreshTimeInfo(30, TimeUnit.Second),
+ new AutoRefreshTimeInfo(1, TimeUnit.Minute),
+ new AutoRefreshTimeInfo(5, TimeUnit.Minute),
+ };
- ///
- /// Method to calculate a based on .
- ///
- /// to calculate
- /// Returns the calculated .
- public static TimeSpan CalculateTimeSpan(AutoRefreshTimeInfo info)
+ ///
+ /// Method to calculate a based on .
+ ///
+ /// to calculate
+ /// Returns the calculated .
+ public static TimeSpan CalculateTimeSpan(AutoRefreshTimeInfo info)
+ {
+ switch (info.TimeUnit)
{
- switch (info.TimeUnit)
- {
- // Calculate the seconds
- case TimeUnit.Second:
- return new TimeSpan(0, 0, info.Value);
- // Calculate the minutes
- case TimeUnit.Minute:
- return new TimeSpan(0, info.Value * 60, 0);
- // Calculate the hours
- case TimeUnit.Hour:
- return new TimeSpan(info.Value * 60, 0, 0);
- case TimeUnit.None:
- default:
- throw new Exception("Wrong time unit.");
- }
- }
- }
+ // Calculate the seconds
+ case TimeUnit.Second:
+ return new TimeSpan(0, 0, info.Value);
+ // Calculate the minutes
+ case TimeUnit.Minute:
+ return new TimeSpan(0, info.Value * 60, 0);
+ // Calculate the hours
+ case TimeUnit.Hour:
+ return new TimeSpan(info.Value * 60, 0, 0);
+ case TimeUnit.None:
+ default:
+ throw new Exception("Wrong time unit.");
+ }
+ }
}
\ No newline at end of file
diff --git a/Source/NETworkManager.Utilities/AutoRefreshTimeInfo.cs b/Source/NETworkManager.Utilities/AutoRefreshTimeInfo.cs
index 0093f4f34a..40c044f153 100644
--- a/Source/NETworkManager.Utilities/AutoRefreshTimeInfo.cs
+++ b/Source/NETworkManager.Utilities/AutoRefreshTimeInfo.cs
@@ -1,38 +1,37 @@
-namespace NETworkManager.Utilities
+namespace NETworkManager.Utilities;
+
+///
+/// Class stores auto refresh time informations.
+///
+public class AutoRefreshTimeInfo
{
///
- /// Class stores auto refresh time informations.
+ /// Value is combined with .
+ /// Example: 5 Mintues, 2 Hours.
///
- public class AutoRefreshTimeInfo
- {
- ///
- /// Value is combined with .
- /// Example: 5 Mintues, 2 Hours.
- ///
- public int Value { get; set; }
+ public int Value { get; set; }
- ///
- /// is combined with .
- ///
- public TimeUnit TimeUnit { get; set; }
+ ///
+ /// is combined with .
+ ///
+ public TimeUnit TimeUnit { get; set; }
- ///
- /// Initializes a new instance of the class.
- ///
- public AutoRefreshTimeInfo()
- {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public AutoRefreshTimeInfo()
+ {
- }
+ }
- ///
- /// Initializes a new instance of the class with parameters.
- ///
- /// .
- /// .
- public AutoRefreshTimeInfo(int value, TimeUnit timenUnit)
- {
- Value = value;
- TimeUnit = timenUnit;
- }
+ ///
+ /// Initializes a new instance of the class with parameters.
+ ///
+ /// .
+ /// .
+ public AutoRefreshTimeInfo(int value, TimeUnit timenUnit)
+ {
+ Value = value;
+ TimeUnit = timenUnit;
}
-}
\ No newline at end of file
+}
diff --git a/Source/NETworkManager.Utilities/ClipboardHelper.cs b/Source/NETworkManager.Utilities/ClipboardHelper.cs
index a93ef271c2..80a9ccae2f 100644
--- a/Source/NETworkManager.Utilities/ClipboardHelper.cs
+++ b/Source/NETworkManager.Utilities/ClipboardHelper.cs
@@ -1,19 +1,18 @@
using System.Windows;
-namespace NETworkManager.Utilities
+namespace NETworkManager.Utilities;
+
+///
+/// Class provides static methods to interact with the clipboard.
+///
+public static class ClipboardHelper
{
///
- /// Class provides static methods to interact with the clipboard.
+ /// Methods to set a text to the clipboard.
///
- public static class ClipboardHelper
+ /// Some text...
+ public static void SetClipboard(string text)
{
- ///
- /// Methods to set a text to the clipboard.
- ///
- /// Some text...
- public static void SetClipboard(string text)
- {
- Clipboard.SetDataObject(text, true);
- }
+ Clipboard.SetDataObject(text, true);
}
}
diff --git a/Source/NETworkManager.Utilities/CryptoHelper.cs b/Source/NETworkManager.Utilities/CryptoHelper.cs
index 69b1300dcf..3bec1a31ea 100644
--- a/Source/NETworkManager.Utilities/CryptoHelper.cs
+++ b/Source/NETworkManager.Utilities/CryptoHelper.cs
@@ -1,63 +1,62 @@
using System;
using System.Security.Cryptography;
-namespace NETworkManager.Utilities
+namespace NETworkManager.Utilities;
+
+public static class CryptoHelper
{
- public static class CryptoHelper
+ private static readonly int blockSize = 128;
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static byte[] Encrypt(byte[] decryptedBytes, string password, int keySize, int iterations)
{
- private static readonly int blockSize = 128;
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static byte[] Encrypt(byte[] decryptedBytes, string password, int keySize, int iterations)
- {
- ReadOnlySpan salt = RandomNumberGenerator.GetBytes(keySize / 8); // Generate salt based
- ReadOnlySpan iv = RandomNumberGenerator.GetBytes(blockSize / 8); // Generate iv, has to be the same as the block size
-
- byte[] key = Rfc2898DeriveBytes.Pbkdf2(password, salt, iterations, HashAlgorithmName.SHA512, keySize / 8);
-
- using Aes aes = Aes.Create();
- aes.Key = key;
-
- int encryptedSize = aes.GetCiphertextLengthCbc(decryptedBytes.Length);
-
- byte[] cipher = new byte[salt.Length + iv.Length + encryptedSize];
-
- Span cipherSpan = cipher;
-
- salt.CopyTo(cipherSpan);
- iv.CopyTo(cipherSpan[salt.Length..]);
-
- int encrypted = aes.EncryptCbc(decryptedBytes, iv, cipherSpan[(salt.Length + iv.Length)..]);
-
- return cipher;
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static byte[] Decrypt(byte[] encryptedBytesWithSaltAndIV, string password, int keySize, int iterations)
- {
- ReadOnlySpan salt = encryptedBytesWithSaltAndIV.AsSpan(0, keySize / 8); // Take salt bytes
- ReadOnlySpan iv = encryptedBytesWithSaltAndIV.AsSpan(keySize / 8, blockSize / 8); // Skip salt bytes, take iv bytes
- ReadOnlySpan cipher = encryptedBytesWithSaltAndIV.AsSpan((keySize / 8) + (blockSize / 8));
-
- byte[] key = Rfc2898DeriveBytes.Pbkdf2(password, salt, iterations, HashAlgorithmName.SHA512, keySize / 8);
-
- using Aes aes = Aes.Create();
- aes.Key = key;
-
- return aes.DecryptCbc(cipher, iv);
- }
+ ReadOnlySpan salt = RandomNumberGenerator.GetBytes(keySize / 8); // Generate salt based
+ ReadOnlySpan iv = RandomNumberGenerator.GetBytes(blockSize / 8); // Generate iv, has to be the same as the block size
+
+ byte[] key = Rfc2898DeriveBytes.Pbkdf2(password, salt, iterations, HashAlgorithmName.SHA512, keySize / 8);
+
+ using Aes aes = Aes.Create();
+ aes.Key = key;
+
+ int encryptedSize = aes.GetCiphertextLengthCbc(decryptedBytes.Length);
+
+ byte[] cipher = new byte[salt.Length + iv.Length + encryptedSize];
+
+ Span cipherSpan = cipher;
+
+ salt.CopyTo(cipherSpan);
+ iv.CopyTo(cipherSpan[salt.Length..]);
+
+ int encrypted = aes.EncryptCbc(decryptedBytes, iv, cipherSpan[(salt.Length + iv.Length)..]);
+
+ return cipher;
+ }
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static byte[] Decrypt(byte[] encryptedBytesWithSaltAndIV, string password, int keySize, int iterations)
+ {
+ ReadOnlySpan salt = encryptedBytesWithSaltAndIV.AsSpan(0, keySize / 8); // Take salt bytes
+ ReadOnlySpan iv = encryptedBytesWithSaltAndIV.AsSpan(keySize / 8, blockSize / 8); // Skip salt bytes, take iv bytes
+ ReadOnlySpan cipher = encryptedBytesWithSaltAndIV.AsSpan((keySize / 8) + (blockSize / 8));
+
+ byte[] key = Rfc2898DeriveBytes.Pbkdf2(password, salt, iterations, HashAlgorithmName.SHA512, keySize / 8);
+
+ using Aes aes = Aes.Create();
+ aes.Key = key;
+
+ return aes.DecryptCbc(cipher, iv);
}
}
diff --git a/Source/NETworkManager.Utilities/CustomCommand.cs b/Source/NETworkManager.Utilities/CustomCommand.cs
index 9158526211..130bea5f94 100644
--- a/Source/NETworkManager.Utilities/CustomCommand.cs
+++ b/Source/NETworkManager.Utilities/CustomCommand.cs
@@ -1,17 +1,16 @@
-namespace NETworkManager.Utilities
+namespace NETworkManager.Utilities;
+
+///
+/// Class provides static methods to manage custom commands.
+///
+public static class CustomCommand
{
///
- /// Class provides static methods to manage custom commands.
+ /// Method to execute a .
///
- public static class CustomCommand
+ /// which is executed.
+ public static void Run(CustomCommandInfo info)
{
- ///
- /// Method to execute a .
- ///
- /// which is executed.
- public static void Run(CustomCommandInfo info)
- {
- ExternalProcessStarter.RunProcess(info.FilePath, info.Arguments);
- }
+ ExternalProcessStarter.RunProcess(info.FilePath, info.Arguments);
}
-}
\ No newline at end of file
+}
diff --git a/Source/NETworkManager.Utilities/CustomCommandInfo.cs b/Source/NETworkManager.Utilities/CustomCommandInfo.cs
index c11db8b4b4..d80284d360 100644
--- a/Source/NETworkManager.Utilities/CustomCommandInfo.cs
+++ b/Source/NETworkManager.Utilities/CustomCommandInfo.cs
@@ -1,71 +1,70 @@
using System;
-namespace NETworkManager.Utilities
+namespace NETworkManager.Utilities;
+
+///
+/// Class stores custom command informations.
+///
+public class CustomCommandInfo : ICloneable
{
///
- /// Class stores custom command informations.
+ /// Unique Identifiert for this custom command.
///
- public class CustomCommandInfo : ICloneable
- {
- ///
- /// Unique Identifiert for this custom command.
- ///
- public Guid ID { get; set; }
+ public Guid ID { get; set; }
- ///
- /// Name of this custom command.
- ///
- public string Name { get; set; }
+ ///
+ /// Name of this custom command.
+ ///
+ public string Name { get; set; }
- ///
- /// Filepath to the application to execute.
- ///
- public string FilePath { get; set; }
+ ///
+ /// Filepath to the application to execute.
+ ///
+ public string FilePath { get; set; }
- ///
- /// Arguments to start the application.
- ///
- public string Arguments { get; set; }
+ ///
+ /// Arguments to start the application.
+ ///
+ public string Arguments { get; set; }
- ///
- /// Create an empty with an
- ///
- public CustomCommandInfo()
- {
- ID = Guid.NewGuid();
- }
+ ///
+ /// Create an empty with an
+ ///
+ public CustomCommandInfo()
+ {
+ ID = Guid.NewGuid();
+ }
- ///
- /// Create an .
- ///
- /// .
- /// .
- /// .
- public CustomCommandInfo(Guid id, string name, string filePath)
- {
- ID = id;
- Name = name;
- FilePath = filePath;
- }
+ ///
+ /// Create an .
+ ///
+ /// .
+ /// .
+ /// .
+ public CustomCommandInfo(Guid id, string name, string filePath)
+ {
+ ID = id;
+ Name = name;
+ FilePath = filePath;
+ }
- ///
- /// Create an .
- ///
- /// .
- /// .
- /// .
- /// .
- public CustomCommandInfo(Guid id, string name, string filePath, string arguments) : this(id, name, filePath)
- {
- Arguments = arguments;
- }
+ ///
+ /// Create an .
+ ///
+ /// .
+ /// .
+ /// .
+ /// .
+ public CustomCommandInfo(Guid id, string name, string filePath, string arguments) : this(id, name, filePath)
+ {
+ Arguments = arguments;
+ }
- ///
- /// Method to clone this object.
- ///
- public object Clone()
- {
- return MemberwiseClone();
- }
+ ///
+ /// Method to clone this object.
+ ///
+ public object Clone()
+ {
+ return MemberwiseClone();
}
-}
\ No newline at end of file
+}
diff --git a/Source/NETworkManager.Utilities/ExternalProcessStarter.cs b/Source/NETworkManager.Utilities/ExternalProcessStarter.cs
index b215a52707..61b9b434c8 100644
--- a/Source/NETworkManager.Utilities/ExternalProcessStarter.cs
+++ b/Source/NETworkManager.Utilities/ExternalProcessStarter.cs
@@ -1,46 +1,45 @@
using System.Diagnostics;
-namespace NETworkManager.Utilities
+namespace NETworkManager.Utilities;
+
+public static class ExternalProcessStarter
{
- public static class ExternalProcessStarter
+ ///
+ /// Open an url with the default browser.
+ ///
+ /// Url like: https://github.com/BornToBeRoot
+ public static void OpenUrl(string url)
{
- ///
- /// Open an url with the default browser.
- ///
- /// Url like: https://github.com/BornToBeRoot
- public static void OpenUrl(string url)
- {
- // Escape the $ in the command promp
- url = url.Replace("&", "^&");
+ // Escape the $ in the command promp
+ url = url.Replace("&", "^&");
- Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true });
- }
+ Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true });
+ }
- public static void RunProcess(string filename)
- {
- RunProcess(filename, false);
- }
+ public static void RunProcess(string filename)
+ {
+ RunProcess(filename, false);
+ }
- public static void RunProcess(string filename, bool asAdmin)
- {
- RunProcess(filename, "", asAdmin);
- }
+ public static void RunProcess(string filename, bool asAdmin)
+ {
+ RunProcess(filename, "", asAdmin);
+ }
- public static void RunProcess(string filename, string arguments = "", bool asAdmin = false)
+ public static void RunProcess(string filename, string arguments = "", bool asAdmin = false)
+ {
+ ProcessStartInfo info = new()
{
- ProcessStartInfo info = new()
- {
- FileName = filename,
- UseShellExecute = true
- };
+ FileName = filename,
+ UseShellExecute = true
+ };
- if (!string.IsNullOrEmpty(arguments))
- info.Arguments = arguments;
+ if (!string.IsNullOrEmpty(arguments))
+ info.Arguments = arguments;
- if (asAdmin)
- info.Verb = "runas";
+ if (asAdmin)
+ info.Verb = "runas";
- Process.Start(info);
- }
+ Process.Start(info);
}
}
diff --git a/Source/NETworkManager.Utilities/FileSizeConverter.cs b/Source/NETworkManager.Utilities/FileSizeConverter.cs
index 7b4e4cc714..fd3b897d9c 100644
--- a/Source/NETworkManager.Utilities/FileSizeConverter.cs
+++ b/Source/NETworkManager.Utilities/FileSizeConverter.cs
@@ -1,77 +1,76 @@
-namespace NETworkManager.Utilities
+namespace NETworkManager.Utilities;
+
+///
+/// Class provides static methods to convert file size.
+///
+public static class FileSizeConverter
{
///
- /// Class provides static methods to convert file size.
+ /// Returns the human-readable file size for an arbitrary, 64-bit file size.
+ /// The default format is "0.### XB", e.g. "4.2 KB" or "1.434 GB".
+ /// See also: https://stackoverflow.com/questions/281640/how-do-i-get-a-human-readable-file-size-in-bytes-abbreviation-using-net
///
- public static class FileSizeConverter
+ /// File size as to convert.
+ /// File size as human readable .
+ public static string GetBytesReadable(long i)
{
- ///
- /// Returns the human-readable file size for an arbitrary, 64-bit file size.
- /// The default format is "0.### XB", e.g. "4.2 KB" or "1.434 GB".
- /// See also: https://stackoverflow.com/questions/281640/how-do-i-get-a-human-readable-file-size-in-bytes-abbreviation-using-net
- ///
- /// File size as to convert.
- /// File size as human readable .
- public static string GetBytesReadable(long i)
- {
- // Get absolute value
- var absolute_i = (i < 0 ? -i : i);
-
- // Determine the suffix and readable value
- string suffix;
- double readable;
+ // Get absolute value
+ var absolute_i = (i < 0 ? -i : i);
- if (absolute_i >= 0x1000000000000000) // Exabyte
- {
- suffix = "EB";
- readable = (i >> 50);
- }
- else if (absolute_i >= 0x4000000000000) // Petabyte
- {
- suffix = "PB";
- readable = (i >> 40);
- }
- else if (absolute_i >= 0x10000000000) // Terabyte
- {
- suffix = "TB";
- readable = (i >> 30);
- }
- else if (absolute_i >= 0x40000000) // Gigabyte
- {
- suffix = "GB";
- readable = (i >> 20);
- }
- else if (absolute_i >= 0x100000) // Megabyte
- {
- suffix = "MB";
- readable = (i >> 10);
- }
- else if (absolute_i >= 0x400) // Kilobyte
- {
- suffix = "KB";
- readable = i;
- }
- else
- {
- return i.ToString("0 B"); // Byte
- }
+ // Determine the suffix and readable value
+ string suffix;
+ double readable;
- // Divide by 1024 to get fractional value
- readable /= 1024;
-
- // Return formatted number with suffix
- return readable.ToString("0.## ") + suffix;
+ if (absolute_i >= 0x1000000000000000) // Exabyte
+ {
+ suffix = "EB";
+ readable = (i >> 50);
}
-
- ///
- /// Method to convert speed as bytes to human readable string.
- ///
- /// Bytes as .
- /// Suffix which is appended to the converted bytes.
- /// Speed as human readable .
- public static string GetBytesSpeedReadable(long i, string suffix)
+ else if (absolute_i >= 0x4000000000000) // Petabyte
+ {
+ suffix = "PB";
+ readable = (i >> 40);
+ }
+ else if (absolute_i >= 0x10000000000) // Terabyte
+ {
+ suffix = "TB";
+ readable = (i >> 30);
+ }
+ else if (absolute_i >= 0x40000000) // Gigabyte
+ {
+ suffix = "GB";
+ readable = (i >> 20);
+ }
+ else if (absolute_i >= 0x100000) // Megabyte
{
- return GetBytesReadable(i) + suffix;
+ suffix = "MB";
+ readable = (i >> 10);
}
+ else if (absolute_i >= 0x400) // Kilobyte
+ {
+ suffix = "KB";
+ readable = i;
+ }
+ else
+ {
+ return i.ToString("0 B"); // Byte
+ }
+
+ // Divide by 1024 to get fractional value
+ readable /= 1024;
+
+ // Return formatted number with suffix
+ return readable.ToString("0.## ") + suffix;
+ }
+
+ ///
+ /// Method to convert speed as bytes to human readable string.
+ ///
+ /// Bytes as .
+ /// Suffix which is appended to the converted bytes.
+ /// Speed as human readable .
+ public static string GetBytesSpeedReadable(long i, string suffix)
+ {
+ return GetBytesReadable(i) + suffix;
}
}
diff --git a/Source/NETworkManager.Utilities/HotKeys.cs b/Source/NETworkManager.Utilities/HotKeys.cs
index a097506e57..6b96595887 100644
--- a/Source/NETworkManager.Utilities/HotKeys.cs
+++ b/Source/NETworkManager.Utilities/HotKeys.cs
@@ -1,98 +1,97 @@
using System.Windows.Input;
-namespace NETworkManager.Utilities
+namespace NETworkManager.Utilities;
+
+///
+/// Class provides static methods for hotkeys.
+///
+public static class HotKeys
{
///
- /// Class provides static methods for hotkeys.
+ /// Method to calculate the sum of the modifier keys.
///
- public static class HotKeys
+ /// .
+ /// Sum of the calculated modifier keys.
+ public static int GetModifierKeysSum(ModifierKeys modifierKeys)
{
- ///
- /// Method to calculate the sum of the modifier keys.
- ///
- /// .
- /// Sum of the calculated modifier keys.
- public static int GetModifierKeysSum(ModifierKeys modifierKeys)
- {
- var sum = 0x0000;
+ var sum = 0x0000;
- if (modifierKeys.HasFlag(ModifierKeys.Alt))
- sum += 0x0001;
+ if (modifierKeys.HasFlag(ModifierKeys.Alt))
+ sum += 0x0001;
- if (modifierKeys.HasFlag(ModifierKeys.Control))
- sum += 0x0002;
+ if (modifierKeys.HasFlag(ModifierKeys.Control))
+ sum += 0x0002;
- if (modifierKeys.HasFlag(ModifierKeys.Shift))
- sum += 0x0004;
+ if (modifierKeys.HasFlag(ModifierKeys.Shift))
+ sum += 0x0004;
- if (modifierKeys.HasFlag(ModifierKeys.Windows))
- sum += 0x0008;
+ if (modifierKeys.HasFlag(ModifierKeys.Windows))
+ sum += 0x0008;
- return sum;
- }
+ return sum;
+ }
- ///
- /// Method to convert WPF key to WinForms key.
- ///
- /// WPF key.
- /// WinForms key.
- public static System.Windows.Forms.Keys WpfKeyToFormsKeys(Key key)
- {
- return (System.Windows.Forms.Keys)KeyInterop.VirtualKeyFromKey(key);
- }
+ ///
+ /// Method to convert WPF key to WinForms key.
+ ///
+ /// WPF key.
+ /// WinForms key.
+ public static System.Windows.Forms.Keys WpfKeyToFormsKeys(Key key)
+ {
+ return (System.Windows.Forms.Keys)KeyInterop.VirtualKeyFromKey(key);
+ }
+
+ ///
+ /// Method to convert WinForms key to WPF key.
+ ///
+ /// WinForms key.
+ /// WPF key.
+ public static Key FormsKeysToWpfKey(System.Windows.Forms.Keys keys)
+ {
+ return FormsKeysToWpfKey((int)keys);
+ }
+
+ ///
+ /// Method to convert WinForms key to WPF key.
+ ///
+ /// WinForms key as .
+ /// WPF key.
+
+ public static Key FormsKeysToWpfKey(int keys)
+ {
+ return KeyInterop.KeyFromVirtualKey(keys);
+ }
- ///
- /// Method to convert WinForms key to WPF key.
- ///
- /// WinForms key.
- /// WPF key.
- public static Key FormsKeysToWpfKey(System.Windows.Forms.Keys keys)
+ ///
+ /// Method to get modifier keys from an value.
+ ///
+ /// Modifier key as .
+ /// Return .
+ public static ModifierKeys GetModifierKeysFromInt(int modifierKeys)
+ {
+ var modKeys = ModifierKeys.None;
+
+ if (modifierKeys - 0x0008 >= 0)
{
- return FormsKeysToWpfKey((int)keys);
+ modKeys |= ModifierKeys.Windows;
+ modifierKeys -= 0x0008;
}
- ///
- /// Method to convert WinForms key to WPF key.
- ///
- /// WinForms key as .
- /// WPF key.
-
- public static Key FormsKeysToWpfKey(int keys)
+ if (modifierKeys - 0x0004 >= 0)
{
- return KeyInterop.KeyFromVirtualKey(keys);
+ modKeys |= ModifierKeys.Shift;
+ modifierKeys -= 0x0004;
}
- ///
- /// Method to get modifier keys from an value.
- ///
- /// Modifier key as .
- /// Return .
- public static ModifierKeys GetModifierKeysFromInt(int modifierKeys)
+ if (modifierKeys - 0x0002 >= 0)
{
- var modKeys = ModifierKeys.None;
-
- if (modifierKeys - 0x0008 >= 0)
- {
- modKeys |= ModifierKeys.Windows;
- modifierKeys -= 0x0008;
- }
-
- if (modifierKeys - 0x0004 >= 0)
- {
- modKeys |= ModifierKeys.Shift;
- modifierKeys -= 0x0004;
- }
-
- if (modifierKeys - 0x0002 >= 0)
- {
- modKeys |= ModifierKeys.Control;
- modifierKeys -= 0x0002;
- }
-
- if (modifierKeys - 0x0001 >= 0)
- modKeys |= ModifierKeys.Alt;
-
- return modKeys;
+ modKeys |= ModifierKeys.Control;
+ modifierKeys -= 0x0002;
}
+
+ if (modifierKeys - 0x0001 >= 0)
+ modKeys |= ModifierKeys.Alt;
+
+ return modKeys;
}
}
diff --git a/Source/NETworkManager.Utilities/ListHelper.cs b/Source/NETworkManager.Utilities/ListHelper.cs
index 099d11ae95..79fef96082 100644
--- a/Source/NETworkManager.Utilities/ListHelper.cs
+++ b/Source/NETworkManager.Utilities/ListHelper.cs
@@ -1,35 +1,34 @@
using System.Collections.Generic;
-namespace NETworkManager.Utilities
+namespace NETworkManager.Utilities;
+
+public static class ListHelper
{
- public static class ListHelper
+ public static List Modify(List list, string entry, int length)
{
- public static List Modify(List list, string entry, int length)
- {
- var index = list.IndexOf(entry);
+ var index = list.IndexOf(entry);
- if (index != -1)
- list.RemoveAt(index);
- else if (list.Count == length)
- list.RemoveAt(length - 1);
+ if (index != -1)
+ list.RemoveAt(index);
+ else if (list.Count == length)
+ list.RemoveAt(length - 1);
- list.Insert(0, entry);
+ list.Insert(0, entry);
- return list;
- }
+ return list;
+ }
- public static List Modify(List list, int entry, int length)
- {
- var index = list.IndexOf(entry);
+ public static List Modify(List list, int entry, int length)
+ {
+ var index = list.IndexOf(entry);
- if (index != -1)
- list.RemoveAt(index);
- else if (list.Count == length)
- list.RemoveAt(length - 1);
+ if (index != -1)
+ list.RemoveAt(index);
+ else if (list.Count == length)
+ list.RemoveAt(length - 1);
- list.Insert(0, entry);
+ list.Insert(0, entry);
- return list;
- }
+ return list;
}
}
diff --git a/Source/NETworkManager.Utilities/LvlChartsDefaultInfo.cs b/Source/NETworkManager.Utilities/LvlChartsDefaultInfo.cs
index 3d31ad5813..853c4dfacd 100644
--- a/Source/NETworkManager.Utilities/LvlChartsDefaultInfo.cs
+++ b/Source/NETworkManager.Utilities/LvlChartsDefaultInfo.cs
@@ -1,15 +1,15 @@
using System;
-namespace NETworkManager.Utilities
+
+namespace NETworkManager.Utilities;
+
+public class LvlChartsDefaultInfo
{
- public class LvlChartsDefaultInfo
- {
- public DateTime DateTime { get; }
- public double Value { get; set; }
+ public DateTime DateTime { get; }
+ public double Value { get; set; }
- public LvlChartsDefaultInfo(DateTime dateTime, double value)
- {
- DateTime = dateTime;
- Value = value;
- }
+ public LvlChartsDefaultInfo(DateTime dateTime, double value)
+ {
+ DateTime = dateTime;
+ Value = value;
}
}
diff --git a/Source/NETworkManager.Utilities/MACAddressHelper.cs b/Source/NETworkManager.Utilities/MACAddressHelper.cs
index 60c6bdca92..9d0b6cc79e 100644
--- a/Source/NETworkManager.Utilities/MACAddressHelper.cs
+++ b/Source/NETworkManager.Utilities/MACAddressHelper.cs
@@ -3,51 +3,50 @@
using System.Net.NetworkInformation;
using System.Text.RegularExpressions;
-namespace NETworkManager.Utilities
+namespace NETworkManager.Utilities;
+
+public static class MACAddressHelper
{
- public static class MACAddressHelper
+ ///
+ /// Convert a MAC-Address to a byte array
+ ///
+ ///
+ ///
+ public static byte[] ConvertStringToByteArray(string macAddress)
+ {
+ // Regex to replace "-" and ":" in MAC-Address
+ var regex = new Regex("[-|:|.]");
+ var mac = regex.Replace(macAddress, "");
+
+ // Build the byte-array
+ var bytes = new byte[mac.Length / 2];
+
+ // Convert the MAC-Address into byte and fill it...
+ for (var i = 0; i < 12; i += 2)
+ bytes[i / 2] = Convert.ToByte(mac.Substring(i, 2), 16);
+
+ return bytes;
+ }
+
+ public static string GetDefaultFormat(string macAddress)
+ {
+ macAddress = macAddress.ToUpper();
+
+ if (macAddress.Contains("-"))
+ return macAddress.Replace("-", ":");
+
+ return !macAddress.Contains(":") ? string.Join(":", Enumerable.Range(0, 6).Select(i => macAddress.Substring(i * 2, 2))) : macAddress;
+ }
+
+ public static string GetDefaultFormat(PhysicalAddress macAddress)
{
- ///
- /// Convert a MAC-Address to a byte array
- ///
- ///
- ///
- public static byte[] ConvertStringToByteArray(string macAddress)
- {
- // Regex to replace "-" and ":" in MAC-Address
- var regex = new Regex("[-|:|.]");
- var mac = regex.Replace(macAddress, "");
-
- // Build the byte-array
- var bytes = new byte[mac.Length / 2];
-
- // Convert the MAC-Address into byte and fill it...
- for (var i = 0; i < 12; i += 2)
- bytes[i / 2] = Convert.ToByte(mac.Substring(i, 2), 16);
-
- return bytes;
- }
-
- public static string GetDefaultFormat(string macAddress)
- {
- macAddress = macAddress.ToUpper();
-
- if (macAddress.Contains("-"))
- return macAddress.Replace("-", ":");
-
- return !macAddress.Contains(":") ? string.Join(":", Enumerable.Range(0, 6).Select(i => macAddress.Substring(i * 2, 2))) : macAddress;
- }
-
- public static string GetDefaultFormat(PhysicalAddress macAddress)
- {
- return GetDefaultFormat(macAddress.ToString());
- }
-
- public static string Format(string macAddress, string separator = "")
- {
- macAddress = macAddress.ToUpper().Replace("-", "").Replace(":", "");
-
- return string.Join(separator, Enumerable.Range(0, 6).Select(i => macAddress.Substring(i * 2, 2)));
- }
+ return GetDefaultFormat(macAddress.ToString());
+ }
+
+ public static string Format(string macAddress, string separator = "")
+ {
+ macAddress = macAddress.ToUpper().Replace("-", "").Replace(":", "");
+
+ return string.Join(separator, Enumerable.Range(0, 6).Select(i => macAddress.Substring(i * 2, 2)));
}
}
diff --git a/Source/NETworkManager.Utilities/NativeMethods.cs b/Source/NETworkManager.Utilities/NativeMethods.cs
index 26262b8173..c89505f38c 100644
--- a/Source/NETworkManager.Utilities/NativeMethods.cs
+++ b/Source/NETworkManager.Utilities/NativeMethods.cs
@@ -4,80 +4,79 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
-namespace NETworkManager.Utilities
+namespace NETworkManager.Utilities;
+
+public class NativeMethods
{
- public class NativeMethods
+ #region Win32 Constants
+ public const int GWL_STYLE = -16;
+ public const int WS_THICKFRAME = 0x00040000;
+ public const int SWP_NOZORDER = 0x0004;
+ public const int SWP_NOACTIVATE = 0x0010;
+ public const long WS_POPUP = 0x80000000L;
+ public const long WS_CAPTION = 0x00C00000L;
+ #endregion
+
+ #region Enum
+
+ public enum WindowShowStyle : uint
{
- #region Win32 Constants
- public const int GWL_STYLE = -16;
- public const int WS_THICKFRAME = 0x00040000;
- public const int SWP_NOZORDER = 0x0004;
- public const int SWP_NOACTIVATE = 0x0010;
- public const long WS_POPUP = 0x80000000L;
- public const long WS_CAPTION = 0x00C00000L;
- #endregion
-
- #region Enum
-
- public enum WindowShowStyle : uint
- {
- Hide = 0,
- ShowNormal = 1,
- ShowMinimized = 2,
- ShowMaximized = 3,
- Maximize = 3,
- ShowNormalNoActivate = 4,
- Show = 5,
- Minimize = 6,
- ShowMinNoActivate = 7,
- ShowNoActivate = 8,
- Restore = 9,
- ShowDefault = 10,
- ForceMinimized = 11
- }
-
- public enum WM : uint
- {
- SYSCOMMAND = 0x0112
- }
- #endregion
-
- #region Pinvoke/Win32 Methods
- [DllImport("user32.dll")]
- public static extern IntPtr GetForegroundWindow();
-
- [DllImport("user32.dll", SetLastError = true)]
- public static extern long SetParent(IntPtr hWndChild, IntPtr hWndParent);
-
- [DllImport("user32.dll", EntryPoint = "GetWindowLongA", SetLastError = true)]
- public static extern long GetWindowLong(IntPtr hWnd, int nIndex);
-
- // http://msdn.microsoft.com/en-us/library/windows/desktop/ms644898%28v=vs.85%29.aspx
- public static IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
- {
- return IntPtr.Size == 8 ? SetWindowLongPtr64(hWnd, nIndex, dwNewLong) : new IntPtr(SetWindowLong32(hWnd, nIndex, dwNewLong));
- }
-
- [DllImport("user32.dll", EntryPoint = "SetWindowLong")]
- private static extern int SetWindowLong32(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
-
- [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")]
- private static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
-
- [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
- public static extern IntPtr SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);
-
- [DllImport("user32.dll", CharSet = CharSet.Auto)]
- public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
-
- [DllImport("user32.dll", SetLastError = true)]
- public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int cx, int cy, bool repaint);
-
- [DllImport("user32.dll")]
- public static extern bool ShowWindow(IntPtr hWnd, WindowShowStyle nCmdShow);
-
- [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- public static extern bool SetForegroundWindow(IntPtr hWnd);
- #endregion
+ Hide = 0,
+ ShowNormal = 1,
+ ShowMinimized = 2,
+ ShowMaximized = 3,
+ Maximize = 3,
+ ShowNormalNoActivate = 4,
+ Show = 5,
+ Minimize = 6,
+ ShowMinNoActivate = 7,
+ ShowNoActivate = 8,
+ Restore = 9,
+ ShowDefault = 10,
+ ForceMinimized = 11
}
+
+ public enum WM : uint
+ {
+ SYSCOMMAND = 0x0112
+ }
+ #endregion
+
+ #region Pinvoke/Win32 Methods
+ [DllImport("user32.dll")]
+ public static extern IntPtr GetForegroundWindow();
+
+ [DllImport("user32.dll", SetLastError = true)]
+ public static extern long SetParent(IntPtr hWndChild, IntPtr hWndParent);
+
+ [DllImport("user32.dll", EntryPoint = "GetWindowLongA", SetLastError = true)]
+ public static extern long GetWindowLong(IntPtr hWnd, int nIndex);
+
+ // http://msdn.microsoft.com/en-us/library/windows/desktop/ms644898%28v=vs.85%29.aspx
+ public static IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
+ {
+ return IntPtr.Size == 8 ? SetWindowLongPtr64(hWnd, nIndex, dwNewLong) : new IntPtr(SetWindowLong32(hWnd, nIndex, dwNewLong));
+ }
+
+ [DllImport("user32.dll", EntryPoint = "SetWindowLong")]
+ private static extern int SetWindowLong32(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
+
+ [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")]
+ private static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
+
+ [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
+ public static extern IntPtr SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);
+
+ [DllImport("user32.dll", CharSet = CharSet.Auto)]
+ public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
+
+ [DllImport("user32.dll", SetLastError = true)]
+ public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int cx, int cy, bool repaint);
+
+ [DllImport("user32.dll")]
+ public static extern bool ShowWindow(IntPtr hWnd, WindowShowStyle nCmdShow);
+
+ [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
+ public static extern bool SetForegroundWindow(IntPtr hWnd);
+ #endregion
}
\ No newline at end of file
diff --git a/Source/NETworkManager.Utilities/PortRangeHelper.cs b/Source/NETworkManager.Utilities/PortRangeHelper.cs
index dbd7217c94..b6afeeaee1 100644
--- a/Source/NETworkManager.Utilities/PortRangeHelper.cs
+++ b/Source/NETworkManager.Utilities/PortRangeHelper.cs
@@ -1,38 +1,37 @@
using System.Threading.Tasks;
using System.Collections.Generic;
-namespace NETworkManager.Utilities
+namespace NETworkManager.Utilities;
+
+public static class PortRangeHelper
{
- public static class PortRangeHelper
+ public static Task ConvertPortRangeToIntArrayAsync(string portRange)
{
- public static Task ConvertPortRangeToIntArrayAsync(string portRange)
- {
- return Task.Run(() => ConvertPortRangeToIntArray(portRange));
- }
+ return Task.Run(() => ConvertPortRangeToIntArray(portRange));
+ }
- // Generate from a string like "9; 11-13; 15" an list with "9,11,12,13,15"
- public static int[] ConvertPortRangeToIntArray(string portRange)
- {
- var list = new List();
+ // Generate from a string like "9; 11-13; 15" an list with "9,11,12,13,15"
+ public static int[] ConvertPortRangeToIntArray(string portRange)
+ {
+ var list = new List();
- foreach (var portOrRange in portRange.Replace(" ", "").Split(';'))
+ foreach (var portOrRange in portRange.Replace(" ", "").Split(';'))
+ {
+ if (portOrRange.Contains("-"))
{
- if (portOrRange.Contains("-"))
- {
- var portRangeSplit = portOrRange.Split('-');
+ var portRangeSplit = portOrRange.Split('-');
- for (var i = int.Parse(portRangeSplit[0]); i < int.Parse(portRangeSplit[1]) + 1; i++)
- {
- list.Add(i);
- }
- }
- else
+ for (var i = int.Parse(portRangeSplit[0]); i < int.Parse(portRangeSplit[1]) + 1; i++)
{
- list.Add(int.Parse(portOrRange));
+ list.Add(i);
}
}
-
- return list.ToArray();
+ else
+ {
+ list.Add(int.Parse(portOrRange));
+ }
}
+
+ return list.ToArray();
}
}
\ No newline at end of file
diff --git a/Source/NETworkManager.Utilities/RegexHelper.cs b/Source/NETworkManager.Utilities/RegexHelper.cs
index cfa91eafe4..cfb0e31cb5 100644
--- a/Source/NETworkManager.Utilities/RegexHelper.cs
+++ b/Source/NETworkManager.Utilities/RegexHelper.cs
@@ -1,87 +1,86 @@
using System.Diagnostics.CodeAnalysis;
-namespace NETworkManager.Utilities
-{
- public static class RegexHelper
- {
- ///
- /// Match an IPv4-Address like 192.168.178.1
- ///
- private const string IPv4AddressValues = @"((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)";
+namespace NETworkManager.Utilities;
- ///
- /// Match exactly an IPv4-Address like 192.168.178.1
- ///
- public const string IPv4AddressRegex = "^" + IPv4AddressValues + "$";
+public static class RegexHelper
+{
+ ///
+ /// Match an IPv4-Address like 192.168.178.1
+ ///
+ private const string IPv4AddressValues = @"((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)";
- // Match IPv4-Address within a string
- public const string IPv4AddressExctractRegex = IPv4AddressValues;
+ ///
+ /// Match exactly an IPv4-Address like 192.168.178.1
+ ///
+ public const string IPv4AddressRegex = "^" + IPv4AddressValues + "$";
- // Match IPv4-Address Range like 192.168.178.1-192.168.178.127
- public const string IPv4AddressRangeRegex = "^" + IPv4AddressValues + "-" + IPv4AddressValues + "$";
+ // Match IPv4-Address within a string
+ public const string IPv4AddressExctractRegex = IPv4AddressValues;
- // Match a MAC-Address 000000000000 00:00:00:00:00:00, 00-00-00-00-00-00-00 or 0000.0000.0000
- public const string MACAddressRegex = @"^^[A-Fa-f0-9]{12}$|^[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}$|^[A-Fa-f0-9]{4}.[A-Fa-f0-9]{4}.[A-Fa-f0-9]{4}$$";
+ // Match IPv4-Address Range like 192.168.178.1-192.168.178.127
+ public const string IPv4AddressRangeRegex = "^" + IPv4AddressValues + "-" + IPv4AddressValues + "$";
- // Matche the first 3 bytes of a MAC-Address 000000, 00:00:00, 00-00-00
- public const string MACAddressFirst3BytesRegex = @"^[A-Fa-f0-9]{6}$|^[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}$|^[A-Fa-f0-9]{4}.[A-Fa-f0-9]{2}$";
+ // Match a MAC-Address 000000000000 00:00:00:00:00:00, 00-00-00-00-00-00-00 or 0000.0000.0000
+ public const string MACAddressRegex = @"^^[A-Fa-f0-9]{12}$|^[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}$|^[A-Fa-f0-9]{4}.[A-Fa-f0-9]{4}.[A-Fa-f0-9]{4}$$";
- // Private subnetmask / cidr values
- private const string SubnetmaskValues = @"(((255\.){3}(255|254|252|248|240|224|192|128|0+))|((255\.){2}(255|254|252|248|240|224|192|128|0+)\.0)|((255\.)(255|254|252|248|240|224|192|128|0+)(\.0+){2})|((255|254|252|248|240|224|192|128|0+)(\.0+){3}))";
- private const string CidrRegex = @"([1-9]|[1-2][0-9]|3[0-2])";
+ // Matche the first 3 bytes of a MAC-Address 000000, 00:00:00, 00-00-00
+ public const string MACAddressFirst3BytesRegex = @"^[A-Fa-f0-9]{6}$|^[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}$|^[A-Fa-f0-9]{4}.[A-Fa-f0-9]{2}$";
- // Match a Subnetmask like 255.255.255.0
- public const string SubnetmaskRegex = @"^" + SubnetmaskValues + @"$";
+ // Private subnetmask / cidr values
+ private const string SubnetmaskValues = @"(((255\.){3}(255|254|252|248|240|224|192|128|0+))|((255\.){2}(255|254|252|248|240|224|192|128|0+)\.0)|((255\.)(255|254|252|248|240|224|192|128|0+)(\.0+){2})|((255|254|252|248|240|224|192|128|0+)(\.0+){3}))";
+ private const string CidrRegex = @"([1-9]|[1-2][0-9]|3[0-2])";
- // Match a subnet from 192.168.178.0/1 to 192.168.178.0/32
- public const string IPv4AddressCidrRegex = @"^" + IPv4AddressValues + @"\/" + CidrRegex + @"$";
+ // Match a Subnetmask like 255.255.255.0
+ public const string SubnetmaskRegex = @"^" + SubnetmaskValues + @"$";
- // Match a subnet from 192.168.178.0/192.0.0.0 to 192.168.178.0/255.255.255.255
- public const string IPv4AddressSubnetmaskRegex = @"^" + IPv4AddressValues + @"\/" + SubnetmaskValues + @"$";
+ // Match a subnet from 192.168.178.0/1 to 192.168.178.0/32
+ public const string IPv4AddressCidrRegex = @"^" + IPv4AddressValues + @"\/" + CidrRegex + @"$";
- // Match IPv6 address like ::1
- public const string IPv6AddressRegex = @"(?:^|(?<=\s))(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))(?=\s|$)";
+ // Match a subnet from 192.168.178.0/192.0.0.0 to 192.168.178.0/255.255.255.255
+ public const string IPv4AddressSubnetmaskRegex = @"^" + IPv4AddressValues + @"\/" + SubnetmaskValues + @"$";
- // Match a subnet like 2001:0db8::/64
- public const string IPv6AddressCidrRegex = @"^s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))(%.+)?s*(\/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])){1}?$";
+ // Match IPv6 address like ::1
+ public const string IPv6AddressRegex = @"(?:^|(?<=\s))(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))(?=\s|$)";
- // Match a range like [0-255], [0,2,4] and [2,4-6]
- public const string SpecialRangeRegex = @"\[((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)-(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))([,]((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)-(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))))*\]";
+ // Match a subnet like 2001:0db8::/64
+ public const string IPv6AddressCidrRegex = @"^s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))(%.+)?s*(\/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])){1}?$";
- // Match a IPv4-Address like 192.168.[50-100].1
- public const string IPv4AddressSpecialRangeRegex = @"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|" + SpecialRangeRegex + @")\.){3}((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|" + SpecialRangeRegex + @")$";
+ // Match a range like [0-255], [0,2,4] and [2,4-6]
+ public const string SpecialRangeRegex = @"\[((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)-(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))([,]((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)-(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))))*\]";
- // Private hostname values
- private const string HostnameValues = @"(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])";
+ // Match a IPv4-Address like 192.168.[50-100].1
+ public const string IPv4AddressSpecialRangeRegex = @"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|" + SpecialRangeRegex + @")\.){3}((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|" + SpecialRangeRegex + @")$";
- // Hostname regex like server-01 or server-01.example.com
- public const string HostnameRegex = @"^" + HostnameValues + @"$";
+ // Private hostname values
+ private const string HostnameValues = @"(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])";
- // Match a hostname with cidr like server-01.example.com/24
- public const string HostnameCidrRegex = @"^" + HostnameValues + @"\/" + CidrRegex + @"$";
+ // Hostname regex like server-01 or server-01.example.com
+ public const string HostnameRegex = @"^" + HostnameValues + @"$";
- // Match a hostname with subnetmask like server-01.example.com/255.255.255.0
- public const string HostnameSubnetmaskRegex = @"^" + HostnameValues + @"\/" + SubnetmaskValues + @"$";
+ // Match a hostname with cidr like server-01.example.com/24
+ public const string HostnameCidrRegex = @"^" + HostnameValues + @"\/" + CidrRegex + @"$";
- // Match a domain local.example.com
- public const string DomainRegex = @"^(?!:\/\/)([a-zA-Z0-9-_]+\.)*[a-zA-Z0-9][a-zA-Z0-9-_]+\.[a-zA-Z]{2,11}?$";
+ // Match a hostname with subnetmask like server-01.example.com/255.255.255.0
+ public const string HostnameSubnetmaskRegex = @"^" + HostnameValues + @"\/" + SubnetmaskValues + @"$";
- // Private port values
- private const string PortValues = @"((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([0-5]{0,5})|([0-9]{1,4}))";
+ // Match a domain local.example.com
+ public const string DomainRegex = @"^(?!:\/\/)([a-zA-Z0-9-_]+\.)*[a-zA-Z0-9][a-zA-Z0-9-_]+\.[a-zA-Z]{2,11}?$";
- // Match a port between 1-65535
- public const string PortRegex = @"^" + PortValues + @"$";
-
- // Match any filepath (like "c:\temp\") --> https://www.codeproject.com/Tips/216238/Regular-Expression-to-Validate-File-Path-and-Exten
- public const string FilePathRegex = @"^(?:[\w]\:|\\)(\\[a-z_\-\s0-9\.]+)+$";
+ // Private port values
+ private const string PortValues = @"((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([0-5]{0,5})|([0-9]{1,4}))";
- // Match any fullname (like "c:\temp\test.txt") --> https://www.codeproject.com/Tips/216238/Regular-Expression-to-Validate-File-Path-and-Exten
- public const string FullNameRegex = @"^(?:[\w]\:|\\)(\\[a-zA-Z0-9_\-\s\.()~!@#$%^&=+';,{}\[\]]+)+\.[a-zA-z0-9]{1,4}$";
+ // Match a port between 1-65535
+ public const string PortRegex = @"^" + PortValues + @"$";
+
+ // Match any filepath (like "c:\temp\") --> https://www.codeproject.com/Tips/216238/Regular-Expression-to-Validate-File-Path-and-Exten
+ public const string FilePathRegex = @"^(?:[\w]\:|\\)(\\[a-z_\-\s0-9\.]+)+$";
- // Match a string that doesn't end with ";" (like "80; ldap; ssh; 443")
- public const string StringNotEndWithSemicolonRegex = @"^.*[^;]$";
+ // Match any fullname (like "c:\temp\test.txt") --> https://www.codeproject.com/Tips/216238/Regular-Expression-to-Validate-File-Path-and-Exten
+ public const string FullNameRegex = @"^(?:[\w]\:|\\)(\\[a-zA-Z0-9_\-\s\.()~!@#$%^&=+';,{}\[\]]+)+\.[a-zA-z0-9]{1,4}$";
- // Match a number (like 12, 12.4, 12,3)
- public const string NumberRegex = @"^\d+((\.|,)\d+)?$";
- }
+ // Match a string that doesn't end with ";" (like "80; ldap; ssh; 443")
+ public const string StringNotEndWithSemicolonRegex = @"^.*[^;]$";
+
+ // Match a number (like 12, 12.4, 12,3)
+ public const string NumberRegex = @"^\d+((\.|,)\d+)?$";
}
diff --git a/Source/NETworkManager.Utilities/RelayCommand.cs b/Source/NETworkManager.Utilities/RelayCommand.cs
index 48bbbb57d3..cea11039db 100644
--- a/Source/NETworkManager.Utilities/RelayCommand.cs
+++ b/Source/NETworkManager.Utilities/RelayCommand.cs
@@ -4,46 +4,45 @@
// Source: https://msdn.microsoft.com/en-us/magazine/dd419663.aspx?f=255&MSPPError=-2147217396#id0090030
-namespace NETworkManager.Utilities
+namespace NETworkManager.Utilities;
+
+public class RelayCommand : ICommand
{
- public class RelayCommand : ICommand
+ #region Fields
+
+ private readonly Action