views:

746

answers:

2

I'm writing a C# service that I want to be able to use on Windows and Mono. I've just started experimenting with Mono and am trying to determine the best way to store settings to control the service that works for both Windows and Mono.

  1. Settings file where service is installed

    • Pros: Same code for each platform, easy to find for editing
    • Cons: Permissions, Windows probably won't like writing to the file
  2. Settings file in platform storage (%APPDATA, /etc, ...)

    • Pros: Will have permissions, easier to find for editing
    • Cons: More coding required to handle each platform
  3. Small database (SQLite maybe?)

    • Pros: Easier to write code to store and retrieve settings
    • Cons: Not easy to edit manually, same problem of where to store

Which do you think is the best, or do you have a better suggestion?
I will also probably be writing a command line client to allow for easier changing of settings, will this change how settings should be stored?

A: 

If you have more than a handful of settings, SQLite is gonna give you easy and scalable storage and retrieval. Just install the sqlite-manager Firefox extension, and you've solved the editing problem...

Shog9
What about where to store the database?
Samuel
Also, what should you do regarding the SQLite binaries? And what about platform access to SQLite from C#?
Samuel
Just toss it next to the app. Screw Windows, there's a GUI for permissions...
Shog9
http://stackoverflow.com/questions/741113/sqlite-mono-c-cross-platform
Shog9
+4  A: 

Take a look at IsolatedStorage. This is an API for providing you with per-application storage, it's built into .NET and is supported in Mono. The API provides you with file IO on files that are stored in a location managed by the framework: in Mono it'll be a ~/.isolatedstorage directory, in Windows it'll be somewhere in the user's Documents and Settings.

With this API, you can maintain your settings file without having to worry about operating system specifics or permissions.

Ilya Haykinson
Had no idea IsolatedStorage was implemented in Mono. Looks like SQLite ADO.NET has IsolatedStorage support planned.
Samuel
IsolatedStorage doesn't seem to allow sharing of a store across multiple projects. That kind of kills what I want to do. It also dies if you move the assembly.
Samuel
Are you sure? What if you request the isolated storage store for IsolatedStorageScope.User? I haven't tried this, but it may work...
Ilya Haykinson