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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,6 @@ dotnet_diagnostic.S6603.severity = none # The collection-specific "T
dotnet_diagnostic.S6605.severity = none # Collection-specific "Exists" method should be used instead of the "Any"
dotnet_diagnostic.S6964.severity = none # Value type property used as input in a controller action should be nullable, required or annotated with the JsonRequiredAttribute to avoid under-posting.


##########################################
# Custom - File Extension Settings
##########################################
Expand Down
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ sample/Atc.Wpf.Sample/ # Demo application

- Framework: XUnit 3 with Microsoft Testing Platform
- WPF-specific testing: Xunit.StaFact (for STA thread tests)
- Test utilities: Atc.XUnit, AutoFixture, FluentAssertions, NSubstitute
- Global usings for test projects include: AutoFixture, FluentAssertions, NSubstitute, Xunit
- Test utilities: Atc.XUnit, AutoFixture, AwesomeAssertions, NSubstitute
- Global usings for test projects include: AutoFixture, AwesomeAssertions, NSubstitute, Xunit

### Test Projects Structure

Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
<ItemGroup Label="Code Analyzers">
<PackageReference Include="Atc.Analyzer" Version="0.1.23" PrivateAssets="All" />
<PackageReference Include="AsyncFixer" Version="2.1.0" PrivateAssets="All" />
<PackageReference Include="Meziantou.Analyzer" Version="3.0.83" PrivateAssets="All" />
<PackageReference Include="Meziantou.Analyzer" Version="3.0.112" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.25.0.139117" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="10.27.0.140913" PrivateAssets="All" />
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions sample/Atc.Wpf.Sample/Atc.Wpf.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="3.0.67" />
<PackageReference Include="Atc" Version="3.0.174" />
<PackageReference Include="Atc.XamlToolkit" Version="3.1.1" />
<PackageReference Include="Atc.XamlToolkit.Wpf" Version="3.1.1" />
<PackageReference Include="ControlzEx" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.7" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="10.0.7" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.7" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="10.0.7" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.9" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="10.0.9" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.9" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="10.0.9" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,42 @@
Grid.Column="1"
Margin="10"
Orientation="Vertical"
Spacing="10" />
Spacing="10">

<atc:LabelEndpointBox
x:Name="EndpointBox6"
Host="opcua.demo-this.com"
IsMandatory="True"
LabelText="Endpoint 6"
NetworkProtocol="OpcTcp"
NetworkValidation="Hostname"
Port="51210"
ShowClearTextButton="True"
WatermarkText="opcua.demo-this.com" />

<atc:LabelEndpointBox
x:Name="EndpointBox7"
Host="opcua.demo-this.com"
IsMandatory="True"
LabelText="Endpoint 7"
NetworkProtocol="OpcTcp"
NetworkValidation="IPv4AddressOrHostname"
Port="51210"
ShowClearTextButton="True"
WatermarkText="192.168.0.27 or opcua.demo-this.com" />

<atc:LabelEndpointBox
x:Name="EndpointBox8"
Host="192.168.0.27"
IsMandatory="True"
LabelText="Endpoint 8"
NetworkProtocol="OpcTcp"
NetworkValidation="IPAddressOrHostname"
Port="51210"
ShowClearTextButton="True"
WatermarkText="192.168.0.27 or opcua.demo-this.com" />

</atc:UniformSpacingPanel>

</atc:GridEx>

Expand Down
2 changes: 1 addition & 1 deletion src/Atc.Wpf.Components/Atc.Wpf.Components.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="3.0.67" />
<PackageReference Include="Atc" Version="3.0.174" />
<PackageReference Include="Atc.XamlToolkit" Version="3.1.1" />
<PackageReference Include="Atc.XamlToolkit.Wpf" Version="3.1.1" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Atc.Wpf.Controls.Sample/Atc.Wpf.Controls.Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="3.0.67" />
<PackageReference Include="Atc" Version="3.0.174" />
<PackageReference Include="Atc.XamlToolkit" Version="3.1.1" />
<PackageReference Include="Atc.XamlToolkit.Wpf" Version="3.1.1" />
<PackageReference Include="MdXaml" Version="1.27.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/Atc.Wpf.Controls/Atc.Wpf.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="3.0.67" />
<PackageReference Include="Atc" Version="3.0.174" />
<PackageReference Include="Atc.UndoRedo" Version="1.1.5" />
<PackageReference Include="Atc.XamlToolkit" Version="3.1.1" />
<PackageReference Include="Atc.XamlToolkit.Wpf" Version="3.1.1" />
Expand Down
2 changes: 1 addition & 1 deletion src/Atc.Wpf.Forms/Atc.Wpf.Forms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="3.0.67" />
<PackageReference Include="Atc" Version="3.0.174" />
<PackageReference Include="Atc.XamlToolkit" Version="3.1.1" />
<PackageReference Include="Atc.XamlToolkit.Wpf" Version="3.1.1" />
</ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions src/Atc.Wpf.Forms/Enums/NetworkValidationRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ public enum NetworkValidationRule
IPAddress,
IPv4Address,
IPv6Address,
Hostname,
IPv4AddressOrHostname,
IPv6AddressOrHostname,
IPAddressOrHostname,
}
20 changes: 20 additions & 0 deletions src/Atc.Wpf.Forms/Enums/TextBoxValidationRuleType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ public enum TextBoxValidationRuleType
/// </summary>
IPv6Address,

