40 lines
1.5 KiB
VB.net
40 lines
1.5 KiB
VB.net
Imports System.IO
|
|
Imports DigitalData.Modules.Logging
|
|
|
|
Public Class Archive
|
|
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">If greater than 0, sets this plus the current date as LastAccessTime</param>
|
|
''' <param name="[ReadOnly]">If true, sets ReadOnly Attribute</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
|