add EDMI.File Module

This commit is contained in:
Jonathan Jenne
2020-04-06 15:17:18 +02:00
parent 7de03b4889
commit 77b6658988
13 changed files with 537 additions and 3 deletions

View File

@@ -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