From d1817fedb5ea876e2d930fd878acfab2ecbbf7d1 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Tue, 7 Apr 2020 10:55:09 +0200 Subject: [PATCH] bring EDMIService up to date --- Service.EDMIService/App.config | 67 ++-- Service.EDMIService/EDMIService.vb | 300 +++++++++--------- Service.EDMIService/EDMIService.vbproj | 37 ++- Service.EDMIService/IEDMIService.vb | 24 +- .../My Project/Resources.Designer.vb | 4 +- .../My Project/Settings.Designer.vb | 6 +- Service.EDMIService/WindowsService.vb | 2 +- Service.EDMIService/packages.config | 4 +- 8 files changed, 234 insertions(+), 210 deletions(-) diff --git a/Service.EDMIService/App.config b/Service.EDMIService/App.config index db5e4896..c9a15314 100644 --- a/Service.EDMIService/App.config +++ b/Service.EDMIService/App.config @@ -2,30 +2,28 @@ - + - + - + - + - + - - - - + + + + @@ -33,42 +31,36 @@ - - + + - - + + - - + + - + - + - + - + - + @@ -76,15 +68,18 @@ - - + + - - - - - - \ No newline at end of file + + + + + + + + + diff --git a/Service.EDMIService/EDMIService.vb b/Service.EDMIService/EDMIService.vb index 50accd7e..53dc1f43 100644 --- a/Service.EDMIService/EDMIService.vb +++ b/Service.EDMIService/EDMIService.vb @@ -132,167 +132,167 @@ Public Class EDMIService #End Region #Region "Document (with FileContainer)" - 'Public Function NewFile(FileName As String, Contents() As Byte) As DocumentResult Implements IEDMIService.NewFile - ' Try - ' Dim oContainer As FileContainer - ' Dim oContainerId As String + Public Function NewFile(FileName As String, Contents() As Byte) As DocumentResult Implements IEDMIService.NewFile + Try + Dim oContainer As FileContainer + Dim oContainerId As String + + If Not TestUserAuth() Then + Throw New Exception($"User {_username} not authorized.") + End If + + oContainer = FileContainer.Create(LogConfig, AppConfig.ContainerPassword) + oContainerId = oContainer.ContainerId + _logger.Debug("Container created with id {0}", oContainerId) + + Dim oExtension As String = Path.GetExtension(FileName).Substring(1) + _logger.Debug("File extension of file {0} is {1}", FileName, oExtension) - ' If Not TestUserAuth() Then - ' Throw New Exception($"User {_username} not authorized.") - ' End If + Dim oSQL = $"SELECT FNICM_NEW_DOC('010', '{oContainerId}', '{GetContainerName(oContainerId)}', '{FileName}', '{oExtension}', '{_username}') FROM RDB$DATABASE;" + Dim oDocId As Int64 = Database.GetScalarValue(oSQL) - ' oContainer = FileContainer.Create(LogConfig, AppConfig.ContainerPassword) - ' oContainerId = oContainer.ContainerId - ' _logger.Debug("Container created with id {0}", oContainerId) + If oDocId = -1 Then + _logger.Warn("Database returned -1 while creating Document Entry. File was not saved!") + Return Nothing + End If - ' Dim oExtension As String = Path.GetExtension(FileName).Substring(1) - ' _logger.Debug("File extension of file {0} is {1}", FileName, oExtension) + _logger.Debug("Database Entry created with DocId {0}", oDocId) - ' Dim oSQL = $"SELECT FNICM_NEW_DOC('010', '{oContainerId}', '{GetContainerName(oContainerId)}', '{FileName}', '{oExtension}', '{_username}') FROM RDB$DATABASE;" - ' Dim oDocId As Int64 = Database.GetScalarValue(oSQL) + oContainer.SetFile(Contents, FileName) + oContainer.SaveAs(GetContainerPath(oContainerId)) + + _logger.Debug("File saved in Container!", FileName) + + Dim oDocument = New DocumentObject(oContainerId, oDocId, FileName) + Return New DocumentResult(oDocument) + Catch ex As Exception + _logger.Error(ex) + Return New DocumentResult(ex.Message) + End Try + End Function - ' If oDocId = -1 Then - ' _logger.Warn("Database returned -1 while creating Document Entry. File was not saved!") - ' Return Nothing - ' End If + Public Function UpdateFile(DocObject As DocumentObject, Contents() As Byte) As DocumentResult Implements IEDMIService.UpdateFile + Try + TestFileExists(DocObject.ContainerId) - ' _logger.Debug("Database Entry created with DocId {0}", oDocId) + ' TODO: update db - ' oContainer.SetFile(Contents, FileName) - ' oContainer.SaveAs(GetContainerPath(oContainerId)) + Dim oFilePath = GetContainerPath(DocObject.ContainerId) + Dim oFileContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oFilePath) - ' _logger.Debug("File saved in Container!", FileName) + oFileContainer.SetFile(Contents, oFileContainer.GetFile.FileName) + oFileContainer.Save() - ' Dim oDocument = New DocumentObject(oContainerId, oDocId, FileName) - ' Return New DocumentResult(oDocument) - ' Catch ex As Exception - ' _logger.Error(ex) - ' Return New DocumentResult(ex.Message) - ' End Try - 'End Function - 'Public Function UpdateFile(DocObject As DocumentObject, Contents() As Byte) As DocumentResult Implements IEDMIService.UpdateFile - ' Try - ' TestFileExists(DocObject.ContainerId) + Return New DocumentResult(DocObject) + Catch ex As Exception + _logger.Error(ex) + Return Nothing + End Try + End Function - ' ' TODO: update db - - ' Dim oFilePath = GetContainerPath(DocObject.ContainerId) - ' Dim oFileContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oFilePath) - - ' oFileContainer.SetFile(Contents, oFileContainer.GetFile.FileName) - ' oFileContainer.Save() - - - ' Return New DocumentResult(DocObject) - ' Catch ex As Exception - ' _logger.Error(ex) - ' Return Nothing - ' End Try - 'End Function - - 'Public Function GetFile(DocObject As DocumentObject) As DocumentResult Implements IEDMIService.GetFile - ' Try - ' TestFileExists(DocObject.ContainerId) - - ' Dim oContainerPath = GetContainerPath(DocObject.ContainerId) - ' Dim oContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oContainerPath) - ' Dim oContents As Byte() = oContainer.GetFile().Contents - - ' Return New DocumentResult(DocObject, oContents) - ' Catch ex As Exception - ' _logger.Error(ex) - ' Return New DocumentResult(ex.Message) - ' End Try - 'End Function - - 'Public Function DeleteFile(DocObject As DocumentObject) As Boolean Implements IEDMIService.DeleteFile - ' Try - ' TestFileExists(DocObject.ContainerId) - - ' Dim oFilePath = GetContainerPath(DocObject.ContainerId) - ' IO.File.Delete(oFilePath) - - ' 'TODO: Delete doc from db - - ' Return True - ' Catch ex As Exception - ' _logger.Error(ex) - ' Return False - ' End Try - 'End Function - - 'Private Function GetContainerPath(ContainerId As String) As String - ' Return Path.Combine(AppConfig.ContainerPath, GetContainerName(ContainerId)) - 'End Function - - 'Private Function GetContainerName(ContainerId As String) As String - ' Return ContainerId & ".enc" - 'End Function - - 'Private Sub TestFileExists(ContainerId) - ' Dim oContainerPath = GetContainerPath(ContainerId) - - ' If Not IO.File.Exists(oContainerPath) Then - ' Throw New FileNotFoundException("Container existiert nicht", oContainerPath) - ' End If - 'End Sub - - '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) - - ' If oTable.Rows.Count = 0 Then - ' Return New DocumentResult("Document not found") - ' End If - - ' Dim oRow As DataRow = oTable.Rows.Item(0) - ' Dim oDocument As New DocumentObject( - ' oRow.Item("CONTAINER_ID"), - ' oRow.Item("GUID"), - ' oRow.Item("ORIGINAL_FILENAME") - ' ) - - ' TestFileExists(oDocument.ContainerId) - - ' Dim oContainerPath = GetContainerPath(oDocument.ContainerId) - ' Dim oContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oContainerPath) - ' Dim oContents As Byte() = oContainer.GetFile().Contents - - ' Return New DocumentResult(oDocument, oContents) - ' Catch ex As Exception - ' Return New DocumentResult(ex.Message) - ' End Try - 'End Function - - '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) - - ' If oTable.Rows.Count = 0 Then - ' Return New DocumentResult("Document not found") - ' End If - - ' Dim oRow As DataRow = oTable.Rows.Item(0) - ' Dim oDocument As New DocumentObject( - ' oRow.Item("CONTAINER_ID"), - ' oRow.Item("GUID"), - ' oRow.Item("ORIGINAL_FILENAME") - ' ) - - ' TestFileExists(oDocument.ContainerId) - - ' Dim oContainerPath = GetContainerPath(oDocument.ContainerId) - ' Dim oContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oContainerPath) - ' Dim oContents As Byte() = oContainer.GetFile().Contents - - ' Return New DocumentResult(oDocument, oContents) - ' Catch ex As Exception - ' Return New DocumentResult(ex.Message) - ' End Try - 'End Function + Public Function GetFile(DocObject As DocumentObject) As DocumentResult Implements IEDMIService.GetFile + Try + TestFileExists(DocObject.ContainerId) + + Dim oContainerPath = GetContainerPath(DocObject.ContainerId) + Dim oContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oContainerPath) + Dim oContents As Byte() = oContainer.GetFile().Contents + + Return New DocumentResult(DocObject, oContents) + Catch ex As Exception + _logger.Error(ex) + Return New DocumentResult(ex.Message) + End Try + End Function + + Public Function DeleteFile(DocObject As DocumentObject) As Boolean Implements IEDMIService.DeleteFile + Try + TestFileExists(DocObject.ContainerId) + + Dim oFilePath = GetContainerPath(DocObject.ContainerId) + IO.File.Delete(oFilePath) + + 'TODO: Delete doc from db + + Return True + Catch ex As Exception + _logger.Error(ex) + Return False + End Try + End Function + + Private Function GetContainerPath(ContainerId As String) As String + Return Path.Combine(AppConfig.ContainerPath, GetContainerName(ContainerId)) + End Function + + Private Function GetContainerName(ContainerId As String) As String + Return ContainerId & ".enc" + End Function + + Private Sub TestFileExists(ContainerId) + Dim oContainerPath = GetContainerPath(ContainerId) + + If Not IO.File.Exists(oContainerPath) Then + Throw New FileNotFoundException("Container existiert nicht", oContainerPath) + End If + End Sub + + 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) + + If oTable.Rows.Count = 0 Then + Return New DocumentResult("Document not found") + End If + + Dim oRow As DataRow = oTable.Rows.Item(0) + Dim oDocument As New DocumentObject( + oRow.Item("CONTAINER_ID"), + oRow.Item("GUID"), + oRow.Item("ORIGINAL_FILENAME") + ) + + TestFileExists(oDocument.ContainerId) + + Dim oContainerPath = GetContainerPath(oDocument.ContainerId) + Dim oContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oContainerPath) + Dim oContents As Byte() = oContainer.GetFile().Contents + + Return New DocumentResult(oDocument, oContents) + Catch ex As Exception + Return New DocumentResult(ex.Message) + End Try + End Function + + 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) + + If oTable.Rows.Count = 0 Then + Return New DocumentResult("Document not found") + End If + + Dim oRow As DataRow = oTable.Rows.Item(0) + Dim oDocument As New DocumentObject( + oRow.Item("CONTAINER_ID"), + oRow.Item("GUID"), + oRow.Item("ORIGINAL_FILENAME") + ) + + TestFileExists(oDocument.ContainerId) + + Dim oContainerPath = GetContainerPath(oDocument.ContainerId) + Dim oContainer As FileContainer = FileContainer.Load(LogConfig, AppConfig.ContainerPassword, oContainerPath) + Dim oContents As Byte() = oContainer.GetFile().Contents + + Return New DocumentResult(oDocument, oContents) + Catch ex As Exception + Return New DocumentResult(ex.Message) + End Try + End Function #End Region #Region "Document" diff --git a/Service.EDMIService/EDMIService.vbproj b/Service.EDMIService/EDMIService.vbproj index 1c164a29..65fd134b 100644 --- a/Service.EDMIService/EDMIService.vbproj +++ b/Service.EDMIService/EDMIService.vbproj @@ -11,8 +11,24 @@ EDMIService 512 Console - v4.6.1 + v4.7.2 true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + AnyCPU @@ -47,12 +63,12 @@ On - - ..\..\packages\FirebirdSql.Data.FirebirdClient.6.4.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll + + ..\packages\FirebirdSql.Data.FirebirdClient.6.5.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll - ..\..\packages\NLog.4.7.0\lib\net45\NLog.dll + ..\packages\NLog.4.7.0\lib\net45\NLog.dll @@ -64,6 +80,7 @@ + @@ -162,5 +179,17 @@ Logging + + + False + Microsoft .NET Framework 4.6.1 %28x86 und x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/Service.EDMIService/IEDMIService.vb b/Service.EDMIService/IEDMIService.vb index b5dcf705..d7b15caa 100644 --- a/Service.EDMIService/IEDMIService.vb +++ b/Service.EDMIService/IEDMIService.vb @@ -28,23 +28,23 @@ Interface IEDMIService #End Region #Region "Document (with FileContainer)" - ' - 'Function NewFile(FileName As String, Contents As Byte()) As DocumentResult + + Function NewFile(FileName As String, Contents As Byte()) As DocumentResult - ' - 'Function UpdateFile(DocObject As DocumentObject, Contents As Byte()) As DocumentResult + + Function UpdateFile(DocObject As DocumentObject, Contents As Byte()) As DocumentResult - ' - 'Function GetFile(DocObject As DocumentObject) As DocumentResult + + Function GetFile(DocObject As DocumentObject) As DocumentResult - ' - 'Function DeleteFile(DocObject As DocumentObject) As Boolean + + Function DeleteFile(DocObject As DocumentObject) As Boolean - ' - 'Function GetDocumentByDocumentId(DocumentId As Int64) As DocumentResult + + Function GetDocumentByDocumentId(DocumentId As Int64) As DocumentResult - ' - 'Function GetDocumentByContainerId(ContainerId As String) As DocumentResult + + Function GetDocumentByContainerId(ContainerId As String) As DocumentResult #End Region #Region "Document (New)" diff --git a/Service.EDMIService/My Project/Resources.Designer.vb b/Service.EDMIService/My Project/Resources.Designer.vb index 51507018..3cd07b10 100644 --- a/Service.EDMIService/My Project/Resources.Designer.vb +++ b/Service.EDMIService/My Project/Resources.Designer.vb @@ -22,7 +22,7 @@ Namespace My.Resources ''' ''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. ''' - _ @@ -39,7 +39,7 @@ Namespace My.Resources Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager Get If Object.ReferenceEquals(resourceMan, Nothing) Then - Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("DigitalData.Services.IDBService.Resources", GetType(Resources).Assembly) + Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("DigitalData.Services.EDMIService.Resources", GetType(Resources).Assembly) resourceMan = temp End If Return resourceMan diff --git a/Service.EDMIService/My Project/Settings.Designer.vb b/Service.EDMIService/My Project/Settings.Designer.vb index eea38754..63f0e69c 100644 --- a/Service.EDMIService/My Project/Settings.Designer.vb +++ b/Service.EDMIService/My Project/Settings.Designer.vb @@ -15,7 +15,7 @@ Option Explicit On Namespace My _ Partial Friend NotInheritable Class MySettings Inherits Global.System.Configuration.ApplicationSettingsBase @@ -62,8 +62,8 @@ Namespace My Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _ Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _ Friend Module MySettingsProperty - - + + _ Friend ReadOnly Property Settings() As Global.DigitalData.Services.EDMIService.My.MySettings Get Return Global.DigitalData.Services.EDMIService.My.MySettings.Default diff --git a/Service.EDMIService/WindowsService.vb b/Service.EDMIService/WindowsService.vb index 6541fb46..8e616f5c 100644 --- a/Service.EDMIService/WindowsService.vb +++ b/Service.EDMIService/WindowsService.vb @@ -64,7 +64,7 @@ Public Class WindowsService _logger.Debug("Starting WCF ServiceHost...") - _serviceHost = New ServiceHost(GetType(IEDMIService)) + _serviceHost = New ServiceHost(GetType(EDMIService)) _serviceHost.Open() _logger.Debug("WCF ServiceHost started.") diff --git a/Service.EDMIService/packages.config b/Service.EDMIService/packages.config index da1b48cf..380efd84 100644 --- a/Service.EDMIService/packages.config +++ b/Service.EDMIService/packages.config @@ -1,5 +1,5 @@  - - + + \ No newline at end of file