EDMIService: Use EDMI.File functions, add DatastorePath

This commit is contained in:
Jonathan Jenne 2020-04-06 16:04:01 +02:00
parent 0e13de63fb
commit eb527a7abb
10 changed files with 50 additions and 31 deletions

View File

@ -15,7 +15,7 @@ Imports DigitalData.Modules.EDMI
Assert.AreEqual(oPath.GetActivePath("TestDocumentType"), $"EDMI\Active\TestDocumentType\{oYear}\{oMonth}\{oDay}") Assert.AreEqual(oPath.GetActivePath("TestDocumentType"), $"EDMI\Active\TestDocumentType\{oYear}\{oMonth}\{oDay}")
Assert.AreEqual(oPath.GetActivePath("TestDocumentType"), $"EDMI\Archive\TestDocumentType\{oYear}\{oMonth}\{oDay}") Assert.AreEqual(oPath.GetArchivePath("TestDocumentType"), $"EDMI\Archive\TestDocumentType\{oYear}\{oMonth}\{oDay}")
End Sub End Sub
End Class End Class

View File

@ -14,8 +14,8 @@ Public Class Archive
''' Sets a retention-period for a give file path by setting the file attributes LastAccessTime and ReadOnly ''' Sets a retention-period for a give file path by setting the file attributes LastAccessTime and ReadOnly
''' </summary> ''' </summary>
''' <param name="FilePath"></param> ''' <param name="FilePath"></param>
''' <param name="RetentionTimeInDays"></param> ''' <param name="RetentionTimeInDays">If greater than 0, sets this plus the current date as LastAccessTime</param>
''' <param name="[ReadOnly]"></param> ''' <param name="[ReadOnly]">If true, sets ReadOnly Attribute</param>
Public Sub SetRetention(FilePath As String, RetentionTimeInDays As Integer, [ReadOnly] As Boolean) Public Sub SetRetention(FilePath As String, RetentionTimeInDays As Integer, [ReadOnly] As Boolean)
Try Try
If RetentionTimeInDays > 0 Then If RetentionTimeInDays > 0 Then

View File

@ -4,25 +4,27 @@ Imports System.IO
Public Class Path Public Class Path
Private ReadOnly _LogConfig As LogConfig Private ReadOnly _LogConfig As LogConfig
Private ReadOnly _Logger As Logger Private ReadOnly _Logger As Logger
Private ReadOnly _BasePath As String
Public Const BASE_PATH_ACTIVE As String = "Active" Public Const PATH_ACTIVE As String = "Active"
Public Const BASE_PATH_ARCHIVE As String = "Archive" Public Const PATH_ARCHIVE As String = "Archive"
Public Const BASE_PATH_EDMI As String = "EDMI" Public Const PATH_EDMI As String = "EDMI"
Public Sub New(LogConfig As LogConfig) Public Sub New(LogConfig As LogConfig, DatastoreBasePath As String)
_LogConfig = LogConfig _LogConfig = LogConfig
_Logger = LogConfig.GetLogger() _Logger = LogConfig.GetLogger()
_BasePath = DatastoreBasePath
End Sub End Sub
Public Function GetActivePath(DocumentType As String) Public Function GetActivePath(DocumentType As String)
Dim oPathParts As New List(Of String) From {BASE_PATH_EDMI, BASE_PATH_ACTIVE, DocumentType} Dim oPathParts As New List(Of String) From {_BasePath, PATH_EDMI, PATH_ACTIVE, DocumentType}
oPathParts.AddRange(GetDatePath()) oPathParts.AddRange(GetDatePath())
Return IO.Path.Combine(oPathParts.ToArray()) Return IO.Path.Combine(oPathParts.ToArray())
End Function End Function
Public Function GetArchivePath(DocumentType As String) Public Function GetArchivePath(DocumentType As String)
Dim oPathParts As New List(Of String) From {BASE_PATH_EDMI, BASE_PATH_ARCHIVE, DocumentType} Dim oPathParts As New List(Of String) From {_BasePath, PATH_EDMI, PATH_ARCHIVE, DocumentType}
oPathParts.AddRange(GetDatePath()) oPathParts.AddRange(GetDatePath())
Return IO.Path.Combine(oPathParts.ToArray()) Return IO.Path.Combine(oPathParts.ToArray())

View File

