Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What options are available for local state persistence in .Net

I'm looking for good options for persisting local state of an application (created in .Net / C#.)

I've considered rolling my own solution, or using a simple local database such as Sqllite, however I thought I'd ask the SO community what options are available.

The application I'm working on exists on a Kiosk, and I will need to maintain local state in case of accidental shutdown and other similar exceptions.

What do you recommend?

Update

Well, after further review I decided to use SQLite with DbLinq, the main alternative contender was SQL Server Compact edition, but there are several factors which I found important, which placed SQLite above SQLCE.

Notably.

  • The API provided by SQLCE (IMO) wasn't as rich as the ones provided by both SQLite.net or DbLinq.
  • SQLCE runtime performance wasn't as good as SQLite.
  • SQLite being open-source is a useful factor.

Why I didn't use Properties.Settings or app.config?

For my use case I needed something like a (easily) query-able event log (I need to allow auditing of credit transactions.) The primary state value I was addressing here was available credit on a kiosk. So to restore my state variables at application start up, I can query the log for the last entry and get the required values from there.

When you only need to store a value and retrieve it Properties.Settings or app.config are perfectly adequate places to do this.

like image 544
ocodo Avatar asked Jan 19 '23 17:01

ocodo


1 Answers

I would recommend XmlSerializer or BinaryFormatter, you can look them both on SO or google.

Your choice will depend on few preferences such as size of dataset or ability to serialize it quickly.

And both are really quick way IF YOU NEED whole app state saved in one go.

However, if you need to save app state part by part, as changes occur, you'll be better of with some kind of a database, http://www.sqlite.org/ for example.

http://www.jonasjohn.de/snippets/csharp/xmlserializer-example.htm

http://www.jpreece.com/csharp/serialization-tutorial/

like image 62
Daniel Mošmondor Avatar answered Mar 03 '23 01:03

Daniel Mošmondor