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 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 = ""

View File

@ -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}")
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
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
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!")
oIndexResult = WINDREAM.SetFileIndex(oTargetPath, oIndexName, oIndexValueArray(0), oWMObjecttype)
End If
oResult = oIndexResult
Else
oResult = False
End If
If oResult = False Then
LOGGER.Warn("Indexing failed. Exiting.")
Exit For
End If
End If
m = m.NextMatch()
Loop
Next
End If
If oResult = True Then
LOGGER.Info("## All Tasks finished ##")
oErrorImport = False
End If
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

View File

@ -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

View File

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

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<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>
</Project>