Imports DigitalData.Modules.Logging

Namespace Modules
    Public Class Clipboard
        Inherits BaseModule
        Implements IModule

        Public Const CLIP_VALUE_BOARD As String = "BOARD"

        Public Const CLIPBOARD_VALUE_DE = "@Zwischenablage"
        Public Const CLIPBOARD_VALUE_EN = "@Clipboard"

        Public Property PatternIdentifier As String = "CLIP" 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, pClipboardContents As String) As String
            Dim oResult = pInput
            Dim oCounter = 0

            Try
                ' LEGACY: Replace Clipboard Contents
                oResult = oResult.Replace(CLIPBOARD_VALUE_DE.ToLower, pClipboardContents)
                oResult = oResult.Replace(CLIPBOARD_VALUE_DE.ToUpper, pClipboardContents)
                oResult = oResult.Replace(CLIPBOARD_VALUE_DE, pClipboardContents)

                oResult = oResult.Replace(CLIPBOARD_VALUE_EN.ToLower, pClipboardContents)
                oResult = oResult.Replace(CLIPBOARD_VALUE_EN.ToUpper, pClipboardContents)
                oResult = oResult.Replace(CLIPBOARD_VALUE_EN, pClipboardContents)

                ' Replace Clipboard Contents
                While ContainsPatternAndValue(oResult, PatternIdentifier, CLIP_VALUE_BOARD)
                    oResult = ReplacePattern(oResult, PatternIdentifier, pClipboardContents)
                    IncrementCounterOrThrow(oCounter)
                End While

                Logger.Debug("Input after Clipboard.Replace: [{0}]", pInput)
            Catch ex As Exception
                Logger.Error(ex)

            End Try

            Return oResult
        End Function
    End Class
End Namespace
