gpt4 book ai didi

windows-phone-7 - Sterling 数据库不会在 Windows Phone 上持续存在

转载 作者:行者123 更新时间:2023-12-04 06:57:56 25 4
gpt4 key购买 nike

我遵循了几个人的 sterling 数据库示例。他们似乎都不适合我。当我在我的数据库中保留一些东西时,在调试时,一切都清楚地使用 sterling(在我的手机上,而不是模拟器上)保留下来。但是,当我重新启动我的应用程序时,数据库是空的。是否有人遇到同样的问题。或者有人有一个完整的工作示例。我知道我的序列化和保存工作......只要我不重新启动我的应用程序加载我的状态工作......

我的 app.cs 中的代码

    public static ISterlingDatabaseInstance Database { get; private set; }
private static SterlingEngine _engine;
private static SterlingDefaultLogger _logger;

private void Application_Launching(object sender, LaunchingEventArgs e)
{
ActivateEngine();
}

// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
ActivateEngine();
}

// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
DeactivateEngine();
}

// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
DeactivateEngine();
}



private void ActivateEngine()
{
_engine = new SterlingEngine();
_logger = new SterlingDefaultLogger(SterlingLogLevel.Information);
_engine.Activate();
Database = _engine.SterlingDatabase.RegisterDatabase<SokobanDb>();
}

private void DeactivateEngine()
{
_logger.Detach();
_engine.Dispose();
Database = null;
_engine = null;
}

我的 viewModel 中的代码

    public void LoadState(int level)
{
var levelState = App.Database.Load<LevelState>(level);
if (levelState != null)
{
//TODO: check if game started, then create board from boardstring property else create new board
//Labyrint = new Labyrint(Factory.CreateBoard());
NewGame(level);
}
else
{
NewGame(level);
}
}

public void SaveState()
{
var levelState = new LevelState { LevelId = _level, Moves = Labyrint.Moves, Board = Labyrint.ToString() };
App.Database.Save(levelState);
App.Database.Flush(); //Required to clean indexes etc.
}

最佳答案

默认的 Sterling 数据库使用内存驱动程序。要坚持下去,请将其传递给一个独立的存储驱动程序。根据文档指南快速入门:

https://sites.google.com/site/sterlingdatabase/sterling-user-guide/getting-started

代码如下:

_databaseInstance = _engine.SterlingDatabase.RegisterDatabase(new IsolatedStorageDriver());

请注意传入的隔离存储驱动程序的实例。这应该会为您完成。

如有疑问,请查看源代码附带的单元测试。其中包含大量内存、独立存储等示例,以展示用于设置它的各种模式。

关于windows-phone-7 - Sterling 数据库不会在 Windows Phone 上持续存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9831297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com