/// <summary>
/// Validates DNS host name format only (RFC 1123).
/// </summary>
Hostname,

/// <summary>
/// Validates IPv4 address or DNS host name format.
/// </summary>
IPv4AddressOrHostname,

/// <summary>
/// Validates IPv6 address or DNS host name format.
/// </summary>
IPv6AddressOrHostname,

/// <summary>
/// Validates IPv4/IPv6 address or DNS host name format.
/// </summary>
IPAddressOrHostname,

/// <summary>
/// Validates OPC TCP URL format.
/// </summary>
Expand Down
2 changes: 0 additions & 2 deletions src/Atc.Wpf.Forms/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
global using System.Diagnostics.CodeAnalysis;
global using System.Globalization;
global using System.IO;
global using System.Net;
global using System.Net.Sockets;
global using System.Reflection;
global using System.Runtime.CompilerServices;
global using System.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public static TextBoxValidationRuleType MapNetworkValidationRuleToValidationType
NetworkValidationRule.IPAddress => TextBoxValidationRuleType.IPAddress,
NetworkValidationRule.IPv4Address => TextBoxValidationRuleType.IPv4Address,
NetworkValidationRule.IPv6Address => TextBoxValidationRuleType.IPv6Address,
NetworkValidationRule.Hostname => TextBoxValidationRuleType.Hostname,
NetworkValidationRule.IPv4AddressOrHostname => TextBoxValidationRuleType.IPv4AddressOrHostname,
NetworkValidationRule.IPv6AddressOrHostname => TextBoxValidationRuleType.IPv6AddressOrHostname,
NetworkValidationRule.IPAddressOrHostname => TextBoxValidationRuleType.IPAddressOrHostname,
_ => TextBoxValidationRuleType.None,
};

