EDMI Service: WIP
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user