add EDMI.File Module
This commit is contained in:
@@ -1,11 +1,39 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports System.IO
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Public Class Archive
|
||||
Private _LogConfig As LogConfig
|
||||
Private _Logger As Logger
|
||||
Private ReadOnly _LogConfig As LogConfig
|
||||
Private ReadOnly _Logger As Logger
|
||||
|
||||
Public Sub New(LogConfig As LogConfig)
|
||||
_LogConfig = LogConfig
|
||||
_Logger = LogConfig.GetLogger()
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Sets a retention-period for a give file path by setting the file attributes LastAccessTime and ReadOnly
|
||||
''' </summary>
|
||||
''' <param name="FilePath"></param>
|
||||
''' <param name="RetentionTimeInDays"></param>
|
||||
''' <param name="[ReadOnly]"></param>
|
||||
Public Sub SetRetention(FilePath As String, RetentionTimeInDays As Integer, [ReadOnly] As Boolean)
|
||||
Try
|
||||
If RetentionTimeInDays > 0 Then
|
||||
_Logger.Info("Setting LastAccessTime for file [{0}]", FilePath)
|
||||
IO.File.SetLastAccessTime(FilePath, Date.Now.AddDays(RetentionTimeInDays))
|
||||
End If
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
|
||||
Try
|
||||
If [ReadOnly] Then
|
||||
_Logger.Info("Setting ReadOnly Attribute for file [{0}]", FilePath)
|
||||
Dim oAttributes = IO.File.GetAttributes(FilePath) Or FileAttributes.ReadOnly
|
||||
IO.File.SetAttributes(FilePath, oAttributes)
|
||||
End If
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
@@ -89,6 +89,7 @@
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="Path.vb" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="My Project\Resources.resx">
|
||||
|
||||
41
EDMI.File/Path.vb
Normal file
41
EDMI.File/Path.vb
Normal file
@@ -0,0 +1,41 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports System.IO
|
||||
|
||||
Public Class Path
|
||||
Private ReadOnly _LogConfig As LogConfig
|
||||
Private ReadOnly _Logger As Logger
|
||||
|
||||
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 Sub New(LogConfig As LogConfig)
|
||||
_LogConfig = LogConfig
|
||||
_Logger = LogConfig.GetLogger()
|
||||
End Sub
|
||||
|
||||
Public Function GetActivePath(DocumentType As String)
|
||||
Dim oPathParts As New List(Of String) From {BASE_PATH_EDMI, BASE_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}
|
||||
oPathParts.AddRange(GetDatePath())
|
||||
|
||||
Return IO.Path.Combine(oPathParts.ToArray())
|
||||
End Function
|
||||
|
||||
Private Function GetDatePath() As List(Of String)
|
||||
Dim oDate = DateTime.Now
|
||||
Dim oResultList As New List(Of String) From {
|
||||
oDate.Year,
|
||||
oDate.Month.ToString.PadLeft(2, "0"),
|
||||
oDate.Day.ToString.PadLeft(2, "0")
|
||||
}
|
||||
|
||||
Return oResultList
|
||||
End Function
|
||||
End Class
|
||||
Reference in New Issue
Block a user