Expand Down
48 changes: 38 additions & 10 deletions src/Atc.Wpf.Forms/Internal/Helpers/TextBoxValidationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,25 @@ public static (bool IsValid, string ErrorMessage) Validate(
ValidateHexArgb(value, ref isValid, ref errorMessage);
break;
case TextBoxValidationRuleType.IPAddress:
ValidateIpAddress(value, ref isValid, ref errorMessage, allowV4: true, allowV6: true);
ValidateHostOrIp(value, ref isValid, ref errorMessage, allowV4: true, allowV6: true, allowHostname: false);
break;
case TextBoxValidationRuleType.IPv4Address:
ValidateIpAddress(value, ref isValid, ref errorMessage, allowV4: true, allowV6: false);
ValidateHostOrIp(value, ref isValid, ref errorMessage, allowV4: true, allowV6: false, allowHostname: false);
break;
case TextBoxValidationRuleType.IPv6Address:
ValidateIpAddress(value, ref isValid, ref errorMessage, allowV4: false, allowV6: true);
ValidateHostOrIp(value, ref isValid, ref errorMessage, allowV4: false, allowV6: true, allowHostname: false);
break;
case TextBoxValidationRuleType.Hostname:
ValidateHostOrIp(value, ref isValid, ref errorMessage, allowV4: false, allowV6: false, allowHostname: true);
break;
case TextBoxValidationRuleType.IPv4AddressOrHostname:
ValidateHostOrIp(value, ref isValid, ref errorMessage, allowV4: true, allowV6: false, allowHostname: true);
break;
case TextBoxValidationRuleType.IPv6AddressOrHostname:
ValidateHostOrIp(value, ref isValid, ref errorMessage, allowV4: false, allowV6: true, allowHostname: true);
break;
case TextBoxValidationRuleType.IPAddressOrHostname:
ValidateHostOrIp(value, ref isValid, ref errorMessage, allowV4: true, allowV6: true, allowHostname: true);
break;
case TextBoxValidationRuleType.OpcTcp:
ValidateOpcTcp(value, ref isValid, ref errorMessage);
Expand Down Expand Up @@ -176,33 +188,49 @@ private static void ValidateHexArgb(
errorMessage = Validations.InvalidHexArgb;
}

private static void ValidateIpAddress(
private static void ValidateHostOrIp(
string? value,
ref bool isValid,
ref string errorMessage,
bool allowV4,
bool allowV6)
bool allowV6,
bool allowHostname)
{
if (IPAddress.TryParse(value, out var ipAddress))
if (!string.IsNullOrEmpty(value))
{
if (allowV4 && allowV6)
if (allowV4 && value.IsIPv4Address())
{
return;
}

if (allowV4 && ipAddress.AddressFamily == AddressFamily.InterNetwork)
if (allowV6 && value.IsIPv6Address())
{
return;
}

if (allowV6 && ipAddress.AddressFamily == AddressFamily.InterNetworkV6)
// A dotted-numeric string (e.g. "192.168.0.27") is syntactically a valid
// host name, so an IP address is explicitly excluded here; IP input is only
// accepted via the allowV4/allowV6 branches above.
if (allowHostname && value.IsHostName() && !value.IsIPAddress())
{
return;
}
}

isValid = false;
errorMessage = Validations.InvalidIpAddres;

if (!allowHostname)
{
errorMessage = Validations.InvalidIpAddres;
}
else if (allowV4 || allowV6)
{
errorMessage = Validations.InvalidHostnameOrIpAddress;
}
else
{
errorMessage = Validations.InvalidHostname;
}
}

private static void ValidateOpcTcp(
Expand Down
13 changes: 12 additions & 1 deletion src/Atc.Wpf.Forms/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ A labeled control for entering network endpoints (protocol + host + port) with v
| `WatermarkText` | `string` | `"localhost"` | Placeholder text for the host field |
| `ShowClearTextButton` | `bool` | `true` | Show/hide the clear button in host field |
| `HideUpDownButtons` | `bool` | `true` | Show/hide increment/decrement buttons for port |
| `NetworkValidation` | `NetworkValidationRule` | `None` | Additional validation rule for host (IPv4Address, IPv6Address, etc.) |
| `NetworkValidation` | `NetworkValidationRule` | `None` | Additional validation rule for host. One of: `None`, `IPAddress`, `IPv4Address`, `IPv6Address`, `Hostname`, `IPv4AddressOrHostname`, `IPv6AddressOrHostname`, `IPAddressOrHostname` |
| `MinimumPort` | `int` | `1` | Minimum allowed port number |
| `MaximumPort` | `int` | `65535` | Maximum allowed port number |

Expand All @@ -870,6 +870,17 @@ A labeled control for entering network endpoints (protocol + host + port) with v
IsMandatory="True"
WatermarkText="192.168.1.1" />

<!-- OPC TCP endpoint accepting an IPv4 address OR a DNS host name
(e.g. opc.tcp://opcua.demo-this.com:51210/UA/SampleServer) -->
<atc:LabelEndpointBox
LabelText="OPC Server"
NetworkProtocol="OpcTcp"
NetworkValidation="IPv4AddressOrHostname"
Host="opcua.demo-this.com"
Port="51210"
IsMandatory="True"
WatermarkText="192.168.0.27" />

<!-- Binding to a Uri property in ViewModel -->
<atc:LabelEndpointBox
LabelText="Service Endpoint"
Expand Down
18 changes: 18 additions & 0 deletions src/Atc.Wpf.Forms/Resources/Validations.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/Atc.Wpf.Forms/Resources/Validations.da-DK.resx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@
<data name="InvalidHttpUrl" xml:space="preserve">
<value>Ugyldig HTTP webadresse</value>
</data>
<data name="InvalidHostname" xml:space="preserve">
<value>Ugyldigt værtsnavn</value>
</data>
<data name="InvalidHostnameOrIpAddress" xml:space="preserve">
<value>Ugyldigt værtsnavn eller IP addresse</value>
</data>
<data name="InvalidIpAddres" xml:space="preserve">
<value>Ugyldig IP addresse</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions src/Atc.Wpf.Forms/Resources/Validations.de-DE.resx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@
<data name="InvalidHttpUrl" xml:space="preserve">
<value>Ungültige HTTP-URL</value>
</data>
<data name="InvalidHostname" xml:space="preserve">
<value>Ungültiger Hostname</value>
</data>
<data name="InvalidHostnameOrIpAddress" xml:space="preserve">
<value>Ungültiger Hostname oder IP-Adresse</value>
</data>
<data name="InvalidIpAddres" xml:space="preserve">
<value>Ungültige IP-Adresse</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions src/Atc.Wpf.Forms/Resources/Validations.resx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@
<data name="InvalidHttpUrl" xml:space="preserve">
<value>Invalid HTTP url</value>
</data>
<data name="InvalidHostname" xml:space="preserve">
<value>Invalid host name</value>
</data>
<data name="InvalidHostnameOrIpAddress" xml:space="preserve">
<value>Invalid host name or IP address</value>
</data>
<data name="InvalidIpAddres" xml:space="preserve">
<value>Invalid IP address</value>
</data>
Expand Down
2 changes: 1 addition & 1 deletion src/Atc.Wpf.Hardware/Atc.Wpf.Hardware.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="3.0.67" />
<PackageReference Include="Atc" Version="3.0.174" />
<PackageReference Include="Atc.XamlToolkit" Version="3.1.1" />
<PackageReference Include="Atc.XamlToolkit.Wpf" Version="3.1.1" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Atc.Wpf.Network/Atc.Wpf.Network.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="3.0.67" />
<PackageReference Include="Atc" Version="3.0.174" />
<PackageReference Include="Atc.Network" Version="1.0.236" />
<PackageReference Include="Atc.XamlToolkit" Version="3.1.1" />
<PackageReference Include="Atc.XamlToolkit.Wpf" Version="3.1.1" />
Expand Down
Loading
Loading