@ -21,12 +21,21 @@
<trace autoflush="true" /> <trace autoflush="true" />
</system.diagnostics> </system.diagnostics>
<appSettings> <appSettings>
<!-- FIREBIRD SETTINGS -->
<add key="FIREBIRD_DATASOURCE" value="" /> <add key="FIREBIRD_DATASOURCE" value="" />
<add key="FIREBIRD_DATABASE_NAME" value="" /> <add key="FIREBIRD_DATABASE_NAME" value="" />
<add key="FIREBIRD_DATABASE_USER" value="" /> <add key="FIREBIRD_DATABASE_USER" value="" />
<add key="FIREBIRD_DATABASE_PASS" value="" /> <add key="FIREBIRD_DATABASE_PASS" value="" />
<!-- END FIREBIRD SETTINGS -->
<!-- DATASTORE SETTINGS -->
<add key="DATASTORE_PATH" value=""/>
<!-- END DATASTORE SETTINGS -->
<!-- CONTAINER SETTINGS -->
<add key="CONTAINER_PATH" value="" /> <add key="CONTAINER_PATH" value="" />
<add key="CONTAINER_PASSWORD" value="" /> <add key="CONTAINER_PASSWORD" value="" />
<!-- END CONTAINER SETTINGS -->
</appSettings> </appSettings>
<system.serviceModel> <system.serviceModel>
<diagnostics wmiProviderEnabled="true"> <diagnostics wmiProviderEnabled="true">

View File

@ -7,6 +7,7 @@ Public Class AppConfig
Public Shared FirebirdPassword As String Public Shared FirebirdPassword As String
Public Shared ContainerPath As String Public Shared ContainerPath As String
Public Shared ContainerPassword As String Public Shared ContainerPassword As String
Public Shared DatastorePath As String
Public Shared Sub Load() Public Shared Sub Load()
With ConfigurationManager.AppSettings With ConfigurationManager.AppSettings
@ -16,6 +17,7 @@ Public Class AppConfig
FirebirdPassword = .Item("FIREBIRD_DATABASE_PASS") FirebirdPassword = .Item("FIREBIRD_DATABASE_PASS")
ContainerPath = .Item("CONTAINER_PATH") ContainerPath = .Item("CONTAINER_PATH")
ContainerPassword = .Item("CONTAINER_PASSWORD") ContainerPassword = .Item("CONTAINER_PASSWORD")
DatastorePath = .Item("DATASTORE_PATH")
End With End With
End Sub End Sub
End Class End Class

View File

@ -2,7 +2,7 @@
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.Services.EDMIService Imports DigitalData.Modules
Imports System.IO Imports System.IO
<ServiceBehavior(InstanceContextMode:=InstanceContextMode.PerSession)> <ServiceBehavior(InstanceContextMode:=InstanceContextMode.PerSession)>
@ -12,6 +12,8 @@ Public Class EDMIService
Public Shared LogConfig As LogConfig Public Shared LogConfig As LogConfig
Public Shared Database As Firebird Public Shared Database As Firebird
Public Shared AppConfig As AppConfig Public Shared AppConfig As AppConfig
Public Shared EDMIPath As EDMI.File.Path
Public Shared EDMIArchive As EDMI.File.Archive
Private ReadOnly _logger As Logger Private ReadOnly _logger As Logger
@ -19,6 +21,7 @@ Public Class EDMIService
Private _debug As Boolean = False Private _debug As Boolean = False
Private _username As String Private _username As String
Public Sub New() Public Sub New()
Dim oOperationContext As OperationContext = OperationContext.Current Dim oOperationContext As OperationContext = OperationContext.Current
Dim oInstanceContext As InstanceContext = oOperationContext.InstanceContext Dim oInstanceContext As InstanceContext = oOperationContext.InstanceContext
@ -294,7 +297,8 @@ Public Class EDMIService
#Region "Document" #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(FileInfo As FileInfo, Contents() As Byte, [Readonly] As Boolean, RetentionPeriod As Integer) As DocumentResult2 Implements IEDMIService.ImportFile
Dim oFilePath = Path.Combine(AppConfig.ContainerPath, FileInfo.Name) Dim oDocumentType As String = "DummyDocumentType"
Dim oFilePath = Path.Combine(EDMIPath.GetActivePath(oDocumentType), FileInfo.Name)
Dim oDocument = New DocumentResult2.DocumentObject() With {.FileName = FileInfo.Name} Dim oDocument = New DocumentResult2.DocumentObject() With {.FileName = FileInfo.Name}
Try Try
@ -305,17 +309,7 @@ Public Class EDMIService
oStream.Close() oStream.Close()
End Using End Using
Dim oAttributes = IO.File.GetAttributes(oFilePath) Or FileAttributes.ReadOnly EDMIArchive.SetRetention(oFilePath, RetentionPeriod, [Readonly])
If RetentionPeriod Then
_logger.Info("Setting LastAccessTime")
IO.File.SetLastAccessTime(oFilePath, Date.Now.AddYears(30))
End If
If [Readonly] Then
_logger.Info("Setting ReadOnly Attribute")
IO.File.SetAttributes(oFilePath, oAttributes)
End If
Return New DocumentResult2(oDocument) Return New DocumentResult2(oDocument)
Catch ex As Exception Catch ex As Exception

