4 Commits

Author SHA1 Message Date
Jonathan Jenne
cbab70c288 EDMIAPI: Version 1.2.4 2021-11-04 14:29:16 +01:00
Jonathan Jenne
fe3f9c5156 Patterns: Begin IDB Module 2021-11-04 14:28:29 +01:00
Jonathan Jenne
a900379704 EDMIAPI: First usable version of DatabaseWithFallback 2021-11-04 14:28:13 +01:00
Jonathan Jenne
bd176e3de0 Patterns: Add Controls and Windream Modules 2021-11-04 14:19:21 +01:00
11 changed files with 262 additions and 111 deletions

View File

@@ -47,15 +47,15 @@ Public Class DatabaseWithFallback
End If
End Function
Public Function GetDatatable(DataTable As String, FallbackSQL As String, FallbackType As Constants.DatabaseType, Optional FilterExpression As String = "", Optional SortByColumn As String = "", Optional ForceFallback As Boolean = False) As DataTable
Public Function GetDatatable(pDataTableName As String, pFallbackSQL As String, pFallbackType As Constants.DatabaseType, Optional pFilterExpression As String = "", Optional pSortByColumn As String = "", Optional pForceFallback As Boolean = False) As DataTable
Try
Dim oResult As DataTable = Nothing
If ForceFallback = False Then
If pForceFallback = False Then
Dim oTableResult As TableResult
Try
oTableResult = _Client.GetDatatableByName(DataTable, FilterExpression, SortByColumn)
oTableResult = _Client.GetDatatableByName(pDataTableName, pFilterExpression, pSortByColumn)
Catch ex As Exception
_Logger.Error(ex)
oTableResult = Nothing
@@ -63,12 +63,12 @@ Public Class DatabaseWithFallback
If oTableResult Is Nothing OrElse oTableResult.OK = False Then
_Logger.Warn("Datatable [{0}] could not be fetched from AppServer Cache. Falling back to direct Database Access.")
Return GetDatatableFromDatabase(FallbackSQL, FallbackType)
Return GetDatatableFromDatabase(pFallbackSQL, pFallbackType)
End If
Return oTableResult.Table
Else
Return GetDatatableFromDatabase(FallbackSQL, FallbackType)
Return GetDatatableFromDatabase(pFallbackSQL, pFallbackType)
End If
Catch ex As Exception
_Logger.Error(ex)
@@ -95,32 +95,5 @@ Public Class DatabaseWithFallback
End Try
End Function
Public Function GetUserData(UserName As String, ModuleCode As String, Client As Integer) As UserData
'Dim oSQL = $"SELECT * FROM FNDD_CHECK_USER_MODULE('{UserName}','{ModuleCode}',{Client})"
'Dim oTable As DataTable = GetDatatable("TBDD_USER_MODULE", $"USERNAME = '{UserName.ToLower}' AND MODULE_SHORT = '{ModuleCode}'", "", oSQL, DatabaseType.ECM)
'If oTable Is Nothing Then
' Return Nothing
'End If
'If oTable.Rows.Count = 0 Then
' Return Nothing
'End If
'Dim oRow As DataRow = oTable.Rows.Item(0)
'Dim oUserData As New UserData With {
' .Id = NotNull(oRow, "USER_ID", -1),
' .Surname = NotNull(oRow, "USER_SURNAME", String.Empty),
' .Prename = NotNull(oRow, "USER_PRENAME", String.Empty),
' .Shortname = NotNull(oRow, "USER_SHORTNAME", String.Empty),
' .Email = NotNull(oRow, "USER_EMAIL", String.Empty),
' .Language = NotNull(oRow, "USER_LANGUAGE", "de-DE"),
' .DateFormat = NotNull(oRow, "USER_DATE_FORMAT", "dd.MM.yyyy")
'}
Throw New NotImplementedException()
End Function
End Class

View File

@@ -1,14 +0,0 @@
Public Class UserData
Public Id As Integer
Public Surname As String
Public Prename As String
Public Shortname As String
Public Email As String
Public Language As String
Public DateFormat As String
Public IsAdmin As Boolean
Public HasAccess As Boolean
Public ModuleName As String
End Class

View File

@@ -97,7 +97,6 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="DatabaseWithFallback\UserData.vb" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="My Project\Resources.resx">

View File

@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.2.3.0")>
<Assembly: AssemblyFileVersion("1.2.3.0")>
<Assembly: AssemblyVersion("1.2.4.0")>
<Assembly: AssemblyFileVersion("1.2.4.0")>

View File

@@ -3,9 +3,11 @@ Imports System.Text.RegularExpressions
Namespace [PatternModule]
Public Class BaseModule
Friend ReadOnly Logger As Logger
Private ReadOnly Logger As Logger
Private ReadOnly MyRegex As Regex = New Regex("{#(\w+)#([\:\.\w\s_-]+)}+")
Private ReadOnly SqlPhrases As New List(Of String) From {
"SELECT ", "UPDATE ", "DELETE ", "EXEC "
}
Private Const MAX_TRY_COUNT = 500
@@ -21,23 +23,37 @@ Namespace [PatternModule]
pCounter += 1
End Sub
Public Function ReplacePattern(input As String, type As String, replacement As String) As String
Dim elements As MatchCollection = MyRegex.Matches(input)
Public Function ReplacePattern(pInput As String, pType As String, pReplacement As String) As String
Dim oElements As MatchCollection = MyRegex.Matches(pInput)
If IsNothing(replacement) Then
Return input
If IsNothing(pReplacement) Then
Return pInput
End If
For Each element As Match In elements
Dim oIsSQL As Boolean = False
For Each oPhrase In SqlPhrases
If pInput.Contains(oPhrase) Then
oIsSQL = True
Exit For
End If
Next
If oIsSQL = True Then
Logger.Debug("Input string is most likely an SQL Query, masking quotes in replacement string.")
pReplacement = pReplacement.Replace("'", "''")
End If
For Each oElement As Match In oElements
' if group 1 contains the 'pattern' the replace whole group with 'replacement'
' and return it
If element.Groups(1).Value = type Then
Return Regex.Replace(input, element.Groups(0).Value, replacement)
If oElement.Groups(1).Value = pType Then
Logger.Debug("Replacing Placeholder with [{0}]", pReplacement)
Return Regex.Replace(pInput, oElement.Groups(0).Value, pReplacement)
End If
Next
' no replacement made
Return input
Return pInput
End Function
Public Function ContainsPatternAndValue(pInput As String, pType As String, pValue As String) As Boolean
@@ -45,10 +61,10 @@ Namespace [PatternModule]
For Each oElement As Match In oElements
' Pattern in pInput
Dim t As String = oElement.Groups(1).Value
Dim v As String = oElement.Groups(2).Value
Dim oType As String = oElement.Groups(1).Value
Dim oValue As String = oElement.Groups(2).Value
If t = pType And v = pValue Then
If oType = pType And oValue = pValue Then
Return True
End If
Next
@@ -84,16 +100,16 @@ Namespace [PatternModule]
Return False
End Function
Public Function GetNextPattern(input As String, type As String) As Pattern
Dim elements As MatchCollection = MyRegex.Matches(input)
Public Function GetNextPattern(pInput As String, pType As String) As Pattern
Dim oElements As MatchCollection = MyRegex.Matches(pInput)
For Each element As Match In elements
For Each oElement As Match In oElements
' Pattern in pInput
Dim t As String = element.Groups(1).Value
Dim v As String = element.Groups(2).Value
Dim oType As String = oElement.Groups(1).Value
Dim oValue As String = oElement.Groups(2).Value
If t = type Then
Return New Pattern(t, v)
If oType = pType Then
Return New Pattern(oType, oValue)
End If
Next

View File

@@ -4,55 +4,62 @@ Imports DigitalData.Modules.Logging
Namespace [PatternModule]
''' <summary>
''' Simple patterns that only rely on .NET functions
''' Patterns for control values on a panel
''' </summary>
Public Class Controls
Inherits BaseModule
Implements IModule
Public Const CTRL_VALUE_PANEL = "PANEL"
Public Const CTRL_VALUE_PANEL = "CTRL_VALUE_PANEL"
Public Property PatternIdentifier As String = "CTRL" Implements IModule.PatternIdentifier
Public Property IsComplex As Boolean = True Implements IModule.IsComplex
Private ReadOnly Logger As Logger
Public Sub New(pLogConfig As LogConfig)
MyBase.New(pLogConfig)
Logger = pLogConfig.GetLogger()
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")
Dim oPanel As Panel = pReplaceMap.Item(CTRL_VALUE_PANEL)
While ContainsPattern(oResult, PatternIdentifier)
Dim oControlName As String = GetNextPattern(oResult, PatternIdentifier).Value
Dim oControl As Control = oPanel.Controls.Find(oControlName, False).FirstOrDefault()
Try
Dim oControlName As String = 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
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 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
End Select
oResult = ReplacePattern(oResult, PatternIdentifier, oReplaceValue)
End If
oResult = ReplacePattern(oResult, PatternIdentifier, oReplaceValue)
End If
Catch ex As Exception
Logger.Error(ex)
Finally
IncrementCounterOrThrow(oCounter)
End Try
IncrementCounterOrThrow(oCounter)
End While
Return oResult

