Imports DigitalData.Modules.Logging

Namespace Modules
    ''' <summary>
    ''' Simple patterns that only rely on .NET functions
    ''' </summary>
    Public Class Internal
        Inherits BaseModule
        Implements IModule

        Public Const INT_VALUE_USERNAME = "USERNAME"
        Public Const INT_VALUE_MACHINE = "MACHINE"
        Public Const INT_VALUE_DOMAIN = "DOMAIN"
        Public Const INT_VALUE_DATE = "DATE"
        Public Const INT_VALUE_DATE_YYYY = "DATE_YYYY"
        Public Const INT_VALUE_DATE_MM = "DATE_MM"
        Public Const INT_VALUE_DATE_DD = "DATE_DD"

        Public Property PatternIdentifier As String = "INT" 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) As String
            Dim oResult = pInput
            Dim oCounter = 0
            Dim oNow As Date = Now

            ' Replace CurrentDate(s)
            While ContainsPatternAndValue(oResult, PatternIdentifier, INT_VALUE_DATE)
                oResult = ReplacePattern(oResult, PatternIdentifier, oNow.ToString("yyyy-MM-dd"))
                IncrementCounterOrThrow(oCounter)
            End While

            ' Replace Year(s)
            While ContainsPatternAndValue(oResult, PatternIdentifier, INT_VALUE_DATE_YYYY)
                oResult = ReplacePattern(oResult, PatternIdentifier, oNow.ToString("yyyy"))
                IncrementCounterOrThrow(oCounter)
            End While

            ' Replace Month(s)
            While ContainsPatternAndValue(oResult, PatternIdentifier, INT_VALUE_DATE_MM)
                oResult = ReplacePattern(oResult, PatternIdentifier, oNow.ToString("MM"))
                IncrementCounterOrThrow(oCounter)
            End While

            ' Replace Day(s)
            While ContainsPatternAndValue(oResult, PatternIdentifier, INT_VALUE_DATE_DD)
                oResult = ReplacePattern(oResult, PatternIdentifier, oNow.ToString("dd"))
                IncrementCounterOrThrow(oCounter)
            End While

            Return oResult
        End Function
    End Class
End Namespace
