From 8120b9e48da101a04ada0296fe2bdefaefbe7c66 Mon Sep 17 00:00:00 2001 From: Markus Quaritsch <markus.quaritsch@tugraz.at> Date: Thu, 7 Dec 2017 16:15:45 +0100 Subject: [PATCH] refactoring of XML validation: consider schema version number read from document, use single class for validating all vecto-related xml files --- HashingCmd/Program.cs | 71 +-- HashingTool/HashingTool.csproj | 2 +- HashingTool/Util/AsyncXMLValidator.cs | 58 ++ HashingTool/Util/XMLValidator.cs | 109 ---- .../ViewModel/HashComponentDataViewModel.cs | 5 +- .../ViewModel/UserControl/XMLFileSelector.cs | 5 +- .../XML/ToHash/vecto_engine-input.xml | 2 +- .../XML/ToHash/vecto_engine_withid-input.xml | 2 +- .../XML/ToHash/vecto_gearbox-input.xml | 2 +- VectoCommon/VectoHashingTest/VectoHashTest.cs | 31 +- .../XMLDeclarationInputDataProvider.cs | 32 +- ...ractEngineeringXMLComponentDataProvider.cs | 4 +- .../XMLEngineeringAirdragDataProvider.cs | 69 +-- .../XMLEngineeringAngledriveDataProvider.cs | 82 +-- .../XMLEngineeringAuxiliaryDataProvider.cs | 213 +++---- .../XMLEngineeringAxlegearDataProvider.cs | 90 +-- .../XMLEngineeringDriverDataProvider.cs | 320 +++++------ .../XMLEngineeringEngineDataProvider.cs | 230 ++++---- .../XMLEngineeringGearboxDataProvider.cs | 284 ++++----- .../XMLEngineeringInputDataProvider.cs | 69 +-- .../XMLEngineeringJobInputDataProvider.cs | 7 +- .../XMLEngineeringRetarderDataProvider.cs | 72 +-- ...LEngineeringTorqueConverterDataProvider.cs | 158 ++--- .../XMLEngineeringVehicleDataProvider.cs | 54 +- .../OutputData/XML/AbstractXMLWriter.cs | 3 +- .../OutputData/XML/XMLCustomerReport.cs | 10 +- .../OutputData/XML/XMLDeclarationWriter.cs | 1 + .../OutputData/XML/XMLEngineeringWriter.cs | 2 +- .../OutputData/XML/XMLManufacturerReport.cs | 10 +- .../Resources/XSD/VectoComponent.1.0.xsd | 31 + .../XSD/VectoEngineeringInput.0.7.xsd | 15 + .../Resources/XSD/VectoInput.1.0.xsd | 10 + .../Resources/XSD/VectoOutputCustomer.0.4.xsd | 258 +++++++++ .../Resources/XSD/VectoOutputCustomer.xsd | 2 +- .../XSD/VectoOutputManufacturer.0.4.xsd | 540 ++++++++++++++++++ VectoCore/VectoCore/Utils/XMLValidator.cs | 148 +++++ VectoCore/VectoCore/VectoCore.csproj | 16 + .../Class5_Tractor_topTorque.vveh | 2 +- .../engineering_axlegear-sample_ref.xml | 2 +- .../engineering_engine-sample_ref.xml | 2 +- .../engineering_gearbox-sample_ref.xml | 2 +- ...engineering_job-engine_only-sample_ref.xml | 2 +- .../engineering_job-sample.xml | 2 +- .../engineering_job-sample_FULL.xml | 2 +- .../engineering_job-sample_ref.xml | 2 +- .../engineering_retarder-sample_ref.xml | 2 +- .../engineering_vehicle_ref.xml | 2 +- VectoCore/VectoCoreTest/XML/XMLReportTest.cs | 41 +- 48 files changed, 1967 insertions(+), 1111 deletions(-) create mode 100644 HashingTool/Util/AsyncXMLValidator.cs delete mode 100644 HashingTool/Util/XMLValidator.cs create mode 100644 VectoCore/VectoCore/Resources/XSD/VectoComponent.1.0.xsd create mode 100644 VectoCore/VectoCore/Resources/XSD/VectoEngineeringInput.0.7.xsd create mode 100644 VectoCore/VectoCore/Resources/XSD/VectoInput.1.0.xsd create mode 100644 VectoCore/VectoCore/Resources/XSD/VectoOutputCustomer.0.4.xsd create mode 100644 VectoCore/VectoCore/Resources/XSD/VectoOutputManufacturer.0.4.xsd create mode 100644 VectoCore/VectoCore/Utils/XMLValidator.cs diff --git a/HashingCmd/Program.cs b/HashingCmd/Program.cs index 5ce77962cb..89e4fa8963 100644 --- a/HashingCmd/Program.cs +++ b/HashingCmd/Program.cs @@ -57,7 +57,7 @@ hashingcmd.exe -h: print help -v: verify hashed file -s: create hashed file --x: validate generated XML against VECTO XML schema +-x: validate XML file against VECTO XML schema -c: compute hash and write to stdout -r: read hash from file and write to stdout "; @@ -70,7 +70,7 @@ hashingcmd.exe }; static bool _validateXML; - private static bool xmlValid = true; + static int Main(string[] args) { @@ -158,68 +158,36 @@ hashingcmd.exe writer.Close(); if (_validateXML) { - ValidateXML(destination); + new XMLValidator(XmlReader.Create(destination), null, ValidationCallBack).ValidateXML(XMLValidator.XmlDocumentType + .DeclarationComponentData); + WriteLine("Valid", ConsoleColor.Green); + } } - private static void ValidateXML(string filename) + private static void ValidationCallBack(XmlSeverityType severity, ValidationEvent evt) { - try { - var settings = new XmlReaderSettings { - ValidationType = ValidationType.Schema, - ValidationFlags = //XmlSchemaValidationFlags.ProcessInlineSchema | - //XmlSchemaValidationFlags.ProcessSchemaLocation | - XmlSchemaValidationFlags.ReportValidationWarnings - }; - settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack); - settings.Schemas.Add(GetXMLSchema("")); - - var vreader = XmlReader.Create(filename, settings); - var doc = new XmlDocument(); - doc.Load(vreader); - doc.Validate(ValidationCallBack); - //while (vreader.Read()) { - // Console.WriteLine(vreader.Value); - //} - if (xmlValid) { - WriteLine("Valid", ConsoleColor.Green); - } - } catch (Exception e) { - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine("Failed to validate hashed XML file!"); - Console.Error.WriteLine(e.Message); - if (e.InnerException != null) { - Console.Error.WriteLine(e.InnerException.Message); - } - Console.ResetColor(); - } - } - - private static void ValidationCallBack(object sender, ValidationEventArgs args) - { - xmlValid = false; - if (args.Severity == XmlSeverityType.Error) { + var args = evt.ValidationEventArgs; + if (severity == XmlSeverityType.Error) { throw new Exception(string.Format("Validation error: {0}" + Environment.NewLine + - "Line: {1}", args.Message, args.Exception.LineNumber)); + "Line: {1}", args.Message, args.Exception.LineNumber), evt.Exception); } else { - Console.Error.WriteLine(string.Format("Validation warning: {0}" + Environment.NewLine + - "Line: {1}", args.Message, args.Exception.LineNumber)); + Console.Error.WriteLine("Validation warning: {0}" + Environment.NewLine + + "Line: {1}", args.Message, args.Exception.LineNumber); } } - private static XmlSchemaSet GetXMLSchema(string version) + private static void ValidateFile(string filename) { - var resource = RessourceHelper.LoadResourceAsStream(RessourceHelper.ResourceType.XMLSchema, "VectoComponent.xsd"); - var xset = new XmlSchemaSet() { XmlResolver = new XmlResourceResolver() }; - var reader = XmlReader.Create(resource, new XmlReaderSettings(), "schema://"); - xset.Add(XmlSchema.Read(reader, null)); - xset.Compile(); - return xset; + new XMLValidator(XmlReader.Create(filename),null, ValidationCallBack).ValidateXML( + XMLValidator.XmlDocumentType.DeclarationJobData | XMLValidator.XmlDocumentType.CustomerReport | + XMLValidator.XmlDocumentType.ManufacturerReport | XMLValidator.XmlDocumentType.DeclarationComponentData); } - + private static void ReadHashAction(string filename, VectoHash h) { WriteLine("reading hashes"); + ValidateFile(filename); var components = h.GetContainigComponents().GroupBy(s => s) .Select(g => new { Entry = g.Key, Count = g.Count() }); @@ -237,6 +205,7 @@ hashingcmd.exe private static void ComputeHashAction(string filename, VectoHash h) { WriteLine("computing hashes"); + ValidateFile(filename); var components = h.GetContainigComponents(); if (components.Count > 1) { @@ -262,7 +231,7 @@ hashingcmd.exe private static void VerifyHashAction(string filename, VectoHash h) { WriteLine("validating hashes"); - + ValidateFile(filename); var components = h.GetContainigComponents().GroupBy(s => s) .Select(g => new { Entry = g.Key, Count = g.Count() }); foreach (var component in components) { diff --git a/HashingTool/HashingTool.csproj b/HashingTool/HashingTool.csproj index 371a4c2c0d..d3195f3739 100644 --- a/HashingTool/HashingTool.csproj +++ b/HashingTool/HashingTool.csproj @@ -92,7 +92,7 @@ <Compile Include="ViewModel\VerifyJobInputDataViewModel.cs" /> <Compile Include="ViewModel\VerifyComponentInputDataViewModel.cs" /> <Compile Include="ViewModel\UserControl\XMLFileSelector.cs" /> - <Compile Include="Util\XMLValidator.cs" /> + <Compile Include="Util\AsyncXMLValidator.cs" /> <Compile Include="ViewModel\VerifyResultDataViewModel.cs" /> <Compile Include="Views\AboutDialog.xaml.cs"> <DependentUpon>AboutDialog.xaml</DependentUpon> diff --git a/HashingTool/Util/AsyncXMLValidator.cs b/HashingTool/Util/AsyncXMLValidator.cs new file mode 100644 index 0000000000..4c531174a4 --- /dev/null +++ b/HashingTool/Util/AsyncXMLValidator.cs @@ -0,0 +1,58 @@ +/* +* This file is part of VECTO. +* +* Copyright © 2012-2017 European Union +* +* Developed by Graz University of Technology, +* Institute of Internal Combustion Engines and Thermodynamics, +* Institute of Technical Informatics +* +* VECTO is licensed under the EUPL, Version 1.1 or - as soon they will be approved +* by the European Commission - subsequent versions of the EUPL (the "Licence"); +* You may not use VECTO except in compliance with the Licence. +* You may obtain a copy of the Licence at: +* +* https://joinup.ec.europa.eu/community/eupl/og_page/eupl +* +* Unless required by applicable law or agreed to in writing, VECTO +* distributed under the Licence is distributed on an "AS IS" basis, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the Licence for the specific language governing permissions and +* limitations under the Licence. +* +* Authors: +* Stefan Hausberger, hausberger@ivt.tugraz.at, IVT, Graz University of Technology +* Christian Kreiner, christian.kreiner@tugraz.at, ITI, Graz University of Technology +* Michael Krisper, michael.krisper@tugraz.at, ITI, Graz University of Technology +* Raphael Luz, luz@ivt.tugraz.at, IVT, Graz University of Technology +* Markus Quaritsch, markus.quaritsch@tugraz.at, IVT, Graz University of Technology +* Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology +*/ + +using System; +using System.Threading.Tasks; +using System.Xml; +using System.Xml.Schema; +using TUGraz.VectoCore.Utils; + +namespace HashingTool.Util +{ + public class AsyncXMLValidator + { + private XMLValidator _validator; + + public AsyncXMLValidator(XmlReader xml, Action<bool> resultaction, Action<XmlSeverityType, ValidationEvent> validationErrorAction) + { + _validator = new XMLValidator(xml, resultaction, validationErrorAction); + } + + public Task<bool> ValidateXML(TUGraz.VectoCore.Utils.XMLValidator.XmlDocumentType docType) + { + var task = new Task<bool>(() => _validator.ValidateXML(docType)); + task.Start(); + return task; + } + } + + +} diff --git a/HashingTool/Util/XMLValidator.cs b/HashingTool/Util/XMLValidator.cs deleted file mode 100644 index 3d222adb33..0000000000 --- a/HashingTool/Util/XMLValidator.cs +++ /dev/null @@ -1,109 +0,0 @@ -/* -* This file is part of VECTO. -* -* Copyright © 2012-2017 European Union -* -* Developed by Graz University of Technology, -* Institute of Internal Combustion Engines and Thermodynamics, -* Institute of Technical Informatics -* -* VECTO is licensed under the EUPL, Version 1.1 or - as soon they will be approved -* by the European Commission - subsequent versions of the EUPL (the "Licence"); -* You may not use VECTO except in compliance with the Licence. -* You may obtain a copy of the Licence at: -* -* https://joinup.ec.europa.eu/community/eupl/og_page/eupl -* -* Unless required by applicable law or agreed to in writing, VECTO -* distributed under the Licence is distributed on an "AS IS" basis, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the Licence for the specific language governing permissions and -* limitations under the Licence. -* -* Authors: -* Stefan Hausberger, hausberger@ivt.tugraz.at, IVT, Graz University of Technology -* Christian Kreiner, christian.kreiner@tugraz.at, ITI, Graz University of Technology -* Michael Krisper, michael.krisper@tugraz.at, ITI, Graz University of Technology -* Raphael Luz, luz@ivt.tugraz.at, IVT, Graz University of Technology -* Markus Quaritsch, markus.quaritsch@tugraz.at, IVT, Graz University of Technology -* Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology -*/ - -using System; -using System.Threading.Tasks; -using System.Xml; -using System.Xml.Schema; -using TUGraz.VectoCore.Utils; - -namespace HashingTool.Util -{ - public class XMLValidator - { - private readonly Action<XmlSeverityType, ValidationEvent> _validationErrorAction; - private readonly Action<bool> _resultAction; - private bool _valid; - - public XMLValidator(Action<bool> resultaction, Action<XmlSeverityType, ValidationEvent> validationErrorAction) - { - _validationErrorAction = validationErrorAction ?? ((x, y) => { }); - _resultAction = resultaction ?? (x => { }); - _valid = false; - } - - public Task<bool> ValidateXML(XmlReader hashedComponent) - { - var task = new Task<bool>(() => DoValidation(hashedComponent)); - task.Start(); - return task; - } - - private bool DoValidation(XmlReader hashedComponent) - { - _valid = true; - try { - var settings = new XmlReaderSettings { - ValidationType = ValidationType.Schema, - ValidationFlags = //XmlSchemaValidationFlags.ProcessInlineSchema | - //XmlSchemaValidationFlags.ProcessSchemaLocation | - XmlSchemaValidationFlags.ReportValidationWarnings - }; - settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack); - settings.Schemas.Add(GetXMLSchema("")); - - var vreader = XmlReader.Create(hashedComponent, settings); - var doc = new XmlDocument(); - doc.Load(vreader); - doc.Validate(ValidationCallBack); - } catch (Exception e) { - _validationErrorAction(XmlSeverityType.Error, new ValidationEvent() { Exception = e }); - } - return _valid; - } - - private void ValidationCallBack(object sender, ValidationEventArgs args) - { - _resultAction(false); - _valid = false; - _validationErrorAction(args.Severity, new ValidationEvent { ValidationEventArgs = args }); - } - - private static XmlSchemaSet GetXMLSchema(string version) - { - var xset = new XmlSchemaSet() { XmlResolver = new XmlResourceResolver() }; - foreach (var schema in new[] {"VectoComponent.xsd", "VectoInput.xsd", "VectoOutputManufacturer.xsd", "VectoOutputCustomer.xsd"}) { - var resource = RessourceHelper.LoadResourceAsStream(RessourceHelper.ResourceType.XMLSchema, schema); - - var reader = XmlReader.Create(resource, new XmlReaderSettings(), "schema://"); - xset.Add(XmlSchema.Read(reader, null)); - } - xset.Compile(); - return xset; - } - } - - public class ValidationEvent - { - public Exception Exception; - public ValidationEventArgs ValidationEventArgs; - } -} diff --git a/HashingTool/ViewModel/HashComponentDataViewModel.cs b/HashingTool/ViewModel/HashComponentDataViewModel.cs index e3c02db878..8d280f73a9 100644 --- a/HashingTool/ViewModel/HashComponentDataViewModel.cs +++ b/HashingTool/ViewModel/HashComponentDataViewModel.cs @@ -43,6 +43,7 @@ using System.Xml.Schema; using HashingTool.Helper; using HashingTool.Util; using HashingTool.ViewModel.UserControl; +using TUGraz.VectoCore.Utils; using TUGraz.VectoHashing; using TUGraz.VectoHashing.Impl; @@ -160,7 +161,7 @@ namespace HashingTool.ViewModel ms.Flush(); ms.Seek(0, SeekOrigin.Begin); ComponentDataValid = true; - var validator = new XMLValidator(r => { ComponentDataValid = r; }, + var validator = new AsyncXMLValidator(XmlReader.Create(ms), r => { ComponentDataValid = r; }, (s, e) => { Application.Current.Dispatcher.Invoke(() => _xmlFile.LogError( string.Format("Validation {0} Line {2}: {1}", s == XmlSeverityType.Warning ? "WARNING" : "ERROR", @@ -170,7 +171,7 @@ namespace HashingTool.ViewModel : e.ValidationEventArgs.Message, e.ValidationEventArgs == null ? 0 : e.ValidationEventArgs.Exception.LineNumber))); }); - await validator.ValidateXML(XmlReader.Create(ms)); + await validator.ValidateXML(XMLValidator.XmlDocumentType.DeclarationComponentData); } if (ComponentDataValid != null && ComponentDataValid.Value) { //var c14N = XMLHashProvider.DefaultCanonicalizationMethod.ToArray(); diff --git a/HashingTool/ViewModel/UserControl/XMLFileSelector.cs b/HashingTool/ViewModel/UserControl/XMLFileSelector.cs index ea4d2142fa..3d016b1474 100644 --- a/HashingTool/ViewModel/UserControl/XMLFileSelector.cs +++ b/HashingTool/ViewModel/UserControl/XMLFileSelector.cs @@ -40,6 +40,7 @@ using System.Xml; using System.Xml.Schema; using HashingTool.Helper; using HashingTool.Util; +using TUGraz.VectoCore.Utils; namespace HashingTool.ViewModel.UserControl { @@ -269,7 +270,7 @@ namespace HashingTool.ViewModel.UserControl { var valid = true; try { - var validator = new XMLValidator(r => { valid = r; }, + var validator = new AsyncXMLValidator(xml, r => { valid = r; }, (s, e) => { Application.Current.Dispatcher.Invoke( () => @@ -281,7 +282,7 @@ namespace HashingTool.ViewModel.UserControl : e.ValidationEventArgs.Message, e.ValidationEventArgs == null ? 0 : e.ValidationEventArgs.Exception.LineNumber))); }); - await validator.ValidateXML(xml); + await validator.ValidateXML(XMLValidator.XmlDocumentType.DeclarationComponentData | XMLValidator.XmlDocumentType.DeclarationJobData | XMLValidator.XmlDocumentType.CustomerReport | XMLValidator.XmlDocumentType.ManufacturerReport); } catch (Exception e) { LogError(e.Message); } diff --git a/VectoCommon/VectoHashingTest/Testdata/XML/ToHash/vecto_engine-input.xml b/VectoCommon/VectoHashingTest/Testdata/XML/ToHash/vecto_engine-input.xml index 4bebaa2369..499da0ab5c 100644 --- a/VectoCommon/VectoHashingTest/Testdata/XML/ToHash/vecto_engine-input.xml +++ b/VectoCommon/VectoHashingTest/Testdata/XML/ToHash/vecto_engine-input.xml @@ -2,7 +2,7 @@ <tns:VectoInputDeclaration xmlns="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.8" xmlns:tns="urn:tugraz:ivt:VectoAPI:DeclarationComponent:v0.8" - xmlns:di="http://www.w3.org/2000/09/xmldsig#" schemaVersion="0.6" + xmlns:di="http://www.w3.org/2000/09/xmldsig#" schemaVersion="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:DeclarationComponent:v0.8 ../XSD/VectoComponent.xsd"> <tns:Engine> diff --git a/VectoCommon/VectoHashingTest/Testdata/XML/ToHash/vecto_engine_withid-input.xml b/VectoCommon/VectoHashingTest/Testdata/XML/ToHash/vecto_engine_withid-input.xml index 663762376f..d036f868ba 100644 --- a/VectoCommon/VectoHashingTest/Testdata/XML/ToHash/vecto_engine_withid-input.xml +++ b/VectoCommon/VectoHashingTest/Testdata/XML/ToHash/vecto_engine_withid-input.xml @@ -2,7 +2,7 @@ <tns:VectoInputDeclaration xmlns="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.8" xmlns:tns="urn:tugraz:ivt:VectoAPI:DeclarationComponent:v0.8" - xmlns:di="http://www.w3.org/2000/09/xmldsig#" schemaVersion="0.6" + xmlns:di="http://www.w3.org/2000/09/xmldsig#" schemaVersion="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:DeclarationComponent:v0.8 ../XSD/VectoComponent.xsd"> <tns:Engine> diff --git a/VectoCommon/VectoHashingTest/Testdata/XML/ToHash/vecto_gearbox-input.xml b/VectoCommon/VectoHashingTest/Testdata/XML/ToHash/vecto_gearbox-input.xml index 83a5f29092..0f0883a338 100644 --- a/VectoCommon/VectoHashingTest/Testdata/XML/ToHash/vecto_gearbox-input.xml +++ b/VectoCommon/VectoHashingTest/Testdata/XML/ToHash/vecto_gearbox-input.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<tns:VectoInputDeclaration xmlns="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.8" xmlns:tns="urn:tugraz:ivt:VectoAPI:DeclarationComponent:v0.8" xmlns:di="http://www.w3.org/2000/09/xmldsig#" schemaVersion="0.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:DeclarationComponent:v0.8 ../XSD/VectoComponent.xsd"> +<tns:VectoInputDeclaration xmlns="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.8" xmlns:tns="urn:tugraz:ivt:VectoAPI:DeclarationComponent:v0.8" xmlns:di="http://www.w3.org/2000/09/xmldsig#" schemaVersion="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:DeclarationComponent:v0.8 ../XSD/VectoComponent.xsd"> <tns:Gearbox> <Data> <Manufacturer>Generic Gearbox Manufacturer</Manufacturer> diff --git a/VectoCommon/VectoHashingTest/VectoHashTest.cs b/VectoCommon/VectoHashingTest/VectoHashTest.cs index 986e32cb75..163bff91ce 100644 --- a/VectoCommon/VectoHashingTest/VectoHashTest.cs +++ b/VectoCommon/VectoHashingTest/VectoHashTest.cs @@ -414,16 +414,8 @@ namespace VectoHashingTest Assert.IsTrue(h2.ValidateHash()); // re-load generated XML and perform XSD validation - var settings = new XmlReaderSettings() { - ValidationType = ValidationType.Schema, - ValidationFlags = XmlSchemaValidationFlags.ProcessInlineSchema | - //XmlSchemaValidationFlags.ProcessSchemaLocation | - XmlSchemaValidationFlags.ReportValidationWarnings - }; - settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack); - settings.Schemas.Add(GetXMLSchema(false)); - var xmlValidator = XmlReader.Create(destination, settings); - var xmlDoc = XDocument.Load(xmlValidator); + var validator = new XMLValidator(XmlReader.Create(destination)); + Assert.IsTrue(validator.ValidateXML(XMLValidator.XmlDocumentType.DeclarationComponentData)); } @@ -505,24 +497,5 @@ namespace VectoHashingTest { AssertHelper.Exception<ArgumentOutOfRangeException>(() => ((VectoComponents)9999).HashIdPrefix()); } - - private static XmlSchemaSet GetXMLSchema(bool job) - { - var resource = RessourceHelper.LoadResourceAsStream(RessourceHelper.ResourceType.XMLSchema, - job ? "VectoInput.xsd" : "VectoComponent.xsd"); - var xset = new XmlSchemaSet() { XmlResolver = new XmlResourceResolver() }; - var reader = XmlReader.Create(resource, new XmlReaderSettings(), "schema://"); - xset.Add(XmlSchema.Read(reader, null)); - xset.Compile(); - return xset; - } - - private static void ValidationCallBack(object sender, ValidationEventArgs args) - { - if (args.Severity == XmlSeverityType.Error) { - throw new Exception(string.Format("Validation error: {0}" + Environment.NewLine + - "Line: {1}", args.Message, args.Exception.LineNumber)); - } - } } } diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/XMLDeclarationInputDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/XMLDeclarationInputDataProvider.cs index 6e8b95b573..63ad01d6dd 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/XMLDeclarationInputDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Declaration/XMLDeclarationInputDataProvider.cs @@ -30,6 +30,7 @@ */ using System; +using System.IO; using System.Xml; using System.Xml.Linq; using System.Xml.Schema; @@ -61,21 +62,13 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration protected XMLDeclarationInputDataProvider(XmlReader inputData, string source, bool verifyXml) { Source = source; - if (verifyXml) { - var settings = new XmlReaderSettings { - ValidationType = ValidationType.Schema, - ValidationFlags = XmlSchemaValidationFlags.ProcessInlineSchema | - //XmlSchemaValidationFlags.ProcessSchemaLocation | - XmlSchemaValidationFlags.ReportValidationWarnings - }; - settings.ValidationEventHandler += ValidationCallBack; - settings.Schemas.Add(GetXMLSchema("")); + var xmldoc = new XmlDocument(); + xmldoc.Load(inputData); - inputData = XmlReader.Create(inputData, settings); + if (verifyXml) { + new XMLValidator(xmldoc, null, ValidationCallBack).ValidateXML(XMLValidator.XmlDocumentType.DeclarationJobData); } - var xmldoc = new XmlDocument(); - xmldoc.Load(inputData); var h = VectoHash.Load(xmldoc); XMLHash = h.ComputeXmlHash(); Document = new XPathDocument(new XmlNodeReader(xmldoc)); @@ -85,24 +78,15 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Declaration public string Source { get; protected set; } - private static void ValidationCallBack(object sender, ValidationEventArgs args) + private static void ValidationCallBack(XmlSeverityType severity, ValidationEvent evt) { - if (args.Severity == XmlSeverityType.Error) { + if (severity == XmlSeverityType.Error) { + var args = evt.ValidationEventArgs; throw new VectoException("Validation error: {0}" + Environment.NewLine + "Line: {1}", args.Message, args.Exception.LineNumber); } } - private static XmlSchemaSet GetXMLSchema(string version) - { - var resource = RessourceHelper.LoadResourceAsStream(RessourceHelper.ResourceType.XMLSchema, "VectoInput.xsd"); - var xset = new XmlSchemaSet() { XmlResolver = new XmlResourceResolver() }; - var reader = XmlReader.Create(resource, new XmlReaderSettings(), XmlResourceResolver.BaseUri); - xset.Add(XmlSchema.Read(reader, null)); - xset.Compile(); - return xset; - } - public IDeclarationJobInputData JobInputData { get { return _xmlJobData; } diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/AbstractEngineeringXMLComponentDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/AbstractEngineeringXMLComponentDataProvider.cs index 68cbf355d3..b4bc0fb6f9 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/AbstractEngineeringXMLComponentDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/AbstractEngineeringXMLComponentDataProvider.cs @@ -48,11 +48,11 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering protected readonly string FSBasePath; - protected readonly XPathDocument XMLDocument; + protected readonly XmlDocument XMLDocument; protected AbstractEngineeringXMLComponentDataProvider( XMLEngineeringInputDataProvider xmlEngineeringJobInputDataProvider, - XPathDocument document, string xmlBasePath, string fsBasePath) + XmlDocument document, string xmlBasePath, string fsBasePath) { XMLDocument = document; XBasePath = xmlBasePath; diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringAirdragDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringAirdragDataProvider.cs index ed40f61f05..d57c472d91 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringAirdragDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringAirdragDataProvider.cs @@ -29,38 +29,39 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.Xml.XPath; -using TUGraz.IVT.VectoXML; -using TUGraz.VectoCommon.InputData; -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Resources; -using TUGraz.VectoCommon.Utils; - -namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering -{ - public class XMLEngineeringAirdragDataProvider : AbstractEngineeringXMLComponentDataProvider, - IAirdragEngineeringInputData - { - public XMLEngineeringAirdragDataProvider(XMLEngineeringInputDataProvider xmlEngineeringJobInputDataProvider, - XPathDocument axlegearDocument, string xmlBasePath, string fsBasePath) - : base(xmlEngineeringJobInputDataProvider, axlegearDocument, xmlBasePath, fsBasePath) {} - - public SquareMeter AirDragArea - { - get { return GetDoubleElementValue(XMLNames.Vehicle_AirDragArea).SI<SquareMeter>(); } - } - - public CrossWindCorrectionMode CrossWindCorrectionMode - { - get { return GetElementValue(XMLNames.Vehicle_CrossWindCorrectionMode).ParseEnum<CrossWindCorrectionMode>(); } - } - - public TableData CrosswindCorrectionMap - { - get { - return ReadTableData(AttributeMappings.CrossWindCorrectionMapping, - Helper.Query(XMLNames.Vehicle_CrosswindCorrectionData, XMLNames.Vehicle_CrosswindCorrectionData_Entry)); - } - } - } +using System.Xml; +using System.Xml.XPath; +using TUGraz.IVT.VectoXML; +using TUGraz.VectoCommon.InputData; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Resources; +using TUGraz.VectoCommon.Utils; + +namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering +{ + public class XMLEngineeringAirdragDataProvider : AbstractEngineeringXMLComponentDataProvider, + IAirdragEngineeringInputData + { + public XMLEngineeringAirdragDataProvider(XMLEngineeringInputDataProvider xmlEngineeringJobInputDataProvider, + XmlDocument axlegearDocument, string xmlBasePath, string fsBasePath) + : base(xmlEngineeringJobInputDataProvider, axlegearDocument, xmlBasePath, fsBasePath) {} + + public SquareMeter AirDragArea + { + get { return GetDoubleElementValue(XMLNames.Vehicle_AirDragArea).SI<SquareMeter>(); } + } + + public CrossWindCorrectionMode CrossWindCorrectionMode + { + get { return GetElementValue(XMLNames.Vehicle_CrossWindCorrectionMode).ParseEnum<CrossWindCorrectionMode>(); } + } + + public TableData CrosswindCorrectionMap + { + get { + return ReadTableData(AttributeMappings.CrossWindCorrectionMapping, + Helper.Query(XMLNames.Vehicle_CrosswindCorrectionData, XMLNames.Vehicle_CrosswindCorrectionData_Entry)); + } + } + } } \ No newline at end of file diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringAngledriveDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringAngledriveDataProvider.cs index cbc9d310ed..b1c575b1f5 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringAngledriveDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringAngledriveDataProvider.cs @@ -29,45 +29,45 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.Xml.XPath; -using TUGraz.IVT.VectoXML; -using TUGraz.VectoCommon.InputData; -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Resources; - -namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering -{ - public class XMLEngineeringAngledriveDataProvider : AbstractEngineeringXMLComponentDataProvider, IAngledriveInputData - { - public XMLEngineeringAngledriveDataProvider(XMLEngineeringInputDataProvider jobInputData, XPathDocument xmlDocument, - string xBasePath, string fsBasePath) : base(jobInputData, xmlDocument, xBasePath, fsBasePath) {} - - public AngledriveType Type - { - get { return InputData.VehicleData.AngledriveType; } - } - - public double Ratio - { - get { return GetDoubleElementValue(XMLNames.AngleDrive_Ratio); } - } - - public TableData LossMap - { - get { - if (ElementExists(Helper.Query(XMLNames.AngleDrive_TorqueLossMap, XMLNames.Angledrive_LossMap_Entry))) { - return ReadTableData(AttributeMappings.TransmissionLossmapMapping, - Helper.Query(XMLNames.AngleDrive_TorqueLossMap, XMLNames.Angledrive_LossMap_Entry)); - } - return ReadCSVResourceFile(XMLNames.AngleDrive_TorqueLossMap); - } - } - - public double Efficiency - { - get { - return GetDoubleElementValue(Helper.Query(XMLNames.AngleDrive_TorqueLossMap, XMLNames.AngleDrive_Efficiency)); - } - } - } +using System.Xml; +using TUGraz.IVT.VectoXML; +using TUGraz.VectoCommon.InputData; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Resources; + +namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering +{ + public class XMLEngineeringAngledriveDataProvider : AbstractEngineeringXMLComponentDataProvider, IAngledriveInputData + { + public XMLEngineeringAngledriveDataProvider(XMLEngineeringInputDataProvider jobInputData, XmlDocument xmlDocument, + string xBasePath, string fsBasePath) : base(jobInputData, xmlDocument, xBasePath, fsBasePath) {} + + public AngledriveType Type + { + get { return InputData.VehicleData.AngledriveType; } + } + + public double Ratio + { + get { return GetDoubleElementValue(XMLNames.AngleDrive_Ratio); } + } + + public TableData LossMap + { + get { + if (ElementExists(Helper.Query(XMLNames.AngleDrive_TorqueLossMap, XMLNames.Angledrive_LossMap_Entry))) { + return ReadTableData(AttributeMappings.TransmissionLossmapMapping, + Helper.Query(XMLNames.AngleDrive_TorqueLossMap, XMLNames.Angledrive_LossMap_Entry)); + } + return ReadCSVResourceFile(XMLNames.AngleDrive_TorqueLossMap); + } + } + + public double Efficiency + { + get { + return GetDoubleElementValue(Helper.Query(XMLNames.AngleDrive_TorqueLossMap, XMLNames.AngleDrive_Efficiency)); + } + } + } } \ No newline at end of file diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringAuxiliaryDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringAuxiliaryDataProvider.cs index 88d19a8bda..5ded5d655b 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringAuxiliaryDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringAuxiliaryDataProvider.cs @@ -29,110 +29,111 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Xml.XPath; -using TUGraz.IVT.VectoXML; -using TUGraz.VectoCommon.Exceptions; -using TUGraz.VectoCommon.InputData; -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Resources; -using TUGraz.VectoCommon.Utils; -using TUGraz.VectoCore.InputData.Impl; - -namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering -{ - public class XMLEngineeringAuxiliaryDataProvider : AbstractEngineeringXMLComponentDataProvider, - IAuxiliariesEngineeringInputData - { - public XMLEngineeringAuxiliaryDataProvider(XMLEngineeringInputDataProvider xmlEngineeringJobInputDataProvider, - XPathDocument auxDocument, string xmlBasePath, string fsBasePath) - : base(xmlEngineeringJobInputDataProvider, auxDocument, xmlBasePath, fsBasePath) {} - - - public IList<IAuxiliaryDeclarationInputData> Auxiliaries - { - get { return AuxiliaryInputData().Cast<IAuxiliaryDeclarationInputData>().ToList(); } - } - - IList<IAuxiliaryEngineeringInputData> IAuxiliariesEngineeringInputData.Auxiliaries - { - get { return AuxiliaryInputData().Cast<IAuxiliaryEngineeringInputData>().ToList(); } - } - - private IEnumerable<AuxiliaryDataInputData> AuxiliaryInputData() - { - var retVal = new List<AuxiliaryDataInputData>(); - var auxiliaries = Navigator.Select(Helper.Query(XBasePath, XMLNames.Auxiliaries_Auxiliary), Manager); - while (auxiliaries.MoveNext()) { - var constantAux = auxiliaries.Current.SelectSingleNode(Helper.Query(XMLNames.Auxiliaries_Auxiliary_ConstantAuxLoad), Manager); - if (constantAux == null) { - retVal.Add(CreateMappingAuxiliary(auxiliaries)); - } else { - retVal.Add(new AuxiliaryDataInputData() { - ID = "ConstantAux", - AuxiliaryType = AuxiliaryDemandType.Constant, - ConstantPowerDemand = constantAux.ValueAsDouble.SI<Watt>() - }); - } - } - return retVal; - } - - protected AuxiliaryDataInputData CreateMappingAuxiliary(XPathNodeIterator auxiliaries) - { - var auxData = new AuxiliaryDataInputData { - AuxiliaryType = AuxiliaryDemandType.Mapping, - ID = auxiliaries.Current.GetAttribute("id", ""), - }; - var node = - auxiliaries.Current.SelectSingleNode(ExtCsvResourceTag, Manager); - if (node != null) { - var auxFile = node.GetAttribute(XMLNames.ExtResource_File_Attr, ""); - - if (!File.Exists(Path.Combine(FSBasePath, auxFile))) { - throw new VectoException("Auxiliary resource file {0} not found! Aux: {1}", auxFile, auxData.ID); - } - AuxiliaryFileHelper.FillAuxiliaryDataInputData(auxData, Path.Combine(FSBasePath, auxFile)); - } else { - var transmissionRatio = - auxiliaries.Current.SelectSingleNode(Helper.Query(XMLNames.Auxiliaries_Auxiliary_TransmissionRatioToEngine), - Manager); - if (transmissionRatio != null) { - auxData.TransmissionRatio = transmissionRatio.ValueAsDouble; - } - var efficiencyEngine = - auxiliaries.Current.SelectSingleNode(Helper.Query(XMLNames.Auxiliaries_Auxiliary_EfficiencyToEngine), Manager); - if (efficiencyEngine != null) { - auxData.EfficiencyToEngine = efficiencyEngine.ValueAsDouble; - } - var efficiencyAuxSupply = - auxiliaries.Current.SelectSingleNode(Helper.Query(XMLNames.Auxiliaries_Auxiliary_EfficiencyAuxSupply), Manager); - if (efficiencyAuxSupply != null) { - auxData.EfficiencyToSupply = efficiencyAuxSupply.ValueAsDouble; - } - auxData.DemandMap = ReadTableData(AttributeMappings.AuxMapMapping, - Helper.Query(XMLNames.Auxiliaries_Auxiliary_AuxMap, XMLNames.Auxiliaries_Auxiliary_AuxMap_Entry), - auxiliaries.Current); - - } - return auxData; - } - - public AuxiliaryModel AuxiliaryAssembly - { - get { return AuxiliaryModel.Classic; } - } - - public string AuxiliaryVersion - { - get { return ""; } - } - - public string AdvancedAuxiliaryFilePath - { - get { return ""; } - } - } +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Xml; +using System.Xml.XPath; +using TUGraz.IVT.VectoXML; +using TUGraz.VectoCommon.Exceptions; +using TUGraz.VectoCommon.InputData; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Resources; +using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.InputData.Impl; + +namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering +{ + public class XMLEngineeringAuxiliaryDataProvider : AbstractEngineeringXMLComponentDataProvider, + IAuxiliariesEngineeringInputData + { + public XMLEngineeringAuxiliaryDataProvider(XMLEngineeringInputDataProvider xmlEngineeringJobInputDataProvider, + XmlDocument auxDocument, string xmlBasePath, string fsBasePath) + : base(xmlEngineeringJobInputDataProvider, auxDocument, xmlBasePath, fsBasePath) {} + + + public IList<IAuxiliaryDeclarationInputData> Auxiliaries + { + get { return AuxiliaryInputData().Cast<IAuxiliaryDeclarationInputData>().ToList(); } + } + + IList<IAuxiliaryEngineeringInputData> IAuxiliariesEngineeringInputData.Auxiliaries + { + get { return AuxiliaryInputData().Cast<IAuxiliaryEngineeringInputData>().ToList(); } + } + + private IEnumerable<AuxiliaryDataInputData> AuxiliaryInputData() + { + var retVal = new List<AuxiliaryDataInputData>(); + var auxiliaries = Navigator.Select(Helper.Query(XBasePath, XMLNames.Auxiliaries_Auxiliary), Manager); + while (auxiliaries.MoveNext()) { + var constantAux = auxiliaries.Current.SelectSingleNode(Helper.Query(XMLNames.Auxiliaries_Auxiliary_ConstantAuxLoad), Manager); + if (constantAux == null) { + retVal.Add(CreateMappingAuxiliary(auxiliaries)); + } else { + retVal.Add(new AuxiliaryDataInputData() { + ID = "ConstantAux", + AuxiliaryType = AuxiliaryDemandType.Constant, + ConstantPowerDemand = constantAux.ValueAsDouble.SI<Watt>() + }); + } + } + return retVal; + } + + protected AuxiliaryDataInputData CreateMappingAuxiliary(XPathNodeIterator auxiliaries) + { + var auxData = new AuxiliaryDataInputData { + AuxiliaryType = AuxiliaryDemandType.Mapping, + ID = auxiliaries.Current.GetAttribute("id", ""), + }; + var node = + auxiliaries.Current.SelectSingleNode(ExtCsvResourceTag, Manager); + if (node != null) { + var auxFile = node.GetAttribute(XMLNames.ExtResource_File_Attr, ""); + + if (!File.Exists(Path.Combine(FSBasePath, auxFile))) { + throw new VectoException("Auxiliary resource file {0} not found! Aux: {1}", auxFile, auxData.ID); + } + AuxiliaryFileHelper.FillAuxiliaryDataInputData(auxData, Path.Combine(FSBasePath, auxFile)); + } else { + var transmissionRatio = + auxiliaries.Current.SelectSingleNode(Helper.Query(XMLNames.Auxiliaries_Auxiliary_TransmissionRatioToEngine), + Manager); + if (transmissionRatio != null) { + auxData.TransmissionRatio = transmissionRatio.ValueAsDouble; + } + var efficiencyEngine = + auxiliaries.Current.SelectSingleNode(Helper.Query(XMLNames.Auxiliaries_Auxiliary_EfficiencyToEngine), Manager); + if (efficiencyEngine != null) { + auxData.EfficiencyToEngine = efficiencyEngine.ValueAsDouble; + } + var efficiencyAuxSupply = + auxiliaries.Current.SelectSingleNode(Helper.Query(XMLNames.Auxiliaries_Auxiliary_EfficiencyAuxSupply), Manager); + if (efficiencyAuxSupply != null) { + auxData.EfficiencyToSupply = efficiencyAuxSupply.ValueAsDouble; + } + auxData.DemandMap = ReadTableData(AttributeMappings.AuxMapMapping, + Helper.Query(XMLNames.Auxiliaries_Auxiliary_AuxMap, XMLNames.Auxiliaries_Auxiliary_AuxMap_Entry), + auxiliaries.Current); + + } + return auxData; + } + + public AuxiliaryModel AuxiliaryAssembly + { + get { return AuxiliaryModel.Classic; } + } + + public string AuxiliaryVersion + { + get { return ""; } + } + + public string AdvancedAuxiliaryFilePath + { + get { return ""; } + } + } } \ No newline at end of file diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringAxlegearDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringAxlegearDataProvider.cs index 83a15cc185..50bb256c65 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringAxlegearDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringAxlegearDataProvider.cs @@ -29,49 +29,49 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.Xml.XPath; -using TUGraz.IVT.VectoXML; -using TUGraz.VectoCommon.InputData; -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Resources; -using TUGraz.VectoCommon.Utils; - -namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering -{ - public class XMLEngineeringAxlegearDataProvider : AbstractEngineeringXMLComponentDataProvider, IAxleGearInputData - { - public XMLEngineeringAxlegearDataProvider(XMLEngineeringInputDataProvider xmlEngineeringJobInputDataProvider, - XPathDocument axlegearDocument, string xmlBasePath, string fsBasePath) - : base(xmlEngineeringJobInputDataProvider, axlegearDocument, xmlBasePath, fsBasePath) {} - - public double Ratio - { - get { return GetDoubleElementValue(XMLNames.Axlegear_Ratio); } - } - - public TableData LossMap - { - get { - if (ElementExists(Helper.Query(XMLNames.Axlegear_TorqueLossMap, XMLNames.Axlegear_TorqueLossMap_Entry))) { - return ReadTableData(AttributeMappings.TransmissionLossmapMapping, - Helper.Query(XMLNames.Axlegear_TorqueLossMap, XMLNames.Axlegear_TorqueLossMap_Entry)); - } - return ReadCSVResourceFile(XMLNames.Axlegear_TorqueLossMap); - } - } - - public double Efficiency - { - get { return GetDoubleElementValue(Helper.Query(XMLNames.Axlegear_TorqueLossMap, XMLNames.Axlegear_Efficiency)); } - } - - public AxleLineType LineType - { - get { - return ElementExists(XMLNames.Axlegear_LineType) - ? GetElementValue(XMLNames.Axlegear_LineType).ParseEnum<AxleLineType>() - : AxleLineType.SinglePortalAxle; - } - } - } +using System.Xml; +using TUGraz.IVT.VectoXML; +using TUGraz.VectoCommon.InputData; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Resources; +using TUGraz.VectoCommon.Utils; + +namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering +{ + public class XMLEngineeringAxlegearDataProvider : AbstractEngineeringXMLComponentDataProvider, IAxleGearInputData + { + public XMLEngineeringAxlegearDataProvider(XMLEngineeringInputDataProvider xmlEngineeringJobInputDataProvider, + XmlDocument axlegearDocument, string xmlBasePath, string fsBasePath) + : base(xmlEngineeringJobInputDataProvider, axlegearDocument, xmlBasePath, fsBasePath) {} + + public double Ratio + { + get { return GetDoubleElementValue(XMLNames.Axlegear_Ratio); } + } + + public TableData LossMap + { + get { + if (ElementExists(Helper.Query(XMLNames.Axlegear_TorqueLossMap, XMLNames.Axlegear_TorqueLossMap_Entry))) { + return ReadTableData(AttributeMappings.TransmissionLossmapMapping, + Helper.Query(XMLNames.Axlegear_TorqueLossMap, XMLNames.Axlegear_TorqueLossMap_Entry)); + } + return ReadCSVResourceFile(XMLNames.Axlegear_TorqueLossMap); + } + } + + public double Efficiency + { + get { return GetDoubleElementValue(Helper.Query(XMLNames.Axlegear_TorqueLossMap, XMLNames.Axlegear_Efficiency)); } + } + + public AxleLineType LineType + { + get { + return ElementExists(XMLNames.Axlegear_LineType) + ? GetElementValue(XMLNames.Axlegear_LineType).ParseEnum<AxleLineType>() + : AxleLineType.SinglePortalAxle; + } + } + } } \ No newline at end of file diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringDriverDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringDriverDataProvider.cs index bfa2fcfa30..cc87c768a7 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringDriverDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringDriverDataProvider.cs @@ -29,164 +29,164 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System; -using System.IO; -using System.Xml; -using System.Xml.XPath; -using TUGraz.IVT.VectoXML; -using TUGraz.VectoCommon.Exceptions; -using TUGraz.VectoCommon.InputData; -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Resources; -using TUGraz.VectoCommon.Utils; -using TUGraz.VectoCore.Configuration; -using TUGraz.VectoCore.InputData.Impl; -using TUGraz.VectoCore.Models.Declaration; -using TUGraz.VectoCore.Models.SimulationComponent.Data; -using TUGraz.VectoCore.Utils; - -namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering -{ - public class XMLEngineeringDriverDataProvider : AbstractEngineeringXMLComponentDataProvider, - IDriverEngineeringInputData - { - public XMLEngineeringDriverDataProvider(XMLEngineeringInputDataProvider xmlEngineeringJobInputDataProvider, - XPathDocument driverDocument, string xmlBasePath, string fsBasePath) - : base(xmlEngineeringJobInputDataProvider, driverDocument, xmlBasePath, fsBasePath) {} - - IOverSpeedEcoRollEngineeringInputData IDriverEngineeringInputData.OverSpeedEcoRoll - { - get { - var minSpeedPath = Helper.Query(XMLNames.Component_DriverModel, - XMLNames.DriverModel_Overspeed, XMLNames.DriverModel_Overspeed_MinSpeed); - var overSpeedPath = Helper.Query(XMLNames.Component_DriverModel, - XMLNames.DriverModel_Overspeed, XMLNames.DriverModel_Overspeed_AllowedOverspeed); - var underSpeedPath = Helper.Query(XMLNames.Component_DriverModel, - XMLNames.DriverModel_Overspeed, XMLNames.DriverModel_Overspeed_AllowedUnderspeed); - var retVal = new OverSpeedEcoRollInputData { - Mode = GetElementValue(Helper.Query(XMLNames.Component_DriverModel, - XMLNames.DriverModel_Overspeed, XMLNames.DriverModel_Overspeed_Mode)).ParseEnum<DriverMode>(), - MinSpeed = ElementExists(minSpeedPath) - ? GetDoubleElementValue(minSpeedPath).KMPHtoMeterPerSecond() - : DeclarationData.Driver.OverSpeedEcoRoll.MinSpeed, - OverSpeed = ElementExists(overSpeedPath) - ? GetDoubleElementValue(overSpeedPath).KMPHtoMeterPerSecond() - : DeclarationData.Driver.OverSpeedEcoRoll.OverSpeed, - UnderSpeed = ElementExists(underSpeedPath) - ? GetDoubleElementValue(underSpeedPath).KMPHtoMeterPerSecond() - : DeclarationData.Driver.OverSpeedEcoRoll.UnderSpeed - }; - - return retVal; - } - } - - public TableData AccelerationCurve - { - get { - if (ElementExists(Helper.Query(XMLNames.Component_DriverModel, XMLNames.DriverModel_DriverAccelerationCurve))) { - return - ReadTableData(AttributeMappings.DriverAccelerationCurveMapping, - Helper.Query(XMLNames.Component_DriverModel, XMLNames.DriverModel_DriverAccelerationCurve, - XMLNames.DriverModel_DriverAccelerationCurve_Entry)); - } - //Log.Warn("Could not find file for acceleration curve. Trying lookup in declaration data."); - try { - var resourceName = DeclarationData.DeclarationDataResourcePrefix + ".VACC.Truck" + - Constants.FileExtensions.DriverAccelerationCurve; - return VectoCSVFile.ReadStream(RessourceHelper.ReadStream(resourceName), source: resourceName); - } catch (Exception e) { - throw new VectoException("Failed to read Driver Acceleration Curve: " + e.Message, e); - } - } - } - - public ILookaheadCoastingInputData Lookahead - { - get { - var lookAheadXmlPath = Helper.Query(XMLNames.Component_DriverModel, XMLNames.DriverModel_LookAheadCoasting); - - var retVal = new LookAheadCoastingInputData { - Enabled = - XmlConvert.ToBoolean( - GetElementValue(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_Enabled))), - LookaheadDistanceFactor = - ElementExists(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_PreviewDistanceFactor)) - ? GetDoubleElementValue(Helper.Query(lookAheadXmlPath, - XMLNames.DriverModel_LookAheadCoasting_PreviewDistanceFactor)) - : DeclarationData.Driver.LookAhead.LookAheadDistanceFactor, - CoastingDecisionFactorOffset = - ElementExists(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_DecisionFactorOffset)) - ? GetDoubleElementValue(Helper.Query(lookAheadXmlPath, - XMLNames.DriverModel_LookAheadCoasting_DecisionFactorOffset)) - : DeclarationData.Driver.LookAhead.DecisionFactorCoastingOffset, - CoastingDecisionFactorScaling = - ElementExists(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_DecisionFactorScaling)) - ? GetDoubleElementValue(Helper.Query(lookAheadXmlPath, - XMLNames.DriverModel_LookAheadCoasting_DecisionFactorScaling)) - : DeclarationData.Driver.LookAhead.DecisionFactorCoastingScaling, - MinSpeed = ElementExists(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_MinSpeed)) - ? GetDoubleElementValue(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_MinSpeed)) - .KMPHtoMeterPerSecond() - : DeclarationData.Driver.LookAhead.MinimumSpeed - }; - - if ( - ElementExists(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_SpeedDependentDecisionFactor, - XMLNames.LookAheadCoasting_SpeedDependentDecisionFactor_Entry))) { - retVal.CoastingDecisionFactorTargetSpeedLookup = ReadTableData( - AttributeMappings.CoastingDFTargetSpeedLookupMapping, - Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_SpeedDependentDecisionFactor, - XMLNames.LookAheadCoasting_SpeedDependentDecisionFactor_Entry)); - } else if ( - ElementExists(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_SpeedDependentDecisionFactor, - XMLNames.ExternalResource))) { - var node = Navigator.SelectSingleNode(Helper.Query(XBasePath, lookAheadXmlPath, - XMLNames.DriverModel_LookAheadCoasting_SpeedDependentDecisionFactor, XMLNames.ExternalResource), Manager); - if (node != null && - XMLNames.ExtResource_Type_Value_CSV.Equals(node.GetAttribute(XMLNames.ExtResource_Type_Attr, ""))) { - retVal.CoastingDecisionFactorTargetSpeedLookup = - VectoCSVFile.Read(Path.Combine(FSBasePath, node.GetAttribute(XMLNames.ExtResource_File_Attr, ""))); - } - } else { - retVal.CoastingDecisionFactorTargetSpeedLookup = null; - } - - if ( - ElementExists(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_VelocityDropDecisionFactor, - XMLNames.LookAheadCoasting_VelocityDropDecisionFactor_Entry))) { - retVal.CoastingDecisionFactorVelocityDropLookup = - ReadTableData(AttributeMappings.CoastingDFVelocityDropLookupMapping, - Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_VelocityDropDecisionFactor, - XMLNames.LookAheadCoasting_VelocityDropDecisionFactor_Entry)); - } else if ( - ElementExists(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_VelocityDropDecisionFactor, - XMLNames.ExternalResource))) { - var node = - Navigator.SelectSingleNode(Helper.Query(XBasePath, lookAheadXmlPath, - XMLNames.DriverModel_LookAheadCoasting_VelocityDropDecisionFactor, XMLNames.ExternalResource), Manager); - if (node != null && - XMLNames.ExtResource_Type_Value_CSV.Equals(node.GetAttribute(XMLNames.ExtResource_Type_Attr, ""))) { - retVal.CoastingDecisionFactorVelocityDropLookup = - VectoCSVFile.Read(Path.Combine(FSBasePath, node.GetAttribute(XMLNames.ExtResource_File_Attr, ""))); - } - } else { - retVal.CoastingDecisionFactorVelocityDropLookup = null; - } - return retVal; - } - } - - public IOverSpeedEcoRollDeclarationInputData OverSpeedEcoRoll - { - get { - var node = - Navigator.SelectSingleNode(Helper.Query(XBasePath, XMLNames.Component_DriverModel, XMLNames.DriverModel_Overspeed, - XMLNames.DriverModel_Overspeed_Mode), Manager); - return new OverSpeedEcoRollInputData() { - Mode = node != null ? DriverData.ParseDriverMode(node.Value) : DriverMode.Off - }; - } - } - } +using System; +using System.IO; +using System.Xml; +using System.Xml.XPath; +using TUGraz.IVT.VectoXML; +using TUGraz.VectoCommon.Exceptions; +using TUGraz.VectoCommon.InputData; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Resources; +using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Configuration; +using TUGraz.VectoCore.InputData.Impl; +using TUGraz.VectoCore.Models.Declaration; +using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering +{ + public class XMLEngineeringDriverDataProvider : AbstractEngineeringXMLComponentDataProvider, + IDriverEngineeringInputData + { + public XMLEngineeringDriverDataProvider(XMLEngineeringInputDataProvider xmlEngineeringJobInputDataProvider, + XmlDocument driverDocument, string xmlBasePath, string fsBasePath) + : base(xmlEngineeringJobInputDataProvider, driverDocument, xmlBasePath, fsBasePath) {} + + IOverSpeedEcoRollEngineeringInputData IDriverEngineeringInputData.OverSpeedEcoRoll + { + get { + var minSpeedPath = Helper.Query(XMLNames.Component_DriverModel, + XMLNames.DriverModel_Overspeed, XMLNames.DriverModel_Overspeed_MinSpeed); + var overSpeedPath = Helper.Query(XMLNames.Component_DriverModel, + XMLNames.DriverModel_Overspeed, XMLNames.DriverModel_Overspeed_AllowedOverspeed); + var underSpeedPath = Helper.Query(XMLNames.Component_DriverModel, + XMLNames.DriverModel_Overspeed, XMLNames.DriverModel_Overspeed_AllowedUnderspeed); + var retVal = new OverSpeedEcoRollInputData { + Mode = GetElementValue(Helper.Query(XMLNames.Component_DriverModel, + XMLNames.DriverModel_Overspeed, XMLNames.DriverModel_Overspeed_Mode)).ParseEnum<DriverMode>(), + MinSpeed = ElementExists(minSpeedPath) + ? GetDoubleElementValue(minSpeedPath).KMPHtoMeterPerSecond() + : DeclarationData.Driver.OverSpeedEcoRoll.MinSpeed, + OverSpeed = ElementExists(overSpeedPath) + ? GetDoubleElementValue(overSpeedPath).KMPHtoMeterPerSecond() + : DeclarationData.Driver.OverSpeedEcoRoll.OverSpeed, + UnderSpeed = ElementExists(underSpeedPath) + ? GetDoubleElementValue(underSpeedPath).KMPHtoMeterPerSecond() + : DeclarationData.Driver.OverSpeedEcoRoll.UnderSpeed + }; + + return retVal; + } + } + + public TableData AccelerationCurve + { + get { + if (ElementExists(Helper.Query(XMLNames.Component_DriverModel, XMLNames.DriverModel_DriverAccelerationCurve))) { + return + ReadTableData(AttributeMappings.DriverAccelerationCurveMapping, + Helper.Query(XMLNames.Component_DriverModel, XMLNames.DriverModel_DriverAccelerationCurve, + XMLNames.DriverModel_DriverAccelerationCurve_Entry)); + } + //Log.Warn("Could not find file for acceleration curve. Trying lookup in declaration data."); + try { + var resourceName = DeclarationData.DeclarationDataResourcePrefix + ".VACC.Truck" + + Constants.FileExtensions.DriverAccelerationCurve; + return VectoCSVFile.ReadStream(RessourceHelper.ReadStream(resourceName), source: resourceName); + } catch (Exception e) { + throw new VectoException("Failed to read Driver Acceleration Curve: " + e.Message, e); + } + } + } + + public ILookaheadCoastingInputData Lookahead + { + get { + var lookAheadXmlPath = Helper.Query(XMLNames.Component_DriverModel, XMLNames.DriverModel_LookAheadCoasting); + + var retVal = new LookAheadCoastingInputData { + Enabled = + XmlConvert.ToBoolean( + GetElementValue(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_Enabled))), + LookaheadDistanceFactor = + ElementExists(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_PreviewDistanceFactor)) + ? GetDoubleElementValue(Helper.Query(lookAheadXmlPath, + XMLNames.DriverModel_LookAheadCoasting_PreviewDistanceFactor)) + : DeclarationData.Driver.LookAhead.LookAheadDistanceFactor, + CoastingDecisionFactorOffset = + ElementExists(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_DecisionFactorOffset)) + ? GetDoubleElementValue(Helper.Query(lookAheadXmlPath, + XMLNames.DriverModel_LookAheadCoasting_DecisionFactorOffset)) + : DeclarationData.Driver.LookAhead.DecisionFactorCoastingOffset, + CoastingDecisionFactorScaling = + ElementExists(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_DecisionFactorScaling)) + ? GetDoubleElementValue(Helper.Query(lookAheadXmlPath, + XMLNames.DriverModel_LookAheadCoasting_DecisionFactorScaling)) + : DeclarationData.Driver.LookAhead.DecisionFactorCoastingScaling, + MinSpeed = ElementExists(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_MinSpeed)) + ? GetDoubleElementValue(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_MinSpeed)) + .KMPHtoMeterPerSecond() + : DeclarationData.Driver.LookAhead.MinimumSpeed + }; + + if ( + ElementExists(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_SpeedDependentDecisionFactor, + XMLNames.LookAheadCoasting_SpeedDependentDecisionFactor_Entry))) { + retVal.CoastingDecisionFactorTargetSpeedLookup = ReadTableData( + AttributeMappings.CoastingDFTargetSpeedLookupMapping, + Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_SpeedDependentDecisionFactor, + XMLNames.LookAheadCoasting_SpeedDependentDecisionFactor_Entry)); + } else if ( + ElementExists(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_SpeedDependentDecisionFactor, + XMLNames.ExternalResource))) { + var node = Navigator.SelectSingleNode(Helper.Query(XBasePath, lookAheadXmlPath, + XMLNames.DriverModel_LookAheadCoasting_SpeedDependentDecisionFactor, XMLNames.ExternalResource), Manager); + if (node != null && + XMLNames.ExtResource_Type_Value_CSV.Equals(node.GetAttribute(XMLNames.ExtResource_Type_Attr, ""))) { + retVal.CoastingDecisionFactorTargetSpeedLookup = + VectoCSVFile.Read(Path.Combine(FSBasePath, node.GetAttribute(XMLNames.ExtResource_File_Attr, ""))); + } + } else { + retVal.CoastingDecisionFactorTargetSpeedLookup = null; + } + + if ( + ElementExists(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_VelocityDropDecisionFactor, + XMLNames.LookAheadCoasting_VelocityDropDecisionFactor_Entry))) { + retVal.CoastingDecisionFactorVelocityDropLookup = + ReadTableData(AttributeMappings.CoastingDFVelocityDropLookupMapping, + Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_VelocityDropDecisionFactor, + XMLNames.LookAheadCoasting_VelocityDropDecisionFactor_Entry)); + } else if ( + ElementExists(Helper.Query(lookAheadXmlPath, XMLNames.DriverModel_LookAheadCoasting_VelocityDropDecisionFactor, + XMLNames.ExternalResource))) { + var node = + Navigator.SelectSingleNode(Helper.Query(XBasePath, lookAheadXmlPath, + XMLNames.DriverModel_LookAheadCoasting_VelocityDropDecisionFactor, XMLNames.ExternalResource), Manager); + if (node != null && + XMLNames.ExtResource_Type_Value_CSV.Equals(node.GetAttribute(XMLNames.ExtResource_Type_Attr, ""))) { + retVal.CoastingDecisionFactorVelocityDropLookup = + VectoCSVFile.Read(Path.Combine(FSBasePath, node.GetAttribute(XMLNames.ExtResource_File_Attr, ""))); + } + } else { + retVal.CoastingDecisionFactorVelocityDropLookup = null; + } + return retVal; + } + } + + public IOverSpeedEcoRollDeclarationInputData OverSpeedEcoRoll + { + get { + var node = + Navigator.SelectSingleNode(Helper.Query(XBasePath, XMLNames.Component_DriverModel, XMLNames.DriverModel_Overspeed, + XMLNames.DriverModel_Overspeed_Mode), Manager); + return new OverSpeedEcoRollInputData() { + Mode = node != null ? DriverData.ParseDriverMode(node.Value) : DriverMode.Off + }; + } + } + } } \ No newline at end of file diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringEngineDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringEngineDataProvider.cs index e8787885ee..fce8b36454 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringEngineDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringEngineDataProvider.cs @@ -29,122 +29,122 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.Xml.XPath; -using TUGraz.IVT.VectoXML; -using TUGraz.VectoCommon.Exceptions; -using TUGraz.VectoCommon.InputData; -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Resources; -using TUGraz.VectoCommon.Utils; - -namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering -{ - public class XMLEngineeringEngineDataProvider : AbstractEngineeringXMLComponentDataProvider, - IEngineEngineeringInputData - { - public XMLEngineeringEngineDataProvider(XMLEngineeringInputDataProvider xmlEngineeringJobInputDataProvider, - XPathDocument engineDocument, string xmlBasePath, string fsBasePath) - : base(xmlEngineeringJobInputDataProvider, engineDocument, xmlBasePath, fsBasePath) {} - +using System.Xml; +using TUGraz.IVT.VectoXML; +using TUGraz.VectoCommon.Exceptions; +using TUGraz.VectoCommon.InputData; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Resources; +using TUGraz.VectoCommon.Utils; + +namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering +{ + public class XMLEngineeringEngineDataProvider : AbstractEngineeringXMLComponentDataProvider, + IEngineEngineeringInputData + { + public XMLEngineeringEngineDataProvider(XMLEngineeringInputDataProvider xmlEngineeringJobInputDataProvider, + XmlDocument engineDocument, string xmlBasePath, string fsBasePath) + : base(xmlEngineeringJobInputDataProvider, engineDocument, xmlBasePath, fsBasePath) {} + public CubicMeter Displacement { get { return GetDoubleElementValue(XMLNames.Engine_Displacement).SI(Unit.SI.Cubic.Centi.Meter).Cast<CubicMeter>(); } - } - - public PerSecond IdleSpeed - { - get { return GetDoubleElementValue(XMLNames.Engine_IdlingSpeed).RPMtoRad(); } - } - - public double WHTCEngineering - { - get { return GetDoubleElementValue(XMLNames.Engine_WHTCEngineering); } - } - - public double WHTCMotorway - { - get { throw new VectoException("Property not available in Engineering Mode"); } - } - - public double WHTCRural - { - get { throw new VectoException("Property not available in Engineering Mode"); } - } - - public double WHTCUrban - { - get { throw new VectoException("Property not available in Engineering Mode"); } - } - - public double ColdHotBalancingFactor - { - get { throw new VectoException("Property not available in Engineering Mode"); } - } - - public double CorrectionFactorRegPer - { - get { - return 1; - //GetDoubleElementValue(XMLNames.Engine_CorrectionFactor_RegPer); - } - } - - public double CorrectionFactorNCV - { - get { return 1; //GetDoubleElementValue(XMLNames.Engine_CorrecionFactor_NCV); - } - } - - public FuelType FuelType - { - get { return FuelType.DieselCI; //GetElementValue(XMLNames.Engine_FuelType).ParseEnum<FuelType>(); - } - } - - public TableData FuelConsumptionMap - { - get { - if (!ElementExists(Helper.Query(XMLNames.Engine_FuelConsumptionMap, XMLNames.Engine_FuelConsumptionMap_Entry))) { - return ReadCSVResourceFile(XMLNames.Engine_FuelConsumptionMap); - } - return ReadTableData(AttributeMappings.FuelConsumptionMapMapping, - Helper.Query(XMLNames.Engine_FuelConsumptionMap, XMLNames.Engine_FuelConsumptionMap_Entry)); - } - } - - public TableData FullLoadCurve - { - get { - if (!ElementExists(Helper.Query(XMLNames.Engine_FullLoadAndDragCurve, XMLNames.Engine_FuelConsumptionMap_Entry))) { - return ReadCSVResourceFile(XMLNames.Engine_FullLoadAndDragCurve); - } - - return ReadTableData(AttributeMappings.EngineFullLoadCurveMapping, - Helper.Query(XMLNames.Engine_FullLoadAndDragCurve, XMLNames.Engine_FuelConsumptionMap_Entry)); - } - } - - public Watt RatedPowerDeclared - { - get { return null; //GetDoubleElementValue(XMLNames.Engine_RatedPower).SI<Watt>(); - } - } - - public PerSecond RatedSpeedDeclared - { - get { return null; //GetDoubleElementValue(XMLNames.Engine_RatedSpeed).RPMtoRad(); - } - } - - public NewtonMeter MaxTorqueDeclared - { - get { return null; //GetDoubleElementValue(XMLNames.Engine_MaxTorque).SI<NewtonMeter>(); - } - } - - public KilogramSquareMeter Inertia - { - get { return GetDoubleElementValue(XMLNames.Engine_Inertia).SI<KilogramSquareMeter>(); } - } - } + } + + public PerSecond IdleSpeed + { + get { return GetDoubleElementValue(XMLNames.Engine_IdlingSpeed).RPMtoRad(); } + } + + public double WHTCEngineering + { + get { return GetDoubleElementValue(XMLNames.Engine_WHTCEngineering); } + } + + public double WHTCMotorway + { + get { throw new VectoException("Property not available in Engineering Mode"); } + } + + public double WHTCRural + { + get { throw new VectoException("Property not available in Engineering Mode"); } + } + + public double WHTCUrban + { + get { throw new VectoException("Property not available in Engineering Mode"); } + } + + public double ColdHotBalancingFactor + { + get { throw new VectoException("Property not available in Engineering Mode"); } + } + + public double CorrectionFactorRegPer + { + get { + return 1; + //GetDoubleElementValue(XMLNames.Engine_CorrectionFactor_RegPer); + } + } + + public double CorrectionFactorNCV + { + get { return 1; //GetDoubleElementValue(XMLNames.Engine_CorrecionFactor_NCV); + } + } + + public FuelType FuelType + { + get { return FuelType.DieselCI; //GetElementValue(XMLNames.Engine_FuelType).ParseEnum<FuelType>(); + } + } + + public TableData FuelConsumptionMap + { + get { + if (!ElementExists(Helper.Query(XMLNames.Engine_FuelConsumptionMap, XMLNames.Engine_FuelConsumptionMap_Entry))) { + return ReadCSVResourceFile(XMLNames.Engine_FuelConsumptionMap); + } + return ReadTableData(AttributeMappings.FuelConsumptionMapMapping, + Helper.Query(XMLNames.Engine_FuelConsumptionMap, XMLNames.Engine_FuelConsumptionMap_Entry)); + } + } + + public TableData FullLoadCurve + { + get { + if (!ElementExists(Helper.Query(XMLNames.Engine_FullLoadAndDragCurve, XMLNames.Engine_FuelConsumptionMap_Entry))) { + return ReadCSVResourceFile(XMLNames.Engine_FullLoadAndDragCurve); + } + + return ReadTableData(AttributeMappings.EngineFullLoadCurveMapping, + Helper.Query(XMLNames.Engine_FullLoadAndDragCurve, XMLNames.Engine_FuelConsumptionMap_Entry)); + } + } + + public Watt RatedPowerDeclared + { + get { return null; //GetDoubleElementValue(XMLNames.Engine_RatedPower).SI<Watt>(); + } + } + + public PerSecond RatedSpeedDeclared + { + get { return null; //GetDoubleElementValue(XMLNames.Engine_RatedSpeed).RPMtoRad(); + } + } + + public NewtonMeter MaxTorqueDeclared + { + get { return null; //GetDoubleElementValue(XMLNames.Engine_MaxTorque).SI<NewtonMeter>(); + } + } + + public KilogramSquareMeter Inertia + { + get { return GetDoubleElementValue(XMLNames.Engine_Inertia).SI<KilogramSquareMeter>(); } + } + } } \ No newline at end of file diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringGearboxDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringGearboxDataProvider.cs index 3440ad834b..b88a700357 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringGearboxDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringGearboxDataProvider.cs @@ -29,146 +29,146 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.Collections.Generic; -using System.Xml; -using System.Xml.XPath; -using TUGraz.IVT.VectoXML; -using TUGraz.VectoCommon.InputData; -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Resources; -using TUGraz.VectoCommon.Utils; -using TUGraz.VectoCore.InputData.Impl; - -namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering -{ - public class XMLEngineeringGearboxDataProvider : AbstractEngineeringXMLComponentDataProvider, - IGearboxEngineeringInputData - { - public XMLEngineeringGearboxDataProvider(XMLEngineeringInputDataProvider xmlEngineeringJobInputDataProvider, - XPathDocument gbxDocument, string xmlBasePath, string fsBasePath) - : base(xmlEngineeringJobInputDataProvider, gbxDocument, xmlBasePath, fsBasePath) {} - - public GearboxType Type - { - get { return GetElementValue(XMLNames.Gearbox_TransmissionType).ParseEnum<GearboxType>(); } - } - - - public KilogramSquareMeter Inertia - { - get { return GetDoubleElementValue(XMLNames.Gearbox_Inertia).SI<KilogramSquareMeter>(); } - } - - public Second TractionInterruption - { - get { return GetDoubleElementValue(XMLNames.Gearbox_TractionInterruption).SI<Second>(); } - } - - public IList<ITransmissionInputData> Gears - { - get - { - var retVal = new List<ITransmissionInputData>(); - var gears = Navigator.Select(Helper.Query(XBasePath, XMLNames.Gearbox_Gears, XMLNames.Gearbox_Gears_Gear), Manager); - while (gears.MoveNext()) { - var gear = gears.Current.GetAttribute(XMLNames.Gearbox_Gear_GearNumber_Attr, ""); - retVal.Add(ReadGear(gear)); - } - return retVal; - } - } - - protected ITransmissionInputData ReadGear(string gearNr) - { - var retVal = new TransmissionInputData(); - var gearPath = Helper.Query(XMLNames.Gearbox_Gears, - Helper.QueryConstraint(XMLNames.Gearbox_Gears_Gear, XMLNames.Gearbox_Gear_GearNumber_Attr, gearNr)); - retVal.Ratio = GetDoubleElementValue(Helper.Query(gearPath, XMLNames.Gearbox_Gear_Ratio)); - retVal.Gear = XmlConvert.ToUInt16(gearNr); - if ( - ElementExists(Helper.Query(gearPath, XMLNames.Gearbox_Gear_TorqueLossMap, XMLNames.Gearbox_Gear_TorqueLossMap_Entry))) { - retVal.LossMap = ReadTableData(AttributeMappings.TransmissionLossmapMapping, - Helper.Query(gearPath, XMLNames.Gearbox_Gear_TorqueLossMap, XMLNames.Gearbox_Gear_TorqueLossMap_Entry)); - } else { - retVal.LossMap = ReadCSVResourceFile(Helper.Query(gearPath, XMLNames.Gearbox_Gear_TorqueLossMap)); - } - - if ( - ElementExists(Helper.Query(gearPath, XMLNames.Gearbox_Gears_Gear_ShiftPolygon, - XMLNames.Gearbox_Gears_Gear_ShiftPolygon_Entry))) { - retVal.ShiftPolygon = ReadTableData(AttributeMappings.ShiftPolygonMapping, - Helper.Query(gearPath, XMLNames.Gearbox_Gears_Gear_ShiftPolygon, XMLNames.Gearbox_Gears_Gear_ShiftPolygon_Entry)); - } - if ( - ElementExists(Helper.Query(gearPath, XMLNames.Gearbox_Gears_Gear_ShiftPolygon, ExtCsvResourceTag))) { - retVal.ShiftPolygon = ReadCSVResourceFile(Helper.Query(gearPath, XMLNames.Gearbox_Gears_Gear_ShiftPolygon)); - } - - retVal.MaxTorque = ElementExists(Helper.Query(gearPath, XMLNames.Gearbox_Gears_MaxTorque)) - ? GetDoubleElementValue(Helper.Query(gearPath, XMLNames.Gearbox_Gears_MaxTorque)).SI<NewtonMeter>() - : null; - return retVal; - } - - public Second MinTimeBetweenGearshift - { - get { return InputData.XMLEngineeringJobData.MinTimeBetweenGearshift; } - } - - public double TorqueReserve - { - get { return InputData.XMLEngineeringJobData.TorqueReserve; } - } - - public MeterPerSecond StartSpeed - { - get { return InputData.XMLEngineeringJobData.StartSpeed; } - } - - public MeterPerSquareSecond StartAcceleration - { - get { return InputData.XMLEngineeringJobData.StartAcceleration; } - } - - public double StartTorqueReserve - { - get { return InputData.XMLEngineeringJobData.StartTorqueReserve; } - } - - - ITorqueConverterDeclarationInputData IGearboxDeclarationInputData.TorqueConverter - { - get { return TorqueConverter; } - } - - public ITorqueConverterEngineeringInputData TorqueConverter - { - get - { - return new XMLEngineeringTorqueConverterDataProvider(InputData, XMLDocument, - Helper.Query(XBasePath, "parent::*", XMLNames.Component_TorqueConverter, XMLNames.ComponentDataWrapper), FSBasePath); - } - } - - public Second DownshiftAfterUpshiftDelay - { - get { return InputData.XMLEngineeringJobData.DownshiftAfterUpshiftDelay; } - } - - public Second UpshiftAfterDownshiftDelay - { - get { return InputData.XMLEngineeringJobData.UpshiftAfterDownshiftDelay; } - } - - public MeterPerSquareSecond UpshiftMinAcceleration - { - get { return InputData.XMLEngineeringJobData.UpshiftMinAcceleration; } - } - - public Second PowershiftShiftTime - { - get { return InputData.XMLEngineeringJobData.PowershiftShiftTime; } - } - - } +using System.Collections.Generic; +using System.Xml; +using System.Xml.XPath; +using TUGraz.IVT.VectoXML; +using TUGraz.VectoCommon.InputData; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Resources; +using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.InputData.Impl; + +namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering +{ + public class XMLEngineeringGearboxDataProvider : AbstractEngineeringXMLComponentDataProvider, + IGearboxEngineeringInputData + { + public XMLEngineeringGearboxDataProvider(XMLEngineeringInputDataProvider xmlEngineeringJobInputDataProvider, + XmlDocument gbxDocument, string xmlBasePath, string fsBasePath) + : base(xmlEngineeringJobInputDataProvider, gbxDocument, xmlBasePath, fsBasePath) {} + + public GearboxType Type + { + get { return GetElementValue(XMLNames.Gearbox_TransmissionType).ParseEnum<GearboxType>(); } + } + + + public KilogramSquareMeter Inertia + { + get { return GetDoubleElementValue(XMLNames.Gearbox_Inertia).SI<KilogramSquareMeter>(); } + } + + public Second TractionInterruption + { + get { return GetDoubleElementValue(XMLNames.Gearbox_TractionInterruption).SI<Second>(); } + } + + public IList<ITransmissionInputData> Gears + { + get + { + var retVal = new List<ITransmissionInputData>(); + var gears = Navigator.Select(Helper.Query(XBasePath, XMLNames.Gearbox_Gears, XMLNames.Gearbox_Gears_Gear), Manager); + while (gears.MoveNext()) { + var gear = gears.Current.GetAttribute(XMLNames.Gearbox_Gear_GearNumber_Attr, ""); + retVal.Add(ReadGear(gear)); + } + return retVal; + } + } + + protected ITransmissionInputData ReadGear(string gearNr) + { + var retVal = new TransmissionInputData(); + var gearPath = Helper.Query(XMLNames.Gearbox_Gears, + Helper.QueryConstraint(XMLNames.Gearbox_Gears_Gear, XMLNames.Gearbox_Gear_GearNumber_Attr, gearNr)); + retVal.Ratio = GetDoubleElementValue(Helper.Query(gearPath, XMLNames.Gearbox_Gear_Ratio)); + retVal.Gear = XmlConvert.ToUInt16(gearNr); + if ( + ElementExists(Helper.Query(gearPath, XMLNames.Gearbox_Gear_TorqueLossMap, XMLNames.Gearbox_Gear_TorqueLossMap_Entry))) { + retVal.LossMap = ReadTableData(AttributeMappings.TransmissionLossmapMapping, + Helper.Query(gearPath, XMLNames.Gearbox_Gear_TorqueLossMap, XMLNames.Gearbox_Gear_TorqueLossMap_Entry)); + } else { + retVal.LossMap = ReadCSVResourceFile(Helper.Query(gearPath, XMLNames.Gearbox_Gear_TorqueLossMap)); + } + + if ( + ElementExists(Helper.Query(gearPath, XMLNames.Gearbox_Gears_Gear_ShiftPolygon, + XMLNames.Gearbox_Gears_Gear_ShiftPolygon_Entry))) { + retVal.ShiftPolygon = ReadTableData(AttributeMappings.ShiftPolygonMapping, + Helper.Query(gearPath, XMLNames.Gearbox_Gears_Gear_ShiftPolygon, XMLNames.Gearbox_Gears_Gear_ShiftPolygon_Entry)); + } + if ( + ElementExists(Helper.Query(gearPath, XMLNames.Gearbox_Gears_Gear_ShiftPolygon, ExtCsvResourceTag))) { + retVal.ShiftPolygon = ReadCSVResourceFile(Helper.Query(gearPath, XMLNames.Gearbox_Gears_Gear_ShiftPolygon)); + } + + retVal.MaxTorque = ElementExists(Helper.Query(gearPath, XMLNames.Gearbox_Gears_MaxTorque)) + ? GetDoubleElementValue(Helper.Query(gearPath, XMLNames.Gearbox_Gears_MaxTorque)).SI<NewtonMeter>() + : null; + return retVal; + } + + public Second MinTimeBetweenGearshift + { + get { return InputData.XMLEngineeringJobData.MinTimeBetweenGearshift; } + } + + public double TorqueReserve + { + get { return InputData.XMLEngineeringJobData.TorqueReserve; } + } + + public MeterPerSecond StartSpeed + { + get { return InputData.XMLEngineeringJobData.StartSpeed; } + } + + public MeterPerSquareSecond StartAcceleration + { + get { return InputData.XMLEngineeringJobData.StartAcceleration; } + } + + public double StartTorqueReserve + { + get { return InputData.XMLEngineeringJobData.StartTorqueReserve; } + } + + + ITorqueConverterDeclarationInputData IGearboxDeclarationInputData.TorqueConverter + { + get { return TorqueConverter; } + } + + public ITorqueConverterEngineeringInputData TorqueConverter + { + get + { + return new XMLEngineeringTorqueConverterDataProvider(InputData, XMLDocument, + Helper.Query(XBasePath, "parent::*", XMLNames.Component_TorqueConverter, XMLNames.ComponentDataWrapper), FSBasePath); + } + } + + public Second DownshiftAfterUpshiftDelay + { + get { return InputData.XMLEngineeringJobData.DownshiftAfterUpshiftDelay; } + } + + public Second UpshiftAfterDownshiftDelay + { + get { return InputData.XMLEngineeringJobData.UpshiftAfterDownshiftDelay; } + } + + public MeterPerSquareSecond UpshiftMinAcceleration + { + get { return InputData.XMLEngineeringJobData.UpshiftMinAcceleration; } + } + + public Second PowershiftShiftTime + { + get { return InputData.XMLEngineeringJobData.PowershiftShiftTime; } + } + + } } \ No newline at end of file diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringInputDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringInputDataProvider.cs index e7083336b7..ba7ed582a4 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringInputDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringInputDataProvider.cs @@ -46,28 +46,30 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering { public readonly string FileName; - internal XPathDocument Document; + internal XmlDocument Document; protected internal XMLEngineeringJobInputDataProvider XMLEngineeringJobData; protected internal XMLEngineeringVehicleDataProvider VehicleData; protected internal XMLEngineeringDriverDataProvider XMLEngineeringDriverData; - public XmlReaderSettings Settings { get; private set; } + public bool VerifyXml { get; protected set; } public XMLEngineeringInputDataProvider(string filename, bool verifyXml) { + VerifyXml = verifyXml; FileName = filename; - ReadXMLDocument(File.OpenRead(filename), verifyXml); + ReadXMLDocument(File.OpenRead(filename)); - InitializeComponentDataProvider(verifyXml); + InitializeComponentDataProvider(); } public XMLEngineeringInputDataProvider(Stream inputData, bool verifyXml) { FileName = "."; - ReadXMLDocument(inputData, verifyXml); + VerifyXml = verifyXml; + ReadXMLDocument(inputData); var nav = Document.CreateNavigator(); var manager = new XmlNamespaceManager(nav.NameTable); @@ -82,43 +84,23 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering throw new VectoException("XML input data with file references can not be read via stream!"); } - InitializeComponentDataProvider(verifyXml); + InitializeComponentDataProvider(); } - private void ReadXMLDocument(Stream inputData, bool verifyXml) + private void ReadXMLDocument(Stream inputData) { - XmlReaderSettings settings = null; - if (verifyXml) { - settings = new XmlReaderSettings { - ValidationType = ValidationType.Schema, - ValidationFlags = XmlSchemaValidationFlags.ProcessInlineSchema | - //XmlSchemaValidationFlags.ProcessSchemaLocation | - XmlSchemaValidationFlags.ReportValidationWarnings - }; - settings.ValidationEventHandler += ValidationCallBack; - settings.Schemas.Add(GetXMLSchema("")); - } - try { - Document = new XPathDocument(XmlReader.Create(inputData, settings)); - } catch (XmlSchemaValidationException validationException) { - throw new VectoException("Validation of input data failed", validationException); + + var xmldoc = new XmlDocument(); + xmldoc.Load(inputData); + if (VerifyXml) { + new XMLValidator(xmldoc, null, ValidationCallBack).ValidateXML(XMLValidator.XmlDocumentType.EngineeringData); } + Document = xmldoc; } - private void InitializeComponentDataProvider(bool verifyXml) + private void InitializeComponentDataProvider() { - Settings = null; - if (verifyXml) { - Settings = new XmlReaderSettings { - ValidationType = ValidationType.Schema, - ValidationFlags = XmlSchemaValidationFlags.ProcessInlineSchema | - //XmlSchemaValidationFlags.ProcessSchemaLocation | - XmlSchemaValidationFlags.ReportValidationWarnings - }; - Settings.Schemas.Add(GetXMLSchema("")); - } - var helper = new XPathHelper(ExecutionMode.Engineering); XMLEngineeringJobData = new XMLEngineeringJobInputDataProvider(this, Document, helper.QueryAbs(helper.NSPrefix(XMLNames.VectoInputEngineering, Constants.XML.RootNSPrefix)), @@ -130,19 +112,19 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering XMLNames.ComponentDataWrapper), Path.GetDirectoryName(Path.GetFullPath(FileName))); return; } - ReadVehicle(Settings); + ReadVehicle(); XMLEngineeringDriverData = XMLEngineeringJobData.GetDriverData(); } - private static void ValidationCallBack(object sender, ValidationEventArgs args) + internal static void ValidationCallBack(XmlSeverityType severity, ValidationEvent evt) { - if (args.Severity == XmlSeverityType.Error) { - throw new VectoException("Validation error: {0}", args.Message); + if (severity == XmlSeverityType.Error) { + throw new VectoException("Validation error: {0}", evt.ValidationEventArgs.Message); } } - private void ReadVehicle(XmlReaderSettings settings) + private void ReadVehicle() { var helper = new XPathHelper(ExecutionMode.Engineering); @@ -166,9 +148,12 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering if (extVehicle != null) { try { var vehicleFile = extVehicle.GetAttribute(XMLNames.ExtResource_File_Attr, ""); - var vehicleDocument = new XPathDocument( - XmlReader.Create(Path.Combine(Path.GetDirectoryName(FileName) ?? "./", vehicleFile), - settings)); + var vehicleDocument = new XmlDocument(); + vehicleDocument.Load(XmlReader.Create(Path.Combine(Path.GetDirectoryName(FileName) ?? "./", vehicleFile))); + if (VerifyXml) { + new XMLValidator(vehicleDocument, null, ValidationCallBack).ValidateXML(XMLValidator.XmlDocumentType + .EngineeringData); + } var vehicleCompPath = helper.QueryAbs( helper.NSPrefix("VectoComponentEngineering", Constants.XML.RootNSPrefix), diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringJobInputDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringJobInputDataProvider.cs index 324054616a..553a5ff056 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringJobInputDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringJobInputDataProvider.cs @@ -48,7 +48,7 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering public class XMLEngineeringJobInputDataProvider : AbstractEngineeringXMLComponentDataProvider, IEngineeringJobInputData { public XMLEngineeringJobInputDataProvider(XMLEngineeringInputDataProvider xmlEngineeringJobInputDataProvider, - XPathDocument jobDocument, string xmlBasePath, string fsBasePath) + XmlDocument jobDocument, string xmlBasePath, string fsBasePath) : base(xmlEngineeringJobInputDataProvider, jobDocument, xmlBasePath, fsBasePath) {} @@ -62,11 +62,6 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering get { return InputData.VehicleInputData; } } - //IEngineEngineeringInputData EngineInputData - //{ - // get { return new XMLEngineeringEngineDataProvider(InputData, XMLDocument, Helper.Query(XBasePath, XMLNames.Component_Engine, XMLNames.ComponentDataWrapper) ,FSBasePath); } - //} - public IList<ICycleData> Cycles { get { diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringRetarderDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringRetarderDataProvider.cs index 082df62445..ccd8c51df2 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringRetarderDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringRetarderDataProvider.cs @@ -29,40 +29,40 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.Xml.XPath; -using TUGraz.IVT.VectoXML; -using TUGraz.VectoCommon.InputData; -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Resources; - -namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering -{ - public class XMLEngineeringRetarderDataProvider : AbstractEngineeringXMLComponentDataProvider, IRetarderInputData - { - public XMLEngineeringRetarderDataProvider(XMLEngineeringInputDataProvider xmlEngineeringJobInputDataProvider, - XPathDocument retarderDocument, string xmlBasePath, string fsBasePath) - : base(xmlEngineeringJobInputDataProvider, retarderDocument, xmlBasePath, fsBasePath) {} - - public RetarderType Type - { - get { return InputData.VehicleData.RetarderType; } - } - - public double Ratio - { - get { return InputData.VehicleData.RetarderRatio; } - } - - public TableData LossMap - { - get - { - if (ElementExists(Helper.Query(XMLNames.Retarder_RetarderLossMap, XMLNames.Retarder_RetarderLossMap_Entry))) { - return ReadTableData(AttributeMappings.RetarderLossmapMapping, - Helper.Query(XMLNames.Retarder_RetarderLossMap, XMLNames.Retarder_RetarderLossMap_Entry)); - } - return ReadCSVResourceFile(XMLNames.Retarder_RetarderLossMap); - } - } - } +using System.Xml; +using TUGraz.IVT.VectoXML; +using TUGraz.VectoCommon.InputData; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Resources; + +namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering +{ + public class XMLEngineeringRetarderDataProvider : AbstractEngineeringXMLComponentDataProvider, IRetarderInputData + { + public XMLEngineeringRetarderDataProvider(XMLEngineeringInputDataProvider xmlEngineeringJobInputDataProvider, + XmlDocument retarderDocument, string xmlBasePath, string fsBasePath) + : base(xmlEngineeringJobInputDataProvider, retarderDocument, xmlBasePath, fsBasePath) {} + + public RetarderType Type + { + get { return InputData.VehicleData.RetarderType; } + } + + public double Ratio + { + get { return InputData.VehicleData.RetarderRatio; } + } + + public TableData LossMap + { + get + { + if (ElementExists(Helper.Query(XMLNames.Retarder_RetarderLossMap, XMLNames.Retarder_RetarderLossMap_Entry))) { + return ReadTableData(AttributeMappings.RetarderLossmapMapping, + Helper.Query(XMLNames.Retarder_RetarderLossMap, XMLNames.Retarder_RetarderLossMap_Entry)); + } + return ReadCSVResourceFile(XMLNames.Retarder_RetarderLossMap); + } + } + } } \ No newline at end of file diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringTorqueConverterDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringTorqueConverterDataProvider.cs index dec48e55ba..fa71b69239 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringTorqueConverterDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringTorqueConverterDataProvider.cs @@ -29,83 +29,83 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.Xml.XPath; -using TUGraz.IVT.VectoXML; -using TUGraz.VectoCommon.InputData; -using TUGraz.VectoCommon.Resources; -using TUGraz.VectoCommon.Utils; - -namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering -{ - public class XMLEngineeringTorqueConverterDataProvider : AbstractEngineeringXMLComponentDataProvider, - ITorqueConverterEngineeringInputData - { - public XMLEngineeringTorqueConverterDataProvider(XMLEngineeringInputDataProvider jobInputData, - XPathDocument xmlDocument, - string xBasePath, string fsBasePath) - : base(jobInputData, xmlDocument, xBasePath, fsBasePath) {} - - public TableData TCData - { - get - { - if ( - ElementExists(Helper.Query(XMLNames.TorqueConverter_Characteristics, XMLNames.TorqueConverter_Characteristics_Entry))) { - return ReadTableData(AttributeMappings.TorqueConverterDataMapping, - Helper.Query(XMLNames.TorqueConverter_Characteristics, XMLNames.TorqueConverter_Characteristics_Entry)); - } - return ReadCSVResourceFile(XMLNames.TorqueConverter_Characteristics); - } - } - - public PerSecond ReferenceRPM - { - get { return GetDoubleElementValue(XMLNames.TorqueConverter_ReferenceRPM).RPMtoRad(); } - } - - public KilogramSquareMeter Inertia - { - get { return GetDoubleElementValue(XMLNames.TorqueConverter_Inertia).SI<KilogramSquareMeter>(); } - } - - - public TableData ShiftPolygon - { - get - { - if (ElementExists(Helper.Query(XMLNames.TorqueConverter_ShiftPolygon, XMLNames.TorqueConverter_ShiftPolygon_Entry))) { - return ReadTableData(AttributeMappings.ShiftPolygonMapping, - Helper.Query(XMLNames.TorqueConverter_ShiftPolygon, XMLNames.TorqueConverter_ShiftPolygon_Entry)); - } - if ( - ElementExists(Helper.Query(XMLNames.TorqueConverter_ShiftPolygon, ExtCsvResourceTag))) { - return ReadCSVResourceFile(XMLNames.TorqueConverter_ShiftPolygon); - } - return null; - } - } - - public PerSecond MaxInputSpeed - { - get - { - return ElementExists(Helper.Query("MaxInputSpeed")) - ? GetDoubleElementValue("MaxInputSpeed").RPMtoRad() - : 5000.RPMtoRad(); - } - } - - public MeterPerSquareSecond CLUpshiftMinAcceleration - { - get { return InputData.XMLEngineeringJobData.CLUpshiftMinAcceleration; } - } - - public MeterPerSquareSecond CCUpshiftMinAcceleration - { - get - { - return InputData.XMLEngineeringJobData.CCUpshiftMinAcceleration; - } - } - } +using System.Xml; +using TUGraz.IVT.VectoXML; +using TUGraz.VectoCommon.InputData; +using TUGraz.VectoCommon.Resources; +using TUGraz.VectoCommon.Utils; + +namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering +{ + public class XMLEngineeringTorqueConverterDataProvider : AbstractEngineeringXMLComponentDataProvider, + ITorqueConverterEngineeringInputData + { + public XMLEngineeringTorqueConverterDataProvider(XMLEngineeringInputDataProvider jobInputData, + XmlDocument xmlDocument, + string xBasePath, string fsBasePath) + : base(jobInputData, xmlDocument, xBasePath, fsBasePath) {} + + public TableData TCData + { + get + { + if ( + ElementExists(Helper.Query(XMLNames.TorqueConverter_Characteristics, XMLNames.TorqueConverter_Characteristics_Entry))) { + return ReadTableData(AttributeMappings.TorqueConverterDataMapping, + Helper.Query(XMLNames.TorqueConverter_Characteristics, XMLNames.TorqueConverter_Characteristics_Entry)); + } + return ReadCSVResourceFile(XMLNames.TorqueConverter_Characteristics); + } + } + + public PerSecond ReferenceRPM + { + get { return GetDoubleElementValue(XMLNames.TorqueConverter_ReferenceRPM).RPMtoRad(); } + } + + public KilogramSquareMeter Inertia + { + get { return GetDoubleElementValue(XMLNames.TorqueConverter_Inertia).SI<KilogramSquareMeter>(); } + } + + + public TableData ShiftPolygon + { + get + { + if (ElementExists(Helper.Query(XMLNames.TorqueConverter_ShiftPolygon, XMLNames.TorqueConverter_ShiftPolygon_Entry))) { + return ReadTableData(AttributeMappings.ShiftPolygonMapping, + Helper.Query(XMLNames.TorqueConverter_ShiftPolygon, XMLNames.TorqueConverter_ShiftPolygon_Entry)); + } + if ( + ElementExists(Helper.Query(XMLNames.TorqueConverter_ShiftPolygon, ExtCsvResourceTag))) { + return ReadCSVResourceFile(XMLNames.TorqueConverter_ShiftPolygon); + } + return null; + } + } + + public PerSecond MaxInputSpeed + { + get + { + return ElementExists(Helper.Query("MaxInputSpeed")) + ? GetDoubleElementValue("MaxInputSpeed").RPMtoRad() + : 5000.RPMtoRad(); + } + } + + public MeterPerSquareSecond CLUpshiftMinAcceleration + { + get { return InputData.XMLEngineeringJobData.CLUpshiftMinAcceleration; } + } + + public MeterPerSquareSecond CCUpshiftMinAcceleration + { + get + { + return InputData.XMLEngineeringJobData.CCUpshiftMinAcceleration; + } + } + } } \ No newline at end of file diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringVehicleDataProvider.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringVehicleDataProvider.cs index 8a3c606876..287678bfd0 100644 --- a/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringVehicleDataProvider.cs +++ b/VectoCore/VectoCore/InputData/FileIO/XML/Engineering/XMLEngineeringVehicleDataProvider.cs @@ -44,6 +44,7 @@ using TUGraz.VectoCommon.Resources; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.InputData.Impl; +using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering { @@ -55,18 +56,18 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering protected internal XMLEngineeringAxlegearDataProvider AxlegearData; public XMLEngineeringVehicleDataProvider(XMLEngineeringInputDataProvider jobProvider, - XPathDocument vehicleDocument, string xmlBasePath, string fsBasePath) + XmlDocument vehicleDocument, string xmlBasePath, string fsBasePath) : base(jobProvider, vehicleDocument, xmlBasePath, fsBasePath) { - AxlegearData = GetAxleGearInputData(jobProvider.Settings); + AxlegearData = GetAxleGearInputData(jobProvider.VerifyXml); AngledriveInputData = GetAngularGearInputData(); - EngineInputData = GetEngineInputData(jobProvider.Settings); - RetarderInputData = GetRetarderInputData(jobProvider.Settings); - XMLEngineeringAuxiliaryData = GetAuxiliaryData(jobProvider.Settings); - GearboxInputData = GetGearboxData(jobProvider.Settings); + EngineInputData = GetEngineInputData(jobProvider.VerifyXml); + RetarderInputData = GetRetarderInputData(jobProvider.VerifyXml); + XMLEngineeringAuxiliaryData = GetAuxiliaryData(jobProvider.VerifyXml); + GearboxInputData = GetGearboxData(jobProvider.VerifyXml); TorqueConverterInputData = GearboxInputData.TorqueConverter; PTOTransmissionInputData = GetPTOData(); - AirdragInputData = GetAirdragInputData(jobProvider.Settings); + AirdragInputData = GetAirdragInputData(jobProvider.VerifyXml); } public string GetVehicleID @@ -215,8 +216,8 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering Steered = steered != null && XmlConvert.ToBoolean(steered.Value), AxleWeightShare = weightShare == null ? 0 : weightShare.ValueAsDouble, Tyre = new TyreInputData() { - TyreTestLoad = tyreTestLoad == null ? null : tyreTestLoad.ValueAsDouble.SI<Newton>(), - RollResistanceCoefficient = rollResistance == null ? double.NaN : rollResistance.ValueAsDouble, + TyreTestLoad = tyreTestLoad == null ? null : tyreTestLoad.Value.ToDouble().SI<Newton>(), + RollResistanceCoefficient = rollResistance == null ? double.NaN : rollResistance.Value.ToDouble(), Dimension = dimension == null ? null : dimension.Value, Inertia = inertia == null ? null : inertia.ValueAsDouble.SI<KilogramSquareMeter>(), } @@ -291,25 +292,25 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering #region "FactoryMethods" - private IAirdragEngineeringInputData GetAirdragInputData(XmlReaderSettings settings) + private IAirdragEngineeringInputData GetAirdragInputData(bool verifyXml) { - return CreateComponentInput(XMLNames.Component_AirDrag, settings, + return CreateComponentInput(XMLNames.Component_AirDrag, verifyXml, (a, b, c, d) => new XMLEngineeringAirdragDataProvider(a, b, c, d)); } - private XMLEngineeringAxlegearDataProvider GetAxleGearInputData(XmlReaderSettings settings) + private XMLEngineeringAxlegearDataProvider GetAxleGearInputData(bool verifyXml) { - return CreateComponentInput(XMLNames.Component_Axlegear, settings, + return CreateComponentInput(XMLNames.Component_Axlegear, verifyXml, (a, b, c, d) => new XMLEngineeringAxlegearDataProvider(a, b, c, d)); } - private XMLEngineeringEngineDataProvider GetEngineInputData(XmlReaderSettings settings) + private XMLEngineeringEngineDataProvider GetEngineInputData(bool verifyXml) { - return CreateComponentInput(XMLNames.Component_Engine, settings, + return CreateComponentInput(XMLNames.Component_Engine, verifyXml, (a, b, c, d) => new XMLEngineeringEngineDataProvider(a, b, c, d)); } - private XMLEngineeringRetarderDataProvider GetRetarderInputData(XmlReaderSettings settings) + private XMLEngineeringRetarderDataProvider GetRetarderInputData(bool verifyXml) { if (!RetarderType.IsDedicatedComponent()) { return new XMLEngineeringRetarderDataProvider(InputData, XMLDocument, @@ -317,25 +318,25 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering FSBasePath); } - return CreateComponentInput(XMLNames.Component_Retarder, settings, + return CreateComponentInput(XMLNames.Component_Retarder, verifyXml, (a, b, c, d) => new XMLEngineeringRetarderDataProvider(a, b, c, d)); } - private XMLEngineeringGearboxDataProvider GetGearboxData(XmlReaderSettings settings) + private XMLEngineeringGearboxDataProvider GetGearboxData(bool verifyXml) { - return CreateComponentInput(XMLNames.Component_Gearbox, settings, + return CreateComponentInput(XMLNames.Component_Gearbox, verifyXml, (a, b, c, d) => new XMLEngineeringGearboxDataProvider(a, b, c, d)); } - private XMLEngineeringAuxiliaryDataProvider GetAuxiliaryData(XmlReaderSettings settings) + private XMLEngineeringAuxiliaryDataProvider GetAuxiliaryData(bool verifyXml) { - return CreateComponentInput(XMLNames.Component_Auxiliaries, settings, + return CreateComponentInput(XMLNames.Component_Auxiliaries, verifyXml, (a, b, c, d) => new XMLEngineeringAuxiliaryDataProvider(a, b, c, d)); } - private T CreateComponentInput<T>(string componentName, XmlReaderSettings settings, - Func<XMLEngineeringInputDataProvider, XPathDocument, string, string, T> creator) + private T CreateComponentInput<T>(string componentName, bool verifyXml, + Func<XMLEngineeringInputDataProvider, XmlDocument, string, string, T> creator) { if (ElementExists(Helper.Query(XMLNames.Vehicle_Components, componentName))) { return creator(InputData, XMLDocument, @@ -352,7 +353,12 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Engineering if (componentNode != null) { try { var componentFile = componentNode.GetAttribute(XMLNames.ExtResource_File_Attr, ""); - var componentDocument = new XPathDocument(XmlReader.Create(Path.Combine(FSBasePath, componentFile), settings)); + var componentDocument = new XmlDocument(); + componentDocument.Load(XmlReader.Create(Path.Combine(FSBasePath, componentFile))); + if (verifyXml) { + new XMLValidator(componentDocument, null, XMLEngineeringInputDataProvider.ValidationCallBack).ValidateXML(XMLValidator.XmlDocumentType + .EngineeringData); + } return creator(InputData, componentDocument, Helper.QueryAbs(Helper.NSPrefix(XMLNames.VectoComponentEngineering, Constants.XML.RootNSPrefix), componentName, XMLNames.ComponentDataWrapper), diff --git a/VectoCore/VectoCore/OutputData/XML/AbstractXMLWriter.cs b/VectoCore/VectoCore/OutputData/XML/AbstractXMLWriter.cs index 33dac0d7cb..9334f831de 100644 --- a/VectoCore/VectoCore/OutputData/XML/AbstractXMLWriter.cs +++ b/VectoCore/VectoCore/OutputData/XML/AbstractXMLWriter.cs @@ -43,7 +43,8 @@ namespace TUGraz.IVT.VectoXML.Writer { //protected const string SchemaLocationBaseUrl = "http://markus.quaritsch.at/VECTO/"; public const string SchemaLocationBaseUrl = "https://webgate.ec.europa.eu/CITnet/svn/VECTO/trunk/Share/XML/XSD/"; - protected const string SchemaVersion = "1.0"; + + protected string SchemaVersion; // = "1.0"; protected XNamespace tns; protected XNamespace rootNamespace; diff --git a/VectoCore/VectoCore/OutputData/XML/XMLCustomerReport.cs b/VectoCore/VectoCore/OutputData/XML/XMLCustomerReport.cs index c26fbfec89..3f47fff9c0 100644 --- a/VectoCore/VectoCore/OutputData/XML/XMLCustomerReport.cs +++ b/VectoCore/VectoCore/OutputData/XML/XMLCustomerReport.cs @@ -50,6 +50,8 @@ namespace TUGraz.VectoCore.OutputData.XML { public class XMLCustomerReport { + public const string CURRENT_SCHEMA_VERSION = "0.4"; + protected readonly XElement VehiclePart; protected XElement InputDataIntegrity; @@ -63,7 +65,7 @@ namespace TUGraz.VectoCore.OutputData.XML public XMLCustomerReport() { di = "http://www.w3.org/2000/09/xmldsig#"; - tns = "urn:tugraz:ivt:VectoAPI:CustomerOutput:v0.4"; + tns = "urn:tugraz:ivt:VectoAPI:CustomerOutput:v" + CURRENT_SCHEMA_VERSION; VehiclePart = new XElement(tns + XMLNames.Component_Vehicle); Results = new XElement(tns + "Results"); } @@ -82,7 +84,7 @@ namespace TUGraz.VectoCore.OutputData.XML new XElement(tns + XMLNames.Vehicle_CurbMassChassis, modelData.VehicleData.CurbWeight.ToXMLFormat(0)), new XElement(tns + XMLNames.Report_Vehicle_EngineRatedPower, modelData.EngineData.RatedPowerDeclared.ToXMLFormat(0)), new XElement(tns + XMLNames.Report_Vehicle_EngineDisplacement, - modelData.EngineData.Displacement.ConvertToCubicCentiMeter().ToXMLFormat(0)), + modelData.EngineData.Displacement.ConvertToCubicCentiMeter().ToXMLFormat(0)), new XElement(tns + XMLNames.Engine_FuelType, modelData.EngineData.FuelType.ToXMLFormat()), new XElement(tns + XMLNames.Report_Vehicle_TransmissionCertificationMethod, modelData.GearboxData.CertificationMethod.ToXMLFormat()), @@ -164,12 +166,12 @@ namespace TUGraz.VectoCore.OutputData.XML var vehicle = new XElement(VehiclePart); vehicle.Add(InputDataIntegrity); retVal.Add(new XElement(tns + XMLNames.VectoCustomerReport, - new XAttribute("schemaVersion", "0.4"), + new XAttribute("schemaVersion", CURRENT_SCHEMA_VERSION), new XAttribute(XNamespace.Xmlns + "xsi", xsi.NamespaceName), new XAttribute("xmlns", tns), new XAttribute(XNamespace.Xmlns + "di", di), new XAttribute(xsi + "schemaLocation", - string.Format("{0} {1}VectoOutputCustomer.xsd", tns, AbstractXMLWriter.SchemaLocationBaseUrl)), + string.Format("{0} {1}VectoOutputCustomer.{2}.xsd", tns, AbstractXMLWriter.SchemaLocationBaseUrl, CURRENT_SCHEMA_VERSION)), new XElement(tns + "Data", vehicle, new XElement(tns + "ResultDataSignature", resultSignature), diff --git a/VectoCore/VectoCore/OutputData/XML/XMLDeclarationWriter.cs b/VectoCore/VectoCore/OutputData/XML/XMLDeclarationWriter.cs index 0c5c8112f8..fd57f7e22e 100644 --- a/VectoCore/VectoCore/OutputData/XML/XMLDeclarationWriter.cs +++ b/VectoCore/VectoCore/OutputData/XML/XMLDeclarationWriter.cs @@ -56,6 +56,7 @@ namespace TUGraz.VectoCore.OutputData.XML tns = "urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v1.0"; rootNamespace = "urn:tugraz:ivt:VectoAPI:DeclarationInput:v1.0"; componentNamespace = "urn:tugraz:ivt:VectoAPI:DeclarationComponent:v1.0"; + SchemaVersion = "1.0"; } public XDocument GenerateVectoJob(IDeclarationInputDataProvider data) diff --git a/VectoCore/VectoCore/OutputData/XML/XMLEngineeringWriter.cs b/VectoCore/VectoCore/OutputData/XML/XMLEngineeringWriter.cs index 2bfb4dc489..f4ae584bf3 100644 --- a/VectoCore/VectoCore/OutputData/XML/XMLEngineeringWriter.cs +++ b/VectoCore/VectoCore/OutputData/XML/XMLEngineeringWriter.cs @@ -57,7 +57,7 @@ namespace TUGraz.VectoCore.OutputData.XML public XMLEngineeringWriter(string basePath, bool singleFile, string vendor) : base(basePath, vendor) { _singleFile = singleFile; - + SchemaVersion = "0.7"; tns = Constants.XML.VectoEngineeringDefinitionsNS; // "urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.6"; rootNamespace = Constants.XML.VectoEngineeringInputNS; // "urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.6"; _declarationNamespace = Constants.XML.VectoDeclarationDefinitionsNS; diff --git a/VectoCore/VectoCore/OutputData/XML/XMLManufacturerReport.cs b/VectoCore/VectoCore/OutputData/XML/XMLManufacturerReport.cs index b6e27f794a..e6cabff5b6 100644 --- a/VectoCore/VectoCore/OutputData/XML/XMLManufacturerReport.cs +++ b/VectoCore/VectoCore/OutputData/XML/XMLManufacturerReport.cs @@ -52,8 +52,10 @@ namespace TUGraz.VectoCore.OutputData.XML { public class XMLManufacturerReport { + public const string CURRENT_SCHEMA_VERSION = "0.4"; + protected XElement VehiclePart; - + protected XElement InputDataIntegrity; protected XElement Results; @@ -65,7 +67,7 @@ namespace TUGraz.VectoCore.OutputData.XML public XMLManufacturerReport() { di = "http://www.w3.org/2000/09/xmldsig#"; - tns = "urn:tugraz:ivt:VectoAPI:DeclarationOutput:v0.4"; + tns = "urn:tugraz:ivt:VectoAPI:DeclarationOutput:v" + CURRENT_SCHEMA_VERSION; VehiclePart = new XElement(tns + XMLNames.Component_Vehicle); Results = new XElement(tns + "Results"); } @@ -346,12 +348,12 @@ namespace TUGraz.VectoCore.OutputData.XML var vehicle = new XElement(VehiclePart); vehicle.Add(InputDataIntegrity); retVal.Add(new XElement(tns + XMLNames.VectoManufacturerReport, - new XAttribute("schemaVersion", "0.4"), + new XAttribute("schemaVersion", CURRENT_SCHEMA_VERSION), new XAttribute(XNamespace.Xmlns + "xsi", xsi.NamespaceName), new XAttribute("xmlns", tns), new XAttribute(XNamespace.Xmlns + "di", di), new XAttribute(xsi + "schemaLocation", - string.Format("{0} {1}VectoOutputManufacturer.xsd", tns, AbstractXMLWriter.SchemaLocationBaseUrl)), + string.Format("{0} {1}VectoOutputManufacturer.{2}.xsd", tns, AbstractXMLWriter.SchemaLocationBaseUrl, CURRENT_SCHEMA_VERSION)), new XElement(tns + "Data", vehicle, results, diff --git a/VectoCore/VectoCore/Resources/XSD/VectoComponent.1.0.xsd b/VectoCore/VectoCore/Resources/XSD/VectoComponent.1.0.xsd new file mode 100644 index 0000000000..b620690470 --- /dev/null +++ b/VectoCore/VectoCore/Resources/XSD/VectoComponent.1.0.xsd @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- edited with XMLSpy v2016 rel. 2 (x64) (http://www.altova.com) by Helmut Eichlseder (TU Graz/Inst. f. VKM und THD) --> +<xs:schema xmlns:tns="urn:tugraz:ivt:VectoAPI:DeclarationComponent:v1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:vectoParam="urn:tugraz:ivt:VectoAPI:ParameterDocumentation" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v1.0" targetNamespace="urn:tugraz:ivt:VectoAPI:DeclarationComponent:v1.0" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:ParameterDocumentation ParameterDocumentation.xsd"> + <xs:import namespace="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v1.0" schemaLocation="VectoDeclarationDefinitions.1.0.xsd"/> + <xs:element name="VectoInputDeclaration"> + <xs:annotation> + <xs:documentation>Root Node Declaration Data</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:choice> + <xs:element name="Engine" type="vdecdef:EngineComponentDeclarationType"/> + <xs:element name="Gearbox" type="vdecdef:GearboxComponentDeclarationType"/> + <xs:element name="TorqueConverter" type="vdecdef:TorqueConverterComponentDeclarationType"/> + <xs:element name="Retarder" type="vdecdef:RetarderComponentDeclarationType"/> + <xs:element name="Axlegear" type="vdecdef:AxlegearComponentDeclarationType"/> + <xs:element name="Tyre" type="vdecdef:TyreDeclarationType"/> + <xs:element name="Auxiliaries" type="vdecdef:AuxiliariesComponentDeclarationType"/> + <xs:element name="Angledrive" type="vdecdef:AngledriveComponentDeclarationType"/> + <xs:element name="AirDrag" type="vdecdef:AirDragComponentDeclarationType"/> + </xs:choice> + <xs:attribute name="schemaVersion" use="required"> + <xs:simpleType> + <xs:restriction base="xs:decimal"> + <xs:minExclusive value="0"/> + <xs:fractionDigits value="1"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + </xs:complexType> + </xs:element> +</xs:schema> diff --git a/VectoCore/VectoCore/Resources/XSD/VectoEngineeringInput.0.7.xsd b/VectoCore/VectoCore/Resources/XSD/VectoEngineeringInput.0.7.xsd new file mode 100644 index 0000000000..9737f6812b --- /dev/null +++ b/VectoCore/VectoCore/Resources/XSD/VectoEngineeringInput.0.7.xsd @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- edited with XMLSpy v2016 rel. 2 (x64) (http://www.altova.com) by Helmut Eichlseder (TU Graz/Inst. f. VKM und THD) --> +<xs:schema xmlns:tns="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:vectoParam="urn:tugraz:ivt:VectoAPI:ParameterDocumentation" xmlns:vengdef="urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.7" targetNamespace="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7" elementFormDefault="qualified" attributeFormDefault="unqualified" version="0.7" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:ParameterDocumentation ParameterDocumentation.xsd"> + <xs:import namespace="urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.7" schemaLocation="VectoEngineeringDefinitions.0.7.xsd"/> + <xs:element name="VectoComponentEngineering" type="vengdef:VectoComponentEngineeringType"> + <xs:annotation> + <xs:documentation>Root Node Engineering Component Data</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="VectoInputEngineering" type="vengdef:VectoJobEngineeringType"> + <xs:annotation> + <xs:documentation>Root Node Engineering Job</xs:documentation> + </xs:annotation> + </xs:element> +</xs:schema> diff --git a/VectoCore/VectoCore/Resources/XSD/VectoInput.1.0.xsd b/VectoCore/VectoCore/Resources/XSD/VectoInput.1.0.xsd new file mode 100644 index 0000000000..bafee4d8c7 --- /dev/null +++ b/VectoCore/VectoCore/Resources/XSD/VectoInput.1.0.xsd @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- edited with XMLSpy v2016 rel. 2 (x64) (http://www.altova.com) by Helmut Eichlseder (TU Graz/Inst. f. VKM und THD) --> +<xs:schema xmlns:tns="urn:tugraz:ivt:VectoAPI:DeclarationInput:v1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:vectoParam="urn:tugraz:ivt:VectoAPI:ParameterDocumentation" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v1.0" targetNamespace="urn:tugraz:ivt:VectoAPI:DeclarationInput:v1.0" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:ParameterDocumentation ParameterDocumentation.xsd"> + <xs:import namespace="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v1.0" schemaLocation="VectoDeclarationDefinitions.1.0.xsd"/> + <xs:element name="VectoInputDeclaration" type="vdecdef:VectoDeclarationJobType"> + <xs:annotation> + <xs:documentation>Root Node Declaration Data</xs:documentation> + </xs:annotation> + </xs:element> +</xs:schema> diff --git a/VectoCore/VectoCore/Resources/XSD/VectoOutputCustomer.0.4.xsd b/VectoCore/VectoCore/Resources/XSD/VectoOutputCustomer.0.4.xsd new file mode 100644 index 0000000000..79393a75b6 --- /dev/null +++ b/VectoCore/VectoCore/Resources/XSD/VectoOutputCustomer.0.4.xsd @@ -0,0 +1,258 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- edited with XMLSpy v2016 rel. 2 (x64) (http://www.altova.com) by Helmut Eichlseder (TU Graz/Inst. f. VKM und THD) --> +<!--W3C XML Schema generated by XMLSpy vXMLSpy Professional Edition v2016 rel. 2 (x64) (http://www.altova.com)--> +<xs:schema xmlns="urn:tugraz:ivt:VectoAPI:CustomerOutput:v0.4" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v1.0" targetNamespace="urn:tugraz:ivt:VectoAPI:CustomerOutput:v0.4" elementFormDefault="qualified" attributeFormDefault="unqualified" version="0.4"> + <xs:import namespace="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v1.0" schemaLocation="VectoDeclarationDefinitions.1.0.xsd"/> + <xs:element name="VectoCustomerInformation"> + <xs:annotation> + <xs:documentation>Comment describing your root element</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:sequence> + <xs:element name="Data"> + <xs:complexType> + <xs:complexContent> + <xs:extension base="VectoOutputDataType"/> + </xs:complexContent> + </xs:complexType> + </xs:element> + <xs:element name="Signature" type="vdecdef:SignatureType"/> + </xs:sequence> + <xs:attribute name="schemaVersion" type="xs:decimal" use="required"/> + </xs:complexType> + </xs:element> + <xs:complexType name="CO2Type"> + <xs:simpleContent> + <xs:extension base="xs:double"> + <xs:attribute name="unit" type="CO2UnitType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + <xs:complexType name="FuelConsumptionType"> + <xs:simpleContent> + <xs:extension base="xs:double"> + <xs:attribute name="unit" type="FuelConsumptionUnitType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + <xs:complexType name="ResultType"> + <xs:sequence> + <xs:element name="Mission" type="MissionTypeType"/> + <xs:choice> + <xs:sequence> + <xs:element name="Payload"> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:double"> + <xs:attribute name="unit" type="MassUnitType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="FuelType" type="vdecdef:FuelTypeType"/> + <xs:element name="AverageSpeed"> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:double"> + <xs:attribute name="unit" type="SpeedUnitType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="FuelConsumption" type="FuelConsumptionType" maxOccurs="unbounded"/> + <xs:element name="CO2" type="CO2Type" maxOccurs="unbounded"/> + </xs:sequence> + <xs:element name="Error"/> + </xs:choice> + </xs:sequence> + <xs:attribute name="status" use="required"> + <xs:simpleType> + <xs:restriction base="xs:string"> + <xs:enumeration value="success"/> + <xs:enumeration value="error"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + </xs:complexType> + <xs:complexType name="VectoOutputDataType"> + <xs:sequence> + <xs:element name="Vehicle" type="VehicleType"/> + <xs:element name="ResultDataSignature" type="vdecdef:SignatureType"/> + <xs:element name="Results"> + <xs:complexType> + <xs:sequence> + <xs:element name="Status"> + <xs:simpleType> + <xs:restriction base="xs:string"> + <xs:enumeration value="success"/> + <xs:enumeration value="error"/> + </xs:restriction> + </xs:simpleType> + </xs:element> + <xs:element name="Result" type="ResultType" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="ApplicationInformation"> + <xs:complexType> + <xs:sequence> + <xs:element name="SimulationToolVersion"/> + <xs:element name="Date"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + <xs:attribute name="id" use="required"/> + </xs:complexType> + <xs:complexType name="VehiclePerformanceType"> + <xs:sequence/> + </xs:complexType> + <xs:complexType name="VehicleType"> + <xs:sequence> + <xs:element name="Model" type="vdecdef:ModelType"/> + <xs:element name="Manufacturer" type="vdecdef:ManufacturerType"/> + <xs:element name="ManufacturerAddress" type="vdecdef:ManufacturerAddressType"/> + <xs:element name="VIN"> + <xs:annotation> + <xs:documentation>P238</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="LegislativeClass" type="vdecdef:LegislativeClassDeclarationType"> + <xs:annotation> + <xs:documentation>P251</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="VehicleGroup" type="VehicleGroupType"> + <xs:annotation> + <xs:documentation>VECTO</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="AxleConfiguration" type="vdecdef:VehicleAxleConfigurationDeclarationType"> + <xs:annotation> + <xs:documentation>P037</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="GrossVehicleMass" type="vdecdef:VehicleGrossVehicleMassType"> + <xs:annotation> + <xs:documentation>P041</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="CurbMassChassis" type="vdecdef:VehicleCurbMassChassisType"> + <xs:annotation> + <xs:documentation>P038</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="EngineRatedPower" type="vdecdef:EngineRatedPower"> + <xs:annotation> + <xs:documentation>P250</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="EngineDisplacement" type="vdecdef:EngineDisplacementType"> + <xs:annotation> + <xs:documentation>P061</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="FuelType" type="vdecdef:FuelTypeType"> + <xs:annotation> + <xs:documentation>P193</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="TransmissionMainCertificationMethod" type="vdecdef:GearboxCertificationOptionType"> + <xs:annotation> + <xs:documentation>P154</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="TransmissionType" type="vdecdef:GearboxTransmissionTypeType"> + <xs:annotation> + <xs:documentation>P076</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="GearsCount"> + <xs:annotation> + <xs:documentation>P199</xs:documentation> + </xs:annotation> + <xs:simpleType> + <xs:restriction base="xs:int"> + <xs:minInclusive value="1"/> + </xs:restriction> + </xs:simpleType> + </xs:element> + <xs:element name="Retarder" type="xs:boolean"> + <xs:annotation> + <xs:documentation>P052</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="AxleRatio" type="vdecdef:AxlegearRatioType"> + <xs:annotation> + <xs:documentation>P150</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="AverageRRC" type="vdecdef:TyreRRCISOType"/> + <xs:element name="InputDataSignature" type="vdecdef:SignatureType"/> + </xs:sequence> + </xs:complexType> + <xs:simpleType name="AccelerationUnitType"> + <xs:restriction base="xs:token"> + <xs:enumeration value="m/s²"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="AirdragCertificationOptionType"> + <xs:restriction base="xs:string"> + <xs:enumeration value="Measured"/> + <xs:enumeration value="Standard values"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="CO2UnitType"> + <xs:restriction base="xs:string"> + <xs:enumeration value="g/km"/> + <xs:enumeration value="g/t-km"/> + <xs:enumeration value="g/p-km"/> + <xs:enumeration value="g/m³-km"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="DistanceUnitType"> + <xs:restriction base="xs:token"> + <xs:enumeration value="km"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="FuelConsumptionUnitType"> + <xs:restriction base="xs:string"> + <xs:enumeration value="g/km"/> + <xs:enumeration value="g/t-km"/> + <xs:enumeration value="g/p-km"/> + <xs:enumeration value="g/m³-km"/> + <xs:enumeration value="l/100km"/> + <xs:enumeration value="l/t-km"/> + <xs:enumeration value="l/p-km"/> + <xs:enumeration value="l/m³-km"/> + <xs:enumeration value="MJ/km"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="MassUnitType"> + <xs:restriction base="xs:token"> + <xs:enumeration value="kg"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="MissionTypeType"> + <xs:restriction base="xs:token"> + <xs:enumeration value="Long Haul EMS"/> + <xs:enumeration value="Long Haul"/> + <xs:enumeration value="Regional Delivery EMS"/> + <xs:enumeration value="Regional Delivery"/> + <xs:enumeration value="Urban Delivery"/> + <xs:enumeration value="Municipal Utility"/> + <xs:enumeration value="Construction"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="SpeedUnitType"> + <xs:restriction base="xs:token"> + <xs:enumeration value="km/h"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="VehicleGroupType"> + <xs:restriction base="xs:int"> + <xs:minInclusive value="1"/> + <xs:maxInclusive value="16"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> diff --git a/VectoCore/VectoCore/Resources/XSD/VectoOutputCustomer.xsd b/VectoCore/VectoCore/Resources/XSD/VectoOutputCustomer.xsd index 79393a75b6..044e6c7007 100644 --- a/VectoCore/VectoCore/Resources/XSD/VectoOutputCustomer.xsd +++ b/VectoCore/VectoCore/Resources/XSD/VectoOutputCustomer.xsd @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- edited with XMLSpy v2016 rel. 2 (x64) (http://www.altova.com) by Helmut Eichlseder (TU Graz/Inst. f. VKM und THD) --> <!--W3C XML Schema generated by XMLSpy vXMLSpy Professional Edition v2016 rel. 2 (x64) (http://www.altova.com)--> -<xs:schema xmlns="urn:tugraz:ivt:VectoAPI:CustomerOutput:v0.4" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v1.0" targetNamespace="urn:tugraz:ivt:VectoAPI:CustomerOutput:v0.4" elementFormDefault="qualified" attributeFormDefault="unqualified" version="0.4"> +<xs:schema xmlns="urn:tugraz:ivt:VectoAPI:CustomerOutput:v0.5" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v1.0" targetNamespace="urn:tugraz:ivt:VectoAPI:CustomerOutput:v0.5" elementFormDefault="qualified" attributeFormDefault="unqualified" version="0.5"> <xs:import namespace="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v1.0" schemaLocation="VectoDeclarationDefinitions.1.0.xsd"/> <xs:element name="VectoCustomerInformation"> <xs:annotation> diff --git a/VectoCore/VectoCore/Resources/XSD/VectoOutputManufacturer.0.4.xsd b/VectoCore/VectoCore/Resources/XSD/VectoOutputManufacturer.0.4.xsd new file mode 100644 index 0000000000..2efd70f2fc --- /dev/null +++ b/VectoCore/VectoCore/Resources/XSD/VectoOutputManufacturer.0.4.xsd @@ -0,0 +1,540 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- edited with XMLSpy v2016 rel. 2 (x64) (http://www.altova.com) by Helmut Eichlseder (TU Graz/Inst. f. VKM und THD) --> +<!--W3C XML Schema generated by XMLSpy vXMLSpy Professional Edition v2016 rel. 2 (x64) (http://www.altova.com)--> +<xs:schema xmlns="urn:tugraz:ivt:VectoAPI:DeclarationOutput:v0.4" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v1.0" targetNamespace="urn:tugraz:ivt:VectoAPI:DeclarationOutput:v0.4" elementFormDefault="qualified" attributeFormDefault="unqualified" version="0.4"> + <xs:import namespace="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v1.0" schemaLocation="VectoDeclarationDefinitions.1.0.xsd"/> + <xs:element name="VectoOutput"> + <xs:annotation> + <xs:documentation>Comment describing your root element</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:sequence> + <xs:element name="Data"> + <xs:complexType> + <xs:complexContent> + <xs:extension base="VectoOutputDataType"/> + </xs:complexContent> + </xs:complexType> + </xs:element> + <xs:element name="Signature" type="vdecdef:SignatureType"/> + </xs:sequence> + <xs:attribute name="schemaVersion" type="xs:decimal" use="required"/> + </xs:complexType> + </xs:element> + <xs:complexType name="AirdragType"> + <xs:sequence> + <xs:element name="Model" minOccurs="0"/> + <xs:element name="CertificationMethod" type="AirdragCertificationOptionType"/> + <xs:element name="CertificationNumber" minOccurs="0"/> + <xs:element name="DigestValue" minOccurs="0"/> + <xs:element name="CdxA" type="vdecdef:AirdragCdxAType"> + <xs:annotation> + <xs:documentation>P245</xs:documentation> + </xs:annotation> + </xs:element> + </xs:sequence> + </xs:complexType> + <xs:complexType name="AngledriveType"> + <xs:sequence> + <xs:element name="Model" type="vdecdef:ModelType"/> + <xs:element name="CertificationMethod" type="vdecdef:AngledriveCertificationOptionType"> + <xs:annotation> + <xs:documentation>P258</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="CertificationNumber" type="vdecdef:CertificationNumberType" minOccurs="0"/> + <xs:element name="DigestValue" type="xs:token"/> + <xs:element name="Ratio" type="vdecdef:AngledriveRatioType"> + <xs:annotation> + <xs:documentation>P176</xs:documentation> + </xs:annotation> + </xs:element> + </xs:sequence> + </xs:complexType> + <xs:complexType name="AuxiliariesType"> + <xs:sequence> + <xs:element name="FanTechnology" type="vdecdef:AuxFanTechnologyType"> + <xs:annotation> + <xs:documentation>P181</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="SteeringPumpTechnology" maxOccurs="4"> + <xs:annotation> + <xs:documentation>P182</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="vdecdef:AuxSPTechnologyType"/> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="ElectricSystemTechnology" type="vdecdef:AuxESTechnologyType"> + <xs:annotation> + <xs:documentation>P183</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="PneumaticSystemTechnology" type="vdecdef:AuxPSTechnologyType"> + <xs:annotation> + <xs:documentation>P184</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="HVACTechnology" type="vdecdef:AuxHVACTechnologyType"> + <xs:annotation> + <xs:documentation>P185</xs:documentation> + </xs:annotation> + </xs:element> + </xs:sequence> + </xs:complexType> + <xs:complexType name="AxlegearType"> + <xs:sequence> + <xs:element name="Model" type="vdecdef:ModelType"/> + <xs:element name="CertificationMethod" type="vdecdef:AxlegearCertificationOptionType"> + <xs:annotation> + <xs:documentation>P256</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="CertificationNumber" type="vdecdef:CertificationNumberType" minOccurs="0"/> + <xs:element name="DigestValue" type="xs:token"/> + <xs:element name="LineType" type="vdecdef:AxlegearLineTypeType"> + <xs:annotation> + <xs:documentation>P253</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="Ratio" type="vdecdef:AxlegearRatioType"> + <xs:annotation> + <xs:documentation>P150</xs:documentation> + </xs:annotation> + </xs:element> + </xs:sequence> + </xs:complexType> + <xs:complexType name="AxleType"> + <xs:sequence> + <xs:element name="TyreDimension" type="vdecdef:TyreDimensionType"> + <xs:annotation> + <xs:documentation>P108</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="TyreCertificationNumber" type="vdecdef:CertificationNumberType"> + <xs:annotation> + <xs:documentation>P267</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="TyreRRCDeclared" type="vdecdef:TyreRRCISOType"> + <xs:annotation> + <xs:documentation>P046</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="TwinTyres" type="vdecdef:AxleTwinTyresType"> + <xs:annotation> + <xs:documentation>P045</xs:documentation> + </xs:annotation> + </xs:element> + </xs:sequence> + <xs:attribute name="axleNumber" use="required"/> + </xs:complexType> + <xs:complexType name="AxleWheelsType"> + <xs:sequence minOccurs="2" maxOccurs="4"> + <xs:element name="Axle" type="AxleType"/> + </xs:sequence> + </xs:complexType> + <xs:complexType name="CO2Type"> + <xs:simpleContent> + <xs:extension base="xs:double"> + <xs:attribute name="unit" type="CO2UnitType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + <xs:complexType name="ComponentDescriptionType"> + <xs:sequence> + <xs:element name="Model" type="vdecdef:ModelType"/> + <xs:element name="CertificationNumber" type="vdecdef:CertificationNumberType"/> + <xs:element name="DigestValue" type="xs:token"/> + </xs:sequence> + </xs:complexType> + <xs:complexType name="EngineType"> + <xs:complexContent> + <xs:extension base="ComponentDescriptionType"> + <xs:sequence> + <xs:element name="RatedPower" type="vdecdef:EngineRatedPower"> + <xs:annotation> + <xs:documentation>P250</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="IdlingSpeed" type="vdecdef:EngineDeclaredSpeedType"> + <xs:annotation> + <xs:documentation>P063 / P198</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="RatedSpeed" type="vdecdef:EngineDeclaredSpeedType"> + <xs:annotation> + <xs:documentation>P249</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="Displacement" type="vdecdef:EngineDisplacementType"> + <xs:annotation> + <xs:documentation>P061</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="FuelType" type="vdecdef:FuelTypeType"> + <xs:annotation> + <xs:documentation>P193</xs:documentation> + </xs:annotation> + </xs:element> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> + <xs:complexType name="FuelConsumptionType"> + <xs:simpleContent> + <xs:extension base="xs:double"> + <xs:attribute name="unit" type="FuelConsumptionUnitType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + <xs:complexType name="GearboxType"> + <xs:sequence> + <xs:element name="Model" type="vdecdef:ModelType"/> + <xs:element name="CertificationMethod" type="vdecdef:GearboxCertificationOptionType"> + <xs:annotation> + <xs:documentation>P154</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="CertificationNumber" type="vdecdef:CertificationNumberType" minOccurs="0"/> + <xs:element name="DigestValue" type="xs:token"/> + <xs:element name="TransmissionType" type="vdecdef:GearboxTransmissionTypeType"> + <xs:annotation> + <xs:documentation>P076</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="GearsCount"> + <xs:annotation> + <xs:documentation>P199</xs:documentation> + </xs:annotation> + <xs:simpleType> + <xs:restriction base="xs:int"> + <xs:minInclusive value="1"/> + </xs:restriction> + </xs:simpleType> + </xs:element> + <xs:element name="TransmissionRatioFinalGear" type="vdecdef:GearboxGearRatioType"> + <xs:annotation> + <xs:documentation>P078</xs:documentation> + </xs:annotation> + </xs:element> + </xs:sequence> + </xs:complexType> + <xs:complexType name="ResultType"> + <xs:sequence> + <xs:element name="Mission" type="MissionTypeType"/> + <xs:choice> + <xs:sequence> + <xs:element name="Distance"> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:double"> + <xs:attribute name="unit" type="DistanceUnitType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="SimulationParameters" type="SimulationParametersType"/> + <xs:element name="VehiclePerformance" type="VehiclePerformanceType"/> + <xs:element name="FuelConsumption" type="FuelConsumptionType" maxOccurs="unbounded"/> + <xs:element name="CO2" type="CO2Type" maxOccurs="unbounded"/> + </xs:sequence> + <xs:sequence> + <xs:element name="Error" type="xs:string"/> + <xs:element name="ErrorDetails" type="xs:string"/> + </xs:sequence> + </xs:choice> + </xs:sequence> + <xs:attribute name="status" use="required"> + <xs:simpleType> + <xs:restriction base="xs:string"> + <xs:enumeration value="success"/> + <xs:enumeration value="error"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + </xs:complexType> + <xs:complexType name="RetarderType"> + <xs:sequence> + <xs:element name="RetarderType" type="vdecdef:RetarderTypeType"> + <xs:annotation> + <xs:documentation>P052</xs:documentation> + </xs:annotation> + </xs:element> + <xs:sequence minOccurs="0"> + <xs:element name="Model" type="vdecdef:ModelType"/> + <xs:element name="CertificationMethod" type="vdecdef:RetarderCertificationOptionType"> + <xs:annotation> + <xs:documentation>P255</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="CertificationNumber" type="vdecdef:CertificationNumberType" minOccurs="0"/> + <xs:element name="DigestValue" type="xs:token"/> + </xs:sequence> + </xs:sequence> + </xs:complexType> + <xs:complexType name="SimulationParametersType"> + <xs:sequence> + <xs:element name="TotalVehicleMass"> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:double"> + <xs:attribute name="unit" type="MassUnitType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="Payload"> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:double"> + <xs:attribute name="unit" type="MassUnitType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="FuelType" type="vdecdef:FuelTypeType"/> + </xs:sequence> + </xs:complexType> + <xs:complexType name="TorqueconverterType"> + <xs:sequence> + <xs:element name="Model" type="vdecdef:ModelType"/> + <xs:element name="CertificationMethod" type="vdecdef:TorqueConverterCertificationOptionType"> + <xs:annotation> + <xs:documentation>P257</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="CertificationNumber" type="vdecdef:CertificationNumberType" minOccurs="0"/> + <xs:element name="DigestValue" type="xs:token"/> + </xs:sequence> + </xs:complexType> + <xs:complexType name="TorqueLimitsEntryType"> + <xs:attribute name="gear" type="vdecdef:GearboxGearNumberType" use="required"> + <xs:annotation> + <xs:documentation>P196</xs:documentation> + </xs:annotation> + </xs:attribute> + <xs:attribute name="torqueLimit" type="vdecdef:TorqueLimitEntryMaxTorqueType" use="required"> + <xs:annotation> + <xs:documentation>P197 / P194</xs:documentation> + </xs:annotation> + </xs:attribute> + </xs:complexType> + <xs:complexType name="TorqueLimitsType"> + <xs:sequence> + <xs:element name="Entry" type="TorqueLimitsEntryType"/> + </xs:sequence> + </xs:complexType> + <xs:complexType name="VectoOutputDataType"> + <xs:sequence> + <xs:element name="Vehicle" type="VehicleType"/> + <xs:element name="Results"> + <xs:complexType> + <xs:sequence> + <xs:element name="Status"> + <xs:simpleType> + <xs:restriction base="xs:string"> + <xs:enumeration value="success"/> + <xs:enumeration value="error"/> + </xs:restriction> + </xs:simpleType> + </xs:element> + <xs:element name="Result" type="ResultType" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="ApplicationInformation"> + <xs:complexType> + <xs:sequence> + <xs:element name="SimulationToolVersion"/> + <xs:element name="Date"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:sequence> + <xs:attribute name="id" use="required"/> + </xs:complexType> + <xs:complexType name="VehiclePerformanceType"> + <xs:sequence> + <xs:element name="AverageSpeed"> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:double"> + <xs:attribute name="unit" type="SpeedUnitType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="MinSpeed"> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:double"> + <xs:attribute name="unit" type="SpeedUnitType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="MaxSpeed"> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:double"> + <xs:attribute name="unit" type="SpeedUnitType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="MaxDeceleration"> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:double"> + <xs:attribute name="unit" type="AccelerationUnitType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="MaxAcceleration"> + <xs:complexType> + <xs:simpleContent> + <xs:extension base="xs:double"> + <xs:attribute name="unit" type="AccelerationUnitType" use="required"/> + </xs:extension> + </xs:simpleContent> + </xs:complexType> + </xs:element> + <xs:element name="FullLoadDrivingtimePercentage"> + <xs:simpleType> + <xs:restriction base="xs:double"> + <xs:minInclusive value="0"/> + <xs:maxInclusive value="100"/> + </xs:restriction> + </xs:simpleType> + </xs:element> + <xs:element name="GearshiftCount" type="xs:int"/> + </xs:sequence> + </xs:complexType> + <xs:complexType name="VehicleType"> + <xs:sequence> + <xs:element name="VIN"> + <xs:annotation> + <xs:documentation>P238</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="LegislativeClass" type="vdecdef:LegislativeClassDeclarationType"> + <xs:annotation> + <xs:documentation>P251</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="VehicleGroup" type="VehicleGroupType"> + <xs:annotation> + <xs:documentation>VECTO</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="AxleConfiguration" type="vdecdef:VehicleAxleConfigurationDeclarationType"> + <xs:annotation> + <xs:documentation>P037</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="GrossVehicleMass" type="vdecdef:VehicleGrossVehicleMassType"> + <xs:annotation> + <xs:documentation>P041</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="CurbMassChassis" type="vdecdef:VehicleCurbMassChassisType"> + <xs:annotation> + <xs:documentation>P038</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="PTO" type="xs:boolean"> + <xs:annotation> + <xs:documentation>P247</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="TorqueLimits" type="TorqueLimitsType" minOccurs="0"/> + <xs:element name="Components"> + <xs:complexType> + <xs:sequence> + <xs:element name="Engine" type="EngineType"/> + <xs:element name="Gearbox" type="GearboxType"/> + <xs:element name="Torqueconverter" type="TorqueconverterType" minOccurs="0"/> + <xs:element name="Retarder" type="RetarderType"/> + <xs:element name="Angledrive" type="AngledriveType" minOccurs="0"/> + <xs:element name="Axlegear" type="AxlegearType"/> + <xs:element name="AirDrag" type="AirdragType"/> + <xs:element name="AxleWheels" type="AxleWheelsType"/> + <xs:element name="Auxiliaries" type="AuxiliariesType"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="InputDataSignature" type="vdecdef:SignatureType"/> + </xs:sequence> + </xs:complexType> + <xs:simpleType name="AccelerationUnitType"> + <xs:restriction base="xs:token"> + <xs:enumeration value="m/s²"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="AirdragCertificationOptionType"> + <xs:restriction base="xs:string"> + <xs:enumeration value="Measured"/> + <xs:enumeration value="Standard values"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="CO2UnitType"> + <xs:restriction base="xs:string"> + <xs:enumeration value="g/km"/> + <xs:enumeration value="g/t-km"/> + <xs:enumeration value="g/p-km"/> + <xs:enumeration value="g/m³-km"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="DistanceUnitType"> + <xs:restriction base="xs:token"> + <xs:enumeration value="km"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="FuelConsumptionUnitType"> + <xs:restriction base="xs:string"> + <xs:enumeration value="g/km"/> + <xs:enumeration value="g/t-km"/> + <xs:enumeration value="g/p-km"/> + <xs:enumeration value="g/m³-km"/> + <xs:enumeration value="l/100km"/> + <xs:enumeration value="l/t-km"/> + <xs:enumeration value="l/p-km"/> + <xs:enumeration value="l/m³-km"/> + <xs:enumeration value="MJ/km"/> + <xs:enumeration value="MJ/t-km"/> + <xs:enumeration value="MJ/m³-km"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="MassUnitType"> + <xs:restriction base="xs:token"> + <xs:enumeration value="kg"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="MissionTypeType"> + <xs:restriction base="xs:token"> + <xs:enumeration value="Long Haul EMS"/> + <xs:enumeration value="Long Haul"/> + <xs:enumeration value="Regional Delivery EMS"/> + <xs:enumeration value="Regional Delivery"/> + <xs:enumeration value="Urban Delivery"/> + <xs:enumeration value="Municipal Utility"/> + <xs:enumeration value="Construction"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="SpeedUnitType"> + <xs:restriction base="xs:token"> + <xs:enumeration value="km/h"/> + </xs:restriction> + </xs:simpleType> + <xs:simpleType name="VehicleGroupType"> + <xs:restriction base="xs:int"> + <xs:minInclusive value="1"/> + <xs:maxInclusive value="16"/> + </xs:restriction> + </xs:simpleType> +</xs:schema> diff --git a/VectoCore/VectoCore/Utils/XMLValidator.cs b/VectoCore/VectoCore/Utils/XMLValidator.cs new file mode 100644 index 0000000000..dea07d031e --- /dev/null +++ b/VectoCore/VectoCore/Utils/XMLValidator.cs @@ -0,0 +1,148 @@ +/* +* This file is part of VECTO. +* +* Copyright © 2012-2017 European Union +* +* Developed by Graz University of Technology, +* Institute of Internal Combustion Engines and Thermodynamics, +* Institute of Technical Informatics +* +* VECTO is licensed under the EUPL, Version 1.1 or - as soon they will be approved +* by the European Commission - subsequent versions of the EUPL (the "Licence"); +* You may not use VECTO except in compliance with the Licence. +* You may obtain a copy of the Licence at: +* +* https://joinup.ec.europa.eu/community/eupl/og_page/eupl +* +* Unless required by applicable law or agreed to in writing, VECTO +* distributed under the Licence is distributed on an "AS IS" basis, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the Licence for the specific language governing permissions and +* limitations under the Licence. +* +* Authors: +* Stefan Hausberger, hausberger@ivt.tugraz.at, IVT, Graz University of Technology +* Christian Kreiner, christian.kreiner@tugraz.at, ITI, Graz University of Technology +* Michael Krisper, michael.krisper@tugraz.at, ITI, Graz University of Technology +* Raphael Luz, luz@ivt.tugraz.at, IVT, Graz University of Technology +* Markus Quaritsch, markus.quaritsch@tugraz.at, IVT, Graz University of Technology +* Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology +*/ + +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using System.Xml; +using System.Xml.Schema; +using TUGraz.VectoCommon.Utils; + +namespace TUGraz.VectoCore.Utils +{ + public class XMLValidator + { + private readonly Action<XmlSeverityType, ValidationEvent> _validationErrorAction; + private readonly Action<bool> _resultAction; + private bool _valid; + private readonly XmlDocument _doc; + + private static Dictionary<XmlDocumentType, string> schemaFilenames = new Dictionary<XmlDocumentType, string>() { + {XmlDocumentType.DeclarationJobData, "VectoInput{0}.xsd" }, + {XmlDocumentType.DeclarationComponentData, "VectoComponent{0}.xsd" }, + {XmlDocumentType.EngineeringData, "VectoEngineeringInput{0}.xsd" }, + {XmlDocumentType.ManufacturerReport, "VectoOutputManufacturer{0}.xsd" }, + { XmlDocumentType.CustomerReport , "VectoOutputCustomer{0}.xsd"}, + }; + + private XMLValidator(Action<bool> resultaction, Action<XmlSeverityType, ValidationEvent> validationErrorAction) + { + _validationErrorAction = validationErrorAction ?? ((x, y) => { }); + _resultAction = resultaction ?? (x => { }); + _valid = false; + } + + public XMLValidator(XmlReader document, Action<bool> resultaction = null, Action<XmlSeverityType, ValidationEvent> validationErrorAction = null):this(resultaction,validationErrorAction) + { + _doc = new XmlDocument(); + _doc.Load(document); + } + + public XMLValidator(XmlDocument document, Action<bool> resultaction = null, Action<XmlSeverityType, ValidationEvent> validationErrorAction = null) : this(resultaction, validationErrorAction) + { + _doc = document; + } + + public bool ValidateXML(XmlDocumentType docType) + { + _valid = true; + //try { + if (_doc.DocumentElement == null) { + throw new Exception("empty XML document"); + } + var version = _doc.DocumentElement.GetAttribute("schemaVersion"); + _doc.Schemas = GetXMLSchema(docType, version); + _doc.Validate(ValidationCallBack); + //} catch (Exception e) { + // _valid = false; + // _validationErrorAction(XmlSeverityType.Error, new ValidationEvent() { + + // Exception = e + // }); + //} + return _valid; + } + + private void ValidationCallBack(object sender, ValidationEventArgs args) + { + _resultAction(false); + _valid = false; + _validationErrorAction(args.Severity, new ValidationEvent { ValidationEventArgs = args }); + } + + private static XmlSchemaSet GetXMLSchema(XmlDocumentType docType, string version) + { + var xset = new XmlSchemaSet() { XmlResolver = new XmlResourceResolver() }; + + foreach (var entry in EnumHelper.GetValues<XmlDocumentType>()) { + if ((entry & docType) == 0) { + continue; + } + Stream resource; + var schemaFile = GetSchemaFilename(entry, string.IsNullOrWhiteSpace(version) ? "" : "."+ version); + try { + resource= RessourceHelper.LoadResourceAsStream(RessourceHelper.ResourceType.XMLSchema, schemaFile); + } catch (Exception e) { + throw new Exception(string.Format("Unknown XML schema! version: {0}, xml document type: {1} ({2})", entry, version, schemaFile), e); + } + var reader = XmlReader.Create(resource, new XmlReaderSettings(), "schema://"); + xset.Add(XmlSchema.Read(reader, null)); + } + xset.Compile(); + return xset; + } + + public static string GetSchemaFilename(XmlDocumentType type, string version) + { + if (!schemaFilenames.ContainsKey(type)) { + throw new Exception(string.Format("Invalid argument {0} - only use single flags", type)); + } + return string.Format(schemaFilenames[type], version); + } + + [Flags] + public enum XmlDocumentType + { + DeclarationJobData = 1<<1, + DeclarationComponentData = 1<<3, + EngineeringData = 1<<4, + ManufacturerReport = 1<<5, + CustomerReport = 1<<6, + } + } + + public class ValidationEvent + { + public Exception Exception; + public ValidationEventArgs ValidationEventArgs; + } +} diff --git a/VectoCore/VectoCore/VectoCore.csproj b/VectoCore/VectoCore/VectoCore.csproj index 688a3f6ed0..c34c5b71c3 100644 --- a/VectoCore/VectoCore/VectoCore.csproj +++ b/VectoCore/VectoCore/VectoCore.csproj @@ -340,6 +340,7 @@ <DependentUpon>VectoVersionCore.tt</DependentUpon> </Compile> <Compile Include="Utils\XmlResourceResolver.cs" /> + <Compile Include="Utils\XMLValidator.cs" /> <Compile Include="Utils\XPathHelper.cs" /> </ItemGroup> <ItemGroup> @@ -426,6 +427,21 @@ <EmbeddedResource Include="Resources\XSD\VectoOutputCustomer.xsd"> <SubType>Designer</SubType> </EmbeddedResource> + <EmbeddedResource Include="Resources\XSD\VectoInput.1.0.xsd"> + <SubType>Designer</SubType> + </EmbeddedResource> + <EmbeddedResource Include="Resources\XSD\VectoOutputCustomer.0.4.xsd"> + <SubType>Designer</SubType> + </EmbeddedResource> + <EmbeddedResource Include="Resources\XSD\VectoOutputManufacturer.0.4.xsd"> + <SubType>Designer</SubType> + </EmbeddedResource> + <EmbeddedResource Include="Resources\XSD\VectoEngineeringInput.0.7.xsd"> + <SubType>Designer</SubType> + </EmbeddedResource> + <EmbeddedResource Include="Resources\XSD\VectoComponent.1.0.xsd"> + <SubType>Designer</SubType> + </EmbeddedResource> <None Include="Utils\VectoVersionCore.tt"> <Generator>TextTemplatingFileGenerator</Generator> <LastGenOutput>VectoVersionCore.cs</LastGenOutput> diff --git a/VectoCore/VectoCoreTest/TestData/Integration/DeclarationMode/Class5_Tractor_4x2_TopTorque/Class5_Tractor_topTorque.vveh b/VectoCore/VectoCoreTest/TestData/Integration/DeclarationMode/Class5_Tractor_4x2_TopTorque/Class5_Tractor_topTorque.vveh index 9ba3943c0f..068a03771d 100644 --- a/VectoCore/VectoCoreTest/TestData/Integration/DeclarationMode/Class5_Tractor_4x2_TopTorque/Class5_Tractor_topTorque.vveh +++ b/VectoCore/VectoCoreTest/TestData/Integration/DeclarationMode/Class5_Tractor_4x2_TopTorque/Class5_Tractor_topTorque.vveh @@ -42,7 +42,7 @@ "8": 1950, "9": 1950, "10": 1950, - "11": 1950, + "11": 1950 }, "AxleConfig": { "Type": "4x2", diff --git a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_axlegear-sample_ref.xml b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_axlegear-sample_ref.xml index 0bf25d2503..0abb244641 100644 --- a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_axlegear-sample_ref.xml +++ b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_axlegear-sample_ref.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<tns:VectoComponentEngineering xmlns="urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.7" xmlns:tns="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.6" schemaVersion="0.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7 ../XSD/VectoEngineeringInput.xsd"> +<tns:VectoComponentEngineering xmlns="urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.7" xmlns:tns="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.6" schemaVersion="0.7" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7 ../XSD/VectoEngineeringInput.xsd"> <Axlegear> <Data id="AXL-EC3ohnoh"> <Manufacturer>Generic Gearbox Vendor</Manufacturer> diff --git a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_engine-sample_ref.xml b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_engine-sample_ref.xml index 6bf427cdf2..42959f54f4 100644 --- a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_engine-sample_ref.xml +++ b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_engine-sample_ref.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<tns:VectoComponentEngineering xmlns="urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.7" xmlns:tns="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.6" schemaVersion="0.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7 ../XSD/VectoEngineeringInput.xsd"> +<tns:VectoComponentEngineering xmlns="urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.7" xmlns:tns="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.6" schemaVersion="0.7" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7 ../XSD/VectoEngineeringInput.xsd"> <Engine> <Data id="ENG-gooZah3D"> <Manufacturer>Generic Engine Vendor</Manufacturer> diff --git a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_gearbox-sample_ref.xml b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_gearbox-sample_ref.xml index 8f15d664a9..219327ca0e 100644 --- a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_gearbox-sample_ref.xml +++ b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_gearbox-sample_ref.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<tns:VectoComponentEngineering xmlns="urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.7" xmlns:tns="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.6" schemaVersion="0.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7 ../XSD/VectoEngineeringInput.xsd"> +<tns:VectoComponentEngineering xmlns="urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.7" xmlns:tns="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.6" schemaVersion="0.7" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7 ../XSD/VectoEngineeringInput.xsd"> <Gearbox> <Data id="gbx-vi2Oak2N"> <Manufacturer>Generic Gearbox Vendor</Manufacturer> diff --git a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_job-engine_only-sample_ref.xml b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_job-engine_only-sample_ref.xml index db94838987..44644a3f72 100644 --- a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_job-engine_only-sample_ref.xml +++ b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_job-engine_only-sample_ref.xml @@ -2,7 +2,7 @@ <tns:VectoInputEngineering xmlns="urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.7" xmlns:tns="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7" - xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.6" schemaVersion="0.6" + xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.6" schemaVersion="0.7" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7 ../XSD/VectoEngineeringInput.xsd"> <EngineOnlyMode>false</EngineOnlyMode> diff --git a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_job-sample.xml b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_job-sample.xml index ceb0cf63ff..d3c33d3f41 100644 --- a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_job-sample.xml +++ b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_job-sample.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<tns:VectoInputEngineering xmlns="urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.7" xmlns:tns="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.6" schemaVersion="0.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7 ../XSD/VectoEngineeringInput.xsd"> +<tns:VectoInputEngineering xmlns="urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.7" xmlns:tns="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.6" schemaVersion="0.7" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7 ../XSD/VectoEngineeringInput.xsd"> <EngineOnlyMode>false</EngineOnlyMode> <Vehicle id="VEH-1234567890"> <Manufacturer>Generic Truck Manufacturer</Manufacturer> diff --git a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_job-sample_FULL.xml b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_job-sample_FULL.xml index 7e6407b19d..79c860cf53 100644 --- a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_job-sample_FULL.xml +++ b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_job-sample_FULL.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<tns:VectoInputEngineering xmlns="urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.7" xmlns:tns="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.8" schemaVersion="0.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7 ../XSD/VectoEngineeringInput.xsd"> +<tns:VectoInputEngineering xmlns="urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.7" xmlns:tns="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.8" schemaVersion="0.7" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7 ../XSD/VectoEngineeringInput.xsd"> <EngineOnlyMode>false</EngineOnlyMode> <Vehicle id="VEH-1234567890"> <Manufacturer>Generic Truck Manufacturer</Manufacturer> diff --git a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_job-sample_ref.xml b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_job-sample_ref.xml index bf13d0edd9..9d7de168f8 100644 --- a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_job-sample_ref.xml +++ b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_job-sample_ref.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<tns:VectoInputEngineering xmlns="urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.7" xmlns:tns="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.6" schemaVersion="0.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7 ../XSD/VectoEngineeringInput.xsd"> +<tns:VectoInputEngineering xmlns="urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.7" xmlns:tns="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.6" schemaVersion="0.7" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7 ../XSD/VectoEngineeringInput.xsd"> <EngineOnlyMode>false</EngineOnlyMode> <Resource type="xml" component="Vehicle" file="engineering_vehicle_ref.xml"/> <Signature> diff --git a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_retarder-sample_ref.xml b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_retarder-sample_ref.xml index c002b38bc2..e3eb7f44fd 100644 --- a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_retarder-sample_ref.xml +++ b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_retarder-sample_ref.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<tns:VectoComponentEngineering xmlns="urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.7" xmlns:tns="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.6" schemaVersion="0.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7 ../XSD/VectoEngineeringInput.xsd"> +<tns:VectoComponentEngineering xmlns="urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.7" xmlns:tns="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.6" schemaVersion="0.7" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7 ../XSD/VectoEngineeringInput.xsd"> <Retarder> <Data id="RET-Shai9imi"> <Manufacturer>Generic Retarder Vendor</Manufacturer> diff --git a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_vehicle_ref.xml b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_vehicle_ref.xml index b7453290a9..6b9257ba18 100644 --- a/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_vehicle_ref.xml +++ b/VectoCore/VectoCoreTest/TestData/XML/XMLReaderEngineering/engineering_vehicle_ref.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<tns:VectoComponentEngineering xmlns="urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.7" xmlns:tns="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.6" schemaVersion="0.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7 ../XSD/VectoEngineeringInput.xsd"> +<tns:VectoComponentEngineering xmlns="urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.7" xmlns:tns="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7" xmlns:vdecdef="urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:v0.6" schemaVersion="0.7" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.7 ../XSD/VectoEngineeringInput.xsd"> <Vehicle id="VEH-1234567890"> <Manufacturer>Generic Truck Manufacturer</Manufacturer> <Model>Generic LongHaul Truck</Model> diff --git a/VectoCore/VectoCoreTest/XML/XMLReportTest.cs b/VectoCore/VectoCoreTest/XML/XMLReportTest.cs index 3273e35fb4..1c3e85a08d 100644 --- a/VectoCore/VectoCoreTest/XML/XMLReportTest.cs +++ b/VectoCore/VectoCoreTest/XML/XMLReportTest.cs @@ -73,44 +73,11 @@ namespace TUGraz.VectoCore.Tests.XML var customerRecord = fileWriter.XMLCustomerReportName; var manufacturerRecord = fileWriter.XMLFullReportName; - Assert.IsTrue(DoValidation(XmlReader.Create(customerRecord))); - Assert.IsTrue(DoValidation(XmlReader.Create(manufacturerRecord))); - } - - private bool DoValidation(XmlReader hashedComponent) - { - var settings = new XmlReaderSettings { - ValidationType = ValidationType.Schema, - ValidationFlags = //XmlSchemaValidationFlags.ProcessInlineSchema | - //XmlSchemaValidationFlags.ProcessSchemaLocation | - XmlSchemaValidationFlags.ReportValidationWarnings - }; - //settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack); - settings.Schemas.Add(GetXMLSchema("")); - - var vreader = XmlReader.Create(hashedComponent, settings); - var doc = new XmlDocument(); - doc.Load(vreader); - doc.Validate(ValidationCallBack); - return true; - } - - private void ValidationCallBack(object sender, ValidationEventArgs args) - { - throw new Exception("Validation failed"); - } - - private static XmlSchemaSet GetXMLSchema(string version) - { - var xset = new XmlSchemaSet() { XmlResolver = new XmlResourceResolver() }; - foreach (var schema in new[] { "VectoComponent.xsd", "VectoInput.xsd", "VectoOutputManufacturer.xsd", "VectoOutputCustomer.xsd" }) { - var resource = RessourceHelper.LoadResourceAsStream(RessourceHelper.ResourceType.XMLSchema, schema); + var validator1 = new XMLValidator(XmlReader.Create(customerRecord)); + Assert.IsTrue(validator1.ValidateXML(XMLValidator.XmlDocumentType.CustomerReport)); - var reader = XmlReader.Create(resource, new XmlReaderSettings(), "schema://"); - xset.Add(XmlSchema.Read(reader, null)); - } - xset.Compile(); - return xset; + var validator2 = new XMLValidator(XmlReader.Create(manufacturerRecord)); + Assert.IsTrue(validator2.ValidateXML(XMLValidator.XmlDocumentType.ManufacturerReport)); } } } \ No newline at end of file -- GitLab