Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit b2b3cc0e authored by Kostis ANAGNOSTOPOULOS's avatar Kostis ANAGNOSTOPOULOS
Browse files

json: Invoke field-populate methods by default.

* GUI: Show wait-cursor for all Form when calculating.
parent f7d87a0b
No related branches found
No related tags found
No related merge requests found
......@@ -101,7 +101,7 @@
Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal ev As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException
Dim ex As Exception = ev.Exception
If AppFormStarted Then
logme(9, False, format("Unhandled exception: \i{0}", ex.Message), ex)
logme(9, False, format("Unhandled exception in {0}: \i{1}", ex.Source, ex.Message), ex)
ev.ExitApplication = False
Else
MsgBox(format("{0} failed after init due to: \n\i{1}", AppName, ex), MsgBoxStyle.Critical, format("{0} failed to Start!", AppName))
......
......@@ -18,8 +18,8 @@
meID.Add(0)
dID.Add(0)
KoordA.Add({0})
KoordE.Add({0})
KoordA.Add(New Integer() {0})
KoordE.Add(New Integer() {0})
NewSec.Add(0)
Head.Add(0)
End Sub
......
......@@ -184,8 +184,8 @@ Public Class F_Main
'#### Only HERE manage "Exec" button's state (Text, Image, etc). ####
'####################################################################
Private _CalibrationState As Boolean = False
Private _CalibrationTxts = {"Calibrate", "Cancel"}
Private _CalibrationImgs = {My.Resources.Resources.Play_icon, My.Resources.Resources.Stop_icon}
Private ReadOnly _CalibrationTxts = {"Calibrate", "Cancel"}
Private ReadOnly _CalibrationImgs = {My.Resources.Resources.Play_icon, My.Resources.Resources.Stop_icon}
Private Property CalibrationState As Boolean
Get
Return _CalibrationState
......@@ -195,7 +195,7 @@ Public Class F_Main
Dim indx = -CInt(value)
Me.ButtonCalC.Text = _CalibrationTxts(indx)
Me.ButtonCalC.Image = _CalibrationImgs(indx)
Me.ButtonCalC.UseWaitCursor = value
Me.UseWaitCursor = value
End If
_CalibrationState = value
End Set
......@@ -265,8 +265,8 @@ Public Class F_Main
'#### Only HERE manage "Exec" button's state (Text, Image, etc). ####
'####################################################################
Private _EvaluationState As Boolean = False
Private _EvaluationTxts = {"Evaluate", "Cancel"}
Private _EvaluationImgs = {My.Resources.Resources.Play_icon, My.Resources.Resources.Stop_icon}
Private ReadOnly _EvaluationTxts = {"Evaluate", "Cancel"}
Private ReadOnly _EvaluationImgs = {My.Resources.Resources.Play_icon, My.Resources.Resources.Stop_icon}
Private Property EvaluationState As Boolean
Get
Return _EvaluationState
......@@ -276,7 +276,7 @@ Public Class F_Main
Dim indx = -CInt(value)
Me.ButtonEval.Text = _EvaluationTxts(indx)
Me.ButtonEval.Image = _EvaluationImgs(indx)
Me.ButtonEval.UseWaitCursor = value
Me.UseWaitCursor = value
End If
_EvaluationState = value
End Set
......
......@@ -12,11 +12,8 @@ Public Class cCriteria
End Function
Private ForeignBody As JToken
'' Default values are Decleration
Public Shared Function BuildBody() As JObject
Private Shared Function BuildBody() As JObject
Dim b, g As Object
b = New JObject()
......@@ -252,17 +249,14 @@ Public Class cCriteria
''' <remarks>See cJsonFile() constructor</remarks>
Sub New(Optional ByVal skipValidation As Boolean = False)
MyBase.New(BuildBody, skipValidation)
PopulateFields()
End Sub
''' <summary>Reads from file or creates defaults</summary>
''' <param name="inputFilePath">the fpath of the file to read data from</param>
Sub New(ByVal inputFilePath As String, Optional ByVal skipValidation As Boolean = False)
MyBase.New(inputFilePath, skipValidation)
PopulateFields()
End Sub
Sub New(ByVal foreignBody As JToken, Optional ByVal skipValidation As Boolean = False)
MyBase.New(foreignBody, skipValidation)
PopulateFields()
End Sub
......@@ -275,8 +269,8 @@ Public Class cCriteria
Protected Overrides Sub ValidateBody(ByVal isStrictBody As Boolean, ByVal validateMsgs As IList(Of String))
'' Check version
''
Dim fromVersion = "1.0.0--"
Dim toVersion = "2.0.0--" ' The earliest pre-release.
Const fromVersion = "1.0.0--"
Const toVersion = "2.0.0--" ' The earliest pre-release.
If Not IsSemanticVersionsSupported(Me.FileVersion, fromVersion, toVersion) Then
validateMsgs.Add(format("Unsupported FileVersion({0}, was not in between [{1}, {2})", Me.FileVersion, fromVersion, toVersion))
Return
......@@ -337,62 +331,7 @@ Public Class cCriteria
Public t_amb_tarmac As Single
''' <summary>Override it to set custome fields</summary>
Overrides Sub Store(ByVal fpath As String, Optional ByVal prefs As cPreferences = Nothing)
Dim g, b As Object
b = Me.Body
g = b("Processing")
g.roh_air_ref = Me.roh_air_ref
g.accel_correction = Me.accel_correction
g.gradient_correction = Me.gradient_correction
g.hz_out = Me.hz_out
g.rr_corr_factor = Me.rr_corr_factor
g.acc_corr_avg = Me.acc_corr_avg
g.dist_float = Me.dist_float
g = b("Validation")
g.trigger_delta_x_max = Me.trigger_delta_x_max
g.trigger_delta_y_max = Me.trigger_delta_y_max
g.delta_head_max = Me.delta_head_max
g.segruns_min_CAL = Me.segruns_min_CAL
g.segruns_min_LS = Me.segruns_min_LS
g.segruns_min_HS = Me.segruns_min_HS
g.segruns_min_head_MS = Me.segruns_min_head_MS
g.delta_Hz_max = Me.delta_Hz_max
g.delta_parallel_max = Me.delta_parallel_max
g.v_wind_avg_max_CAL = Me.v_wind_avg_max_CAL
g.v_wind_1s_max_CAL = Me.v_wind_1s_max_CAL
g.beta_avg_max_CAL = Me.beta_avg_max_CAL
g.leng_crit = Me.leng_crit
g.v_wind_avg_max_LS = Me.v_wind_avg_max_LS
g.v_wind_1s_max_LS = Me.v_wind_1s_max_LS
g.v_veh_avg_min_LS = Me.v_veh_avg_min_LS
g.v_veh_avg_max_LS = Me.v_veh_avg_max_LS
g.v_veh_float_delta_LS = Me.v_veh_float_delta_LS
g.tq_sum_float_delta_LS = Me.tq_sum_float_delta_LS
g.v_wind_avg_max_HS = Me.v_wind_avg_max_HS
g.v_wind_1s_max_HS = Me.v_wind_1s_max_HS
g.beta_avg_max_HS = Me.beta_avg_max_HS
g.v_veh_avg_min_HS = Me.v_veh_avg_min_HS
g.v_veh_1s_delta_HS = Me.v_veh_1s_delta_HS
g.tq_sum_1s_delta_HS = Me.tq_sum_1s_delta_HS
g.delta_t_tyre_max = Me.delta_t_tyre_max
g.delta_rr_corr_max = Me.delta_rr_corr_max
g.t_amb_var = Me.t_amb_var
g.t_amb_tarmac = Me.t_amb_tarmac
g.t_amb_max = Me.t_amb_max
g.t_amb_min = Me.t_amb_min
MyBase.Store(fpath, prefs)
End Sub
Private Sub PopulateFields()
Protected Overrides Sub OnContentUpdated()
Dim g, p As Object
p = Me.Body
......@@ -445,6 +384,59 @@ Public Class cCriteria
Me.t_amb_min = g("t_amb_min")
End Sub
''' <summary>Override it to set custome fields</summary>
Protected Overrides Sub OnBeforeContentStored()
Dim g, b As Object
b = Me.Body
g = b("Processing")
g.roh_air_ref = Me.roh_air_ref
g.accel_correction = Me.accel_correction
g.gradient_correction = Me.gradient_correction
g.hz_out = Me.hz_out
g.rr_corr_factor = Me.rr_corr_factor
g.acc_corr_avg = Me.acc_corr_avg
g.dist_float = Me.dist_float
g = b("Validation")
g.trigger_delta_x_max = Me.trigger_delta_x_max
g.trigger_delta_y_max = Me.trigger_delta_y_max
g.delta_head_max = Me.delta_head_max
g.segruns_min_CAL = Me.segruns_min_CAL
g.segruns_min_LS = Me.segruns_min_LS
g.segruns_min_HS = Me.segruns_min_HS
g.segruns_min_head_MS = Me.segruns_min_head_MS
g.delta_Hz_max = Me.delta_Hz_max
g.delta_parallel_max = Me.delta_parallel_max
g.v_wind_avg_max_CAL = Me.v_wind_avg_max_CAL
g.v_wind_1s_max_CAL = Me.v_wind_1s_max_CAL
g.beta_avg_max_CAL = Me.beta_avg_max_CAL
g.leng_crit = Me.leng_crit
g.v_wind_avg_max_LS = Me.v_wind_avg_max_LS
g.v_wind_1s_max_LS = Me.v_wind_1s_max_LS
g.v_veh_avg_min_LS = Me.v_veh_avg_min_LS
g.v_veh_avg_max_LS = Me.v_veh_avg_max_LS
g.v_veh_float_delta_LS = Me.v_veh_float_delta_LS
g.tq_sum_float_delta_LS = Me.tq_sum_float_delta_LS
g.v_wind_avg_max_HS = Me.v_wind_avg_max_HS
g.v_wind_1s_max_HS = Me.v_wind_1s_max_HS
g.beta_avg_max_HS = Me.beta_avg_max_HS
g.v_veh_avg_min_HS = Me.v_veh_avg_min_HS
g.v_veh_1s_delta_HS = Me.v_veh_1s_delta_HS
g.tq_sum_1s_delta_HS = Me.tq_sum_1s_delta_HS
g.delta_t_tyre_max = Me.delta_t_tyre_max
g.delta_rr_corr_max = Me.delta_rr_corr_max
g.t_amb_var = Me.t_amb_var
g.t_amb_tarmac = Me.t_amb_tarmac
g.t_amb_max = Me.t_amb_max
g.t_amb_min = Me.t_amb_min
End Sub
#End Region ' json props
End Class
......@@ -98,13 +98,11 @@ Public Class cJob
''' <remarks>See cJsonFile() constructor</remarks>
Sub New(Optional ByVal skipValidation As Boolean = False)
MyBase.New(BuildBody, skipValidation)
PopulateFields()
End Sub
''' <summary>Reads from file or creates defaults</summary>
''' <param name="inputFilePath">the fpath of the file to read data from</param>
Sub New(ByVal inputFilePath As String, Optional ByVal skipValidation As Boolean = False)
MyBase.New(inputFilePath, skipValidation)
PopulateFields()
End Sub
......@@ -142,7 +140,7 @@ Public Class cJob
Public beta_f As Double
Public beta_d As Double
Private Sub PopulateFields()
Protected Overrides Sub OnContentUpdated()
Dim anem = PropOrDefault(".Anemometer")
Me.v_air_f = anem("v_air_f")
Me.v_air_d = anem("v_air_d")
......@@ -151,15 +149,13 @@ Public Class cJob
End Sub
''' <summary>Override it to set custome fields</summary>
Overrides Sub Store(ByVal fpath As String, Optional ByVal prefs As cPreferences = Nothing)
Protected Overrides Sub OnBeforeContentStored()
Dim b As Object = Me.Body
b.v_air_f = Me.v_air_f
b.v_air_d = Me.v_air_d
b.beta_f = Me.beta_f
b.beta_d = Me.beta_d
MyBase.Store(fpath, prefs)
End Sub
......@@ -296,10 +292,10 @@ Public Class cJob
For i = 0 To UBound(factors) - 1
factors(i) = Line(i)
Next i
Job.v_air_f = factors(0)
Job.v_air_d = factors(1)
Job.beta_f = factors(2)
Job.beta_d = factors(3)
Me.v_air_f = factors(0)
Me.v_air_d = factors(1)
Me.beta_f = factors(2)
Me.beta_d = factors(3)
' Calibration test files
calib_track_fpath = FileInVECTO.ReadLine(0)
......@@ -426,6 +422,8 @@ Public Class cJob
End Using
Me.OnBeforeContentStored()
F_Main.UI_PopulateFromJob()
F_Main.UI_PopulateFromCriteria()
End Sub
......
Option Strict Off
Imports Newtonsoft.Json.Linq
Imports Newtonsoft.Json.Linq
Imports Newtonsoft.Json.Schema
Imports System.Globalization
......@@ -25,7 +23,7 @@ Imports System.Globalization
Public MustInherit Class cJsonFile
Implements ICloneable
Shared dateFrmt As String = "yyyy/MM/dd HH:mm:ss zzz"
Private Const DateFrmt As String = "yyyy/MM/dd HH:mm:ss zzz"
''' <summary>The json-content for a json-file structured in Header/Body</summary>
''' <remarks>Note that the content is invalid according to the schema, and has to be specified by sub-classers.</remarks>
......@@ -111,6 +109,11 @@ When False, it overrides Application's choice and is not replaced ever.",
''' <remarks>To signify validation-failure it can throw an exception or add err-messages into the supplied list</remarks>
Protected MustOverride Sub ValidateBody(ByVal isStrict As Boolean, ByVal validateMsgs As IList(Of String))
Protected Overridable Sub OnContentUpdated()
End Sub
Protected Overridable Sub OnBeforeContentStored()
End Sub
''' <summary>The whole json-content receiving any changes, always ready to be written as is.</summary>
Private Content As JObject
......@@ -127,9 +130,8 @@ When False, it overrides Application's choice and is not replaced ever.",
''' <param name="skipValidation">When false (the default), validates json-contents in both cases (reading or creating-defaults)</param>
''' <remarks>It optionally checks version and validates its body with ValidateVersionAndBody().</remarks>
Protected Sub New(ByVal inputFilePath As String, Optional ByVal skipValidation As Boolean = False)
Dim strictHeader = True
Dim strictHeader = False '' Accept unknown headers.
strictHeader = False '' Try to read even bad headers.
logme(4, False, format("Reading JSON-file({0})...", inputFilePath))
Me.Content = ReadJsonFile(inputFilePath)
......@@ -139,6 +141,8 @@ When False, it overrides Application's choice and is not replaced ever.",
If Not skipValidation Then
Me.Validate(strictHeader)
End If
OnContentUpdated()
End Sub
''' <summary>Creates an instance with defaults</summary>
......@@ -146,7 +150,7 @@ When False, it overrides Application's choice and is not replaced ever.",
''' <param name="skipValidation">When false (the default), validates json-contents in both cases (reading or creating-defaults)</param>
''' <remarks>When defaulting, the resulted file-version is retrieved from 'CodeVersion' prop and the body from 'BodyStr' prop.</remarks>
Protected Sub New(ByVal body As JToken, Optional ByVal skipValidation As Boolean = False)
Dim strictHeader = True
Dim strictHeader = False '' Accept unknown headers.
Dim jstr = JsonStr_FileContents()
Me.Content = JObject.Parse(jstr)
......@@ -159,10 +163,14 @@ When False, it overrides Application's choice and is not replaced ever.",
If Not skipValidation Then
Me.Validate(strictHeader)
End If
OnContentUpdated()
End Sub
''' <summary>Validates and Writing to the config file</summary>
Overridable Sub Store(ByVal fpath As String, Optional ByVal prefs As cPreferences = Nothing)
OnBeforeContentStored()
logme(4, False, format("Writting JSON-file({0})...", fpath))
Me.UpdateHeader(prefs)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment