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

@ -15,7 +15,7 @@ Imports DigitalData.Modules.EDMI
Dim oDay = oNow.Day.ToString.PadLeft(2, "0") Dim oDay = oNow.Day.ToString.PadLeft(2, "0")
Assert.AreEqual(oPath.GetActivePath("TestDocumentType"), $"{oTempPath}EDMI\Active\TestDocumentType\{oYear}\{oMonth}\{oDay}") Assert.AreEqual(oPath.GetFullPath("TestDocumentType"), $"{oTempPath}EDMI\Active\TestDocumentType\{oYear}\{oMonth}\{oDay}")
Assert.AreEqual(oPath.GetArchivePath("TestDocumentType"), $"{oTempPath}EDMI\Archive\TestDocumentType\{oYear}\{oMonth}\{oDay}") Assert.AreEqual(oPath.GetArchivePath("TestDocumentType"), $"{oTempPath}EDMI\Archive\TestDocumentType\{oYear}\{oMonth}\{oDay}")
End Sub End Sub

View File

@ -6,38 +6,21 @@ Public Class Path
Private ReadOnly _Logger As Logger Private ReadOnly _Logger As Logger
Private ReadOnly _BasePath As String Private ReadOnly _BasePath As String
Public Const PATH_ACTIVE As String = "Active"
Public Const PATH_ARCHIVE As String = "Archive"
Public Const PATH_EDMI As String = "EDMI"
Public Sub New(LogConfig As LogConfig, DatastoreBasePath As String) Public Sub New(LogConfig As LogConfig, DatastoreBasePath As String)
_LogConfig = LogConfig _LogConfig = LogConfig
_Logger = LogConfig.GetLogger() _Logger = LogConfig.GetLogger()
_BasePath = DatastoreBasePath _BasePath = DatastoreBasePath
End Sub End Sub
Public Function GetActivePath(DocumentType As String, Optional FileName As String = "") As String Public Function GetFullPath(DocumentType As String, Optional FileName As String = "") As String
Dim oParts = New List(Of String) From {_BasePath, PATH_EDMI, PATH_ACTIVE} Dim oParts = New List(Of String) From {_BasePath}
oParts.AddRange(Do_GetRelativePath(DocumentType, FileName)) oParts.AddRange(Do_GetRelativePath(DocumentType, FileName))
Return IO.Path.Combine(oParts.ToArray()) Return IO.Path.Combine(oParts.ToArray())
End Function End Function
Public Function GetActivePathFromRelativePath(RelativePath As String) As String Public Function GetFullPathFromRelativePath(RelativePath As String) As String
Dim oParts = New List(Of String) From {_BasePath, PATH_EDMI, PATH_ACTIVE} Dim oParts = New List(Of String) From {_BasePath}
oParts.Add(RelativePath)
Return IO.Path.Combine(oParts.ToArray)
End Function
Public Function GetArchivePath(DocumentType As String, Optional FileName As String = "") As String
Dim oParts = New List(Of String) From {_BasePath, PATH_EDMI, PATH_ARCHIVE}
oParts.AddRange(Do_GetRelativePath(DocumentType, FileName))
Return IO.Path.Combine(oParts.ToArray())
End Function
Public Function GetArchivePathFromRelativePath(RelativePath As String) As String
Dim oParts = New List(Of String) From {_BasePath, PATH_EDMI, PATH_ARCHIVE}
oParts.Add(RelativePath) oParts.Add(RelativePath)
Return IO.Path.Combine(oParts.ToArray) Return IO.Path.Combine(oParts.ToArray)
End Function End Function

View File

