diff --git a/CSE/Calculation/Minor_routines_calculate.vb b/CSE/Calculation/Minor_routines_calculate.vb index cac666760a803f4ca9f7468d92783ba668a42a5e..15f532a055bdd11db7397df4d508ee57d0a617bd 100644 --- a/CSE/Calculation/Minor_routines_calculate.vb +++ b/CSE/Calculation/Minor_routines_calculate.vb @@ -36,7 +36,7 @@ ElseIf Dy < 0 And DX = 0 Then QuadReq = 180 Else - fInfWarErrBW(9, False, "The angle definition is not possible") + fInfWarErr(9, False, "The angle definition is not possible") QuadReq = "x" End If End Function @@ -59,7 +59,7 @@ If i = 1 Then tstep = TimeX(i) - TimeX(i - 1) If tstep + (tstep * delta_Hz_max / 100) < Math.Abs(TimeX(i) - TimeX(i - 1)) Or tstep - (tstep * delta_Hz_max / 100) > Math.Abs(TimeX(i) - TimeX(i - 1)) Then If Sprung Then - fInfWarErrBW(9, False, "Time step invalid! t(" & i - 1 & ") = " & TimeX(i - 1) & "[s], t(" & i & ") = " & TimeX(i) & "[s]") + fInfWarErr(9, False, "Time step invalid! t(" & i - 1 & ") = " & TimeX(i - 1) & "[s], t(" & i & ") = " & TimeX(i) & "[s]") Return False Else Sprung = True @@ -130,7 +130,7 @@ If i = 1 Then tstep = TimeX(i) - TimeX(i - 1) If tstep + (tstep * delta_Hz_max / 100) < Math.Abs(TimeX(i) - TimeX(i - 1)) Or tstep - (tstep * delta_Hz_max / 100) > Math.Abs(TimeX(i) - TimeX(i - 1)) Then If Sprung Then - fInfWarErrBW(9, False, "Time step invalid! t(" & i - 1 & ") = " & TimeX(i - 1) & "[s], t(" & i & ") = " & TimeX(i) & "[s]") + fInfWarErr(9, False, "Time step invalid! t(" & i - 1 & ") = " & TimeX(i - 1) & "[s], t(" & i & ") = " & TimeX(i) & "[s]") Return False Else Sprung = True @@ -203,7 +203,7 @@ 'Check whether Time is not reversed For z = 1 To UBound(TimeX) If TimeX(z) < TimeX(z - 1) Then - fInfWarErrBW(9, False, "Time step invalid! t(" & z - 1 & ") = " & TimeX(z - 1) & "[s], t(" & z & ") = " & TimeX(z) & "[s]") + fInfWarErr(9, False, "Time step invalid! t(" & z - 1 & ") = " & TimeX(z - 1) & "[s], t(" & z & ") = " & TimeX(z) & "[s]") Return False End If Next z @@ -339,12 +339,12 @@ Dim vline(), Line() As String ' Output on the GUI - fInfWarErrBW(5, False, "Read altitude file") + fInfWarErr(5, False, "Read altitude file") ' Open the MSC spezification file If Not FileInAlt.OpenRead(File) Then ' Error if the file is not available - fInfWarErrBW(9, False, "Can´t find the altitude file: " & File) + fInfWarErr(9, False, "Can´t find the altitude file: " & File) Return False End If @@ -353,7 +353,7 @@ vline = FileInAlt.ReadLine If dist < vline(0) Then - fInfWarErrBW(9, False, "The distance is lower then the minimum in the altitude file") + fInfWarErr(9, False, "The distance is lower then the minimum in the altitude file") BWorker.CancelAsync() fAltInterp = 0 End If @@ -431,7 +431,7 @@ ' Erreor message wehen lambda can not be calculated If i = 0 Then - fInfWarErrBW(9, False, "Was not able to calculate the distance and bearing between koordinates.") + fInfWarErr(9, False, "Was not able to calculate the distance and bearing between koordinates.") BWorker.CancelAsync() Return 0 ' formula failed to converge End If diff --git a/CSE/Calculation/Signal_identification.vb b/CSE/Calculation/Signal_identification.vb index 907b8aea0482d087733232b53265c6abd66a3d72..2a1b4fa1ebf6797c5131e1c7b121a1fb15f4d190 100644 --- a/CSE/Calculation/Signal_identification.vb +++ b/CSE/Calculation/Signal_identification.vb @@ -8,7 +8,7 @@ If SectionDev Then ' Output on the GUI - fInfWarErrBW(6, False, "Identifying the sections") + fInfWarErr(6, False, "Identifying the sections") ' Devide the measured data into there sections DevInSec(vMSC) @@ -16,7 +16,7 @@ ' Leap in time control If JumpPoint <> -1 Then If CalcData(tCompCali.SecID)(JumpPoint) <> 0 Then - fInfWarErrBW(9, False, "The detected leap in time is inside a measurement section. This is not allowed!") + fInfWarErr(9, False, "The detected leap in time is inside a measurement section. This is not allowed!") BWorker.CancelAsync() Return False End If @@ -723,7 +723,7 @@ For j = 0 To InputWeatherData(tCompWeat.t).Count - 1 If j = 0 Then If CalcData(tCompCali.t)(i) < InputWeatherData(tCompWeat.t)(j) And j = 0 Then - fInfWarErrBW(9, False, "The test time is outside the range of the data from the stationary weather station.") + fInfWarErr(9, False, "The test time is outside the range of the data from the stationary weather station.") BWorker.CancelAsync() Return False ElseIf CalcData(tCompCali.t)(i) >= InputWeatherData(tCompWeat.t)(j) And CalcData(tCompCali.t)(i) < InputWeatherData(tCompWeat.t)(j + 1) Then @@ -741,7 +741,7 @@ End If End If If j = InputWeatherData(tCompWeat.t).Count - 1 Then - fInfWarErrBW(9, False, "The test time is outside the range of the data from the stationary weather station.") + fInfWarErr(9, False, "The test time is outside the range of the data from the stationary weather station.") BWorker.CancelAsync() Return False End If @@ -771,7 +771,7 @@ If CalcData(tCompCali.SecID)(i - 1) = CalcData(tCompCali.SecID)(i) And CalcData(tCompCali.SecID)(i + 1) = CalcData(tCompCali.SecID)(i) Then If (CalcData(tCompCali.dist_root)(i + 1) - CalcData(tCompCali.dist_root)(i - 1)) = 0 Then CalcData(tCompCali.slope_deg)(i) = 0 - fInfWarErrBW(9, False, "Standstill or loss of vehicle speed signal inside MS not permitted (Error at line " & i & ")") + fInfWarErr(9, False, "Standstill or loss of vehicle speed signal inside MS not permitted (Error at line " & i & ")") BWorker.CancelAsync() Else CalcData(tCompCali.slope_deg)(i) = (Math.Asin((CalcData(tCompCali.alt)(i + 1) - CalcData(tCompCali.alt)(i - 1)) / (CalcData(tCompCali.dist_root)(i + 1) - CalcData(tCompCali.dist_root)(i - 1)))) * 180 / Math.PI diff --git a/CSE/Calculation/main_calculation_call.vb b/CSE/Calculation/main_calculation_call.vb index 204f927869087e1bf61576d7d367ff0544574475..37211e21155789946050260147a1b21d0c7f0621 100644 --- a/CSE/Calculation/main_calculation_call.vb +++ b/CSE/Calculation/main_calculation_call.vb @@ -20,7 +20,7 @@ Dim vMSC As New cVirtMSC ' Read the input data - fInfWarErrBW(7, False, "Reading Input Files...") + fInfWarErr(7, False, "Reading Input Files...") Dim vehicle As New cVehicle(Vehspez) ReadInputMSC(MSC, MSCCSpez, isCalibrate) ReadDataFile(DataSpez(1), MSC) @@ -29,7 +29,7 @@ If BWorker.CancellationPending Then Return False ' Output on the GUI - fInfWarErrBW(7, False, "Calculating the calibration run...") + fInfWarErr(7, False, "Calculating the calibration run...") ' Identify the signal measurement sections fIdentifyMS(MSC, vMSC) @@ -38,7 +38,7 @@ If BWorker.CancellationPending Then Return False ' Output on the GUI - fInfWarErrBW(6, False, "Calculating the calibration run parameter") + fInfWarErr(6, False, "Calculating the calibration run parameter") ' Calculate the results from the calibration test fCalcCalib(MSC, vehicle) @@ -47,7 +47,7 @@ 'If BWorker.CancellationPending Then Return False ' Output on the GUI - fInfWarErrBW(7, False, "Writing the output files...") + fInfWarErr(7, False, "Writing the output files...") ' Output fOutDataCalc1Hz(DataSpez(1), isCalibrate) @@ -58,10 +58,10 @@ Dim vMSC As New cVirtMSC ' Output on the GUI - fInfWarErrBW(7, False, "Calculating the speed runs...") + fInfWarErr(7, False, "Calculating the speed runs...") ' Read the input files - fInfWarErrBW(7, False, "Reading Input Files...") + fInfWarErr(7, False, "Reading Input Files...") Dim vehicle As New cVehicle(Vehspez) ReadInputMSC(MSC, MSCTSpez, isCalibrate) ReadWeather(Ambspez) @@ -77,17 +77,17 @@ If i = 2 Or i = 4 Then ' Output on the GUI If i = 2 Then - fInfWarErrBW(7, False, "Calculating the first low speed run...") + fInfWarErr(7, False, "Calculating the first low speed run...") Else - fInfWarErrBW(7, False, "Calculating the second low speed run...") + fInfWarErr(7, False, "Calculating the second low speed run...") End If Else ' Output on the GUI - fInfWarErrBW(7, False, "Calculating the high speed run...") + fInfWarErr(7, False, "Calculating the high speed run...") End If ' Output on the GUI - fInfWarErrBW(6, False, "Reading the data file...") + fInfWarErr(6, False, "Reading the data file...") ReadDataFile(DataSpez(i), MSC) ' Exit function if error is detected @@ -106,7 +106,7 @@ If BWorker.CancellationPending Then Return False ' Output on the GUI - fInfWarErrBW(6, False, "Writing the output files...") + fInfWarErr(6, False, "Writing the output files...") ' Output fOutDataCalc1Hz(DataSpez(i), isCalibrate) @@ -133,7 +133,7 @@ ' Exit function if error is detected If BWorker.CancellationPending Then ' Write the summerised output file - fInfWarErrBW(7, False, "Writing the summarised output file...") + fInfWarErr(7, False, "Writing the summarised output file...") fOutCalcRes(DataSpez, isCalibrate) Return False End If @@ -142,7 +142,7 @@ fCalcReg(vehicle) ' Write the summerised output file - fInfWarErrBW(7, False, "Writing the summarised output file...") + fInfWarErr(7, False, "Writing the summarised output file...") fOutCalcRes(DataSpez, isCalibrate) ' Check if all is valid @@ -155,10 +155,10 @@ fOutCalcResReg(DataSpez) ' Write the results on the GUI - fInfWarErrBW(7, False, "Results from the calculation") - fInfWarErrBW(6, False, "average absolute beta HS test: " & Math.Round(beta, 4)) - fInfWarErrBW(6, False, "delta CdxA correction: " & Math.Round(delta_CdxA, 4)) - fInfWarErrBW(6, False, "CdxA(0): " & Math.Round(CdxA0, 4)) + fInfWarErr(7, False, "Results from the calculation") + fInfWarErr(6, False, "average absolute beta HS test: " & Math.Round(beta, 4)) + fInfWarErr(6, False, "delta CdxA correction: " & Math.Round(delta_CdxA, 4)) + fInfWarErr(6, False, "CdxA(0): " & Math.Round(CdxA0, 4)) ' Clear the dictionaries ErgValuesComp = Nothing @@ -221,7 +221,7 @@ ' Error If run > 10 Then - fInfWarErrBW(9, False, "The calibration is not possible because iteration for valid datasets does not converge (n>10)") + fInfWarErr(9, False, "The calibration is not possible because iteration for valid datasets does not converge (n>10)") Change = False BWorker.CancelAsync() Return False @@ -309,7 +309,7 @@ ' error message if the CAN velocity is 0 For i = 0 To UBound(CalcX) If ave_vn(i) = 0 And VSec(i) = 1 Then - fInfWarErrBW(9, False, "The measured vehicle velocity (v_veh_CAN) is 0 in section: " & CalcX(i)) + fInfWarErr(9, False, "The measured vehicle velocity (v_veh_CAN) is 0 in section: " & CalcX(i)) BWorker.CancelAsync() Return False End If @@ -552,7 +552,7 @@ ' Ceck if enough sections are detected If SecCount.AnzSec.Count - 1 < 1 Then - fInfWarErrBW(9, False, "Insufficent numbers of valid measurement sections available") + fInfWarErr(9, False, "Insufficent numbers of valid measurement sections available") BWorker.CancelAsync() Return False End If @@ -613,7 +613,7 @@ End If Next i If anz < 2 Then - fInfWarErrBW(9, False, "Insufficent numbers of valid measurement sections available") + fInfWarErr(9, False, "Insufficent numbers of valid measurement sections available") BWorker.CancelAsync() Return False End If @@ -701,7 +701,7 @@ ' Ceck if enough sections are detected If SecCount.AnzSec.Count - 1 < 1 Then - fInfWarErrBW(9, False, "Insufficent numbers of valid measurement sections in the low speed test available") + fInfWarErr(9, False, "Insufficent numbers of valid measurement sections in the low speed test available") BWorker.CancelAsync() Return False End If @@ -741,7 +741,7 @@ End If End If Else - fInfWarErrBW(9, False, "Not enough valid data for low speed tests available in section " & Trim(Mid(SecCount.NameSec(i), 1, InStr(SecCount.NameSec(i), "(") - 2))) + fInfWarErr(9, False, "Not enough valid data for low speed tests available in section " & Trim(Mid(SecCount.NameSec(i), 1, InStr(SecCount.NameSec(i), "(") - 2))) End If End If Next j @@ -817,7 +817,7 @@ ' Ceck if enough sections are detected If SecCount.AnzSec.Count - 1 < 1 Then - fInfWarErrBW(9, False, "Insufficent numbers of valid measurement sections in the high speed test available") + fInfWarErr(9, False, "Insufficent numbers of valid measurement sections in the high speed test available") BWorker.CancelAsync() Return False End If @@ -835,12 +835,12 @@ Case 2 anzHS2 += SecCount.AnzSec(i) + SecCount.AnzSec(j) Case Else - fInfWarErrBW(9, False, "headID not known") + fInfWarErr(9, False, "headID not known") BWorker.CancelAsync() Return False End Select Else - fInfWarErrBW(9, False, "Not enough valid data for high speed tests available in section " & Trim(Mid(SecCount.NameSec(i), 1, InStr(SecCount.NameSec(i), "(") - 2))) + fInfWarErr(9, False, "Not enough valid data for high speed tests available in section " & Trim(Mid(SecCount.NameSec(i), 1, InStr(SecCount.NameSec(i), "(") - 2))) BWorker.CancelAsync() End If End If @@ -849,7 +849,7 @@ ' Ceck if enough sections are detected If anzHS1 < ds_min_head_MS Or anzHS2 < ds_min_head_MS Then - fInfWarErrBW(9, False, "Number of valid high speed datasets too low") + fInfWarErr(9, False, "Number of valid high speed datasets too low") BWorker.CancelAsync() 'Return False End If diff --git a/CSE/Calculation/sub_linear_regression.vb b/CSE/Calculation/sub_linear_regression.vb index 2952990aba780394a871fec2126849f01db0372f..c60fe3500c1449889518c9a3327dd27201e0151c 100644 --- a/CSE/Calculation/sub_linear_regression.vb +++ b/CSE/Calculation/sub_linear_regression.vb @@ -10,7 +10,7 @@ Dim EnumStr As tCompErgReg ' Output on the GUI - fInfWarErrBW(7, False, "Calculate the linear regression...") + fInfWarErr(7, False, "Calculate the linear regression...") ' Initialisation lauf = -1 @@ -322,16 +322,16 @@ ' Test validation t_amb_f = t_amb_f / t_amb_num If (t_amb_f - t_amb_min_f) > t_amb_var Or (t_amb_max_f - t_amb_f) > t_amb_var Then - fInfWarErrBW(9, False, "Invalid test - variation of ambient temperature (at the vehicle) outside boundaries") + fInfWarErr(9, False, "Invalid test - variation of ambient temperature (at the vehicle) outside boundaries") valid_t_amb = False End If If t_amb_max_f > t_amb_max Then - fInfWarErrBW(9, False, "Invalid test - maximum ambient temperature exceeded") + fInfWarErr(9, False, "Invalid test - maximum ambient temperature exceeded") ElseIf t_amb_min_f < t_amb_min Then - fInfWarErrBW(9, False, "Invalid test - fallen below minimum ambient temperature") + fInfWarErr(9, False, "Invalid test - fallen below minimum ambient temperature") ElseIf t_amb_max_f > t_amb_tarmac Then - fInfWarErrBW(9, False, "Invalid test - Ambient temperature higher than " & t_amb_tarmac & "°C") + fInfWarErr(9, False, "Invalid test - Ambient temperature higher than " & t_amb_tarmac & "°C") End If Return True @@ -414,10 +414,10 @@ End If If i = GenShape.x_val(pos).Length - 1 And beta > GenShape.x_val(pos)(i + 1) Then ValueX = 0 - fInfWarErrBW(8, False, "The calculated yaw angle is higher than the greatest value in the generic curve. Delta_CdxA is set to 0!") + fInfWarErr(8, False, "The calculated yaw angle is higher than the greatest value in the generic curve. Delta_CdxA is set to 0!") ElseIf i = 0 And GenShape.x_val(pos)(i) > beta Then ValueX = 0 - fInfWarErrBW(8, False, "The calculated yaw angle is lower than the lowest value in the generic curve. Delta_CdxA is set to 0!") + fInfWarErr(8, False, "The calculated yaw angle is lower than the lowest value in the generic curve. Delta_CdxA is set to 0!") End If Next i diff --git a/CSE/GUI/F_Main.vb b/CSE/GUI/F_Main.vb index 05dec25930953cc2d56b8c7c92a9956d2ccec3d0..7a11dc96d6fb6d7de44c27e277e2330877d84b7e 100644 --- a/CSE/GUI/F_Main.vb +++ b/CSE/GUI/F_Main.vb @@ -25,6 +25,9 @@ Public Class F_Main ' Name of the GUI Me.Text = AppName & " " & AppVers + ' Write the beginning in the Log + fWriteLog(1) + ' Load the config file ' Try @@ -47,9 +50,6 @@ Public Class F_Main IO.Directory.CreateDirectory(AppPreferences.workingDir) End If - ' Write the beginning in the Log - fWriteLog(1) - 'Lizenz checken If Not Lic.LICcheck() Then fInfWarErr(9, True, Lic.FailMsg) @@ -223,8 +223,7 @@ Public Class F_Main Me.ListBoxMSG.Items.Clear() fClear_VECTO_Form(False, False) - fInfWarErr(7, False, "Starting VECTO CSE calibration calculation...") - If AppPreferences.writeLog Then fWriteLog(2, 4, "------------- Job: " & JobFile & " | Out: " & OutFolder & " | " & CDate(DateAndTime.Now) & "-------------") + fInfWarErr(7, False, format("Starting CALIBRATION: \n\i* Job: {0}\n* Out: {1}", JobFile, OutFolder)) ' Start the calculation in the backgroundworker Me.BackgroundWorkerVECTO.RunWorkerAsync() @@ -376,7 +375,7 @@ Public Class F_Main fClear_VECTO_Form(False, False) ' Write the Calculation status in the Messageoutput and in the Log - fInfWarErr(7, False, "Starting VECTO CSE test evaluation...") + fInfWarErr(7, False, format("Starting EVALUATION: \n\i* Job: {0}\n* Out: {1}", JobFile, OutFolder)) ' Start the calculation in the backgroundworker Me.BackgroundWorkerVECTO.RunWorkerAsync() @@ -561,14 +560,15 @@ Public Class F_Main '*********Backgroundworker********* ' Backgroundworker for the calculation in the background - Private Sub BackgroundWorkerVECTO_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorkerVECTO.DoWork + Private Sub BackgroundWorkerVECTO_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) _ + Handles BackgroundWorkerVECTO.DoWork '##### START THE CALCULATION ##### '################################# Try calculation(Cali) Catch ex As Exception - fInfWarErrBW(9, False, format("Calculation Failed due to: {0}", ex.Message), ex) + fInfWarErr(9, False, format("Calculation Failed due to: {0}", ex.Message), ex) End Try '################################# @@ -580,37 +580,33 @@ Public Class F_Main End Sub ' Output from messages with the Backgroundworker - Private Sub BackgroundWorkerVECTO_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorkerVECTO.ProgressChanged - ' Declarations - Dim WorkerMsg As CMsg - WorkerMsg = New CMsg - - ' Identify the Message - WorkerMsg = e.UserState - - If e.UserState Is Nothing Then + Private Sub BackgroundWorkerVECTO_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) _ + Handles BackgroundWorkerVECTO.ProgressChanged - Else - ' Call the function for the depiction from the message on the GUI - WorkerMsg.MsgToForm() + Dim workerMsg As cLogMsg = e.UserState + If workerMsg IsNot Nothing Then + workerMsg.forwardLog() End If End Sub ' Identify the ending from the backgroundworker - Private Sub BackgroundWorkerVECTO_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorkerVECTO.RunWorkerCompleted + Private Sub BackgroundWorkerVECTO_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) _ + Handles BackgroundWorkerVECTO.RunWorkerCompleted + + Dim op = IIf(Cali, "Calibration", "Evaluation") + ' If an Error is detected If e.Error IsNot Nothing Then - fInfWarErr(7, False, "End with Error") - MsgBox(e.Error.Message) + fInfWarErr(8, True, format("{0} ended with exception: {1}", op, e.Error), e.Error) Else If e.Cancelled Then If ErrorExit Then - fInfWarErr(7, False, "End with Error") + fInfWarErr(8, False, format("{0} ended with exception: {1}", op, e.Error), e.Error) Else - fInfWarErr(7, False, "Aborted by user") + fInfWarErr(7, False, format("{0} aborted by user.", op)) End If Else - fInfWarErr(7, False, "Done") + fInfWarErr(7, False, format("{0} ended OK.", op)) If Cali Then Me.ButtonEval.Enabled = True End If End If diff --git a/CSE/GUI/utils_GUI.vb b/CSE/GUI/utils_GUI.vb index 240969c8b184d7387c1971d432b4e3ec74eda660..d27333dcf9ec30fd9a0cd0099608d95c937e9202 100644 --- a/CSE/GUI/utils_GUI.vb +++ b/CSE/GUI/utils_GUI.vb @@ -79,7 +79,7 @@ Module utils_GUI ' Open the jobfile If Not FileInVECTO.OpenRead(JobFile) Then ' Falls File nicht vorhanden, abbrechen mit Fehler - fInfWarErrBW(9, False, "Can´t find the Jobfile file: " & JobFile) + fInfWarErr(9, False, "Can´t find the Jobfile file: " & JobFile) Return False End If @@ -217,21 +217,21 @@ Module utils_GUI tq_sum_1s_delta = Line(0) End Select Else - fInfWarErrBW(9, False, "The given value in the job file at position: " & i & " is not a number") + fInfWarErr(9, False, "The given value in the job file at position: " & i & " is not a number") BWorker.CancelAsync() Return False End If Loop Catch ex As Exception ' Error - fInfWarErrBW(9, False, "Invalid value in the job file at position: " & i) + fInfWarErr(9, False, "Invalid value in the job file at position: " & i) BWorker.CancelAsync() Return False End Try ' Look if enough parameters are given If i < 34 Then - fInfWarErrBW(9, False, "Not enough parameters given in the job file") + fInfWarErr(9, False, "Not enough parameters given in the job file") BWorker.CancelAsync() Return False End If diff --git a/CSE/IO/OutputTest.vb b/CSE/IO/OutputTest.vb index 91fcf7df8bfd8253e04ffcd0fa702ea46aec4d6f..3914200b341f48db2e4f0cac3c9e8e06013c16d9 100644 --- a/CSE/IO/OutputTest.vb +++ b/CSE/IO/OutputTest.vb @@ -23,7 +23,7 @@ End If ' Write on GUI - fInfWarErrBW(5, False, "Write output-file (*.csv)") + fInfWarErr(5, False, "Write output-file (*.csv)") ' Generate the file name NameOutFile = OutFolder & fName(Datafile, False) & "_test.csv" @@ -64,7 +64,7 @@ ' Ausgabe bei blockierter Datei If BWorker.CancellationPending And FileBlock Then - fInfWarErrBW(9, False, "Can´t write in file " & NameOutFile & ". File is blocked by another process!") + fInfWarErr(9, False, "Can´t write in file " & NameOutFile & ". File is blocked by another process!") End If Return True diff --git a/CSE/IO/cJsonFile.vb b/CSE/IO/cJsonFile.vb index 00c402b767412d351e3f43f828640009dbb84840..cc59defd6f4c907f62b488870d3503b67cd126dc 100644 --- a/CSE/IO/cJsonFile.vb +++ b/CSE/IO/cJsonFile.vb @@ -100,7 +100,14 @@ Public MustInherit Class cJsonFile Protected MustOverride Sub ValidateBody(ByVal isStrict As Boolean, ByVal validateMsgs As IList(Of String)) - Protected Json_Contents As JObject + ''' <summary>The whole json-content receiving any changes, always ready to be written as is.</summary> + Private Content As JObject + + ''' <summary>Cached instance from 'Content', used (tentatively) for perfomance.</summary> + Public ReadOnly Header As JObject + + ''' <summary>Cached instance from 'Content', used (tentatively) for perfomance.</summary> + Public ReadOnly Body As JObject ''' <summary>Reads from a file (aka "Load") or creates an instance with defaults ''' @@ -115,14 +122,19 @@ Public MustInherit Class cJsonFile If (inputFilePath Is Nothing) Then Dim jstr = JsonStr_FileContents() - Me.Json_Contents = JObject.Parse(jstr) - + Me.Content = JObject.Parse(jstr) + Me.Header = Content("Header") UpdateHeader() - Me.Json_Contents("Body") = Me.BodyContent + + Me.Content("Body") = Me.BodyContent + Me.Body = Content("Body") Else - fInfWarErrBW(5, False, format("Reading JSON-file({0})...", inputFilePath)) - Me.Json_Contents = ReadJsonFile(inputFilePath) strictHeader = False '' Try to read even bad headers. + fInfWarErr(4, False, format("Reading JSON-file({0})...", inputFilePath)) + + Me.Content = ReadJsonFile(inputFilePath) + Me.Header = Content("Header") + Me.Body = Content("Body") End If If Not skipValidation Then @@ -135,10 +147,11 @@ Public MustInherit Class cJsonFile Me.UpdateHeader() Me.Validate(Me.StrictBody) - WriteJsonFile(fpath, Json_Contents) + WriteJsonFile(fpath, Content) End Sub ''' <summary>Maintains header's standard props and overlays any props from subclass.</summary> + ''' <remarks>Note that it is invoked early enough, before the new file has acquired a Body.</remarks> Sub UpdateHeader() Dim h As JObject = Me.Header @@ -185,7 +198,7 @@ Public MustInherit Class cJsonFile '' Validate Header '' - ValidateJson(Me.Json_Contents, fileSchema, validateMsgs) + ValidateJson(Me.Content, fileSchema, validateMsgs) If (validateMsgs.Any()) Then Throw New FormatException(format("Validating /Header failed due to: {0}", String.Join(vbCrLf, validateMsgs))) End If @@ -205,7 +218,7 @@ Public MustInherit Class cJsonFile Public Function Clone() As Object Implements ICloneable.Clone Dim nobj As cJsonFile = Me.MemberwiseClone() - nobj.Json_Contents = Me.Json_Contents.DeepClone() + nobj.Content = Me.Content.DeepClone() Return nobj End Function @@ -214,7 +227,7 @@ Public MustInherit Class cJsonFile If obj Is Nothing OrElse Not Me.GetType().Equals(obj.GetType()) Then Return False Else - Return JToken.DeepEquals(Me.Json_Contents, DirectCast(obj, cJsonFile).Json_Contents) + Return JToken.DeepEquals(Me.Content, DirectCast(obj, cJsonFile).Content) End If End Function @@ -241,16 +254,16 @@ Public MustInherit Class cJsonFile End Function #Region "json props" - Protected ReadOnly Property Header() As JObject - Get - Return Me.Json_Contents("Header") - End Get - End Property - Protected ReadOnly Property Body() As JObject - Get - Return Me.Json_Contents("Body") - End Get - End Property + 'Protected ReadOnly Property Header() As JObject + ' Get + ' Return Me.Json_Contents("Header") + ' End Get + 'End Property + 'Protected ReadOnly Property Body() As JObject + ' Get + ' Return Me.Json_Contents("Body") + ' End Get + 'End Property Public ReadOnly Property Title As String diff --git a/CSE/IO/cPreferences.vb b/CSE/IO/cPreferences.vb index 54c1d46b9dc595de6f9612ec31946369a3cefaee..9fc244aff1ad187c03a975cca11e8c97eab1d227 100644 --- a/CSE/IO/cPreferences.vb +++ b/CSE/IO/cPreferences.vb @@ -177,9 +177,9 @@ Each file can override it by setting its '/Header/BodySchema' property to false/ '' NOTE: Early-binding makes Nulls end-up as 'string' schema-type. '' If value Is Nothing Then - Me.Json_Contents("Body")("workingDir") = Nothing + Me.Body("workingDir") = Nothing Else - Me.Json_Contents("Body")("workingDir") = value + Me.Body("workingDir") = value End If End Set End Property diff --git a/CSE/IO/input.vb b/CSE/IO/input.vb index cd9aa9bb6ca032fcf87308a267114b87e5b662d9..6f970c9c7b94ad455a76ba447612801610504138 100644 --- a/CSE/IO/input.vb +++ b/CSE/IO/input.vb @@ -10,12 +10,12 @@ Public Module input ' Read the filelist with the MSC spezifications ' Output on the GUI - fInfWarErrBW(5, False, "Read MS configuration file") + fInfWarErr(5, False, "Read MS configuration file") ' Open the MSC spezification file If Not FileInMSCSpez.OpenRead(MSCfile) Then ' Error if the file is not available - fInfWarErrBW(9, False, "Can´t find the MS configuration specification file: " & MSCfile) + fInfWarErr(9, False, "Can´t find the MS configuration specification file: " & MSCfile) Return False End If @@ -40,7 +40,7 @@ Public Module input Loop Catch ex As Exception ' Falls kein gültiger Wert eingegeben wurde - fInfWarErrBW(9, False, "Invalid value in the trigger data file: " & fName(MSCfile, True)) + fInfWarErr(9, False, "Invalid value in the trigger data file: " & fName(MSCfile, True)) BWorker.CancelAsync() Return False End Try @@ -63,7 +63,7 @@ Public Module input MSCX.headID.Add(2) Continue For Else - fInfWarErrBW(9, False, "Measurement section with invalid headings identified (test track not parallel) at line: " & i) + fInfWarErr(9, False, "Measurement section with invalid headings identified (test track not parallel) at line: " & i) BWorker.CancelAsync() Return False End If @@ -74,7 +74,7 @@ Public Module input For i = 1 To MSCX.meID.Count - 1 If GradC Then If MSCX.AltPath(i) = Nothing Then - fInfWarErrBW(9, False, "Altitude correction = on, missing altitude file at line: " & i) + fInfWarErr(9, False, "Altitude correction = on, missing altitude file at line: " & i) BWorker.CancelAsync() Return False End If @@ -82,7 +82,7 @@ Public Module input If fPath(MSCX.AltPath(i)) = Nothing Then MSCX.AltPath(i) = joinPaths(fPath(MSCfile), MSCX.AltPath(i)) fControlInput(MSCX.AltPath(i), 3, "csalt") If Not FileIO.FileSystem.FileExists(MSCX.AltPath(i)) Then - fInfWarErrBW(9, False, "Altitude correction = on, altitude file doesen´t exist: " & MSCX.AltPath(i)) + fInfWarErr(9, False, "Altitude correction = on, altitude file doesen´t exist: " & MSCX.AltPath(i)) BWorker.CancelAsync() Return False End If @@ -116,14 +116,14 @@ Public Module input 'Abort if there's no file If Datafile = "" OrElse Not IO.File.Exists(Datafile) Then - fInfWarErrBW(9, False, "Weather data file not found (" & Datafile & ") !") + fInfWarErr(9, False, "Weather data file not found (" & Datafile & ") !") BWorker.CancelAsync() Return False End If 'Open file If Not FileInWeather.OpenRead(Datafile) Then - fInfWarErrBW(9, False, "Failed to open file (" & Datafile & ") !") + fInfWarErr(9, False, "Failed to open file (" & Datafile & ") !") BWorker.CancelAsync() Return False End If @@ -148,7 +148,7 @@ Public Module input Else ' Check if component is already defined If WeathCheck(Comp) Then - fInfWarErrBW(9, False, "Component '" & Line(i) & "' already defined! Column " & i + 1) + fInfWarErr(9, False, "Component '" & Line(i) & "' already defined! Column " & i + 1) BWorker.CancelAsync() Return False End If @@ -164,7 +164,7 @@ Public Module input ' Check if all required data is given For Each sKVW In WeathCheck If Not WeathCheck(sKVW.Key) Then - fInfWarErrBW(9, False, "Missing signal for " & fCompName(sKVW.Key)) + fInfWarErr(9, False, "Missing signal for " & fCompName(sKVW.Key)) BWorker.CancelAsync() Return False End If @@ -185,7 +185,7 @@ Public Module input Next sKV Loop Catch ex As Exception - fInfWarErrBW(9, False, "Error during file read! Line number: " & tdim + 1 & " (" & Datafile & ")") + fInfWarErr(9, False, "Error during file read! Line number: " & tdim + 1 & " (" & Datafile & ")") BWorker.CancelAsync() Return False End Try @@ -240,14 +240,14 @@ Public Module input 'Abort if there's no file If Datafile = "" OrElse Not IO.File.Exists(Datafile) Then - fInfWarErrBW(9, False, "Measurement data file not found (" & Datafile & ") !") + fInfWarErr(9, False, "Measurement data file not found (" & Datafile & ") !") BWorker.CancelAsync() Return False End If 'Open file If Not FileInMeasure.OpenRead(Datafile) Then - fInfWarErrBW(9, False, "Failed to open file (" & Datafile & ") !") + fInfWarErr(9, False, "Failed to open file (" & Datafile & ") !") BWorker.CancelAsync() Return False End If @@ -286,7 +286,7 @@ Public Module input ' Check if the component is already defined If InputUndefData.ContainsKey(txt) Then - fInfWarErrBW(9, False, "Component '" & Line(i) & "' already defined! Column " & i + 1) + fInfWarErr(9, False, "Component '" & Line(i) & "' already defined! Column " & i + 1) BWorker.CancelAsync() Return False End If @@ -298,7 +298,7 @@ Public Module input Else ' Check if component is already defined If MeasCheck(Comp) Then - fInfWarErrBW(9, False, "Component '" & Line(i) & "' already defined! Column " & i + 1) + fInfWarErr(9, False, "Component '" & Line(i) & "' already defined! Column " & i + 1) BWorker.CancelAsync() Return False End If @@ -317,7 +317,7 @@ Public Module input Select Case sKVM.Key Case tComp.trigger If MSCX.tUse Then - fInfWarErrBW(9, False, "No trigger signal detected, but trigger_used in MS config activated!") + fInfWarErr(9, False, "No trigger signal detected, but trigger_used in MS config activated!") BWorker.CancelAsync() Return False End If @@ -329,7 +329,7 @@ Public Module input Case tComp.user_valid valid_set = True Case Else - fInfWarErrBW(9, False, "Missing signal for " & fCompName(sKVM.Key)) + fInfWarErr(9, False, "Missing signal for " & fCompName(sKVM.Key)) BWorker.CancelAsync() Return False End Select @@ -352,7 +352,7 @@ Public Module input If tDim >= 2 Then If Math.Abs((InputData(sKV.Key)(tDim - 1) - InputData(sKV.Key)(tDim - 2)) / (1 / HzIn) - 1) * 100 > delta_Hz_max Then If ErrDat Then - fInfWarErrBW(9, False, "The input data is not recorded at " & HzIn & "Hz at line: " & JumpPoint & " and " & tDim) + fInfWarErr(9, False, "The input data is not recorded at " & HzIn & "Hz at line: " & JumpPoint & " and " & tDim) BWorker.CancelAsync() Return False Else @@ -367,7 +367,7 @@ Public Module input If Not ZoneChange Then If tDim > 1 Then If CalcData(tCompCali.zone_UTM).Last <> UTMCoord.Zone Then - fInfWarErrBW(8, False, "The coordinates lie in different UTM Zones. A zone adjustment will be done!") + fInfWarErr(8, False, "The coordinates lie in different UTM Zones. A zone adjustment will be done!") ZoneChange = True End If End If @@ -385,7 +385,7 @@ Public Module input If Not ZoneChange Then If tDim > 1 Then If CalcData(tCompCali.zone_UTM).Last <> UTMCoord.Zone Then - fInfWarErrBW(8, False, "The coordinates lie in different UTM Zones. A zone adjustment will be done!") + fInfWarErr(8, False, "The coordinates lie in different UTM Zones. A zone adjustment will be done!") ZoneChange = True End If End If @@ -422,7 +422,7 @@ Public Module input Next Loop Catch ex As Exception - fInfWarErrBW(9, False, "Error during file read! Line number: " & tDim + 1 & " (" & Datafile & ")") + fInfWarErr(9, False, "Error during file read! Line number: " & tDim + 1 & " (" & Datafile & ")") BWorker.CancelAsync() Return False End Try @@ -445,7 +445,7 @@ Public Module input CalcData(tCompCali.longi_UTM)(i) = UTMCoord.Easting Next i If Zone1CentralMeridian > 180 Then - fInfWarErrBW(9, False, "The adjustment is not possible because the data lie to far away from each other to fit into one UTM stripe") + fInfWarErr(9, False, "The adjustment is not possible because the data lie to far away from each other to fit into one UTM stripe") BWorker.CancelAsync() Return False End If diff --git a/CSE/IO/output.vb b/CSE/IO/output.vb index 584151a1f0844a2c1177e706ba4b031ff8530941..89345d391cd6de2af41feb94cf7e0d8720ce4679 100644 --- a/CSE/IO/output.vb +++ b/CSE/IO/output.vb @@ -29,7 +29,7 @@ End If ' Write on GUI - fInfWarErrBW(5, False, "Writing output-file (*.csv)") + fInfWarErr(5, False, "Writing output-file (*.csv)") ' Generate the file name NameOutFile = "" @@ -80,7 +80,7 @@ ' Ausgabe bei blockierter Datei If BWorker.CancellationPending And FileBlock Then - fInfWarErrBW(9, False, "Can´t write in file " & NameOutFile & ". File is blocked by another process!") + fInfWarErr(9, False, "Can´t write in file " & NameOutFile & ". File is blocked by another process!") End If Return True @@ -109,7 +109,7 @@ End If ' Write on GUI - fInfWarErrBW(5, False, "Writing result-file (*.csv)") + fInfWarErr(5, False, "Writing result-file (*.csv)") ' Generate the file name NameOutFile = OutFolder & fName(JobFile, False) & "_MS_CAL.csv" @@ -183,7 +183,7 @@ ' Ausgabe bei blockierter Datei If BWorker.CancellationPending And FileBlock Then - fInfWarErrBW(9, False, "Can´t write in file " & NameOutFile & ". File is blocked by another process!") + fInfWarErr(9, False, "Can´t write in file " & NameOutFile & ". File is blocked by another process!") End If Return True @@ -210,7 +210,7 @@ End If ' Write on GUI - fInfWarErrBW(5, False, "Writing result-file (*.csv)") + fInfWarErr(5, False, "Writing result-file (*.csv)") ' Generate the file name NameOutFile = OutFolder & fName(JobFile, False) & "_CSE.csv" @@ -277,7 +277,7 @@ ' Ausgabe bei blockierter Datei If BWorker.CancellationPending And FileBlock Then - fInfWarErrBW(9, False, "Can´t write in file " & NameOutFile & ". File is blocked by another process!") + fInfWarErr(9, False, "Can´t write in file " & NameOutFile & ". File is blocked by another process!") End If Return True @@ -653,7 +653,7 @@ For z = 1 To ValuesX.Item(tCompCali.t).Count - 1 If fTime(z) < fTime(z - 1) Then If Sprung Then - fInfWarErrBW(9, False, "Time step invalid! t(" & z - 1 & ") = " & fTime(z - 1) & "[s], t(" & z & ") = " & fTime(z) & "[s]") + fInfWarErr(9, False, "Time step invalid! t(" & z - 1 & ") = " & fTime(z - 1) & "[s], t(" & z & ") = " & fTime(z) & "[s]") Return False Else Sprung = True @@ -844,7 +844,7 @@ For z = 1 To ValuesX.Item(tComp.t).Count - 1 If fTime(z) < fTime(z - 1) Then If Sprung Then - fInfWarErrBW(9, False, "Time step invalid! t(" & z - 1 & ") = " & fTime(z - 1) & "[s], t(" & z & ") = " & fTime(z) & "[s]") + fInfWarErr(9, False, "Time step invalid! t(" & z - 1 & ") = " & fTime(z - 1) & "[s], t(" & z & ") = " & fTime(z) & "[s]") Return False Else Sprung = True @@ -1035,7 +1035,7 @@ For z = 1 To ValuesX.Item(ValuesX.First.Key).Count - 1 If fTime(z) < fTime(z - 1) Then If Sprung Then - fInfWarErrBW(9, False, "Time step invalid! t(" & z - 1 & ") = " & fTime(z - 1) & "[s], t(" & z & ") = " & fTime(z) & "[s]") + fInfWarErr(9, False, "Time step invalid! t(" & z - 1 & ") = " & fTime(z - 1) & "[s], t(" & z & ") = " & fTime(z) & "[s]") Return False Else Sprung = True diff --git a/CSE/utils.vb b/CSE/utils.vb index 553097436507fe357fb38988f800b4876b4be332..3d6ae3ba06e42ed915b07e828594e01aa02bf41d 100644 --- a/CSE/utils.vb +++ b/CSE/utils.vb @@ -162,12 +162,12 @@ Module utils ' Functions for the information depiction on the GUI with the backgroundworker (Info, Warning, Error) #Region "Logging" - ' Output from Informations\Warnings\Errors on the GUI + ''' <summary>Output from Informations\Warnings\Errors on the GUI, even from within the Backgoundworker</summary> Sub fInfWarErr(ByVal logLevel As Integer, ByVal MsgBoxOut As Boolean, _ ByVal text As String, Optional ByVal ex As Exception = Nothing) ' Declaration - Dim Styletext = "Debug" + Dim tabLabel = "Debug" Dim logFileLevel As Integer = 0 Dim StyleOut = MsgBoxStyle.Information @@ -175,149 +175,152 @@ Module utils Select Case logLevel Case 5 To 7 ' Info logFileLevel = 1 - Styletext = "Info" + tabLabel = "Info" Case 8 ' Warning logFileLevel = 2 - Styletext = "Warning" + tabLabel = "Warning" StyleOut = MsgBoxStyle.Exclamation Case 9 ' Error logFileLevel = 3 - Styletext = "Error" + tabLabel = "Error" StyleOut = MsgBoxStyle.Critical End Select ' Write to Log-file. fWriteLog(2, logFileLevel, text, ex) - ' Polling the MSG if the message should shown + '' Print only filtered msgs in log-window + '' If logLevel >= AppPreferences.logLevel Then - - ' Established the text wit the symbol from the style - text = AnzeigeMessage(logLevel) & text - - ' Write to Log-windows - Select Case logFileLevel - Case 1 ' Info - F_Main.ListBoxMSG.Items.Add(text) - Case 2 ' Warning - F_Main.ListBoxMSG.Items.Add(text) - F_Main.ListBoxWar.Items.Add(text) - F_Main.TabPageWar.Text = Styletext & " (" & F_Main.ListBoxWar.Items.Count & ")" - Case 3 ' Error - F_Main.ListBoxMSG.Items.Add(text) - F_Main.ListBoxErr.Items.Add(text) - F_Main.TabPageErr.Text = Styletext & " (" & F_Main.ListBoxErr.Items.Count & ")" - F_Main.TabControlOutMsg.SelectTab(2) - Case Else - '' ignored - End Select - - ' Set the Scrollbars in the Listboxes at the end - F_Main.ListBoxMSG.TopIndex = F_Main.ListBoxMSG.Items.Count - 1 - F_Main.ListBoxWar.TopIndex = F_Main.ListBoxWar.Items.Count - 1 - F_Main.ListBoxErr.TopIndex = F_Main.ListBoxErr.Items.Count - 1 + Dim wintext = AnzeigeMessage(logLevel) & text + If BWorker.IsBusy Then + '' If in Worker-thread, update GUI through a ProgressChanged event + '' + Dim WorkerMsg As New cLogMsg(logFileLevel, MsgBoxOut, wintext, ex, tabLabel) + BWorker.ReportProgress(0, WorkerMsg) + Else + updateLogWindow(logFileLevel, wintext, tabLabel) + End If End If - ' Output as an messagebox or on the tabcontrols + '' Output as an messagebox (if requested) + '' If MsgBoxOut Then ' Output in a MsgBox If RestartN Then ' By changes in the confic use other output RestartN = False - If MsgBox(text, MsgBoxStyle.YesNo, Styletext) = MsgBoxResult.Yes Then + If MsgBox(text, MsgBoxStyle.YesNo, tabLabel) = MsgBoxResult.Yes Then RestartN = True F_Main.Close() End If Else - MsgBox(text, StyleOut, Styletext) + MsgBox(text, StyleOut, tabLabel) End If End If End Sub - ''' <summary>Log from Informations\Warnings\Errors from within the Backgoundworker</summary> - Sub fInfWarErrBW(ByVal logLevel As Integer, ByVal msgBoxOut As Boolean, _ - ByVal text As String, Optional ByVal ex As Exception = Nothing) - Dim WorkerMsg As New CMsg + Private Sub updateLogWindow(ByVal logFileLevel As Integer, ByVal text As String, ByVal tabLabel As String) + ' Established the text wit the symbol from the style + + ' Write to Log-windows + Select Case logFileLevel + Case 1 ' Info + F_Main.ListBoxMSG.Items.Add(text) + Case 2 ' Warning + F_Main.ListBoxMSG.Items.Add(text) + F_Main.ListBoxWar.Items.Add(text) + F_Main.TabPageWar.Text = tabLabel & " (" & F_Main.ListBoxWar.Items.Count & ")" + Case 3 ' Error + F_Main.ListBoxMSG.Items.Add(text) + F_Main.ListBoxErr.Items.Add(text) + F_Main.TabPageErr.Text = tabLabel & " (" & F_Main.ListBoxErr.Items.Count & ")" + F_Main.TabControlOutMsg.SelectTab(2) + Case Else + '' ignored + End Select - WorkerMsg.LogLevel = logLevel - WorkerMsg.MsgBoxOut = msgBoxOut - WorkerMsg.Text = text - WorkerMsg.Ex = ex + ' Set the Scrollbars in the Listboxes at the end + F_Main.ListBoxMSG.TopIndex = F_Main.ListBoxMSG.Items.Count - 1 + F_Main.ListBoxWar.TopIndex = F_Main.ListBoxWar.Items.Count - 1 + F_Main.ListBoxErr.TopIndex = F_Main.ListBoxErr.Items.Count - 1 - ' Output in the Tabcontrols (Call from Backgroundworker_ProgressChanged) - BWorker.ReportProgress(0, WorkerMsg) End Sub + ' Definition for the Backgroundworker - Class CMsg - Public LogLevel As Integer - Public Text As String - Public Ex As Exception - Public MsgBoxOut As Boolean = False + Class cLogMsg + Private LogLevel As Integer + Private Text As String + Private Ex As Exception + Private MsgBoxOut As Boolean = False + Private TabLabel + + Public Sub New(ByVal logLevel As Integer, ByVal msgBoxOut As Boolean, ByVal text As String, _ + ByVal ex As Exception, Optional ByVal TabLabel As String = "") + Me.LogLevel = logLevel + Me.MsgBoxOut = msgBoxOut + Me.Text = text + Me.Ex = ex + End Sub ' Call for the output from Informations\Warnings\Errors with the backgoundworker - Public Sub MsgToForm() - fInfWarErr(LogLevel, MsgBoxOut, Text, Ex) + Public Sub forwardLog() + updateLogWindow(LogLevel, Text, TabLabel) End Sub End Class + Private logDateFrmt As String = "yyyy/MM/dd HH:mm:ss zzz" - ' Generation or upgrade from the log file - Function fWriteLog(ByVal filePosition As Integer, Optional ByVal logLevel As Integer = 4, Optional ByVal text As String = "", _ + ''' <summary>Format and write log-mesages to file.</summary> + ''' <param name="eventType">1: Session started, 2: Add log, 3: Session ended</param> + Function fWriteLog(ByVal eventType As Integer, Optional ByVal logLevel As Integer = 4, Optional ByVal text As String = "", _ Optional ByVal ex As Exception = Nothing) As Boolean - ' filePosition: - ' Write beginning - ' Add - ' Write end If Not AppPreferences.writeLog Then Return True - ' Declaration Dim LogFilenam As String = joinPaths(MyPath, "log.txt") + If eventType = 1 Then + logLevel = 1 + text = "Session started: " & AppName & " " & AppVers + + '' Truncate log-file if size exceeded on session-start. + '' + Dim fInf As New System.IO.FileInfo(LogFilenam) + If fInf.Exists AndAlso fInf.Length > AppPreferences.logSize * Math.Pow(10, 6) Then + fLoeschZeilen(LogFilenam, System.IO.File.ReadAllLines(LogFilenam).Length / 2) + End If + ElseIf eventType = 3 Then + logLevel = 1 + text = "Session finished: " & AppName & " " & AppVers + End If + + Dim slevel As String + Select Case logLevel + Case 1 + slevel = "INFO" + Case 2 + slevel = "WARN" + Case 3 + slevel = "ERROR" + Case Else + slevel = "DEBUG" + End Select + + Try - ' Decision where should be write - Select Case filePosition - Case 1 ' At the beginning of VECTO - Dim fInf As New System.IO.FileInfo(LogFilenam) - If IO.File.Exists(LogFilenam) Then - If fInf.Length > AppPreferences.logSize * Math.Pow(10, 6) Then - fLoeschZeilen(LogFilenam, System.IO.File.ReadAllLines(LogFilenam).Length / 2) - End If - FileOutLog.OpenWrite(LogFilenam, , True) - Else - FileOutLog.OpenWrite(LogFilenam) - End If - FileOutLog.WriteLine("-----") - - ' Write the start time into the Log - FileOutLog.WriteLine("Starting Session " & CDate(DateAndTime.Now)) - FileOutLog.WriteLine(AppName & " " & AppVers) - - Case 2 ' Add a message to the Log - Dim slevel As String - Select Case logLevel - Case 1 - slevel = "INFO | " - Case 2 - slevel = "WARNING| " - Case 3 - slevel = "ERROR | " - Case Else - slevel = "DEBUG | " - End Select - FileOutLog.OpenWrite(LogFilenam, , True) - FileOutLog.WriteLine(slevel & text) - If ex IsNot Nothing Then - FileOutLog.WriteLine(ex.StackTrace) - End If - - Case 3 ' At the end - FileOutLog.OpenWrite(LogFilenam, , True) - ' Write the end to the Log - FileOutLog.WriteLine("Closing Session " & CDate(DateAndTime.Now)) - FileOutLog.WriteLine("-----") - End Select + FileOutLog.OpenWrite(LogFilenam, , True) + + If eventType = 1 Then FileOutLog.WriteLine("---------------") + + If ex Is Nothing Then + FileOutLog.WriteLine(format("{0}: {1,-5}| {2}", DateAndTime.Now.ToString(logDateFrmt), slevel, text)) + Else + FileOutLog.WriteLine(format("{0}: {1,-5}| {2}\n\i{3}", DateAndTime.Now.ToString(logDateFrmt), slevel, text, ex)) + End If + + If eventType = 3 Then FileOutLog.WriteLine("---------------") Finally FileOutLog.Dispose() End Try