EDMI: Load Object Store Paths

This commit is contained in:
Jonathan Jenne
2020-04-17 11:57:18 +02:00
parent 88dfb3fab1
commit 14194248ad
12 changed files with 183 additions and 121 deletions

View File

@@ -1,16 +1,16 @@
Imports System.Configuration
Public Class AppConfig
Public Shared FirebirdDataSource As String
Public Shared FirebirdDatabase As String
Public Shared FirebirdUser As String
Public Shared FirebirdPassword As String
Public Shared ContainerPath As String
Public Shared ContainerPassword As String
Public Shared DatastorePath As String
Public Shared MSSQLConnectionString As String
Public FirebirdDataSource As String
Public FirebirdDatabase As String
Public FirebirdUser As String
Public FirebirdPassword As String
Public ContainerPath As String
Public ContainerPassword As String
Public DatastorePath As String
Public MSSQLConnectionString As String
Public Shared Sub Load()
Public Sub New()
With ConfigurationManager.AppSettings
FirebirdDataSource = .Item("FIREBIRD_DATASOURCE")
FirebirdDatabase = .Item("FIREBIRD_DATABASE_NAME")
@@ -26,12 +26,12 @@ Public Class AppConfig
End With
End Sub
Public Shared Function IsFirebirdConfigured() As Boolean
Public Function IsFirebirdConfigured() As Boolean
Dim oProps As New List(Of String) From {FirebirdDataSource, FirebirdDatabase, FirebirdUser, FirebirdPassword}
Return Not oProps.Any(Function(Prop) String.IsNullOrWhiteSpace(Prop))
End Function
Public Shared Function IsMSSQLConfigured() As Boolean
Public Function IsMSSQLConfigured() As Boolean
Return Not String.IsNullOrWhiteSpace(MSSQLConnectionString)
End Function
End Class

View File

@@ -1,11 +1,9 @@
Imports System.ServiceModel
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Filesystem
Imports DigitalData.Modules
Imports System.IO
Imports System.ServiceModel.Description
Imports System.ServiceModel.Channels
Imports System.ServiceModel
Imports System.Data.SqlClient
<ServiceBehavior(InstanceContextMode:=InstanceContextMode.PerSession)>
@@ -17,8 +15,8 @@ Public Class EDMIService
Public Shared Firebird As Firebird
Public Shared AppConfig As AppConfig
Public Shared Filesystem As Filesystem.File
Public Shared EDMIPath As EDMI.File.Path
Public Shared EDMIArchive As EDMI.File.Archive
Public Shared GlobalState As GlobalState
Private ReadOnly _logger As Logger
@@ -34,7 +32,6 @@ Public Class EDMIService
_username = oUsername
_logger = LogConfig.GetLogger()
_logger.Debug("New Request by User [{0}]", _username)
End Sub
@@ -320,6 +317,16 @@ Public Class EDMIService
''' <param name="Contents"></param>
''' <returns></returns>
Public Function ImportFile(FileName As String, Contents() As Byte, ObjectStoreId As Int64, DocumentType As String, Optional RetentionDays As Int64 = Nothing) As DocumentResult Implements IEDMIService.ImportFile
Dim oObjectStore = GlobalState.ObjectStores.
Where(Function(s) s.Id = ObjectStoreId).
FirstOrDefault()
If oObjectStore Is Nothing Then
Return New DocumentResult($"Object Store with Id [{ObjectStoreId}] does not exist!")
End If
Dim EDMIPath = New EDMI.File.Path(LogConfig, oObjectStore.Path)
' TODO:
' - Get Object Store -> Object Catalog -> Catalog Path
' - If IS_ARCHIVE = True And RetentionDays <> Nothing:
@@ -328,10 +335,9 @@ Public Class EDMIService
' and return ObjectStore Path from ObjectStoreId + RelativePath
' VWIDB_OBJECTSTORE
Dim oDocumentType As String = "DummyDocumentType"
Dim oRelativePath As String = EDMIPath.GetRelativePath(oDocumentType, FileName)
Dim oAbsolutePath As String = EDMIPath.GetActivePath(oDocumentType, FileName)
Dim oDirectoryPath = EDMIPath.GetActivePath(oDocumentType)
Dim oRelativePath As String = EDMIPath.GetRelativePath(DocumentType, FileName)
Dim oAbsolutePath As String = EDMIPath.GetFullPath(DocumentType, FileName)
Dim oDirectoryPath = EDMIPath.GetFullPath(DocumentType)
Dim oDocument = New DocumentResult.DocumentObject With {.FileName = FileName}
Try
@@ -372,14 +378,23 @@ Public Class EDMIService
Public Function GetFileByObjectId(Data As Messages.DocumentStreamRequest) As Messages.DocumentStreamResponse Implements IEDMIService.GetFileByObjectId
Try
Dim oSQL As String = $"SELECT DocRelativePath FROM VWIDB_DOC_DATA WHERE IDB_OBJ_ID = {Data.ObjectId}"
Dim oPath As String = MSSQL.GetScalarValue(oSQL)
Dim oSQL As String = $"SELECT ObjectStoreId FROM VWIDB_DOC_DATA WHERE IDB_OBJ_ID = {Data.ObjectId}"
Dim oObjectStoreId = MSSQL.GetScalarValue(oSQL)
Dim oObjectStore = GlobalState.ObjectStores.
Where(Function(s) s.Id = oObjectStoreId).
FirstOrDefault()
Dim oSQL2 As String = $"SELECT DocRelativePath FROM VWIDB_DOC_DATA WHERE IDB_OBJ_ID = {Data.ObjectId}"
Dim oPath As String = MSSQL.GetScalarValue(oSQL2)
If IsNothing(oPath) Then
Throw New FaultException($"Object [{Data.ObjectId}] does not exist in database!")
End If
Dim oFullPath = EDMIPath.GetActivePathFromRelativePath(oPath)
Dim EDMIPath As New EDMI.File.Path(LogConfig, oObjectStore.Path)
Dim oFullPath = EDMIPath.GetFullPathFromRelativePath(oPath)
_logger.Debug("GetFileByObjectId: Loading file [{0}]", oFullPath)