@ -57,7 +57,7 @@ Public Class Form1
Await oStream.ReadAsync(oContents, 0, oFileInfo.Length) Await oStream.ReadAsync(oContents, 0, oFileInfo.Length)
End Using End Using
Dim oResult As EDMIServiceReference.DocumentResult = Await _Channel.ImportFileAsync(oFileInfo.Name, oContents, Environment.UserName) Dim oResult As EDMIServiceReference.DocumentResult = Await _Channel.ImportFileAsync(oFileInfo.Name, oContents, 1, "WichtigesDokument", 0)
If oResult.OK Then If oResult.OK Then
AddLogMessage($"File [{oFileInfo.Name}] with Id [{oResult.Document.FileId}] imported!") AddLogMessage($"File [{oFileInfo.Name}] with Id [{oResult.Document.FileId}] imported!")
Else Else

View File

@ -98,6 +98,8 @@ Public Class MSSQLServer
Return Nothing Return Nothing
End If End If
_Logger.Debug("Running Query: {0}", SqlCommand)
Using oConnection = GetSQLConnection() Using oConnection = GetSQLConnection()
Using oSQLCOmmand = oConnection.CreateCommand() Using oSQLCOmmand = oConnection.CreateCommand()
oSQLCOmmand.CommandText = SqlCommand oSQLCOmmand.CommandText = SqlCommand
@ -137,6 +139,8 @@ Public Class MSSQLServer
Return Nothing Return Nothing
End If End If
_Logger.Debug("Running Query: {0}", SQLCommand)
Using oConnection = GetSQLConnection() Using oConnection = GetSQLConnection()
Using oSQLCOmmand = oConnection.CreateCommand() Using oSQLCOmmand = oConnection.CreateCommand()
oSQLCOmmand.CommandText = SQLCommand oSQLCOmmand.CommandText = SQLCommand
@ -166,15 +170,17 @@ Public Class MSSQLServer
Return GetScalarValue(ScalarSQL) Return GetScalarValue(ScalarSQL)
End Function End Function
Public Function GetScalarValue(SQLQuery As String, Timeout As Integer) As Object Implements IDatabase.GetScalarValue Public Function GetScalarValue(SQLCommand As String, Timeout As Integer) As Object Implements IDatabase.GetScalarValue
Try Try
If TestCanConnect() = False Then If TestCanConnect() = False Then
Return Nothing Return Nothing
End If End If
_Logger.Debug("Running Query: {0}", SQLCommand)
Using oConnection As SqlConnection = GetSQLConnection() Using oConnection As SqlConnection = GetSQLConnection()
Using oSQLCOmmand = oConnection.CreateCommand() Using oSQLCOmmand = oConnection.CreateCommand()
oSQLCOmmand.CommandText = SQLQuery oSQLCOmmand.CommandText = SQLCommand
oSQLCOmmand.CommandTimeout = Timeout oSQLCOmmand.CommandTimeout = Timeout
Dim oResult As Object = oSQLCOmmand.ExecuteScalar() Dim oResult As Object = oSQLCOmmand.ExecuteScalar()
Return oResult Return oResult
@ -182,7 +188,7 @@ Public Class MSSQLServer
End Using End Using
Catch ex As Exception Catch ex As Exception
_Logger.Error(ex) _Logger.Error(ex)
_Logger.Warn("SQLQuery: " & SQLQuery) _Logger.Warn("SQLQuery: " & SQLCommand)
Return Nothing Return Nothing
End Try End Try
End Function End Function
@ -197,6 +203,8 @@ Public Class MSSQLServer
Return Nothing Return Nothing
End If End If
_Logger.Debug("Running Query: {0}", SQLCommand)
If SQLCommand.CommandText.Contains(" ") Then If SQLCommand.CommandText.Contains(" ") Then
SQLCommand.CommandType = CommandType.Text SQLCommand.CommandType = CommandType.Text
Else Else
@ -227,27 +235,29 @@ Public Class MSSQLServer
''' <summary> ''' <summary>
''' Executes the passed sql-statement in asyncmode ''' Executes the passed sql-statement in asyncmode
''' </summary> ''' </summary>
''' <param name="executeStatement">the sql statement</param> ''' <param name="SqlCommand">the sql statement</param>
''' <param name="commandtimeout">Optional Timeout</param> ''' <param name="commandtimeout">Optional Timeout</param>
''' <remarks></remarks> ''' <remarks></remarks>
Public Sub NewExecuteNonQueryAsync(executeStatement As String, Optional commandtimeout As Integer = 120) Public Sub NewExecuteNonQueryAsync(SqlCommand As String, Optional commandtimeout As Integer = 120)
If TestCanConnect() = False Then If TestCanConnect() = False Then
Exit Sub Exit Sub
End If End If
_Logger.Debug("Running Query: {0}", SqlCommand)
Try Try
Dim oCallback As New AsyncCallback(AddressOf NewExecuteNonQueryAsync_Callback) Dim oCallback As New AsyncCallback(AddressOf NewExecuteNonQueryAsync_Callback)
Using oConnection As SqlConnection = GetSQLConnection() Using oConnection As SqlConnection = GetSQLConnection()
Using oSQLCOmmand = oConnection.CreateCommand() Using oSQLCOmmand = oConnection.CreateCommand()
oSQLCOmmand.CommandText = executeStatement oSQLCOmmand.CommandText = SqlCommand
oSQLCOmmand.CommandTimeout = commandtimeout oSQLCOmmand.CommandTimeout = commandtimeout
oSQLCOmmand.BeginExecuteNonQuery(oCallback, oSQLCOmmand) oSQLCOmmand.BeginExecuteNonQuery(oCallback, oSQLCOmmand)
End Using End Using
End Using End Using
Catch ex As Exception Catch ex As Exception
_Logger.Error(ex) _Logger.Error(ex)
_Logger.Warn("executeStatement: " & executeStatement) _Logger.Warn("executeStatement: " & SqlCommand)
End Try End Try
End Sub End Sub

