diff --git a/EDMI.File.Test/EDMI.File.Test.vbproj b/EDMI.File.Test/EDMI.File.Test.vbproj new file mode 100644 index 00000000..68bf6ba4 --- /dev/null +++ b/EDMI.File.Test/EDMI.File.Test.vbproj @@ -0,0 +1,138 @@ + + + + + + Debug + AnyCPU + {16857A4E-2609-47E6-9C35-7669D64DD040} + Library + EDMI.File.Test + EDMI.File.Test + 512 + Windows + v4.7.2 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{F184B08F-C81C-45F6-A57F-5ABD9991F28F} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + true + full + true + true + bin\Debug\ + EDMI.File.Test.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + + + pdbonly + false + true + true + bin\Release\ + EDMI.File.Test.xml + 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 + + + On + + + Binary + + + Off + + + On + + + + ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + + + + + + + + + + + + + + + + + + + + + + + True + Application.myapp + + + True + True + Resources.resx + + + True + Settings.settings + True + + + + + VbMyResourcesResXFileCodeGenerator + Resources.Designer.vb + My.Resources + Designer + + + + + MyApplicationCodeGenerator + Application.Designer.vb + + + SettingsSingleFileGenerator + My + Settings.Designer.vb + + + + + + {1477032d-7a02-4c5f-b026-a7117da4bc6b} + EDMI.File + + + {903B2D7D-3B80-4BE9-8713-7447B704E1B0} + Logging + + + + + + + Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}". + + + + + + \ No newline at end of file diff --git a/EDMI.File.Test/My Project/Application.Designer.vb b/EDMI.File.Test/My Project/Application.Designer.vb new file mode 100644 index 00000000..88dd01c7 --- /dev/null +++ b/EDMI.File.Test/My Project/Application.Designer.vb @@ -0,0 +1,13 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + diff --git a/EDMI.File.Test/My Project/Application.myapp b/EDMI.File.Test/My Project/Application.myapp new file mode 100644 index 00000000..758895de --- /dev/null +++ b/EDMI.File.Test/My Project/Application.myapp @@ -0,0 +1,10 @@ + + + false + false + 0 + true + 0 + 1 + true + diff --git a/EDMI.File.Test/My Project/AssemblyInfo.vb b/EDMI.File.Test/My Project/AssemblyInfo.vb new file mode 100644 index 00000000..d81985a1 --- /dev/null +++ b/EDMI.File.Test/My Project/AssemblyInfo.vb @@ -0,0 +1,18 @@ +Imports System +Imports System.Reflection +Imports System.Runtime.InteropServices + + + + + + + + + + + + +' + + diff --git a/EDMI.File.Test/My Project/Resources.Designer.vb b/EDMI.File.Test/My Project/Resources.Designer.vb new file mode 100644 index 00000000..3a5490d9 --- /dev/null +++ b/EDMI.File.Test/My Project/Resources.Designer.vb @@ -0,0 +1,62 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + + +Namespace My.Resources + + 'This class was auto-generated by the StronglyTypedResourceBuilder + 'class via a tool like ResGen or Visual Studio. + 'To add or remove a member, edit your .ResX file then rerun ResGen + 'with the /str option, or rebuild your VS project. + ''' + ''' A strongly-typed resource class, for looking up localized strings, etc. + ''' + _ + Friend Module Resources + + Private resourceMan As Global.System.Resources.ResourceManager + + Private resourceCulture As Global.System.Globalization.CultureInfo + + ''' + ''' Returns the cached ResourceManager instance used by this class. + ''' + _ + Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager + Get + If Object.ReferenceEquals(resourceMan, Nothing) Then + Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("EDMI.File.Test.Resources", GetType(Resources).Assembly) + resourceMan = temp + End If + Return resourceMan + End Get + End Property + + ''' + ''' Overrides the current thread's CurrentUICulture property for all + ''' resource lookups using this strongly typed resource class. + ''' + _ + Friend Property Culture() As Global.System.Globalization.CultureInfo + Get + Return resourceCulture + End Get + Set(ByVal value As Global.System.Globalization.CultureInfo) + resourceCulture = value + End Set + End Property + End Module +End Namespace diff --git a/EDMI.File.Test/My Project/Resources.resx b/EDMI.File.Test/My Project/Resources.resx new file mode 100644 index 00000000..af7dbebb --- /dev/null +++ b/EDMI.File.Test/My Project/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/EDMI.File.Test/My Project/Settings.Designer.vb b/EDMI.File.Test/My Project/Settings.Designer.vb new file mode 100644 index 00000000..1157b717 --- /dev/null +++ b/EDMI.File.Test/My Project/Settings.Designer.vb @@ -0,0 +1,73 @@ +'------------------------------------------------------------------------------ +' +' This code was generated by a tool. +' Runtime Version:4.0.30319.42000 +' +' Changes to this file may cause incorrect behavior and will be lost if +' the code is regenerated. +' +'------------------------------------------------------------------------------ + +Option Strict On +Option Explicit On + + +Namespace My + + _ + Partial Friend NotInheritable Class MySettings + Inherits Global.System.Configuration.ApplicationSettingsBase + + Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings) + +#Region "My.Settings Auto-Save Functionality" +#If _MyType = "WindowsForms" Then + Private Shared addedHandler As Boolean + + Private Shared addedHandlerLockObject As New Object + + _ + Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) + If My.Application.SaveMySettingsOnExit Then + My.Settings.Save() + End If + End Sub +#End If +#End Region + + Public Shared ReadOnly Property [Default]() As MySettings + Get + +#If _MyType = "WindowsForms" Then + If Not addedHandler Then + SyncLock addedHandlerLockObject + If Not addedHandler Then + AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings + addedHandler = True + End If + End SyncLock + End If +#End If + Return defaultInstance + End Get + End Property + End Class +End Namespace + +Namespace My + + _ + Friend Module MySettingsProperty + + _ + Friend ReadOnly Property Settings() As Global.EDMI.File.Test.My.MySettings + Get + Return Global.EDMI.File.Test.My.MySettings.Default + End Get + End Property + End Module +End Namespace diff --git a/EDMI.File.Test/My Project/Settings.settings b/EDMI.File.Test/My Project/Settings.settings new file mode 100644 index 00000000..85b890b3 --- /dev/null +++ b/EDMI.File.Test/My Project/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/EDMI.File.Test/PathTest.vb b/EDMI.File.Test/PathTest.vb new file mode 100644 index 00000000..4a05ec92 --- /dev/null +++ b/EDMI.File.Test/PathTest.vb @@ -0,0 +1,21 @@ +Imports System.Text +Imports DigitalData.Modules.Logging +Imports Microsoft.VisualStudio.TestTools.UnitTesting +Imports DigitalData.Modules.EDMI + + Public Class PathTest + + Public Sub TestMethod1() + Dim oLogConfig As New LogConfig(LogConfig.PathType.Temp) + Dim oPath As New DigitalData.Modules.EDMI.File.Path(oLogConfig) + Dim oNow As DateTime = DateTime.Now + Dim oYear = oNow.Year + Dim oMonth = oNow.Month.ToString.PadLeft(2, "0") + Dim oDay = oNow.Day.ToString.PadLeft(2, "0") + + + Assert.AreEqual(oPath.GetActivePath("TestDocumentType"), $"EDMI\Active\TestDocumentType\{oYear}\{oMonth}\{oDay}") + Assert.AreEqual(oPath.GetActivePath("TestDocumentType"), $"EDMI\Archive\TestDocumentType\{oYear}\{oMonth}\{oDay}") + End Sub + +End Class \ No newline at end of file diff --git a/EDMI.File.Test/packages.config b/EDMI.File.Test/packages.config new file mode 100644 index 00000000..2f7c5a18 --- /dev/null +++ b/EDMI.File.Test/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/EDMI.File/Archive.vb b/EDMI.File/Archive.vb index ff632038..bf4b0541 100644 --- a/EDMI.File/Archive.vb +++ b/EDMI.File/Archive.vb @@ -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 + + ''' + ''' Sets a retention-period for a give file path by setting the file attributes LastAccessTime and ReadOnly + ''' + ''' + ''' + ''' + 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 diff --git a/EDMI.File/EDMI.File.vbproj b/EDMI.File/EDMI.File.vbproj index b20b8189..10093658 100644 --- a/EDMI.File/EDMI.File.vbproj +++ b/EDMI.File/EDMI.File.vbproj @@ -89,6 +89,7 @@ Settings.settings True + diff --git a/EDMI.File/Path.vb b/EDMI.File/Path.vb new file mode 100644 index 00000000..70ddd7ec --- /dev/null +++ b/EDMI.File/Path.vb @@ -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