View File

@@ -104,6 +104,7 @@
<Compile Include="AppConfig.vb" />
<Compile Include="Database\IDatabase.vb" />
<Compile Include="Database\MSSQL.vb" />
<Compile Include="GlobalState.vb" />
<Compile Include="Messages.vb" />
<Compile Include="Results\BaseResult.vb" />
<Compile Include="Results\ContainerResult.vb" />

View File

@@ -0,0 +1,46 @@
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging
Public Class GlobalState
Private _LogConfig As LogConfig
Private _Logger As Logger
Private _MSSQL As MSSQLServer
Public Property ObjectStores As New List(Of ObjectStore)
Public Sub New(LogConfig As LogConfig, MSSQL As MSSQLServer)
_LogConfig = LogConfig
_Logger = LogConfig.GetLogger()
_MSSQL = MSSQL
End Sub
Public Sub LoadObjectStores()
_Logger.Debug("Loading Object Stores")
Try
Dim oSQL As String = "SELECT * FROM VWIDB_OBJECTSTORE"
Dim oDatatable As DataTable = _MSSQL.GetDatatable(oSQL)
ObjectStores.Clear()
For Each oRow As DataRow In oDatatable.Rows
Dim oStore As New ObjectStore() With {
.Id = oRow.Item("OST_ID"),
.IsArchive = oRow.Item("OS_IS_ARCHIVE"),
.Path = oRow.Item("IDB_PRAEFIX"),
.Title = oRow.Item("OS_TITLE")
}
_Logger.Debug("New Object Store [{0}]", oStore.Title)
ObjectStores.Add(oStore)
Next
Catch ex As Exception
_Logger.Error(ex)
Throw ex
End Try
End Sub
Class ObjectStore
Public Id As Int64
Public Title As String
Public IsArchive As Boolean
Public Path As String
End Class
End Class

View File

