Fix windream pattern replacement when variable value is not string

This commit is contained in:
Jonathan Jenne 2020-11-04 10:29:35 +01:00
parent 5561328f44
commit f26a5a6936

View File

@ -57,7 +57,9 @@ Public Class clsPatterns
LOGGER.Debug($"input BEFORE replacing: [{result}]") LOGGER.Debug($"input BEFORE replacing: [{result}]")
result = ReplaceInternalValues(result) result = ReplaceInternalValues(result)
result = ReplaceControlValues(result, panel, is_SQL) result = ReplaceControlValues(result, panel, is_SQL)
If Not IsNothing(CURRENT_WMFILE) Then result = ReplaceWindreamIndicies(result, CURRENT_WMFILE, is_SQL) If Not IsNothing(CURRENT_WMFILE) Then
result = ReplaceWindreamIndicies(result, CURRENT_WMFILE, is_SQL)
End If
If IDB_ACTIVE = True Then If IDB_ACTIVE = True Then
result = ReplaceIDBAttributes(result, is_SQL) result = ReplaceIDBAttributes(result, is_SQL)
End If End If
@ -96,7 +98,7 @@ Public Class clsPatterns
While ContainsPatternAndValue(result, PATTERN_INT, INT_VALUE_DATE) While ContainsPatternAndValue(result, PATTERN_INT, INT_VALUE_DATE)
result = ReplacePattern(result, PATTERN_INT, Now.ToShortDateString) result = ReplacePattern(result, PATTERN_INT, Now.ToShortDateString)
End While End While
LOGGER.Debug("input AFTER ReplaceInternalValues: " & input) LOGGER.Debug("pInput AFTER ReplaceInternalValues: " & input)
Return result Return result
Catch ex As Exception Catch ex As Exception
LOGGER.Error(ex) LOGGER.Error(ex)
@ -137,7 +139,7 @@ Public Class clsPatterns
While ContainsPatternAndValue(result, PATTERN_USER, USER_VALUE_PROFILE_ID) While ContainsPatternAndValue(result, PATTERN_USER, USER_VALUE_PROFILE_ID)
result = ReplacePattern(result, PATTERN_USER, profileId) result = ReplacePattern(result, PATTERN_USER, profileId)
End While End While
LOGGER.Debug("input AFTER ReplaceUserValues: " & input) LOGGER.Debug("pInput AFTER ReplaceUserValues: " & input)
Return result Return result
Catch ex As Exception Catch ex As Exception
LOGGER.Error(ex) LOGGER.Error(ex)
@ -190,7 +192,7 @@ Public Class clsPatterns
oTryCounter += 1 oTryCounter += 1
End While End While
LOGGER.Debug("input AFTER ReplaceControlValues: " & input) LOGGER.Debug("pInput AFTER ReplaceControlValues: " & input)
Return result Return result
Catch ex As Exception Catch ex As Exception
LOGGER.Error(ex) LOGGER.Error(ex)
@ -198,35 +200,36 @@ Public Class clsPatterns
End Try End Try
End Function End Function
Public Shared Function ReplaceWindreamIndicies(input As String, document As WMObject, IS_SQL As Boolean) As String Public Shared Function ReplaceWindreamIndicies(pInput As String, pDocument As WMObject, pIsSQL As Boolean) As String
Try Try
Dim result = input Dim oResult = pInput
Dim oTryCounter As Integer = 0 Dim oTryCounter As Integer = 0
While ContainsPattern(result, PATTERN_WMI)
Dim indexName As String = GetNextPattern(result, PATTERN_WMI).Value While ContainsPattern(oResult, PATTERN_WMI)
Dim oWMValue = document.GetVariableValue(indexName)
Dim oIndexName As String = GetNextPattern(oResult, PATTERN_WMI).Value
Dim oWMValue As String = pDocument.GetVariableValue(oIndexName)
If IsNothing(oWMValue) And oTryCounter = MAX_TRY_COUNT Then If IsNothing(oWMValue) And oTryCounter = MAX_TRY_COUNT Then
LOGGER.Warn("Max tries in ReplaceWindreamIndicies exceeded - Replacing with [0]!")
result = ReplacePattern(result, PATTERN_WMI, 0)
Throw New Exception("Max tries in ReplaceWindreamIndicies exceeded.") Throw New Exception("Max tries in ReplaceWindreamIndicies exceeded.")
End If End If
If oWMValue IsNot Nothing Then If oWMValue IsNot Nothing Then
If IS_SQL = True Then If pIsSQL = True Then
LOGGER.Debug($"IS_SQL = True - oReplaceValue = {oWMValue}") LOGGER.Debug($"IS_SQL = True - oReplaceValue = {oWMValue}")
oWMValue = oWMValue.Replace("'", "''") oWMValue = oWMValue.ToString().Replace("'", "''")
LOGGER.Debug($"oReplaceValue = {oWMValue}") LOGGER.Debug($"oReplaceValue = {oWMValue}")
End If End If
result = ReplacePattern(result, PATTERN_WMI, oWMValue) oResult = ReplacePattern(oResult, PATTERN_WMI, oWMValue)
End If End If
oTryCounter += 100 oTryCounter += 100
End While End While
LOGGER.Debug("sql AFTER ReplaceWindreamIndicies: " & input) LOGGER.Debug("sql AFTER ReplaceWindreamIndicies: " & pInput)
Return result Return oResult
Catch ex As Exception Catch ex As Exception
LOGGER.Error(ex) LOGGER.Error(ex)
LOGGER.Info("Error in ReplaceWindreamIndicies:" & ex.Message) LOGGER.Info("Error in ReplaceWindreamIndicies:" & ex.Message)
Return pInput
End Try End Try
End Function End Function
Public Shared Function ReplaceIDBAttributes(input As String, IS_SQL As Boolean) As String Public Shared Function ReplaceIDBAttributes(input As String, IS_SQL As Boolean) As String
@ -244,7 +247,6 @@ Public Class clsPatterns
ElseIf indexName = "DocID" Then ElseIf indexName = "DocID" Then
oIDBValue = CURRENT_DOC_ID oIDBValue = CURRENT_DOC_ID
Else Else
oIDBValue = IDBData.GetVariableValue(indexName) oIDBValue = IDBData.GetVariableValue(indexName)
End If End If
@ -304,7 +306,7 @@ Public Class clsPatterns
Dim elements As MatchCollection = MyRegex.Matches(input) Dim elements As MatchCollection = MyRegex.Matches(input)
For Each element As Match In elements For Each element As Match In elements
' Pattern in input ' Pattern in pInput
Dim t As String = element.Groups(1).Value Dim t As String = element.Groups(1).Value
Dim v As String = element.Groups(2).Value Dim v As String = element.Groups(2).Value
@ -321,7 +323,7 @@ Public Class clsPatterns
Dim results As New List(Of Pattern) Dim results As New List(Of Pattern)
For Each element As Match In elements For Each element As Match In elements
' Pattern in input ' Pattern in pInput
Dim t As String = element.Groups(1).Value Dim t As String = element.Groups(1).Value
Dim v As String = element.Groups(2).Value Dim v As String = element.Groups(2).Value
@ -354,7 +356,7 @@ Public Class clsPatterns
Dim elements As MatchCollection = MyRegex.Matches(input) Dim elements As MatchCollection = MyRegex.Matches(input)
For Each element As Match In elements For Each element As Match In elements
' Pattern in input ' Pattern in pInput
Dim t As String = element.Groups(1).Value Dim t As String = element.Groups(1).Value
Dim v As String = element.Groups(2).Value Dim v As String = element.Groups(2).Value