From f26a5a693640fff789eaf8f4c186a4d64c57e3d9 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 4 Nov 2020 10:29:35 +0100 Subject: [PATCH] Fix windream pattern replacement when variable value is not string --- app/DD_PM_WINDREAM/clsPatterns.vb | 44 ++++++++++++++++--------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/app/DD_PM_WINDREAM/clsPatterns.vb b/app/DD_PM_WINDREAM/clsPatterns.vb index b399dba..d8ac63a 100644 --- a/app/DD_PM_WINDREAM/clsPatterns.vb +++ b/app/DD_PM_WINDREAM/clsPatterns.vb @@ -57,7 +57,9 @@ Public Class clsPatterns LOGGER.Debug($"input BEFORE replacing: [{result}]") result = ReplaceInternalValues(result) 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 result = ReplaceIDBAttributes(result, is_SQL) End If @@ -96,7 +98,7 @@ Public Class clsPatterns While ContainsPatternAndValue(result, PATTERN_INT, INT_VALUE_DATE) result = ReplacePattern(result, PATTERN_INT, Now.ToShortDateString) End While - LOGGER.Debug("input AFTER ReplaceInternalValues: " & input) + LOGGER.Debug("pInput AFTER ReplaceInternalValues: " & input) Return result Catch ex As Exception LOGGER.Error(ex) @@ -137,7 +139,7 @@ Public Class clsPatterns While ContainsPatternAndValue(result, PATTERN_USER, USER_VALUE_PROFILE_ID) result = ReplacePattern(result, PATTERN_USER, profileId) End While - LOGGER.Debug("input AFTER ReplaceUserValues: " & input) + LOGGER.Debug("pInput AFTER ReplaceUserValues: " & input) Return result Catch ex As Exception LOGGER.Error(ex) @@ -190,7 +192,7 @@ Public Class clsPatterns oTryCounter += 1 End While - LOGGER.Debug("input AFTER ReplaceControlValues: " & input) + LOGGER.Debug("pInput AFTER ReplaceControlValues: " & input) Return result Catch ex As Exception LOGGER.Error(ex) @@ -198,35 +200,36 @@ Public Class clsPatterns End Try 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 - Dim result = input + Dim oResult = pInput Dim oTryCounter As Integer = 0 - While ContainsPattern(result, PATTERN_WMI) - Dim indexName As String = GetNextPattern(result, PATTERN_WMI).Value - Dim oWMValue = document.GetVariableValue(indexName) + While ContainsPattern(oResult, PATTERN_WMI) + + 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 - LOGGER.Warn("Max tries in ReplaceWindreamIndicies exceeded - Replacing with [0]!") - result = ReplacePattern(result, PATTERN_WMI, 0) Throw New Exception("Max tries in ReplaceWindreamIndicies exceeded.") - End If + If oWMValue IsNot Nothing Then - If IS_SQL = True Then + If pIsSQL = True Then LOGGER.Debug($"IS_SQL = True - oReplaceValue = {oWMValue}") - oWMValue = oWMValue.Replace("'", "''") + oWMValue = oWMValue.ToString().Replace("'", "''") LOGGER.Debug($"oReplaceValue = {oWMValue}") End If - result = ReplacePattern(result, PATTERN_WMI, oWMValue) + oResult = ReplacePattern(oResult, PATTERN_WMI, oWMValue) End If oTryCounter += 100 End While - LOGGER.Debug("sql AFTER ReplaceWindreamIndicies: " & input) - Return result + LOGGER.Debug("sql AFTER ReplaceWindreamIndicies: " & pInput) + Return oResult Catch ex As Exception LOGGER.Error(ex) LOGGER.Info("Error in ReplaceWindreamIndicies:" & ex.Message) + Return pInput End Try End Function Public Shared Function ReplaceIDBAttributes(input As String, IS_SQL As Boolean) As String @@ -244,7 +247,6 @@ Public Class clsPatterns ElseIf indexName = "DocID" Then oIDBValue = CURRENT_DOC_ID Else - oIDBValue = IDBData.GetVariableValue(indexName) End If @@ -304,7 +306,7 @@ Public Class clsPatterns Dim elements As MatchCollection = MyRegex.Matches(input) For Each element As Match In elements - ' Pattern in input + ' Pattern in pInput Dim t As String = element.Groups(1).Value Dim v As String = element.Groups(2).Value @@ -321,7 +323,7 @@ Public Class clsPatterns Dim results As New List(Of Pattern) For Each element As Match In elements - ' Pattern in input + ' Pattern in pInput Dim t As String = element.Groups(1).Value Dim v As String = element.Groups(2).Value @@ -354,7 +356,7 @@ Public Class clsPatterns Dim elements As MatchCollection = MyRegex.Matches(input) For Each element As Match In elements - ' Pattern in input + ' Pattern in pInput Dim t As String = element.Groups(1).Value Dim v As String = element.Groups(2).Value