Imports DigitalData.Modules.Logging

Namespace Modules
    ''' <summary>
    ''' Custom Patterns that are defined at runtime
    ''' </summary>
    Public Class Custom
        Inherits BaseModule
        Implements IModule

        Public Property PatternIdentifier As String = "CUST" Implements IModule.PatternIdentifier
        Public Property IsComplex As Boolean = False Implements IModule.IsComplex

        Public Sub New(pLogConfig As LogConfig)
            MyBase.New(pLogConfig)
        End Sub

        Public Function Replace(pInput As String, pCustomValues As Dictionary(Of String, String)) As String
            Dim oResult = pInput
            Dim oCounter = 0
            Dim oNow As Date = Now

            Logger.Trace("Replacing Custom Patterns")

            While HasPattern(oResult, PatternIdentifier)
                For Each oCustomValue In pCustomValues
                    If ContainsPatternAndValue(oResult, PatternIdentifier, oCustomValue.Key) Then
                        oResult = ReplacePattern(oResult, PatternIdentifier, oCustomValue.Value)
                    End If
                Next
                IncrementCounterOrThrow(oCounter)
            End While

            Return oResult
        End Function
    End Class
End Namespace
