MS New Version

This commit is contained in:
2021-04-23 12:08:10 +02:00
parent 08219ec327
commit a3d2226cbf
23 changed files with 510 additions and 99 deletions

View File

@@ -3,15 +3,18 @@ Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Windream
Imports DigitalData.Modules.Config
Imports System.IO
Imports System.Text.RegularExpressions
Imports DigitalData.Modules.Database
Module Module1
Private _ArgumentLength As Integer
Public _database As MSSQLServer
Public oRegExArg As String
Public Function Main(args As String()) As Integer
Try
' Console.WriteLine("Starting up WIDig...")
Dim opath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
Dim oLogConfig As New LogConfig(LogConfig.PathType.CustomPath,
opath & "\Digital Data\WIDigDat\Log",
Nothing,
Dim oLogConfig As New LogConfig(LogConfig.PathType.AppData, Nothing, Nothing,
"Digital Data",
"WIDigCons")
@@ -26,27 +29,36 @@ Module Module1
System.Console.WriteLine($"Starting up WIDig...")
If Connect2Windream(oUserPW) = True Then
System.Console.WriteLine($"Windream initialized!")
Dim oArguments As String() = Environment.GetCommandLineArgs()
If ParseArgs(args) = True Then
System.Console.WriteLine($"Parsed all arguments!")
If StreamIndexFile() = True Then
oErrorImport = False
If InitDatabase() = True Then
Load_DB_DAta()
'Dim oArguments As String() = Environment.GetCommandLineArgs()
If ParseArgs(args) = True Then
System.Console.WriteLine($"Parsed all arguments!")
If StreamIndexFile() = True Then
oErrorImport = False
Else
System.Console.WriteLine($"###Error in StreamIndexFile!####")
oErrorImport = True
End If
Else
System.Console.WriteLine($"###Error in StreamIndexFile!####")
oErrorImport = True
System.Console.WriteLine($"###Error in ParseArgs!####")
System.Console.WriteLine($"### Error in ParseArgs ####")
System.Console.WriteLine(oErrorMessage)
System.Console.WriteLine("### For more information check the log! Press any key to exit! ####")
System.Console.WriteLine($"####################")
Console.ReadKey()
End If
Else
System.Console.WriteLine($"###Error in ParseArgs!####")
System.Console.WriteLine($"### Error in ParseArgs ####")
System.Console.WriteLine(oErrorMessage)
System.Console.WriteLine("### For more information check the log! Press any key to exit! ####")
System.Console.WriteLine($"####################")
Console.ReadKey()
oErrorMessage = "Could not initialize DB"
End If
Else
oErrorMessage = "Could not initialize windream"
End If
If oErrorParse = True Or oErrorImport = True Then
System.Console.WriteLine(oErrorMessage)
System.Console.WriteLine("### For more information check the log! Press any key to exit! ####")
@@ -69,10 +81,39 @@ Module Module1
CONFIG = New ConfigManager(Of ClassConfig)(LOGCONFIG, oUserAppDataPath, System.AppDomain.CurrentDomain.BaseDirectory, oCommonAppDataPath)
System.Console.WriteLine($"Config loaded!")
LOGGER.Info("Config loaded")
'Settings_Load()
End Sub
Public Function InitDatabase() As Boolean
If My.Settings.MyECM_ConnectionString = String.Empty Then
Return False
End If
Try
_database = New MSSQLServer(LOGCONFIG, My.Settings.MyECM_ConnectionString)
If _database.DBInitialized = True Then
Return True
Else
Return False
End If
Catch ex As Exception
LOGGER.Error(ex)
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'"
oRegExArg = _database.GetScalarValue(oSql, 120)
If oRegExArg.Length = 0 Then
oRegExArg = 0
End If
Catch ex As Exception
LOGGER.Error(ex)
Return False
End Try
End Function
Private Function Connect2Windream(oPW As String)
Try
WINDREAM = New Windream(LOGCONFIG, False, CONFIG.Config.WMDrive, CONFIG.Config.WMRelPath, True, CONFIG.Config.WMServer, CONFIG.Config.WMUsername, oPW, CONFIG.Config.Domain)
@@ -104,6 +145,8 @@ Module Module1
End Try
End Function
Public Function ParseArgs(pArguments As String(), Optional pTest As Boolean = False)
Dim oINDEXInfoStarted As Boolean = False
Dim oINDEXInfotemp As String = ""
Try
If pArguments.Length <= 3 Then
_ArgumentLength = pArguments.Length
@@ -166,16 +209,22 @@ Module Module1
WMIndices = WINDREAM.GetIndiciesByObjecttype(oWMObjecttype)
End If
ElseIf oArg.StartsWith("-index@") Then
Dim oINDEXInfotemp = oArg
oINDEXInfotemp = oINDEXInfotemp.Replace("-index@{", "")
oINDEXInfotemp = oINDEXInfotemp.Replace("}", "")
Dim oSplit() = oINDEXInfotemp.ToString.Split(";")
LOGGER.Debug($" [{oSplit.Length}] Indices transmitted...")
oIndexArr = oSplit
oINDEXInfotemp = oArg
oINDEXInfoStarted = True
oINDEXInfotemp = oINDEXInfotemp.Replace("-index@", "")
Else
If oINDEXInfoStarted Then
oINDEXInfotemp &= " " & oArg
End If
End If
ocount += 1
Next
Dim oIndexparts As String() = oINDEXInfotemp.Split(New String() {"#~#"}, StringSplitOptions.RemoveEmptyEntries)
LOGGER.Info($" [{oIndexparts.Length}] Indices transmitted...")
oIndexArr = oIndexparts
Return True
Catch ex As Exception
LOGGER.Warn("Error in ParseArgs:" & vbNewLine & ex.Message)
@@ -205,28 +254,45 @@ Module Module1
If oResult = True Then
LOGGER.Info($"File successfully streamed to windream [{oTargetPath}]! Now indexing...")
For Each oIndex2 As String In oIndexArr
Dim oIndexInfo() = oIndex2.Split("=")
Dim oIndexInfo() = oIndex2.Split("={")
Dim oIndexName = oIndexInfo(0)
Dim oIndexvalue = oIndexInfo(1)
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
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 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
Next
If oResult = True Then
LOGGER.Info("Import finished!")