Skip to content

Commit 885dc2a

Browse files
authored
Merge pull request #50 from PandaTechAM/development
Logging enhancement, RegexBox merge + nuget updates
2 parents e143fd5 + cf79d7f commit 885dc2a

20 files changed

+697
-102
lines changed

Readme.md

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This package currently supports:
2626
- **SignalR Extensions** for adding simple SignalR or distributed SignalR backed with Redis.
2727
- **OpenTelemetry**: Metrics, traces, and logs with Prometheus support.
2828
- **Health Checks**: Startup validation and endpoints for monitoring.
29+
- **ValidationHelper**: A collection of regex-based validators for common data formats.
2930
- Various **Extensions and Utilities**, including enumerable, string, dictionary and queryable extensions.
3031

3132
## Prerequisites
@@ -315,11 +316,12 @@ builder.AddSerilog(
315316
);
316317
```
317318

318-
>- **Asynchronous Sinks (asyncSinks: true):** Recommended for very high-traffic environments (e.g., 1000+ requests per
319-
second per pod) where performance is critical and the possibility of losing a small amount of log data (e.g., on
320-
sudden process termination) is acceptable. <br><br>
321-
>- **Synchronous Sinks (asyncSinks: false):** Recommended if you can handle up to ~1000 requests per second per pod and must
322-
retain every log entry without fail. This might incur slightly more overhead but ensures maximum reliability.
319+
> - **Asynchronous Sinks (asyncSinks: true):** Recommended for very high-traffic environments (e.g., 1000+ requests per
320+
second per pod) where performance is critical and the possibility of losing a small amount of log data (e.g., on
321+
sudden process termination) is acceptable. <br><br>
322+
>- **Synchronous Sinks (asyncSinks: false):** Recommended if you can handle up to ~1000 requests per second per pod and
323+
must
324+
retain every log entry without fail. This might incur slightly more overhead but ensures maximum reliability.
323325

324326
Configure minimal Serilog settings in your environment JSON files as needed, for example in
325327
`appsettings.{Environment}.json`:
@@ -651,6 +653,68 @@ app.MapHealthCheckEndpoints(); // Map health check routes
651653
app.Run();
652654
```
653655

656+
## ValidationHelper
657+
658+
The `ValidationHelper` class is a highly performant and robust C# class designed to simplify complex regex validations
659+
for
660+
various data formats. With 100% test coverage and a focus on security through a 50ms regex execution timeout, it's an
661+
ideal solution for applications requiring reliable and efficient data validation.
662+
663+
```csharp
664+
using Pandatech.RegexBox;
665+
666+
// URI validation
667+
bool isValidUri = ValidationHelper.IsUri("http://example.com", allowNonSecure: false);
668+
669+
// US Social Security Number validation
670+
bool isValidSsnUs = ValidationHelper.IsUsSocialSecurityNumber("123-45-6789");
671+
672+
// Email validation
673+
bool isValidEmail = ValidationHelper.IsEmail("[email protected]");
674+
675+
// Username validation
676+
bool isValidUsername = ValidationHelper.IsUsername("user123");
677+
678+
// Armenian Social Security Number validation
679+
bool isValidSsnAm = ValidationHelper.IsArmeniaSocialSecurityNumber("12345678912");
680+
681+
//ArmenianIDCard validation
682+
bool isValidArmenianIdCard = ValidationHelper.IsArmeniaIdCard("AN1234567");
683+
684+
// Armenian Passport validation
685+
bool isValidArmenianPassport = ValidationHelper.IsArmeniaPassport("AN1234567");
686+
687+
// Armenian Tax code validation
688+
bool isValidArmenianTaxCode = ValidationHelper.IsArmeniaTaxCode("12345678");
689+
690+
// Panda Formatted Phone Number validation
691+
bool isValidPhoneNumber = ValidationHelper.IsPandaFormattedPhoneNumber("(374)94810553");
692+
693+
// Armenian State Registration Number validation
694+
bool isValidArmenianStateRegistrationNumber = ValidationHelper.IsArmeniaStateRegistryNumber("123.456.78");
695+
696+
// Panda formatted phone number validation
697+
698+
bool isValidPandaFormattedPhoneNumber = ValidationHelper.IsPandaFormattedPhoneNumber("(374)94810553");
699+
700+
// Guid validation
701+
bool isValidGuid = ValidationHelper.IsGuid("12345678-1234-1234-1234-123456789012");
702+
703+
// IPv4 validation
704+
bool isValidIpv4 = ValidationHelper.IsIPv4("192.168.1.1");
705+
706+
// IPv6 validation
707+
bool isValidIpv6 = ValidationHelper.IsIPv6("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
708+
709+
// Any IP validation
710+
bool isValidIp = ValidationHelper.IsIpAddress("192.168.1.1");
711+
712+
// Json validation
713+
bool isValidJson = ValidationHelper.IsJson("{\"name\":\"John\", \"age\":30}");
714+
715+
// and many more...
716+
```
717+
654718
## Additional Extensions and NuGet Packages
655719

