Reputation: 8187
I'm building a processing system, and I would like to configure it using an XML.
What technology should I use?, I have a lot of options:
1] I can serilize a dumy object into xml, change the content and then load it every time I run the app. I'v implemented this, because you don't have to write a lot of code to make this work, but It's a very dirty process. So I'm currently unhapppy.
2] You can use a XElement to read XMLs, just pass one to the constructer and let it build itself from that.
3] Use the .NET application settings architecture. <- I don't really undstand how this works yet.
I want the code to be simple and stupid, and to allow the code to change the config file for example, change the date of the last successful event.
Anyways if you can point me to useful places, and give me some direction, I'd really appreciate it.
Cheers.
Upvotes: 1
Views: 2863
Reputation: 12552
The easy and correct way to do it would be indeed to use the settings files. You can add as many as you need and insert whatever configurations. Here's and example about how it's used. Let me now if you'll need more examples and tutorials.
Upvotes: 0
Reputation: 27323
.NET Application Settings is the way to go.
Doubleclick on properties in your Visual Studio project. Choose 'Settings' and add a new settings file.
Depending on your desired features you can choose a setting to be in the 'application' scope or in the 'user' scope:
User
Advantage: configurable from the application itself.
Application
Advantage: configurable from the app.config
file in your application's folder
So save all the settings you want to edit in xml, in the Application scope. And save the LastSuccessfulEvent
in your User scope.
You can retrieve your settings from the Properties.Settings.Default
class.
Make sure that when you change a setting from code, to call the Save()
function.
Settings.Default.LastSuccessfulEvent = "NewValue";
Settings.Default.Save();
Upvotes: 4