Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 091f578c authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

adapted writing of json content

parent 1a8a28b7
Branches
Tags
No related merge requests found
......@@ -11,7 +11,7 @@ Module AdvancedAuxiliariesModule
ByVal messageType As AdvancedAuxiliaryMessageType) Handles advancedAuxModel.AuxiliaryEvent
WorkerMsg(messageType, message, "Advanced Auxiliaries")
WorkerMsg(CType(messageType, MessageType), message, "Advanced Auxiliaries")
End Sub
'AA-TB
......
......@@ -90,28 +90,27 @@ Public Class Configuration
Public Sub Save()
Dim json As New JSONParser
Dim dic As Dictionary(Of String, Object)
dic = New Dictionary(Of String, Object)
dic.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")")
dic.Add("Date", Now.ToUniversalTime().ToString("o"))
dic.Add("AppVersion", VECTOvers)
dic.Add("FileVersion", FormatVersion)
json.Content.Add("Header", JToken.FromObject(dic))
Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
header.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")")
header.Add("Date", Now.ToUniversalTime().ToString("o"))
header.Add("AppVersion", VECTOvers)
header.Add("FileVersion", FormatVersion)
dic = New Dictionary(Of String, Object)
dic.Add("ModOut", ModOut)
dic.Add("Mod1Hz", Mod1Hz)
dic.Add("LogSize", LogSize)
dic.Add("AirDensity", AirDensity)
dic.Add("FuelDensity", FuelDens)
dic.Add("CO2perFC", CO2perFC)
dic.Add("OpenCmd", OpenCmd)
dic.Add("OpenCmdName", OpenCmdName)
dic.Add("FirstRun", FirstRun)
dic.Add("DeclMode", DeclMode)
json.Content.Add("Body", JToken.FromObject(dic))
Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
body.Add("ModOut", ModOut)
body.Add("Mod1Hz", Mod1Hz)
body.Add("LogSize", LogSize)
body.Add("AirDensity", AirDensity)
body.Add("FuelDensity", FuelDens)
body.Add("CO2perFC", CO2perFC)
body.Add("OpenCmd", OpenCmd)
body.Add("OpenCmdName", OpenCmdName)
body.Add("FirstRun", FirstRun)
body.Add("DeclMode", DeclMode)
json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}})
json.WriteFile(FilePath)
End Sub
End Class
......
......@@ -365,7 +365,11 @@ Public Class MainForm
If VehicleForm.WindowState = FormWindowState.Minimized Then VehicleForm.WindowState = FormWindowState.Normal
VehicleForm.BringToFront()
End If
Try
VehicleForm.OpenVehicle(File)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error loading Vehicle File")
End Try
Case ".VENG"
If Not EngineForm.Visible Then
EngineForm.Show()
......@@ -939,7 +943,10 @@ lbFound:
End Sub
Private Sub VectoWorkerV3_OnDoWork(sender As BackgroundWorker, e As DoWorkEventArgs)
Private Sub VectoWorkerV3_OnDoWork(theSender As Object, e As DoWorkEventArgs)
Dim sender As BackgroundWorker = TryCast(theSender, BackgroundWorker)
If sender Is Nothing Then Exit Sub
AllowSleepOFF()
Dim sumFileWriter As FileOutputWriter = New FileOutputWriter(JobFileList(0))
......
......@@ -232,7 +232,13 @@ Public Class VectoJobForm
VehicleForm.BringToFront()
End If
If Not Trim(f) = "" Then VehicleForm.OpenVehicle(f)
If Not Trim(f) = "" Then
Try
VehicleForm.OpenVehicle(f)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error loading Vehicle File")
End Try
End If
End Sub
'Open Engine Editor
......
......@@ -192,7 +192,14 @@ Public Class VehicleForm
'Open
Private Sub ToolStripBtOpen_Click(sender As Object, e As EventArgs) Handles ToolStripBtOpen.Click
If VehicleFileBrowser.OpenDialog(_vehFile) Then OpenVehicle(VehicleFileBrowser.Files(0))
If VehicleFileBrowser.OpenDialog(_vehFile) Then
Try
OpenVehicle(VehicleFileBrowser.Files(0))
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error loading Vehicle File")
End Try
End If
End Sub
'Save
......@@ -330,6 +337,10 @@ Public Class VehicleForm
End Select
End If
CbCat.SelectedValue = veh.VehicleCategory
CbAxleConfig.SelectedValue = veh.AxleConfiguration
TbMassMass.Text = veh.MassMax.ToGUIFormat()
TbMass.Text = veh.Mass.ToGUIFormat()
TbMassExtra.Text = veh.MassExtra.ToGUIFormat()
TbLoad.Text = veh.Loading.ToGUIFormat()
......@@ -346,9 +357,6 @@ Public Class VehicleForm
tbAngularGearRatio.Text = veh.AngularGearRatio.ToGUIFormat()
tbAngularGearLossMapPath.Text = veh.AngularGearLossMapFile.OriginalPath
CbCat.SelectedValue = veh.VehicleCategory
LvRRC.Items.Clear()
Dim i = 0
For Each a0 In veh.Axles
......@@ -365,10 +373,8 @@ Public Class VehicleForm
Next
TbMassMass.Text = veh.MassMax.ToGUIFormat()
TbMassExtra.Text = veh.MassExtra.ToGUIFormat()
CbAxleConfig.SelectedValue = veh.AxleConfiguration
TbMassExtra.Text = veh.MassExtra.ToGUIFormat()
TBcdA.Text = veh.CdA0.ToGUIFormat()
......@@ -416,12 +422,12 @@ Public Class VehicleForm
veh.FilePath = file
veh.Mass = TbMass.Text.ToDouble()
veh.MassExtra = TbMassExtra.Text.ToDouble()
veh.Loading = TbLoad.Text.ToDouble()
veh.MassExtra = TbMassExtra.Text.ToDouble(0)
veh.Loading = TbLoad.Text.ToDouble(0)
veh.CdA0 = TBcdA.Text.ToDouble()
veh.DynamicTyreRadius = TBrdyn.Text.ToDouble()
veh.DynamicTyreRadius = TBrdyn.Text.ToDouble(0)
veh.CrossWindCorrectionMode = CType(CbCdMode.SelectedValue, CrossWindCorrectionMode)
veh.CrossWindCorrectionFile.Init(GetPath(file), TbCdFile.Text)
veh.RetarderType = CType(CbRtType.SelectedValue, RetarderType)
......@@ -437,13 +443,13 @@ Public Class VehicleForm
Dim axleShareCheck As Double
For Each entry As ListViewItem In LvRRC.Items
Dim a0 = New Vehicle.Axle
a0.Share = entry.SubItems(AxleTbl.RelativeLoad).Text.ToDouble()
a0.Share = entry.SubItems(AxleTbl.RelativeLoad).Text.ToDouble(0)
axleShareCheck += a0.Share
a0.TwinTire = (entry.SubItems(AxleTbl.TwinTyres).Text = "yes")
a0.RRC = entry.SubItems(AxleTbl.RRC).Text.ToDouble()
a0.FzISO = entry.SubItems(AxleTbl.FzISO).Text.ToDouble()
a0.RRC = entry.SubItems(AxleTbl.RRC).Text.ToDouble(0)
a0.FzISO = entry.SubItems(AxleTbl.FzISO).Text.ToDouble(0)
a0.Wheels = entry.SubItems(AxleTbl.WheelsDimension).Text
a0.Inertia = entry.SubItems(AxleTbl.Inertia).Text.ToDouble()
a0.Inertia = entry.SubItems(AxleTbl.Inertia).Text.ToDouble(0)
veh.Axles.Add(a0)
Next
......@@ -457,7 +463,7 @@ Public Class VehicleForm
End If
veh.MassMax = TbMassMass.Text.ToDouble()
veh.MassExtra = TbMassExtra.Text.ToDouble()
veh.MassExtra = TbMassExtra.Text.ToDouble(0)
veh.AxleConfiguration = CType(CbAxleConfig.SelectedValue, AxleConfiguration)
......
......@@ -141,42 +141,38 @@ Public Class Engine
''' <returns>True if successful.</returns>
''' <remarks></remarks>
Public Function SaveFile() As Boolean
Dim JSON As New JSONParser
Dim dic As Dictionary(Of String, Object)
Dim json As New JSONParser
'Header
dic = New Dictionary(Of String, Object)
dic.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")")
dic.Add("Date", Now.ToUniversalTime().ToString("o"))
dic.Add("AppVersion", VECTOvers)
dic.Add("FileVersion", FormatVersion)
JSON.Content.Add("Header", JToken.FromObject(dic))
Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
header.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")")
header.Add("Date", Now.ToUniversalTime().ToString("o"))
header.Add("AppVersion", VECTOvers)
header.Add("FileVersion", FormatVersion)
'Body
dic = New Dictionary(Of String, Object)
Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
dic.Add("SavedInDeclMode", Cfg.DeclMode)
body.Add("SavedInDeclMode", Cfg.DeclMode)
SavedInDeclMode = Cfg.DeclMode
dic.Add("ModelName", ModelName)
dic.Add("Displacement", Displacement)
dic.Add("IdlingSpeed", IdleSpeed)
dic.Add("Inertia", EngineInertia)
body.Add("ModelName", ModelName)
dic.Add("FullLoadCurve", _fullLoadCurvePath.PathOrDummy)
body.Add("Displacement", Displacement)
body.Add("IdlingSpeed", IdleSpeed)
body.Add("Inertia", EngineInertia)
dic.Add("FuelMap", _fuelConsumptionMapPath.PathOrDummy)
body.Add("FullLoadCurve", _fullLoadCurvePath.PathOrDummy)
dic.Add("WHTC-Urban", WHTCurban)
dic.Add("WHTC-Rural", WHTCrural)
dic.Add("WHTC-Motorway", WHTCmw)
body.Add("FuelMap", _fuelConsumptionMapPath.PathOrDummy)
body.Add("WHTC-Urban", WHTCurban)
body.Add("WHTC-Rural", WHTCrural)
body.Add("WHTC-Motorway", WHTCmw)
JSON.Content.Add("Body", JToken.FromObject(dic))
json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}})
Return JSON.WriteFile(_filePath)
Return json.WriteFile(_filePath)
End Function
''' <summary>
......@@ -290,3 +286,4 @@ Public Class Engine
End Property
End Class
......@@ -98,26 +98,25 @@ Public Class Gearbox
Public Function SaveFile() As Boolean
Dim i As Integer
Dim json As New JSONParser
Dim content As Dictionary(Of String, Object)
'Header
content = New Dictionary(Of String, Object)
content.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")")
content.Add("Date", Now.ToUniversalTime().ToString("o"))
content.Add("AppVersion", VECTOvers)
content.Add("FileVersion", FormatVersion)
json.Content.Add("Header", JToken.FromObject(content))
Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
header.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")")
header.Add("Date", Now.ToUniversalTime().ToString("o"))
header.Add("AppVersion", VECTOvers)
header.Add("FileVersion", FormatVersion)
'Body
content = New Dictionary(Of String, Object)
Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
content.Add("SavedInDeclMode", Cfg.DeclMode)
body.Add("SavedInDeclMode", Cfg.DeclMode)
SavedInDeclMode = Cfg.DeclMode
content.Add("ModelName", ModelName)
body.Add("ModelName", ModelName)
content.Add("Inertia", GbxInertia)
content.Add("TracInt", TracIntrSi)
body.Add("Inertia", GbxInertia)
body.Add("TracInt", TracIntrSi)
Dim ls As New List(Of Object)
For i = 0 To GearRatios.Count - 1
......@@ -135,18 +134,18 @@ Public Class Gearbox
ls.Add(gearDict)
Next
content.Add("Gears", ls)
body.Add("Gears", ls)
content.Add("TqReserve", TorqueResv)
content.Add("SkipGears", SkipGears)
content.Add("ShiftTime", ShiftTime)
content.Add("EaryShiftUp", ShiftInside)
body.Add("TqReserve", TorqueResv)
body.Add("SkipGears", SkipGears)
body.Add("ShiftTime", ShiftTime)
body.Add("EaryShiftUp", ShiftInside)
content.Add("StartTqReserve", TorqueResvStart)
content.Add("StartSpeed", StartSpeed)
content.Add("StartAcc", StartAcc)
body.Add("StartTqReserve", TorqueResvStart)
body.Add("StartSpeed", StartSpeed)
body.Add("StartAcc", StartAcc)
content.Add("GearboxType", Type)
body.Add("GearboxType", Type)
Dim torqueConverterDict As New Dictionary(Of String, Object)
torqueConverterDict.Add("Enabled", TorqueConverterEnabled)
......@@ -154,14 +153,14 @@ Public Class Gearbox
torqueConverterDict.Add("RefRPM", TorqueConverterReferenceRpm)
torqueConverterDict.Add("Inertia", TorqueConverterInertia)
torqueConverterDict.Add("ShiftPolygon", TorqueConverterShiftPolygonFile)
content.Add("TorqueConverter", torqueConverterDict)
body.Add("TorqueConverter", torqueConverterDict)
content.Add("DownshiftAferUpshiftDelay", DownshiftAfterUpshift)
content.Add("UpshiftAfterDownshiftDelay", UpshiftAfterDownshift)
content.Add("UpshiftMinAcceleration", UpshiftMinAcceleration)
body.Add("DownshiftAferUpshiftDelay", DownshiftAfterUpshift)
body.Add("UpshiftAfterDownshiftDelay", UpshiftAfterDownshift)
body.Add("UpshiftMinAcceleration", UpshiftMinAcceleration)
json.Content.Add("Body", JToken.FromObject(content))
json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}})
Return json.WriteFile(_filePath)
End Function
......@@ -202,7 +201,7 @@ Public Class Gearbox
If dic("Efficiency") Is Nothing Then
GearLossmaps(i).Init(_myPath, dic.GetEx(Of String)("LossMap"))
Else
GearLossmaps(i).Init(_myPath, dic.GetEx(Of Double)("Efficiency"))
GearLossmaps(i).Init(_myPath, dic.GetEx(Of Double)("Efficiency").ToString())
End If
MaxTorque.Add(dic.GetEx(Of String)("MaxTorque"))
......
......@@ -89,36 +89,36 @@ Public Class VectoJob
Dim json As New JSONParser
'Header
json.Content.Add("Header", JToken.FromObject(New Dictionary(Of String, Object) From {
Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From {
{"CreatedBy", Lic.LicString & " (" & Lic.GUID & ")"},
{"Date", Now.ToUniversalTime().ToString("o")},
{"AppVersion", VECTOvers},
{"FileVersion", FormatVersion}}))
{"FileVersion", FormatVersion}}
'Body
Dim dic0 = New Dictionary(Of String, Object)
Dim body = New Dictionary(Of String, Object)
dic0.Add("SavedInDeclMode", Cfg.DeclMode)
body.Add("SavedInDeclMode", Cfg.DeclMode)
SavedInDeclMode = Cfg.DeclMode
'Main Files
dic0.Add("VehicleFile", _vehicleFile.PathOrDummy)
dic0.Add("EngineFile", _engineFile.PathOrDummy)
dic0.Add("GearboxFile", _gearboxFile.PathOrDummy)
body.Add("VehicleFile", _vehicleFile.PathOrDummy)
body.Add("EngineFile", _engineFile.PathOrDummy)
body.Add("GearboxFile", _gearboxFile.PathOrDummy)
'Cycles
If CycleFiles.Count > 0 Then
dic0.Add("Cycles", CycleFiles.Select(Function(sb) sb.PathOrDummy))
body.Add("Cycles", CycleFiles.Select(Function(sb) sb.PathOrDummy))
End If
'AA-TB
'ADVANCED AUXILIARIES
dic0.Add("AuxiliaryAssembly", AuxiliaryAssembly)
dic0.Add("AuxiliaryVersion", AuxiliaryVersion)
dic0.Add("AdvancedAuxiliaryFilePath", AdvancedAuxiliaryFilePath)
body.Add("AuxiliaryAssembly", AuxiliaryAssembly)
body.Add("AuxiliaryVersion", AuxiliaryVersion)
body.Add("AdvancedAuxiliaryFilePath", AdvancedAuxiliaryFilePath)
If AuxPaths.Any() Then
dic0.Add("Aux", AuxPaths.Select(Function(kv) New Dictionary(Of String, Object) From {
body.Add("Aux", AuxPaths.Select(Function(kv) New Dictionary(Of String, Object) From {
{"ID", Trim(UCase(kv.Key))},
{"Type", kv.Value.Type},
{"Path", kv.Value.Path.PathOrDummy},
......@@ -126,14 +126,14 @@ Public Class VectoJob
}))
End If
dic0.Add("VACC", _driverAccelerationFile.PathOrDummy)
dic0.Add("EngineOnlyMode", EngineOnly)
dic0.Add("StartStop", New Dictionary(Of String, Object) From {
body.Add("VACC", _driverAccelerationFile.PathOrDummy)
body.Add("EngineOnlyMode", EngineOnly)
body.Add("StartStop", New Dictionary(Of String, Object) From {
{"Enabled", _startStop},
{"MaxSpeed", _startStopMaxSpeed},
{"MinTime", _startStopMinTime},
{"Delay", StartStopDelay}})
dic0.Add("LAC", New Dictionary(Of String, Object) From {
body.Add("LAC", New Dictionary(Of String, Object) From {
{"Enabled", LookAheadOn},
{"PreviewDistanceFactor", LacPreviewFactor},
{"DF_offset", LacDfOffset},
......@@ -153,9 +153,9 @@ Public Class VectoJob
overspeedDic.Add("MinSpeed", VMin)
overspeedDic.Add("OverSpeed", OverSpeed)
overspeedDic.Add("UnderSpeed", UnderSpeed)
dic0.Add("OverSpeedEcoRoll", overspeedDic)
body.Add("OverSpeedEcoRoll", overspeedDic)
json.Content.Add("Body", JToken.FromObject(dic0))
json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}})
Return json.WriteFile(_sFilePath)
End Function
......
......@@ -124,7 +124,7 @@ Public Class Vehicle
If Not json.ReadFile(_filePath) Then Return False
Try
Dim header As jtoken = json.Content.GetEx("Header")
Dim header As JToken = json.Content.GetEx("Header")
Dim body As JToken = json.Content.GetEx("Body")
_fileVersion = header.GetEx(Of Integer)("FileVersion")
......@@ -253,15 +253,14 @@ Public Class Vehicle
Dim json As New JSONParser
'Header
json.Content.Add("Header", JToken.FromObject(New Dictionary(Of String, Object) From {
Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From {
{"CreatedBy", Lic.LicString & " (" & Lic.GUID & ")"},
{"Date", Now.ToUniversalTime().ToString("o")},
{"AppVersion", VECTOvers},
{"FileVersion", FormatVersion}}))
{"FileVersion", FormatVersion}}
'Body
Dim dic As Dictionary(Of String, Object)
dic = New Dictionary(Of String, Object) From {
Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From {
{"SavedInDeclMode", Cfg.DeclMode},
{"VehCat", VehicleCategory.ToString()},
{"CurbWeight", Mass},
......@@ -295,7 +294,7 @@ Public Class Vehicle
{"FzISO", axle.FzISO}})}}}
}
json.Content.Add("Body", JToken.FromObject(dic))
json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}})
Return json.WriteFile(_filePath)
End Function
......
......@@ -10,6 +10,7 @@
' See the LICENSE.txt for the specific language governing permissions and limitations.
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports Microsoft.VisualBasic.FileIO
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
......@@ -19,7 +20,7 @@ Imports Newtonsoft.Json.Linq
''' </summary>
''' <remarks></remarks>
Public Class JSONParser
Public Content As JObject 'Dictionary(Of String, Object)
Public Content As JToken 'Dictionary(Of String, Object)
Public Sub New()
'Content = New Dictionary(Of String, Object)
......@@ -30,50 +31,11 @@ Public Class JSONParser
Return False
End If
Using reader As TextReader = File.OpenText(path)
JToken.ReadFrom(New JsonTextReader(reader))
Content = JToken.ReadFrom(New JsonTextReader(reader))
End Using
Return True
End Function
''' <summary>
''' Reads a JSON File into the Content variable.
''' </summary>
''' <param name="path"></param>
''' <returns></returns>
''' <remarks></remarks>
'Public Function ReadFile(path As String) As Boolean
' Dim file As TextFieldParser
' Dim str As String
' Content.Clear()
' If Not IO.File.Exists(path) Then
' Return False
' End If
' Try
' file = New TextFieldParser(path)
' Catch ex As Exception
' Return False
' End Try
' If file.EndOfData Then
' file.Close()
' Return False
' End If
' str = file.ReadToEnd
' file.Close()
' Try
' Content = JsonConvert.DeserializeObject(str, Content.GetType)
' Catch ex As Exception
' Return False
' End Try
' Return True
'End Function
''' <summary>
''' Writes the Content variable into a JSON file.
......
......@@ -131,6 +131,7 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\iTextSharp.5.5.9\lib\itextsharp.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
......@@ -140,6 +141,7 @@
<HintPath>..\packages\NLog.4.2.3\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Design" />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment