Placeholder for Grids Column
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports WINDREAMLib
|
||||
Imports DigitalData.Controls.LookupGrid
|
||||
Imports DevExpress.XtraGrid
|
||||
Imports DevExpress.XtraGrid.Views.Grid
|
||||
Imports DevExpress.XtraGrid.Columns
|
||||
''' <summary>
|
||||
''' Defines common Functions for Checking for and replacing placeholders.
|
||||
''' This Class also includes a child class `Pattern` for passing around Patterns.
|
||||
@@ -17,6 +20,13 @@ Public Class clsPatterns
|
||||
' Complex patterns that rely on a datasource like a Database or Windream
|
||||
Public Const PATTERN_WMI = "WMI"
|
||||
Public Const PATTERN_IDBA = "IDBA"
|
||||
' Kinds of CTRL Placeholder
|
||||
'
|
||||
' Normal Control
|
||||
' {#CTRL#ControlName}
|
||||
'
|
||||
' Summary Item from Table Column
|
||||
' {#CTRL#ControlName::ColumnName}
|
||||
Public Const PATTERN_CTRL = "CTRL"
|
||||
' Simple patterns that only rely on .NET functions
|
||||
Public Const PATTERN_INT = "INT"
|
||||
@@ -37,12 +47,13 @@ Public Class clsPatterns
|
||||
Public Const INT_VALUE_DOMAIN = "DOMAIN"
|
||||
Public Const INT_VALUE_DATE = "DATE"
|
||||
|
||||
Public Const MAX_TRY_COUNT = 500
|
||||
Public Const MAX_TRY_COUNT = 50
|
||||
Public Const ERROR_REPLACE_VALUE = "[Replace Error]"
|
||||
|
||||
Private Shared MyRegex As Regex = New Regex("{#(\w+)#([\:\.\w\s_-]+)}+")
|
||||
Private Shared allPatterns As New List(Of String) From {PATTERN_WMI, PATTERN_CTRL, PATTERN_IDBA, PATTERN_USER, PATTERN_INT}
|
||||
Private Shared complexPatterns As New List(Of String) From {PATTERN_WMI, PATTERN_CTRL, PATTERN_IDBA}
|
||||
Private Shared simplePatterns As New List(Of String) From {PATTERN_USER, PATTERN_INT}
|
||||
Private Shared ReadOnly MyRegex As Regex = New Regex("{#(\w+)#([\:\.\w\s_-]+)}+")
|
||||
Private Shared ReadOnly allPatterns As New List(Of String) From {PATTERN_WMI, PATTERN_CTRL, PATTERN_IDBA, PATTERN_USER, PATTERN_INT}
|
||||
Private Shared ReadOnly complexPatterns As New List(Of String) From {PATTERN_WMI, PATTERN_CTRL, PATTERN_IDBA}
|
||||
Private Shared ReadOnly simplePatterns As New List(Of String) From {PATTERN_USER, PATTERN_INT}
|
||||
|
||||
''' <summary>
|
||||
''' Wraps a pattern-type and -value in the common format: {#type#value}
|
||||
@@ -77,34 +88,36 @@ Public Class clsPatterns
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Shared Function ReplaceInternalValues(input As String) As String
|
||||
Try
|
||||
Dim result = input
|
||||
Public Shared Function ReplaceInternalValues(pInput As String) As String
|
||||
Dim oResult = pInput
|
||||
|
||||
Try
|
||||
' Replace Username(s)
|
||||
While ContainsPatternAndValue(result, PATTERN_INT, INT_VALUE_USERNAME)
|
||||
result = ReplacePattern(result, PATTERN_INT, USER_USERNAME)
|
||||
While ContainsPatternAndValue(oResult, PATTERN_INT, INT_VALUE_USERNAME)
|
||||
oResult = ReplacePattern(oResult, PATTERN_INT, USER_USERNAME)
|
||||
End While
|
||||
|
||||
' Replace Machinename(s)
|
||||
While ContainsPatternAndValue(result, PATTERN_INT, INT_VALUE_MACHINE)
|
||||
result = ReplacePattern(result, PATTERN_INT, Environment.MachineName)
|
||||
While ContainsPatternAndValue(oResult, PATTERN_INT, INT_VALUE_MACHINE)
|
||||
oResult = ReplacePattern(oResult, PATTERN_INT, Environment.MachineName)
|
||||
End While
|
||||
|
||||
' Replace Domainname(s)
|
||||
While ContainsPatternAndValue(result, PATTERN_INT, INT_VALUE_DOMAIN)
|
||||
result = ReplacePattern(result, PATTERN_INT, Environment.UserDomainName)
|
||||
While ContainsPatternAndValue(oResult, PATTERN_INT, INT_VALUE_DOMAIN)
|
||||
oResult = ReplacePattern(oResult, PATTERN_INT, Environment.UserDomainName)
|
||||
End While
|
||||
|
||||
' Replace CurrentDate(s)
|
||||
While ContainsPatternAndValue(result, PATTERN_INT, INT_VALUE_DATE)
|
||||
result = ReplacePattern(result, PATTERN_INT, Now.ToShortDateString)
|
||||
While ContainsPatternAndValue(oResult, PATTERN_INT, INT_VALUE_DATE)
|
||||
oResult = ReplacePattern(oResult, PATTERN_INT, Now.ToShortDateString)
|
||||
End While
|
||||
LOGGER.Debug("pInput AFTER ReplaceInternalValues: " & input)
|
||||
Return result
|
||||
|
||||
LOGGER.Debug("pInput AFTER ReplaceInternalValues: " & pInput)
|
||||
Return oResult
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
LOGGER.Info("Error in ReplaceInternalValues:" & ex.Message)
|
||||
Return oResult
|
||||
End Try
|
||||
End Function
|
||||
|
||||
@@ -156,56 +169,91 @@ Public Class clsPatterns
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Shared Function ReplaceControlValues(input As String, panel As Panel, IS_SQL As Boolean) As String
|
||||
Public Shared Function ReplaceControlValues(pInput As String, oPanel As Panel, oIsSQL As Boolean) As String
|
||||
Dim oResult = pInput
|
||||
|
||||
Try
|
||||
Dim result = input
|
||||
|
||||
Dim oTryCounter = 0
|
||||
|
||||
While ContainsPattern(result, PATTERN_CTRL)
|
||||
While ContainsPattern(oResult, PATTERN_CTRL)
|
||||
If oTryCounter > MAX_TRY_COUNT Then
|
||||
LOGGER.Warn($"Max tries in ReplaceControlValues exceeded - Replacing with [0]")
|
||||
result = ReplacePattern(result, PATTERN_CTRL, 0)
|
||||
Throw New Exception($"Max tries in ReplaceControlValues exceeded - Result so far [{result}].")
|
||||
oResult = ReplacePattern(oResult, PATTERN_CTRL, 0)
|
||||
Throw New Exception($"Max tries in ReplaceControlValues exceeded - Result so far [{oResult}].")
|
||||
End If
|
||||
|
||||
Dim controlName As String = GetNextPattern(result, PATTERN_CTRL).Value
|
||||
Dim oControl As Control = panel.Controls.Find(controlName, False).FirstOrDefault()
|
||||
Dim oControlName As String = GetNextPattern(oResult, PATTERN_CTRL).Value
|
||||
Dim oColumnName As String = String.Empty
|
||||
|
||||
If oControlName.Contains("::") Then
|
||||
Dim oSplitName = Split(oControlName, "::").ToList()
|
||||
oControlName = oSplitName.First()
|
||||
oColumnName = oSplitName.Last()
|
||||
End If
|
||||
|
||||
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
|
||||
Select Case oControl.GetType
|
||||
Case GetType(TextBox)
|
||||
oReplaceValue = oControl.Text
|
||||
Case GetType(LookupControl3).ToString
|
||||
|
||||
Case GetType(LookupControl3)
|
||||
Dim oLookupControl3 As LookupControl3 = oControl
|
||||
If oLookupControl3.Properties.SelectedValues.Count = 1 Then
|
||||
oReplaceValue = oLookupControl3.Properties.SelectedValues.Item(0)
|
||||
Else
|
||||
oReplaceValue = "0"
|
||||
oReplaceValue = ERROR_REPLACE_VALUE
|
||||
End If
|
||||
Case GetType(ComboBox).ToString
|
||||
|
||||
Case GetType(ComboBox)
|
||||
oReplaceValue = oControl.Text
|
||||
Case GetType(CheckBox).ToString
|
||||
|
||||
Case GetType(CheckBox)
|
||||
Dim oCheckBox As CheckBox = oControl
|
||||
oReplaceValue = oCheckBox.Checked
|
||||
|
||||
Case GetType(GridControl)
|
||||
Dim oGrid As GridControl = oControl
|
||||
Dim oView As GridView = oGrid.FocusedView
|
||||
|
||||
If oColumnName = String.Empty Then
|
||||
LOGGER.Warn("Used placeholder for Table [{0}] but without Column Name!", oControlName)
|
||||
oReplaceValue = ERROR_REPLACE_VALUE
|
||||
End If
|
||||
|
||||
Dim oColumn As GridColumn = oView.Columns.
|
||||
Where(Function(c) c.FieldName = oColumnName).
|
||||
SingleOrDefault()
|
||||
|
||||
If oColumn Is Nothing Then
|
||||
LOGGER.Warn("Column [{0}] not found in Grid!", oColumnName)
|
||||
oReplaceValue = ERROR_REPLACE_VALUE
|
||||
End If
|
||||
|
||||
oReplaceValue = oColumn.SummaryItem.SummaryValue
|
||||
|
||||
Case Else
|
||||
oReplaceValue = "0"
|
||||
oReplaceValue = ERROR_REPLACE_VALUE
|
||||
End Select
|
||||
If IS_SQL = True Then
|
||||
If oIsSQL = True Then
|
||||
LOGGER.Debug($"IS_SQL = True - oReplaceValue = {oReplaceValue}")
|
||||
oReplaceValue = oReplaceValue.Replace("'", "''")
|
||||
LOGGER.Debug($"oReplaceValue = {oReplaceValue}")
|
||||
End If
|
||||
result = ReplacePattern(result, PATTERN_CTRL, oReplaceValue)
|
||||
oResult = ReplacePattern(oResult, PATTERN_CTRL, oReplaceValue)
|
||||
End If
|
||||
|
||||
oTryCounter += 1
|
||||
End While
|
||||
LOGGER.Debug("pInput AFTER ReplaceControlValues: " & input)
|
||||
Return result
|
||||
LOGGER.Debug("pInput AFTER ReplaceControlValues: " & pInput)
|
||||
Return oResult
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
LOGGER.Info("Error in ReplaceControlValues:" & ex.Message)
|
||||
LOGGER.Warn("Error in ReplaceControlValues:" & ex.Message)
|
||||
Return oResult
|
||||
End Try
|
||||
End Function
|
||||
|
||||
@@ -231,7 +279,9 @@ Public Class clsPatterns
|
||||
End If
|
||||
oResult = ReplacePattern(oResult, PATTERN_WMI, oWMValue)
|
||||
End If
|
||||
oTryCounter += 100
|
||||
|
||||
' Increase counter by 10 to avoid DDOSing the Windream Service
|
||||
oTryCounter += 10
|
||||
End While
|
||||
LOGGER.Debug("sql AFTER ReplaceWindreamIndicies: " & pInput)
|
||||
Return oResult
|
||||
@@ -287,7 +337,9 @@ Public Class clsPatterns
|
||||
Dim oReplaceValue = "{" + $"#{PATTERN_IDBA}#{indexName}" + "}"
|
||||
result = result.Replace(oReplaceValue, 0)
|
||||
End If
|
||||
oTryCounter += 100
|
||||
|
||||
' Increase counter by 10 to avoid DDOSing the Database/IDB Service
|
||||
oTryCounter += 10
|
||||
End While
|
||||
LOGGER.Debug("sql after ReplaceIDBAttributes: " & input)
|
||||
Return result
|
||||
|
||||
Reference in New Issue
Block a user