• supersocket/SocketEngin/BootstrapFactory.cs 详解


    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
    {
        /// <summary>
        /// Bootstrap Factory
        /// </summary>
        public static class BootstrapFactory
        {
            /// <summary>
            /// Creates the bootstrap.
            /// </summary>
            /// <param name="config">The config.</param>
            /// <returns></returns>
            public static IBootstrap CreateBootstrap(IConfigurationSource config)
            {
                if (config == null)
                    throw new ArgumentNullException("config");
    
    
                if (config.Isolation == IsolationMode.AppDomain)
                    return new AppDomainBootstrap(config);
                else if (config.Isolation == IsolationMode.Process)
                    return new ProcessBootstrap(config);
                else
                    return new DefaultBootstrap(config);
            }
    
    
            /// <summary>
            /// Creates the bootstrap from app configuration's socketServer section.
            /// </summary>
            /// <returns></returns>
            public static IBootstrap CreateBootstrap()
            {
                var configSection = ConfigurationManager.GetSection("superSocket");
    
    
                if (configSection == null)//to keep compatible with old version
                    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);
            }
    
    
            /// <summary>
            /// Creates the bootstrap.
            /// </summary>
            /// <param name="configSectionName">Name of the config section.</param>
            /// <returns></returns>
            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);
            }
    
    
            /// <summary>
            /// Creates the bootstrap from configuration file.
            /// </summary>
            /// <param name="configFile">The configuration file.</param>
            /// <returns></returns>
            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);
            }
        }
    }
    
  • 相关阅读:
    读书是最划算的自我投资,免费送几本最好的Python学习电子书
    一个出身寒门的状元之编程
    幼儿园小朋友都在学人工智能了,已经从小学毕业的我们该如何学?
    python语音识别终极指南
    Python可视化神器——pyecharts的超详细使用指南!
    用 Python 分析过往 36 年春晚节目数据,发现一些趣事
    拉勾网数据分析职位分析
    按时分秒对数据进行分箱
    numpy
    基于协同过滤的推荐系统案列
  • 原文地址:https://www.cnblogs.com/little-white/p/3465965.html
Copyright © 2020-2023  润新知