This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class NetFwMgr : DynamicComBase | |
| { | |
| /// <summary> | |
| /// Default constructor. | |
| /// </summary> | |
| public NetFwMgr() | |
| { | |
| // Initialize the COM object. | |
| Type fwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr"); | |
| base.comObj = Activator.CreateInstance(fwMgrType); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IServerConfiguration | |
| { | |
| int Port { get; set; } | |
| string Server { get; set; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8" ?> | |
| <configuration> | |
| <configSections> | |
| <section name="srvConfig" type="Sandrino.MyApplication.ServerConfigurationSection, Sandrino.MyApplication"/> | |
| </configSections> | |
| <srvConfig server="sandrino.loc" port="1986"/> | |
| </configuration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public abstract class ConfigurationProviderBase<TSection, TException> | |
| where TSection : ConfigurationSection | |
| where TException : Exception, new() | |
| { | |
| /// <summary> | |
| /// Name of the section to read from the app.config. | |
| /// </summary> | |
| private string sectionName; | |
| /// <summary> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ServerConfigurationProvider : ConfigurationProviderBase<ServerConfigurationSection, ServerConfigurationMissingException>, IServerConfigurationProvider | |
| { | |
| public ServerConfigurationProvider() | |
| : base("srvConfig") | |
| { | |
| } | |
| /// <summary> | |
| /// Read the configuration and just return the interface. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IServerConfigurationProvider | |
| { | |
| IServerConfiguration Read(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ConfigurationModule : StandardModule | |
| { | |
| public override void Load() | |
| { | |
| Bind<IServerConfigurationProvider>().To<ServerConfigurationProvider>(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| using (IKernel krn = new StandardKernel()) | |
| { | |
| // Create bindings. | |
| krn.Load(new ConfigurationModule()); | |
| // Get the provider and read the app.config. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void RegisterConfiguration(string filename) | |
| { | |
| krn = new StandardKernel(new InlineModule(m => m | |
| .Bind<IServerConfigurationProvider>() | |
| .ToMethod<IServerConfigurationProvider>( | |
| (e) => | |
| { | |
| ServerConfigurationProvider config = new ServerConfigurationProvider(); | |
| config.SetConfigurationFile(filename); | |
| return config; |