From c76eb92b22f82c1e8cf4510d53f2567529740c5b Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Fri, 6 Mar 2015 10:39:43 +0100
Subject: [PATCH] minor refactorings

---
 VectoCore/Exceptions/VectoExceptions.cs       | 29 +++++++++++++++++++
 .../Data/CombustionEngineData.cs              | 15 +++++-----
 .../Data/EngineOnlyDrivingCycle.cs            |  4 +--
 .../SimulationComponent/Data/ModalResult.cs   |  2 +-
 .../{IDataWriter.cs => IModalDataWriter.cs}   |  4 +--
 ...stDataWriter.cs => TestModalDataWriter.cs} |  0
 6 files changed, 42 insertions(+), 12 deletions(-)
 create mode 100644 VectoCore/Exceptions/VectoExceptions.cs
 rename VectoCore/Models/SimulationComponent/{IDataWriter.cs => IModalDataWriter.cs} (84%)
 rename VectoCoreTest/Utils/{TestDataWriter.cs => TestModalDataWriter.cs} (100%)

diff --git a/VectoCore/Exceptions/VectoExceptions.cs b/VectoCore/Exceptions/VectoExceptions.cs
new file mode 100644
index 0000000000..6cc96ea95e
--- /dev/null
+++ b/VectoCore/Exceptions/VectoExceptions.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TUGraz.VectoCore.Exceptions
+{
+	
+
+	abstract class  FileIOException : Exception
+	{
+		protected FileIOException(string message) : base(message)
+		{
+
+		}
+
+		protected FileIOException(string message, Exception inner)
+			: base(message, inner)
+		{
+		}
+	}
+
+	class UnsupportedFileVersion : FileIOException
+	{
+		public UnsupportedFileVersion(string message) : base(message) { }
+		public UnsupportedFileVersion(string message, Exception inner) : base(message, inner) { }
+	}
+}
diff --git a/VectoCore/Models/SimulationComponent/Data/CombustionEngineData.cs b/VectoCore/Models/SimulationComponent/Data/CombustionEngineData.cs
index 52730cfefc..440d116faf 100644
--- a/VectoCore/Models/SimulationComponent/Data/CombustionEngineData.cs
+++ b/VectoCore/Models/SimulationComponent/Data/CombustionEngineData.cs
@@ -6,6 +6,7 @@ using System.Linq;
 using System.Net.Mime;
 using System.Runtime.CompilerServices;
 using Newtonsoft.Json;
+using TUGraz.VectoCore.Exceptions;
 using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine;
 
 namespace TUGraz.VectoCore.Models.SimulationComponent.Data
@@ -59,7 +60,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
             var header = results["Header"];
 
             if (header["FileVersion"] > 2)
-                throw new Exception("Unsupported Version of .veng file. Got Version: " + header["FileVersion"]);
+                throw new UnsupportedFileVersion("Unsupported Version of .veng file. Got Version: " + header["FileVersion"]);
 
             var body = results["Body"];
 
@@ -77,22 +78,22 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
             engine.ConsumptionMap = FuelConsumptionMap.ReadFromFile(body["FuelMap"].Value);
 
             if (body["WHTC-Urban"] != null)
-                WHTCUrban = body["WHTC-Urban"].Value;
+                engine.WHTCUrban = body["WHTC-Urban"].Value;
 
             if (body["WHTC-Rural"] != null)
-                WHTCRural = body["WHTC-Rural"].Value;
+				engine.WHTCRural = body["WHTC-Rural"].Value;
 
             if (body["WHTC-Motorway"] != null)
-                WHTCMotorway = body["WHTC-Motorway"].Value;
+				engine.WHTCMotorway = body["WHTC-Motorway"].Value;
 
             return engine;
         }
 
-        public static double WHTCMotorway { get; set; }
+        public double WHTCMotorway { get; set; }
 
-        public static double WHTCRural { get; set; }
+        public double WHTCRural { get; set; }
 
-        public static double WHTCUrban { get; set; }
+        public double WHTCUrban { get; set; }
 
         public bool SavedInDeclarationMode { get; set; }
 
diff --git a/VectoCore/Models/SimulationComponent/Data/EngineOnlyDrivingCycle.cs b/VectoCore/Models/SimulationComponent/Data/EngineOnlyDrivingCycle.cs
index 7d00d4a493..a0f56e66a1 100644
--- a/VectoCore/Models/SimulationComponent/Data/EngineOnlyDrivingCycle.cs
+++ b/VectoCore/Models/SimulationComponent/Data/EngineOnlyDrivingCycle.cs
@@ -25,8 +25,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
         /// </summary>
         public double Pe
         {
-            get { return 2 * Math.PI / 60 * T * n; }
-            set { T = 60 / (2 * Math.PI) * value / n; }
+            get { return 2.0 * Math.PI / 60.0 * T * n; }
+            set { T = 60.0 / (2.0 * Math.PI) * value / n; }
         }
 
         public static List<EngineOnlyDrivingCycle> Read(string fileName)
diff --git a/VectoCore/Models/SimulationComponent/Data/ModalResult.cs b/VectoCore/Models/SimulationComponent/Data/ModalResult.cs
index 61877639fc..952f447ea5 100644
--- a/VectoCore/Models/SimulationComponent/Data/ModalResult.cs
+++ b/VectoCore/Models/SimulationComponent/Data/ModalResult.cs
@@ -70,7 +70,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
     {
         public static Type GetDataType(this ModalResult field)
         {
-            return typeof(double);
+            return GetAttr(field).FieldType;
         }
 
 	    private static ModalResultFieldAttr GetAttr(ModalResult field)
diff --git a/VectoCore/Models/SimulationComponent/IDataWriter.cs b/VectoCore/Models/SimulationComponent/IModalDataWriter.cs
similarity index 84%
rename from VectoCore/Models/SimulationComponent/IDataWriter.cs
rename to VectoCore/Models/SimulationComponent/IModalDataWriter.cs
index 2248d7a53f..0b7b917d23 100644
--- a/VectoCore/Models/SimulationComponent/IDataWriter.cs
+++ b/VectoCore/Models/SimulationComponent/IModalDataWriter.cs
@@ -2,14 +2,14 @@
 using TUGraz.VectoCore.Models.SimulationComponent.Data;
 namespace TUGraz.VectoCore.Models.SimulationComponent
 {
-    public interface IDataWriter
+    public interface IModalDataWriter
     {
         /// <summary>
         /// Indexer for fields of the DataWriter. Accesses the data of the current step.
         /// </summary>
         /// <param name="key"></param>
         /// <returns></returns>
-        object this[Enum key] { get; set; }
+        object this[ModalResult key] { get; set; }
 
         /// <summary>
         /// Commits the data of the current simulation step.
diff --git a/VectoCoreTest/Utils/TestDataWriter.cs b/VectoCoreTest/Utils/TestModalDataWriter.cs
similarity index 100%
rename from VectoCoreTest/Utils/TestDataWriter.cs
rename to VectoCoreTest/Utils/TestModalDataWriter.cs
-- 
GitLab