View File

@@ -0,0 +1,31 @@
Imports System.Windows.Forms
Imports DigitalData.Controls.LookupGrid
Imports DigitalData.Modules.Logging
Namespace [PatternModule]
''' <summary>
''' Patterns for Windream Indicies
''' </summary>
Public Class IDB
Inherits BaseModule
Implements IModule
Public Const IDB_OBJECT_ID = "IDB_OBJECT_ID"
Public Property PatternIdentifier As String = "IDB" Implements IModule.PatternIdentifier
Public Property IsComplex As Boolean = True Implements IModule.IsComplex
Private ReadOnly Logger As Logger
Public Sub New(pLogConfig As LogConfig)
MyBase.New(pLogConfig)
Logger = pLogConfig.GetLogger()
End Sub
Public Function Replace(pInput As String, pReplaceMap As Dictionary(Of String, Object)) As String Implements IModule.Replace
'TODO: Implement, depends on IDB Data, which is not in monorepo yet
Return pInput
End Function
End Class
End Namespace

View File

@@ -0,0 +1,53 @@
Imports System.Windows.Forms
Imports DigitalData.Controls.LookupGrid
Imports DigitalData.Modules.Logging
Namespace [PatternModule]
''' <summary>
''' Patterns for Windream Indicies
''' </summary>
Public Class Windream
Inherits BaseModule
Implements IModule
Public Const WM_VALUE_DOCUMENT = "WM_DOCUMENT"
Public Property PatternIdentifier As String = "WMI" Implements IModule.PatternIdentifier
Public Property IsComplex As Boolean = True Implements IModule.IsComplex
Private ReadOnly Logger As Logger
Public Sub New(pLogConfig As LogConfig)
MyBase.New(pLogConfig)
Logger = pLogConfig.GetLogger()
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 pWMObject As WINDREAMLib.WMObject = pReplaceMap.Item(WM_VALUE_DOCUMENT)
While ContainsPattern(oResult, PatternIdentifier)
Try
Dim oIndexName As String = GetNextPattern(oResult, PatternIdentifier).Value
Dim oWMValue As Object = pWMObject.GetVariableValue(oIndexName)
If oWMValue Is Nothing Then
Logger.Warn("Value for Index [{0}] is empty and will not be used for replacing. Skipping.")
Return oResult
End If
oResult = ReplacePattern(oResult, PatternIdentifier, oWMValue.ToString)
Catch ex As Exception
Logger.Error(ex)
Return oResult
Finally
IncrementCounterOrThrow(oCounter)
End Try
End While
Return oResult
End Function
End Class
End Namespace

View File

@@ -12,7 +12,7 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("Patterns")>
<Assembly: AssemblyCopyright("Copyright © 2019")>
<Assembly: AssemblyCopyright("Copyright © 2021")>
<Assembly: AssemblyTrademark("")>
<Assembly: ComVisible(False)>

View File

@@ -81,6 +81,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Constants.vb" />
<Compile Include="Modules\IDB.vb" />
<Compile Include="Modules\Windream.vb" />
<Compile Include="Modules\User.vb" />
<Compile Include="Modules\IModule.vb" />
<Compile Include="Modules\Clipboard.vb" />

View File