656720
This package includes various extensions and utilities to aid development:
@@ -671,7 +735,6 @@ This package includes various extensions and utilities to aid development:
671735

672736
- **Pandatech.Crypto:** Provides cryptographic utilities.
673737
- **Pandatech.FluentMinimalApiMapper:** Simplifies mapping in minimal APIs.
674-
- **Pandatech.RegexBox:** A collection of useful regular expressions.
675738
- **Pandatech.ResponseCrafter:** A utility for crafting consistent API responses.
676739
- **Pandatech.DistributedCache:** A distributed cache provider for Redis.
677740
- **Pandatech.FileExporter:** A utility for exporting files.

SharedKernel.Demo/MessageHub.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.AspNetCore.SignalR;
2+
using ResponseCrafter.ExceptionHandlers.SignalR;
3+
4+
namespace SharedKernel.Demo;
5+
6+
public class MessageHub : Hub
7+
{
8+
public async Task SendMessage(SendMessageRequest message)
9+
{
10+
await Clients.All.SendAsync("ReceiveMessage", "Thanks for the message that I have received");
11+
}
12+
}
13+
14+
public class SendMessageRequest : IHubArgument
15+
{
16+
public required string InvocationId { get; set; }
17+
public required string Message { get; set; }
18+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using SharedKernel.Demo2;
66
using ResponseCrafter.Enums;
77
using ResponseCrafter.Extensions;
8+
using SharedKernel.Demo;
89
using SharedKernel.Extensions;
910
using SharedKernel.Helpers;
1011
using SharedKernel.Logging;
@@ -78,6 +79,8 @@
7879
return response;
7980
});
8081

82+
app.MapHub<MessageHub>("/hub");
83+
8184
app.LogStartSuccess();
8285
app.Run();
8386

File renamed without changes.

Shared.Kernel.Demo/Shared.Kernel.Demo.csproj renamed to SharedKernel.Demo/SharedKernel.Demo.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.4" />
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.5" />
1111
</ItemGroup>
1212

1313
<ItemGroup>
File renamed without changes.

SharedKernel.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1717
.editorconfig = .editorconfig
1818
EndProjectSection
1919
EndProject
20-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared.Kernel.Demo", "Shared.Kernel.Demo\Shared.Kernel.Demo.csproj", "{1CD76A30-4A74-4F54-AC0C-AEDD92408553}"
20+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharedKernel.Demo", "SharedKernel.Demo\SharedKernel.Demo.csproj", "{1CD76A30-4A74-4F54-AC0C-AEDD92408553}"
2121
EndProject
2222
Global
2323
GlobalSection(SolutionConfigurationPlatforms) = preSolution

src/SharedKernel/Extensions/CorsExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Microsoft.AspNetCore.Builder;
22
using Microsoft.Extensions.DependencyInjection;
33
using Microsoft.Extensions.Hosting;
4-
using RegexBox;
4+
using SharedKernel.Helpers;
55

66
namespace SharedKernel.Extensions;
77

@@ -56,7 +56,7 @@ private static string[] SplitOrigins(this string input)
5656
result[i] = result[i]
5757
.Trim();
5858

59-
if (PandaValidator.IsUri(result[i], false))
59+
if (ValidationHelper.IsUri(result[i], false))
6060
{
6161
continue;
6262
}

src/SharedKernel/Extensions/SignalRExtensions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using Microsoft.AspNetCore.SignalR;
33
using Microsoft.Extensions.DependencyInjection;
44
using ResponseCrafter.ExceptionHandlers.SignalR;
5+
using Serilog;
6+
using Serilog.Events;
57
using SharedKernel.Logging;
68
using StackExchange.Redis;
79

@@ -35,8 +37,12 @@ private static ISignalRServerBuilder AddSignalRWithFiltersAndMessagePack(this We
3537
return builder.Services
3638
.AddSignalR(o =>
3739
{
40+
if (Log.Logger.IsEnabled(LogEventLevel.Information))
41+
{
42+
o.AddFilter<SignalRLoggingHubFilter>();
43+
}
44+
3845
o.AddFilter<SignalRExceptionFilter>();
39-
o.AddFilter<SignalRLoggingHubFilter>();
4046
})
4147
.AddMessagePackProtocol();
4248
}

0 commit comments

Comments
 (0)