@@ -8,19 +8,18 @@ Imports System.ServiceModel.Description
Public Class WindowsService
Inherits ServiceBase
Private _serviceHost As ServiceHost = Nothing
Private _edmService As IEDMIService = Nothing
Private _ServiceHost As ServiceHost
Private _LogConfig As LogConfig
Private _Logger As Logger
Private _logConfig As LogConfig
Private _logger As Logger
Private _Firebird As Firebird
Private _MSSQL As MSSQLServer
Private _firebird As Firebird
Private _mssql As MSSQLServer
Private _config As AppConfig
Private _Config As AppConfig
Private _Path As EDMI.File.Path
Private _Archive As EDMI.File.Archive
Private _filesystem As Filesystem.File
Private _Filesystem As Filesystem.File
Private _Global As GlobalState
Public Sub New()
ServiceName = SERVICE_NAME
@@ -32,78 +31,84 @@ Public Class WindowsService
Protected Overrides Sub OnStart(ByVal args As String())
Try
AppConfig.Load()
_logConfig = New LogConfig(LogConfig.PathType.CustomPath, "E:\EDMService") With {
_Config = New AppConfig()
_LogConfig = New LogConfig(LogConfig.PathType.CustomPath, "E:\EDMService") With {
.Debug = True
}
_Logger = _LogConfig.GetLogger()
_Logger.Info("Service {0} is starting...", SERVICE_DISPLAY_NAME)
_logger = _logConfig.GetLogger()
MaybeStartFirebird()
MaybeStartMSSQL()
_logger.Info("Service {0} is starting...", SERVICE_DISPLAY_NAME)
_Logger.Debug("Initializing EDMI Functions")
If AppConfig.IsFirebirdConfigured() Then
_logger.Debug("Connecting to Firebird...")
_firebird = New Firebird(
_logConfig,
AppConfig.FirebirdDataSource,
AppConfig.FirebirdDatabase,
AppConfig.FirebirdUser,
AppConfig.FirebirdPassword
)
_logger.Info("Database connection established.")
Else
_logger.Info("Firebird is not configured, will not be used!")
End If
_Archive = New EDMI.File.Archive(_LogConfig)
_Filesystem = New Filesystem.File(_LogConfig)
_Global = New GlobalState(_LogConfig, _MSSQL)
If AppConfig.IsMSSQLConfigured() Then
_logger.Debug("Connecting to MSSQL...")
_mssql = New MSSQLServer(_logConfig, AppConfig.MSSQLConnectionString)
_logger.Info("Database connection established.")
Else
_logger.Info("MSSQL is not configured, will not be used!")
End If
_Global.LoadObjectStores()
_logger.Debug("Initializing EDMI Functions")
_Logger.Info("EDMI Functions initialized.")
_Path = New EDMI.File.Path(_logConfig, AppConfig.DatastorePath)
_Archive = New EDMI.File.Archive(_logConfig)
_filesystem = New Filesystem.File(_logConfig)
_logger.Info("EDMI Functions initialized.")
EDMIService.MSSQL = _mssql
EDMIService.Firebird = _firebird
EDMIService.LogConfig = _logConfig
EDMIService.AppConfig = _config
EDMIService.MSSQL = _MSSQL
EDMIService.Firebird = _Firebird
EDMIService.LogConfig = _LogConfig
EDMIService.AppConfig = _Config
EDMIService.EDMIArchive = _Archive
EDMIService.EDMIPath = _Path
EDMIService.Filesystem = _filesystem
EDMIService.Filesystem = _Filesystem
EDMIService.GlobalState = _Global
_logger.Debug("Starting WCF ServiceHost...")
_Logger.Debug("Starting WCF ServiceHost...")
_serviceHost = New ServiceHost(GetType(EDMIService))
_serviceHost.Open()
_ServiceHost = New ServiceHost(GetType(EDMIService))
_ServiceHost.Open()
_logger.Info("WCF ServiceHost started.")
_Logger.Info("WCF ServiceHost started.")
_logger.Info("Service {0} successfully started.", SERVICE_DISPLAY_NAME)
_Logger.Info("Service {0} successfully started.", SERVICE_DISPLAY_NAME)
Catch ex As Exception
_logger.Error(ex, "Failed to start the service host!")
_Logger.Error(ex, "Failed to start the service host!")
GracefullyStop()
End Try
End Sub
Private Sub MaybeStartFirebird()
If _Config.IsFirebirdConfigured() Then
_Logger.Debug("Connecting to Firebird")
_Firebird = New Firebird(
_LogConfig,
_Config.FirebirdDataSource,
_Config.FirebirdDatabase,
_Config.FirebirdUser,
_Config.FirebirdPassword
)
_Logger.Info("Database connection established.")
Else
_Logger.Info("Firebird is not configured, will not be used!")
End If
End Sub
Private Sub MaybeStartMSSQL()
If _Config.IsMSSQLConfigured() Then
_Logger.Debug("Connecting to MSSQL")
_MSSQL = New MSSQLServer(_LogConfig, _Config.MSSQLConnectionString)
_Logger.Info("Database connection established.")
Else
_Logger.Info("MSSQL is not configured, will not be used!")
End If
End Sub
Protected Overrides Sub OnStop()
GracefullyStop()
End Sub
Private Sub GracefullyStop()
If _serviceHost IsNot Nothing Then
_serviceHost.Close()
_serviceHost = Nothing
If _ServiceHost IsNot Nothing Then
_ServiceHost.Close()
_ServiceHost = Nothing
End If
_logger.Info("Service {0} is stopping!", SERVICE_DISPLAY_NAME)
_Logger.Info("Service {0} is stopping!", SERVICE_DISPLAY_NAME)
End Sub
End Class