@@ -91,29 +91,113 @@ Public Class Patterns2
Return oResult
End Function
Private Function GetReplaceMapForModule(pModule As IModule, pPanel As Panel, pUser As State.UserState) As Dictionary(Of String, Object)
Public Function ReplaceUserValues(pInput As String, pUser As State.UserState) As String
Dim oResult = pInput
Dim oModule = GetModule(Of PatternModule.User)()
Dim oArgs = GetReplaceMapForModule(oModule, pUser:=pUser)
oResult = DoReplaceForModule(oResult, oModule, oArgs)
Return oResult
End Function
Public Function ReplaceControlValues(pInput As String, pPanel As Panel) As String
Dim oResult = pInput
Dim oModule = GetModule(Of PatternModule.Controls)()
Dim oArgs = GetReplaceMapForModule(oModule, pPanel:=pPanel)
oResult = DoReplaceForModule(oResult, oModule, oArgs)
Return oResult
End Function
Public Function ReplaceWindreamValues(pInput As String, pWMObject As WMObject) As String
Dim oResult = pInput
Dim oModule = GetModule(Of PatternModule.Windream)()
Dim oArgs = GetReplaceMapForModule(oModule, pWMObject:=pWMObject)
oResult = DoReplaceForModule(oResult, oModule, oArgs)
Return oResult
End Function
Public Function ReplaceInternalValues(pInput As String) As String
Dim oResult = pInput
Dim oInternalModule = GetModule(Of PatternModule.Internal)()
Dim oInternalArgs = GetReplaceMapForModule(oInternalModule)
oResult = DoReplaceForModule(oResult, oInternalModule, oInternalArgs)
Dim oClipboardModule = GetModule(Of PatternModule.Clipboard)()
Dim oClipboardArgs = GetReplaceMapForModule(oClipboardModule)
oResult = DoReplaceForModule(oResult, oClipboardModule, oClipboardArgs)
Return oResult
End Function
Private Function DoReplaceForModule(pInput As String, pModule As IModule, pArgs As Dictionary(Of String, Object)) As String
Try
pInput = pModule.Replace(pInput, pArgs)
Catch ex As Exception
Logger.Warn("Placeholders for String [{0}] could not be replaced completely in Module [{1}]. Skipping.", pInput, pModule.GetType.Name)
Logger.Error(ex)
End Try
Return pInput
End Function
Private Function GetModule(Of ModuleT)() As IModule
Return Modules.
Where(Function(m) TypeOf m Is ModuleT).
SingleOrDefault()
End Function
Private Function GetReplaceMapForModule(pModule As IModule, Optional pPanel As Panel = Nothing, Optional pUser As State.UserState = Nothing, Optional pWMObject As WMObject = Nothing) 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())
Try
oArgs.Add(PatternModule.Clipboard.CLIP_VALUE_BOARD, My.Computer.Clipboard.GetText())
Catch ex As Exception
Logger.Error(ex)
End Try
ElseIf TypeOf pModule Is PatternModule.Internal Then
oArgs.Add(PatternModule.Internal.INT_VALUE_USERNAME, System.Environment.UserName)
oArgs.Add(PatternModule.Internal.INT_VALUE_MACHINE, System.Environment.MachineName)
oArgs.Add(PatternModule.Internal.INT_VALUE_DOMAIN, System.Environment.UserDomainName)
oArgs.Add(PatternModule.Internal.INT_VALUE_DATE, Now.ToShortDateString)
Try
oArgs.Add(PatternModule.Internal.INT_VALUE_USERNAME, System.Environment.UserName)
oArgs.Add(PatternModule.Internal.INT_VALUE_MACHINE, System.Environment.MachineName)
oArgs.Add(PatternModule.Internal.INT_VALUE_DOMAIN, System.Environment.UserDomainName)
oArgs.Add(PatternModule.Internal.INT_VALUE_DATE, Now.ToShortDateString)
Catch ex As Exception
Logger.Error(ex)
End Try
ElseIf TypeOf pModule Is PatternModule.User Then
oArgs.Add(PatternModule.User.USER_VALUE_EMAIL, pUser.Email)
oArgs.Add(PatternModule.User.USER_VALUE_LANGUAGE, pUser.Language)
oArgs.Add(PatternModule.User.USER_VALUE_PRENAME, pUser.GivenName)
oArgs.Add(PatternModule.User.USER_VALUE_SHORTNAME, pUser.ShortName)
oArgs.Add(PatternModule.User.USER_VALUE_SURNAME, pUser.Surname)
oArgs.Add(PatternModule.User.USER_VALUE_USER_ID, pUser.UserId)
oArgs.Add(PatternModule.User.USER_VALUE_USER_NAME, pUser.UserName)
Try
oArgs.Add(PatternModule.User.USER_VALUE_EMAIL, pUser.Email)
oArgs.Add(PatternModule.User.USER_VALUE_LANGUAGE, pUser.Language)
oArgs.Add(PatternModule.User.USER_VALUE_PRENAME, pUser.GivenName)
oArgs.Add(PatternModule.User.USER_VALUE_SHORTNAME, pUser.ShortName)
oArgs.Add(PatternModule.User.USER_VALUE_SURNAME, pUser.Surname)
oArgs.Add(PatternModule.User.USER_VALUE_USER_ID, pUser.UserId)
oArgs.Add(PatternModule.User.USER_VALUE_USER_NAME, pUser.UserName)
Catch ex As Exception
Logger.Error(ex)
End Try
ElseIf TypeOf pModule Is PatternModule.Controls Then
oArgs.Add(PatternModule.Controls.CTRL_VALUE_PANEL, pPanel)
Try
oArgs.Add(PatternModule.Controls.CTRL_VALUE_PANEL, pPanel)
Catch ex As Exception
Logger.Error(ex)
End Try
ElseIf TypeOf pModule Is PatternModule.Windream Then
Try
oArgs.Add(PatternModule.Windream.WM_VALUE_DOCUMENT, pWMObject)
Catch ex As Exception
Logger.Error(ex)
End Try
End If