Fix indexing for NI, dont overwrite existing vector entries

This commit is contained in:
Jonathan Jenne 2021-07-29 15:05:41 +02:00
parent 6cd68bd776
commit cbe113aea4
5 changed files with 144 additions and 87 deletions

View File

@ -6,7 +6,7 @@ Public Class ClassConfig
Public Property ConnectionString As String = "" Public Property ConnectionString As String = ""
Public Property WMUsername As String = "" Public Property WMUsername As String = ""
Public Property WMUserPW 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 WMRelPath As String = ""
Public Property WMServer As String = "" Public Property WMServer As String = ""
Public Property Domain As String = "" Public Property Domain As String = ""

View File

@ -6,18 +6,29 @@ Imports System.IO
Imports System.Text.RegularExpressions Imports System.Text.RegularExpressions
Imports DigitalData.Modules.Database Imports DigitalData.Modules.Database
Module Module1 Module ModuleMain
Private _ArgumentLength As Integer Private _ArgumentLength As Integer
Public _database As MSSQLServer Public _database As MSSQLServer
Public oRegExArg As String Public oRegExArg As String
Public oRegex As New Regex("([\s\S]+)\={([\s\S]+)}")
Public Const CODE_SUCCESS = 0 Public Const CODE_SUCCESS = 0
Public Const CODE_ERROR = 1 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 Public Function Main(CommandLineArguments As String()) As Integer
Dim oReturnResult As Integer Dim oReturnResult As Integer
Try Try
oReturnResult = CODE_SUCCESS oReturnResult = CODE_SUCCESS
' Console.WriteLine("Starting up WIDig...") ' Console.WriteLine("Starting up WIDig...")
Dim opath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) Dim opath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
@ -102,7 +113,6 @@ Module Module1
Return False Return False
End Try End Try
End Function End Function
Public Function Load_DB_DAta() Public Function Load_DB_DAta()
Try Try
Dim oSql = "SELECT [REGEX] FROM [TBDD_FUNCTION_REGEX] WHERE FUNCTION_NAME = 'WM-INDEXER-INDEX_GROUP'" Dim oSql = "SELECT [REGEX] FROM [TBDD_FUNCTION_REGEX] WHERE FUNCTION_NAME = 'WM-INDEXER-INDEX_GROUP'"
@ -133,15 +143,15 @@ Module Module1
End Function End Function
Private Function GetUserPWPlain() Private Function GetUserPWPlain()
Try Try
Dim PWplainText As String Dim oPassword As String
Dim wrapper As New ClassEncryption("!35452didalog=") Dim oEncryption As New ClassEncryption("!35452didalog=")
If CONFIG.Config.WMUserPW = String.Empty Then If CONFIG.Config.WMUserPW = String.Empty Then
PWplainText = "" oPassword = ""
Else Else
PWplainText = wrapper.DecryptData(CONFIG.Config.WMUserPW) oPassword = oEncryption.DecryptData(CONFIG.Config.WMUserPW)
End If End If
Return PWplainText Return oPassword
Catch ex As Exception Catch ex As Exception
LOGGER.Warn("Error in GetUserPWPlain - the password [" & CONFIG.Config.WMUserPW & "] could not be decrypted", False) LOGGER.Warn("Error in GetUserPWPlain - the password [" & CONFIG.Config.WMUserPW & "] could not be decrypted", False)
Return String.Empty Return String.Empty
@ -159,12 +169,12 @@ Module Module1
Return False Return False
End If End If
Dim ocount As Integer = 0 Dim oCount As Integer = 0
For Each oArg As String In pArguments For Each oArg As String In pArguments
LOGGER.Debug($"[{ocount}] {oArg}") LOGGER.Debug($"[{oCount}] {oArg}")
oArg = oArg.Replace("""", "") oArg = oArg.Replace("""", "")
If oArg.StartsWith("-Source@") Then If oArg.StartsWith(PARAM_SOURCE) Then
oSourceFile = oArg.Replace("-Source@", "") oSourceFile = oArg.Replace(PARAM_SOURCE, "")
If IsNumeric(oSourceFile) Then If IsNumeric(oSourceFile) Then
LOGGER.Info($"SourceFile seems to be a DocID [{oSourceFile}]") LOGGER.Info($"SourceFile seems to be a DocID [{oSourceFile}]")
Dim oSQL = $"SELECT [dbo].[FNDD_GET_WINDREAM_FILE_PATH] ({oSourceFile})" Dim oSQL = $"SELECT [dbo].[FNDD_GET_WINDREAM_FILE_PATH] ({oSourceFile})"
@ -177,11 +187,11 @@ Module Module1
Return False Return False
End If End If
ElseIf oArg.StartsWith("-Mode@") Then ElseIf oArg.StartsWith(PARAM_MODE) Then
oMode = oArg.Replace("-Mode@", "").ToUpper oMode = oArg.Replace(PARAM_MODE, "").ToUpper
ElseIf oArg.StartsWith("-Target@") Then ElseIf oArg.StartsWith(PARAM_TARGET) Then
oTargetPath = oArg.Replace("-Target@", "") oTargetPath = oArg.Replace(PARAM_TARGET, "")
If IsNumeric(oTargetPath) Then If IsNumeric(oTargetPath) Then
LOGGER.Info($"Target seems to be a DocID [{oTargetPath}]") LOGGER.Info($"Target seems to be a DocID [{oTargetPath}]")
Dim oSQL = $"SELECT [dbo].[FNDD_GET_WINDREAM_FILE_PATH] ({oTargetPath})" Dim oSQL = $"SELECT [dbo].[FNDD_GET_WINDREAM_FILE_PATH] ({oTargetPath})"
@ -194,7 +204,7 @@ Module Module1
If WINDREAM.TestFileExists(oTargetPath) = False Then If WINDREAM.TestFileExists(oTargetPath) = False Then
LOGGER.Info($"WMFile [{oTargetPath}] not existing!") LOGGER.Info($"WMFile [{oTargetPath}] not existing!")
End If End If
If oMode = "IMPV" Then If oMode = MODE_VERSION Then
Dim oWMCheckPath = WINDREAM.VersionWMFilename(oTargetPath, System.IO.Path.GetExtension(oTargetPath)) Dim oWMCheckPath = WINDREAM.VersionWMFilename(oTargetPath, System.IO.Path.GetExtension(oTargetPath))
If oNormalizePath.ToUpper <> oWMCheckPath.ToString.ToUpper Then If oNormalizePath.ToUpper <> oWMCheckPath.ToString.ToUpper Then
LOGGER.Info($"Target [{oNormalizePath}] already existed!! - NewWMFilename [{oWMCheckPath}]") LOGGER.Info($"Target [{oNormalizePath}] already existed!! - NewWMFilename [{oWMCheckPath}]")
@ -204,8 +214,8 @@ Module Module1
'Checks and creates the path if necessary 'Checks and creates the path if necessary
WINDREAM.NewFolder(oTargetPath, oExtension) WINDREAM.NewFolder(oTargetPath, oExtension)
ElseIf oArg.StartsWith("-WMOT@") Then ElseIf oArg.StartsWith(PARAM_WMTO) Then
oWMObjecttype = oArg.Replace("-WMOT@", "") oWMObjecttype = oArg.Replace(PARAM_WMTO, "")
Dim oexists As Boolean = False Dim oexists As Boolean = False
Dim myWMOTypes = WINDREAM.ObjectTypes Dim myWMOTypes = WINDREAM.ObjectTypes
For Each otype As String In myWMOTypes For Each otype As String In myWMOTypes
@ -222,22 +232,30 @@ Module Module1
Else Else
WMIndices = WINDREAM.GetIndiciesByObjecttype(oWMObjecttype) WMIndices = WINDREAM.GetIndiciesByObjecttype(oWMObjecttype)
End If End If
ElseIf oArg.StartsWith("-index@") Then ElseIf oArg.StartsWith(PARAM_INDEX) Then
oINDEXInfotemp = oArg oINDEXInfotemp = oArg
oINDEXInfoStarted = True oINDEXInfoStarted = True
oINDEXInfotemp = oINDEXInfotemp.Replace("-index@", "") oINDEXInfotemp = oINDEXInfotemp.Replace(PARAM_INDEX, "")
Else Else
If oINDEXInfoStarted Then If oINDEXInfoStarted Then
oINDEXInfotemp &= " " & oArg oINDEXInfotemp &= " " & oArg
End If End If
End If End If
ocount += 1 oCount += 1
Next 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 oIndexArr = oIndexparts
Return True Return True
Catch ex As Exception Catch ex As Exception
@ -253,71 +271,120 @@ Module Module1
Public Function StreamORIndexFile() Public Function StreamORIndexFile()
Try Try
Dim oResult As Boolean = False Dim oResult As Boolean = False
If oMode = "IMPV" Then If oMode = MODE_VERSION Then
oResult = WINDREAM.NewFileStream(oSourceFile, oTargetPath) oResult = WINDREAM.NewFileStream(oSourceFile, oTargetPath)
ElseIf oMode = "IMPO" Then ElseIf oMode = MODE_OVERWRITE Then
Dim oDeleted = WINDREAM.RemoveFile(oTargetPath) Dim oDeleted = WINDREAM.RemoveFile(oTargetPath)
If oDeleted = True Then If oDeleted = True Then
oResult = WINDREAM.NewFileStream(oSourceFile, oTargetPath) oResult = WINDREAM.NewFileStream(oSourceFile, oTargetPath)
Else Else
LOGGER.Warn($"Mode ImportOverwrite is active - but WMFile could not be deleted!!") LOGGER.Warn($"Mode ImportOverwrite is active - but WMFile could not be deleted!!")
End If End If
ElseIf oMode = "NI" Then ElseIf oMode = MODE_NACHINDEXIERUNG Then
oResult = True oResult = True
End If End If
If oResult = True Then If oResult = True Then
If oMode <> "NI" Then If oMode <> MODE_NACHINDEXIERUNG Then
LOGGER.Info($"File successfully streamed to windream [{oTargetPath}]! Now indexing...") LOGGER.Info($"File successfully streamed to windream [{oTargetPath}]! Now indexing...")
End If End If
For Each oIndex2 As String In oIndexArr For Each oIndex As String In oIndexArr
Dim oIndexInfo() = oIndex2.Split("={") Dim oMatch As Match = oRegex.Match(oIndex)
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, "") If oMatch.Success Then
'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 Dim oIndexName = oMatch.Groups(1)?.Value
oIndexvalue = g2.Value Dim oIndexValues = oMatch.Groups.Item(2)?.Value
Console.WriteLine($"Indexvalue: {oIndexvalue}") 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 End If
If Len(oIndexvalue) > 0 Then
If WMIndex_exists(oIndexName) = True Then oResult = oIndexResult
LOGGER.Info($"Setting Index: oIndexName [{oIndexName}] - oIndexvalue [{oIndexvalue}]") Else
If WINDREAM.SetFileIndex(oTargetPath, oIndexName, oIndexvalue, oWMObjecttype) = False Then oResult = False
LOGGER.Info($"Index could not be set...") End If
If WINDREAM.RemoveFile(oTargetPath) = True Then
LOGGER.Info($"File deleted after error!") If oResult = False Then
End If LOGGER.Warn("Indexing failed. Exiting.")
oResult = False Exit For
Exit For End If
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 Next
If oResult = True Then
LOGGER.Info("## All Tasks finished ##")
oErrorImport = False
End If
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 Return oResult
Catch ex As Exception Catch ex As Exception
LOGGER.Warn($"Unexpected Error in StreamORIndexFile: {ex.Message}") LOGGER.Warn($"Unexpected Error in StreamORIndexFile: {ex.Message}")
@ -325,14 +392,4 @@ Module Module1
Return False Return False
End Try End Try
End Function 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 End Module

