Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit a3e74ebc authored by Raphael LUZ's avatar Raphael LUZ
Browse files

- New 3rd party JSON library implemented

- JSON signature file
parent a28b42ed
No related branches found
No related tags found
No related merge requests found
File added
File added
This diff is collapsed.
Copyright (c) 2007 James Newton-King
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
Json.NET
http://james.newtonking.com/projects/json-net.aspx
http://www.codeplex.com/json/
https://github.com/JamesNK/Newtonsoft.Json
Description:
Json.NET is a popular high-performance JSON framework for .NET
-Flexible JSON serializer for converting between .NET objects and JSON
-LINQ to JSON for manually reading and writing JSON
-High performance, faster than .NET's built-in JSON serializers
-Write indented, easy to read JSON
-Convert JSON to and from XML
-Supports .NET 2, .NET 3.5, .NET 4, .NET 4.5, Silverlight, Windows Phone and Windows 8 Store
Documentation:
http://james.newtonking.com/projects/json/help/
Versions:
Json.NET has different libaries for the various .NET Framework versions.
-Net45:
.NET latest (4.5)
-Net40:
.NET 4.0
-Net35:
.NET 3.5
-Net20:
.NET 2.0
-WinRT:
Windows 8 Store
-Portable45:
.NET 4.5, Windows Phone 8, Windows 8 Store
-Portable40:
.NET 4.0, Windows Phone 7, Windows 8 Store, Silverlight 4
Notes:
Microsoft stopped support for the Compact Framework in Visual Studio 2010.
For a Compact Framework 3.5 build download Json.NET 3.5.
For a Silverlight 3.0 build download Json.NET 3.5.
\ No newline at end of file
......@@ -27,7 +27,7 @@ Public Class F_FileSign
Lic.FileSigning.NewFile()
Lic.FileSigning.Comment = "User-created"
Lic.FileSigning.Mode = vectolic.cFileSigning.tMode.Manual
For Each lv0 In Me.lvFiles.Items
......@@ -46,17 +46,9 @@ Public Class F_FileSign
Me.TbLicStr.Text = Lic.FileSigning.CreatorLicStr
Me.TbPubKey.Text = Lic.FileSigning.PubKey
Me.LbMode.Text = Lic.FileSigning.Comment
Me.LbMode.Text = Lic.FileSigning.ModeConv(Lic.FileSigning.Mode)
Me.LbDateStr.Text = Lic.FileSigning.DateStr
If Lic.FileSigning.FilesOK.Count > 0 Then
For Each lv0 In Me.lvFiles.Items
lv0.SubItems(1).Text = Lic.FileSigning.FilesMsg(lv0.Index)
......@@ -93,8 +85,8 @@ Public Class F_FileSign
Me.TbLicStr.Text = Lic.FileSigning.CreatorLicStr
Me.TbPubKey.Text = Lic.FileSigning.PubKey
Me.LbMode.Text = Lic.FileSigning.Comment
If Lic.FileSigning.Comment = "Created by VECTO" Then
Me.LbMode.Text = Lic.FileSigning.ModeConv(Lic.FileSigning.Mode)
If Lic.FileSigning.Mode = vectolic.cFileSigning.tMode.Auto Then
Me.LbMode.ForeColor = Color.DarkGreen
Else
Me.LbMode.ForeColor = Color.Red
......
......@@ -479,6 +479,13 @@ lbEr:
Dim ls As List(Of Object)
Dim dic As Dictionary(Of String, Object)
'Meta
dic = New Dictionary(Of String, Object)
dic.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")")
dic.Add("Date", Now.ToString)
dic.Add("Version", VECTOvers)
JSON.Content.Add("Info", dic)
'Main Files
JSON.Content.Add("VehicleFile", stPathVEH.PathOrDummy)
JSON.Content.Add("EngineFile", stPathENG.PathOrDummy)
......@@ -553,7 +560,7 @@ lbEr:
Dim SubPath As cSubPath
Dim JSON As New cJSON
Dim str As String
Dim dic As Dictionary(Of String, Object)
Dim dic As Object
MsgSrc = "Main/ReadInp/GEN"
......@@ -592,7 +599,7 @@ lbEr:
If JSON.Content.ContainsKey("Aux") Then
For Each dic In JSON.Content("Aux")
AuxID = UCase(Trim(dic("ID")))
AuxID = UCase(Trim(dic("ID").ToString))
If AuxPaths.ContainsKey(AuxID) Then
WorkerMsg(tMsgID.Err, "Multiple definitions of the same auxiliary type (" & AuxID & ")!", MsgSrc)
......@@ -644,7 +651,7 @@ lbEr:
dic = JSON.Content("OverSpeedEcoRoll")
Select Case UCase(dic("Mode")).Trim
Select Case UCase(dic("Mode").ToString).Trim
Case "ECOROLL"
OverSpeedOn = False
EcoRollOn = True
......@@ -664,7 +671,7 @@ lbEr:
vMin = dic("MinSpeed")
OverSpeed = dic("OverSpeed")
If dic.ContainsKey("UnderSpeed") Then UnderSpeed = dic("UnderSpeed")
If Not dic("UnderSpeed") Is Nothing Then UnderSpeed = dic("UnderSpeed")
Else
OverSpeedOn = False
......
......@@ -591,7 +591,7 @@ lbNextJob:
'Write file signatures
WorkerMsg(tMsgID.Normal, "Signing files", MsgSrc)
Lic.FileSigning.Comment = "Created by VECTO"
Lic.FileSigning.Mode = vectolic.cFileSigning.tMode.Auto
If Lic.FileSigning.WriteSigFile(SigFile, LicSigAppCode) Then
WorkerMsg(tMsgID.Normal, "Files signed successfully: " & fFILE(SigFile, True), MsgSrc, SigFile)
......
......@@ -82,6 +82,9 @@
<CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\Third Party Libraries\JSON.Net\Bin\Net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
......
......@@ -2,7 +2,7 @@
Module VECTO_Global
Public Const VECTOvers As String = "1.4 RC2 JSON"
Public Const VECTOvers As String = "1.4 RC2 JSON 2"
Public Const LicSigAppCode As String = "VECTO-Release-0093C61E0A2E4BFA9A7ED7E729C56AE4"
Public MyAppPath As String
Public MyConfPath As String
......
Imports System.Collections.Generic
Imports Newtonsoft.Json
'uses JSON.NET http://json.codeplex.com/
Public Class cJSON
Public Content As Dictionary(Of String, Object)
Private fullfile As String
Public ErrorMsg As String
Public Sub New()
Content = New Dictionary(Of String, Object)
......@@ -11,6 +15,79 @@ Public Class cJSON
Public Function ReadFile(ByVal path As String) As Boolean
Dim file As Microsoft.VisualBasic.FileIO.TextFieldParser
Dim str As String
Content.Clear()
'check if file exists
If Not IO.File.Exists(path) Then
ErrorMsg = "file not found"
Return False
End If
'open file
Try
file = New Microsoft.VisualBasic.FileIO.TextFieldParser(path)
Catch ex As Exception
ErrorMsg = ex.Message
Return False
End Try
'Check if file is empty
If file.EndOfData Then
file.Close()
ErrorMsg = "file is empty"
Return False
End If
'read file
str = file.ReadToEnd
'close file
file.Close()
'parse JSON to Dictionary
Try
'JSONobj = JsonConvert.DeserializeObject(str)
Content = JsonConvert.DeserializeObject(str, Content.GetType)
Catch ex As Exception
ErrorMsg = ex.Message
Return False
End Try
Return True
End Function
Public Function WriteFile(ByVal path As String) As Boolean
Dim file As System.IO.StreamWriter
Dim str As String
Dim First As Boolean = True
If Content.Count = 0 Then Return False
Try
str = Newtonsoft.Json.JsonConvert.SerializeObject(Content, Formatting.Indented)
file = My.Computer.FileSystem.OpenTextFileWriter(path, False)
Catch ex As Exception
Return False
End Try
file.Write(str)
file.Close()
Return True
End Function
#Region "old self-made parser"
Private fullfile As String
Private Function ReadFileXXX(ByVal path As String) As Boolean
Dim file As Microsoft.VisualBasic.FileIO.TextFieldParser
Content.Clear()
......@@ -56,7 +133,10 @@ Public Class cJSON
End Function
Public Function WriteFile(ByVal path As String) As Boolean
Private Function WriteFileXXX(ByVal path As String) As Boolean
Dim file As System.IO.StreamWriter
Dim kv As KeyValuePair(Of String, Object)
Dim str As New System.Text.StringBuilder
......@@ -79,7 +159,7 @@ Public Class cJSON
Catch ex As Exception
Return False
End Try
Try
file = My.Computer.FileSystem.OpenTextFileWriter(path, False)
Catch ex As Exception
......@@ -212,11 +292,6 @@ Public Class cJSON
Return str
End Function
Private Function GetObject() As Dictionary(Of String, Object)
Dim MyDic As Dictionary(Of String, Object)
Dim key As String
......@@ -337,6 +412,7 @@ lb20:
End Function
#End Region
......
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