From 446cb41811b395e40796b537ccd344b5898dc827 Mon Sep 17 00:00:00 2001
From: Michael Krisper <michael.krisper@tugraz.at>
Date: Wed, 17 Aug 2016 11:34:54 +0200
Subject: [PATCH] Lookup's: Moved NormalizeTable up to constructor

---
 .../Models/Declaration/ElectricSystem.cs         |  6 ------
 VectoCore/VectoCore/Models/Declaration/Fan.cs    |  3 ---
 VectoCore/VectoCore/Models/Declaration/HVAC.cs   |  3 ---
 .../VectoCore/Models/Declaration/LookupData.cs   | 16 +++++++++-------
 .../VectoCore/Models/Declaration/Payloads.cs     |  2 --
 .../Models/Declaration/PneumaticSystem.cs        |  3 ---
 .../VectoCore/Models/Declaration/Segments.cs     |  1 -
 .../Models/Declaration/StandardBodies.cs         |  5 ++---
 .../VectoCore/Models/Declaration/SteeringPump.cs |  9 ---------
 .../Models/Declaration/WHTCCorrection.cs         |  3 ---
 10 files changed, 11 insertions(+), 40 deletions(-)

diff --git a/VectoCore/VectoCore/Models/Declaration/ElectricSystem.cs b/VectoCore/VectoCore/Models/Declaration/ElectricSystem.cs
index b68718cc1f..e418f67066 100644
--- a/VectoCore/VectoCore/Models/Declaration/ElectricSystem.cs
+++ b/VectoCore/VectoCore/Models/Declaration/ElectricSystem.cs
@@ -52,9 +52,6 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 		protected override void ParseData(DataTable table)
 		{
-			Data.Clear();
-			NormalizeTable(table);
-
 			foreach (DataRow row in table.Rows) {
 				var name = row.Field<string>("technology");
 				foreach (DataColumn col in table.Columns) {
@@ -88,9 +85,6 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 			protected override void ParseData(DataTable table)
 			{
-				Data.Clear();
-				NormalizeTable(table);
-
 				foreach (DataRow row in table.Rows) {
 					var name = row.Field<string>("technology");
 					foreach (DataColumn col in table.Columns) {
diff --git a/VectoCore/VectoCore/Models/Declaration/Fan.cs b/VectoCore/VectoCore/Models/Declaration/Fan.cs
index b1940483d8..ec69f8734d 100644
--- a/VectoCore/VectoCore/Models/Declaration/Fan.cs
+++ b/VectoCore/VectoCore/Models/Declaration/Fan.cs
@@ -50,9 +50,6 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 		protected override void ParseData(DataTable table)
 		{
-			Data.Clear();
-			NormalizeTable(table);
-
 			foreach (DataRow row in table.Rows) {
 				var name = row.Field<string>("technology");
 				foreach (DataColumn col in table.Columns) {
diff --git a/VectoCore/VectoCore/Models/Declaration/HVAC.cs b/VectoCore/VectoCore/Models/Declaration/HVAC.cs
index 2dbdaa7618..e0bf4e8114 100644
--- a/VectoCore/VectoCore/Models/Declaration/HVAC.cs
+++ b/VectoCore/VectoCore/Models/Declaration/HVAC.cs
@@ -50,9 +50,6 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 		protected override void ParseData(DataTable table)
 		{
-			Data.Clear();
-			NormalizeTable(table);
-
 			foreach (DataRow row in table.Rows) {
 				var hdvClass = VehicleClassHelper.Parse(row.Field<string>("hdvclass"));
 				foreach (DataColumn col in table.Columns) {
diff --git a/VectoCore/VectoCore/Models/Declaration/LookupData.cs b/VectoCore/VectoCore/Models/Declaration/LookupData.cs
index f170922cf9..ef4c938336 100644
--- a/VectoCore/VectoCore/Models/Declaration/LookupData.cs
+++ b/VectoCore/VectoCore/Models/Declaration/LookupData.cs
@@ -41,17 +41,19 @@ namespace TUGraz.VectoCore.Models.Declaration
 {
 	public abstract class LookupData : LoggingObject
 	{
-		protected LookupData()
-		{
-			if (!string.IsNullOrWhiteSpace(ResourceId))
-				ParseData(ReadCsvResource(ResourceId));
-		}
-
 		protected abstract string ResourceId { get; }
 		protected abstract string ErrorMessage { get; }
-
 		protected abstract void ParseData(DataTable table);
 
+		protected LookupData()
+		{
+			if (!string.IsNullOrWhiteSpace(ResourceId)) {
+				var table = ReadCsvResource(ResourceId);
+				NormalizeTable(table);
+				ParseData(table);
+			}
+		}
+
 		protected static DataTable ReadCsvResource(string resourceId)
 		{
 			return VectoCSVFile.ReadStream(RessourceHelper.ReadStream(resourceId));
diff --git a/VectoCore/VectoCore/Models/Declaration/Payloads.cs b/VectoCore/VectoCore/Models/Declaration/Payloads.cs
index abf14d3cc6..a0eeb1226a 100644
--- a/VectoCore/VectoCore/Models/Declaration/Payloads.cs
+++ b/VectoCore/VectoCore/Models/Declaration/Payloads.cs
@@ -81,8 +81,6 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 		protected override void ParseData(DataTable table)
 		{
-			NormalizeTable(table);
-
 			Data = table.Rows.Cast<DataRow>()
 				.ToDictionary(
 					kv => kv.ParseDouble("grossvehicleweight").SI<Kilogram>(),
diff --git a/VectoCore/VectoCore/Models/Declaration/PneumaticSystem.cs b/VectoCore/VectoCore/Models/Declaration/PneumaticSystem.cs
index c0d2bbc799..9e82d0a081 100644
--- a/VectoCore/VectoCore/Models/Declaration/PneumaticSystem.cs
+++ b/VectoCore/VectoCore/Models/Declaration/PneumaticSystem.cs
@@ -50,9 +50,6 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 		protected override void ParseData(DataTable table)
 		{
-			Data.Clear();
-			NormalizeTable(table);
-
 			foreach (DataRow row in table.Rows) {
 				var technology = row.Field<string>("technology");
 				foreach (DataColumn col in table.Columns) {
diff --git a/VectoCore/VectoCore/Models/Declaration/Segments.cs b/VectoCore/VectoCore/Models/Declaration/Segments.cs
index 4ce4fe1ad1..fefb9561a4 100644
--- a/VectoCore/VectoCore/Models/Declaration/Segments.cs
+++ b/VectoCore/VectoCore/Models/Declaration/Segments.cs
@@ -61,7 +61,6 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 		protected override void ParseData(DataTable table)
 		{
-			NormalizeTable(table);
 			_segmentTable = table.Copy();
 		}
 
diff --git a/VectoCore/VectoCore/Models/Declaration/StandardBodies.cs b/VectoCore/VectoCore/Models/Declaration/StandardBodies.cs
index 9fc0ffb834..922776383d 100644
--- a/VectoCore/VectoCore/Models/Declaration/StandardBodies.cs
+++ b/VectoCore/VectoCore/Models/Declaration/StandardBodies.cs
@@ -79,7 +79,8 @@ namespace TUGraz.VectoCore.Models.Declaration
 	/// </summary>
 	public sealed class StandardBodies : LookupData<string, StandardBody>
 	{
-		public static StandardBody Empty = new StandardBody("", 0.SI<Kilogram>(), 0.SI<Kilogram>(), 0.SI<SquareMeter>(), null);
+		public static readonly StandardBody Empty = new StandardBody("", 0.SI<Kilogram>(), 0.SI<Kilogram>(),
+			0.SI<SquareMeter>(), null);
 
 		protected override string ResourceId
 		{
@@ -98,8 +99,6 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 		protected override void ParseData(DataTable table)
 		{
-			NormalizeTable(table);
-
 			Data = table.Rows.Cast<DataRow>().Select(k => new StandardBody(
 				k.Field<string>("name"),
 				k.ParseDoubleOrGetDefault("curbmass").SI<Kilogram>(),
diff --git a/VectoCore/VectoCore/Models/Declaration/SteeringPump.cs b/VectoCore/VectoCore/Models/Declaration/SteeringPump.cs
index dc2965fc58..651f252017 100644
--- a/VectoCore/VectoCore/Models/Declaration/SteeringPump.cs
+++ b/VectoCore/VectoCore/Models/Declaration/SteeringPump.cs
@@ -84,9 +84,6 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 			protected override void ParseData(DataTable table)
 			{
-				NormalizeTable(table);
-				Data.Clear();
-
 				foreach (DataRow row in table.Rows) {
 					var hdvClass = VehicleClassHelper.Parse(row.Field<string>("hdvclass"));
 					foreach (DataColumn col in table.Columns) {
@@ -115,9 +112,6 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 			protected override void ParseData(DataTable table)
 			{
-				NormalizeTable(table);
-				Data.Clear();
-
 				Data = table.Rows.Cast<DataRow>().ToDictionary(
 					key => key.Field<string>("Technology"),
 					value => new SteeringPumpValues<double>(value.ParseDouble("UF"), value.ParseDouble("B"), value.ParseDouble("S")));
@@ -160,9 +154,6 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 			protected override void ParseData(DataTable table)
 			{
-				NormalizeTable(table);
-				Data.Clear();
-
 				foreach (DataRow row in table.Rows) {
 					var axleNumber = int.Parse(row.Field<string>("steeredaxles"));
 					foreach (DataColumn col in table.Columns) {
diff --git a/VectoCore/VectoCore/Models/Declaration/WHTCCorrection.cs b/VectoCore/VectoCore/Models/Declaration/WHTCCorrection.cs
index 06b305fffd..94964d95b7 100644
--- a/VectoCore/VectoCore/Models/Declaration/WHTCCorrection.cs
+++ b/VectoCore/VectoCore/Models/Declaration/WHTCCorrection.cs
@@ -61,9 +61,6 @@ namespace TUGraz.VectoCore.Models.Declaration
 
 			protected override void ParseData(DataTable table)
 			{
-				NormalizeTable(table);
-				Data.Clear();
-
 				foreach (MissionType mission in Enum.GetValues(typeof(MissionType))) {
 					var values = table.Columns[mission.ToString().ToLower()].Values<string>().ToDouble().ToArray();
 					Data[mission] = new Entry { Urban = values[0], Rural = values[1], Motorway = values[2] };
-- 
GitLab