Add max retries to pattern replacer
This commit is contained in:
@@ -31,6 +31,8 @@ Public Class clsPatterns
|
||||
Public Const INT_VALUE_MACHINE = "MACHINE"
|
||||
Public Const INT_VALUE_DOMAIN = "DOMAIN"
|
||||
|
||||
Public Const MAX_TRY_COUNT = 100
|
||||
|
||||
Private Shared regex As Regex = New Regex("{#(\w+)#([\w\s_-]+)}+")
|
||||
Private Shared allPatterns As New List(Of String) From {PATTERN_WMI, PATTERN_CTRL, PATTERN_USER, PATTERN_INT}
|
||||
Private Shared complexPatterns As New List(Of String) From {PATTERN_WMI, PATTERN_CTRL}
|
||||
@@ -118,8 +120,13 @@ Public Class clsPatterns
|
||||
Public Shared Function ReplaceControlValues(input As String, panel As Panel) As String
|
||||
Try
|
||||
Dim result = input
|
||||
Dim oTryCounter = 0
|
||||
|
||||
While ContainsPattern(result, PATTERN_CTRL)
|
||||
If oTryCounter > MAX_TRY_COUNT Then
|
||||
Throw New Exception("Max tries in ReplaceControlValues exceeded.")
|
||||
End If
|
||||
|
||||
Dim controlName As String = GetNextPattern(result, PATTERN_CTRL).Value
|
||||
Dim control As Control = panel.Controls.Find(controlName, False).FirstOrDefault()
|
||||
|
||||
@@ -127,6 +134,8 @@ Public Class clsPatterns
|
||||
Dim value As String = control.Text
|
||||
result = ReplacePattern(result, PATTERN_CTRL, value)
|
||||
End If
|
||||
|
||||
oTryCounter += 1
|
||||
End While
|
||||
|
||||
Return result
|
||||
|
||||
Reference in New Issue
Block a user