public bool GetDictEntryByAcronym(string fidname, out RdmDictEntry rdmDictEntry) { var result = from x in _dict.Values where x.Acronym == fidname select x; var rdmDictEntries = result as RdmDictEntry[] ?? result.ToArray(); rdmDictEntry = rdmDictEntries.First(); return(rdmDictEntries.Any()); }
public bool GetDictEntryById(int fidId, out RdmDictEntry rdmDictEntry) { rdmDictEntry = null; if (!_dict.ContainsKey(fidId)) { return(false); } rdmDictEntry = _dict[fidId]; return(true); }
public void Add(int fidId, RdmDictEntry entry) { _dict.Add(fidId, entry); }
public static async Task <Tuple <bool, RdmFieldDictionary, string> > LoadRdmDictionaryAsync(string filename) { var rdmDict = new RdmFieldDictionary(); var errorMsg = string.Empty; if (!File.Exists(filename)) { errorMsg += $"\nCannot find file {filename}"; return(new Tuple <bool, RdmFieldDictionary, string>(false, rdmDict, errorMsg)); } try { using (var fs = File.OpenRead(filename)) using (var bs = new BufferedStream(fs)) using (var sr = new StreamReader(bs)) { string s; while ((s = await sr.ReadLineAsync()) != null) { if (s[0] != '!') { var splitStr = Regex.Matches(s, @"[\""].+?[\""]|[^ ]+") .Cast <Match>() .Select(column => column.Value) .ToList(); var isEnum = splitStr[4].Contains("ENUMERATED"); var entry = new RdmDictEntry(); entry.Acronym = splitStr[0]; entry.DDEAcronym = splitStr[1]; if (int.TryParse(splitStr[2], out var fid)) { entry.Fid = fid; } else { entry.Fid = 0; errorMsg += "\nUnable to get FID set it to 0 instead"; } entry.RipplesTo = splitStr[3]; entry.FieldType = splitStr[4]; if (isEnum) { var newLength = $"{splitStr[5]} {splitStr[6]} {splitStr[7]} {splitStr[8]}"; entry.Length = newLength; entry.RwfType = RwfStringToTypeEnum(splitStr[9]); if (int.TryParse(splitStr[10], out var rwfLen)) { entry.RwfLen = rwfLen; } else { entry.RwfLen = 0; errorMsg += "\nUnable to get RWFLEN set it to 0 instead"; } } else { entry.Length = splitStr[5]; entry.RwfType = RwfStringToTypeEnum(splitStr[6]); if (int.TryParse(splitStr[7], out var rwfLen)) { entry.RwfLen = rwfLen; } else { entry.RwfLen = 0; errorMsg += "\nUnable to get RWFLEN set it to 0 instead"; } } rdmDict.Add(entry.Fid, entry); } } } return(new Tuple <bool, RdmFieldDictionary, string>(true, rdmDict, errorMsg)); } catch (Exception ex) { errorMsg += $"\n{ex.Message}\n{ex.StackTrace}"; return(new Tuple <bool, RdmFieldDictionary, string>(false, rdmDict, errorMsg)); } }