From d8bb4e3caa48e1128a8b508afae15ab9f4da5b4b Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Thu, 30 Apr 2020 14:24:51 +0200 Subject: [PATCH] allow backslash in dynamic folderpaths --- Global_Indexer/Global_Indexer.vbproj | 10 ++-- Global_Indexer/frmIndex.vb | 87 ++++++++++++++-------------- 2 files changed, 51 insertions(+), 46 deletions(-) diff --git a/Global_Indexer/Global_Indexer.vbproj b/Global_Indexer/Global_Indexer.vbproj index a1ff8e5..6e82df3 100644 --- a/Global_Indexer/Global_Indexer.vbproj +++ b/Global_Indexer/Global_Indexer.vbproj @@ -160,11 +160,13 @@ ..\..\DDMonorepo\Modules.Config\bin\Debug\DigitalData.Modules.Config.dll - - ..\..\DDMonorepo\Modules.Config\bin\Debug\DigitalData.Modules.Filesystem.dll + + ..\..\DDMonorepo\Modules.Filesystem\bin\Debug\DigitalData.Modules.Filesystem.dll + False - - ..\..\DDMonorepo\Modules.Config\bin\Debug\DigitalData.Modules.Logging.dll + + False + ..\..\DDMonorepo\Modules.Logging\bin\Debug\DigitalData.Modules.Logging.dll ..\..\DDMonorepo\Modules.Windream\bin\Debug\DigitalData.Modules.Windream.dll diff --git a/Global_Indexer/frmIndex.vb b/Global_Indexer/frmIndex.vb index ad578fa..6cef84e 100644 --- a/Global_Indexer/frmIndex.vb +++ b/Global_Indexer/frmIndex.vb @@ -435,6 +435,7 @@ Public Class frmIndex Try LOGGER.Debug("#### Name_Generieren ####") Dim sql As String = "select VERSION_DELIMITER, FILE_DELIMITER FROM TBDD_MODULES WHERE GUID = 1" + Dim oFilesystem As New DigitalData.Modules.Filesystem.File(LOGCONFIG) Dim DT1 As DataTable = ClassDatabase.Return_Datatable(sql) For Each row As DataRow In DT1.Rows FILE_DELIMITER = row.Item("FILE_DELIMITER") @@ -606,8 +607,8 @@ Public Class frmIndex End Select Next - - CURRENT_NEWFILENAME = ClassFilehandle.CleanFilename(NewFileString, "") + CURRENT_NEWFILENAME = oFilesystem.GetCleanFilename(NewFileString) + 'CURRENT_NEWFILENAME = ClassFilehandle.CleanFilename(NewFileString, "") CURRENT_NEWFILENAME = oRAWZielordner & "\" & CURRENT_NEWFILENAME If CURRENT_NEWFILENAME.EndsWith("_") Then @@ -2333,40 +2334,43 @@ Public Class frmIndex End Try End Function - Private Function CreateFolderForIndex(myDynamicFolder As String) + Private Function CreateFolderForIndex(DynamicFolderConfig As String) Try - Dim ORootFolder As String = Path.GetDirectoryName(CURRENT_NEWFILENAME) + Dim oRootFolder As String = Path.GetDirectoryName(CURRENT_NEWFILENAME) + Dim oFilesystem As New DigitalData.Modules.Filesystem.File(LOGCONFIG) '###### - Dim p_reg As String = "\[%{1}[a-zA-Z0-9\!\$\&\/\(\)\=\?\,\.\-\;\:_öÖüÜäÄ\#\'\+\*\~\{\}\@\€\<\>\ ]+]{1}" + Dim oRegexString As String = "\[%{1}[a-zA-Z0-9\!\$\&\/\(\)\=\?\,\.\-\;\:_öÖüÜäÄ\#\'\+\*\~\{\}\@\€\<\>\ ]+]{1}" ' einen Regulären Ausdruck laden - Dim regularExpression As Regex = New Regex(p_reg) + Dim oRegex As Regex = New Regex(oRegexString) ' die Vorkommen im Folder-String auslesen - Dim elemente As MatchCollection = regularExpression.Matches(myDynamicFolder) + Dim oMatches As MatchCollection = oRegex.Matches(DynamicFolderConfig) '#### ' alle Vorkommen innerhalb des Ordnerstrings durchlaufen - For Each element As Match In elemente - LOGGER.Info("Elementname in FolderString: '" & element.ToString & "'") - Select Case element.Value.Substring(2, 1).ToUpper + For Each oMatch As Match In oMatches + LOGGER.Info("Elementname in FolderString: '" & oMatch.ToString & "'") + Select Case oMatch.Value.Substring(2, 1).ToUpper 'Manueller Indexwert Case "M" - Dim ManIndexname = element.Value.Substring(3, element.Value.Length - 4) - Dim optional_index As Boolean = ClassDatabase.Execute_Scalar("SELECT OPTIONAL FROM TBDD_INDEX_MAN WHERE DOK_ID = " & CURRENT_DOKART_ID & " AND UPPER(NAME) = UPPER('" & ManIndexname & "')", MyConnectionString, True) - LOGGER.Info("Versuch den Indexwert aus '" & ManIndexname & "' auszulesen.") - Dim ManIndex_Value As String = GetManIndex_Value(ManIndexname, "FILE", optional_index) - LOGGER.Info("Ergebnis/Wert für neuen Ordner: '" & ManIndexname & "'") - If Not ManIndex_Value = String.Empty Then - If IsDate(ManIndex_Value) Then - ManIndex_Value = CDate(ManIndex_Value).ToString("yyyyMMdd") + Dim oManIndexName = oMatch.Value.Substring(3, oMatch.Value.Length - 4) + Dim oIsOptional As Boolean = ClassDatabase.Execute_Scalar("SELECT OPTIONAL FROM TBDD_INDEX_MAN WHERE DOK_ID = " & CURRENT_DOKART_ID & " AND UPPER(NAME) = UPPER('" & oManIndexName & "')", MyConnectionString, True) + LOGGER.Info("Versuch den Indexwert aus '" & oManIndexName & "' auszulesen.") + Dim oManIndexValue As String = GetManIndex_Value(oManIndexName, "FILE", oIsOptional) + LOGGER.Info("Ergebnis/Wert für neuen Ordner: '" & oManIndexName & "'") + If Not oManIndexValue = String.Empty Then + If IsDate(oManIndexValue) Then + oManIndexValue = CDate(oManIndexValue).ToString("yyyyMMdd") End If - ManIndex_Value = ClassFilehandle.CleanFilename(ManIndex_Value, "") - myDynamicFolder = myDynamicFolder.Replace(element.ToString, ManIndex_Value) - LOGGER.Info("FolderPattern: '" & myDynamicFolder & "'") + oManIndexValue = oFilesystem.GetCleanPath(oManIndexValue) + 'oManIndexValue = ClassFilehandle.CleanFilename(oManIndexValue, "") + DynamicFolderConfig = DynamicFolderConfig.Replace(oMatch.ToString, oManIndexValue) + + LOGGER.Info("FolderPattern: '" & DynamicFolderConfig & "'") Else - If optional_index = True Then + If oIsOptional = True Then LOGGER.Info("Optionaler Indexwert ist NICHT gefüllt") Else LOGGER.Info(" - Achtung Ausnahme in 'CrFolderForIndex': der Index ist leer!") @@ -2374,17 +2378,19 @@ Public Class frmIndex End If End If Case "A" - Dim AutoIndexname = element.Value.Substring(3, element.Value.Length - 4) - LOGGER.Info("Versuch den Auto-Indexwert aus '" & AutoIndexname & "' auszulesen.") - Dim AutoIndex_Value As String = GetAutoIndex_Value(AutoIndexname) - LOGGER.Info("Ergebnis/Wert für neuen Ordner: '" & AutoIndexname & "'") - If Not AutoIndex_Value = String.Empty Then - AutoIndex_Value = ClassFilehandle.CleanFilename(AutoIndex_Value, "") - If AutoIndex_Value = "EMPTY_OI" Then - myDynamicFolder = myDynamicFolder.Replace(element.ToString, "") + Dim oAutoIndexName = oMatch.Value.Substring(3, oMatch.Value.Length - 4) + LOGGER.Info("Versuch den Auto-Indexwert aus '" & oAutoIndexName & "' auszulesen.") + Dim oAutoIndexValue As String = GetAutoIndex_Value(oAutoIndexName) + LOGGER.Info("Ergebnis/Wert für neuen Ordner: '" & oAutoIndexName & "'") + If Not oAutoIndexValue = String.Empty Then + + oAutoIndexValue = oFilesystem.GetCleanPath(oAutoIndexValue) + 'oAutoIndexValue = ClassFilehandle.CleanFilename(oAutoIndexValue, "") + If oAutoIndexValue = "EMPTY_OI" Then + DynamicFolderConfig = DynamicFolderConfig.Replace(oMatch.ToString, "") Else - myDynamicFolder = myDynamicFolder.Replace(element.ToString, AutoIndex_Value) - LOGGER.Info("FolderPattern: '" & myDynamicFolder & "'") + DynamicFolderConfig = DynamicFolderConfig.Replace(oMatch.ToString, oAutoIndexValue) + LOGGER.Info("FolderPattern: '" & DynamicFolderConfig & "'") End If Else @@ -2400,7 +2406,7 @@ Public Class frmIndex If _day.Length = 1 Then _day = "0" & _day End If - Dim type = element.Value.Substring(3, element.Value.Length - 4) + Dim type = oMatch.Value.Substring(3, oMatch.Value.Length - 4) If type.StartsWith("_") Then type = type.Replace("_", "") End If @@ -2414,26 +2420,23 @@ Public Class frmIndex Case "YYYY-MM" oElementTemp = My.Computer.Clock.LocalTime.Year & "-" & _Month End Select - myDynamicFolder = myDynamicFolder.Replace(element.ToString, oElementTemp) - LOGGER.Info("FolderPatter nach V-Element: '" & myDynamicFolder & "'") + DynamicFolderConfig = DynamicFolderConfig.Replace(oMatch.ToString, oElementTemp) + LOGGER.Info("FolderPatter nach V-Element: '" & DynamicFolderConfig & "'") Case Else - LOGGER.Info(" - Achtung - in der Namenkonvention wurde ein Element gefunden welches nicht zugeordnet werden kann!" & vbNewLine & "Elementname: " & element.Value.ToUpper) + LOGGER.Info(" - Achtung - in der Namenkonvention wurde ein Element gefunden welches nicht zugeordnet werden kann!" & vbNewLine & "Elementname: " & oMatch.Value.ToUpper) If USER_LANGUAGE = "de-DE" Then - MsgBox("Achtung - in der Namenkonvention wurde ein Element gefunden welches nicht zugeordnet werden kann!" & vbNewLine & "Elementname: " & element.Value.ToUpper, MsgBoxStyle.Exclamation, "Unexpected error in Name generieren:") + MsgBox("Achtung - in der Namenkonvention wurde ein Element gefunden welches nicht zugeordnet werden kann!" & vbNewLine & "Elementname: " & oMatch.Value.ToUpper, MsgBoxStyle.Exclamation, "Unexpected error in Name generieren:") Else - MsgBox("Attention - One element in Namingconvention could not be matched!" & vbNewLine & "Elementname: " & element.Value.ToUpper, MsgBoxStyle.Exclamation, "Unexpected error in Name generieren:") + MsgBox("Attention - One element in Namingconvention could not be matched!" & vbNewLine & "Elementname: " & oMatch.Value.ToUpper, MsgBoxStyle.Exclamation, "Unexpected error in Name generieren:") End If End Select Next - LOGGER.Info("Den Root-Folder zusammenfügen>> ") - Dim oNewFullpath As String = ORootFolder & "\" & myDynamicFolder & "\" - oNewFullpath = oNewFullpath.Replace("\\", "\") - oNewFullpath = Path.Combine(ORootFolder, myDynamicFolder) + Dim oNewFullPath As String = System.IO.Path.Combine(oRootFolder, DynamicFolderConfig) LOGGER.Info("Fullpath (mit evtl. Sonderzeichen (SZ)) '" & oNewFullpath & "'") Dim invalidPathChars() As Char = Path.GetInvalidPathChars()