View File

@ -1,7 +1,7 @@
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Windream Imports DigitalData.Modules.Windream
Imports DigitalData.Modules.Config Imports DigitalData.Modules.Config
Module Runtime Module ModuleRuntime
Public LOGCONFIG As LogConfig Public LOGCONFIG As LogConfig
Public LOGGER As Logger Public LOGGER As Logger
Public WINDREAM As Windream Public WINDREAM As Windream
@ -13,7 +13,7 @@ Module Runtime
Public oSourceFile As String Public oSourceFile As String
Public oTargetPath As String Public oTargetPath As String
Public oWMObjecttype As String Public oWMObjecttype As String
Public oIndexArr As String() Public oIndexArr As List(Of String)
Public WMIndices As List(Of String) Public WMIndices As List(Of String)
Public oExtension As String Public oExtension As String
End Module End Module

View File

@ -6,7 +6,7 @@
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B146A4E7-FD28-4F57-9BE0-C4178A258623}</ProjectGuid> <ProjectGuid>{B146A4E7-FD28-4F57-9BE0-C4178A258623}</ProjectGuid>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<StartupObject>WIDigConsoleApp.Module1</StartupObject> <StartupObject>WIDigConsoleApp.ModuleMain</StartupObject>
<RootNamespace>WIDigConsoleApp</RootNamespace> <RootNamespace>WIDigConsoleApp</RootNamespace>
<AssemblyName>WIDigConsoleApp</AssemblyName> <AssemblyName>WIDigConsoleApp</AssemblyName>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
@ -87,7 +87,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="ClassConfig.vb" /> <Compile Include="ClassConfig.vb" />
<Compile Include="ClassEncryption.vb" /> <Compile Include="ClassEncryption.vb" />
<Compile Include="Module1.vb" /> <Compile Include="ModuleMain.vb" />
<Compile Include="My Project\AssemblyInfo.vb" /> <Compile Include="My Project\AssemblyInfo.vb" />
<Compile Include="My Project\Application.Designer.vb"> <Compile Include="My Project\Application.Designer.vb">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
@ -103,7 +103,7 @@
<DependentUpon>Settings.settings</DependentUpon> <DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput> <DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile> </Compile>
<Compile Include="Runtime.vb" /> <Compile Include="ModuleRuntime.vb" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="My Project\Resources.resx"> <EmbeddedResource Include="My Project\Resources.resx">

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartArguments>-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"}</StartArguments> <StartArguments>-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"}</StartArguments>
</PropertyGroup> </PropertyGroup>
</Project> </Project>