Files
Monorepo/Service.EDMIService/Methods/GlobalIndexer/Loader.vb
Developer01 0f9e7c55ec Neue Features, Optimierungen und Bugfixes
- Neues Projekt `EDMI.API` zur Solution hinzugefügt.
- `App.config`: Abhängigkeiten und `bindingRedirect` aktualisiert.
- Verbesserte Thread-Sicherheit mit `ReaderWriterLockSlim`.
- SQL-Abfragen mit `WITH (NOLOCK)` für bessere Parallelität.
- Robuste Verarbeitung von `DataRow`-Werten mit `IIf(IsDBNull(...))`.
- Neue Sicherheitsprüfung für `JobListener` initialisiert.
- `SaveDataTables` optimiert, Performance-Warnungen hinzugefügt.
- Versionsnummer auf `2.5.0.0` aktualisiert, Copyright auf 2026.
- Paket `NLog` aus `packages.config` entfernt.
2026-08-28 12:19:34 +02:00

207 lines
9.0 KiB
VB.net

Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Language
Imports DigitalData.Modules.Logging
Imports DigitalData.Services.EDMIService.Methods.Database
Namespace Methods.GlobalIndexer
Public Class Loader
Inherits BaseClass
Private Const VIEW_PROFILE = "VWGI_DOCTYPE_IDB"
Private Const VIEW_INDEX_MANUAL = "VWDDINDEX_MAN"
Private Const VIEW_INDEX_AUTOMATIC = "VWDDINDEX_AUTOM"
Private Const TABLE_POST_PROCESSING = "TBDD_INDEX_MAN_POSTPROCESSING"
Private GetDatatable As GetDatatableFromCache.GetDatatableFromCacheMethod
Public Sub New(pLogConfig As LogConfig, pDatabaseIDB As MSSQLServer, pDatabaseECM As MSSQLServer, pGlobalState As GlobalState)
MyBase.New(pLogConfig)
GetDatatable = New GetDatatableFromCache.GetDatatableFromCacheMethod(pLogConfig, pDatabaseIDB, pDatabaseECM, pGlobalState)
End Sub
''' <summary>
''' Load Profiles for this Import
''' </summary>
Public Function LoadProfile(pProfileId As Integer) As Profile
Logger.Debug("Start of Method [LoadProfile]")
Try
Dim oProfile = GetDatatable.Run(New GetDatatableFromCache.GetDatatableFromCacheRequest With {
.DataTable = VIEW_PROFILE,
.FilterExpression = $"DOCTYPE_ID = {pProfileId}"
})
If oProfile.OK = False Then
LogAndThrow(oProfile.ErrorMessage)
End If
Dim oRow As DataRow = oProfile.Table.Rows.Item(0)
Dim oProfileObject As New Profile With {
.Id = IIf(IsDBNull(oRow.Item("DOCTYPE_ID")), 0, oRow.Item("DOCTYPE_ID")),
.Name = IIf(IsDBNull(oRow.Item("DOCTYPE")), String.Empty, oRow.Item("DOCTYPE")),
.IsActive = IIf(IsDBNull(oRow.Item("AKTIV")), False, oRow.Item("AKTIV")),
.NameConvention = IIf(IsDBNull(oRow.Item("NAMENKONVENTION")), String.Empty, oRow.Item("NAMENKONVENTION")),
.ObjectStore = IIf(IsDBNull(oRow.Item("OBJECT_STORE")), "Work", oRow.Item("OBJECT_STORE")),
.ShortName = IIf(IsDBNull(oRow.Item("KURZNAME")), String.Empty, oRow.Item("KURZNAME")),
.DynamicPath = IIf(IsDBNull(oRow.Item("DYNAMIC_FOLDER")), String.Empty, oRow.Item("DYNAMIC_FOLDER"))
}
Logger.Debug("Name: [{0}]", oProfileObject.Name)
Logger.Debug("Active: [{0}]", oProfileObject.IsActive)
Logger.Debug("ObjectStore: [{0}]", oProfileObject.ObjectStore)
Logger.Debug("ShortName: [{0}]", oProfileObject.ShortName)
Logger.Debug("NameConvention: [{0}]", oProfileObject.NameConvention)
Logger.Debug("DynamicPath: [{0}]", oProfileObject.DynamicPath)
Return oProfileObject
Catch ex As Exception
LogAndThrow(ex, "Error while automatic loading profile!")
Return Nothing
End Try
End Function
''' <summary>
''' Load automatic indexes for this Import
''' </summary>
Public Function LoadAutomaticIndexes(pProfileId As Integer) As List(Of AutomaticIndex)
Logger.Debug("Start of Method [LoadAutomaticIndexes]")
Try
' Load automatic Indexes for this Import
Dim oAutomaticIndexes = GetDatatable.Run(
New GetDatatableFromCache.GetDatatableFromCacheRequest With {
.DataTable = VIEW_INDEX_AUTOMATIC,
.FilterExpression = $"DOCTYPE_ID = {pProfileId}"
})
If oAutomaticIndexes.OK = False Then
LogAndThrow(oAutomaticIndexes.ErrorMessage)
End If
Dim oIndexes As New List(Of AutomaticIndex)
For Each oRow As DataRow In oAutomaticIndexes.Table.Rows
Dim oAutomaticIndex As New AutomaticIndex With {
.Id = oRow.Item("GUID"),
.Name = IIf(IsDBNull(oRow.Item("INDEXNAME")), String.Empty, oRow.Item("INDEXNAME")),
.ProfileId = IIf(IsDBNull(oRow.Item("DOCTYPE_ID")), 0, oRow.Item("DOCTYPE_ID")),
.SQLCommand = IIf(IsDBNull(oRow.Item("SQL_RESULT")), String.Empty, oRow.Item("SQL_RESULT")),
.SQLConnectionId = IIf(IsDBNull(oRow.Item("CONNECTION_ID")), 0, oRow.Item("CONNECTION_ID")),
.Sequence = IIf(IsDBNull(oRow.Item("SEQUENCE")), String.Empty, oRow.Item("SEQUENCE")),
.Value = IIf(IsDBNull(oRow.Item("VALUE")), String.Empty, oRow.Item("VALUE"))
}
oIndexes.Add(oAutomaticIndex)
Next
Logger.Info("Automatic indexes loaded: [{0}]", oIndexes.Count)
Return oIndexes
Catch ex As Exception
LogAndThrow(ex, "Error while loading automatic indexes!")
Return Nothing
End Try
End Function
''' <summary>
''' Load manual indexes for this Import
''' </summary>
Public Function LoadManualIndexes(pProfileId As Integer) As List(Of ManualIndex)
Logger.Debug("Start of Method [LoadManualIndexes]")
Try
' Load manual Indexes for this Import
Dim oManualIndexes = GetDatatable.Run(
New GetDatatableFromCache.GetDatatableFromCacheRequest With {
.DataTable = VIEW_INDEX_MANUAL,
.FilterExpression = $"DOK_ID = {pProfileId}"
})
If oManualIndexes.OK = False Then
LogAndThrow(oManualIndexes.ErrorMessage)
End If
Dim oIndexes As New List(Of ManualIndex)
For Each oRow As DataRow In oManualIndexes.Table.Rows
Dim oManualIndex As New ManualIndex With {
.Id = oRow.Item("GUID"),
.Name = oRow.Item("INDEXNAME"),
.ProfileId = oRow.Item("DOK_ID"),
.IsOptional = oRow.Item("OPTIONAL"),
.IsMultiselect = oRow.Item("MULTISELECT"),
.SQLCommand = oRow.Item("SQL_RESULT"),
.SQLConnectionId = oRow.Item("CONNECTION_ID"),
.DefaultValue = oRow.Item("DEFAULT_VALUE"),
.DataType = oRow.Item("DATATYPE")
}
oIndexes.Add(oManualIndex)
Next
Logger.Info("Manual indexes loaded: [{0}]", oIndexes.Count)
Return oIndexes
Catch ex As Exception
LogAndThrow(ex, $"Error while loading manual indizes [{ex.Message}]")
Return Nothing
End Try
End Function
Public Function LoadPostProcessingSteps(pManualIndexes As List(Of ManualIndex)) As List(Of PostProcessingStep)
Logger.Debug("Start of Method [LoadPostProcessingSteps]")
Try
' Generate a string containing all index ids joined into a string
Dim oIndexIdList As List(Of Integer) = pManualIndexes.
Select(Function(index) index.Id).
ToList()
Dim oIndexIds As String = String.Join(",", oIndexIdList)
If oIndexIdList.Count = 0 Then
Logger.Debug("No Postprocessing steps found for this profile. Exiting.")
Return Nothing
End If
' Load all relevant postprocessing steps
Dim oPostProcessingSteps = GetDatatable.Run(
New GetDatatableFromCache.GetDatatableFromCacheRequest With {
.DataTable = TABLE_POST_PROCESSING,
.FilterExpression = $"IDXMAN_ID IN ({oIndexIds})"
})
If oPostProcessingSteps.OK = False Then
LogAndThrow(oPostProcessingSteps.ErrorMessage)
End If
Dim oSteps As New List(Of PostProcessingStep)
For Each oRow As DataRow In oPostProcessingSteps.Table.Rows
Dim oStep As New PostProcessingStep With {
.Id = oRow.Item("GUID"),
.IndexId = oRow.Item("IDXMAN_ID"),
.[Variant] = oRow.Item("VARIANT"),
.Type = oRow.Item("TYPE"),
.Function1 = oRow.Item("FUNCTION1"),
.Function2 = oRow.Item("FUNCTION2"),
.Text1 = oRow.Item("Text1"),
.Text2 = oRow.Item("Text2"),
.Text3 = oRow.Item("Text3"),
.Sequence = oRow.Item("SEQUENCE")
}
oSteps.Add(oStep)
Next
Return oSteps
Catch ex As Exception
LogAndThrow(ex, "Error while loading post processing steps!")
Return Nothing
End Try
End Function
End Class
End Namespace