diff --git a/VECTO/Input Files/VectoJob.vb b/VECTO/Input Files/VectoJob.vb index 42ab4f4e593b600323a3f4c35a5b00132f499aa0..a1904254eb9068f5c0d900dccdc74cf5ad917a95 100644 --- a/VECTO/Input Files/VectoJob.vb +++ b/VECTO/Input Files/VectoJob.vb @@ -602,6 +602,10 @@ Public Class VectoJob End Get End Property + Public Sub ValidateComponentHashes() Implements IDeclarationInputDataProvider.ValidateComponentHashes + Throw New NotImplementedException + End Sub + Public ReadOnly Property XMLHash As XElement Implements IDeclarationInputDataProvider.XMLHash Get Return Nothing diff --git a/VectoCommon/VectoCommon/InputData/IInputDataProvider.cs b/VectoCommon/VectoCommon/InputData/IInputDataProvider.cs index 3b26742df8a1f307f110a2e3549de0d7388f0230..d65ac6cd801b995da130967f18bed2f8379f77d7 100644 --- a/VectoCommon/VectoCommon/InputData/IInputDataProvider.cs +++ b/VectoCommon/VectoCommon/InputData/IInputDataProvider.cs @@ -44,6 +44,8 @@ namespace TUGraz.VectoCommon.InputData { IDeclarationJobInputData JobInputData { get; } + void ValidateComponentHashes(); + XElement XMLHash { get; } } diff --git a/VectoCommon/VectoHashing/VectoHash.cs b/VectoCommon/VectoHashing/VectoHash.cs index ac1a362332b1eeaf3f22759e2a2582fbcfdb6154..01679936682cf3c71269b04202d6082d81489ee2 100644 --- a/VectoCommon/VectoHashing/VectoHash.cs +++ b/VectoCommon/VectoHashing/VectoHash.cs @@ -37,6 +37,7 @@ using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Xml; using System.Xml.Linq; +using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Hashing; using TUGraz.VectoCommon.Resources; using TUGraz.VectoCommon.Utils; @@ -459,5 +460,30 @@ namespace TUGraz.VectoHashing } return nodes[0].InnerText; } + + public static void ValidateJob(XmlDocument doc) + { + var h = VectoHash.Load(doc); + var components = h.GetContainigComponents().GroupBy(s => s) + .Select(g => new { Entry = g.Key, Count = g.Count() }); + var invalid = new List<string>(); + foreach (var component in components) { + if (component.Entry == VectoComponents.Vehicle) { + continue; + } + for (var i = 0; i < component.Count; i++) { + //var readHash = h.ReadHash(component.Entry, i); + if (!h.ValidateHash(component.Entry, i)) { + var read = h.ReadHash(component.Entry, i); + var computed = h.ComputeHash(component.Entry, i); + invalid.Add($"Hash for component {component.Entry} ({i + 1}) invalid. Read: '{read}', Computed: '{computed}'"); + } + } + } + + if (invalid.Count > 0) { + throw new VectoException(invalid.JoinString(System.Environment.NewLine)); + } + } } } diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONComponentInputData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONComponentInputData.cs index 9806032bac7a6ed8a982e218e4331287dd09bf77..82bd1d0435ae6884d7918d04874dbd8f7475d13d 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONComponentInputData.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONComponentInputData.cs @@ -102,6 +102,11 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON get { return this; } } + public void ValidateComponentHashes() + { + throw new NotImplementedException(); + } + public XElement XMLHash { get { return new XElement(XMLNames.DI_Signature); } diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs index bc46a7e4013c285e365b1b276df45b0497210a01..1688c1d6b30279bc805162519581f55ce28a43a3 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs @@ -265,6 +265,11 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON get { return this; } } + public void ValidateComponentHashes() + { + + } + public XElement XMLHash { get { return new XElement(XMLNames.DI_Signature); } diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationInputDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationInputDataProvider.cs index 9c125841f2286c830b084f79a3a3392f661f01ee..1a88530b1ea4182f055b8eb67dab8711727bd6df 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationInputDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationInputDataProvider.cs @@ -91,6 +91,11 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration } + public void ValidateComponentHashes() + { + VectoHash.ValidateJob(Document); + } + public virtual XElement XMLHash { get; private set; } } diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationJobInputDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationJobInputDataProvider.cs index 28baa39d3d9429fa139c9cec2eedb57c1b7d0cec..e9b68cd7f52a4d9ee4d8e0a63f5d35d2a81272da 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationJobInputDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/DataProvider/XMLDeclarationJobInputDataProvider.cs @@ -35,6 +35,7 @@ using TUGraz.VectoCommon.InputData; using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.Interfaces; using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.Reader; using TUGraz.VectoCore.Utils; +using TUGraz.VectoHashing; namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider { diff --git a/VectoCore/VectoCore/InputData/IVectoRunDataFactory.cs b/VectoCore/VectoCore/InputData/IVectoRunDataFactory.cs index d24a72e7c2b0ab8268fe3a0a3b46df63291b54da..8f5f8e516b2a0389e28ac14276bd943c41175b8e 100644 --- a/VectoCore/VectoCore/InputData/IVectoRunDataFactory.cs +++ b/VectoCore/VectoCore/InputData/IVectoRunDataFactory.cs @@ -30,6 +30,7 @@ */ using System.Collections.Generic; +using TUGraz.VectoCommon.InputData; using TUGraz.VectoCore.Models.Simulation.Data; namespace TUGraz.VectoCore.InputData @@ -37,5 +38,7 @@ namespace TUGraz.VectoCore.InputData public interface IVectoRunDataFactory { IEnumerable<VectoRunData> NextRun(); + + IInputDataProvider DataProvider { get; } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationModeVectoRunDataFactory.cs b/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationModeVectoRunDataFactory.cs index c24aefdf5bd7ae4ff92d44038e8a14a375f9901d..a66a44e338e443a8dbf2cc72cf1a994477749d52 100644 --- a/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationModeVectoRunDataFactory.cs +++ b/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationModeVectoRunDataFactory.cs @@ -193,6 +193,11 @@ namespace TUGraz.VectoCore.InputData.Reader.Impl } } + public IInputDataProvider DataProvider + { + get { return InputDataProvider; } + } + private IEnumerable<VectoRunData> VectoRunDataNonExempted() { diff --git a/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationVTPModeVectoRunDataFactory.cs b/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationVTPModeVectoRunDataFactory.cs index 644710f86c35b802aeb2636a926c2c273c3fb5b5..d1418add776ceebc3f5f1e2aca68fa8d15150024 100644 --- a/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationVTPModeVectoRunDataFactory.cs +++ b/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationVTPModeVectoRunDataFactory.cs @@ -66,8 +66,12 @@ namespace TUGraz.VectoCore.InputData.Reader.Impl public IVTPReport Report; protected ShiftStrategyParameters GearshiftData; - public DeclarationVTPModeVectoRunDataFactory(IVTPDeclarationInputDataProvider ivtpProvider, IVTPReport report) : this( - ivtpProvider.JobInputData, report) { } + public DeclarationVTPModeVectoRunDataFactory(IVTPDeclarationInputDataProvider ivtpProvider, IVTPReport report) : + this( + ivtpProvider.JobInputData, report) + { + DataProvider = ivtpProvider; + } protected DeclarationVTPModeVectoRunDataFactory(IVTPDeclarationJobInputData job, IVTPReport report) { @@ -217,6 +221,8 @@ namespace TUGraz.VectoCore.InputData.Reader.Impl } + public IInputDataProvider DataProvider { get; } + protected virtual AuxFanData GetFanData() { return new AuxFanData() { diff --git a/VectoCore/VectoCore/InputData/Reader/Impl/EngineeringModeVectoRunDataFactory.cs b/VectoCore/VectoCore/InputData/Reader/Impl/EngineeringModeVectoRunDataFactory.cs index d5bcdc581e215a5b8ba927bac989b8e311dcb1bb..f08fd005adcdd9c1e701f7a2749eef6807c45b85 100644 --- a/VectoCore/VectoCore/InputData/Reader/Impl/EngineeringModeVectoRunDataFactory.cs +++ b/VectoCore/VectoCore/InputData/Reader/Impl/EngineeringModeVectoRunDataFactory.cs @@ -174,6 +174,9 @@ namespace TUGraz.VectoCore.InputData.Reader.Impl } } - + public IInputDataProvider DataProvider + { + get { return InputDataProvider; } + } } } diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs b/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs index d882a0866fd895751a1b3cf191358e77a6895370..f9f69f9d012164dafc685ea49c1fbcea326bb9af 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs @@ -59,13 +59,14 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl private readonly ExecutionMode _mode; public SimulatorFactory(ExecutionMode mode, IInputDataProvider dataProvider, IOutputDataWriter writer, - IDeclarationReport declarationReport = null, IVTPReport vtpReport = null, bool validate = true) + IDeclarationReport declarationReport = null, IVTPReport vtpReport = null, bool validate = true, bool validateHashes = true) { Log.Info("########## VectoCore Version {0} ##########", Assembly.GetExecutingAssembly().GetName().Version); JobNumber = Interlocked.Increment(ref _jobNumberCounter); _mode = mode; ModWriter = writer; Validate = validate; + ValidateComponentHashes = validateHashes; int workerThreads; int completionThreads; @@ -87,6 +88,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl } } + public bool ValidateComponentHashes { get; set; } + private void CreateDeclarationDataReader(IInputDataProvider dataProvider, IDeclarationReport declarationReport, IVTPReport vtpReport) { if (dataProvider is IVTPDeclarationInputDataProvider) { @@ -146,6 +149,10 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl var i = 0; var warning1Hz = false; + if (ValidateComponentHashes && DataReader.DataProvider is IDeclarationInputDataProvider declDataProvider) { + declDataProvider.ValidateComponentHashes(); + } + foreach (var data in DataReader.NextRun()) { var current = i++; var d = data;