EDMI: Work on ClassDataASorDB
This commit is contained in:
89
Modules.EDMIAPI/DatabaseWithFallback.vb
Normal file
89
Modules.EDMIAPI/DatabaseWithFallback.vb
Normal file
@@ -0,0 +1,89 @@
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.EDMI.API
|
||||
Imports DigitalData.Modules.EDMI.API.Constants
|
||||
Imports DigitalData.Modules.EDMI.API.EDMIServiceReference
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Language.Utils
|
||||
|
||||
Public Class DatabaseWithFallback
|
||||
Private ReadOnly _Logger As Logger
|
||||
Private ReadOnly _Client As Client
|
||||
Private ReadOnly _DatabaseEDM As MSSQLServer
|
||||
Private ReadOnly _DatabaseIDB As MSSQLServer
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, Client As Client, DatabaseECM As MSSQLServer, DatabaseIDB As MSSQLServer)
|
||||
_Logger = LogConfig.GetLogger()
|
||||
_Client = Client
|
||||
_DatabaseEDM = DatabaseECM
|
||||
_DatabaseIDB = DatabaseIDB
|
||||
End Sub
|
||||
|
||||
Public Function GetDatatable(DataTable As String, FallbackSQL As String, FallbackType As Constants.DatabaseType, Optional FilterExpression As String = "", Optional SortByColumn As String = "", Optional ForceFallback As Boolean = False) As DataTable
|
||||
Try
|
||||
Dim oResult As DataTable = Nothing
|
||||
|
||||
If ForceFallback = False Then
|
||||
Dim oTableResult As TableResult = _Client.GetDatatableByName(DataTable, FilterExpression, SortByColumn)
|
||||
|
||||
If oTableResult Is Nothing OrElse oTableResult.OK = False Then
|
||||
_Logger.Warn("Datatable [{0}] could not be fetched from AppServer Cache. Falling back to direct Database Access.")
|
||||
End If
|
||||
|
||||
Return oTableResult.Table
|
||||
Else
|
||||
Return GetDatatableFromDatabase(FallbackSQL, FallbackType)
|
||||
End If
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function GetDatatableFromDatabase(SQLCommand As String, DatabaseType As DatabaseType)
|
||||
Try
|
||||
Select Case DatabaseType
|
||||
Case DatabaseType.ECM
|
||||
Return _DatabaseEDM.GetDatatable(SQLCommand)
|
||||
|
||||
Case DatabaseType.IDB
|
||||
Return _DatabaseIDB.GetDatatable(SQLCommand)
|
||||
|
||||
Case Else
|
||||
Return Nothing
|
||||
|
||||
End Select
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
Return Nothing
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetUserData(UserName As String, ModuleCode As String, Client As Integer) As UserData
|
||||
'Dim oSQL = $"SELECT * FROM FNDD_CHECK_USER_MODULE('{UserName}','{ModuleCode}',{Client})"
|
||||
'Dim oTable As DataTable = GetDatatable("TBDD_USER_MODULE", $"USERNAME = '{UserName.ToLower}' AND MODULE_SHORT = '{ModuleCode}'", "", oSQL, DatabaseType.ECM)
|
||||
|
||||
'If oTable Is Nothing Then
|
||||
' Return Nothing
|
||||
'End If
|
||||
|
||||
'If oTable.Rows.Count = 0 Then
|
||||
' Return Nothing
|
||||
'End If
|
||||
|
||||
'Dim oRow As DataRow = oTable.Rows.Item(0)
|
||||
'Dim oUserData As New UserData With {
|
||||
' .Id = NotNull(oRow, "USER_ID", -1),
|
||||
' .Surname = NotNull(oRow, "USER_SURNAME", String.Empty),
|
||||
' .Prename = NotNull(oRow, "USER_PRENAME", String.Empty),
|
||||
' .Shortname = NotNull(oRow, "USER_SHORTNAME", String.Empty),
|
||||
' .Email = NotNull(oRow, "USER_EMAIL", String.Empty),
|
||||
' .Language = NotNull(oRow, "USER_LANGUAGE", "de-DE"),
|
||||
' .DateFormat = NotNull(oRow, "USER_DATE_FORMAT", "dd.MM.yyyy")
|
||||
'}
|
||||
|
||||
Throw New NotImplementedException()
|
||||
End Function
|
||||
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user