123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using SuperSocket.SocketBase;
- using SuperSocket.SocketEngine.Configuration;
- using SuperSocket.SocketBase.Config;
- using System.Configuration;
- namespace SuperSocket.SocketEngine
- {
-
-
-
- public static class BootstrapFactory
- {
-
-
-
-
-
- public static IBootstrap CreateBootstrap(IConfigurationSource config)
- {
- if (config == null)
- throw new ArgumentNullException("config");
- IBootstrap bootstrap;
- if (config.Isolation == IsolationMode.AppDomain)
- bootstrap = new AppDomainBootstrap(config);
- else if (config.Isolation == IsolationMode.Process)
- bootstrap = new ProcessBootstrap(config);
- else
- bootstrap = new DefaultBootstrap(config);
- var section = config as ConfigurationSection;
- if (section != null)
- ConfigurationWatcher.Watch(section, bootstrap);
- return bootstrap;
- }
-
-
-
-
- public static IBootstrap CreateBootstrap()
- {
- var configSection = ConfigurationManager.GetSection("superSocket");
- if (configSection == null)
- configSection = ConfigurationManager.GetSection("socketServer");
- if(configSection == null)
- throw new ConfigurationErrorsException("Missing 'superSocket' or 'socketServer' configuration section.");
- var configSource = configSection as IConfigurationSource;
- if(configSource == null)
- throw new ConfigurationErrorsException("Invalid 'superSocket' or 'socketServer' configuration section.");
- return CreateBootstrap(configSource);
- }
-
-
-
-
-
- public static IBootstrap CreateBootstrap(string configSectionName)
- {
- var configSource = ConfigurationManager.GetSection(configSectionName) as IConfigurationSource;
- if (configSource == null)
- throw new ArgumentException("Invalid section name.");
- return CreateBootstrap(configSource);
- }
-
-
-
-
-
- public static IBootstrap CreateBootstrapFromConfigFile(string configFile)
- {
- ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
- fileMap.ExeConfigFilename = configFile;
- var config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
- var configSection = config.GetSection("superSocket");
- if (configSection == null)
- configSection = config.GetSection("socketServer");
- return CreateBootstrap(configSection as IConfigurationSource);
- }
- }
- }
|