Ejemplo n.º 1
0
        /// <summary>
        /// Writes a geojson file from the given database into the open stream
        /// Selects items to write from the given selection criteria
        /// </summary>
        /// <param name="db">The apDatabase to dump</param>
        /// <param name="geojOutStream">The open outstream</param>
        /// <param name="rangeLimitNm">Range Limit in nm</param>
        /// <param name="Lat">Center Lat (decimal)</param>
        /// <param name="Lon">Center Lon (decimal)</param>
        /// <param name="navTypes">Type of nav items to include</param>
        /// <returns>True ??!!</returns>
        public static bool WriteGeoJson(apDatabase db, Stream geojOutStream,
                                        double rangeLimitNm = -1.0, double Lat = 0, double Lon = 0, AptTypes[] aptTypes = null)
        {
            /*
             *  {
             *  "type": "FeatureCollection",
             *  "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
             *  "features": [
             *                    entry, entry
             *              ]
             *   }
             */
            string head = $"{{\n\"type\": \"FeatureCollection\",\n" +
                          $"\"crs\": {{ \"type\": \"name\", \"properties\": {{ \"name\": \"urn:ogc:def:crs:OGC:1.3:CRS84\" }} }}," +
                          $"\"features\": [";
            string foot = $"]\n}}";

            using (var sw = new StreamWriter(geojOutStream, Encoding.UTF8)) {
                sw.WriteLine(head);
                if (rangeLimitNm > 0)
                {
                    WriteFile(sw, db.GetSubtable(rangeLimitNm, Lat, Lon, aptTypes));
                }
                else
                {
                    WriteFile(sw, db.GetTable( ));
                }
                sw.WriteLine(foot);
            }
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Write complete airport db into the supplied database as one transaction
        /// </summary>
        /// <param name="db">The airport db to dump</param>
        /// <param name="sqConnection">The db connection</param>
        /// <returns>The result string, either empty or error</returns>
        public static string WriteSqDB(apDatabase db, SQLiteConnection sqConnection)
        {
            string ret = "";

            using (SQLiteCommand sqlite_cmd = sqConnection.CreateCommand( )) {
                sqlite_cmd.CommandText = "BEGIN TRANSACTION;";
                sqlite_cmd.ExecuteNonQuery( );
                try {
                    ret = WriteFile(sqConnection, db.GetTable( ));
                    sqlite_cmd.CommandText = "COMMIT;";
                    sqlite_cmd.ExecuteNonQuery( );
                }
                catch {
                    sqlite_cmd.CommandText = "ROLLBACK;";
                    sqlite_cmd.ExecuteNonQuery( );
                }
                finally {
                    if (!string.IsNullOrEmpty(ret))
                    {
                        ret = $"ERROR - inserting rows failed: {ret}\n";
                    }
                }
            }
            return(ret);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Write the airport 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 static bool WriteCsv(apDatabase db, Stream csvOutStream)
 {
     using (var sw = new StreamWriter(csvOutStream, Encoding.UTF8)) {
         sw.WriteLine(apRec.CsvHeader);
         WriteFile(sw, db.GetTable(  ));
     }
     return(true);
 }