Patterns: WIP Patterns version 2
This commit is contained in:
13
Modules.Patterns/Modules/BaseModule.vb
Normal file
13
Modules.Patterns/Modules/BaseModule.vb
Normal file
@@ -0,0 +1,13 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Namespace [PatternModule]
|
||||
Public Class BaseModule
|
||||
Friend ReadOnly BaseFunctions As BaseFunctions
|
||||
Friend ReadOnly Logger As Logger
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig)
|
||||
Logger = pLogConfig.GetLogger()
|
||||
BaseFunctions = New BaseFunctions(pLogConfig)
|
||||
End Sub
|
||||
End Class
|
||||
End Namespace
|
||||
51
Modules.Patterns/Modules/Clipboard.vb
Normal file
51
Modules.Patterns/Modules/Clipboard.vb
Normal file
@@ -0,0 +1,51 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Namespace [PatternModule]
|
||||
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, pReplaceMap As Dictionary(Of String, Object)) As String Implements IModule.Replace
|
||||
Dim oResult = pInput
|
||||
Dim oCounter = 0
|
||||
Dim oClipboardContents = pReplaceMap.Item(CLIP_VALUE_BOARD)
|
||||
|
||||
Try
|
||||
' LEGACY: Replace Clipboard Contents
|
||||
oResult = oResult.Replace(CLIPBOARD_VALUE_DE.ToLower, oClipboardContents)
|
||||
oResult = oResult.Replace(CLIPBOARD_VALUE_DE.ToUpper, oClipboardContents)
|
||||
oResult = oResult.Replace(CLIPBOARD_VALUE_DE, oClipboardContents)
|
||||
|
||||
oResult = oResult.Replace(CLIPBOARD_VALUE_EN.ToLower, oClipboardContents)
|
||||
oResult = oResult.Replace(CLIPBOARD_VALUE_EN.ToUpper, oClipboardContents)
|
||||
oResult = oResult.Replace(CLIPBOARD_VALUE_EN, oClipboardContents)
|
||||
|
||||
' Replace Clipboard Contents
|
||||
While BaseFunctions.ContainsPatternAndValue(oResult, PatternIdentifier, CLIP_VALUE_BOARD)
|
||||
oResult = BaseFunctions.ReplacePattern(oResult, PatternIdentifier, oClipboardContents)
|
||||
BaseFunctions.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
|
||||
61
Modules.Patterns/Modules/Controls.vb
Normal file
61
Modules.Patterns/Modules/Controls.vb
Normal file
@@ -0,0 +1,61 @@
|
||||
Imports System.Windows.Forms
|
||||
Imports DigitalData.Controls.LookupGrid
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Namespace [PatternModule]
|
||||
''' <summary>
|
||||
''' Simple patterns that only rely on .NET functions
|
||||
''' </summary>
|
||||
Public Class Controls
|
||||
Inherits BaseModule
|
||||
Implements IModule
|
||||
|
||||
Public Const CTRL_VALUE_PANEL = "PANEL"
|
||||
|
||||
Public Property PatternIdentifier As String = "CTRL" 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, pReplaceMap As Dictionary(Of String, Object)) As String Implements IModule.Replace
|
||||
Dim oResult = pInput
|
||||
Dim oCounter = 0
|
||||
Dim oPanel As Panel = pReplaceMap.Item("CTRL_VALUE_PANEL")
|
||||
|
||||
While BaseFunctions.ContainsPattern(oResult, PatternIdentifier)
|
||||
Dim oControlName As String = BaseFunctions.GetNextPattern(oResult, PatternIdentifier).Value
|
||||
Dim oControl As Control = oPanel.Controls.Find(oControlName, False).FirstOrDefault()
|
||||
|
||||
If oControl IsNot Nothing Then
|
||||
Dim oReplaceValue As String
|
||||
Select Case oControl.GetType.ToString
|
||||
Case GetType(TextBox).ToString
|
||||
oReplaceValue = oControl.Text
|
||||
Case GetType(LookupControl3).ToString
|
||||
Dim oLookupControl3 As LookupControl3 = oControl
|
||||
If oLookupControl3.Properties.SelectedValues.Count = 1 Then
|
||||
oReplaceValue = oLookupControl3.Properties.SelectedValues.Item(0)
|
||||
Else
|
||||
oReplaceValue = "0"
|
||||
End If
|
||||
Case GetType(ComboBox).ToString
|
||||
oReplaceValue = oControl.Text
|
||||
Case GetType(CheckBox).ToString
|
||||
Dim oCheckBox As CheckBox = oControl
|
||||
oReplaceValue = oCheckBox.Checked
|
||||
Case Else
|
||||
oReplaceValue = "0"
|
||||
End Select
|
||||
|
||||
oResult = BaseFunctions.ReplacePattern(oResult, PatternIdentifier, oReplaceValue)
|
||||
End If
|
||||
|
||||
BaseFunctions.IncrementCounterOrThrow(oCounter)
|
||||
End While
|
||||
|
||||
Return oResult
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
19
Modules.Patterns/Modules/IModule.vb
Normal file
19
Modules.Patterns/Modules/IModule.vb
Normal file
@@ -0,0 +1,19 @@
|
||||
Public Interface IModule
|
||||
''' <summary>
|
||||
''' The short identifier which identifies all placeholders of this module
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Property PatternIdentifier As String
|
||||
|
||||
''' <summary>
|
||||
''' Does this Module have outside dependencies like a database or a library like windream
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Property IsComplex As Boolean
|
||||
|
||||
''' <summary>
|
||||
''' Main Replace Function
|
||||
''' </summary>
|
||||
''' <returns>The replaced string</returns>
|
||||
Function Replace(pInput As String, pReplaceMap As Dictionary(Of String, Object)) As String
|
||||
End Interface
|
||||
57
Modules.Patterns/Modules/Internal.vb
Normal file
57
Modules.Patterns/Modules/Internal.vb
Normal file
@@ -0,0 +1,57 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Namespace [PatternModule]
|
||||
''' <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 Property PatternIdentifier As String = "INT" Implements IModule.PatternIdentifier
|
||||
|
||||
Public Property IsComplex As Boolean = False Implements IModule.IsComplex
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pBaseFunctions As BaseFunctions)
|
||||
MyBase.New(pLogConfig)
|
||||
End Sub
|
||||
|
||||
Public Function Replace(pInput As String, pReplaceMap As Dictionary(Of String, Object)) As String Implements IModule.Replace
|
||||
Dim oResult = pInput
|
||||
Dim oCounter = 0
|
||||
|
||||
' Replace Username(s)
|
||||
While BaseFunctions.ContainsPatternAndValue(oResult, PatternIdentifier, INT_VALUE_USERNAME)
|
||||
oResult = BaseFunctions.ReplacePattern(oResult, PatternIdentifier, pReplaceMap.Item(INT_VALUE_USERNAME))
|
||||
BaseFunctions.IncrementCounterOrThrow(oCounter)
|
||||
End While
|
||||
|
||||
' Replace Machinename(s)
|
||||
While BaseFunctions.ContainsPatternAndValue(oResult, PatternIdentifier, INT_VALUE_MACHINE)
|
||||
oResult = BaseFunctions.ReplacePattern(oResult, PatternIdentifier, pReplaceMap.Item(INT_VALUE_MACHINE))
|
||||
BaseFunctions.IncrementCounterOrThrow(oCounter)
|
||||
End While
|
||||
|
||||
|
||||
' Replace Domainname(s)
|
||||
While BaseFunctions.ContainsPatternAndValue(oResult, PatternIdentifier, INT_VALUE_DOMAIN)
|
||||
oResult = BaseFunctions.ReplacePattern(oResult, PatternIdentifier, pReplaceMap.Item(INT_VALUE_DOMAIN))
|
||||
BaseFunctions.IncrementCounterOrThrow(oCounter)
|
||||
End While
|
||||
|
||||
|
||||
' Replace CurrentDate(s)
|
||||
While BaseFunctions.ContainsPatternAndValue(oResult, PatternIdentifier, INT_VALUE_DATE)
|
||||
oResult = BaseFunctions.ReplacePattern(oResult, PatternIdentifier, pReplaceMap.Item(INT_VALUE_DATE))
|
||||
BaseFunctions.IncrementCounterOrThrow(oCounter)
|
||||
End While
|
||||
|
||||
Return oResult
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user