diff --git a/EDMI.File.Test/PathTest.vb b/EDMI.File.Test/PathTest.vb index 4a05ec92..77752502 100644 --- a/EDMI.File.Test/PathTest.vb +++ b/EDMI.File.Test/PathTest.vb @@ -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\Archive\TestDocumentType\{oYear}\{oMonth}\{oDay}") + Assert.AreEqual(oPath.GetArchivePath("TestDocumentType"), $"EDMI\Archive\TestDocumentType\{oYear}\{oMonth}\{oDay}") End Sub End Class \ No newline at end of file diff --git a/EDMI.File/Archive.vb b/EDMI.File/Archive.vb index bf4b0541..ddaddebe 100644 --- a/EDMI.File/Archive.vb +++ b/EDMI.File/Archive.vb @@ -14,8 +14,8 @@ Public Class Archive ''' Sets a retention-period for a give file path by setting the file attributes LastAccessTime and ReadOnly ''' ''' - ''' - ''' + ''' If greater than 0, sets this plus the current date as LastAccessTime + ''' If true, sets ReadOnly Attribute Public Sub SetRetention(FilePath As String, RetentionTimeInDays As Integer, [ReadOnly] As Boolean) Try If RetentionTimeInDays > 0 Then diff --git a/EDMI.File/Path.vb b/EDMI.File/Path.vb index 70ddd7ec..e8b904b0 100644 --- a/EDMI.File/Path.vb +++ b/EDMI.File/Path.vb @@ -4,25 +4,27 @@ Imports System.IO Public Class Path Private ReadOnly _LogConfig As LogConfig Private ReadOnly _Logger As Logger + Private ReadOnly _BasePath As String - Public Const BASE_PATH_ACTIVE As String = "Active" - Public Const BASE_PATH_ARCHIVE As String = "Archive" - Public Const BASE_PATH_EDMI As String = "EDMI" + 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) + Public Sub New(LogConfig As LogConfig, DatastoreBasePath As String) _LogConfig = LogConfig _Logger = LogConfig.GetLogger() + _BasePath = DatastoreBasePath End Sub 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()) Return IO.Path.Combine(oPathParts.ToArray()) End Function 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()) Return IO.Path.Combine(oPathParts.ToArray()) diff --git a/Service.EDMIService/App.config b/Service.EDMIService/App.config index eed07e40..724b7a8a 100644 --- a/Service.EDMIService/App.config +++ b/Service.EDMIService/App.config @@ -21,12 +21,21 @@ + + + + + + + + + diff --git a/Service.EDMIService/AppConfig.vb b/Service.EDMIService/AppConfig.vb index f308f89b..3172d5d1 100644 --- a/Service.EDMIService/AppConfig.vb +++ b/Service.EDMIService/AppConfig.vb @@ -7,6 +7,7 @@ Public Class AppConfig Public Shared FirebirdPassword As String Public Shared ContainerPath As String Public Shared ContainerPassword As String + Public Shared DatastorePath As String Public Shared Sub Load() With ConfigurationManager.AppSettings @@ -16,6 +17,7 @@ Public Class AppConfig FirebirdPassword = .Item("FIREBIRD_DATABASE_PASS") ContainerPath = .Item("CONTAINER_PATH") ContainerPassword = .Item("CONTAINER_PASSWORD") + DatastorePath = .Item("DATASTORE_PATH") End With End Sub End Class diff --git a/Service.EDMIService/EDMIService.vb b/Service.EDMIService/EDMIService.vb index fa436f12..50accd7e 100644 --- a/Service.EDMIService/EDMIService.vb +++ b/Service.EDMIService/EDMIService.vb @@ -2,7 +2,7 @@ Imports DigitalData.Modules.Database Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Filesystem -Imports DigitalData.Services.EDMIService +Imports DigitalData.Modules Imports System.IO @@ -12,6 +12,8 @@ Public Class EDMIService Public Shared LogConfig As LogConfig Public Shared Database As Firebird Public Shared AppConfig As AppConfig + Public Shared EDMIPath As EDMI.File.Path + Public Shared EDMIArchive As EDMI.File.Archive Private ReadOnly _logger As Logger @@ -19,6 +21,7 @@ Public Class EDMIService Private _debug As Boolean = False Private _username As String + Public Sub New() Dim oOperationContext As OperationContext = OperationContext.Current Dim oInstanceContext As InstanceContext = oOperationContext.InstanceContext @@ -294,7 +297,8 @@ Public Class EDMIService #Region "Document" 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} Try @@ -305,17 +309,7 @@ Public Class EDMIService oStream.Close() End Using - Dim oAttributes = IO.File.GetAttributes(oFilePath) Or FileAttributes.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 + EDMIArchive.SetRetention(oFilePath, RetentionPeriod, [Readonly]) Return New DocumentResult2(oDocument) Catch ex As Exception diff --git a/Service.EDMIService/EDMIService.vbproj b/Service.EDMIService/EDMIService.vbproj index 29233af6..1c164a29 100644 --- a/Service.EDMIService/EDMIService.vbproj +++ b/Service.EDMIService/EDMIService.vbproj @@ -145,14 +145,14 @@ + + {1477032d-7a02-4c5f-b026-a7117da4bc6b} + EDMI.File + {EAF0EA75-5FA7-485D-89C7-B2D843B03A96} Database - - {5B1171DC-FFFE-4813-A20D-786AAE47B320} - EDMI.API - {991D0231-4623-496D-8BD0-9CA906029CBC} Filesystem diff --git a/Service.EDMIService/IEDMIService.vb b/Service.EDMIService/IEDMIService.vb index baf379cd..b5dcf705 100644 --- a/Service.EDMIService/IEDMIService.vb +++ b/Service.EDMIService/IEDMIService.vb @@ -52,7 +52,6 @@ Interface IEDMIService Function ImportFile(FileInfo As FileInfo, Contents As Byte(), [ReadOnly] As Boolean, RetentionTime As Integer) As DocumentResult2 #End Region - #Region "Index" Function NewFileIndex(DocObject As DocumentObject, Syskey As String, LanguageCode As String, Value As String) As IndexResult diff --git a/Service.EDMIService/SettingsModule.vb b/Service.EDMIService/SettingsModule.vb index a2149bf4..2e7ba8be 100644 --- a/Service.EDMIService/SettingsModule.vb +++ b/Service.EDMIService/SettingsModule.vb @@ -1,4 +1,4 @@ Module SettingsModule - Public Const SERVICE_NAME As String = "DDIDBSvc" - Public Const SERVICE_DISPLAY_NAME As String = "Digital Data IDB Service" + Public Const SERVICE_NAME As String = "DDEDMIService" + Public Const SERVICE_DISPLAY_NAME As String = "Digital Data EDMI Service" End Module diff --git a/Service.EDMIService/WindowsService.vb b/Service.EDMIService/WindowsService.vb index c13d81a3..6541fb46 100644 --- a/Service.EDMIService/WindowsService.vb +++ b/Service.EDMIService/WindowsService.vb @@ -2,6 +2,7 @@ Imports System.ServiceProcess Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Database +Imports DigitalData.Modules Public Class WindowsService Inherits ServiceBase @@ -14,6 +15,8 @@ Public Class WindowsService Private _db As Firebird Private _clientsConnected As Integer = 0 Private _config As AppConfig + Private _Path As EDMI.File.Path + Private _Archive As EDMI.File.Archive Public Sub New() ServiceName = SERVICE_NAME @@ -27,8 +30,9 @@ Public Class WindowsService Try AppConfig.Load() - _logConfig = New LogConfig(LogConfig.PathType.CustomPath, "E:\EDMService") - _logConfig.Debug = True + _logConfig = New LogConfig(LogConfig.PathType.CustomPath, "E:\EDMService") With { + .Debug = True + } _logger = _logConfig.GetLogger() @@ -45,9 +49,18 @@ Public Class WindowsService _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.LogConfig = _logConfig EDMIService.AppConfig = _config + EDMIService.EDMIArchive = _Archive + EDMIService.EDMIPath = _Path _logger.Debug("Starting WCF ServiceHost...")