Patterns: WIP Patterns version 2
This commit is contained in:
134
Modules.Patterns/Patterns2.vb
Normal file
134
Modules.Patterns/Patterns2.vb
Normal file
@@ -0,0 +1,134 @@
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports System.Windows.Forms
|
||||
Imports DigitalData.Controls.LookupGrid
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports WINDREAMLib
|
||||
|
||||
''' <summary>
|
||||
''' Defines common Functions for Checking for and replacing placeholders.
|
||||
''' This Class also includes a child class `Pattern` for passing around Patterns.
|
||||
'''
|
||||
''' The format of all placeholders is:
|
||||
''' {#TYPE#VALUE}
|
||||
'''
|
||||
''' Some Examples:
|
||||
''' {#INT#USERNAME}
|
||||
''' {#CTRL#CMB_2}
|
||||
''' {#WMI#String 39}
|
||||
''' </summary>
|
||||
Public Class clsPatterns
|
||||
''' <summary>
|
||||
''' Complex patterns that rely on Windream
|
||||
''' </summary>
|
||||
Public Const PATTERN_WMI = "WMI"
|
||||
|
||||
''' <summary>
|
||||
''' Complex patterns that rely on IDB Attribute values
|
||||
''' </summary>
|
||||
Public Const PATTERN_IDBA = "IDBA"
|
||||
|
||||
''' <summary>
|
||||
''' Complex patterns that rely on Control Values
|
||||
''' </summary>
|
||||
Public Const PATTERN_CTRL = "CTRL"
|
||||
|
||||
''' <summary>
|
||||
''' Simple patterns that rely on Data from the TBDD_USER table
|
||||
''' </summary>
|
||||
Public Const PATTERN_USER = "USER"
|
||||
|
||||
Public Const USER_VALUE_PRENAME = "PRENAME"
|
||||
Public Const USER_VALUE_SURNAME = "SURNAME"
|
||||
Public Const USER_VALUE_EMAIL = "EMAIL"
|
||||
Public Const USER_VALUE_SHORTNAME = "SHORTNAME"
|
||||
Public Const USER_VALUE_LANGUAGE = "LANGUAGE"
|
||||
Public Const USER_VALUE_USER_ID = "USER_ID"
|
||||
Public Const VALUE_PROFILE_ID = "PROFILE_ID"
|
||||
Public Const VALUE_PROFILE_TITLE = "PROFILE_TITLE"
|
||||
|
||||
Private ReadOnly LogConfig As LogConfig
|
||||
Private ReadOnly Logger As Logger
|
||||
|
||||
Private ReadOnly ControlPanel As Panel
|
||||
Private ReadOnly IDBActive As Boolean
|
||||
Private ReadOnly Base As BaseFunctions
|
||||
|
||||
Private ReadOnly Modules As New List(Of IModule)
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig)
|
||||
LogConfig = pLogConfig
|
||||
Logger = pLogConfig.GetLogger()
|
||||
Base = New BaseFunctions(LogConfig)
|
||||
|
||||
Modules.Add(New PatternModule.Internal(LogConfig, Base))
|
||||
End Sub
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pControlPanel As Panel, pIDBActive As Boolean)
|
||||
MyClass.New(pLogConfig)
|
||||
ControlPanel = pControlPanel
|
||||
IDBActive = pIDBActive
|
||||
End Sub
|
||||
|
||||
Public Function ReplaceAllValues(pInput As String, pPanel As Panel) As String
|
||||
Dim oResult = pInput
|
||||
|
||||
For Each oModule In Modules
|
||||
Try
|
||||
Dim oArgs = GetReplaceMapForModule(oModule, pPanel)
|
||||
oResult = oModule.Replace(oResult, oArgs)
|
||||
Catch ex As Exception
|
||||
Logger.Warn("Placeholders for String [{0}] could not be replaced completely in Module [{1}]. Skipping.", pInput, oModule.GetType.Name)
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
Next
|
||||
|
||||
Return oResult
|
||||
End Function
|
||||
|
||||
Private Function GetReplaceMapForModule(pModule As IModule, pPanel As Panel) As Dictionary(Of String, Object)
|
||||
Dim oArgs As New Dictionary(Of String, Object)
|
||||
|
||||
If TypeOf pModule Is PatternModule.Clipboard Then
|
||||
oArgs.Add(PatternModule.Clipboard.CLIP_VALUE_BOARD, My.Computer.Clipboard.GetText())
|
||||
|
||||
ElseIf TypeOf pModule Is PatternModule.Internal Then
|
||||
oArgs.Add(PatternModule.Internal.INT_VALUE_USERNAME, Environment.UserName)
|
||||
oArgs.Add(PatternModule.Internal.INT_VALUE_MACHINE, Environment.MachineName)
|
||||
oArgs.Add(PatternModule.Internal.INT_VALUE_DOMAIN, Environment.UserDomainName)
|
||||
oArgs.Add(PatternModule.Internal.INT_VALUE_DATE, Now.ToShortDateString)
|
||||
|
||||
ElseIf TypeOf pModule Is PatternModule.Controls Then
|
||||
oArgs.Add(PatternModule.Controls.CTRL_VALUE_PANEL, pPanel)
|
||||
|
||||
End If
|
||||
|
||||
Return oArgs
|
||||
End Function
|
||||
|
||||
#Region "Helper Functions"
|
||||
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Wraps a pattern-type and -value in the common format: {#type#value}
|
||||
''' </summary>
|
||||
Public Function WrapPatternValue(pType As String, pValue As String) As String
|
||||
Return New Pattern(pType, pValue).ToString
|
||||
End Function
|
||||
|
||||
Public Function HasAnyPatterns(input) As Boolean
|
||||
Return Modules.Any(Function(m) Base.HasPattern(input, m.PatternIdentifier))
|
||||
End Function
|
||||
|
||||
Public Function HasComplexPatterns(input As String) As Boolean
|
||||
Return Modules.
|
||||
Where(Function(m) m.IsComplex = True).
|
||||
Any(Function(m) Base.HasPattern(input, m.PatternIdentifier))
|
||||
End Function
|
||||
|
||||
Public Function HasOnlySimplePatterns(input As String) As Boolean
|
||||
Return Not HasComplexPatterns(input)
|
||||
End Function
|
||||
#End Region
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user