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