Sterling database is not saved on Windows phone

I have followed database examples from multiple instances. None of them work for me. When I save some things in my database, everything is clearly saved using sterling (on my phone, not an emulator) when debugging. However, when I restart my application, the database is empty. Someone else is experiencing the same problem. Or does someone have a complete working example. I know my serialization and rescue works ... Until I reload the app, load my works ...

The code is in my application.

    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;
    }

      

Code in my ModelModel

    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.
    }

      

+3


source to share


1 answer


The Sterling database uses the in-memory driver by default. Pass the isolated storage driver to it to continue. From the Quick Load Documentation Guide:

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

The code looks like this:



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

Note that an instance of the sandboxed storage driver should do this for you.

If in doubt, check out the unit tests provided with the source. They contain many examples of memory, isolated storage, etc. to show various templates for configuring it.

+4


source







All Articles