Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 271bd9f1 authored by Harald MARTINI's avatar Harald MARTINI
Browse files

Updated XMLWriters to use the new GroupWriters

parent 944f51be
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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,
......
......@@ -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>
......
......@@ -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
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~")
......
......@@ -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();
}
......
......@@ -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)
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment