Beispiel #1
0
        /// <summary>
        /// Reads all data from the given file
        /// </summary>
        /// <param name="db">The icaoActDatabase 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 icaoActDatabase 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);
        }
Beispiel #2
0
        /// <summary>
        /// Reads all data from the given file
        /// </summary>
        /// <param name="db">The icaoActDatabase 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 icaoActDatabase 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.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);
                    if (rec.IsValid)
                    {
                        ret += db.Add(rec); // collecting add information
                    }
                    fragment = JsonParser.ExtractFragment(buffer);
                }
            }
            return(ret);
        }
Beispiel #3
0
        /// <summary>
        /// Write the ICAO Aircraft Type Designator database file
        /// </summary>
        /// <param name="db">The ACT database</param>
        /// <param name="dbFile">Absolute path to the db file to write</param>
        /// <returns>True if OK</returns>
        public static bool WriteDb(icaoActDatabase db, string dbFile)
        {
            string dbFolder = Path.GetDirectoryName(dbFile);

            if (!Directory.Exists(dbFolder))
            {
                Directory.CreateDirectory(dbFolder);
            }

            WriteFile(dbFile, db.GetTable());
            WriteReadme(dbFolder);
            return(true);
        }