J
Jens Weiermann
I'm writing kind of a "network monitor" application in .NET 2.0 (C#); At
runtime, the user should be able to configure all kinds of different
"sensors" and I want to serialize them to an xml file.
There are several different classes for different sensors, all derived from
an abstract base sensor class:
public class Sensor
{
public SensorResult Sense();
}
public class PingSensor: Sensor
{
string Hostname;
int timeout;
...
}
public class PortSensor: Sensor
{
string Hostname;
int Port;
...
}
....
Ideally, the resulting xml file would like this (for example):
<sensor type="Sensaction.PingSensor, sensaction.core"
name="Ping some server" host="SomeServer" timeout="5000"/>
<sensor type="Sensaction.PortSensor, sensaction.core"
name="Sql port on db server" host="dbserver" port="1433"/>
<sensor type="Sensaction.HttpSensor, sensaction.core"
name="Homepage availability" url="http://www.somedomain.com/index.htm"/>
I've seen the "Namespace.Class, Assembly" notation in several .config files
and like them pretty much (because some advanced users might want to create
these xml files by hand).
My questions are:
1. Is serialization the way to go, or am I better off with
System.Configuration.* ?
2. If it is serialization, how do I start? (I must admit I never did this
before)
Any help would be greatly appreciated!
Jens
runtime, the user should be able to configure all kinds of different
"sensors" and I want to serialize them to an xml file.
There are several different classes for different sensors, all derived from
an abstract base sensor class:
public class Sensor
{
public SensorResult Sense();
}
public class PingSensor: Sensor
{
string Hostname;
int timeout;
...
}
public class PortSensor: Sensor
{
string Hostname;
int Port;
...
}
....
Ideally, the resulting xml file would like this (for example):
<sensor type="Sensaction.PingSensor, sensaction.core"
name="Ping some server" host="SomeServer" timeout="5000"/>
<sensor type="Sensaction.PortSensor, sensaction.core"
name="Sql port on db server" host="dbserver" port="1433"/>
<sensor type="Sensaction.HttpSensor, sensaction.core"
name="Homepage availability" url="http://www.somedomain.com/index.htm"/>
I've seen the "Namespace.Class, Assembly" notation in several .config files
and like them pretty much (because some advanced users might want to create
these xml files by hand).
My questions are:
1. Is serialization the way to go, or am I better off with
System.Configuration.* ?
2. If it is serialization, how do I start? (I must admit I never did this
before)
Any help would be greatly appreciated!
Jens