View File

@ -145,14 +145,14 @@
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\EDMI.File\EDMI.File.vbproj">
<Project>{1477032d-7a02-4c5f-b026-a7117da4bc6b}</Project>
<Name>EDMI.File</Name>
</ProjectReference>
<ProjectReference Include="..\Modules.Database\Database.vbproj"> <ProjectReference Include="..\Modules.Database\Database.vbproj">
<Project>{EAF0EA75-5FA7-485D-89C7-B2D843B03A96}</Project> <Project>{EAF0EA75-5FA7-485D-89C7-B2D843B03A96}</Project>
<Name>Database</Name> <Name>Database</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\..\Modules.EDMIAPI\EDMI.API.vbproj">
<Project>{5B1171DC-FFFE-4813-A20D-786AAE47B320}</Project>
<Name>EDMI.API</Name>
</ProjectReference>
<ProjectReference Include="..\Modules.Filesystem\Filesystem.vbproj"> <ProjectReference Include="..\Modules.Filesystem\Filesystem.vbproj">
<Project>{991D0231-4623-496D-8BD0-9CA906029CBC}</Project> <Project>{991D0231-4623-496D-8BD0-9CA906029CBC}</Project>
<Name>Filesystem</Name> <Name>Filesystem</Name>

View File

@ -52,7 +52,6 @@ Interface IEDMIService
Function ImportFile(FileInfo As FileInfo, Contents As Byte(), [ReadOnly] As Boolean, RetentionTime As Integer) As DocumentResult2 Function ImportFile(FileInfo As FileInfo, Contents As Byte(), [ReadOnly] As Boolean, RetentionTime As Integer) As DocumentResult2
#End Region #End Region
#Region "Index" #Region "Index"
<OperationContract> <OperationContract>
Function NewFileIndex(DocObject As DocumentObject, Syskey As String, LanguageCode As String, Value As String) As IndexResult Function NewFileIndex(DocObject As DocumentObject, Syskey As String, LanguageCode As String, Value As String) As IndexResult

View File

@ -1,4 +1,4 @@
Module SettingsModule Module SettingsModule
Public Const SERVICE_NAME As String = "DDIDBSvc" Public Const SERVICE_NAME As String = "DDEDMIService"
Public Const SERVICE_DISPLAY_NAME As String = "Digital Data IDB Service" Public Const SERVICE_DISPLAY_NAME As String = "Digital Data EDMI Service"
End Module End Module

View File

@ -2,6 +2,7 @@
Imports System.ServiceProcess Imports System.ServiceProcess
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Database Imports DigitalData.Modules.Database
Imports DigitalData.Modules
Public Class WindowsService Public Class WindowsService
Inherits ServiceBase Inherits ServiceBase
@ -14,6 +15,8 @@ Public Class WindowsService
Private _db As Firebird Private _db As Firebird
Private _clientsConnected As Integer = 0 Private _clientsConnected As Integer = 0
Private _config As AppConfig Private _config As AppConfig
Private _Path As EDMI.File.Path
Private _Archive As EDMI.File.Archive
Public Sub New() Public Sub New()
ServiceName = SERVICE_NAME ServiceName = SERVICE_NAME
@ -27,8 +30,9 @@ Public Class WindowsService
Try Try
AppConfig.Load() AppConfig.Load()
_logConfig = New LogConfig(LogConfig.PathType.CustomPath, "E:\EDMService") _logConfig = New LogConfig(LogConfig.PathType.CustomPath, "E:\EDMService") With {
_logConfig.Debug = True .Debug = True
}
_logger = _logConfig.GetLogger() _logger = _logConfig.GetLogger()
@ -45,9 +49,18 @@ Public Class WindowsService
_logger.Info("Database connection established.") _logger.Info("Database connection established.")
_logger.Debug("Initializing EDMI Functions")
_Path = New EDMI.File.Path(_logConfig, AppConfig.DatastorePath)
_Archive = New EDMI.File.Archive(_logConfig)
_logger.Debug("EDMI Functions initialized.")
EDMIService.Database = _db EDMIService.Database = _db
EDMIService.LogConfig = _logConfig EDMIService.LogConfig = _logConfig
EDMIService.AppConfig = _config EDMIService.AppConfig = _config
EDMIService.EDMIArchive = _Archive
EDMIService.EDMIPath = _Path
_logger.Debug("Starting WCF ServiceHost...") _logger.Debug("Starting WCF ServiceHost...")