From fe031a7a088331060c0ceb4a70f579c095b1cd2d Mon Sep 17 00:00:00 2001
From: "VKMTHD\\franzjosefkober" <franz.josef.kober@ivt.tugraz.at>
Date: Fri, 4 Jun 2021 18:16:20 +0200
Subject: [PATCH] added hash calculation at multistage report

---
 .../VectoCommon/Hashing/VectoComponents.cs    |  1 +
 VectoCommon/VectoHashing/VectoHash.cs         |  3 ++
 .../OutputData/XML/XMLMultistageBusReport.cs  | 37 ++++++++++++++-----
 .../Multistage/MultistageVehicleTest.cs       |  5 ++-
 4 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/VectoCommon/VectoCommon/Hashing/VectoComponents.cs b/VectoCommon/VectoCommon/Hashing/VectoComponents.cs
index 35a31ccf33..11c5729b95 100644
--- a/VectoCommon/VectoCommon/Hashing/VectoComponents.cs
+++ b/VectoCommon/VectoCommon/Hashing/VectoComponents.cs
@@ -127,6 +127,7 @@ namespace TUGraz.VectoCommon.Hashing
 				case VectoComponents.VectoCustomerInformation:
 				case VectoComponents.VectoOutput:
 				case VectoComponents.VectoPrimaryVehicleInformation:
+				case VectoComponents.VectoManufacturingStage:
 					return true;
 				default:
 					return false;
diff --git a/VectoCommon/VectoHashing/VectoHash.cs b/VectoCommon/VectoHashing/VectoHash.cs
index 2a6a8d2218..f4d9e03b24 100644
--- a/VectoCommon/VectoHashing/VectoHash.cs
+++ b/VectoCommon/VectoHashing/VectoHash.cs
@@ -305,6 +305,9 @@ namespace TUGraz.VectoHashing
 			if (Document.DocumentElement.LocalName.Equals("VectoOutputPrimaryVehicle")) {
 				return VectoComponents.VectoPrimaryVehicleInformation;
 			}
+			if (Document.DocumentElement.LocalName.Equals(XMLNames.ManufacturingStage)) {
+				return VectoComponents.VectoManufacturingStage;
+			}
 			throw new Exception("unknown document structure! neither input data nor output data format");
 		}
 
diff --git a/VectoCore/VectoCore/OutputData/XML/XMLMultistageBusReport.cs b/VectoCore/VectoCore/OutputData/XML/XMLMultistageBusReport.cs
index f56be26ea5..ce6de4a380 100644
--- a/VectoCore/VectoCore/OutputData/XML/XMLMultistageBusReport.cs
+++ b/VectoCore/VectoCore/OutputData/XML/XMLMultistageBusReport.cs
@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Linq;
 using System.Security.Cryptography;
 using System.Text;
@@ -15,6 +16,7 @@ using TUGraz.VectoCommon.Utils;
 using TUGraz.VectoCore.InputData.FileIO.XML.Declaration.DataProvider;
 using TUGraz.VectoCore.Models.Simulation.Data;
 using TUGraz.VectoCore.Utils;
+using TUGraz.VectoHashing;
 
 
 namespace TUGraz.VectoCore.OutputData.XML
@@ -161,20 +163,37 @@ namespace TUGraz.VectoCore.OutputData.XML
 
 		#region Generate new manfuacturing Stage
 
+		private XElement GetSignatureElement(XElement stage)
+		{
+			var stream = new MemoryStream();
+			var writer = new StreamWriter(stream);
+			writer.Write(stage);
+			writer.Flush();
+			stream.Seek(0, SeekOrigin.Begin);
+
+			return new XElement(tns + XMLNames.DI_Signature,
+						 VectoHash.Load(stream).ComputeXmlHash
+							(VectoHash.DefaultCanonicalizationMethod, VectoHash.DefaultDigestMethod));
+		}
+
+
 		private XElement GenerateInputManufacturingStage()
 		{
 			var multistageId = $"{VectoComponents.VectoManufacturingStage.HashIdPrefix()}{GetGUID()}";
 			var vehicleId = $"{VectoComponents.Vehicle.HashIdPrefix()}{GetGUID()}";
 
-			return new XElement(tns + XMLNames.ManufacturingStage,
-					new XAttribute("stageCount", GetStageNumber()),
-					new XElement(tns + XMLNames.Report_DataWrap,
-						new XAttribute(xsi + XMLNames.Attr_Type, "BusManufacturingStageDataType"),
-						new XAttribute(XMLNames.Component_ID_Attr, multistageId),
-						GetHashPreviousStageElement(),
-						GetVehicleElement(vehicleId),
-						GetApplicationInformation()),
-					GetInputdataSignature(multistageId));
+			var stage = new XElement(tns + XMLNames.ManufacturingStage,
+				new XAttribute("stageCount", GetStageNumber()),
+				new XElement(tns + XMLNames.Report_DataWrap,
+					new XAttribute(xsi + XMLNames.Attr_Type, "BusManufacturingStageDataType"),
+					new XAttribute(XMLNames.Component_ID_Attr, multistageId),
+					GetHashPreviousStageElement(),
+					GetVehicleElement(vehicleId),
+					GetApplicationInformation()));
+
+			var sigXElement = GetSignatureElement(stage);
+			stage.LastNode.Parent.Add(sigXElement);
+			return stage;
 		}
 		
 		private int GetStageNumber()
diff --git a/VectoCore/VectoCoreTest/Integration/Multistage/MultistageVehicleTest.cs b/VectoCore/VectoCoreTest/Integration/Multistage/MultistageVehicleTest.cs
index ec837b65c6..305c2a461d 100644
--- a/VectoCore/VectoCoreTest/Integration/Multistage/MultistageVehicleTest.cs
+++ b/VectoCore/VectoCoreTest/Integration/Multistage/MultistageVehicleTest.cs
@@ -691,7 +691,8 @@ namespace TUGraz.VectoCore.Tests.Integration.Multistage
 
 			Assert.AreEqual(1, aux.SteeringPumpTechnology.Count);
 			Assert.AreEqual("Variable displacement elec. controlled", aux.SteeringPumpTechnology[0]);
-			
+
+			//ToDo SupplyFromHEVPossible to interface and reader?
 			Assert.AreEqual(AlternatorType.Smart, aux.ElectricSupply.AlternatorTechnology);
 
 			Assert.AreEqual(1, aux.ElectricSupply.Alternators.Count);
@@ -713,7 +714,7 @@ namespace TUGraz.VectoCore.Tests.Integration.Multistage
 			Assert.AreEqual(3.SI<Volt>(), capacitor.Voltage);
 			
 			Assert.AreEqual("Large Supply 2-stage", aux.PneumaticSupply.CompressorSize);//SizeOfAirSupply
-			Assert.AreEqual(CompressorDrive.mechanically, aux.PneumaticSupply.CompressorDrive);
+			Assert.AreEqual(CompressorDrive.electrically, aux.PneumaticSupply.CompressorDrive);
 			Assert.AreEqual("none", aux.PneumaticSupply.Clutch);
 			Assert.AreEqual(1.000, aux.PneumaticSupply.Ratio);
 			Assert.AreEqual(false, aux.PneumaticSupply.SmartAirCompression);
-- 
GitLab