stuff and things

This commit is contained in:
Jonathan Jenne
2022-01-26 13:53:51 +01:00
parent eaf6551251
commit 9e77be80e7
5 changed files with 472 additions and 264 deletions

View File

@@ -7,6 +7,7 @@ Imports DigitalData.Modules.Config
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Language.Utils
Imports DigitalData.Modules.Language
Imports DevExpress.XtraTab
Imports DigitalData.Controls.DocumentViewer
Imports DevExpress.XtraEditors
@@ -15,14 +16,15 @@ Imports DevExpress.XtraTreeList.Columns
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.Utils
Imports DevExpress.XtraEditors.Controls
Imports DigitalData.GUIs.Monitor.SearchLoader
Imports DevExpress.XtraLayout
Imports DevExpress.XtraTreeList
Public Class frmMonitor
Public Property LogConfig As LogConfig
Public Property ConfigManager As ConfigManager(Of Config)
Public Property Database As MSSQLServer
Private ReadOnly SearchKeys As New List(Of SearchKey)
Private ReadOnly SQLColumns As New List(Of String) From {"SELECT1", "SELECT2", "SELECT3", "SELECT4"}
Private ReadOnly DocViewColumns As New List(Of String) From {"DOCVIEW1", "DOCVIEW2"}
Private ReadOnly HtmlViewColumns As New List(Of String) From {"HTML1", "HTML2"}
@@ -33,7 +35,7 @@ Public Class frmMonitor
Private ReadOnly DisplayColumns As New List(Of String) From {"COLUMN1", "COLUMN2", "COLUMN3", "ADDED_WHEN", "STATE", "ICON"}
Private SearchLoader As SearchLoader
Private SQLResultGrids As List(Of GridControl)
@@ -77,6 +79,7 @@ Public Class frmMonitor
Try
LogConfig = New LogConfig(LogConfig.PathType.AppData, Nothing, Nothing, "Digital Data", "Monitor")
ConfigManager = New ConfigManager(Of Config)(LogConfig, Application.UserAppDataPath, Application.UserAppDataPath, Application.StartupPath)
InitializeBaseForm(LogConfig)
If ConfigManager.Config.ConnectionString = String.Empty Then
@@ -91,17 +94,18 @@ Public Class frmMonitor
End If
End If
If ConfigManager.Config.IDB_Praefix <> "" Then
If ConfigManager.Config.SearchKeySQL.Contains("@IDB_PRAEFIX") Then
Dim oREPLACE = ConfigManager.Config.SearchKeySQL.Replace("@IDB_PRAEFIX", ConfigManager.Config.IDB_Praefix)
ConfigManager.Config.SearchKeySQL = oREPLACE
If ConfigManager.Config.DBPrefix <> "" Then
If ConfigManager.Config.SearchSQL.Contains("@IDB_PRAEFIX") Then
Dim oREPLACE = ConfigManager.Config.SearchSQL.Replace("@IDB_PRAEFIX", ConfigManager.Config.DBPrefix)
ConfigManager.Config.SearchSQL = oREPLACE
ConfigManager.Save()
End If
Console.WriteLine(ConfigManager.Config.SearchKeySQL)
Console.WriteLine(ConfigManager.Config.SearchSQL)
End If
Dim oConnectionString = MSSQLServer.DecryptConnectionString(ConfigManager.Config.ConnectionString)
Dim oConnectionString = MSSQLServer.DecryptConnectionString(ConfigManager.Config.ConnectionString)
Database = New MSSQLServer(LogConfig, oConnectionString)
SearchLoader = New SearchLoader(LogConfig, ConfigManager.Config, Database)
GridBuilder = New GridBuilder(New List(Of GridView) From {GridView1, GridView2, GridView3, GridView4})
GridBuilder.
WithDefaults().
@@ -118,7 +122,7 @@ Public Class frmMonitor
HtmlResultViewers = New List(Of RichEditControl) From {RichEditControl1, RichEditControl2}
HtmlResultTabs = New List(Of XtraTabPage) From {XtraTabPageHtml1, XtraTabPageHtml2}
LoadSearchKeys()
LoadSearches()
Dim oLicense = LoadGDPicture()
@@ -156,15 +160,25 @@ Public Class frmMonitor
Private Function LoadData() As Boolean
Try
If cmbSearches.EditValue Is Nothing Then
Return False
End If
Dim oSQL As String = $"EXEC [{ConfigManager.Config.IDB_Praefix}].[dbo].[PRDD_MONITORING_GET_TREEVIEW_RESULT] '{cmbSearchKeys.EditValue}','{TextEdit1.EditValue.ToString}',1"
Dim oSQL As String = $"EXEC [{ConfigManager.Config.DBPrefix}].[dbo].[PRDD_MONITORING_GET_TREEVIEW_RESULT] '{cmbSearches.EditValue}','irgendwas','irgendwas','irgendwas',1"
Dim oTable As DataTable = Database.GetDatatable(oSQL)
TreeListResults.DataSource = oTable
TreeListResults.PopulateColumns()
InitTreeList()
Dim oMaxLength = 0
For Each oRow As DataRow In oTable.Rows
Dim oProcess = oRow.Item("COLUMN1")
Dim oLength = oProcess.ToString.Length
If oLength > oMaxLength Then
oMaxLength = oLength
End If
Next
InitTreeList(oMaxLength)
' Show all columns in DisplayColumns List
For Each oColumn In TreeListResults.Columns
@@ -173,14 +187,9 @@ Public Class frmMonitor
oColumn.Format.FormatType = FormatType.DateTime
oColumn.Format.FormatString = "dd.MM.yyyy HH:MM:ss"
End If
Next
'Dim edit As New RepositoryItemDateEdit()
'TreeListResults.Columns("ADDED_WHEN").ColumnEdit = edit
'edit.Mask.EditMask = "g"
'edit.Mask.UseMaskAsDisplayFormat = True
Dim oStateColumn As TreeListColumn = TreeListResults.Columns.Item("STATE")
Dim oStateColumn As TreeListColumn = TreeListResults.Columns.Item("STATE")
For Each oNode As TreeListNode In TreeListResults.Nodes
ExpandNodes(oNode, Function(n)
Dim oObjectValue = n.GetValue(oStateColumn)
@@ -188,6 +197,7 @@ Public Class frmMonitor
Return oValue IsNot Nothing AndAlso (oValue = STATE_WARNING Or oValue = STATE_FAILURE)
End Function)
Next
Return True
Catch ex As Exception
ShowErrorMessage(ex)
@@ -195,27 +205,18 @@ Public Class frmMonitor
End Try
End Function
Private Sub LoadSearchKeys()
Private Sub LoadSearches()
Try
Dim oSQL = ConfigManager.Config.SearchKeySQL
Dim oTable = Database.GetDatatable(oSQL)
SearchLoader.LoadSearches()
For Each oRow As DataRow In oTable.Rows
SearchKeys.Add(New SearchKey With {
.Id = CInt(oRow.Item(0)),
.Title = oRow.Item(1).ToString,
.TypeName = "Varchar"'oRow.Item(2).ToString
})
Next
cmbSearchKeys.Properties.Items.Clear()
cmbSearchKeys.Properties.Items.AddRange(SearchKeys)
cmbSearches.Properties.Items.Clear()
cmbSearches.Properties.Items.AddRange(SearchLoader.Searches)
Catch ex As Exception
ShowErrorMessage(ex)
End Try
End Sub
Private Sub InitTreeList()
Private Sub InitTreeList(pMaxLength As Integer)
TreeListResults.KeyFieldName = "GUID"
TreeListResults.ParentFieldName = "PARENT_ID"
@@ -253,11 +254,21 @@ Public Class frmMonitor
oStateColumn.VisibleIndex = 1
oIconColumn.VisibleIndex = 2
Dim oColumnLength = pMaxLength * 5
With oColumn1
.MinWidth = oColumnLength
.MaxWidth = oColumnLength
.Width = oColumnLength
.OptionsColumn.AllowSize = False
End With
With oStateColumn
.ColumnEdit = oStateEdit
.MaxWidth = 25
.MinWidth = 25
.Width = 25
.Caption = " "
.OptionsColumn.AllowSize = False
.ImageOptions.Image = SvgImageCollection1.GetImage(NodeImage.Success)
End With
@@ -265,30 +276,40 @@ Public Class frmMonitor
.ColumnEdit = oStateEdit
.MaxWidth = 25
.MinWidth = 25
.Width = 25
.Caption = " "
.OptionsColumn.AllowSize = False
.ImageOptions.Image = SvgImageCollection1.GetImage(NodeImage.SQL)
End With
End Sub
Private Sub cmbSearchKeys_SelectedValueChanged(sender As Object, e As EventArgs) Handles cmbSearchKeys.SelectedValueChanged
Dim oItem As SearchKey = CType(cmbSearchKeys.SelectedItem, SearchKey)
Private Sub cmbSearches_SelectedValueChanged(sender As Object, e As EventArgs) Handles cmbSearches.SelectedValueChanged
Dim oSearch As Search = CType(cmbSearches.SelectedItem, Search)
Dim oAttributes = SearchLoader.LoadSearchAttributes(oSearch.Id)
Select Case oItem.TypeName
Case "VARCHAR"
LayoutItemSearchValue_Date.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never
LayoutItemSearchValue_Text.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always
TextEdit1.EditValue = String.Empty
Case "DATE"
LayoutItemSearchValue_Date.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always
LayoutItemSearchValue_Text.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never
ParameterRoot.Items.Clear()
Case Else
LayoutItemSearchValue_Date.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never
LayoutItemSearchValue_Text.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always
BarStaticItem1.Caption = "oItem.TypeName=" + oItem.TypeName
For Each oAttribute In oAttributes
Dim oControl As Control
Select Case oAttribute.DataType
Case "DATE"
oControl = New DateEdit
Case Else
oControl = New TextEdit
End Select
Dim oItem As LayoutControlItem = ParameterRoot.AddItem()
oItem.Text = oAttribute.Caption
oItem.Control = oControl
oItem.TextLocation = Locations.Top
oItem.TextToControlDistance = 3
oItem.Padding = New DevExpress.XtraLayout.Utils.Padding(0, 0, 10, 0)
Next
End Select
End Sub
Private Sub TreeListResults_FocusedNodeChanged(sender As Object, e As DevExpress.XtraTreeList.FocusedNodeChangedEventArgs) Handles TreeListResults.FocusedNodeChanged
@@ -296,98 +317,102 @@ Public Class frmMonitor
Exit Sub
End If
Dim oValues As Dictionary(Of String, String) = GetValuesFromNode(e.Node, DataColumns)
Try
Dim oValues As Dictionary(Of String, String) = GetValuesFromNode(e.Node, DataColumns)
Dim oSQLCommands = oValues.
Where(Function(v) v.Key.StartsWith("SELECT")).
Where(Function(v) v.Value IsNot Nothing).
ToDictionary(Function(v) v.Key, Function(v) v.Value)
Dim oSQLCommands = oValues.
Where(Function(v) v.Key.StartsWith("SELECT")).
Where(Function(v) v.Value IsNot Nothing).
ToDictionary(Function(v) v.Key, Function(v) v.Value)
Dim oFilePaths = oValues.
Where(Function(v) v.Key.StartsWith("DOCVIEW")).
Where(Function(v) v.Value IsNot Nothing).
ToDictionary(Function(v) v.Key, Function(v) v.Value)
Dim oFilePaths = oValues.
Where(Function(v) v.Key.StartsWith("DOCVIEW")).
Where(Function(v) v.Value IsNot Nothing).
ToDictionary(Function(v) v.Key, Function(v) v.Value)
Dim oHtmlDocuments = oValues.
Where(Function(v) v.Key.StartsWith("HTML")).
Where(Function(v) v.Value IsNot Nothing).
ToDictionary(Function(v) v.Key, Function(v) v.Value)
Dim oHtmlDocuments = oValues.
Where(Function(v) v.Key.StartsWith("HTML")).
Where(Function(v) v.Value IsNot Nothing).
ToDictionary(Function(v) v.Key, Function(v) v.Value)
Dim oAllTabs = SQLResultTabs.
Concat(FileResultTabs).
Concat(HtmlResultTabs)
For Each oTabPage In oAllTabs
oTabPage.PageVisible = False
Next
Dim oAllTabs = SQLResultTabs.
Concat(FileResultTabs).
Concat(HtmlResultTabs)
For Each oTabPage In oAllTabs
oTabPage.PageVisible = False
Next
SplitContainerControl3.Collapsed = oSQLCommands.Count = 0
SplitContainerControl2.Collapsed = (oFilePaths.Count + oHtmlDocuments.Count) = 0
SplitContainerControl3.Collapsed = True
SplitContainerControl2.Collapsed = True
For Each oSQLCommand As KeyValuePair(Of String, String) In oSQLCommands
Try
Dim oExtracted = ExtractTitle(oSQLCommand.Value)
Dim oCommand = oExtracted.Item1
Dim oTitle = oExtracted.Item2
For Each oSQLCommand As KeyValuePair(Of String, String) In oSQLCommands
Try
Dim oExtracted = ExtractTitle(oSQLCommand.Value)
Dim oCommand = oExtracted.Item1
Dim oTitle = oExtracted.Item2
Dim oTable As DataTable = Database.GetDatatable(oCommand)
Dim oTable As DataTable = Database.GetDatatable(oCommand)
If oTable Is Nothing Then
If oTable Is Nothing Then
Continue For
End If
Dim oGridIndex = Integer.Parse(oSQLCommand.Key.Last()) - 1
Dim oGridControl As GridControl = SQLResultGrids.Item(oGridIndex)
FillResultGrid(oGridControl, oTable, oTitle)
Catch ex As Exception
Logger.Error(ex)
Continue For
End If
End Try
Next
Dim oGridIndex = Integer.Parse(oSQLCommand.Key.Last()) - 1
Dim oGridControl As GridControl = SQLResultGrids.Item(oGridIndex)
For Each oFile As KeyValuePair(Of String, String) In oFilePaths
Try
Dim oExtracted = ExtractTitle(oFile.Value)
Dim oPath = oExtracted.Item1
Dim oTitle = oExtracted.Item2
FillResultGrid(oGridControl, oTable, oTitle)
Catch ex As Exception
Logger.Error(ex)
Continue For
End Try
Next
If oPath Is Nothing Then
Continue For
End If
For Each oFile As KeyValuePair(Of String, String) In oFilePaths
Try
Dim oExtracted = ExtractTitle(oFile.Value)
Dim oPath = oExtracted.Item1
Dim oTitle = oExtracted.Item2
If Not IO.File.Exists(oPath) Then
Continue For
End If
If oPath Is Nothing Then
Dim oViewerIndex = Integer.Parse(oFile.Key.Last()) - 1
Dim oViewer As DocumentViewer = FileResultViewers.Item(oViewerIndex)
FillResultViewer(oViewer, oPath, oTitle)
Catch ex As Exception
Logger.Error(ex)
Continue For
End If
End Try
Next
If Not IO.File.Exists(oPath) Then
For Each oFile As KeyValuePair(Of String, String) In oHtmlDocuments
Try
Dim oExtracted = ExtractTitle(oFile.Value)
Dim oHtml = oExtracted.Item1
Dim oTitle = oExtracted.Item2
If oHtml Is Nothing Then
Continue For
End If
Dim oViewerIndex = Integer.Parse(oFile.Key.Last()) - 1
Dim oViewer As RichEditControl = HtmlResultViewers.Item(oViewerIndex)
FillResultHtmlViewer(oViewer, oHtml, oTitle)
Catch ex As Exception
Logger.Error(ex)
Continue For
End If
Dim oViewerIndex = Integer.Parse(oFile.Key.Last()) - 1
Dim oViewer As DocumentViewer = FileResultViewers.Item(oViewerIndex)
FillResultViewer(oViewer, oPath, oTitle)
Catch ex As Exception
Logger.Error(ex)
Continue For
End Try
Next
For Each oFile As KeyValuePair(Of String, String) In oHtmlDocuments
Try
Dim oExtracted = ExtractTitle(oFile.Value)
Dim oHtml = oExtracted.Item1
Dim oTitle = oExtracted.Item2
If oHtml Is Nothing Then
Continue For
End If
Dim oViewerIndex = Integer.Parse(oFile.Key.Last()) - 1
Dim oViewer As RichEditControl = HtmlResultViewers.Item(oViewerIndex)
FillResultHtmlViewer(oViewer, oHtml, oTitle)
Catch ex As Exception
Logger.Error(ex)
Continue For
End Try
Next
End Try
Next
Catch ex As Exception
ShowErrorMessage(ex)
End Try
End Sub
Private Function ExtractTitle(Value As String) As Tuple(Of String, String)
@@ -552,7 +577,7 @@ Public Class frmMonitor
Database = New MSSQLServer(LogConfig, oSQLConfig.ConnectionString)
LoadSearchKeys()
LoadSearches()
End If
End Sub
@@ -573,14 +598,55 @@ Public Class frmMonitor
TreeListResults.ExportToXlsx(XtraSaveFileDialog1.FileName)
End If
End Sub
Private Sub frmMonitor_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp
If e.KeyCode = Keys.F5 Then
Debug.Write("Debug.Write")
Console.WriteLine("Console.WriteLine")
Debug.Print("Debug.Print")
LoadData()
End If
End Sub
Private Sub TreeListResults_MouseClick(sender As Object, e As MouseEventArgs) Handles TreeListResults.MouseClick
Dim oInfo As TreeListHitInfo = TreeListResults.CalcHitInfo(New Point(e.X, e.Y))
If oInfo.InRowCell Then
Dim oNode = oInfo.Node
Dim oValues As Dictionary(Of String, String) = GetValuesFromNode(oNode, DataColumns)
Console.WriteLine()
Dim oShouldToggleSQL = False
Dim oShouldToggleFile = False
For Each oValue As KeyValuePair(Of String, String) In oValues
If oValue.Key.Contains("SELECT") AndAlso oValue.Value IsNot Nothing Then
oShouldToggleSQL = True
Exit For
End If
Next
For Each oValue As KeyValuePair(Of String, String) In oValues
If oValue.Key.Contains("DOCVIEW") AndAlso oValue.Value IsNot Nothing Then
oShouldToggleFile = True
Exit For
End If
If oValue.Key.Contains("HTML") AndAlso oValue.Value IsNot Nothing Then
oShouldToggleFile = True
Exit For
End If
Next
If oShouldToggleSQL Then
SplitContainerControl3.Collapsed = Not SplitContainerControl3.Collapsed
End If
If oShouldToggleFile Then
SplitContainerControl2.Collapsed = Not SplitContainerControl2.Collapsed
End If
End If
End Sub
End Class
Friend Class SearchKey
Public Id As Integer
Public Title As String
Public TypeName As String
Public Overrides Function ToString() As String
Return Title
End Function
End Class