MBTiles db с SQLite в приложении aC# windows store
Я делаю приложение windows store (8.1) на C# Xaml для создания карт с использованием расширения Bing Maps for C# с файлом mbtiles, я уже использовал проект Portable Basemap Server для выполнения этой работы, но теперь я пытаюсь получить доступ к Данные в файле mbtiles самостоятельно с SQLite.
Мне удалось получить плитки из таких файлов в WPF, но я не знаю, как это сделать в проекте Windows Store;
Мой код в WPF:
SQLiteConnection _sqlcon;
using (_sqlcon = new SQLiteConnection(String.Format("Data Source={0};Version=3;", "PATH_TO_MBTILES")))
{
_sqlcon.Open();
SQLiteCommand cmd = new SQLiteCommand(string.Format("SELECT tile_data FROM tiles WHERE tile_column={0} AND tile_row={1} AND zoom_level={2}", 2, 5, 3), _sqlcon);
object o = cmd.ExecuteScalar();
if (o != null)
{
byte[] c = (byte[])o;
using (MemoryStream stream = new MemoryStream(c))
{
BitmapImage bmp = new BitmapImage();
bmp.BeginInit();
bmp.CacheOption = BitmapCacheOption.OnLoad;
bmp.StreamSource = stream;
bmp.EndInit();
img.Source = bmp;
}
}
}
С этим кодом я получаю плитку в столбце 2, строке 5 и на уровне 3.
Но в приложении Windows Store я получаю исключение SQLiteException "Не удалось открыть файл базы данных" при попытке создать SQLiteConnection
с тем же файлом (я использую NuGet sqlite-net и расширение SqLite для Windows Runtime 8.1)
Мой код в приложении Магазина Windows:
SQLiteConnection _sqlcon;
using (_sqlcon = new SQLiteConnection(String.Format("Data Source={0};Version=3;", "PATH_TO_MBTILES"))) //SQLiteExeption here
{
SQLiteCommand cmd = new SQLiteCommand(string.Format("SELECT tile_data FROM tiles WHERE tile_column={0} AND tile_row={1} AND zoom_level={2}", 2, 5, 3), _sqlcon);
byte[] o = cmd.ExecuteScalar<byte[]>();
//etc...
}
Отладчик Visual Studio отправляет меня в файл SQLite.cs из sqlite-net NuGet:
public SQLiteConnection (string databasePath, SQLiteOpenFlags openFlags, bool storeDateTimeAsTicks = false)
{
if (string.IsNullOrEmpty (databasePath))
throw new ArgumentException ("Must be specified", "databasePath");
DatabasePath = databasePath;
#if NETFX_CORE
SQLite3.SetDirectory(/*temp directory type*/2, Windows.Storage.ApplicationData.Current.TemporaryFolder.Path);
#endif
Sqlite3DatabaseHandle handle;
#if SILVERLIGHT || USE_CSHARP_SQLITE
var r = SQLite3.Open (databasePath, out handle, (int)openFlags, IntPtr.Zero);
#else
// open using the byte[]
// in the case where the path may include Unicode
// force open to using UTF-8 using sqlite3_open_v2
var databasePathAsBytes = GetNullTerminatedUtf8 (DatabasePath);
var r = SQLite3.Open (databasePathAsBytes, out handle, (int) openFlags, IntPtr.Zero);
#endif
Handle = handle;
if (r != SQLite3.Result.OK) {
throw SQLiteException.New (r, String.Format ("Could not open database file: {0} ({1})", DatabasePath, r));
}
_open = true; // Debugger Stops here !
StoreDateTimeAsTicks = storeDateTimeAsTicks;
BusyTimeout = TimeSpan.FromSeconds (0.1);
}
Я нашел много примеров файлов mbtiles, используемых в WPF, но ни одного в приложении Windows Store.
Поддерживают ли расширения SQLite для Windows Store dev файлы MBTiles в качестве баз данных? Если да, что я делаю не так?
1 ответ
Приложения Магазина Windows могут обращаться только к своим собственным каталогам, но не к личным файлам пользователя с правами администратора.
Прочитайте документацию, но вы, вероятно, хотите установить данные как часть вашего приложения.