17
17
18
18
using System . Collections . Generic ;
19
19
using System . Linq ;
20
+ using System . Text . RegularExpressions ;
20
21
using Ardalis . GuardClauses ;
21
22
using FellowOakDicom ;
22
23
using Monai . Deploy . InformaticsGateway . Api ;
@@ -29,7 +30,7 @@ public static class ValidationExtensions
29
30
30
31
public static bool IsValid ( this MonaiApplicationEntity monaiApplicationEntity , out IList < string > validationErrors )
31
32
{
32
- Guard . Against . Null ( monaiApplicationEntity , nameof ( monaiApplicationEntity ) ) ;
33
+ Guard . Against . Null ( monaiApplicationEntity ) ;
33
34
34
35
validationErrors = new List < string > ( ) ;
35
36
@@ -42,7 +43,7 @@ public static bool IsValid(this MonaiApplicationEntity monaiApplicationEntity, o
42
43
43
44
public static bool IsValid ( this DestinationApplicationEntity destinationApplicationEntity , out IList < string > validationErrors )
44
45
{
45
- Guard . Against . Null ( destinationApplicationEntity , nameof ( destinationApplicationEntity ) ) ;
46
+ Guard . Against . Null ( destinationApplicationEntity ) ;
46
47
47
48
validationErrors = new List < string > ( ) ;
48
49
@@ -57,7 +58,7 @@ public static bool IsValid(this DestinationApplicationEntity destinationApplicat
57
58
58
59
public static bool IsValid ( this SourceApplicationEntity sourceApplicationEntity , out IList < string > validationErrors )
59
60
{
60
- Guard . Against . Null ( sourceApplicationEntity , nameof ( sourceApplicationEntity ) ) ;
61
+ Guard . Against . Null ( sourceApplicationEntity ) ;
61
62
62
63
validationErrors = new List < string > ( ) ;
63
64
@@ -70,7 +71,7 @@ public static bool IsValid(this SourceApplicationEntity sourceApplicationEntity,
70
71
71
72
public static bool IsValidDicomTag ( string source , string grouping , IList < string > validationErrors = null )
72
73
{
73
- Guard . Against . NullOrWhiteSpace ( source , nameof ( source ) ) ;
74
+ Guard . Against . NullOrWhiteSpace ( source ) ;
74
75
75
76
try
76
77
{
@@ -92,25 +93,35 @@ public static bool IsValidDicomTag(string source, string grouping, IList<string>
92
93
93
94
public static bool IsAeTitleValid ( string source , string aeTitle , IList < string > validationErrors = null )
94
95
{
95
- Guard . Against . NullOrWhiteSpace ( source , nameof ( source ) ) ;
96
+ Guard . Against . NullOrWhiteSpace ( source ) ;
96
97
97
- if ( ! string . IsNullOrWhiteSpace ( aeTitle ) && aeTitle . Length <= 15 ) return true ;
98
+ if ( ! string . IsNullOrWhiteSpace ( aeTitle ) &&
99
+ aeTitle . Length <= 15 &&
100
+ Regex . IsMatch ( aeTitle , @"^[a-zA-Z0-9_\-]+$" ) )
101
+ {
102
+ return true ;
103
+ }
98
104
99
105
validationErrors ? . Add ( $ "'{ aeTitle } ' is not a valid AE Title (source: { source } ).") ;
100
106
return false ;
101
107
}
102
108
103
109
public static bool IsValidHostNameIp ( string source , string hostIp , IList < string > validationErrors = null )
104
110
{
105
- if ( ! string . IsNullOrWhiteSpace ( hostIp ) ) return true ;
111
+ if ( ! string . IsNullOrWhiteSpace ( hostIp ) &&
112
+ ( Regex . IsMatch ( hostIp , @"^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$" ) || // IP address
113
+ Regex . IsMatch ( hostIp , @"^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$" ) ) ) // Host/domain name
114
+ {
115
+ return true ;
116
+ }
106
117
107
118
validationErrors ? . Add ( $ "Invalid host name/IP address '{ hostIp } ' specified for { source } .") ;
108
119
return false ;
109
120
}
110
121
111
122
public static bool IsPortValid ( string source , int port , IList < string > validationErrors = null )
112
123
{
113
- Guard . Against . NullOrWhiteSpace ( source , nameof ( source ) ) ;
124
+ Guard . Against . NullOrWhiteSpace ( source ) ;
114
125
115
126
if ( port > 0 && port <= 65535 ) return true ;
116
127
0 commit comments