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
LookupData.cs 987 B
Newer Older
  • Learn to ignore specific revisions
  • using System;
    using System.Collections.Generic;
    using System.Data;
    
    using Common.Logging;
    
    using TUGraz.VectoCore.Utils;
    
    
    namespace TUGraz.VectoCore.Models.Declaration
    
    	public abstract class LookupData<TKeyType, TEntryType>
    
    		protected LookupData()
    		{
    			Log = LogManager.GetLogger(GetType());
    			var csvFile = ReadCsvFile(ResourceId);
    			ParseData(csvFile);
    		}
    
    		[NonSerialized] protected ILog Log;
    
    		protected abstract string ResourceId { get; }
    		protected abstract void ParseData(DataTable table);
    
    		protected Dictionary<TKeyType, TEntryType> Data;
    
    
    		protected DataTable ReadCsvFile(string resourceId)
    		{
    
    			var myAssembly = Assembly.GetExecutingAssembly();
    
    			var file = myAssembly.GetManifestResourceStream(resourceId);
    			return VectoCSVFile.ReadStream(file);
    		}
    
    
    		public virtual TEntryType Lookup(TKeyType key)
    
    		{
    			var retVal = default(TEntryType);
    
    			if (Data.ContainsKey(key)) {
    				retVal = Data[key];