public static void Set(string nativeId, Mnemocode code) { lock (Mapping) { if (!Mapping.ContainsKey(nativeId)) { Mapping[nativeId] = new HashSet <Mnemocode>(); } Mapping[nativeId].Add(code); } }
private static void MapBack(string nativeId, PsaParameterType type) { Mnemocode mapBack = MnemocodeToPsaTypeConversionCache.MapBack(type); { if (mapBack == null) { if (!UnknownNativeIds.Contains(nativeId)) { Log.Warn(String.Format("Could not find a mnemocode for native id {0} which is {1}", nativeId, type)); UnknownNativeIds.Add(nativeId); } } else { NativeIdToMnemocodeConversionCache.Set(nativeId, mapBack); } } }
public IEnumerable <string> GetParamStrings(Mnemocode code) { string queryFormat = @"SELECT PARLNAME FROM PARAM WHERE PARSNAME='{0}'"; HashSet <string> dsds = new HashSet <string>() { KnownDiagBoxPath.DSD_FDB, KnownDiagBoxPath.DSD_FDB_2, KnownDiagBoxPath.DSD_FDB_3 }; foreach (string dsd in dsds) { if (!File.Exists(dsd)) { continue; } string connectionString = String.Format(ConnectionStringFormat, dsd); using (FbConnection connection = new FbConnection(connectionString)) { connection.Open(); using (FbTransaction transaction = connection.BeginTransaction()) using (FbCommand command = new FbCommand()) { command.Connection = connection; command.Transaction = transaction; command.CommandText = String.Format(queryFormat, code); using (FbDataReader reader = command.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { string result = reader.GetString(reader.GetOrdinal("PARLNAME")); if (!String.IsNullOrEmpty(result)) { yield return(result); } } } } } } } }
public static PsaParameterType GetType(Mnemocode code) { return(MnemocodeToPsaTypeConversionCache.Get(code)); }
public static PsaParameterType GetType(string nativeId) { HashSet <Mnemocode> set = NativeIdToMnemocodeConversionCache.Get(nativeId); Mnemocode code = null; if (set != null) { code = set.FirstOrDefault(); } if (code == null) { IList <Mnemocode> mnemocodesFromDatabase = null; if (!DatabaseMnemocodeResolver.DatabaseReady && !NativeIdsCheckedInDb.Contains(nativeId)) { PsaParameterType result = DataTypeMapper.GetType(nativeId); return(result); } NativeIdsCheckedInDb.Add(nativeId); if (mnemocodesFromDatabase.Any()) { code = mnemocodesFromDatabase.First(); if (!String.IsNullOrWhiteSpace(code.Code)) { NativeIdToMnemocodeConversionCache.Set(nativeId, code); } else { throw new ArgumentException("Wrong mnemocode from database."); } } PsaParameterType oldMappedType = DataTypeMapper.GetType(nativeId); if (oldMappedType == PsaParameterType.Unsupported) { ReportUnknownNativeId(nativeId); return(oldMappedType); } foreach (Mnemocode dbmc in mnemocodesFromDatabase) { MnemocodeToPsaTypeConversionCache.Add(dbmc, oldMappedType); } if (code == null && oldMappedType != PsaParameterType.Unsupported) { Mnemocode mapBack = MnemocodeToPsaTypeConversionCache.MapBack(oldMappedType); { if (mapBack == null) { if (!UnknownNativeIds.Contains(nativeId)) { Log.Warn(String.Format("Could not find a mnemocode for native id {0} which is {1}", nativeId, oldMappedType)); UnknownNativeIds.Add(nativeId); } } else { NativeIdToMnemocodeConversionCache.Set(nativeId, mapBack); } } return(oldMappedType); } } PsaParameterType type = MnemocodeToPsaTypeConversionCache.Get(code); if (type == PsaParameterType.Unsupported) { type = DataTypeMapper.GetType(nativeId); if (type != PsaParameterType.Unsupported) { MnemocodeToPsaTypeConversionCache.Add(code, type); } } if (type == PsaParameterType.Unsupported) { ReportUnknownNativeId(nativeId); } return(type); }