simplify main program structure, correct exit codes
This commit is contained in:
parent
c02aa0c745
commit
86fe78285c
@ -10,11 +10,15 @@ Module Module1
|
||||
Private _ArgumentLength As Integer
|
||||
Public _database As MSSQLServer
|
||||
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
|
||||
Try
|
||||
|
||||
oReturnResult = 0
|
||||
oReturnResult = CODE_SUCCESS
|
||||
' Console.WriteLine("Starting up WIDig...")
|
||||
Dim opath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
|
||||
Dim oLogConfig As New LogConfig(LogConfig.PathType.AppData, Nothing, Nothing,
|
||||
@ -27,57 +31,53 @@ Module Module1
|
||||
LOGCONFIG.Debug = CONFIG.Config.LOG_DEBUG
|
||||
LOGGER = LOGCONFIG.GetLogger
|
||||
Dim oUserPW = GetUserPWPlain()
|
||||
LOGGER.Debug("Initializing MainForm....")
|
||||
|
||||
System.Console.WriteLine($"Starting up WIDig...")
|
||||
|
||||
If Connect2Windream(oUserPW) = True Then
|
||||
System.Console.WriteLine($"Windream initialized!")
|
||||
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"
|
||||
|
||||
Throw New ApplicationException("Could not initialize windream")
|
||||
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
|
||||
System.Console.WriteLine(oErrorMessage)
|
||||
System.Console.WriteLine("### For more information check the log! Press any key to exit! ####")
|
||||
System.Console.WriteLine($"####################")
|
||||
Console.ReadKey()
|
||||
oReturnResult = 0
|
||||
Throw New ApplicationException(oErrorMessage)
|
||||
|
||||
Else
|
||||
oReturnResult = 1
|
||||
End If
|
||||
Return oReturnResult
|
||||
|
||||
Return CODE_SUCCESS
|
||||
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)
|
||||
Return oReturnResult
|
||||
|
||||
Return CODE_ERROR
|
||||
End Try
|
||||
|
||||
End Function
|
||||
@ -120,6 +120,7 @@ Module Module1
|
||||
If oRegExArg.Length = 0 Then
|
||||
oRegExArg = 0
|
||||
End If
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
Return False
|
||||
@ -134,6 +135,7 @@ Module Module1
|
||||
Return True
|
||||
End If
|
||||
End If
|
||||
Return False
|
||||
Catch ex As Exception
|
||||
LOGGER.Warn("CHECKING WMConnectivity: " & ex.Message)
|
||||
Return False
|
||||
@ -330,8 +332,8 @@ Module Module1
|
||||
Catch ex As Exception
|
||||
LOGGER.Warn($"Unexpected Error in StreamORIndexFile: {ex.Message}")
|
||||
LOGGER.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
|
||||
End Function
|
||||
Private Function WMIndex_exists(pIndex As String)
|
||||
Dim oexist As Boolean = False
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user