예제 #1
0
        public async Task WriteMetadataAsync(IDictionary <string, string> metadata)
        {
            try
            {
                using (var command = new SQLiteCommand("create table if not exists metadata (name string, value string)", connection))
                {
                    await command.ExecuteNonQueryAsync();
                }

                using (var command = new SQLiteCommand("insert or replace into metadata (name, value) values (@n, @v)", connection))
                {
                    foreach (var keyValue in metadata)
                    {
                        command.Parameters.AddWithValue("@n", keyValue.Key);
                        command.Parameters.AddWithValue("@v", keyValue.Value);

                        await command.ExecuteNonQueryAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("MBTileData: " + ex.Message);
            }
        }
예제 #2
0
        public async Task WriteImageBufferAsync(int x, int y, int zoomLevel, byte[] imageBuffer)
        {
            try
            {
                using (var command = new SQLiteCommand("create table if not exists tiles (zoom_level integer, tile_column integer, tile_row integer, tile_data blob)", connection))
                {
                    await command.ExecuteNonQueryAsync();
                }

                using (var command = new SQLiteCommand("insert or replace into tiles (zoom_level, tile_column, tile_row, tile_data) values (@z, @x, @y, @b)", connection))
                {
                    command.Parameters.AddWithValue("@z", zoomLevel);
                    command.Parameters.AddWithValue("@x", x);
                    command.Parameters.AddWithValue("@y", (1 << zoomLevel) - y - 1);
                    command.Parameters.AddWithValue("@b", imageBuffer);

                    await command.ExecuteNonQueryAsync();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("MBTileData: {0}/{1}/{2}: {3}", zoomLevel, x, y, ex.Message);
            }
        }
예제 #3
0
        private async Task InitializeAsync(CancellationToken cancel)
        {
            _logger.LogInformation("Initializing db cache: {ConnectionString}",
                                   _config.ConnectionString);

            using (var transaction = _db.BeginTransaction())
            {
                using (var cmd = new DbCommand(Resources.TableInitCommand, _db))
                {
                    cmd.Transaction = transaction;
                    await cmd.ExecuteNonQueryAsync(cancel);
                }
                using (var cmd = new DbCommand(
                           $"INSERT INTO meta (key, value) " +
                           $"VALUES " +
                           $@"(""version"", {SchemaVersion}), " +
                           $@"(""created"", {DateTimeOffset.UtcNow.Ticks})", _db))
                {
                    cmd.Transaction = transaction;
                    await cmd.ExecuteNonQueryAsync(cancel);
                }
                transaction.Commit();
            }
        }