diff --git a/WIDigConsoleApp/ClassConfig.vb b/WIDigConsoleApp/ClassConfig.vb index f6747c3..8da5190 100644 --- a/WIDigConsoleApp/ClassConfig.vb +++ b/WIDigConsoleApp/ClassConfig.vb @@ -6,7 +6,7 @@ Public Class ClassConfig Public Property ConnectionString As String = "" Public Property WMUsername As String = "" Public Property WMUserPW As String = "" - Public Property WMDrive As String = "" + Public Property WMDrive As String = "W" Public Property WMRelPath As String = "" Public Property WMServer As String = "" Public Property Domain As String = "" diff --git a/WIDigConsoleApp/Module1.vb b/WIDigConsoleApp/ModuleMain.vb similarity index 61% rename from WIDigConsoleApp/Module1.vb rename to WIDigConsoleApp/ModuleMain.vb index b4c855d..f93447e 100644 --- a/WIDigConsoleApp/Module1.vb +++ b/WIDigConsoleApp/ModuleMain.vb @@ -6,18 +6,29 @@ Imports System.IO Imports System.Text.RegularExpressions Imports DigitalData.Modules.Database -Module Module1 +Module ModuleMain Private _ArgumentLength As Integer Public _database As MSSQLServer Public oRegExArg As String + Public oRegex As New Regex("([\s\S]+)\={([\s\S]+)}") + Public Const CODE_SUCCESS = 0 Public Const CODE_ERROR = 1 + Public Const MODE_OVERWRITE = "IMPO" + Public Const MODE_VERSION = "IMPV" + Public Const MODE_NACHINDEXIERUNG = "NI" + + Public Const PARAM_SOURCE = "-Source@" + Public Const PARAM_MODE = "-Mode@" + Public Const PARAM_TARGET = "-Target@" + Public Const PARAM_WMTO = "-WMOT@" + Public Const PARAM_INDEX = "-index@" + Public Function Main(CommandLineArguments As String()) As Integer Dim oReturnResult As Integer Try - oReturnResult = CODE_SUCCESS ' Console.WriteLine("Starting up WIDig...") Dim opath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) @@ -102,7 +113,6 @@ Module Module1 Return False End Try End Function - Public Function Load_DB_DAta() Try Dim oSql = "SELECT [REGEX] FROM [TBDD_FUNCTION_REGEX] WHERE FUNCTION_NAME = 'WM-INDEXER-INDEX_GROUP'" @@ -133,15 +143,15 @@ Module Module1 End Function Private Function GetUserPWPlain() Try - Dim PWplainText As String - Dim wrapper As New ClassEncryption("!35452didalog=") + Dim oPassword As String + Dim oEncryption As New ClassEncryption("!35452didalog=") If CONFIG.Config.WMUserPW = String.Empty Then - PWplainText = "" + oPassword = "" Else - PWplainText = wrapper.DecryptData(CONFIG.Config.WMUserPW) + oPassword = oEncryption.DecryptData(CONFIG.Config.WMUserPW) End If - Return PWplainText + Return oPassword Catch ex As Exception LOGGER.Warn("Error in GetUserPWPlain - the password [" & CONFIG.Config.WMUserPW & "] could not be decrypted", False) Return String.Empty @@ -159,12 +169,12 @@ Module Module1 Return False End If - Dim ocount As Integer = 0 + Dim oCount As Integer = 0 For Each oArg As String In pArguments - LOGGER.Debug($"[{ocount}] {oArg}") + LOGGER.Debug($"[{oCount}] {oArg}") oArg = oArg.Replace("""", "") - If oArg.StartsWith("-Source@") Then - oSourceFile = oArg.Replace("-Source@", "") + If oArg.StartsWith(PARAM_SOURCE) Then + oSourceFile = oArg.Replace(PARAM_SOURCE, "") If IsNumeric(oSourceFile) Then LOGGER.Info($"SourceFile seems to be a DocID [{oSourceFile}]") Dim oSQL = $"SELECT [dbo].[FNDD_GET_WINDREAM_FILE_PATH] ({oSourceFile})" @@ -177,11 +187,11 @@ Module Module1 Return False End If - ElseIf oArg.StartsWith("-Mode@") Then - oMode = oArg.Replace("-Mode@", "").ToUpper + ElseIf oArg.StartsWith(PARAM_MODE) Then + oMode = oArg.Replace(PARAM_MODE, "").ToUpper - ElseIf oArg.StartsWith("-Target@") Then - oTargetPath = oArg.Replace("-Target@", "") + ElseIf oArg.StartsWith(PARAM_TARGET) Then + oTargetPath = oArg.Replace(PARAM_TARGET, "") If IsNumeric(oTargetPath) Then LOGGER.Info($"Target seems to be a DocID [{oTargetPath}]") Dim oSQL = $"SELECT [dbo].[FNDD_GET_WINDREAM_FILE_PATH] ({oTargetPath})" @@ -194,7 +204,7 @@ Module Module1 If WINDREAM.TestFileExists(oTargetPath) = False Then LOGGER.Info($"WMFile [{oTargetPath}] not existing!") End If - If oMode = "IMPV" Then + If oMode = MODE_VERSION Then Dim oWMCheckPath = WINDREAM.VersionWMFilename(oTargetPath, System.IO.Path.GetExtension(oTargetPath)) If oNormalizePath.ToUpper <> oWMCheckPath.ToString.ToUpper Then LOGGER.Info($"Target [{oNormalizePath}] already existed!! - NewWMFilename [{oWMCheckPath}]") @@ -204,8 +214,8 @@ Module Module1 'Checks and creates the path if necessary WINDREAM.NewFolder(oTargetPath, oExtension) - ElseIf oArg.StartsWith("-WMOT@") Then - oWMObjecttype = oArg.Replace("-WMOT@", "") + ElseIf oArg.StartsWith(PARAM_WMTO) Then + oWMObjecttype = oArg.Replace(PARAM_WMTO, "") Dim oexists As Boolean = False Dim myWMOTypes = WINDREAM.ObjectTypes For Each otype As String In myWMOTypes @@ -222,22 +232,30 @@ Module Module1 Else WMIndices = WINDREAM.GetIndiciesByObjecttype(oWMObjecttype) End If - ElseIf oArg.StartsWith("-index@") Then + ElseIf oArg.StartsWith(PARAM_INDEX) Then oINDEXInfotemp = oArg oINDEXInfoStarted = True - oINDEXInfotemp = oINDEXInfotemp.Replace("-index@", "") + oINDEXInfotemp = oINDEXInfotemp.Replace(PARAM_INDEX, "") Else If oINDEXInfoStarted Then oINDEXInfotemp &= " " & oArg End If End If - ocount += 1 + oCount += 1 Next - Dim oIndexparts As String() = oINDEXInfotemp.Split(New String() {"#~#"}, StringSplitOptions.RemoveEmptyEntries) + LOGGER.Debug("INDEXInfoTemp: [{0}]", oINDEXInfotemp) - LOGGER.Info($" [{oIndexparts.Length}] Indices transmitted...") + Dim oIndexparts As List(Of String) = oINDEXInfotemp. + Split(New String() {"#~#"}, StringSplitOptions.RemoveEmptyEntries). + ToList() + + For Each oIndexPart As String In oIndexparts + LOGGER.Debug(oIndexPart) + Next + + LOGGER.Info($" [{oIndexparts.Count}] Indices parsed") oIndexArr = oIndexparts Return True Catch ex As Exception @@ -253,71 +271,120 @@ Module Module1 Public Function StreamORIndexFile() Try Dim oResult As Boolean = False - If oMode = "IMPV" Then + If oMode = MODE_VERSION Then oResult = WINDREAM.NewFileStream(oSourceFile, oTargetPath) - ElseIf oMode = "IMPO" Then + ElseIf oMode = MODE_OVERWRITE Then Dim oDeleted = WINDREAM.RemoveFile(oTargetPath) If oDeleted = True Then oResult = WINDREAM.NewFileStream(oSourceFile, oTargetPath) Else LOGGER.Warn($"Mode ImportOverwrite is active - but WMFile could not be deleted!!") End If - ElseIf oMode = "NI" Then + ElseIf oMode = MODE_NACHINDEXIERUNG Then oResult = True End If - If oResult = True Then - If oMode <> "NI" Then + If oMode <> MODE_NACHINDEXIERUNG Then LOGGER.Info($"File successfully streamed to windream [{oTargetPath}]! Now indexing...") End If - For Each oIndex2 As String In oIndexArr - Dim oIndexInfo() = oIndex2.Split("={") - Dim oIndexName = oIndexInfo(0) - Dim oIndexvalue - Dim r As Regex = New Regex(oRegExArg, RegexOptions.IgnoreCase) - ' ' Match the regular expression pattern against a text string. - Dim m As Match = r.Match(oIndex2) - Do While m.Success + For Each oIndex As String In oIndexArr + Dim oMatch As Match = oRegex.Match(oIndex) - ' oClearedBodyText = oClearedBodyText.Replace(m.Value, "") - 'Dim g As Group = m.Groups(1) - Dim g1 As Group = m.Groups(2) - Dim g2 As Group = m.Groups(3) + If oMatch.Success Then - If Not IsNothing(g2.Value) Then - oIndexvalue = g2.Value - Console.WriteLine($"Indexvalue: {oIndexvalue}") + Dim oIndexName = oMatch.Groups(1)?.Value + Dim oIndexValues = oMatch.Groups.Item(2)?.Value + Dim oSplitValue = New String() {"~#~"} + + Dim oIndexValueArray = oIndexValues.Split(oSplitValue, StringSplitOptions.RemoveEmptyEntries) + Dim oIndexResult = False + + LOGGER.Info("Setting Index [{0}] to [{1}].", oIndexName, oIndexValues) + + If WINDREAM.TestIndexNameIsVectorIndex(oIndexName) Then + Dim oCombinedIndexValues = WINDREAM.GetVectorData(oTargetPath, oIndexName, oIndexValueArray, False) + oIndexResult = WINDREAM.SetFileIndex(oTargetPath, oIndexName, oCombinedIndexValues.ToList, oWMObjecttype) + Else + oIndexResult = WINDREAM.SetFileIndex(oTargetPath, oIndexName, oIndexValueArray(0), oWMObjecttype) End If - If Len(oIndexvalue) > 0 Then - If WMIndex_exists(oIndexName) = True Then - LOGGER.Info($"Setting Index: oIndexName [{oIndexName}] - oIndexvalue [{oIndexvalue}]") - If WINDREAM.SetFileIndex(oTargetPath, oIndexName, oIndexvalue, oWMObjecttype) = False Then - LOGGER.Info($"Index could not be set...") - If WINDREAM.RemoveFile(oTargetPath) = True Then - LOGGER.Info($"File deleted after error!") - End If - oResult = False - Exit For - End If - Else - LOGGER.Warn($"Transmitted index with name [{oIndexName}] is not existing in WM Objecttype!") - If WINDREAM.RemoveFile(oTargetPath) = True Then - LOGGER.Info($"File deleted after error!") - End If - oResult = False - Exit For - End If - End If - m = m.NextMatch() - Loop + + oResult = oIndexResult + Else + oResult = False + End If + + If oResult = False Then + LOGGER.Warn("Indexing failed. Exiting.") + Exit For + End If Next - If oResult = True Then - LOGGER.Info("## All Tasks finished ##") - oErrorImport = False - End If End If + + If oResult = True Then + LOGGER.Info("## All Tasks finished ##") + oErrorImport = False + End If + + 'If oResult = True Then + ' If oMode <> MODE_NACHINDEXIERUNG Then + ' LOGGER.Info($"File successfully streamed to windream [{oTargetPath}]! Now indexing...") + ' End If + + ' For Each oIndex2 As String In oIndexArr + ' Dim oIndexInfo() = oIndex2.Split("={") + ' Dim oIndexName = oIndexInfo(0) + ' Dim oIndexvalue + ' Dim r As Regex = New Regex(oRegExArg, RegexOptions.IgnoreCase) + ' ' ' Match the regular expression pattern against a text string. + ' Dim m As Match = r.Match(oIndex2) + ' Do While m.Success + + ' ' oClearedBodyText = oClearedBodyText.Replace(m.Value, "") + ' 'Dim g As Group = m.Groups(1) + ' Dim g1 As Group = m.Groups(2) + ' Dim g2 As Group = m.Groups(3) + + ' If Not IsNothing(g2.Value) Then + ' oIndexvalue = g2.Value + ' Console.WriteLine($"Indexvalue: {oIndexvalue}") + ' End If + + ' If Len(oIndexvalue) > 0 Then + ' If WMIndices.Contains(oIndexName) Then + ' LOGGER.Info($"Setting Index: oIndexName [{oIndexName}] - oIndexvalue [{oIndexvalue}]") + + ' 'DEBUG + ' oIndexvalue = New List(Of String) From {"Wert 1", "Wert 2", "wert 3"} + ' 'DEBUG + + ' If WINDREAM.SetFileIndex(oTargetPath, oIndexName, oIndexvalue, oWMObjecttype) = False Then + ' LOGGER.Info($"Index could not be set...") + ' If WINDREAM.RemoveFile(oTargetPath) = True Then + ' LOGGER.Info($"File deleted after error!") + ' End If + ' oResult = False + ' Exit For + ' End If + ' Else + ' LOGGER.Warn($"Transmitted index with name [{oIndexName}] is not existing in WM Objecttype!") + ' If WINDREAM.RemoveFile(oTargetPath) = True Then + ' LOGGER.Info($"File deleted after error!") + ' End If + ' oResult = False + ' Exit For + ' End If + ' End If + ' m = m.NextMatch() + ' Loop + ' Next + ' If oResult = True Then + ' LOGGER.Info("## All Tasks finished ##") + ' oErrorImport = False + ' End If + 'End If + Return oResult Catch ex As Exception LOGGER.Warn($"Unexpected Error in StreamORIndexFile: {ex.Message}") @@ -325,14 +392,4 @@ Module Module1 Return False End Try End Function - Private Function WMIndex_exists(pIndex As String) - Dim oexist As Boolean = False - For Each oWMIndex As String In WMIndices - If oWMIndex = pIndex Then - Return True - End If - Next - Return oexist - End Function - End Module diff --git a/WIDigConsoleApp/Runtime.vb b/WIDigConsoleApp/ModuleRuntime.vb similarity index 89% rename from WIDigConsoleApp/Runtime.vb rename to WIDigConsoleApp/ModuleRuntime.vb index 263bed8..f428423 100644 --- a/WIDigConsoleApp/Runtime.vb +++ b/WIDigConsoleApp/ModuleRuntime.vb @@ -1,7 +1,7 @@ Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Windream Imports DigitalData.Modules.Config -Module Runtime +Module ModuleRuntime Public LOGCONFIG As LogConfig Public LOGGER As Logger Public WINDREAM As Windream @@ -13,7 +13,7 @@ Module Runtime Public oSourceFile As String Public oTargetPath As String Public oWMObjecttype As String - Public oIndexArr As String() + Public oIndexArr As List(Of String) Public WMIndices As List(Of String) Public oExtension As String End Module \ No newline at end of file diff --git a/WIDigConsoleApp/WIDigConsoleApp.vbproj b/WIDigConsoleApp/WIDigConsoleApp.vbproj index c23fb27..bc093a8 100644 --- a/WIDigConsoleApp/WIDigConsoleApp.vbproj +++ b/WIDigConsoleApp/WIDigConsoleApp.vbproj @@ -6,7 +6,7 @@ AnyCPU {B146A4E7-FD28-4F57-9BE0-C4178A258623} Exe - WIDigConsoleApp.Module1 + WIDigConsoleApp.ModuleMain WIDigConsoleApp WIDigConsoleApp 512 @@ -87,7 +87,7 @@ - + True @@ -103,7 +103,7 @@ Settings.settings True - + diff --git a/WIDigConsoleApp/WIDigConsoleApp.vbproj.user b/WIDigConsoleApp/WIDigConsoleApp.vbproj.user index 5fa9ddd..76527ab 100644 --- a/WIDigConsoleApp/WIDigConsoleApp.vbproj.user +++ b/WIDigConsoleApp/WIDigConsoleApp.vbproj.user @@ -1,6 +1,6 @@  - -Mode%40IMPV -Source%40E:\TEMP\TEST.pdf -Target%40"W:\ImportWIDIG\Testfile1.pdf" -WMOT%40"DIGITAL DATA - Entwicklung" -index%40Integer 24={0815}#~#Vektor_Text1={"Wert 1"~#~"Wert 2"} + -Mode%40NI -Source%40"\\Windream\Objects\ImportWIDIG\Testfile2.pdf" -Target%40"W:\ImportWIDIG\Testfile2.pdf" -WMOT%40"DIGITAL DATA - Entwicklung" -index%40Integer 24={0815}#~#Vektor_Text1={"Wert 1"~#~"Wert 2"} \ No newline at end of file