View File

@ -174,7 +174,9 @@
<xs:sequence> <xs:sequence>
<xs:element minOccurs="0" name="FileName" nillable="true" type="xs:string" /> <xs:element minOccurs="0" name="FileName" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="Contents" nillable="true" type="xs:base64Binary" /> <xs:element minOccurs="0" name="Contents" nillable="true" type="xs:base64Binary" />
<xs:element minOccurs="0" name="AddedWho" nillable="true" type="xs:string" /> <xs:element minOccurs="0" name="ObjectStoreId" type="xs:long" />
<xs:element minOccurs="0" name="DocumentType" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="RetentionDays" type="xs:long" />
</xs:sequence> </xs:sequence>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>

View File

@ -594,10 +594,10 @@ Namespace EDMIServiceReference
Function GetDocumentByContainerIdAsync(ByVal ContainerId As String) As System.Threading.Tasks.Task(Of EDMIServiceReference.DocumentResultOld) Function GetDocumentByContainerIdAsync(ByVal ContainerId As String) As System.Threading.Tasks.Task(Of EDMIServiceReference.DocumentResultOld)
<System.ServiceModel.OperationContractAttribute(Action:="http://DigitalData.Services.EDMIService/IEDMIService/ImportFile", ReplyAction:="http://DigitalData.Services.EDMIService/IEDMIService/ImportFileResponse")> _ <System.ServiceModel.OperationContractAttribute(Action:="http://DigitalData.Services.EDMIService/IEDMIService/ImportFile", ReplyAction:="http://DigitalData.Services.EDMIService/IEDMIService/ImportFileResponse")> _
Function ImportFile(ByVal FileName As String, ByVal Contents() As Byte, ByVal AddedWho As String) As EDMIServiceReference.DocumentResult Function ImportFile(ByVal FileName As String, ByVal Contents() As Byte, ByVal ObjectStoreId As Long, ByVal DocumentType As String, ByVal RetentionDays As Long) As EDMIServiceReference.DocumentResult
<System.ServiceModel.OperationContractAttribute(Action:="http://DigitalData.Services.EDMIService/IEDMIService/ImportFile", ReplyAction:="http://DigitalData.Services.EDMIService/IEDMIService/ImportFileResponse")> _ <System.ServiceModel.OperationContractAttribute(Action:="http://DigitalData.Services.EDMIService/IEDMIService/ImportFile", ReplyAction:="http://DigitalData.Services.EDMIService/IEDMIService/ImportFileResponse")> _
Function ImportFileAsync(ByVal FileName As String, ByVal Contents() As Byte, ByVal AddedWho As String) As System.Threading.Tasks.Task(Of EDMIServiceReference.DocumentResult) Function ImportFileAsync(ByVal FileName As String, ByVal Contents() As Byte, ByVal ObjectStoreId As Long, ByVal DocumentType As String, ByVal RetentionDays As Long) As System.Threading.Tasks.Task(Of EDMIServiceReference.DocumentResult)
'CODEGEN: Der Nachrichtenvertrag wird generiert, da der Wrappername (DocumentStreamRequest) von Nachricht "DocumentStreamRequest" nicht mit dem Standardwert (GetFileByObjectId) übereinstimmt. 'CODEGEN: Der Nachrichtenvertrag wird generiert, da der Wrappername (DocumentStreamRequest) von Nachricht "DocumentStreamRequest" nicht mit dem Standardwert (GetFileByObjectId) übereinstimmt.
<System.ServiceModel.OperationContractAttribute(Action:="http://DigitalData.Services.EDMIService/IEDMIService/GetFileByObjectId", ReplyAction:="http://DigitalData.Services.EDMIService/IEDMIService/GetFileByObjectIdResponse")> _ <System.ServiceModel.OperationContractAttribute(Action:="http://DigitalData.Services.EDMIService/IEDMIService/GetFileByObjectId", ReplyAction:="http://DigitalData.Services.EDMIService/IEDMIService/GetFileByObjectIdResponse")> _
@ -788,12 +788,12 @@ Namespace EDMIServiceReference
Return MyBase.Channel.GetDocumentByContainerIdAsync(ContainerId) Return MyBase.Channel.GetDocumentByContainerIdAsync(ContainerId)
End Function End Function
Public Function ImportFile(ByVal FileName As String, ByVal Contents() As Byte, ByVal AddedWho As String) As EDMIServiceReference.DocumentResult Implements EDMIServiceReference.IEDMIService.ImportFile Public Function ImportFile(ByVal FileName As String, ByVal Contents() As Byte, ByVal ObjectStoreId As Long, ByVal DocumentType As String, ByVal RetentionDays As Long) As EDMIServiceReference.DocumentResult Implements EDMIServiceReference.IEDMIService.ImportFile
Return MyBase.Channel.ImportFile(FileName, Contents, AddedWho) Return MyBase.Channel.ImportFile(FileName, Contents, ObjectStoreId, DocumentType, RetentionDays)
End Function End Function
Public Function ImportFileAsync(ByVal FileName As String, ByVal Contents() As Byte, ByVal AddedWho As String) As System.Threading.Tasks.Task(Of EDMIServiceReference.DocumentResult) Implements EDMIServiceReference.IEDMIService.ImportFileAsync Public Function ImportFileAsync(ByVal FileName As String, ByVal Contents() As Byte, ByVal ObjectStoreId As Long, ByVal DocumentType As String, ByVal RetentionDays As Long) As System.Threading.Tasks.Task(Of EDMIServiceReference.DocumentResult) Implements EDMIServiceReference.IEDMIService.ImportFileAsync
Return MyBase.Channel.ImportFileAsync(FileName, Contents, AddedWho) Return MyBase.Channel.ImportFileAsync(FileName, Contents, ObjectStoreId, DocumentType, RetentionDays)
End Function End Function
<System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)> _ <System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)> _

