EDMI Service: WIP
This commit is contained in:
@@ -7,6 +7,10 @@
|
||||
<add key="FIREBIRD_DATABASE_USER" value=""/>
|
||||
<add key="FIREBIRD_DATABASE_PASS" value=""/>
|
||||
<!-- END FIREBIRD SETTINGS -->
|
||||
|
||||
<!-- MSSQL SETTINGS -->
|
||||
<add key="MSSQ_CONNECTION_STRING" value=""/>
|
||||
<!-- END MSSQL SETTINGS -->
|
||||
|
||||
<!-- DATASTORE SETTINGS -->
|
||||
<add key="DATASTORE_PATH" value=""/>
|
||||
|
||||
@@ -8,6 +8,7 @@ Public Class AppConfig
|
||||
Public Shared ContainerPath As String
|
||||
Public Shared ContainerPassword As String
|
||||
Public Shared DatastorePath As String
|
||||
Public Shared MSSQLConnectionString As String
|
||||
|
||||
Public Shared Sub Load()
|
||||
With ConfigurationManager.AppSettings
|
||||
@@ -15,9 +16,22 @@ Public Class AppConfig
|
||||
FirebirdDatabase = .Item("FIREBIRD_DATABASE_NAME")
|
||||
FirebirdUser = .Item("FIREBIRD_DATABASE_USER")
|
||||
FirebirdPassword = .Item("FIREBIRD_DATABASE_PASS")
|
||||
|
||||
MSSQLConnectionString = .Item("MSSQL_CONNECTION_STRING")
|
||||
|
||||
ContainerPath = .Item("CONTAINER_PATH")
|
||||
ContainerPassword = .Item("CONTAINER_PASSWORD")
|
||||
|
||||
DatastorePath = .Item("DATASTORE_PATH")
|
||||
End With
|
||||
End Sub
|
||||
|
||||
Public Shared 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
|
||||
Return Not String.IsNullOrWhiteSpace(MSSQLConnectionString)
|
||||
End Function
|
||||
End Class
|
||||
|
||||
3
Service.EDMIService/Database/IDatabase.vb
Normal file
3
Service.EDMIService/Database/IDatabase.vb
Normal file
@@ -0,0 +1,3 @@
|
||||
Public Interface IDatabase
|
||||
Function NewDocument(RelativePath As String, AddedWho As String, ObjectStoreId As Int64, ReferenceId As Int64) As Int64
|
||||
End Interface
|
||||
20
Service.EDMIService/Database/MSSQL.vb
Normal file
20
Service.EDMIService/Database/MSSQL.vb
Normal file
@@ -0,0 +1,20 @@
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Public Class MSSQL
|
||||
Implements IDatabase
|
||||
|
||||
Private ReadOnly LogConfig As LogConfig
|
||||
Private ReadOnly Database As MSSQLServer
|
||||
Private ReadOnly Logger As Logger
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, Database As MSSQLServer)
|
||||
Me.LogConfig = LogConfig
|
||||
Me.Database = Database
|
||||
Me.Logger = LogConfig.GetLogger()
|
||||
End Sub
|
||||
|
||||
Public Function NewDocument(RelativePath As String, AddedWho As String, ObjectStoreId As Long, ReferenceId As Long) As Long Implements IDatabase.NewDocument
|
||||
|
||||
End Function
|
||||
End Class
|
||||
@@ -6,13 +6,15 @@ Imports DigitalData.Modules
|
||||
Imports System.IO
|
||||
Imports System.ServiceModel.Description
|
||||
Imports System.ServiceModel.Channels
|
||||
Imports System.Data.SqlClient
|
||||
|
||||
<ServiceBehavior(InstanceContextMode:=InstanceContextMode.PerSession)>
|
||||
Public Class EDMIService
|
||||
Implements IEDMIService
|
||||
|
||||
Public Shared LogConfig As LogConfig
|
||||
Public Shared Database As Firebird
|
||||
Public Shared MSSQL As MSSQLServer
|
||||
Public Shared Firebird As Firebird
|
||||
Public Shared AppConfig As AppConfig
|
||||
Public Shared Filesystem As Filesystem.File
|
||||
Public Shared EDMIPath As EDMI.File.Path
|
||||
@@ -54,7 +56,7 @@ Public Class EDMIService
|
||||
#End Region
|
||||
#Region "Request"
|
||||
Public Sub CreateRequest(Name As String, Optional Debug As Boolean = False)
|
||||
_request = New Request(Name, _username, Database, Debug)
|
||||
_request = New Request(Name, _username, Firebird, Debug)
|
||||
_debug = Debug
|
||||
|
||||
_logger.Info("Creating request {0}/{1}", _request.Name, _request.RequestId)
|
||||
@@ -91,7 +93,7 @@ Public Class EDMIService
|
||||
_logger.Info($"ReturnDatatable, SQL: {SQL}")
|
||||
_request.LogDebug($"ReturnDatatable, SQL: {SQL}")
|
||||
|
||||
Dim oResult As DataTable = Database.GetDatatableWithConnection(SQL, _request.Connection)
|
||||
Dim oResult As DataTable = Firebird.GetDatatableWithConnection(SQL, _request.Connection)
|
||||
Return New TableResult(oResult)
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
@@ -107,7 +109,7 @@ Public Class EDMIService
|
||||
_logger.Info($"ReturnScalar, SQL: {SQL}")
|
||||
_request.LogDebug($"ReturnScalar, SQL: {SQL}")
|
||||
|
||||
Dim oResult As Object = Database.GetScalarValueWithConnection(SQL, _request.Connection)
|
||||
Dim oResult As Object = Firebird.GetScalarValueWithConnection(SQL, _request.Connection)
|
||||
Return New ScalarResult(oResult)
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
@@ -123,7 +125,7 @@ Public Class EDMIService
|
||||
_logger.Info($"ExecuteNonQuery, SQL: {SQL}")
|
||||
_request.LogDebug($"ExecuteNonQuery, SQL: {SQL}")
|
||||
|
||||
Dim oResult As Boolean = Database.ExecuteNonQueryWithConnection(SQL, _request.Connection)
|
||||
Dim oResult As Boolean = Firebird.ExecuteNonQueryWithConnection(SQL, _request.Connection)
|
||||
Return New NonQueryResult()
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
@@ -152,7 +154,7 @@ Public Class EDMIService
|
||||
_logger.Debug("File extension of file {0} is {1}", FileName, oExtension)
|
||||
|
||||
Dim oSQL = $"SELECT FNICM_NEW_DOC('010', '{oContainerId}', '{GetContainerName(oContainerId)}', '{FileName}', '{oExtension}', '{_username}') FROM RDB$DATABASE;"
|
||||
Dim oDocId As Int64 = Database.GetScalarValue(oSQL)
|
||||
Dim oDocId As Int64 = Firebird.GetScalarValue(oSQL)
|
||||
|
||||
If oDocId = -1 Then
|
||||
_logger.Warn("Database returned -1 while creating Document Entry. File was not saved!")
|
||||
@@ -244,7 +246,7 @@ Public Class EDMIService
|
||||
Public Function GetDocumentByDocumentId(DocumentId As Long) As DocumentResult Implements IEDMIService.GetDocumentByDocumentId
|
||||
Try
|
||||
Dim oSQL = $"SELECT GUID, CONTAINER_ID, ORIGINAL_FILENAME FROM TBIDB_DOCUMENT WHERE GUID = {DocumentId}"
|
||||
Dim oTable = Database.GetDatatable(oSQL)
|
||||
Dim oTable = Firebird.GetDatatable(oSQL)
|
||||
|
||||
If oTable.Rows.Count = 0 Then
|
||||
Return New DocumentResult("Document not found")
|
||||
@@ -272,7 +274,7 @@ Public Class EDMIService
|
||||
Public Function GetDocumentByContainerId(ContainerId As String) As DocumentResult Implements IEDMIService.GetDocumentByContainerId
|
||||
Try
|
||||
Dim oSQL = $"SELECT GUID, CONTAINER_ID, ORIGINAL_FILENAME FROM TBIDB_DOCUMENT WHERE CONTAINER_ID = '{ContainerId}'"
|
||||
Dim oTable = Database.GetDatatable(oSQL)
|
||||
Dim oTable = Firebird.GetDatatable(oSQL)
|
||||
|
||||
If oTable.Rows.Count = 0 Then
|
||||
Return New DocumentResult("Document not found")
|
||||
@@ -299,11 +301,12 @@ Public Class EDMIService
|
||||
#End Region
|
||||
|
||||
#Region "Document"
|
||||
Public Function ImportFile(FileInfo As FileInfo, Contents() As Byte, [Readonly] As Boolean, RetentionPeriod As Integer) As DocumentResult2 Implements IEDMIService.ImportFile
|
||||
Public Function ImportFile(FileName As String, Contents() As Byte, AddedWho As String) As DocumentResult2 Implements IEDMIService.ImportFile
|
||||
Dim oDocumentType As String = "DummyDocumentType"
|
||||
Dim oDirectoryPath = EDMIPath.GetActivePath(oDocumentType)
|
||||
Dim oFilePath = Path.Combine(oDirectoryPath, FileInfo.Name)
|
||||
Dim oDocument = New DocumentResult2.DocumentObject() With {.FileName = FileInfo.Name, .FileId = Guid.NewGuid.ToString}
|
||||
Dim oAbsPath = Path.Combine(oDirectoryPath, FileName)
|
||||
Dim oRelativePath = EDMIPath.GetRelativePath(oDocumentType)
|
||||
Dim oDocument = New DocumentResult2.DocumentObject With {.FileName = FileName}
|
||||
|
||||
Try
|
||||
Directory.CreateDirectory(oDirectoryPath)
|
||||
@@ -313,16 +316,26 @@ Public Class EDMIService
|
||||
End Try
|
||||
|
||||
Try
|
||||
Dim oVersionedFileName As String = Filesystem.GetVersionedFilename(oFilePath)
|
||||
Dim oVersionedFileName As String = Filesystem.GetVersionedFilename(oAbsPath)
|
||||
|
||||
_logger.Info("Saving file [{0}] to path [{1}]", FileInfo.Name, oVersionedFileName)
|
||||
_logger.Info("Saving file [{0}] to path [{1}]", FileName, oVersionedFileName)
|
||||
Using oStream = New FileStream(oVersionedFileName, FileMode.CreateNew)
|
||||
oStream.Write(Contents, 0, Contents.Length)
|
||||
oStream.Flush(True)
|
||||
oStream.Close()
|
||||
End Using
|
||||
|
||||
EDMIArchive.SetRetention(oVersionedFileName, RetentionPeriod, [Readonly])
|
||||
' insert into db
|
||||
Dim oCommand As New SqlCommand("PRIDB_NEW_DOCUMENT")
|
||||
oCommand.Parameters.AddWithValue("@OBJ_ST_ID", 1)
|
||||
oCommand.Parameters.AddWithValue("@REL_PATH", oDirectoryPath)
|
||||
oCommand.Parameters.AddWithValue("@WHO", AddedWho)
|
||||
oCommand.Parameters.AddWithValue("@REF_DOCID", 0)
|
||||
oCommand.Parameters.Add(New SqlParameter("@IDB_OBJ_ID", SqlDbType.BigInt))
|
||||
|
||||
Dim oObjectId = MSSQL.GetScalarValue(oCommand, "@IDB_OBJ_ID")
|
||||
|
||||
oDocument.FileId = oObjectId
|
||||
|
||||
Return New DocumentResult2(oDocument)
|
||||
Catch ex As Exception
|
||||
@@ -330,13 +343,14 @@ Public Class EDMIService
|
||||
Return New DocumentResult2(ex.Message)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
#End Region
|
||||
|
||||
#Region "Index"
|
||||
Public Function NewFileIndex(DocObject As DocumentObject, Syskey As String, LanguageCode As String, Value As String) As IndexResult Implements IEDMIService.NewFileIndex
|
||||
Try
|
||||
Dim oSQL = $"SELECT FNIDB_NEW_DOC_VALUE({DocObject.DocumentId},'{Syskey}','{LanguageCode}','{Value}','{_username}') FROM RDB$DATABASE;"
|
||||
Dim oIndexId As Int64 = Database.GetScalarValue(oSQL)
|
||||
Dim oIndexId As Int64 = Firebird.GetScalarValue(oSQL)
|
||||
|
||||
Return New IndexResult(oIndexId)
|
||||
Catch ex As Exception
|
||||
|
||||
@@ -101,6 +101,8 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AppConfig.vb" />
|
||||
<Compile Include="Database\IDatabase.vb" />
|
||||
<Compile Include="Database\MSSQL.vb" />
|
||||
<Compile Include="Results\BaseResult.vb" />
|
||||
<Compile Include="Results\ContainerResult.vb" />
|
||||
<Compile Include="Results\DocumentResult.vb" />
|
||||
|
||||
@@ -49,7 +49,7 @@ Interface IEDMIService
|
||||
|
||||
#Region "Document (New)"
|
||||
<OperationContract>
|
||||
Function ImportFile(FileInfo As FileInfo, Contents As Byte(), [ReadOnly] As Boolean, RetentionTime As Integer) As DocumentResult2
|
||||
Function ImportFile(FileName As String, Contents As Byte(), AddedWho As String) As DocumentResult2
|
||||
#End Region
|
||||
|
||||
#Region "Index"
|
||||
|
||||
@@ -13,8 +13,10 @@ Public Class WindowsService
|
||||
|
||||
Private _logConfig As LogConfig
|
||||
Private _logger As Logger
|
||||
Private _db As Firebird
|
||||
Private _clientsConnected As Integer = 0
|
||||
|
||||
Private _firebird As Firebird
|
||||
Private _mssql As MSSQLServer
|
||||
|
||||
Private _config As AppConfig
|
||||
Private _Path As EDMI.File.Path
|
||||
Private _Archive As EDMI.File.Archive
|
||||
@@ -39,17 +41,28 @@ Public Class WindowsService
|
||||
_logger = _logConfig.GetLogger()
|
||||
|
||||
_logger.Info("Service {0} is starting...", SERVICE_DISPLAY_NAME)
|
||||
_logger.Debug("Connecting to database...")
|
||||
|
||||
_db = New Firebird(
|
||||
_logConfig,
|
||||
AppConfig.FirebirdDataSource,
|
||||
AppConfig.FirebirdDatabase,
|
||||
AppConfig.FirebirdUser,
|
||||
AppConfig.FirebirdPassword
|
||||
)
|
||||
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
|
||||
|
||||
_logger.Info("Database connection established.")
|
||||
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
|
||||
|
||||
_logger.Debug("Initializing EDMI Functions")
|
||||
|
||||
@@ -57,9 +70,10 @@ Public Class WindowsService
|
||||
_Archive = New EDMI.File.Archive(_logConfig)
|
||||
_filesystem = New Filesystem.File(_logConfig)
|
||||
|
||||
_logger.Debug("EDMI Functions initialized.")
|
||||
_logger.Info("EDMI Functions initialized.")
|
||||
|
||||
EDMIService.Database = _db
|
||||
EDMIService.MSSQL = _mssql
|
||||
EDMIService.Firebird = _firebird
|
||||
EDMIService.LogConfig = _logConfig
|
||||
EDMIService.AppConfig = _config
|
||||
EDMIService.EDMIArchive = _Archive
|
||||
@@ -71,7 +85,7 @@ Public Class WindowsService
|
||||
_serviceHost = New ServiceHost(GetType(EDMIService))
|
||||
_serviceHost.Open()
|
||||
|
||||
_logger.Debug("WCF ServiceHost started.")
|
||||
_logger.Info("WCF ServiceHost started.")
|
||||
|
||||
_logger.Info("Service {0} successfully started.", SERVICE_DISPLAY_NAME)
|
||||
Catch ex As Exception
|
||||
|
||||
Reference in New Issue
Block a user