Baget GDPicture
This commit is contained in:
parent
8c829d490f
commit
d4ce8e2891
487
Filesystem/File.vb
Normal file
487
Filesystem/File.vb
Normal file
@ -0,0 +1,487 @@
|
|||||||
|
Imports System.IO
|
||||||
|
Imports System.Security.Cryptography
|
||||||
|
Imports System.Text
|
||||||
|
Imports System.Text.RegularExpressions
|
||||||
|
Imports DigitalData.Modules.Logging
|
||||||
|
|
||||||
|
''' <module>File</module>
|
||||||
|
''' <version>0.0.0.1</version>
|
||||||
|
''' <date>11.10.2018</date>
|
||||||
|
''' <summary>
|
||||||
|
''' Module that provides variouse File operations
|
||||||
|
''' </summary>
|
||||||
|
''' <dependencies>
|
||||||
|
''' NLog, >= 4.5.8
|
||||||
|
''' </dependencies>
|
||||||
|
''' <params>
|
||||||
|
''' LogConfig, DigitalData.Module.Logging.LogConfig
|
||||||
|
''' A LogConfig object
|
||||||
|
''' </params>
|
||||||
|
''' <props>
|
||||||
|
''' </props>
|
||||||
|
''' <example>
|
||||||
|
''' </example>
|
||||||
|
''' <remarks>
|
||||||
|
''' </remarks>
|
||||||
|
Public Class File
|
||||||
|
Private ReadOnly _Logger As Logger
|
||||||
|
Private ReadOnly _LogConfig As LogConfig
|
||||||
|
|
||||||
|
Private ReadOnly _invalidFilenameChars As String
|
||||||
|
Private ReadOnly _invalidPathChars As String
|
||||||
|
|
||||||
|
Private Const REGEX_CLEAN_FILENAME As String = "[\\/:""<>|\b\0\r\n\t]"
|
||||||
|
Private Const REGEX_CLEAN_PATH As String = "[""<>|\b\0\r\n\t]"
|
||||||
|
|
||||||
|
' The limit enforced by windows for filenpaths is 260,
|
||||||
|
' so we use a slightly smaller number to have some Error margin.
|
||||||
|
'
|
||||||
|
' Source: https://docs.microsoft.com/de-de/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN#maximum-path-length-limitation
|
||||||
|
Private Const MAX_FILE_PATH_LENGTH = 250
|
||||||
|
|
||||||
|
Private Const FILE_NAME_ACCESS_TEST = "accessTest.txt"
|
||||||
|
|
||||||
|
Public Sub New(LogConfig As LogConfig)
|
||||||
|
_LogConfig = LogConfig
|
||||||
|
_Logger = LogConfig.GetLogger()
|
||||||
|
|
||||||
|
_invalidFilenameChars = String.Join("", Path.GetInvalidFileNameChars())
|
||||||
|
_invalidPathChars = String.Join("", Path.GetInvalidPathChars())
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Function GetCleanFilename(FileName As String) As String
|
||||||
|
_Logger.Debug("Filename before cleaning: [{0}]", FileName)
|
||||||
|
|
||||||
|
Dim oCleanName As String = FileName
|
||||||
|
oCleanName = Regex.Replace(oCleanName, _invalidFilenameChars, String.Empty)
|
||||||
|
oCleanName = Regex.Replace(oCleanName, REGEX_CLEAN_FILENAME, String.Empty, RegexOptions.Singleline)
|
||||||
|
oCleanName = Regex.Replace(oCleanName, "\s{2,}", " ")
|
||||||
|
oCleanName = Regex.Replace(oCleanName, "\.{2,}", ".")
|
||||||
|
|
||||||
|
_Logger.Debug("Filename after cleaning: [{0}]", oCleanName)
|
||||||
|
|
||||||
|
Return oCleanName
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function GetCleanPath(FilePath As String) As String
|
||||||
|
_Logger.Debug("Path before cleaning: [{0}]", FilePath)
|
||||||
|
|
||||||
|
Dim oCleanName As String = FilePath
|
||||||
|
oCleanName = Regex.Replace(oCleanName, _invalidPathChars, String.Empty)
|
||||||
|
oCleanName = Regex.Replace(oCleanName, REGEX_CLEAN_PATH, String.Empty, RegexOptions.Singleline)
|
||||||
|
|
||||||
|
_Logger.Debug("Path after cleaning: [{0}]", oCleanName)
|
||||||
|
|
||||||
|
Return oCleanName
|
||||||
|
End Function
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Reads the file at `FilePath` and computes a SHA256 Hash from its contents
|
||||||
|
''' </summary>
|
||||||
|
''' <param name="FilePath"></param>
|
||||||
|
''' <returns></returns>
|
||||||
|
Public Function GetChecksum(FilePath As String) As String
|
||||||
|
Try
|
||||||
|
Using oFileStream = IO.File.OpenRead(FilePath)
|
||||||
|
Using oStream As New BufferedStream(oFileStream, 1200000)
|
||||||
|
Dim oChecksum() As Byte = SHA256.Create.ComputeHash(oStream)
|
||||||
|
Return FormatHash(oChecksum)
|
||||||
|
End Using
|
||||||
|
End Using
|
||||||
|
Catch ex As Exception
|
||||||
|
_Logger.Error(ex)
|
||||||
|
Return Nothing
|
||||||
|
End Try
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function GetChecksumFromString(pStringToCheck As String) As String
|
||||||
|
Dim oBytes() As Byte = Encoding.UTF8.GetBytes(pStringToCheck)
|
||||||
|
Dim oChecksum() As Byte = SHA256.Create.ComputeHash(oBytes)
|
||||||
|
Return FormatHash(oChecksum)
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Private Function FormatHash(pChecksum)
|
||||||
|
Return BitConverter.
|
||||||
|
ToString(pChecksum).
|
||||||
|
Replace("-", String.Empty)
|
||||||
|
End Function
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Adds file version string to given filename `Destination` if that file already exists.
|
||||||
|
''' </summary>
|
||||||
|
''' <param name="Destination"></param>
|
||||||
|
''' <returns></returns>
|
||||||
|
Public Function GetVersionedFilename(Destination As String) As String
|
||||||
|
Try
|
||||||
|
Dim oFileName As String = Destination
|
||||||
|
Dim oFinalFileName = oFileName
|
||||||
|
|
||||||
|
Dim oDestinationDir = Path.GetDirectoryName(oFileName)
|
||||||
|
Dim oExtension = Path.GetExtension(oFileName)
|
||||||
|
|
||||||
|
Dim oVersionSeparator As Char = "~"c
|
||||||
|
|
||||||
|
' Split Filename without extension at version separator to:
|
||||||
|
' - Check if file is already versioned
|
||||||
|
' - Get the file version of an already versioned file
|
||||||
|
'
|
||||||
|
' Example:
|
||||||
|
' test1.pdf --> test1 --> ['test1'] --> no fileversion
|
||||||
|
' test1~2.pdf --> test1~2 --> ['test1', '2'] --> version 2
|
||||||
|
' test1~12345~2.pdf --> test1~12345~2 --> ['test1', '12345', '2'] --> still version 2
|
||||||
|
'Dim oFileNameWithoutExtension = Path.GetFileNameWithoutExtension(oFileName)
|
||||||
|
'Dim oSplitFilename = oFileNameWithoutExtension.Split(oVersionSeparator).ToList()
|
||||||
|
|
||||||
|
' if file is already versioned, extract file version
|
||||||
|
' else just use the filename and set version to 1
|
||||||
|
'If oSplitFilename.Count > 1 Then
|
||||||
|
' Dim oVersion As Integer = 1
|
||||||
|
' Try
|
||||||
|
' oVersion = Integer.Parse(oSplitFilename.Last())
|
||||||
|
' oFileNameWithoutExtension = String.Join("", oSplitFilename.Take(oSplitFilename.Count - 1))
|
||||||
|
' Catch ex As Exception
|
||||||
|
' ' oFilenameWithoutExtension does NOT change
|
||||||
|
' oFileNameWithoutExtension = oFileNameWithoutExtension
|
||||||
|
' Finally
|
||||||
|
' oFileVersion = oVersion
|
||||||
|
' End Try
|
||||||
|
'Else
|
||||||
|
' oFileVersion = 1
|
||||||
|
'End If
|
||||||
|
|
||||||
|
Dim oFileNameWithoutExtension = Path.GetFileNameWithoutExtension(oFileName)
|
||||||
|
Dim oSplitResult = GetVersionedString(oFileNameWithoutExtension, oVersionSeparator)
|
||||||
|
|
||||||
|
oFileNameWithoutExtension = oSplitResult.Item1
|
||||||
|
Dim oFileVersion = oSplitResult.Item2
|
||||||
|
|
||||||
|
' Shorten the filename (only filename, without extension or version)
|
||||||
|
' by cutting the length in half. This should work no matter how long the path and/or filename are.
|
||||||
|
If oFileName.Length > MAX_FILE_PATH_LENGTH Then
|
||||||
|
_Logger.Info("Filename is too long. Filename will be cut to prevent further errors.")
|
||||||
|
_Logger.Info("Original Filename is: {0}", oFileNameWithoutExtension)
|
||||||
|
Dim oNewLength As Integer = Math.Round(oFileNameWithoutExtension.Length / 2)
|
||||||
|
Dim oNewFileNameWithoutExtension = oFileNameWithoutExtension.Substring(0, oNewLength)
|
||||||
|
_Logger.Info("New Filename will be: {0}", oNewFileNameWithoutExtension)
|
||||||
|
|
||||||
|
oFileNameWithoutExtension = oNewFileNameWithoutExtension
|
||||||
|
End If
|
||||||
|
|
||||||
|
' while file exists, increment version
|
||||||
|
Do
|
||||||
|
oFinalFileName = Path.Combine(oDestinationDir, GetFilenameWithVersion(oFileNameWithoutExtension, oVersionSeparator, oFileVersion, oExtension))
|
||||||
|
_Logger.Debug("Intermediate Filename is {0}", oFinalFileName)
|
||||||
|
_Logger.Debug("File version: {0}", oFileVersion)
|
||||||
|
oFileVersion += 1
|
||||||
|
Loop While (IO.File.Exists(oFinalFileName))
|
||||||
|
|
||||||
|
_Logger.Debug("Final Filename is {0}", oFinalFileName)
|
||||||
|
|
||||||
|
Return oFinalFileName
|
||||||
|
Catch ex As Exception
|
||||||
|
_Logger.Warn("Filename {0} could not be versioned. Original filename will be returned!", Destination)
|
||||||
|
_Logger.Error(ex)
|
||||||
|
Return Destination
|
||||||
|
End Try
|
||||||
|
End Function
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Split String at version separator to:
|
||||||
|
''' check if string is already versioned,
|
||||||
|
''' get the string version of an already versioned string
|
||||||
|
''' </summary>
|
||||||
|
''' <example>
|
||||||
|
''' Examples:
|
||||||
|
''' test1.pdf --> test1 --> ['test1'] --> no fileversion
|
||||||
|
''' test1~2.pdf --> test1~2 --> ['test1', '2'] --> version 2
|
||||||
|
''' test1~12345~2.pdf --> test1~12345~2 --> ['test1', '12345', '2'] --> still version 2
|
||||||
|
''' somestring~3 --> somestring~3 --> ['somestring', '3'] --> version 3
|
||||||
|
''' </example>
|
||||||
|
''' <param name="pString">The string to versioned</param>
|
||||||
|
''' <param name="pSeparator">The character to split at</param>
|
||||||
|
''' <returns>Tuple of string and version</returns>
|
||||||
|
Public Function GetVersionedString(pString As String, pSeparator As Char) As Tuple(Of String, Integer)
|
||||||
|
Dim oSplitString = pString.Split(pSeparator).ToList()
|
||||||
|
Dim oStringVersion As Integer
|
||||||
|
|
||||||
|
' if string is already versioned, extract string version
|
||||||
|
' else just use the string and set version to 1
|
||||||
|
If oSplitString.Count > 1 Then
|
||||||
|
Dim oVersion As Integer = 1
|
||||||
|
Try
|
||||||
|
oVersion = Integer.Parse(oSplitString.Last())
|
||||||
|
pString = String.Join("", oSplitString.Take(oSplitString.Count - 1))
|
||||||
|
Catch ex As Exception
|
||||||
|
' pString does NOT change
|
||||||
|
pString = pString
|
||||||
|
Finally
|
||||||
|
oStringVersion = oVersion
|
||||||
|
End Try
|
||||||
|
Else
|
||||||
|
oStringVersion = 1
|
||||||
|
End If
|
||||||
|
|
||||||
|
Return New Tuple(Of String, Integer)(pString, oStringVersion)
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function GetAppDataPath(CompanyName As String, ProductName As String)
|
||||||
|
Dim oLocalAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
|
||||||
|
Return Path.Combine(oLocalAppData, CompanyName, ProductName)
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Private Function GetFilenameWithVersion(FileNameWithoutExtension As String, VersionSeparator As Char, FileVersion As Integer, Extension As String) As String
|
||||||
|
If FileVersion <= 1 Then
|
||||||
|
Return $"{FileNameWithoutExtension}{Extension}"
|
||||||
|
Else
|
||||||
|
Return $"{FileNameWithoutExtension}{VersionSeparator}{FileVersion}{Extension}"
|
||||||
|
End If
|
||||||
|
End Function
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Removes files in a directory filtered by filename, extension and last write date
|
||||||
|
''' </summary>
|
||||||
|
''' <param name="Path">The directory in which files will be deleted</param>
|
||||||
|
''' <param name="FileKeepTime">Only delete files which are older than x days. Must be between 0 and 1000 days.</param>
|
||||||
|
''' <param name="FileBaseName">A filename filter which will be checked</param>
|
||||||
|
''' <param name="FileExtension">A file extension which will be checked</param>
|
||||||
|
''' <param name="ContinueOnError">Should the function continue with deleting when a file could not be deleted?</param>
|
||||||
|
''' <returns>True if all files were deleted or if no files were deleted, otherwise false</returns>
|
||||||
|
Public Function RemoveFiles(Path As String, FileKeepTime As Integer, FileBaseName As String, Optional FileExtension As String = "log", Optional ContinueOnError As Boolean = True) As Boolean
|
||||||
|
If Not TestPathIsDirectory(Path) Then
|
||||||
|
Throw New ArgumentException($"Path {Path} is not a directory!")
|
||||||
|
End If
|
||||||
|
|
||||||
|
If Not Directory.Exists(Path) Then
|
||||||
|
Throw New DirectoryNotFoundException($"Path {Path} does not exist!")
|
||||||
|
End If
|
||||||
|
|
||||||
|
If FileKeepTime < 0 Or FileKeepTime > 1000 Then
|
||||||
|
Throw New ArgumentOutOfRangeException("FileKeepTime must be an integer between 0 and 1000!")
|
||||||
|
End If
|
||||||
|
|
||||||
|
Dim oUnableToDeleteCounter = 0
|
||||||
|
Dim oDirectory As New DirectoryInfo(Path)
|
||||||
|
Dim oDateLimit As DateTime = DateTime.Now.AddDays(FileKeepTime)
|
||||||
|
Dim oFiles As List(Of FileInfo) = oDirectory.
|
||||||
|
EnumerateFiles($"*{FileBaseName}*").
|
||||||
|
Where(Function(oFileInfo As FileInfo)
|
||||||
|
Return oFileInfo.Extension = FileExtension And oFileInfo.LastWriteTime < oDateLimit
|
||||||
|
End Function).
|
||||||
|
ToList()
|
||||||
|
|
||||||
|
If oFiles.Count = 0 Then
|
||||||
|
_Logger.Debug("No files found that match the criterias.")
|
||||||
|
Return True
|
||||||
|
End If
|
||||||
|
|
||||||
|
_Logger.Debug("Deleting old files (Found {0}).", oFiles.Count)
|
||||||
|
|
||||||
|
For Each oFile As FileInfo In oFiles
|
||||||
|
Try
|
||||||
|
oFile.Delete()
|
||||||
|
Catch ex As Exception
|
||||||
|
If ContinueOnError = False Then
|
||||||
|
_Logger.Warn("Deleting files was aborted at file {0}.", oFile.FullName)
|
||||||
|
Return False
|
||||||
|
End If
|
||||||
|
oUnableToDeleteCounter = oUnableToDeleteCounter + 1
|
||||||
|
_Logger.Warn("File {0} could not be deleted!")
|
||||||
|
End Try
|
||||||
|
Next
|
||||||
|
|
||||||
|
If oUnableToDeleteCounter > 0 Then
|
||||||
|
_Logger.Debug("Old files partially removed. {0} files could not be removed.", oUnableToDeleteCounter)
|
||||||
|
Else
|
||||||
|
_Logger.Debug("Old files removed.")
|
||||||
|
End If
|
||||||
|
|
||||||
|
Return True
|
||||||
|
End Function
|
||||||
|
|
||||||
|
<DebuggerStepThrough>
|
||||||
|
Public Sub MoveTo(FilePath As String, Directory As String)
|
||||||
|
Dim oFileInfo As New FileInfo(FilePath)
|
||||||
|
IO.File.Move(FilePath, Path.Combine(Directory, oFileInfo.Name))
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
<DebuggerStepThrough>
|
||||||
|
Public Sub MoveTo(FilePath As String, NewFileName As String, Directory As String)
|
||||||
|
IO.File.Move(FilePath, Path.Combine(Directory, NewFileName))
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Copied from https://docs.microsoft.com/en-us/dotnet/standard/io/how-to-copy-directories
|
||||||
|
''' </summary>
|
||||||
|
''' <param name="SourceDirName"></param>
|
||||||
|
''' <param name="DestDirName"></param>
|
||||||
|
''' <param name="CopySubDirs"></param>
|
||||||
|
Public Sub CopyDirectory(ByVal SourceDirName As String, ByVal DestDirName As String, ByVal CopySubDirs As Boolean)
|
||||||
|
Dim oDirectory As DirectoryInfo = New DirectoryInfo(SourceDirName)
|
||||||
|
|
||||||
|
If Not oDirectory.Exists Then
|
||||||
|
Throw New DirectoryNotFoundException("Source directory does not exist or could not be found: " & SourceDirName)
|
||||||
|
End If
|
||||||
|
|
||||||
|
Dim oDirectories As DirectoryInfo() = oDirectory.GetDirectories()
|
||||||
|
Directory.CreateDirectory(DestDirName)
|
||||||
|
Dim oFiles As FileInfo() = oDirectory.GetFiles()
|
||||||
|
|
||||||
|
For Each oFile As FileInfo In oFiles
|
||||||
|
Dim tempPath As String = Path.Combine(DestDirName, oFile.Name)
|
||||||
|
oFile.CopyTo(tempPath, False)
|
||||||
|
Next
|
||||||
|
|
||||||
|
If CopySubDirs Then
|
||||||
|
For Each oSubDirectory As DirectoryInfo In oDirectories
|
||||||
|
Dim oTempPath As String = Path.Combine(DestDirName, oSubDirectory.Name)
|
||||||
|
CopyDirectory(oSubDirectory.FullName, oTempPath, CopySubDirs)
|
||||||
|
Next
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Tries to create a directory and returns its path.
|
||||||
|
''' Returns a temp path if `DirectoryPath` can not be created or written to.
|
||||||
|
''' </summary>
|
||||||
|
''' <param name="DirectoryPath">The directory to create</param>
|
||||||
|
''' <param name="TestWriteAccess">Should a write access test be performed?</param>
|
||||||
|
''' <returns>The used path</returns>
|
||||||
|
Public Function CreateDirectory(DirectoryPath As String, Optional TestWriteAccess As Boolean = True) As String
|
||||||
|
Dim oFinalPath As String
|
||||||
|
If Directory.Exists(DirectoryPath) Then
|
||||||
|
_Logger.Debug("Directory {0} already exists. Skipping.", DirectoryPath)
|
||||||
|
oFinalPath = DirectoryPath
|
||||||
|
Else
|
||||||
|
Try
|
||||||
|
Directory.CreateDirectory(DirectoryPath)
|
||||||
|
oFinalPath = DirectoryPath
|
||||||
|
Catch ex As Exception
|
||||||
|
_Logger.Error(ex)
|
||||||
|
_Logger.Warn("Directory {0} could not be created. Temp path will be used instead.", DirectoryPath)
|
||||||
|
oFinalPath = Path.GetTempPath()
|
||||||
|
End Try
|
||||||
|
End If
|
||||||
|
|
||||||
|
If TestWriteAccess AndAlso Not TestPathIsWritable(DirectoryPath) Then
|
||||||
|
_Logger.Warn("Directory {0} is not writable. Temp path will be used instead.", DirectoryPath)
|
||||||
|
oFinalPath = Path.GetTempPath()
|
||||||
|
Else
|
||||||
|
oFinalPath = DirectoryPath
|
||||||
|
End If
|
||||||
|
|
||||||
|
_Logger.Debug("Using path {0}", oFinalPath)
|
||||||
|
|
||||||
|
Return oFinalPath
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function TestPathIsWritable(DirectoryPath As String) As Boolean
|
||||||
|
Try
|
||||||
|
Dim fileAccessPath = Path.Combine(DirectoryPath, FILE_NAME_ACCESS_TEST)
|
||||||
|
Using fs As FileStream = IO.File.Create(fileAccessPath)
|
||||||
|
fs.WriteByte(0)
|
||||||
|
End Using
|
||||||
|
|
||||||
|
IO.File.Delete(fileAccessPath)
|
||||||
|
Return True
|
||||||
|
Catch ex As Exception
|
||||||
|
Return False
|
||||||
|
End Try
|
||||||
|
End Function
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Checks if a file is locked, ie. in use by another process.
|
||||||
|
''' </summary>
|
||||||
|
''' <remarks>
|
||||||
|
''' https://docs.microsoft.com/en-us/dotnet/standard/io/handling-io-errors
|
||||||
|
''' https://stackoverflow.com/questions/876473/is-there-a-way-to-check-if-a-file-is-in-use
|
||||||
|
''' </remarks>
|
||||||
|
Public Function TestFileIsLocked(pFilePath As String) As Boolean
|
||||||
|
Try
|
||||||
|
Using stream As FileStream = IO.File.Open(pFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None)
|
||||||
|
stream.Close()
|
||||||
|
End Using
|
||||||
|
Catch ex As Exception When ((ex.HResult And &HFFFF) = 32)
|
||||||
|
Return True
|
||||||
|
Catch ex As Exception
|
||||||
|
Return True
|
||||||
|
End Try
|
||||||
|
|
||||||
|
Return False
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function TestPathIsDirectory(Path As String) As Boolean
|
||||||
|
If Not Directory.Exists(Path) Then
|
||||||
|
Return False
|
||||||
|
End If
|
||||||
|
|
||||||
|
Dim oIsDirectory As Boolean = (System.IO.File.GetAttributes(Path) And FileAttributes.Directory) = FileAttributes.Directory
|
||||||
|
Return oIsDirectory
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function GetDateDirectory(pBaseDirectory As String, pDate As Date) As String
|
||||||
|
Dim oDateDirectory = GetDateString(pDate)
|
||||||
|
Dim oFinalDirectory As String = IO.Path.Combine(pBaseDirectory, oDateDirectory)
|
||||||
|
Return oFinalDirectory
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function GetDateDirectory(pBaseDirectory As String) As String
|
||||||
|
Return GetDateDirectory(pBaseDirectory, Now)
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function CreateDateDirectory(pBaseDirectory As String, pDate As Date) As String
|
||||||
|
Dim oDateDirectory = GetDateString(pDate)
|
||||||
|
Dim oFinalDirectory As String = IO.Path.Combine(pBaseDirectory, oDateDirectory)
|
||||||
|
|
||||||
|
If IO.Directory.Exists(oFinalDirectory) = False Then
|
||||||
|
_Logger.Debug("Path does not exist, creating: [{0}]", oFinalDirectory)
|
||||||
|
Try
|
||||||
|
Directory.CreateDirectory(oFinalDirectory)
|
||||||
|
_Logger.Debug("Created folder [{0}]", oFinalDirectory)
|
||||||
|
Catch ex As Exception
|
||||||
|
_Logger.Warn("Final path [{0}] could not be created!", oFinalDirectory)
|
||||||
|
_Logger.Error(ex)
|
||||||
|
End Try
|
||||||
|
End If
|
||||||
|
|
||||||
|
Return oFinalDirectory
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function CreateDateDirectory(pBaseDirectory As String) As String
|
||||||
|
Return CreateDateDirectory(pBaseDirectory, Now)
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function GetDateString() As String
|
||||||
|
Return $"{Now:yyyy\\MM\\dd}"
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function GetDateString(pDate As Date) As String
|
||||||
|
Return $"{pDate:yyyy\\MM\\dd}"
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function GetDateTimeString() As String
|
||||||
|
Return $"{Now:yyyy-MM-dd_hh-mm-ffff}"
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function GetDateTimeString(pDate As Date) As String
|
||||||
|
Return $"{pDate:yyyy-MM-dd_hh-mm-ffff}"
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function GetFilenameWithSuffix(pFilePath As String, pSuffix As String)
|
||||||
|
Dim oFileInfo = New IO.FileInfo(pFilePath)
|
||||||
|
Return GetFilenameWithSuffix(IO.Path.GetFileNameWithoutExtension(pFilePath), pSuffix, oFileInfo.Extension.Substring(1))
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function GetFilenameWithSuffix(pBaseString As String, pSuffix As String, pExtension As String)
|
||||||
|
Return $"{pBaseString}-{pSuffix}.{pExtension}"
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function GetFilenameWithPrefix(pFilePath As String, pPrefix As String)
|
||||||
|
Dim oFileInfo = New IO.FileInfo(pFilePath)
|
||||||
|
Return GetFilenameWithSuffix(IO.Path.GetFileNameWithoutExtension(pFilePath), pPrefix, oFileInfo.Extension.Substring(1))
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Function GetFilenameWithPrefix(pBaseString As String, pPrefix As String, pExtension As String)
|
||||||
|
Return $"{pPrefix}-{pBaseString}.{pExtension}"
|
||||||
|
End Function
|
||||||
|
|
||||||
|
End Class
|
||||||
18
Filesystem/FileContainer/DocumentObject.vb
Normal file
18
Filesystem/FileContainer/DocumentObject.vb
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
Imports System.Runtime.Serialization
|
||||||
|
|
||||||
|
<Serializable>
|
||||||
|
Public Class DocumentObject
|
||||||
|
|
||||||
|
<DataMember(Name:="FileName")>
|
||||||
|
Public ReadOnly FileName As String
|
||||||
|
<DataMember(Name:="ContainerId")>
|
||||||
|
Public ReadOnly ContainerId As String
|
||||||
|
<DataMember(Name:="DocumentId")>
|
||||||
|
Public ReadOnly DocumentId As Int64
|
||||||
|
|
||||||
|
Public Sub New(ContainerId As String, DocumentId As Int64, FileName As String)
|
||||||
|
Me.ContainerId = ContainerId
|
||||||
|
Me.DocumentId = DocumentId
|
||||||
|
Me.FileName = FileName
|
||||||
|
End Sub
|
||||||
|
End Class
|
||||||
193
Filesystem/FileContainer/FileContainer.vb
Normal file
193
Filesystem/FileContainer/FileContainer.vb
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
Imports System.IO
|
||||||
|
Imports DigitalData.Modules.Logging
|
||||||
|
Imports DigitalData.Modules.Encryption
|
||||||
|
Imports ProtoBuf
|
||||||
|
|
||||||
|
''' <module>FileContainer</module>
|
||||||
|
''' <version>0.0.0.2</version>
|
||||||
|
''' <date>21.11.2018</date>
|
||||||
|
''' <summary>
|
||||||
|
''' File Container for securely saving files
|
||||||
|
''' </summary>
|
||||||
|
''' <dependencies>
|
||||||
|
''' NLog, >= 4.5.8
|
||||||
|
''' </dependencies>
|
||||||
|
''' <params>
|
||||||
|
''' LogConfig, DigitalData.Module.Logging.LogConfig
|
||||||
|
''' A LogConfig object
|
||||||
|
''' Password, String
|
||||||
|
''' The Password to Encrypt
|
||||||
|
''' Path, String
|
||||||
|
''' The Path to save/load the container
|
||||||
|
''' </params>
|
||||||
|
''' <example>
|
||||||
|
''' dim oContainer = Container.Create(logConfig, "pass", "E:\some.container")
|
||||||
|
''' dim oContainer = Container.Load(logConfig, "pass", "E:\some.container")
|
||||||
|
'''
|
||||||
|
''' dim oContainer = new Container(logConfig, "pass", "E:\some.container")
|
||||||
|
''' oContainer.Save()
|
||||||
|
'''
|
||||||
|
''' dim oContainer = new Container(logConfig, "pass", "E:\some.container")
|
||||||
|
''' oContainer.Contents = oSomeData
|
||||||
|
''' oContainer.Save()
|
||||||
|
'''
|
||||||
|
''' dim oContainer = new Container(logConfig, "pass", "E:\some.container")
|
||||||
|
''' oContainer.Load()
|
||||||
|
''' dim oContents = oContainer.Contents
|
||||||
|
'''
|
||||||
|
''' dim oContainer = new Container(logConfig, "pass", "E:\some.container")
|
||||||
|
''' oContainer.Load()
|
||||||
|
''' oContainer.Contents = oSomeOtherData
|
||||||
|
''' oContainer.Save()
|
||||||
|
''' oContainer.SaveAs("E:\some2.container")
|
||||||
|
''' </example>
|
||||||
|
Public Class FileContainer
|
||||||
|
Private _crypto As Encryption.Encryption
|
||||||
|
Private _compression As Compression
|
||||||
|
Private _inner As FileContainerInner
|
||||||
|
Private _logger As Logger
|
||||||
|
Private _logConfig As LogConfig
|
||||||
|
Private _path As String
|
||||||
|
|
||||||
|
Public Property Contents As Byte()
|
||||||
|
Get
|
||||||
|
Return _inner.Contents
|
||||||
|
End Get
|
||||||
|
Set(value As Byte())
|
||||||
|
_inner.Contents = value
|
||||||
|
End Set
|
||||||
|
End Property
|
||||||
|
Public ReadOnly Property ContainerId As String
|
||||||
|
Get
|
||||||
|
Return _inner.FileId
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
|
Public ReadOnly Property CreatedAt As String
|
||||||
|
Get
|
||||||
|
Return _inner.CreatedAt
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
|
Public ReadOnly Property UpdatedAt As String
|
||||||
|
Get
|
||||||
|
Return _inner.UpdatedAt
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
|
|
||||||
|
Public Shared Function Create(LogConfig As LogConfig, Password As String) As FileContainer
|
||||||
|
Dim oContainer = New FileContainer(LogConfig, Password)
|
||||||
|
Return oContainer
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Shared Function Load(LogConfig As LogConfig, Password As String, Path As String) As FileContainer
|
||||||
|
Dim oContainer = New FileContainer(LogConfig, Password, Path)
|
||||||
|
oContainer.Load()
|
||||||
|
Return oContainer
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Sub New(LogConfig As LogConfig, Password As String)
|
||||||
|
_logger = LogConfig.GetLogger()
|
||||||
|
_crypto = New Encryption.Encryption(LogConfig, Password)
|
||||||
|
_compression = New Compression(LogConfig)
|
||||||
|
_inner = New FileContainerInner()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Sub New(LogConfig As LogConfig, Password As String, Path As String)
|
||||||
|
MyClass.New(LogConfig, Password)
|
||||||
|
_path = Path
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Sub SetFile(Contents As Byte(), FileName As String)
|
||||||
|
_inner.Contents = Contents
|
||||||
|
_inner.UpdatedAt = Date.Now
|
||||||
|
_inner.FileName = FileName
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Function GetFile() As FileContainerInner
|
||||||
|
Return _inner
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Sub Save()
|
||||||
|
If IsNothing(_path) Then
|
||||||
|
Throw New ArgumentException("Path not set")
|
||||||
|
End If
|
||||||
|
|
||||||
|
SaveAs(_path)
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Sub SaveAs(Path As String)
|
||||||
|
Try
|
||||||
|
WriteBytesToFile(TransformToBytes(_inner), Path)
|
||||||
|
Catch ex As Exception
|
||||||
|
_logger.Error(ex)
|
||||||
|
Throw ex
|
||||||
|
End Try
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Sub Load()
|
||||||
|
If IsNothing(_path) Then
|
||||||
|
Throw New ArgumentException("Path not set")
|
||||||
|
End If
|
||||||
|
|
||||||
|
LoadFrom(_path)
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Sub LoadFrom(Path As String)
|
||||||
|
Try
|
||||||
|
_inner = TransformToObject(ReadBytesFromFile(_path))
|
||||||
|
Catch ex As Exception
|
||||||
|
_logger.Error(ex)
|
||||||
|
Throw ex
|
||||||
|
End Try
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Private Function TransformToBytes([Object] As FileContainerInner) As Byte()
|
||||||
|
Dim oBytes = Serialize([Object])
|
||||||
|
Dim oCompressed = _compression.Compress(oBytes)
|
||||||
|
Dim oEncrypted = _crypto.Encrypt(oCompressed)
|
||||||
|
Return oEncrypted
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Private Function TransformToObject(Bytes As Byte()) As FileContainerInner
|
||||||
|
Dim oDecrypted = _crypto.Decrypt(Bytes)
|
||||||
|
Dim oDecompressed = _compression.Decompress(oDecrypted)
|
||||||
|
Dim oObject = Deserialize(oDecompressed)
|
||||||
|
Return oObject
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Private Function Serialize(InnerData As FileContainerInner) As Byte()
|
||||||
|
Dim oBinaryData As Byte()
|
||||||
|
|
||||||
|
Using oStream As New MemoryStream
|
||||||
|
Serializer.Serialize(oStream, InnerData)
|
||||||
|
oBinaryData = oStream.ToArray()
|
||||||
|
End Using
|
||||||
|
|
||||||
|
Return oBinaryData
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Private Function Deserialize(InnerData As Byte()) As FileContainerInner
|
||||||
|
Dim oObject As FileContainerInner
|
||||||
|
|
||||||
|
Using oStream As New MemoryStream(InnerData)
|
||||||
|
oObject = Serializer.Deserialize(Of FileContainerInner)(oStream)
|
||||||
|
End Using
|
||||||
|
|
||||||
|
Return oObject
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Private Sub WriteBytesToFile(Data As Byte(), FilePath As String)
|
||||||
|
Using oSourceStream As New FileStream(FilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)
|
||||||
|
oSourceStream.Write(Data, 0, Data.Length)
|
||||||
|
oSourceStream.Flush()
|
||||||
|
End Using
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Private Function ReadBytesFromFile(FilePath As String) As Byte()
|
||||||
|
Using oFileStream = New FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096)
|
||||||
|
Dim oBuffer As Byte() = New Byte(oFileStream.Length - 1) {}
|
||||||
|
oFileStream.Read(oBuffer, 0, oFileStream.Length)
|
||||||
|
oFileStream.Close()
|
||||||
|
Return oBuffer
|
||||||
|
End Using
|
||||||
|
End Function
|
||||||
|
End Class
|
||||||
23
Filesystem/FileContainer/FileContainerInner.vb
Normal file
23
Filesystem/FileContainer/FileContainerInner.vb
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
Imports ProtoBuf
|
||||||
|
|
||||||
|
<Serializable>
|
||||||
|
<ProtoContract>
|
||||||
|
Public Class FileContainerInner
|
||||||
|
<ProtoMember(1)>
|
||||||
|
Public FileId As String
|
||||||
|
<ProtoMember(2)>
|
||||||
|
Public Contents As Byte()
|
||||||
|
<ProtoMember(3)>
|
||||||
|
Public CreatedAt As DateTime
|
||||||
|
<ProtoMember(4)>
|
||||||
|
Public UpdatedAt As DateTime
|
||||||
|
<ProtoMember(5)>
|
||||||
|
Public FileName As String
|
||||||
|
|
||||||
|
Public Sub New()
|
||||||
|
FileId = Guid.NewGuid().ToString
|
||||||
|
CreatedAt = Date.Now
|
||||||
|
UpdatedAt = Date.Now
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
End Class
|
||||||
132
Filesystem/FileWatcher/FileWatcher.vb
Normal file
132
Filesystem/FileWatcher/FileWatcher.vb
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
Imports System.IO
|
||||||
|
Imports DigitalData.Modules.Filesystem
|
||||||
|
Imports DigitalData.Modules.Filesystem.FileWatcherFilters
|
||||||
|
Imports DigitalData.Modules.Logging
|
||||||
|
|
||||||
|
|
||||||
|
Public Class FileWatcher
|
||||||
|
' Internals
|
||||||
|
Private ReadOnly _Logger As Logger
|
||||||
|
Private ReadOnly _Watchers As List(Of FileSystemWatcher)
|
||||||
|
Private ReadOnly _Files As Dictionary(Of String, FileWatcherProperties)
|
||||||
|
Private ReadOnly _Filters As List(Of BaseFileFilter)
|
||||||
|
|
||||||
|
' Options
|
||||||
|
Private _Path As String
|
||||||
|
|
||||||
|
' Public Events
|
||||||
|
Public Event FileSaved(ByVal FullName As String, ByVal IsSpecial As Boolean)
|
||||||
|
|
||||||
|
Public Sub New(LogConfig As LogConfig, Path As String, Optional Filters As List(Of BaseFileFilter) = Nothing)
|
||||||
|
_Logger = LogConfig.GetLogger()
|
||||||
|
_Files = New Dictionary(Of String, FileWatcherProperties)
|
||||||
|
_Watchers = New List(Of FileSystemWatcher)
|
||||||
|
_Filters = IIf(IsNothing(Filters), GetDefaultFilters(), Filters)
|
||||||
|
_Path = Path
|
||||||
|
|
||||||
|
For Each oFilePath In Directory.EnumerateFiles(_Path)
|
||||||
|
Try
|
||||||
|
If IO.File.Exists(oFilePath) Then
|
||||||
|
_Files.Add(oFilePath, New FileWatcherProperties With {
|
||||||
|
.CreatedAt = DateTime.Now,
|
||||||
|
.ChangedAt = Nothing
|
||||||
|
})
|
||||||
|
End If
|
||||||
|
Catch ex As Exception
|
||||||
|
_Logger.Error(ex)
|
||||||
|
_Logger.Warn("File {0} cannot be watched!")
|
||||||
|
End Try
|
||||||
|
Next
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Sub Add(Filter As String)
|
||||||
|
_Watchers.Add(CreateWatcher(Filter))
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Sub Start()
|
||||||
|
For Each oWatcher In _Watchers
|
||||||
|
oWatcher.EnableRaisingEvents = True
|
||||||
|
Next
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Sub [Stop]()
|
||||||
|
For Each oWatcher In _Watchers
|
||||||
|
If Not IsNothing(oWatcher) Then
|
||||||
|
oWatcher.EnableRaisingEvents = False
|
||||||
|
oWatcher.Dispose()
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Private Function GetDefaultFilters()
|
||||||
|
Return New List(Of BaseFileFilter) From {
|
||||||
|
New TempFileFilter,
|
||||||
|
New OfficeFileFilter
|
||||||
|
}
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Private Function CreateWatcher(Filter As String)
|
||||||
|
Dim oWatcher = New FileSystemWatcher() With {
|
||||||
|
.Path = _Path,
|
||||||
|
.Filter = Filter,
|
||||||
|
.NotifyFilter = NotifyFilters.LastAccess _
|
||||||
|
Or NotifyFilters.LastWrite _
|
||||||
|
Or NotifyFilters.FileName _
|
||||||
|
Or NotifyFilters.Size _
|
||||||
|
Or NotifyFilters.FileName _
|
||||||
|
Or NotifyFilters.Attributes
|
||||||
|
}
|
||||||
|
|
||||||
|
AddHandler oWatcher.Created, AddressOf HandleFileCreated
|
||||||
|
AddHandler oWatcher.Changed, AddressOf HandleFileChanged
|
||||||
|
AddHandler oWatcher.Deleted, AddressOf HandleFileDeleted
|
||||||
|
AddHandler oWatcher.Renamed, AddressOf HandleFileRenamed
|
||||||
|
|
||||||
|
Return oWatcher
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Private Sub HandleFileCreated(sender As Object, e As FileSystemEventArgs)
|
||||||
|
_Files.Add(e.FullPath, New FileWatcherProperties())
|
||||||
|
_Logger.Debug("[Created] " & e.FullPath)
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' This may fire twice for a single save operation,
|
||||||
|
''' see: https://blogs.msdn.microsoft.com/oldnewthing/20140507-00/?p=1053/
|
||||||
|
''' </summary>
|
||||||
|
Private Sub HandleFileChanged(sender As Object, e As FileSystemEventArgs)
|
||||||
|
_Files.Item(e.FullPath).ChangedAt = DateTime.Now
|
||||||
|
_Logger.Debug("[Changed] " & e.FullPath)
|
||||||
|
|
||||||
|
Dim oShouldRaiseSave As Boolean = Not _Filters.Any(Function(oFilter)
|
||||||
|
Return oFilter.ShouldFilter(e)
|
||||||
|
End Function)
|
||||||
|
|
||||||
|
If oShouldRaiseSave Then
|
||||||
|
RaiseEvent FileSaved(e.FullPath, False)
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
Private Sub HandleFileDeleted(sender As Object, e As FileSystemEventArgs)
|
||||||
|
_Files.Remove(e.FullPath)
|
||||||
|
_Logger.Debug("[Removed] " & e.FullPath)
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Private Sub HandleFileRenamed(sender As Object, e As RenamedEventArgs)
|
||||||
|
Dim oProperties = _Files.Item(e.OldFullPath)
|
||||||
|
_Files.Remove(e.OldFullPath)
|
||||||
|
_Files.Add(e.FullPath, oProperties)
|
||||||
|
' Soll eine umbenannte datei als NEU gelten?
|
||||||
|
|
||||||
|
Dim oShouldRaiseSave = _Filters.Any(Function(oFilter)
|
||||||
|
Return oFilter.ShouldRaiseSave(e)
|
||||||
|
End Function)
|
||||||
|
|
||||||
|
If oShouldRaiseSave Then
|
||||||
|
RaiseEvent FileSaved(e.OldFullPath, True)
|
||||||
|
End If
|
||||||
|
|
||||||
|
_Logger.Debug("[Renamed] {0} --> {1}", e.OldFullPath, e.FullPath)
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
|
||||||
|
End Class
|
||||||
61
Filesystem/FileWatcher/FileWatcherFilters.vb
Normal file
61
Filesystem/FileWatcher/FileWatcherFilters.vb
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
Imports System.IO
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Built-in filters for FileWatcher that are useful for correctly detecting changes on Office documents (currently Office 2016)
|
||||||
|
''' </summary>
|
||||||
|
Public Class FileWatcherFilters
|
||||||
|
''' <summary>
|
||||||
|
''' Base Filter that all filters must inherit from
|
||||||
|
''' Provides two functions that may be overridden and some useful file extension lists
|
||||||
|
''' </summary>
|
||||||
|
Public MustInherit Class BaseFileFilter
|
||||||
|
Public TempFiles As New List(Of String) From {".tmp", ""}
|
||||||
|
|
||||||
|
Public Overridable Function ShouldFilter(e As FileSystemEventArgs) As Boolean
|
||||||
|
Return False
|
||||||
|
End Function
|
||||||
|
Public Overridable Function ShouldRaiseSave(e As RenamedEventArgs) As Boolean
|
||||||
|
Return False
|
||||||
|
End Function
|
||||||
|
End Class
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Simple Filter that filters changes made on temporary files
|
||||||
|
''' </summary>
|
||||||
|
Public Class TempFileFilter
|
||||||
|
Inherits BaseFileFilter
|
||||||
|
|
||||||
|
Public Overrides Function ShouldFilter(e As FileSystemEventArgs) As Boolean
|
||||||
|
Dim oFileInfo As New FileInfo(e.FullPath)
|
||||||
|
Return TempFiles.Contains(oFileInfo.Extension)
|
||||||
|
End Function
|
||||||
|
End Class
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Filter to detect changes on Office files
|
||||||
|
''' </summary>
|
||||||
|
Public Class OfficeFileFilter
|
||||||
|
Inherits BaseFileFilter
|
||||||
|
|
||||||
|
Public OfficeFiles As New List(Of String) From {".docx", ".pptx", ".xlsx"}
|
||||||
|
|
||||||
|
Public Overrides Function ShouldFilter(e As FileSystemEventArgs) As Boolean
|
||||||
|
Dim oFileInfo As New FileInfo(e.FullPath)
|
||||||
|
Return OfficeFiles.Contains(oFileInfo.Extension) And oFileInfo.Name.StartsWith("~")
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Overrides Function ShouldRaiseSave(e As RenamedEventArgs) As Boolean
|
||||||
|
Dim oIsTransform = OfficeFiles.Any(Function(Extension As String)
|
||||||
|
Return e.OldName.EndsWith(Extension)
|
||||||
|
End Function)
|
||||||
|
|
||||||
|
' Check if it is renamed to a temp file
|
||||||
|
Dim oIsTempFile = TempFiles.Any(Function(Extension)
|
||||||
|
Return e.Name.EndsWith(Extension)
|
||||||
|
End Function)
|
||||||
|
|
||||||
|
|
||||||
|
Return oIsTransform And oIsTempFile
|
||||||
|
End Function
|
||||||
|
End Class
|
||||||
|
End Class
|
||||||
10
Filesystem/FileWatcher/FileWatcherProperties.vb
Normal file
10
Filesystem/FileWatcher/FileWatcherProperties.vb
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
Public Class FileWatcherProperties
|
||||||
|
Public Property CreatedAt As DateTime
|
||||||
|
Public Property ChangedAt As DateTime
|
||||||
|
Public ReadOnly Property HasChanged As Boolean
|
||||||
|
Public Sub New()
|
||||||
|
CreatedAt = DateTime.Now
|
||||||
|
ChangedAt = Nothing
|
||||||
|
HasChanged = False
|
||||||
|
End Sub
|
||||||
|
End Class
|
||||||
133
Filesystem/Filesystem.vbproj
Normal file
133
Filesystem/Filesystem.vbproj
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{991D0231-4623-496D-8BD0-9CA906029CBC}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<RootNamespace>DigitalData.Modules.Filesystem</RootNamespace>
|
||||||
|
<AssemblyName>DigitalData.Modules.Filesystem</AssemblyName>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<MyType>Windows</MyType>
|
||||||
|
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||||
|
<TargetFrameworkProfile />
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<DefineDebug>true</DefineDebug>
|
||||||
|
<DefineTrace>true</DefineTrace>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DocumentationFile>DigitalData.Modules.Filesystem.xml</DocumentationFile>
|
||||||
|
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<DefineDebug>false</DefineDebug>
|
||||||
|
<DefineTrace>true</DefineTrace>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DocumentationFile>DigitalData.Modules.Filesystem.xml</DocumentationFile>
|
||||||
|
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<OptionExplicit>On</OptionExplicit>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<OptionCompare>Binary</OptionCompare>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<OptionStrict>Off</OptionStrict>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<OptionInfer>On</OptionInfer>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="DigitalData.Modules.Logging, Version=2.6.5.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\DigitalData.Modules.Logging.2.6.5\lib\net462\DigitalData.Modules.Logging.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\NLog.5.0.5\lib\net46\NLog.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="protobuf-net, Version=2.4.0.0, Culture=neutral, PublicKeyToken=257b51d87d2e4d67, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\protobuf-net.2.4.0\lib\net40\protobuf-net.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Configuration" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.IO.Compression" />
|
||||||
|
<Reference Include="System.Runtime.Serialization" />
|
||||||
|
<Reference Include="System.ServiceModel" />
|
||||||
|
<Reference Include="System.Transactions" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="System.Net.Http" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Import Include="Microsoft.VisualBasic" />
|
||||||
|
<Import Include="System" />
|
||||||
|
<Import Include="System.Collections" />
|
||||||
|
<Import Include="System.Collections.Generic" />
|
||||||
|
<Import Include="System.Data" />
|
||||||
|
<Import Include="System.Diagnostics" />
|
||||||
|
<Import Include="System.Linq" />
|
||||||
|
<Import Include="System.Xml.Linq" />
|
||||||
|
<Import Include="System.Threading.Tasks" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="FileContainer\DocumentObject.vb" />
|
||||||
|
<Compile Include="FileContainer\FileContainer.vb" />
|
||||||
|
<Compile Include="File.vb" />
|
||||||
|
<Compile Include="FileContainer\FileContainerInner.vb" />
|
||||||
|
<Compile Include="FileWatcher\FileWatcher.vb" />
|
||||||
|
<Compile Include="FileWatcher\FileWatcherFilters.vb" />
|
||||||
|
<Compile Include="FileWatcher\FileWatcherProperties.vb" />
|
||||||
|
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||||
|
<Compile Include="My Project\Application.Designer.vb">
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DependentUpon>Application.myapp</DependentUpon>
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="My Project\Resources.Designer.vb">
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="My Project\Settings.Designer.vb">
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DependentUpon>Settings.settings</DependentUpon>
|
||||||
|
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="My Project\Resources.resx">
|
||||||
|
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
|
||||||
|
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
|
||||||
|
<CustomToolNamespace>My.Resources</CustomToolNamespace>
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</EmbeddedResource>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="My Project\Application.myapp">
|
||||||
|
<Generator>MyApplicationCodeGenerator</Generator>
|
||||||
|
<LastGenOutput>Application.Designer.vb</LastGenOutput>
|
||||||
|
</None>
|
||||||
|
<None Include="My Project\Settings.settings">
|
||||||
|
<Generator>SettingsSingleFileGenerator</Generator>
|
||||||
|
<CustomToolNamespace>My</CustomToolNamespace>
|
||||||
|
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
|
||||||
|
</None>
|
||||||
|
<None Include="packages.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Encryption\Encryption.vbproj">
|
||||||
|
<Project>{8a8f20fc-c46e-41ac-bee7-218366cfff99}</Project>
|
||||||
|
<Name>Encryption</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||||
|
</Project>
|
||||||
13
Filesystem/My Project/Application.Designer.vb
generated
Normal file
13
Filesystem/My Project/Application.Designer.vb
generated
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
'------------------------------------------------------------------------------
|
||||||
|
' <auto-generated>
|
||||||
|
' Dieser Code wurde von einem Tool generiert.
|
||||||
|
' Laufzeitversion:4.0.30319.42000
|
||||||
|
'
|
||||||
|
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||||
|
' der Code erneut generiert wird.
|
||||||
|
' </auto-generated>
|
||||||
|
'------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Option Strict On
|
||||||
|
Option Explicit On
|
||||||
|
|
||||||
10
Filesystem/My Project/Application.myapp
Normal file
10
Filesystem/My Project/Application.myapp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||||
|
<MySubMain>false</MySubMain>
|
||||||
|
<SingleInstance>false</SingleInstance>
|
||||||
|
<ShutdownMode>0</ShutdownMode>
|
||||||
|
<EnableVisualStyles>true</EnableVisualStyles>
|
||||||
|
<AuthenticationMode>0</AuthenticationMode>
|
||||||
|
<ApplicationType>1</ApplicationType>
|
||||||
|
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
|
||||||
|
</MyApplicationData>
|
||||||
35
Filesystem/My Project/AssemblyInfo.vb
Normal file
35
Filesystem/My Project/AssemblyInfo.vb
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
Imports System
|
||||||
|
Imports System.Reflection
|
||||||
|
Imports System.Runtime.InteropServices
|
||||||
|
|
||||||
|
' Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||||
|
' Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||||
|
' die einer Assembly zugeordnet sind.
|
||||||
|
|
||||||
|
' Werte der Assemblyattribute überprüfen
|
||||||
|
|
||||||
|
<Assembly: AssemblyTitle("Modules.Filesystem")>
|
||||||
|
<Assembly: AssemblyDescription("Stellt Funktionen für das Filesystem und Container zur Verfügung")>
|
||||||
|
<Assembly: AssemblyCompany("Digital Data")>
|
||||||
|
<Assembly: AssemblyProduct("Modules.Filesystem")>
|
||||||
|
<Assembly: AssemblyCopyright("Copyright © 2022")>
|
||||||
|
<Assembly: AssemblyTrademark("1.3.1.0")>
|
||||||
|
|
||||||
|
<Assembly: ComVisible(False)>
|
||||||
|
|
||||||
|
'Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird.
|
||||||
|
<Assembly: Guid("2787495c-e65f-4730-be0c-af87bede4b11")>
|
||||||
|
|
||||||
|
' Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||||
|
'
|
||||||
|
' Hauptversion
|
||||||
|
' Nebenversion
|
||||||
|
' Buildnummer
|
||||||
|
' Revision
|
||||||
|
'
|
||||||
|
' Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
||||||
|
' übernehmen, indem Sie "*" eingeben:
|
||||||
|
' <Assembly: AssemblyVersion("1.0.*")>
|
||||||
|
|
||||||
|
<Assembly: AssemblyVersion("1.3.3.0")>
|
||||||
|
<Assembly: AssemblyFileVersion("1.3.3.0")>
|
||||||
63
Filesystem/My Project/Resources.Designer.vb
generated
Normal file
63
Filesystem/My Project/Resources.Designer.vb
generated
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
'------------------------------------------------------------------------------
|
||||||
|
' <auto-generated>
|
||||||
|
' Dieser Code wurde von einem Tool generiert.
|
||||||
|
' Laufzeitversion:4.0.30319.42000
|
||||||
|
'
|
||||||
|
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||||
|
' der Code erneut generiert wird.
|
||||||
|
' </auto-generated>
|
||||||
|
'------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Option Strict On
|
||||||
|
Option Explicit On
|
||||||
|
|
||||||
|
Imports System
|
||||||
|
|
||||||
|
Namespace My.Resources
|
||||||
|
|
||||||
|
'Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert
|
||||||
|
'-Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert.
|
||||||
|
'Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen
|
||||||
|
'mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu.
|
||||||
|
'''<summary>
|
||||||
|
''' Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
|
||||||
|
'''</summary>
|
||||||
|
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0"), _
|
||||||
|
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||||
|
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||||
|
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
|
||||||
|
Friend Module Resources
|
||||||
|
|
||||||
|
Private resourceMan As Global.System.Resources.ResourceManager
|
||||||
|
|
||||||
|
Private resourceCulture As Global.System.Globalization.CultureInfo
|
||||||
|
|
||||||
|
'''<summary>
|
||||||
|
''' Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
|
||||||
|
'''</summary>
|
||||||
|
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||||
|
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("DigitalData.Modules.Filesystem.Resources", GetType(Resources).Assembly)
|
||||||
|
resourceMan = temp
|
||||||
|
End If
|
||||||
|
Return resourceMan
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
|
|
||||||
|
'''<summary>
|
||||||
|
''' Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
|
||||||
|
''' Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
|
||||||
|
'''</summary>
|
||||||
|
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||||
|
Friend Property Culture() As Global.System.Globalization.CultureInfo
|
||||||
|
Get
|
||||||
|
Return resourceCulture
|
||||||
|
End Get
|
||||||
|
Set
|
||||||
|
resourceCulture = value
|
||||||
|
End Set
|
||||||
|
End Property
|
||||||
|
End Module
|
||||||
|
End Namespace
|
||||||
117
Filesystem/My Project/Resources.resx
Normal file
117
Filesystem/My Project/Resources.resx
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
||||||
73
Filesystem/My Project/Settings.Designer.vb
generated
Normal file
73
Filesystem/My Project/Settings.Designer.vb
generated
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
'------------------------------------------------------------------------------
|
||||||
|
' <auto-generated>
|
||||||
|
' Dieser Code wurde von einem Tool generiert.
|
||||||
|
' Laufzeitversion:4.0.30319.42000
|
||||||
|
'
|
||||||
|
' Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||||
|
' der Code erneut generiert wird.
|
||||||
|
' </auto-generated>
|
||||||
|
'------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Option Strict On
|
||||||
|
Option Explicit On
|
||||||
|
|
||||||
|
|
||||||
|
Namespace My
|
||||||
|
|
||||||
|
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||||
|
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.9.0.0"), _
|
||||||
|
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||||
|
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 "Automatische My.Settings-Speicherfunktion"
|
||||||
|
#If _MyType = "WindowsForms" Then
|
||||||
|
Private Shared addedHandler As Boolean
|
||||||
|
|
||||||
|
Private Shared addedHandlerLockObject As New Object
|
||||||
|
|
||||||
|
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||||
|
Private Shared Sub AutoSaveSettings(sender As Global.System.Object, 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
|
||||||
|
|
||||||
|
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
|
||||||
|
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||||
|
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
|
||||||
|
Friend Module MySettingsProperty
|
||||||
|
|
||||||
|
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
|
||||||
|
Friend ReadOnly Property Settings() As Global.DigitalData.Modules.Filesystem.My.MySettings
|
||||||
|
Get
|
||||||
|
Return Global.DigitalData.Modules.Filesystem.My.MySettings.Default
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
|
End Module
|
||||||
|
End Namespace
|
||||||
7
Filesystem/My Project/Settings.settings
Normal file
7
Filesystem/My Project/Settings.settings
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" UseMySettingsClassName="true">
|
||||||
|
<Profiles>
|
||||||
|
<Profile Name="(Default)" />
|
||||||
|
</Profiles>
|
||||||
|
<Settings />
|
||||||
|
</SettingsFile>
|
||||||
7
Filesystem/packages.config
Normal file
7
Filesystem/packages.config
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="DigitalData.Modules.Logging" version="2.6.5" targetFramework="net48" />
|
||||||
|
<package id="NLog" version="5.0.5" targetFramework="net48" />
|
||||||
|
<package id="NuGet.CommandLine" version="6.13.2" targetFramework="net48" developmentDependency="true" />
|
||||||
|
<package id="protobuf-net" version="2.4.0" targetFramework="net461" />
|
||||||
|
</packages>
|
||||||
@ -35,6 +35,8 @@ Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Messaging", "Messaging\Mess
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "Database.Test", "Database.Test\Database.Test.vbproj", "{91B4DFC0-543C-43A7-A9E0-6817DCA277EC}"
|
Project("{778DAE3C-4631-46EA-AA77-85C1314464D9}") = "Database.Test", "Database.Test\Database.Test.vbproj", "{91B4DFC0-543C-43A7-A9E0-6817DCA277EC}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Filesystem", "Filesystem\Filesystem.vbproj", "{991D0231-4623-496D-8BD0-9CA906029CBC}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -105,6 +107,10 @@ Global
|
|||||||
{91B4DFC0-543C-43A7-A9E0-6817DCA277EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{91B4DFC0-543C-43A7-A9E0-6817DCA277EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{91B4DFC0-543C-43A7-A9E0-6817DCA277EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{91B4DFC0-543C-43A7-A9E0-6817DCA277EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{91B4DFC0-543C-43A7-A9E0-6817DCA277EC}.Release|Any CPU.Build.0 = Release|Any CPU
|
{91B4DFC0-543C-43A7-A9E0-6817DCA277EC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{991D0231-4623-496D-8BD0-9CA906029CBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{991D0231-4623-496D-8BD0-9CA906029CBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{991D0231-4623-496D-8BD0-9CA906029CBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{991D0231-4623-496D-8BD0-9CA906029CBC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@ -8,12 +8,12 @@ Imports System.Runtime.InteropServices
|
|||||||
|
|
||||||
' Werte der Assemblyattribute überprüfen
|
' Werte der Assemblyattribute überprüfen
|
||||||
|
|
||||||
<Assembly: AssemblyTitle("Patterns")>
|
<Assembly: AssemblyTitle("DigitalData.Patterns")>
|
||||||
<Assembly: AssemblyDescription("")>
|
<Assembly: AssemblyDescription("Enthält die Digital Data Struktur von Patterns die zum Ersetzen innerhalb der DD Produkte dienen")>
|
||||||
<Assembly: AssemblyCompany("")>
|
<Assembly: AssemblyCompany("Digital Data GmbH, Heuchelheim")>
|
||||||
<Assembly: AssemblyProduct("Patterns")>
|
<Assembly: AssemblyProduct("DigitalData.Patterns")>
|
||||||
<Assembly: AssemblyCopyright("Copyright © 2022")>
|
<Assembly: AssemblyCopyright("")>
|
||||||
<Assembly: AssemblyTrademark("1.3.0.0")>
|
<Assembly: AssemblyTrademark("")>
|
||||||
|
|
||||||
<Assembly: ComVisible(False)>
|
<Assembly: ComVisible(False)>
|
||||||
|
|
||||||
@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
|||||||
' übernehmen, indem Sie "*" eingeben:
|
' übernehmen, indem Sie "*" eingeben:
|
||||||
' <Assembly: AssemblyVersion("1.0.*")>
|
' <Assembly: AssemblyVersion("1.0.*")>
|
||||||
|
|
||||||
<Assembly: AssemblyVersion("1.3.0.0")>
|
<Assembly: AssemblyVersion("1.3.1.0")>
|
||||||
<Assembly: AssemblyFileVersion("1.3.0.0")>
|
<Assembly: AssemblyFileVersion("1.3.1.0")>
|
||||||
|
|||||||
@ -39,6 +39,10 @@ Public Class ClassPatterns
|
|||||||
Public Const CLIPBOARD_VALUE_DE = "@Zwischenablage"
|
Public Const CLIPBOARD_VALUE_DE = "@Zwischenablage"
|
||||||
Public Const CLIPBOARD_VALUE_EN = "@Clipboard"
|
Public Const CLIPBOARD_VALUE_EN = "@Clipboard"
|
||||||
|
|
||||||
|
Public Const PATTERN_WMDOCID = "{@WMDocID}"
|
||||||
|
Public Const PATTERN_IDBOBJID = "{@IDBObjID}"
|
||||||
|
|
||||||
|
|
||||||
Public Const MAX_TRY_COUNT = 100
|
Public Const MAX_TRY_COUNT = 100
|
||||||
|
|
||||||
Public ReadOnly Property PatternRegex As Regex
|
Public ReadOnly Property PatternRegex As Regex
|
||||||
@ -51,7 +55,7 @@ Public Class ClassPatterns
|
|||||||
Private ReadOnly _LogConfig As LogConfig
|
Private ReadOnly _LogConfig As LogConfig
|
||||||
|
|
||||||
Private ReadOnly _Regex As Regex = New Regex("{#(\w+)#([\w\s_-]+)}+")
|
Private ReadOnly _Regex As Regex = New Regex("{#(\w+)#([\w\s_-]+)}+")
|
||||||
Private ReadOnly _AllPatterns As New List(Of String) From {PATTERN_WMI, PATTERN_CTRL, PATTERN_USER, PATTERN_INT}
|
Private ReadOnly _AllPatterns As New List(Of String) From {PATTERN_WMI, PATTERN_CTRL, PATTERN_USER, PATTERN_INT, PATTERN_WMDOCID, PATTERN_IDBOBJID}
|
||||||
Private ReadOnly _ComplexPatterns As New List(Of String) From {PATTERN_WMI, PATTERN_CTRL}
|
Private ReadOnly _ComplexPatterns As New List(Of String) From {PATTERN_WMI, PATTERN_CTRL}
|
||||||
Private ReadOnly _SimplePatterns As New List(Of String) From {PATTERN_USER, PATTERN_INT}
|
Private ReadOnly _SimplePatterns As New List(Of String) From {PATTERN_USER, PATTERN_INT}
|
||||||
|
|
||||||
@ -67,12 +71,13 @@ Public Class ClassPatterns
|
|||||||
_Logger = pLogConfig.GetLogger
|
_Logger = pLogConfig.GetLogger
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Public Function ReplaceAllValues(pInput As String, pUser As State.UserState, pClipboardContents As String) As String
|
Public Function ReplaceAllValues(pInput As String, pUser As State.UserState, pClipboardContents As String, pObjectID As String) As String
|
||||||
Try
|
Try
|
||||||
Dim result = pInput
|
Dim result = pInput
|
||||||
|
|
||||||
result = ReplaceClipboardContents(result, pClipboardContents)
|
result = ReplaceClipboardContents(result, pClipboardContents)
|
||||||
result = ReplaceInternalValues(result)
|
result = ReplaceInternalValues(result)
|
||||||
|
result = ReplaceObjectIDValues(result, pObjectID)
|
||||||
result = ReplaceUserValues(result, pUser)
|
result = ReplaceUserValues(result, pUser)
|
||||||
|
|
||||||
Return result
|
Return result
|
||||||
@ -95,6 +100,13 @@ Public Class ClassPatterns
|
|||||||
|
|
||||||
Return oResult
|
Return oResult
|
||||||
End Function
|
End Function
|
||||||
|
Public Function ReplaceObjectIDValues(pInput As String, pObjectID As String) As String
|
||||||
|
Dim oResult = pInput
|
||||||
|
|
||||||
|
oResult = oResult.Replace(CLIPBOARD_VALUE_DE, pObjectID)
|
||||||
|
|
||||||
|
Return oResult
|
||||||
|
End Function
|
||||||
|
|
||||||
Public Function ReplaceInternalValues(pInput As String) As String
|
Public Function ReplaceInternalValues(pInput As String) As String
|
||||||
Try
|
Try
|
||||||
|
|||||||
@ -53,6 +53,9 @@
|
|||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\..\DDMonorepo\Controls.LookupGrid\bin\Debug\DigitalData.Controls.LookupGrid.dll</HintPath>
|
<HintPath>..\..\DDMonorepo\Controls.LookupGrid\bin\Debug\DigitalData.Controls.LookupGrid.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="DigitalData.Modules.Logging, Version=2.6.5.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\DigitalData.Modules.Logging.2.6.5\lib\net462\DigitalData.Modules.Logging.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Interop.WINDREAMLib">
|
<Reference Include="Interop.WINDREAMLib">
|
||||||
<HintPath>P:\Visual Studio Projekte\Bibliotheken\windream\Interop.WINDREAMLib.dll</HintPath>
|
<HintPath>P:\Visual Studio Projekte\Bibliotheken\windream\Interop.WINDREAMLib.dll</HintPath>
|
||||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||||
@ -142,10 +145,6 @@
|
|||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Logging\Logging.vbproj">
|
|
||||||
<Project>{903b2d7d-3b80-4be9-8713-7447b704e1b0}</Project>
|
|
||||||
<Name>Logging</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
<ProjectReference Include="..\ZooFlow\ZooFlow.vbproj">
|
<ProjectReference Include="..\ZooFlow\ZooFlow.vbproj">
|
||||||
<Project>{81cac44f-3711-4c8f-ae98-e02a7448782a}</Project>
|
<Project>{81cac44f-3711-4c8f-ae98-e02a7448782a}</Project>
|
||||||
<Name>ZooFlow</Name>
|
<Name>ZooFlow</Name>
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
|
<package id="DigitalData.Modules.Logging" version="2.6.5" targetFramework="net462" />
|
||||||
<package id="NLog" version="5.0.5" targetFramework="net461" />
|
<package id="NLog" version="5.0.5" targetFramework="net461" />
|
||||||
|
<package id="NuGet.CommandLine" version="6.13.2" targetFramework="net462" developmentDependency="true" />
|
||||||
</packages>
|
</packages>
|
||||||
@ -8,12 +8,12 @@ Imports System.Runtime.InteropServices
|
|||||||
|
|
||||||
' Werte der Assemblyattribute überprüfen
|
' Werte der Assemblyattribute überprüfen
|
||||||
|
|
||||||
<Assembly: AssemblyTitle("Windows")>
|
<Assembly: AssemblyTitle("Modules.Windows")>
|
||||||
<Assembly: AssemblyDescription("")>
|
<Assembly: AssemblyDescription("Stellt Funktionen für windows und Hotkeys bereit")>
|
||||||
<Assembly: AssemblyCompany("")>
|
<Assembly: AssemblyCompany("Digital Data GmbH, Heuchelheim")>
|
||||||
<Assembly: AssemblyProduct("Windows")>
|
<Assembly: AssemblyProduct("Modules.Windows")>
|
||||||
<Assembly: AssemblyCopyright("Copyright © 2022")>
|
<Assembly: AssemblyCopyright("")>
|
||||||
<Assembly: AssemblyTrademark("1.5.0.0")>
|
<Assembly: AssemblyTrademark("")>
|
||||||
|
|
||||||
<Assembly: ComVisible(False)>
|
<Assembly: ComVisible(False)>
|
||||||
|
|
||||||
@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
|||||||
' übernehmen, indem Sie "*" eingeben:
|
' übernehmen, indem Sie "*" eingeben:
|
||||||
' <Assembly: AssemblyVersion("1.0.*")>
|
' <Assembly: AssemblyVersion("1.0.*")>
|
||||||
|
|
||||||
<Assembly: AssemblyVersion("1.5.0.0")>
|
<Assembly: AssemblyVersion("1.5.1.0")>
|
||||||
<Assembly: AssemblyFileVersion("1.5.0.0")>
|
<Assembly: AssemblyFileVersion("1.5.1.0")>
|
||||||
|
|||||||
@ -44,6 +44,9 @@
|
|||||||
<OptionInfer>On</OptionInfer>
|
<OptionInfer>On</OptionInfer>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="DigitalData.Modules.Logging, Version=2.6.5.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\DigitalData.Modules.Logging.2.6.5\lib\net462\DigitalData.Modules.Logging.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
<Reference Include="NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\NLog.5.0.5\lib\net46\NLog.dll</HintPath>
|
<HintPath>..\packages\NLog.5.0.5\lib\net46\NLog.dll</HintPath>
|
||||||
@ -138,10 +141,6 @@
|
|||||||
<Project>{6ea0c51f-c2b1-4462-8198-3de0b32b74f8}</Project>
|
<Project>{6ea0c51f-c2b1-4462-8198-3de0b32b74f8}</Project>
|
||||||
<Name>Base</Name>
|
<Name>Base</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\Logging\Logging.vbproj">
|
|
||||||
<Project>{903B2D7D-3B80-4BE9-8713-7447B704E1B0}</Project>
|
|
||||||
<Name>Logging</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<COMReference Include="Microsoft.Office.Core">
|
<COMReference Include="Microsoft.Office.Core">
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
|
<package id="DigitalData.Modules.Logging" version="2.6.5" targetFramework="net462" />
|
||||||
<package id="NLog" version="5.0.5" targetFramework="net461" />
|
<package id="NLog" version="5.0.5" targetFramework="net461" />
|
||||||
|
<package id="NuGet.CommandLine" version="6.13.2" targetFramework="net462" developmentDependency="true" />
|
||||||
</packages>
|
</packages>
|
||||||
Loading…
x
Reference in New Issue
Block a user