Imports System.Text.RegularExpressions Imports DigitalData.Modules.Logging Imports MultiTool.Shared.Documents Imports MultiTool.Shared.Templates Imports MultiTool.Shared.Winline.Entities Public Class Patterns Inherits BaseClass Private ReadOnly GeneralConfig As GeneralConfig 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, oString As String) Dim oRegex = New Regex("{#(\w+)#([\w\s_-]+)}+") Dim oMatches As MatchCollection = oRegex.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 "FIELD" Dim oFieldName = oPlaceholderValue Dim oTargetField = pRow.Fields. Where(Function(field) field.Key = oFieldName). SingleOrDefault() oString = oString.Replace(oPlaceholderString, oTargetField.Value.Final) Case "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 "MANDATORDB" oValue = pDocument.Mandator.Database Case Else oValue = "" End Select If oValue <> "" Then oString = oString.Replace(oPlaceholderString, oValue) End If End Select Next Return oString 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) 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 "CONST" Dim oValue = "" Select Case oPlaceholderValue.ToUpper Case "MESOYEAR" oValue = GeneralConfig.GetWinLineYear() Case "MESOCOMP" oValue = pMandator.Id Case "USERNAME" oValue = Environment.UserName Case "CURRENTDATE" oValue = Now.ToString() Case "FILENAME" oValue = pDocument.FilenameExport Case "ACCOUNTNUMBER" oValue = pDocument.Account.Id Case "RUNNINGNUMBER" oValue = pDocument.RunningNumber Case "MANDATORDB" oValue = pMandator.Database Case Else oValue = "" End Select If oValue <> "" Then oString = oString.Replace(oPlaceholderString, oValue) End If End Select Next Return oString End Function End Class