View File

@ -53,12 +53,12 @@ Public Class Document
''' </summary> ''' </summary>
''' <param name="FilePath">The filename to import</param> ''' <param name="FilePath">The filename to import</param>
''' <returns>A document object</returns> ''' <returns>A document object</returns>
Public Async Function ImportFileAsync(FilePath As String, Optional [ReadOnly] As Boolean = False, Optional RetentionPeriod As Integer = 0) As Task(Of DocumentResult) Public Async Function ImportFileAsync(FilePath As String, Optional [ReadOnly] As Boolean = False, Optional RetentionDays As Integer = 0) As Task(Of DocumentResult)
Try Try
Using oStream As New FileStream(FilePath, FileMode.Open) Using oStream As New FileStream(FilePath, FileMode.Open)
Dim oContents As Byte() = {} Dim oContents As Byte() = {}
Dim oBytesRead = Await oStream.ReadAsync(oContents, 0, oStream.Length) Dim oBytesRead = Await oStream.ReadAsync(oContents, 0, oStream.Length)
Dim oResult = Await _channel.ImportFileAsync(FilePath, oContents, Environment.UserName) Dim oResult = Await _channel.ImportFileAsync(FilePath, oContents, 1, "WichtigesDokument", RetentionDays)
Return oResult Return oResult
End Using End Using
@ -77,7 +77,7 @@ Public Class Document
Try Try
Dim oContents As Byte() = File.ReadAllBytes(FilePath) Dim oContents As Byte() = File.ReadAllBytes(FilePath)
Dim oInfo As New FileInfo(FilePath) Dim oInfo As New FileInfo(FilePath)
Dim oDocObject = _channel.ImportFile(FilePath, oContents, Environment.UserName) Dim oDocObject = _channel.ImportFile(FilePath, oContents, 1, "WichtigesDokument", 0)
Return oDocObject Return oDocObject
Catch ex As Exception Catch ex As Exception
_logger.Error(ex) _logger.Error(ex)

