Patterns: Completeley rework Patterns2 structure
This commit is contained in:
58
Modules.Patterns/Modules/Globix/GlobixAutomatic.vb
Normal file
58
Modules.Patterns/Modules/Globix/GlobixAutomatic.vb
Normal file
@@ -0,0 +1,58 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Namespace Modules.Globix
|
||||
''' <summary>
|
||||
''' Patterns for Generating a Filename in Global Indexer
|
||||
''' </summary>
|
||||
Public Class GlobixAutomatic
|
||||
Inherits BaseModule
|
||||
Implements IModule
|
||||
|
||||
Public Property PatternIdentifier As String = "ATTR_A" Implements IModule.PatternIdentifier
|
||||
Public Property IsComplex As Boolean = True Implements IModule.IsComplex
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig)
|
||||
MyBase.New(pLogConfig)
|
||||
End Sub
|
||||
|
||||
Public Function Replace(pInput As String, pIndexes As Dictionary(Of String, List(Of String))) As String
|
||||
Dim oResult = pInput
|
||||
Dim oCounter = 0
|
||||
|
||||
If pIndexes Is Nothing Then
|
||||
Throw New ArgumentNullException("pIndexes")
|
||||
End If
|
||||
|
||||
Logger.Debug("Replacing Automatic Indexes. [{0}] Indexes loaded.", pIndexes?.Count)
|
||||
|
||||
While ContainsPattern(oResult, PatternIdentifier)
|
||||
Try
|
||||
Dim oIndexName As String = GetNextPattern(oResult, PatternIdentifier).Value
|
||||
|
||||
If pIndexes.ContainsKey(oIndexName) = False Then
|
||||
Logger.Warn("Value for Index [{0}] does not exist and will not be used for replacing. Skipping.", oIndexName)
|
||||
End If
|
||||
|
||||
' TODO: If Index contains multiple values, only the first value will be used as value
|
||||
Dim oIndexValues As List(Of String) = pIndexes.Item(oIndexName)
|
||||
Dim oFirstValue As String = oIndexValues.FirstOrDefault()
|
||||
|
||||
If oFirstValue Is Nothing Then
|
||||
Logger.Warn("Value for Index [{0}] is empty and will not be used for replacing. Skipping.")
|
||||
Return oResult
|
||||
End If
|
||||
|
||||
oResult = ReplacePattern(oResult, PatternIdentifier, oFirstValue)
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return oResult
|
||||
Finally
|
||||
IncrementCounterOrThrow(oCounter)
|
||||
End Try
|
||||
End While
|
||||
|
||||
Return oResult
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
59
Modules.Patterns/Modules/Globix/GlobixManual.vb
Normal file
59
Modules.Patterns/Modules/Globix/GlobixManual.vb
Normal file
@@ -0,0 +1,59 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Namespace Modules.Globix
|
||||
''' <summary>
|
||||
''' Patterns for Generating a Filename in Global Indexer
|
||||
''' </summary>
|
||||
Public Class GlobixManual
|
||||
Inherits BaseModule
|
||||
Implements IModule
|
||||
|
||||
Public Property PatternIdentifier As String = "ATTR_M" Implements IModule.PatternIdentifier
|
||||
Public Property IsComplex As Boolean = True Implements IModule.IsComplex
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig)
|
||||
MyBase.New(pLogConfig)
|
||||
End Sub
|
||||
|
||||
Public Function Replace(pInput As String, pIndexes As Dictionary(Of String, List(Of String))) As String
|
||||
Dim oResult = pInput
|
||||
Dim oCounter = 0
|
||||
|
||||
If pIndexes Is Nothing Then
|
||||
Throw New ArgumentNullException("pIndexes")
|
||||
End If
|
||||
|
||||
Logger.Debug("Replacing Manual Indexes. [{0}] Indexes loaded.", pIndexes?.Count)
|
||||
|
||||
While ContainsPattern(oResult, PatternIdentifier)
|
||||
Try
|
||||
Dim oIndexName As String = GetNextPattern(oResult, PatternIdentifier).Value
|
||||
|
||||
If pIndexes.ContainsKey(oIndexName) = False Then
|
||||
Logger.Warn("Value for Index [{0}] does not exist and will not be used for replacing. Exiting.", oIndexName)
|
||||
Return oResult
|
||||
End If
|
||||
|
||||
' TODO: If Index contains multiple values, only the first value will be used as value
|
||||
Dim oIndexValues As List(Of String) = pIndexes.Item(oIndexName)
|
||||
Dim oFirstValue As String = oIndexValues.FirstOrDefault()
|
||||
|
||||
If oFirstValue Is Nothing Then
|
||||
Logger.Warn("Value for Index [{0}] is empty and will not be used for replacing. Exiting.")
|
||||
Return oResult
|
||||
End If
|
||||
|
||||
oResult = ReplacePattern(oResult, PatternIdentifier, oFirstValue)
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return oResult
|
||||
Finally
|
||||
IncrementCounterOrThrow(oCounter)
|
||||
End Try
|
||||
End While
|
||||
|
||||
Return oResult
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user