Add max retries to pattern replacer

This commit is contained in:
Jonathan Jenne 2019-06-11 12:53:15 +02:00
parent aab9f309b3
commit 84b340e026
2 changed files with 11 additions and 0 deletions

View File

@ -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

View File

@ -1004,6 +1004,7 @@ Public Class frmValidator
End Try
End Sub
Public Sub onLookUp1(sender As Object, SelectedValues As List(Of String))
LOGGER.Debug("onLookup1")
If FormLoaded = False Then
Exit Sub
End If
@ -1033,6 +1034,7 @@ Public Class frmValidator
Try
'Dim oDependingLookup As LookupControl2 = pnldesigner.Controls.Find(oDEPENDING_CtrlName, False).FirstOrDefault()
For Each oControl As Control In pnldesigner.Controls
If oControl.Tag = oDEPENDING_GUID Then
Dim oDependingLookup As LookupControl2 = oControl
oDependingLookup.DataSource = oDTDEPENDING_RESULT