View File

@ -1,16 +1,16 @@
Imports System.Configuration Imports System.Configuration
Public Class AppConfig Public Class AppConfig
Public Shared FirebirdDataSource As String Public FirebirdDataSource As String
Public Shared FirebirdDatabase As String Public FirebirdDatabase As String
Public Shared FirebirdUser As String Public FirebirdUser As String
Public Shared FirebirdPassword As String Public FirebirdPassword As String
Public Shared ContainerPath As String Public ContainerPath As String
Public Shared ContainerPassword As String Public ContainerPassword As String
Public Shared DatastorePath As String Public DatastorePath As String
Public Shared MSSQLConnectionString As String Public MSSQLConnectionString As String
Public Shared Sub Load() Public Sub New()
With ConfigurationManager.AppSettings With ConfigurationManager.AppSettings
FirebirdDataSource = .Item("FIREBIRD_DATASOURCE") FirebirdDataSource = .Item("FIREBIRD_DATASOURCE")
FirebirdDatabase = .Item("FIREBIRD_DATABASE_NAME") FirebirdDatabase = .Item("FIREBIRD_DATABASE_NAME")
@ -26,12 +26,12 @@ Public Class AppConfig
End With End With
End Sub 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} Dim oProps As New List(Of String) From {FirebirdDataSource, FirebirdDatabase, FirebirdUser, FirebirdPassword}
Return Not oProps.Any(Function(Prop) String.IsNullOrWhiteSpace(Prop)) Return Not oProps.Any(Function(Prop) String.IsNullOrWhiteSpace(Prop))
End Function End Function
Public Shared Function IsMSSQLConfigured() As Boolean Public Function IsMSSQLConfigured() As Boolean
Return Not String.IsNullOrWhiteSpace(MSSQLConnectionString) Return Not String.IsNullOrWhiteSpace(MSSQLConnectionString)
End Function End Function
End Class 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.Logging
Imports DigitalData.Modules.Filesystem Imports DigitalData.Modules.Filesystem
Imports DigitalData.Modules Imports DigitalData.Modules
Imports System.IO Imports System.IO
Imports System.ServiceModel.Description Imports System.ServiceModel
Imports System.ServiceModel.Channels
Imports System.Data.SqlClient Imports System.Data.SqlClient
<ServiceBehavior(InstanceContextMode:=InstanceContextMode.PerSession)> <ServiceBehavior(InstanceContextMode:=InstanceContextMode.PerSession)>
@ -17,8 +15,8 @@ Public Class EDMIService
Public Shared Firebird As Firebird Public Shared Firebird As Firebird
Public Shared AppConfig As AppConfig Public Shared AppConfig As AppConfig
Public Shared Filesystem As Filesystem.File Public Shared Filesystem As Filesystem.File
Public Shared EDMIPath As EDMI.File.Path
Public Shared EDMIArchive As EDMI.File.Archive Public Shared EDMIArchive As EDMI.File.Archive
Public Shared GlobalState As GlobalState
Private ReadOnly _logger As Logger Private ReadOnly _logger As Logger
@ -34,7 +32,6 @@ Public Class EDMIService
_username = oUsername _username = oUsername
_logger = LogConfig.GetLogger() _logger = LogConfig.GetLogger()
_logger.Debug("New Request by User [{0}]", _username) _logger.Debug("New Request by User [{0}]", _username)
End Sub End Sub
@ -320,6 +317,16 @@ Public Class EDMIService
''' <param name="Contents"></param> ''' <param name="Contents"></param>
''' <returns></returns> ''' <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 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: ' TODO:
' - Get Object Store -> Object Catalog -> Catalog Path ' - Get Object Store -> Object Catalog -> Catalog Path
' - If IS_ARCHIVE = True And RetentionDays <> Nothing: ' - If IS_ARCHIVE = True And RetentionDays <> Nothing:
@ -328,10 +335,9 @@ Public Class EDMIService
' and return ObjectStore Path from ObjectStoreId + RelativePath ' and return ObjectStore Path from ObjectStoreId + RelativePath
' VWIDB_OBJECTSTORE ' VWIDB_OBJECTSTORE
Dim oDocumentType As String = "DummyDocumentType" Dim oRelativePath As String = EDMIPath.GetRelativePath(DocumentType, FileName)
Dim oRelativePath As String = EDMIPath.GetRelativePath(oDocumentType, FileName) Dim oAbsolutePath As String = EDMIPath.GetFullPath(DocumentType, FileName)
Dim oAbsolutePath As String = EDMIPath.GetActivePath(oDocumentType, FileName) Dim oDirectoryPath = EDMIPath.GetFullPath(DocumentType)
Dim oDirectoryPath = EDMIPath.GetActivePath(oDocumentType)
Dim oDocument = New DocumentResult.DocumentObject With {.FileName = FileName} Dim oDocument = New DocumentResult.DocumentObject With {.FileName = FileName}
Try Try
@ -372,14 +378,23 @@ Public Class EDMIService
Public Function GetFileByObjectId(Data As Messages.DocumentStreamRequest) As Messages.DocumentStreamResponse Implements IEDMIService.GetFileByObjectId Public Function GetFileByObjectId(Data As Messages.DocumentStreamRequest) As Messages.DocumentStreamResponse Implements IEDMIService.GetFileByObjectId
Try Try
Dim oSQL As String = $"SELECT DocRelativePath FROM VWIDB_DOC_DATA WHERE IDB_OBJ_ID = {Data.ObjectId}" Dim oSQL As String = $"SELECT ObjectStoreId FROM VWIDB_DOC_DATA WHERE IDB_OBJ_ID = {Data.ObjectId}"
Dim oPath As String = MSSQL.GetScalarValue(oSQL) 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 If IsNothing(oPath) Then
Throw New FaultException($"Object [{Data.ObjectId}] does not exist in database!") Throw New FaultException($"Object [{Data.ObjectId}] does not exist in database!")
End If 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) _logger.Debug("GetFileByObjectId: Loading file [{0}]", oFullPath)

