コード例 #1
0
ファイル: awyWriter.cs プロジェクト: bm98/XPVTraffic
        /// <summary>
        /// Writes the given DB to a file
        /// NOTE does not overwrite but complains
        /// </summary>
        /// <param name="db">The DB to write</param>
        /// <param name="fName">The file to write to</param>
        /// <returns>An empty string or error message</returns>
        public static string WriteDb(awyDatabase db, string fName)
        {
            if (File.Exists(fName))
            {
                return($"File does exist\n");
            }

            return(WriteDbFile(db, fName));
        }
コード例 #2
0
ファイル: awyReader.cs プロジェクト: bm98/XPVTraffic
        /// <summary>
        /// Reads the XPlane 11 earth_awy.dat file and populates the supplied database
        /// </summary>
        /// <param name="db">The awyDatabase to fill</param>
        /// <param name="fName">The file to read</param>
        /// <returns>The result string, either empty or error</returns>
        public static string ReadDb(ref awyDatabase db, string fName)
        {
            if (!File.Exists(fName))
            {
                return($"File does not exist\n");
            }

            return(ReadDbFile(ref db, fName));
        }
コード例 #3
0
ファイル: awyWriter.cs プロジェクト: bm98/XPVTraffic
        private static string WriteDbFile(awyDatabase db, string fName)
        {
            string ret = "";

            using (var sr = new StreamWriter(fName)) {
                foreach (var awrec in db.GetTable())
                {
                    sr.WriteLine(awrec.Value.ToString( ));
                }
                sr.WriteLine("99 ");
            }
            return(ret);
        }
コード例 #4
0
ファイル: DBCreator.cs プロジェクト: bm98/XPVTraffic
        /// <summary>
        /// Creates the dbfile for our internal use
        /// </summary>
        /// <param name="myDataPath"></param>
        /// <returns></returns>
        public string CreateDbFile(string myDataPath)
        {
            Logger.Instance.Log($"DBCreator-CreateDbFile");
            if (!Valid)
            {
                Error = "$Error: Init failed, check XP11 base path and earth_nav, earth_fix, earth_awy files";
                Logger.Instance.Log($"DBCreator: {Error}");
                return(Error); // ERROR exit
            }

            // delete existing files
            string eawy = Path.Combine(myDataPath, MyAwyDbName);

            if (File.Exists(eawy))
            {
                File.Delete(eawy);
            }

            string erwy = Path.Combine(myDataPath, MyRwyDbName);

            if (File.Exists(erwy))
            {
                File.Delete(erwy);
            }

            var MYAWDB = new my_awlib.awyDatabase( );

            MYAWDB.LoadFromX11DB(NAVDB, AWYDB);
            Error = my_awlib.awyWriter.WriteDb(MYAWDB, eawy);
            Logger.Instance.Log($"DBCreator-CreateMyAWYDB ended: {Error}");

            var MYRWYDB = new my_rwylib.rwyDatabase( );

            MYRWYDB.LoadFromX11DB(APTDB);
            Error = my_rwylib.rwyWriter.WriteDb(MYRWYDB, erwy);
            Logger.Instance.Log($"DBCreator-CreateMyRWYDB ended: {Error}");

            return(Error);
        }
コード例 #5
0
ファイル: awyReader.cs プロジェクト: bm98/XPVTraffic
        /// <summary>
        /// Reads one file to fill the db
        /// </summary>
        /// <param name="db">The awyDatabase to fill</param>
        /// <param name="fName">The qualified filename</param>
        /// <returns>The result string, either empty or error</returns>
        private static string ReadDbFile(ref awyDatabase db, string fName)
        {
            string ret = "";

            using (var sr = new StreamReader(fName)) {
                string buffer = sr.ReadLine( );
                while (!sr.EndOfStream)
                {
                    if (buffer.StartsWith("99 "))
                    {
                        break;
                    }
                    var rec = FromNative(buffer);
                    if (rec != null && rec.IsValid)
                    {
                        ret += db.Add(rec); // collect adding information
                    }
                    buffer = sr.ReadLine( );
                }
                //
            }
            return(ret);
        }