Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Language
Imports DigitalData.Modules.Logging
Imports DigitalData.Services.EDMIService.Methods.GetDatatableFromCache
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 GetDatatableFromCacheMethod
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pGlobalState As GlobalState)
MyBase.New(pLogConfig)
GetDatatable = New GetDatatableFromCacheMethod(pLogConfig, pDatabase, pGlobalState)
End Sub
'''
''' Load Profiles for this Import
'''
Public Function LoadProfile(pProfileId As Integer) As Profile
Logger.Debug("Start of Method [LoadAutomaticIndexes]")
Try
Dim oProfile = GetDatatable.Run(
New 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 = oRow.ItemEx("DOCTYPE_ID", 0),
.Name = oRow.ItemEx("DOCTYPE", "Missing Profile Name"),
.IsActive = oRow.ItemEx("AKTIV", False),
.NameConvention = oRow.ItemEx("NAMENKONVENTION", ""),
.ObjectStore = oRow.ItemEx("OBJECT_STORE", "Work"),
.ShortName = oRow.ItemEx("KURZNAME", ""),
.DynamicPath = oRow.ItemEx("DYNAMIC_PATH", "")
}
Return oProfileObject
Catch ex As Exception
LogAndThrow(ex, "Error while automatic loading indexes!")
Return Nothing
End Try
End Function
'''
''' Load automatic indexes for this Import
'''
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 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.ItemEx(Of Integer)("GUID"),
.Name = oRow.ItemEx(Of String)("INDEXNAME"),
.ProfileId = oRow.ItemEx(Of Integer)("DOCTYPE_ID"),
.SQLCommand = oRow.ItemEx(Of String)("SQL_RESULT"),
.SQLConnectionId = oRow.ItemEx(Of Integer)("CONNECTION_ID"),
.Sequence = oRow.ItemEx(Of String)("SEQUENCE"),
.Value = oRow.ItemEx(Of String)("VALUE")
}
oIndexes.Add(oAutomaticIndex)
Next
Logger.Info("Automatic indexes loaded: [{0}]", oIndexes.Count)
Return oIndexes
Catch ex As Exception
LogAndThrow(ex, "Error while automatic loading indexes!")
Return Nothing
End Try
End Function
'''
''' Load manual indexes for this Import
'''
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 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.ItemEx(Of Integer)("GUID"),
.Name = oRow.ItemEx(Of String)("INDEXNAME"),
.ProfileId = oRow.ItemEx(Of Integer)("DOCTYPE_ID"),
.IsOptional = oRow.ItemEx(Of Boolean)("OPTIONAL"),
.IsMultiselect = oRow.ItemEx(Of String)("MULTISELECT"),
.SQLCommand = oRow.ItemEx(Of String)("SQL_RESULT"),
.SQLConnectionId = oRow.ItemEx(Of Integer)("CONNECTION_ID"),
.DefaultValue = oRow.ItemEx(Of String)("DEFAULT_VALUE"),
.DataType = oRow.ItemEx(Of String)("DATA_TYPE")
}
oIndexes.Add(oManualIndex)
Next
Logger.Info("Manual indexes loaded: [{0}]", oIndexes.Count)
Return oIndexes
Catch ex As Exception
LogAndThrow(ex, "Error while loading indexes!")
Return Nothing
End Try
End Function
Public Function LoadPostProcessingSteps(pManualIndexes As List(Of ManualIndex)) As DataTable
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 GetDatatableFromCacheRequest With {
.DataTable = TABLE_POST_PROCESSING,
.FilterExpression = $"IDXMAN_ID IN ({oIndexIds})"
})
If oPostProcessingSteps.OK = False Then
LogAndThrow(oPostProcessingSteps.ErrorMessage)
End If
Return oPostProcessingSteps.Table
Catch ex As Exception
LogAndThrow(ex, "Error while loading post processing steps!")
Return Nothing
End Try
End Function
End Class
End Namespace