From 4c1a3a9220ad80ab9b3ef25710bf9785c3b22275 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 16 Mar 2022 12:17:54 +0100 Subject: [PATCH] improve function + params handling --- MultiTool.Shared/Documents/DocumentLoader.vb | 41 +++++++++++-------- .../Templates/TemplateConfigItem.vb | 13 ++++++ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/MultiTool.Shared/Documents/DocumentLoader.vb b/MultiTool.Shared/Documents/DocumentLoader.vb index 93211aa..ed73eb2 100644 --- a/MultiTool.Shared/Documents/DocumentLoader.vb +++ b/MultiTool.Shared/Documents/DocumentLoader.vb @@ -281,22 +281,11 @@ Namespace Documents Continue For End If - Dim oFunctionName = oColumn.Config?.Function?.Name - - ' TODO: Make more nice - Dim oParams = oColumn.Config?.Function?.Params - Dim oParamsDict As New Dictionary(Of String, String) - - If oParams IsNot Nothing AndAlso oParams <> String.Empty Then - Dim oParamList = oParams.Split("|").ToList() - For Each oParam In oParamList - Dim oParamSplit = oParam.Split("=") - oParamsDict.Add(oParamSplit(0), oParamSplit(1)) - Next - End If - + Dim oFunctionName = oColumn.Config.FunctionName + Dim oFunctionParams = oColumn.Config.FunctionParams + Dim oParamsDict = ParseFunctionParamsAsDict(oFunctionParams) - If oFunctionName = "PRICE" Then + If oFunctionName = Constants.FUNCTION_PRICE Then Await SetPrice(oRow, oField.Key, oParamsDict, pDocument, pMandator, pTemplate) End If Next @@ -319,10 +308,12 @@ Namespace Documents Continue For End If - Dim oFunctionName = oColumn.Config?.Function?.Name + Dim oFunctionName = oColumn.Config.FunctionName + Dim oFunctionParams = oColumn.Config.FunctionParams + Dim oParamsDict = ParseFunctionParamsAsDict(oFunctionParams) If oFunctionName = "GLN" Then - SetAccountByGLN(oRow, pMandator, oField.Key, Nothing) + SetAccountByGLN(oRow, pMandator, oField.Key, Nothing, oParamsDict) End If If oFunctionName = "EAN" Then @@ -419,7 +410,7 @@ Namespace Documents End If End Sub - Private Sub SetAccountByGLN(oRow As DocumentRow, pMandator As Mandator, pNumberField As String, pNameField As String) + Private Sub SetAccountByGLN(oRow As DocumentRow, pMandator As Mandator, pNumberField As String, pNameField As String, pParams As Dictionary(Of String, String)) ' Try to read the Account number (which is a GLN really) and account Name Dim oNumberItem As DocumentRow.FieldValue = oRow.Fields.GetOrDefault(pNumberField) Dim oNameItem As DocumentRow.FieldValue = oRow.Fields.GetOrDefault(pNameField) @@ -456,6 +447,20 @@ Namespace Documents Private Function WrapFileInfo(pFileInfo As FileInfo) As Document Return New Document With {.File = pFileInfo} End Function + + Private Function ParseFunctionParamsAsDict(pParams As String) As Dictionary(Of String, String) + Dim oParamsDict As New Dictionary(Of String, String) + + If pParams <> String.Empty Then + Dim oParamList = pParams.Split("|").ToList() + For Each oParam In oParamList + Dim oParamSplit = oParam.Split("=") + oParamsDict.Add(oParamSplit(0), oParamSplit(1)) + Next + End If + + Return oParamsDict + End Function End Class End Namespace \ No newline at end of file diff --git a/MultiTool.Shared/Templates/TemplateConfigItem.vb b/MultiTool.Shared/Templates/TemplateConfigItem.vb index 92716e1..a23a6e8 100644 --- a/MultiTool.Shared/Templates/TemplateConfigItem.vb +++ b/MultiTool.Shared/Templates/TemplateConfigItem.vb @@ -1,4 +1,5 @@ Imports MultiTool.Shared.Constants +Imports DigitalData.Modules.Language Namespace Templates Public Class TemplateConfigItem @@ -16,6 +17,18 @@ Namespace Templates Public Property [Function] As ColumnFunction + Public ReadOnly Property FunctionName As String + Get + Return Utils.NotNull([Function]?.Name, String.Empty) + End Get + End Property + + Public ReadOnly Property FunctionParams As String + Get + Return Utils.NotNull([Function]?.Params, String.Empty) + End Get + End Property + Public Class ColumnFunction Public Id As XmlFunction Public Name As String