/// <summary> /// Reads all data from the given file /// </summary> /// <param name="db">The acDatabase to fill from the file</param> /// <param name="csvFile">The file to read</param> /// <returns>The result string, either empty or error</returns> public static string ReadDb(ref acDatabase db, string csvFile) { if (!File.Exists(csvFile)) { return($"File does not exist\n"); } return(ReadDbFile(ref db, csvFile)); }
/// <summary> /// Write the aircraft db as CSV formatted file /// </summary> /// <param name="db">The database to dump</param> /// <param name="csvOutStream">The stream to write to</param> /// <returns>True for success</returns> public bool WriteCsv(acDatabase db, Stream csvOutStream) { using (var sw = new StreamWriter(csvOutStream, Encoding.UTF8)) { sw.WriteLine(acRec.CsvHeader); foreach (var c in PREFIXES) { WriteFile(sw, db.GetSubtable(c.ToString( ))); } } return(true); }
/// <summary> /// Write the aircraft db as FA formatted Json files into the given folder /// </summary> /// <param name="db">The database to dump</param> /// <param name="dbFolder">The folder to write to</param> /// <returns>True for success</returns> public static bool WriteDb(acDatabase db, string dbFolder) { if (!Directory.Exists(dbFolder)) { return(false); } Dictionary <string, int> prefixes = new Dictionary <string, int>( ); foreach (var c in PREFIXES) { DecomposeTable(dbFolder, db.GetSubtable(c.ToString( ))); // level one get always decomposed } return(true); }
/// <summary> /// Reads one db file /// </summary> /// <param name="db">The acDatabase 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 acDatabase 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); }