Right, so I have a Windows service that goes off and does some work on a server every few minutes. The service reads a whole lot of info (host, username, port etc) regarding the server it's connecting to from the App.config and it works just great.
I now have a requirement that the service caters for n different servers. So now my service needs to read from the App.config and do what it needs to do for server1..serverN sequentially. Wait a predetermined time and then start at server1 again.
I don't know how or what would be the best way to store n sets of server settings in the App.config and then programatically determine how many sets of settings there are and then read each set.
I've thought of having a setting that tells me that there are 5 servers and then having settings for server1..server5 but that's really not elegant.
Is there a better way to do this?
My full source file is below:
using System;
using System.Collections;
using System.Text;
using System.Configuration;
using System.Xml;
namespace FTPConfig
{
public class MyAppConfig : ConfigurationSection
{
public static MyAppConfig GetConfiguration()
{
MyAppConfig configuration = ConfigurationManager.GetSection("MainSettings") as MyAppConfig;
if (configuration != null) return configuration;
return new MyAppConfig();
}
}
[ConfigurationProperty("host", IsRequired = true)]
public String Host
{
get
{
return this["host"] as string;
}
}
}