Consolidate parameter format and logic
This commit is contained in:
@@ -405,7 +405,8 @@ Namespace Documents
|
|||||||
Logger.Debug("Running Function: [{0}]", oFunctionName)
|
Logger.Debug("Running Function: [{0}]", oFunctionName)
|
||||||
Logger.Debug("With Parameters: [{0}]", oFunctionParams)
|
Logger.Debug("With Parameters: [{0}]", oFunctionParams)
|
||||||
|
|
||||||
Dim oParamsDict = ParseFunctionParamsAsDict(oFunctionParams)
|
|
||||||
|
Dim oParamsDict = Parameters.Parse(oFunctionParams)
|
||||||
|
|
||||||
If oFunctionName = Constants.FUNCTION_PRICE Then
|
If oFunctionName = Constants.FUNCTION_PRICE Then
|
||||||
Await SetPrice(oRow, oField.Key, oParamsDict, pDocument, pMandator, pTemplate)
|
Await SetPrice(oRow, oField.Key, oParamsDict, pDocument, pMandator, pTemplate)
|
||||||
@@ -432,13 +433,15 @@ Namespace Documents
|
|||||||
|
|
||||||
Dim oFunctionName = oColumn.Config.FunctionName
|
Dim oFunctionName = oColumn.Config.FunctionName
|
||||||
Dim oFunctionParams = oColumn.Config.FunctionParams
|
Dim oFunctionParams = oColumn.Config.FunctionParams
|
||||||
Dim oParamsDict = ParseFunctionParamsAsDict(oFunctionParams)
|
|
||||||
|
|
||||||
' The code below needs a defined function
|
' The code below needs a defined function
|
||||||
If oFunctionName = String.Empty Then
|
If oFunctionName = String.Empty Then
|
||||||
Continue For
|
Continue For
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
Dim oParamsDict = Parameters.Parse(oFunctionParams)
|
||||||
|
|
||||||
' The main identifier will be checked for String.empty and not required.
|
' The main identifier will be checked for String.empty and not required.
|
||||||
' This makes sure that optional fields do not generate errors.
|
' This makes sure that optional fields do not generate errors.
|
||||||
Dim oIdentifier As DocumentRow.FieldValue = oRow.Fields.GetOrDefault(oField.Key)
|
Dim oIdentifier As DocumentRow.FieldValue = oRow.Fields.GetOrDefault(oField.Key)
|
||||||
@@ -483,7 +486,7 @@ Namespace Documents
|
|||||||
|
|
||||||
Dim oFunctionName = oColumn.Config.FunctionName
|
Dim oFunctionName = oColumn.Config.FunctionName
|
||||||
Dim oFunctionParams = oColumn.Config.FunctionParams
|
Dim oFunctionParams = oColumn.Config.FunctionParams
|
||||||
Dim oParamsDict = ParseFunctionParamsAsDict(oFunctionParams)
|
Dim oParamsDict = Parameters.Parse(oFunctionParams)
|
||||||
|
|
||||||
If oFunctionName = Constants.FUNCTION_FIELD Then
|
If oFunctionName = Constants.FUNCTION_FIELD Then
|
||||||
Try
|
Try
|
||||||
@@ -707,27 +710,6 @@ Namespace Documents
|
|||||||
Throw ex
|
Throw ex
|
||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Function ParseFunctionParamsAsDict(pParams As String) As Dictionary(Of String, String)
|
|
||||||
Try
|
|
||||||
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("=")
|
|
||||||
If oParamSplit.Count = 2 Then
|
|
||||||
oParamsDict.Add(oParamSplit(0), oParamSplit(1))
|
|
||||||
End If
|
|
||||||
Next
|
|
||||||
End If
|
|
||||||
|
|
||||||
Return oParamsDict
|
|
||||||
Catch ex As Exception
|
|
||||||
Logger.Error(ex)
|
|
||||||
Return New Dictionary(Of String, String)
|
|
||||||
End Try
|
|
||||||
End Function
|
|
||||||
End Class
|
End Class
|
||||||
|
|
||||||
End Namespace
|
End Namespace
|
||||||
@@ -128,6 +128,7 @@
|
|||||||
<DependentUpon>Settings.settings</DependentUpon>
|
<DependentUpon>Settings.settings</DependentUpon>
|
||||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Parameters.vb" />
|
||||||
<Compile Include="Patterns.vb" />
|
<Compile Include="Patterns.vb" />
|
||||||
<Compile Include="Report\ReportGenerator.vb" />
|
<Compile Include="Report\ReportGenerator.vb" />
|
||||||
<Compile Include="Templates\GeneralConfig.vb" />
|
<Compile Include="Templates\GeneralConfig.vb" />
|
||||||
|
|||||||
49
MultiTool.Common/Parameters.vb
Normal file
49
MultiTool.Common/Parameters.vb
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
Imports DigitalData.Modules.Logging
|
||||||
|
|
||||||
|
Public Class Parameters
|
||||||
|
''' <summary>
|
||||||
|
''' Parse a list of parameters and return a directory of the parsed parameters.
|
||||||
|
''' </summary>
|
||||||
|
''' <remarks>The special case of SQL Parameters is NOT handled by this function.</remarks>
|
||||||
|
Public Shared Function Parse(pParameters As String) As Dictionary(Of String, String)
|
||||||
|
Try
|
||||||
|
Dim oParamsDict As New Dictionary(Of String, String)
|
||||||
|
|
||||||
|
If pParameters <> String.Empty Then
|
||||||
|
Dim oParamList = pParameters.Split("|").ToList()
|
||||||
|
|
||||||
|
For Each oParam In oParamList
|
||||||
|
Dim oParamSplit = oParam.Split("=")
|
||||||
|
|
||||||
|
If oParamSplit.Count = 2 Then
|
||||||
|
oParamsDict.Add(oParamSplit(0), oParamSplit(1))
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
End If
|
||||||
|
|
||||||
|
Return oParamsDict
|
||||||
|
Catch ex As Exception
|
||||||
|
Return New Dictionary(Of String, String)
|
||||||
|
End Try
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Shared Function TryGet(pParameters As String, pName As String) As Tuple(Of String, String)
|
||||||
|
Try
|
||||||
|
Dim pParamDict = Parse(pParameters)
|
||||||
|
|
||||||
|
If pParamDict.Count = 0 Then
|
||||||
|
Return Nothing
|
||||||
|
End If
|
||||||
|
|
||||||
|
If Not pParamDict.ContainsKey(pName) Then
|
||||||
|
Return Nothing
|
||||||
|
End If
|
||||||
|
|
||||||
|
Dim oValue = pParamDict.Item(pName)
|
||||||
|
Return New Tuple(Of String, String)(pName, oValue)
|
||||||
|
|
||||||
|
Catch ex As Exception
|
||||||
|
Return Nothing
|
||||||
|
End Try
|
||||||
|
End Function
|
||||||
|
End Class
|
||||||
@@ -93,8 +93,8 @@ Namespace Templates
|
|||||||
Dim oParam1 As String = Utils.NotNull(Parameter1, String.Empty)
|
Dim oParam1 As String = Utils.NotNull(Parameter1, String.Empty)
|
||||||
Dim oParam2 As String = Utils.NotNull(Parameter2, String.Empty)
|
Dim oParam2 As String = Utils.NotNull(Parameter2, String.Empty)
|
||||||
|
|
||||||
Dim oParamValue1 = TryGetParameter(oParam1, pName)
|
Dim oParamValue1 = Parameters.TryGet(oParam1, pName)
|
||||||
Dim oParamValue2 = TryGetParameter(oParam2, pName)
|
Dim oParamValue2 = Parameters.TryGet(oParam2, pName)
|
||||||
|
|
||||||
If oParamValue1 IsNot Nothing AndAlso oParamValue1.Item1 = pName Then
|
If oParamValue1 IsNot Nothing AndAlso oParamValue1.Item1 = pName Then
|
||||||
Return oParamValue1.Item2
|
Return oParamValue1.Item2
|
||||||
@@ -107,22 +107,6 @@ Namespace Templates
|
|||||||
Return Nothing
|
Return Nothing
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Function TryGetParameter(pParameterString As String, pName As String) As Tuple(Of String, String)
|
|
||||||
If pParameterString <> String.Empty Then
|
|
||||||
For Each oParameter In pParameterString.Split(",")
|
|
||||||
Dim oSplit = oParameter.Split("=").ToList()
|
|
||||||
|
|
||||||
If oSplit.Count = 2 AndAlso oSplit.First = pName Then
|
|
||||||
Return New Tuple(Of String, String)(oSplit.First, oSplit.Last)
|
|
||||||
End If
|
|
||||||
Next
|
|
||||||
|
|
||||||
Return Nothing
|
|
||||||
Else
|
|
||||||
Return Nothing
|
|
||||||
End If
|
|
||||||
End Function
|
|
||||||
|
|
||||||
''' <summary>
|
''' <summary>
|
||||||
''' Table from XSD
|
''' Table from XSD
|
||||||
''' </summary>
|
''' </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user