/// <summary> /// Reads one file to fill the db /// </summary> /// <param name="db">The navDatabase to fill</param> /// <param name="fName">The qualified filename</param> /// <returns>The result string, either empty or error</returns> private static string ReadDbFile(ref icaoDatabase db, string fName) { if (!File.Exists(fName)) { return($"File {fName} does not exist\n"); } var icaoPre = Path.GetFileNameWithoutExtension(fName).ToUpperInvariant(); string ret = ""; using (var sr = new StreamReader(fName)) { string buffer = sr.ReadToEnd( ); buffer = buffer.Replace("\n", "").Replace("\r", "").Trim( ); // cleanup any CR, LFs and whitespaces buffer = buffer.Substring(1); // skip enclosing { var fragment = JsonParser.ExtractFragment(buffer); while (!string.IsNullOrEmpty(fragment)) { buffer = buffer.Substring(fragment.Length + 1); // remove extracted + comma var rec = FromNative(fragment); rec.AddPrefix(icaoPre); // make it a valid one - the FA db icao is without the prefix from the file... if (rec.IsValid) { ret += db.Add(rec); // collecting add information } fragment = JsonParser.ExtractFragment(buffer); } } return(ret); }
/// <summary> /// Reads all data from the given file /// </summary> /// <param name="db">The icaoDatabase to fill</param> /// <param name="fName">A fully qualified name</param> /// <returns>The result string, either empty or error</returns> public static string ReadDb(ref icaoDatabase db, string fName) { if (!File.Exists(fName)) { return($"File {fName} does not exist\n"); } string ret = ""; using (var sr = new StreamReader(fName)) { string buffer = sr.ReadLine( ); // header line buffer = sr.ReadLine( ); while (!sr.EndOfStream) { var rec = FromNative(buffer); if (rec.IsValid) { ret += db.Add(rec); // collect adding information } buffer = sr.ReadLine( ); } // } return(ret); }
/// <summary> /// Reads one db file /// </summary> /// <param name="db">The icaoDatabase to fill from the file</param> /// <param name="fName">The qualified filename</param> /// <returns>The result string, either empty or error</returns> private static string ReadDbFile(ref icaoDatabase db, string fName) { var icaoPre = Path.GetFileNameWithoutExtension(fName); string ret = ""; using (var sr = new StreamReader(fName)) { string buffer = sr.ReadLine( ); // header line buffer = sr.ReadLine( ); while (!sr.EndOfStream) { var rec = FromNative(buffer); if (rec.IsValid) { ret += db.Add(rec); // collect adding information } buffer = sr.ReadLine( ); } // } return(ret); }