Ejemplo n.º 1
0
        public async Task <byte[]> ReadImageBufferAsync(int x, int y, int zoomLevel)
        {
            byte[] imageBuffer = null;

            try
            {
                using (var command = new SQLiteCommand("select tile_data from tiles where zoom_level=@z and tile_column=@x and tile_row=@y", connection))
                {
                    command.Parameters.AddWithValue("@z", zoomLevel);
                    command.Parameters.AddWithValue("@x", x);
                    command.Parameters.AddWithValue("@y", (1 << zoomLevel) - y - 1);

                    imageBuffer = await command.ExecuteScalarAsync() as byte[];
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("MBTileData: {0}/{1}/{2}: {3}", zoomLevel, x, y, ex.Message);
            }

            return(imageBuffer);
        }
Ejemplo n.º 2
0
        // Some day, Microsoft will deign it useful to add async service initializers and we can
        // bring this code back to the light of day.
#if false
        private async Task <bool> CheckExistingDbAsync(DbConnection db, CancellationToken cancel)
        {
            try
            {
                // Check for correct structure
                using (var cmd = new DbCommand(@"SELECT COUNT(*) from sqlite_master", db))
                {
                    var result = (long)await cmd.ExecuteScalarAsync(cancel);

                    // We are expecting two tables and one additional index
                    if (result != 3)
                    {
                        _logger.LogWarning("Incorrect/incompatible existing cache db structure found!");
                        return(false);
                    }
                }

                // Check for correct version
                using (var cmd = new DbCommand(@"SELECT value FROM meta WHERE key = ""version""", db))
                {
                    var result = (long)await cmd.ExecuteScalarAsync(cancel);

                    if (result != SchemaVersion)
                    {
                        _logger.LogWarning("Existing cache db has unsupported schema version {SchemaVersion}",
                                           result);
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error while checking compatibilty of existing cache db!");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Tests the connection asynchronously.
 /// </summary>
 /// <returns></returns>
 public override async Task TestConnectionAsync()
 {
     using (var con = await CreateConnectionAsync())
         using (var cmd = new SQLiteCommand("SELECT 1", con))
             await cmd.ExecuteScalarAsync();
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Tests the connection asynchronously.
 /// </summary>
 /// <returns></returns>
 public override async Task TestConnectionAsync()
 {
     using (var con = await CreateConnectionAsync())
     using (var cmd = new SQLiteCommand("SELECT 1", con))
         await cmd.ExecuteScalarAsync();
 }