Depending Controls
This commit is contained in:
@@ -39,7 +39,7 @@ Public Class ClassPatterns
|
||||
|
||||
Public Const MAX_TRY_COUNT = 500
|
||||
|
||||
Private Shared regex As Regex = New Regex("{#(\w+)#([\w\s_-]+)}+")
|
||||
Private Shared regex As Regex = New Regex("{#(\w+)#([\w\d\s_-]+)}+")
|
||||
Private Shared allPatterns As New List(Of String) From {PATTERN_WMI, PATTERN_CTRL, PATTERN_IDBA, PATTERN_USER, PATTERN_INT}
|
||||
Private Shared complexPatterns As New List(Of String) From {PATTERN_WMI, PATTERN_CTRL, PATTERN_IDBA}
|
||||
Private Shared simplePatterns As New List(Of String) From {PATTERN_USER, PATTERN_INT}
|
||||
@@ -146,12 +146,28 @@ Public Class ClassPatterns
|
||||
Dim result = input
|
||||
Dim oTryCounter = 0
|
||||
|
||||
LOGGER.Debug("Input String: [{0}]", input)
|
||||
|
||||
While ContainsPattern(result, PATTERN_CTRL)
|
||||
LOGGER.Debug("ReplaceControlValues Try no. [{0}]", oTryCounter)
|
||||
|
||||
If oTryCounter > MAX_TRY_COUNT Then
|
||||
Throw New Exception($"Max tries in ReplaceControlValues exceeded - Result so far [{result}].")
|
||||
End If
|
||||
|
||||
Dim controlName As String = GetNextPattern(result, PATTERN_CTRL).Value
|
||||
LOGGER.Debug("Getting next pattern..")
|
||||
|
||||
Dim oNextPattern = GetNextPattern(result, PATTERN_CTRL)
|
||||
|
||||
If oNextPattern Is Nothing Then
|
||||
LOGGER.Debug("No Next Pattern found. Exiting!")
|
||||
Exit While
|
||||
End If
|
||||
|
||||
LOGGER.Debug("Next Pattern Value: [{0}]", oNextPattern.Value)
|
||||
LOGGER.Debug("Next Pattern Type: [{0}]", oNextPattern.Type)
|
||||
|
||||
Dim controlName As String = oNextPattern.Value
|
||||
Dim oFoundControl As Control = Nothing
|
||||
Dim oFoundType As String = Nothing
|
||||
|
||||
@@ -160,9 +176,15 @@ Public Class ClassPatterns
|
||||
Continue For
|
||||
End If
|
||||
|
||||
LOGGER.Debug("Getting control metadata..")
|
||||
|
||||
Dim oMeta = DirectCast(oControl.Tag, ClassControls.ControlMeta)
|
||||
|
||||
LOGGER.Debug("Checking Control Name matches..")
|
||||
|
||||
If oMeta.IndexName = controlName Then
|
||||
LOGGER.Debug("Control Name matches! Matching Control: [{0}]", controlName)
|
||||
|
||||
oFoundControl = oControl
|
||||
oFoundType = oMeta.IndexType
|
||||
Exit For
|
||||
@@ -173,28 +195,47 @@ Public Class ClassPatterns
|
||||
Dim oValue As String = String.Empty
|
||||
|
||||
If TypeOf oFoundControl Is TextBox Then
|
||||
oValue = DirectCast(oFoundControl, TextBox).Text
|
||||
Try
|
||||
oValue = DirectCast(oFoundControl, TextBox).Text
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
LOGGER.Warn("Control Value for TextBox [{0}] could not be retrieved!", oFoundControl.Name)
|
||||
End Try
|
||||
ElseIf TypeOf oFoundControl Is CheckBox Then
|
||||
oValue = IIf(DirectCast(oFoundControl, CheckBox).Checked, 1, 0)
|
||||
Try
|
||||
oValue = IIf(DirectCast(oFoundControl, CheckBox).Checked, 1, 0)
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
LOGGER.Warn("Control Value for CheckBox [{0}] could not be retrieved!", oFoundControl.Name)
|
||||
End Try
|
||||
ElseIf TypeOf oFoundControl Is LookupControl2 Then
|
||||
Dim oLookupControl = DirectCast(oFoundControl, LookupControl2)
|
||||
Try
|
||||
Dim oLookupControl = DirectCast(oFoundControl, LookupControl2)
|
||||
|
||||
If oLookupControl.MultiSelect Then
|
||||
Select Case oFoundType
|
||||
Case "INTEGER"
|
||||
oValue = String.Join(",", oLookupControl.SelectedValues)
|
||||
Case "VARCHAR"
|
||||
Dim oWrapped = oLookupControl.SelectedValues.Select(Function(v) $"'{v}'")
|
||||
oValue = String.Join(",", oWrapped)
|
||||
End Select
|
||||
Else
|
||||
oValue = NotNull(oLookupControl.SelectedValues.Item(0), "")
|
||||
End If
|
||||
If oLookupControl.MultiSelect Then
|
||||
Select Case oFoundType
|
||||
Case "INTEGER"
|
||||
oValue = String.Join(",", oLookupControl.SelectedValues)
|
||||
Case "VARCHAR"
|
||||
Dim oWrapped = oLookupControl.SelectedValues.Select(Function(v) $"'{v}'")
|
||||
oValue = String.Join(",", oWrapped)
|
||||
End Select
|
||||
Else
|
||||
oValue = NotNull(oLookupControl.SelectedValues.Item(0), "")
|
||||
End If
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
LOGGER.Warn("Control Value for LookupControl2 [{0}] could not be retrieved!", oFoundControl.Name)
|
||||
End Try
|
||||
Else
|
||||
oValue = ""
|
||||
End If
|
||||
|
||||
LOGGER.Debug("Retrieved Value from Control [{0}] is: [{1}]", oFoundControl.Name, oValue)
|
||||
|
||||
result = ReplacePattern(result, PATTERN_CTRL, oValue)
|
||||
Else
|
||||
LOGGER.Warn("Control [{0}] not found!", controlName)
|
||||
End If
|
||||
|
||||
oTryCounter += 1
|
||||
@@ -204,6 +245,7 @@ Public Class ClassPatterns
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
LOGGER.Info("Error in ReplaceControlValues:" & ex.Message)
|
||||
Return input
|
||||
End Try
|
||||
End Function
|
||||
|
||||
|
||||
Reference in New Issue
Block a user