View File

@ -104,6 +104,7 @@
<Compile Include="AppConfig.vb" /> <Compile Include="AppConfig.vb" />
<Compile Include="Database\IDatabase.vb" /> <Compile Include="Database\IDatabase.vb" />
<Compile Include="Database\MSSQL.vb" /> <Compile Include="Database\MSSQL.vb" />
<Compile Include="GlobalState.vb" />
<Compile Include="Messages.vb" /> <Compile Include="Messages.vb" />
<Compile Include="Results\BaseResult.vb" /> <Compile Include="Results\BaseResult.vb" />
<Compile Include="Results\ContainerResult.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 Public Class WindowsService
Inherits ServiceBase Inherits ServiceBase
Private _serviceHost As ServiceHost = Nothing Private _ServiceHost As ServiceHost
Private _edmService As IEDMIService = Nothing Private _LogConfig As LogConfig
Private _Logger As Logger
Private _logConfig As LogConfig Private _Firebird As Firebird
Private _logger As Logger Private _MSSQL As MSSQLServer
Private _firebird As Firebird Private _Config As AppConfig
Private _mssql As MSSQLServer
Private _config As AppConfig
Private _Path As EDMI.File.Path Private _Path As EDMI.File.Path
Private _Archive As EDMI.File.Archive Private _Archive As EDMI.File.Archive
Private _filesystem As Filesystem.File Private _Filesystem As Filesystem.File
Private _Global As GlobalState
Public Sub New() Public Sub New()
ServiceName = SERVICE_NAME ServiceName = SERVICE_NAME
@ -32,78 +31,84 @@ Public Class WindowsService
Protected Overrides Sub OnStart(ByVal args As String()) Protected Overrides Sub OnStart(ByVal args As String())
Try Try
AppConfig.Load() _Config = New AppConfig()
_LogConfig = New LogConfig(LogConfig.PathType.CustomPath, "E:\EDMService") With {
_logConfig = New LogConfig(LogConfig.PathType.CustomPath, "E:\EDMService") With {
.Debug = True .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 _Archive = New EDMI.File.Archive(_LogConfig)
_logger.Debug("Connecting to Firebird...") _Filesystem = New Filesystem.File(_LogConfig)
_firebird = New Firebird( _Global = New GlobalState(_LogConfig, _MSSQL)
_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
If AppConfig.IsMSSQLConfigured() Then _Global.LoadObjectStores()
_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
_logger.Debug("Initializing EDMI Functions") _Logger.Info("EDMI Functions initialized.")
_Path = New EDMI.File.Path(_logConfig, AppConfig.DatastorePath) EDMIService.MSSQL = _MSSQL
_Archive = New EDMI.File.Archive(_logConfig) EDMIService.Firebird = _Firebird
_filesystem = New Filesystem.File(_logConfig) EDMIService.LogConfig = _LogConfig
EDMIService.AppConfig = _Config
_logger.Info("EDMI Functions initialized.")
EDMIService.MSSQL = _mssql
EDMIService.Firebird = _firebird
EDMIService.LogConfig = _logConfig
EDMIService.AppConfig = _config
EDMIService.EDMIArchive = _Archive 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 = New ServiceHost(GetType(EDMIService))
_serviceHost.Open() _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 Catch ex As Exception
_logger.Error(ex, "Failed to start the service host!") _Logger.Error(ex, "Failed to start the service host!")
GracefullyStop() GracefullyStop()
End Try End Try
End Sub 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() Protected Overrides Sub OnStop()
GracefullyStop() GracefullyStop()
End Sub End Sub
Private Sub GracefullyStop() Private Sub GracefullyStop()
If _serviceHost IsNot Nothing Then If _ServiceHost IsNot Nothing Then
_serviceHost.Close() _ServiceHost.Close()
_serviceHost = Nothing _ServiceHost = Nothing
End If End If
_logger.Info("Service {0} is stopping!", SERVICE_DISPLAY_NAME) _Logger.Info("Service {0} is stopping!", SERVICE_DISPLAY_NAME)
End Sub End Sub
End Class End Class