simplify main program structure, correct exit codes
This commit is contained in:
@@ -10,11 +10,15 @@ Module Module1
|
|||||||
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 Function Main(args As String()) As Integer
|
|
||||||
|
Public Const CODE_SUCCESS = 0
|
||||||
|
Public Const CODE_ERROR = 1
|
||||||
|
|
||||||
|
Public Function Main(CommandLineArguments As String()) As Integer
|
||||||
Dim oReturnResult As Integer
|
Dim oReturnResult As Integer
|
||||||
Try
|
Try
|
||||||
|
|
||||||
oReturnResult = 0
|
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)
|
||||||
Dim oLogConfig As New LogConfig(LogConfig.PathType.AppData, Nothing, Nothing,
|
Dim oLogConfig As New LogConfig(LogConfig.PathType.AppData, Nothing, Nothing,
|
||||||
@@ -27,57 +31,53 @@ Module Module1
|
|||||||
LOGCONFIG.Debug = CONFIG.Config.LOG_DEBUG
|
LOGCONFIG.Debug = CONFIG.Config.LOG_DEBUG
|
||||||
LOGGER = LOGCONFIG.GetLogger
|
LOGGER = LOGCONFIG.GetLogger
|
||||||
Dim oUserPW = GetUserPWPlain()
|
Dim oUserPW = GetUserPWPlain()
|
||||||
LOGGER.Debug("Initializing MainForm....")
|
|
||||||
|
|
||||||
System.Console.WriteLine($"Starting up WIDig...")
|
System.Console.WriteLine($"Starting up WIDig...")
|
||||||
|
|
||||||
If Connect2Windream(oUserPW) = True Then
|
If Connect2Windream(oUserPW) = True Then
|
||||||
System.Console.WriteLine($"Windream initialized!")
|
Throw New ApplicationException("Could not initialize windream")
|
||||||
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 StreamORIndexFile() = True Then
|
|
||||||
oErrorImport = False
|
|
||||||
oReturnResult = 1
|
|
||||||
Else
|
|
||||||
System.Console.WriteLine($"###Error in StreamIndexFile!####")
|
|
||||||
oErrorImport = True
|
|
||||||
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()
|
|
||||||
End If
|
|
||||||
|
|
||||||
|
|
||||||
Else
|
|
||||||
oErrorMessage = "Could not initialize DB"
|
|
||||||
End If
|
|
||||||
|
|
||||||
Else
|
|
||||||
oErrorMessage = "Could not initialize windream"
|
|
||||||
|
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
System.Console.WriteLine($"Windream initialized!")
|
||||||
|
|
||||||
|
If InitDatabase() = False Then
|
||||||
|
Throw New ApplicationException("Could not initialize DB")
|
||||||
|
End If
|
||||||
|
|
||||||
|
System.Console.WriteLine($"Database initialized!")
|
||||||
|
|
||||||
|
If Load_DB_DAta() = False Then
|
||||||
|
Throw New ApplicationException("Could not load Regex from Database")
|
||||||
|
End If
|
||||||
|
|
||||||
|
System.Console.WriteLine($"Regex loaded from Database!")
|
||||||
|
|
||||||
|
If ParseArgs(CommandLineArguments) = False Then
|
||||||
|
Throw New ApplicationException("Could not parse command line arguments")
|
||||||
|
End If
|
||||||
|
|
||||||
|
System.Console.WriteLine($"Command line arguments parsed!")
|
||||||
|
|
||||||
|
If StreamORIndexFile() = False Then
|
||||||
|
Throw New ApplicationException("Could not stream or index file")
|
||||||
|
End If
|
||||||
|
|
||||||
|
System.Console.WriteLine($"File indexed or streamed!")
|
||||||
|
|
||||||
|
' Brauchen Sie das überhaupt?
|
||||||
If oErrorParse = True Or oErrorImport = True Then
|
If oErrorParse = True Or oErrorImport = True Then
|
||||||
System.Console.WriteLine(oErrorMessage)
|
Throw New ApplicationException(oErrorMessage)
|
||||||
System.Console.WriteLine("### For more information check the log! Press any key to exit! ####")
|
|
||||||
System.Console.WriteLine($"####################")
|
|
||||||
Console.ReadKey()
|
|
||||||
oReturnResult = 0
|
|
||||||
|
|
||||||
Else
|
|
||||||
oReturnResult = 1
|
|
||||||
End If
|
End If
|
||||||
Return oReturnResult
|
|
||||||
|
Return CODE_SUCCESS
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
|
LOGGER.Warn("Could not process file because of an error: {0}", oErrorMessage)
|
||||||
|
LOGGER.Warn("Error at Parse Stage: [{0}]", oErrorParse)
|
||||||
|
LOGGER.Warn("Error at Import Stage: [{0}]", oErrorImport)
|
||||||
LOGGER.Error(ex)
|
LOGGER.Error(ex)
|
||||||
Return oReturnResult
|
|
||||||
|
Return CODE_ERROR
|
||||||
End Try
|
End Try
|
||||||
|
|
||||||
End Function
|
End Function
|
||||||
@@ -120,6 +120,7 @@ Module Module1
|
|||||||
If oRegExArg.Length = 0 Then
|
If oRegExArg.Length = 0 Then
|
||||||
oRegExArg = 0
|
oRegExArg = 0
|
||||||
End If
|
End If
|
||||||
|
Return True
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
LOGGER.Error(ex)
|
LOGGER.Error(ex)
|
||||||
Return False
|
Return False
|
||||||
@@ -134,6 +135,7 @@ Module Module1
|
|||||||
Return True
|
Return True
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
|
Return False
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
LOGGER.Warn("CHECKING WMConnectivity: " & ex.Message)
|
LOGGER.Warn("CHECKING WMConnectivity: " & ex.Message)
|
||||||
Return False
|
Return False
|
||||||
@@ -330,8 +332,8 @@ Module Module1
|
|||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
LOGGER.Warn($"Unexpected Error in StreamORIndexFile: {ex.Message}")
|
LOGGER.Warn($"Unexpected Error in StreamORIndexFile: {ex.Message}")
|
||||||
LOGGER.Error(ex)
|
LOGGER.Error(ex)
|
||||||
|
Return False
|
||||||
End Try
|
End Try
|
||||||
|
|
||||||
End Function
|
End Function
|
||||||
Private Function WMIndex_exists(pIndex As String)
|
Private Function WMIndex_exists(pIndex As String)
|
||||||
Dim oexist As Boolean = False
|
Dim oexist As Boolean = False
|
||||||
|
|||||||
Reference in New Issue
Block a user