From 271bd9f18e6397c835367425ab678983390d0d10 Mon Sep 17 00:00:00 2001 From: "harald.martini@student.tugraz.at" <harald.martini@student.tugraz.at> Date: Thu, 19 Aug 2021 18:15:32 +0200 Subject: [PATCH] Updated XMLWriters to use the new GroupWriters --- VECTO3GUI2020/Helper/XmlHelper.cs | 4 +- .../Ninject/XMLWriterFactoryModule.cs | 4 +- .../Properties/GUILabels.Designer.cs | 9 ++ VECTO3GUI2020/Properties/GUILabels.resx | 3 + .../XMLBusAuxiliariesWriter.cs | 49 ++++++- .../ComponentWriter/XMLVehicleWriter.cs | 130 ++++++++++++++++-- VECTO3GUI2020/Util/XML/XMLNamespaces.cs | 6 +- .../Implementation/StageViewModelBase.cs | 4 +- 8 files changed, 183 insertions(+), 26 deletions(-) diff --git a/VECTO3GUI2020/Helper/XmlHelper.cs b/VECTO3GUI2020/Helper/XmlHelper.cs index 2db50eed49..872ad97935 100644 --- a/VECTO3GUI2020/Helper/XmlHelper.cs +++ b/VECTO3GUI2020/Helper/XmlHelper.cs @@ -64,7 +64,7 @@ namespace VECTO3GUI2020.Helper } public static XDocument CreateWrapperDocument(this XElement xElement, XNamespace defaultNamespace, - XmlDocumentType docType = XmlDocumentType.DeclarationJobData) + XmlDocumentType docType = XmlDocumentType.DeclarationJobData, string schemaVersion = "2.0") { var prefixMap = new Dictionary<string, XNamespace>(); @@ -74,7 +74,7 @@ namespace VECTO3GUI2020.Helper Debug.WriteLine(rootElement.ToString()); rootElement.Add(new XAttribute("xmlns", defaultNamespace)); - rootElement.Add(new XAttribute("schemaVersion", XMLHelper.GetVersionFromNamespaceUri(defaultNamespace))); + rootElement.Add(new XAttribute("schemaVersion", schemaVersion)); xDocument.Add(rootElement); diff --git a/VECTO3GUI2020/Ninject/XMLWriterFactoryModule.cs b/VECTO3GUI2020/Ninject/XMLWriterFactoryModule.cs index 9c9912f5a1..ed0a9a0e03 100644 --- a/VECTO3GUI2020/Ninject/XMLWriterFactoryModule.cs +++ b/VECTO3GUI2020/Ninject/XMLWriterFactoryModule.cs @@ -45,9 +45,9 @@ namespace VECTO3GUI2020.Ninject Bind<IXMLVehicleWriter>().To<XMLVehicleWriter_v2_0>().Named(sv)); Array.ForEach( - XMLVehicleWriter_v2_8.SUPPORTEDVERSIONS, + XMLVehicleWriter_v2_10.SUPPORTEDVERSIONS, sv => - Bind<IXMLVehicleWriter>().To<XMLVehicleWriter_v2_8>().Named(sv)); + Bind<IXMLVehicleWriter>().To<XMLVehicleWriter_v2_10>().Named(sv)); Array.ForEach( XMLComponentsWriter_v1_0.SUPPORTED_VERSIONS, diff --git a/VECTO3GUI2020/Properties/GUILabels.Designer.cs b/VECTO3GUI2020/Properties/GUILabels.Designer.cs index 265621a826..2566813125 100644 --- a/VECTO3GUI2020/Properties/GUILabels.Designer.cs +++ b/VECTO3GUI2020/Properties/GUILabels.Designer.cs @@ -114,6 +114,15 @@ namespace VECTO3GUI2020.Properties { } } + /// <summary> + /// Looks up a localized string similar to Components_Conventional_CompletedBusType. + /// </summary> + public static string Components_Conventional_CompletedBusType { + get { + return ResourceManager.GetString("Components_Conventional_CompletedBusType", resourceCulture); + } + } + /// <summary> /// Looks up a localized string similar to VECTO. /// </summary> diff --git a/VECTO3GUI2020/Properties/GUILabels.resx b/VECTO3GUI2020/Properties/GUILabels.resx index 81f893a3dc..1d9a9b8a37 100644 --- a/VECTO3GUI2020/Properties/GUILabels.resx +++ b/VECTO3GUI2020/Properties/GUILabels.resx @@ -156,4 +156,7 @@ <data name="_consolidateElectricConsumerData" xml:space="preserve"> <value>Electric Consumer Data</value> </data> + <data name="Components_Conventional_CompletedBusType" xml:space="preserve"> + <value>Components_Conventional_CompletedBusType</value> + </data> </root> \ No newline at end of file diff --git a/VECTO3GUI2020/Util/XML/Implementation/ComponentWriter/XMLBusAuxiliariesWriter.cs b/VECTO3GUI2020/Util/XML/Implementation/ComponentWriter/XMLBusAuxiliariesWriter.cs index aa35657f62..e60a7c01bc 100644 --- a/VECTO3GUI2020/Util/XML/Implementation/ComponentWriter/XMLBusAuxiliariesWriter.cs +++ b/VECTO3GUI2020/Util/XML/Implementation/ComponentWriter/XMLBusAuxiliariesWriter.cs @@ -1,10 +1,12 @@ using System; using System.Linq; using System.Xml.Linq; +using Castle.Components.DictionaryAdapter.Xml; using Castle.Core.Internal; using TUGraz.VectoCommon.BusAuxiliaries; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Resources; +using TUGraz.VectoCore.OutputData.XML.GroupWriter; using VECTO3GUI2020.Util.XML.Interfaces; namespace VECTO3GUI2020.Util.XML.Implementation.ComponentWriter @@ -52,20 +54,29 @@ namespace VECTO3GUI2020.Util.XML.Implementation.ComponentWriter private XNamespace _defaultNamespace; - public XMLBusAuxiliariesWriterMultistage(IBusAuxiliariesDeclarationData inputData) : base(inputData) { } + private readonly IGroupWriterFactory _groupWriterFactory; + + public XMLBusAuxiliariesWriterMultistage(IBusAuxiliariesDeclarationData inputData, + IGroupWriterFactory groupWriterFactory) : base(inputData) + { + _groupWriterFactory = groupWriterFactory; + } #region Overrides of XMLBusAuxiliariesWriter public override void Initialize() { - _defaultNamespace = XMLNamespaces.v210; + _defaultNamespace = XMLNamespaces.v2_10_2; _xElement = new XElement(_defaultNamespace + XMLNames.Component_Auxiliaries); } public override void CreateElements() { - - var dataElement = new XElement(_defaultNamespace + XMLNames.ComponentDataWrapper, + CreateElementsWithGroupWriters(); + return; + + + var dataElement = new XElement(_defaultNamespace + XMLNames.ComponentDataWrapper, new XAttribute(XMLNamespaces.Xsi + XMLNames.Attr_Type, "CompletedVehicleAuxiliaryDataDeclarationType")); _xElement.Add(dataElement); @@ -114,6 +125,36 @@ namespace VECTO3GUI2020.Util.XML.Implementation.ComponentWriter dataElement.DescendantsAndSelf().Where(e => e.Value.IsNullOrEmpty()).Remove(); } + private void CreateElementsWithGroupWriters() + { + + var dataElement = new XElement(_defaultNamespace + XMLNames.ComponentDataWrapper, + new XAttribute("xmlns" , XMLNamespaces.v2_10_2), + new XAttribute(XMLNamespaces.Xsi + XMLNames.Attr_Type, "AUX_Conventional_CompletedBusType")); + + if (_inputData.ElectricConsumers != null) { + var electricSystemElement = new XElement(_defaultNamespace + XMLNames.BusAux_ElectricSystem); + var ledLightsElement = new XElement(_defaultNamespace + "LEDLights"); + ledLightsElement.Add( + // ReSharper disable once CoVariantArrayConversion + _groupWriterFactory.GetBusAuxiliariesDeclarationGroupWriter(GroupNames.BusAuxElectricSystemLightsGroup, _defaultNamespace) + .GetGroupElements(_inputData)); + electricSystemElement.Add(ledLightsElement); + dataElement.Add(electricSystemElement); + + } + + if (_inputData.HVACAux != null) { + var hvacElement = new XElement(_defaultNamespace + "HVAC"); + hvacElement.Add(_groupWriterFactory.GetBusAuxiliariesDeclarationGroupWriter(GroupNames.BusAuxHVACConventionalSequenceGroup, _defaultNamespace) + .GetGroupElements(_inputData)); + dataElement.Add(hvacElement); + } + + _xElement.Add(dataElement); + + } + private XElement GetHeatPumpTypeElement(string xmlName, string value) { if (value == "~null~") diff --git a/VECTO3GUI2020/Util/XML/Implementation/ComponentWriter/XMLVehicleWriter.cs b/VECTO3GUI2020/Util/XML/Implementation/ComponentWriter/XMLVehicleWriter.cs index 33f0d0cae0..58b66f6a99 100644 --- a/VECTO3GUI2020/Util/XML/Implementation/ComponentWriter/XMLVehicleWriter.cs +++ b/VECTO3GUI2020/Util/XML/Implementation/ComponentWriter/XMLVehicleWriter.cs @@ -9,7 +9,11 @@ using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Resources; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider; +using TUGraz.VectoCore.OutputData.XML.ComponentWriter; +using TUGraz.VectoCore.OutputData.XML.GroupWriter; +using TUGraz.VectoCore.Utils; using VECTO3GUI2020.Helper; +using VECTO3GUI2020.Properties; using VECTO3GUI2020.Util.XML.Interfaces; using VECTO3GUI2020.ViewModel.Implementation.JobEdit.Vehicle; using VECTO3GUI2020.ViewModel.Interfaces.JobEdit.Vehicle; @@ -118,7 +122,8 @@ namespace VECTO3GUI2020.Util.XML.Implementation.ComponentWriter typeof(VehicleViewModel_v2_0).ToString() }; - public XMLVehicleWriter_v2_0(IVehicleDeclarationInputData inputData, IXMLWriterFactory xmlWriterFactory) : base(inputData, xmlWriterFactory) + public XMLVehicleWriter_v2_0(IVehicleDeclarationInputData inputData, + IXMLWriterFactory xmlWriterFactory) : base(inputData, xmlWriterFactory) { @@ -187,37 +192,58 @@ namespace VECTO3GUI2020.Util.XML.Implementation.ComponentWriter public class XMLVehicleWriter_ExcemptedVehicle_v2_2 { } - public class XMLVehicleWriter_v2_8 : XMLVehicleWriter + public class XMLVehicleWriter_v2_10 : XMLVehicleWriter { private readonly bool _exempted; public static readonly string[] SUPPORTEDVERSIONS = { - typeof(InterimStageBusVehicleViewModel_v2_8).ToString() + typeof(InterimStageBusVehicleViewModel_v2_8).ToString(), + typeof(StageInputViewModel).ToString() }; - public XMLVehicleWriter_v2_8(IVehicleDeclarationInputData inputData, IXMLWriterFactory xmlWriterFactory) : base(inputData, xmlWriterFactory) + + private readonly IGroupWriterFactory _groupWriterFactory; + private readonly bool _conventional; + private readonly IComponentWriterFactory _componentWriterFactory; + + public XMLVehicleWriter_v2_10(IVehicleDeclarationInputData inputData, + IXMLWriterFactory xmlWriterFactory, + IGroupWriterFactory groupWriterFactory, + IComponentWriterFactory componentWriterFactory) : base(inputData, xmlWriterFactory) { + + //TODO: CHECK ALL POSSIBIBILITIES FOR VEHICLES _exempted = inputData.ExemptedVehicle; + _conventional = !_exempted; + _groupWriterFactory = groupWriterFactory; + _componentWriterFactory = componentWriterFactory; } #region Overrides of XMLVehicleWriter protected override void Initialize() { - _defaultNamespace = XMLNamespaces.V28; + _defaultNamespace = XMLNamespaces.v2_10_2; - _Xelement = new XElement(XMLNamespaces.V20 + XMLNames.Component_Vehicle); + _Xelement = new XElement(XMLNamespaces.V20 + XMLNames.Component_Vehicle, + new XAttribute("xmlns", _defaultNamespace)); _Xelement.Add(new XAttribute(XMLNames.Component_ID_Attr, _inputData.Identifier ?? ("VEH-" + Guid.NewGuid().ToString("n").Substring(0, 20)))); - if (_exempted) { - _Xelement.Add(new XAttribute(XMLNamespaces.Xsi + XMLNames.Attr_Type, "ExemptedInterimStageInputType")); + if (_conventional) { + _Xelement.Add(new XAttribute(XMLNamespaces.Xsi + XMLNames.Attr_Type, "Vehicle_Conventional_CompletedBusDeclarationType")); } else { - _Xelement.Add(new XAttribute(XMLNamespaces.Xsi + XMLNames.Attr_Type, "InterimStageInputType")); + throw new NotImplementedException(); + //_Xelement.Add(new XAttribute(XMLNamespaces.Xsi + XMLNames.Attr_Type, "InterimStageInputType")); } } protected override void CreateElements() { + if (_conventional) { + CreateConventionalElements(); + return; + } + if (_exempted) { CreateExemptedElements(); return; @@ -227,7 +253,7 @@ namespace VECTO3GUI2020.Util.XML.Implementation.ComponentWriter _inputData.ManufacturerAddress)); _Xelement.Add(new XElement(_defaultNamespace + XMLNames.Vehicle_VIN, _inputData.VIN)); - _Xelement.Add(new XElement(_defaultNamespace + XMLNames.Component_Date, DateTime.Today.ToXmlFormat())); + _Xelement.Add(new XElement(_defaultNamespace + XMLNames.Component_Date, XMLExtension.ToXmlFormat(DateTime.Today))); _Xelement.Add(new XElement(_defaultNamespace + XMLNames.Component_Model, _inputData.Model)); _Xelement.Add(new XElement(_defaultNamespace + XMLNames.Vehicle_LegislativeCategory, _inputData.LegislativeClass.ToXMLFormat())); @@ -247,7 +273,7 @@ namespace VECTO3GUI2020.Util.XML.Implementation.ComponentWriter _Xelement.Add(new XElement(_defaultNamespace + XMLNames.Bus_LowEntry, _inputData.LowEntry)); - _Xelement.Add(new XElement(_defaultNamespace + XMLNames.Bus_HeighIntegratedBody, _inputData.Height?.ConvertToMilliMeter())); + _Xelement.Add(new XElement(_defaultNamespace + XMLNames.Bus_HeightIntegratedBody, _inputData.Height?.ConvertToMilliMeter())); _Xelement.Add(new XElement(_defaultNamespace + XMLNames.Bus_VehicleLength, _inputData.Length?.ConvertToMilliMeter())); _Xelement.Add(new XElement(_defaultNamespace + XMLNames.Bus_VehicleWidth, _inputData.Width?.ConvertToMilliMeter())); @@ -301,14 +327,90 @@ namespace VECTO3GUI2020.Util.XML.Implementation.ComponentWriter componentElement.Add(auxiliaryElement); } + _Xelement.Add(componentElement); + + } + } + + private void CreateConventionalElements() + { + _Xelement.Add( + _groupWriterFactory.GetVehicleDeclarationGroupWriter( + GroupNames.Vehicle_CompletedBus_GeneralParametersSequenceGroup, _defaultNamespace).GetGroupElements(_inputData), + _groupWriterFactory.GetVehicleDeclarationGroupWriter( + GroupNames.Vehicle_CompletedBusParametersSequenceGroup, _defaultNamespace).GetGroupElements(_inputData) + ); + _Xelement.AddIfContentNotNull(new XElement(_defaultNamespace + XMLNames.Vehicle_NgTankSystem, _inputData.TankSystem)); + + if (_inputData.NumberPassengerSeatsUpperDeck != null && + _inputData.NumberPassengerSeatsLowerDeck != null && + _inputData.NumberPassengersStandingUpperDeck != null && + _inputData.NumberPassengersStandingLowerDeck != null) + { + // ReSharper disable once CoVariantArrayConversion + _Xelement.Add(_groupWriterFactory.GetVehicleDeclarationGroupWriter( + GroupNames.Vehicle_CompletedBus_PassengerCountSequenceGroup, _defaultNamespace).GetGroupElements(_inputData)); + } + + _Xelement.AddIfContentNotNull(new XElement(_defaultNamespace + XMLNames.Vehicle_BodyworkCode, _inputData.VehicleCode.ToXMLFormat())); + _Xelement.AddIfContentNotNull(new XElement(_defaultNamespace + XMLNames.Bus_LowEntry, _inputData.LowEntry)); + + if (_inputData.Height != null && + _inputData.Length != null && + _inputData.Width != null && + _inputData.EntranceHeight != null) { + // ReSharper disable once CoVariantArrayConversion + _Xelement.Add(_groupWriterFactory.GetVehicleDeclarationGroupWriter( + GroupNames.Vehicle_CompletedBus_DimensionsSequenceGroup, _defaultNamespace) + .GetGroupElements(_inputData)); + } + + _Xelement.AddIfContentNotNull(new XElement(_defaultNamespace + XMLNames.BusAux_PneumaticSystem_DoorDriveTechnology, + _inputData.DoorDriveTechnology != null + ? _inputData.DoorDriveTechnology.ToXMLFormat() + : null)); + + _Xelement.Add(new XElement(_defaultNamespace + XMLNames.Bus_VehicleDeclarationType, _inputData.VehicleDeclarationType)); + + if (_inputData.ADAS != null) { + _Xelement.Add(_componentWriterFactory.getDeclarationAdasWriter(GroupNames.ADAS_Conventional_Type, _defaultNamespace).GetComponent(_inputData.ADAS)); + } + if (_inputData.Components != null) + { + var componentElement = new XElement( + _defaultNamespace + XMLNames.Vehicle_Components, + new XAttribute(XMLNamespaces.Xsi + XMLNames.Attr_Type, + GUILabels.Components_Conventional_CompletedBusType)); + + //Airdrag + if (_inputData.Components.AirdragInputData != null) + { + var airDragElement = _xmlWriterFactory.CreateComponentWriter(_inputData.Components.AirdragInputData) + .GetElement(); + var tempAirDragElement = new XElement(_defaultNamespace + XMLNames.Component_AirDrag); + + airDragElement.Name = tempAirDragElement.Name; + componentElement.Add(airDragElement); + } + + //auxiliaries + if (_inputData.Components.BusAuxiliaries != null) + { + var auxiliaryElement = _xmlWriterFactory.CreateBuxAuxiliariesWriter(_inputData.Components.BusAuxiliaries) + .GetElement(); + + componentElement.Add(auxiliaryElement); + + } _Xelement.Add(componentElement); + } - } + private void CreateExemptedElements() { _Xelement.Add(new XElement(_defaultNamespace + XMLNames.Component_Manufacturer, _inputData.Manufacturer)); @@ -316,7 +418,7 @@ namespace VECTO3GUI2020.Util.XML.Implementation.ComponentWriter _inputData.ManufacturerAddress)); _Xelement.Add(new XElement(_defaultNamespace + XMLNames.Vehicle_VIN, _inputData.VIN)); - _Xelement.Add(new XElement(_defaultNamespace + XMLNames.Component_Date, DateTime.Today.ToXmlFormat())); + _Xelement.Add(new XElement(_defaultNamespace + XMLNames.Component_Date, XMLExtension.ToXmlFormat(DateTime.Today))); _Xelement.Add(new XElement(_defaultNamespace + XMLNames.Component_Model, _inputData.Model)); _Xelement.Add(new XElement(_defaultNamespace + XMLNames.Vehicle_LegislativeCategory, _inputData.LegislativeClass.ToXMLFormat())); @@ -336,7 +438,7 @@ namespace VECTO3GUI2020.Util.XML.Implementation.ComponentWriter _Xelement.Add(new XElement(_defaultNamespace + XMLNames.Bus_LowEntry, _inputData.LowEntry)); - _Xelement.Add(new XElement(_defaultNamespace + XMLNames.Bus_HeighIntegratedBody, _inputData.Height?.ConvertToMilliMeter())); + //_Xelement.Add(new XElement(_defaultNamespace + XMLNames.Bus_HeighIntegratedBody, _inputData.Height?.ConvertToMilliMeter())); _Xelement.DescendantsAndSelf().Where(e => e.Value.IsNullOrEmpty()).Remove(); } diff --git a/VECTO3GUI2020/Util/XML/XMLNamespaces.cs b/VECTO3GUI2020/Util/XML/XMLNamespaces.cs index e396eb3730..174d4718ae 100644 --- a/VECTO3GUI2020/Util/XML/XMLNamespaces.cs +++ b/VECTO3GUI2020/Util/XML/XMLNamespaces.cs @@ -11,7 +11,6 @@ namespace VECTO3GUI2020.Util.XML public static class XMLNamespaces { public static readonly string DeclarationDefinition = "urn:tugraz:ivt:VectoAPI:DeclarationDefinitions"; - public static readonly string SchemaVersion = "2.0"; public static XNamespace Xsi = XNamespace.Get("http://www.w3.org/2001/XMLSchema-instance"); public static XNamespace Tns = "urn:tugraz:ivt:VectoAPI:DeclarationInput"; public static XNamespace Tns_v20 = Tns.NamespaceName + ":v2.0"; @@ -21,7 +20,8 @@ namespace VECTO3GUI2020.Util.XML public static XNamespace V20 = DeclarationDefinition + ":v2.0"; public static XNamespace V10 = DeclarationDefinition + ":v1.0"; public static XNamespace V28 = DeclarationDefinition + ":DEV:v2.8"; - public static XNamespace v210 = "urn:tugraz:ivt:VectoAPI:DeclarationDefinitions:DEV:v2.10.2"; + public static XNamespace v2_10_1 = DeclarationDefinition + ":DEV:v2.10.1"; + public static XNamespace v2_10_2 = DeclarationDefinition + ":DEV:v2.10.2"; public static XNamespace Di = "http://www.w3.org/2000/09/xmldsig#"; @@ -41,6 +41,8 @@ namespace VECTO3GUI2020.Util.XML { V26, "v2.6"}, { Di, "di"}, { V28, "v2.8"}, + {v2_10_2, "v2.10.2"}, + {v2_10_1, "v2.10.1"} }; public static string GetPrefix(XNamespace xNamespace) diff --git a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageViewModelBase.cs b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageViewModelBase.cs index 622e89e146..a4284ead66 100644 --- a/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageViewModelBase.cs +++ b/VECTO3GUI2020/ViewModel/MultiStage/Implementation/StageViewModelBase.cs @@ -186,8 +186,8 @@ namespace VECTO3GUI2020.ViewModel.MultiStage.Implementation var xElement = vehicleWriter.GetElement(); - var xDoc = xElement.CreateWrapperDocument(XMLNamespaces.V28); - Debug.WriteLine(xElement.CreateWrapperDocument(XMLNamespaces.V28).ToString()); + var xDoc = xElement.CreateWrapperDocument(XMLNamespaces.v2_10_2); + Debug.WriteLine(xElement.CreateWrapperDocument(XMLNamespaces.v2_10_2).ToString()); var valid = false; -- GitLab