Rework Patterns to allow for row based and final sql replacement when importing
This commit is contained in:
@@ -2,21 +2,29 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports MultiTool.Common.Documents
|
||||
Imports MultiTool.Common.Templates
|
||||
Imports MultiTool.Common.Constants
|
||||
Imports MultiTool.Common.Winline.Entities
|
||||
|
||||
Public Class Patterns
|
||||
Inherits BaseClass
|
||||
|
||||
Private ReadOnly GeneralConfig As GeneralConfig
|
||||
Private ReadOnly Regex As New Regex("{#(\w+)#([\w\s_-]+)}+")
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pGeneralConfig As GeneralConfig)
|
||||
MyBase.New(pLogConfig)
|
||||
GeneralConfig = pGeneralConfig
|
||||
End Sub
|
||||
|
||||
Public Function ReplaceForImport(pDocument As Documents.Document, pRow As DocumentRow, pReportFileName As String, oString As String)
|
||||
Dim oRegex = New Regex("{#(\w+)#([\w\s_-]+)}+")
|
||||
Dim oMatches As MatchCollection = oRegex.Matches(oString)
|
||||
''' <summary>
|
||||
''' Replaces placeholders in an sql marked as final sql in the template.
|
||||
''' </summary>
|
||||
''' <remarks>
|
||||
''' This SQL does not replace field-value placeholders!
|
||||
''' This is a globally applied function!
|
||||
''' </remarks>
|
||||
Public Function ReplaceForImportFinalSQL(pDocument As Document, pReportFileName As String, pString As String) As String
|
||||
Dim oMatches As MatchCollection = Regex.Matches(pString)
|
||||
|
||||
For Each oMatch As Match In oMatches
|
||||
Dim oPlaceholderString As String = oMatch.Groups.Item(0)?.Value
|
||||
@@ -24,56 +32,39 @@ Public Class Patterns
|
||||
Dim oPlaceholderValue As String = oMatch.Groups.Item(2)?.Value
|
||||
|
||||
Select Case oPlaceholderType.ToUpper
|
||||
Case "FIELD"
|
||||
Dim oFieldName = oPlaceholderValue
|
||||
Dim oTargetField = pRow.Fields.
|
||||
Where(Function(field) field.Key = oFieldName).
|
||||
SingleOrDefault()
|
||||
|
||||
oString = oString.Replace(oPlaceholderString, oTargetField.Value.Final)
|
||||
|
||||
Case "CONST"
|
||||
Case PLACEHOLDER_CONST
|
||||
Dim oValue = ""
|
||||
|
||||
Select Case oPlaceholderValue.ToUpper
|
||||
Case "MESOYEAR"
|
||||
oValue = GeneralConfig.GetWinLineYear()
|
||||
|
||||
Case "MESOCOMP"
|
||||
oValue = pDocument.Mandator.Id
|
||||
|
||||
Case "USERNAME"
|
||||
oValue = Environment.UserName
|
||||
|
||||
Case "CURRENTDATE"
|
||||
oValue = Now.ToString()
|
||||
|
||||
Case "FILENAME"
|
||||
oValue = pDocument.FileName
|
||||
|
||||
Case "FILENAME_REPORT"
|
||||
oValue = pReportFileName
|
||||
|
||||
Case "MANDATORDB"
|
||||
oValue = pDocument.Mandator.Database
|
||||
|
||||
Case Else
|
||||
oValue = ""
|
||||
oValue = ReplaceBasicValues(oPlaceholderValue, pDocument.Mandator)
|
||||
|
||||
End Select
|
||||
|
||||
If oValue <> "" Then
|
||||
oString = oString.Replace(oPlaceholderString, oValue)
|
||||
pString = pString.Replace(oPlaceholderString, oValue)
|
||||
End If
|
||||
End Select
|
||||
Next
|
||||
|
||||
Return oString
|
||||
Return pString
|
||||
End Function
|
||||
|
||||
Public Function ReplaceForExport(pDocument As ExportDocument, pMandator As Mandator, oString As String)
|
||||
Dim oRegex = New Regex("{#(\w+)#([\w\s_-]+)}+")
|
||||
Dim oMatches As MatchCollection = oRegex.Matches(oString)
|
||||
''' <summary>
|
||||
'''
|
||||
''' </summary>
|
||||
''' <param name="pDocument"></param>
|
||||
''' <param name="pRow"></param>
|
||||
''' <param name="pString"></param>
|
||||
''' <returns></returns>
|
||||
Public Function ReplaceForImport(pDocument As Document, pRow As DocumentRow, pString As String)
|
||||
Dim oMatches As MatchCollection = Regex.Matches(pString)
|
||||
|
||||
For Each oMatch As Match In oMatches
|
||||
Dim oPlaceholderString As String = oMatch.Groups.Item(0)?.Value
|
||||
@@ -81,22 +72,48 @@ Public Class Patterns
|
||||
Dim oPlaceholderValue As String = oMatch.Groups.Item(2)?.Value
|
||||
|
||||
Select Case oPlaceholderType.ToUpper
|
||||
Case "CONST"
|
||||
Case PLACEHOLDER_FIELD
|
||||
Dim oFieldName = oPlaceholderValue
|
||||
Dim oTargetField = pRow.Fields.
|
||||
Where(Function(field) field.Key = oFieldName).
|
||||
SingleOrDefault()
|
||||
|
||||
pString = pString.Replace(oPlaceholderString, oTargetField.Value.Final)
|
||||
|
||||
Case PLACEHOLDER_CONST
|
||||
Dim oValue = ""
|
||||
|
||||
Select Case oPlaceholderValue.ToUpper
|
||||
Case "MESOYEAR"
|
||||
oValue = GeneralConfig.GetWinLineYear()
|
||||
Case "FILENAME"
|
||||
oValue = pDocument.FileName
|
||||
|
||||
Case "MESOCOMP"
|
||||
oValue = pMandator.Id
|
||||
Case Else
|
||||
oValue = ReplaceBasicValues(oPlaceholderValue, pDocument.Mandator)
|
||||
|
||||
Case "USERNAME"
|
||||
oValue = Environment.UserName
|
||||
End Select
|
||||
|
||||
Case "CURRENTDATE"
|
||||
oValue = Now.ToString()
|
||||
If oValue <> "" Then
|
||||
pString = pString.Replace(oPlaceholderString, oValue)
|
||||
End If
|
||||
End Select
|
||||
Next
|
||||
|
||||
Return pString
|
||||
End Function
|
||||
|
||||
Public Function ReplaceForExport(pDocument As ExportDocument, pMandator As Mandator, oString As String)
|
||||
Dim oMatches As MatchCollection = Regex.Matches(oString)
|
||||
|
||||
For Each oMatch As Match In oMatches
|
||||
Dim oPlaceholderString As String = oMatch.Groups.Item(0)?.Value
|
||||
Dim oPlaceholderType As String = oMatch.Groups.Item(1)?.Value
|
||||
Dim oPlaceholderValue As String = oMatch.Groups.Item(2)?.Value
|
||||
|
||||
Select Case oPlaceholderType.ToUpper
|
||||
Case PLACEHOLDER_CONST
|
||||
Dim oValue = ""
|
||||
|
||||
Select Case oPlaceholderValue.ToUpper
|
||||
Case "FILENAME"
|
||||
oValue = pDocument.FilenameExport
|
||||
|
||||
@@ -106,11 +123,9 @@ Public Class Patterns
|
||||
Case "RUNNINGNUMBER"
|
||||
oValue = pDocument.RunningNumber
|
||||
|
||||
Case "MANDATORDB"
|
||||
oValue = pMandator.Database
|
||||
|
||||
Case Else
|
||||
oValue = ""
|
||||
oValue = ReplaceBasicValues(oPlaceholderValue, pMandator)
|
||||
|
||||
End Select
|
||||
|
||||
@@ -122,4 +137,31 @@ Public Class Patterns
|
||||
|
||||
Return oString
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Replaces basic values in the CONST namespace that only depend on the current mandator
|
||||
''' </summary>
|
||||
''' <returns>Value that will be used to replaced the placeholder</returns>
|
||||
Public Function ReplaceBasicValues(pPlaceholderValue As String, pMandator As Mandator) As String
|
||||
Select Case pPlaceholderValue.ToUpper
|
||||
Case "MESOYEAR"
|
||||
Return GeneralConfig.GetWinLineYear()
|
||||
|
||||
Case "MESOCOMP"
|
||||
Return pMandator.Id
|
||||
|
||||
Case "USERNAME"
|
||||
Return Environment.UserName
|
||||
|
||||
Case "MANDATORDB"
|
||||
Return pMandator.Database
|
||||
|
||||
Case "CURRENTDATE"
|
||||
Return Now.ToString()
|
||||
|
||||
Case Else
|
||||
Return String.Empty
|
||||
|
||||
End Select
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user