EDMIAPI: Add DataWithFallback

This commit is contained in:
Jonathan Jenne 2021-05-20 16:13:16 +02:00
parent e29c635f41
commit c022872832
3 changed files with 116 additions and 0 deletions

View File

@ -0,0 +1,92 @@
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.EDMI.API
Imports DigitalData.Modules.EDMI.API.EDMIServiceReference
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Language.Utils
Public Class DataWithFallback
Private _Logger As Logger
Private _Client As Client
Private _DatabaseEDM As MSSQLServer
Private _DatabaseIDB As MSSQLServer
Private _Type As DatabaseType
Public Enum DatabaseType
ECM
IDB
End Enum
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, FilterExpression As String, SortByColumn As String, FallbackSQL As String, FallbackType As DatabaseType, 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")
}
End Function
End Class

View File

@ -0,0 +1,14 @@
Public Class UserData
Public Id As Integer
Public Surname As String
Public Prename As String
Public Shortname As String
Public Email As String
Public Language As String
Public DateFormat As String
Public IsAdmin As Boolean
Public HasAccess As Boolean
Public ModuleName As String
End Class

View File

@ -80,6 +80,7 @@
<DependentUpon>Reference.svcmap</DependentUpon>
</Compile>
<Compile Include="Client.vb" />
<Compile Include="DataWithFallback.vb" />
<Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen>
@ -95,6 +96,7 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="DataWithFallback\UserData.vb" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="My Project\Resources.resx">
@ -175,6 +177,14 @@
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Modules.Database\Database.vbproj">
<Project>{eaf0ea75-5fa7-485d-89c7-b2d843b03a96}</Project>
<Name>Database</Name>
</ProjectReference>
<ProjectReference Include="..\Modules.Language\Language.vbproj">
<Project>{d3c8cfed-d6f6-43a8-9bdf-454145d0352f}</Project>
<Name>Language</Name>
</ProjectReference>
<ProjectReference Include="..\Modules.Logging\Logging.vbproj">
<Project>{903b2d7d-3b80-4be9-8713-7447b704e1b0}</Project>
<Name>Logging</Name>