Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Select Git revision
  • 82f7ef8396fc517ed31780f530ae3e4dc5d3db4f
  • stable default
  • feat-fchv-bus
  • fix-h2-ice-bus
  • powertrains-multiple-axles
  • amdm3/develop
  • issue-1039
  • amdm3/main
  • test/nuget_publish
  • IEPC-experiments
  • amdm2/main
  • amdm2/develop
  • aptngearbox-not-auto
  • playground
  • official/main
  • official/develop
  • issue-templates
  • pdf-reports
  • HEV-timeruns-dev
  • timerun-empower-hybrids
  • timerun-pwheel-hybrids
  • Release/v5.0.3
  • Release/v5.0.1
  • Release/5.0.0-RC
  • Nuget/v0.11.4-DEV
  • Release/v0.11.4-DEV
  • Release/4.3.4-DEV
  • Release/4.3.3
  • Release/4.3.2-RC
  • Release/v4.3.0-DEV
  • Release/4.2.7
  • XMLConverterTool/4.2.6.0
  • Release/4.2.6-RC
  • Release/v4.2.5
  • Release/v4.2.3
  • Release/v4.2.2.3539-RC
  • Release/v4.2.1.3469
  • Release/v0.11.2.3456-DEV
  • Release/v4.2.0.3448-RC
  • Release/v4.1.3.3415
  • Release/v4.1.1.3413
41 results

LookupData.cs

Blame
  • Forked from VECTO / VECTO Sim
    11553 commits behind the upstream repository.
    user avatar
    Michael KRISPER authored
    implemented steering pump auxiliaries in declaration mode, renamed declaration classes (removed declaration from name, because it is already in namespace)
    82f7ef83
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    LookupData.cs 1.78 KiB
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Reflection;
    using Common.Logging;
    using TUGraz.VectoCore.Utils;
    
    namespace TUGraz.VectoCore.Models.Declaration
    {
    	public abstract class LookupData
    	{
    		protected LookupData()
    		{
    			Log = LogManager.GetLogger(GetType());
    			var csvFile = ReadCsvFile(ResourceId);
    			ParseData(csvFile);
    		}
    
    		[NonSerialized] protected ILog Log;
    
    		/// <summary>
    		/// Gets the resource identifier. e.g. "TUGraz.VectoCore.Resources.Declaration.Rims.csv"
    		/// </summary>
    		protected abstract string ResourceId { get; }
    
    		protected abstract void ParseData(DataTable table);
    
    		protected DataTable ReadCsvFile(string resourceId)
    		{
    			var myAssembly = Assembly.GetExecutingAssembly();
    			var file = myAssembly.GetManifestResourceStream(resourceId);
    			return VectoCSVFile.ReadStream(file);
    		}
    
    		protected void NormalizeTable(DataTable table)
    		{
    			foreach (DataColumn col in table.Columns) {
    				table.Columns[col.ColumnName].ColumnName = col.ColumnName.ToLower().Replace(" ", "");
    			}
    		}
    	}
    
    
    	public abstract class LookupData<TKey, TValue> : LookupData
    	{
    		protected Dictionary<TKey, TValue> Data = new Dictionary<TKey, TValue>();
    
    		public virtual TValue Lookup(TKey key)
    		{
    			var retVal = default(TValue);
    			if (Data.ContainsKey(key)) {
    				retVal = Data[key];
    			}
    			return retVal;
    		}
    	}
    
    	public abstract class LookupData<TKey1, TKey2, TValue> : LookupData
    	{
    		public abstract TValue Lookup(TKey1 key1, TKey2 key2);
    	}
    
    	public abstract class LookupData<TKey1, TKey2, TKey3, TValue> : LookupData
    	{
    		public abstract TValue Lookup(TKey1 key1, TKey2 key2, TKey3 key3);
    	}
    
    	public abstract class LookupData<TKey1, TKey2, TKey3, TKey4, TValue> : LookupData
    	{
    		public abstract TValue Lookup(TKey1 key1, TKey2 key2, TKey3 key3, TKey4 key4);
    	}
    }