先上一段代码:

        public EnvironmentSetting()
{
var appServer = GetServerSection();
var protocol = GetProtocolSection();
var cacheSection = GetCacheSection();
var scriptSection = GetScriptSection(); CacheGlobalPeriod = cacheSection.ShareExpirePeriod;
CacheUserPeriod = cacheSection.PersonalExpirePeriod; ScriptSysAsmReferences = scriptSection.SysAssemblyReferences;
ScriptAsmReferences = scriptSection.AssemblyReferences;
GamePort = protocol.GamePort;
GameIpAddress = string.IsNullOrEmpty(protocol.GameIpAddress) ? GetLocalIp() : protocol.GameIpAddress; try
{
if (!string.IsNullOrEmpty(appServer.EntityAssemblyName))
{
EntityAssembly = Assembly.LoadFrom(appServer.EntityAssemblyName);
}
}
catch (Exception ex)
{
TraceLog.WriteError("Load entity assembly error:\"{0}\" {1}", appServer.EntityAssemblyName, ex);
}
ActionDispatcher = new ScutActionDispatcher();
InitSerializer();
Reset();
}

  可以看到,配置都是通过 GetServerSection、GetProtocolSection 等API导入的。

  再来看一下 GetServerSction 的具体操作:

        private static AppServerSection GetServerSection()
{
return ConfigManager.Configger.GetFirstOrAddConfig<AppServerSection>();
}
        public AppServerSection()
{
ProductCode = ConfigUtils.GetSetting("Product.Code", );
ProductName = ConfigUtils.GetSetting("Product.Name", "Game");
ProductServerId = ConfigUtils.GetSetting("Product.ServerId", );
UserLoginDecodeKey = ConfigUtils.GetSetting("Product.ClientDesDeKey", "");
ClientVersion = new Version(, , );
Version ver;
if (Version.TryParse(ConfigUtils.GetSetting("Product.ClientVersion", "1.0.0"), out ver))
{
ClientVersion = ver;
} PublishType = ConfigUtils.GetSetting("PublishType", "Release");
ActionTimeOut = ConfigUtils.GetSetting("ActionTimeOut", );
LanguageTypeName = ConfigUtils.GetSetting("Game.Language.TypeName", "Game.src.Locale.DefaultLanguage"); ActionTypeName = ConfigUtils.GetSetting("Game.Action.TypeName");
if (string.IsNullOrEmpty(ActionTypeName))
{
string assemblyName = ConfigUtils.GetSetting("Game.Action.AssemblyName", "GameServer.CsScript");
if (!string.IsNullOrEmpty(assemblyName))
{
ActionTypeName = assemblyName + ".Action.Action{0}," + assemblyName;
}
}
ScriptTypeName = ConfigUtils.GetSetting("Game.Action.Script.TypeName", "Game.Script.Action{0}");
EntityAssemblyName = ConfigUtils.GetSetting("Game.Entity.AssemblyName");
DecodeFuncTypeName = ConfigUtils.GetSetting("Game.Script.DecodeFunc.TypeName", "");
RemoteTypeName = ConfigUtils.GetSetting("Game.Remote.Script.TypeName", "Game.Script.Remote.{0}");
AccountServerUrl = ConfigUtils.GetSetting("AccountServerUrl", "");
}

  ConfigUtils 是控制 app.config 配置的。那么,我们可以很清楚地明白,Scut 的配置,如果在 app.config 中有该字段,则使用配置文件的值,如果没有,则使用程序默认值。

  那么,我们是否可以完全由外部配置来启动,并更加清晰地管理外部配置呢?

        static EnvironmentSetting()
{
bool result;
try
{
result = ConfigManager.Intialize("appServerConfigger");
}
catch (Exception)
{
result = false;
}
if (!result)
{
try
{
ConfigManager.GetConfigger<DefaultAppConfigger>();
}
catch (Exception ex)
{
TraceLog.WriteError("Configger init error:{0}", ex);
}
}
LoadDecodeFunc();
}
        public static bool Intialize(string sectionName)
{
lock (syncRoot)
{
var section = ConfigurationManager.GetSection(sectionName);
if (section is IConfigger)
{
var instance = section as IConfigger;
instance.Install();
_configgerSet.Add(instance);
_configger = instance;
return true;
}
return false;
}
}

  我们可以在 static EnvironmentSetting 中,直接从配置文件中读取全部配置:

ConfigManager.Intialize("appServerConfigger");
ConfigManager.Intialize("ProtocolConfigger");
ConfigManager.Intialize("CacheConfigger");
ConfigManager.Intialize("ScriptConfigger");

  同时,从 DataDefaultConfigger 派生出 appServerConfigger、ProtocolConfigger、CacheConfigger、ScriptConfigger。

  每个 Configger 还应包括相应的配置:AppServerSection、ProtocolSection、CacheSection、ScriptSection。

  每个 Configger 还应重写 LoadConfigData 接口,将数据从 .config 中读入 appServerConfigger 的 AppServerSection 中...

  最后,还应在 app.config 中添加所有的自定义配置节。

  在写 app.config 的过程中出现了问题:

  首先测试性地修改 appServerConfigger,添加测试变量:

    public class DefaultAppConfigger : DefaultDataConfigger
{
public int ProductCode { get; set; }
...
}
  <configSections>
<section name="appServerConfigger" type="ZyGames.Framework.Game.Runtime.DefaultAppConfigger, ZyGames.Framework.Game" requirePermission="false"/>
</configSections> <appServerConfigger>
<add key="ProductCode" value=""/>
</appServerConfigger>

  这样在 GetSection 时,执行 add 操作时就会抛出异常了。

												

Scut:参数导入方式(有遗留疑问)的更多相关文章

  1. mybatis mapper xml文件的导入方式和查询方式

    mybatis mapper xml文件的导入方式和查询方式 ssm框架 Mybatis  mapper与SQLSession的关系 每个基于MyBatis的应用都是以一个SqlSessionFact ...

  2. 将Hive统计分析结果导入到MySQL数据库表中(一)——Sqoop导入方式

    https://blog.csdn.net/niityzu/article/details/45190787 交通流的数据分析,需求是对于海量的城市交通数据,需要使用MapReduce清洗后导入到HB ...

  3. 相机标定过程(opencv) + matlab参数导入opencv + matlab标定和矫正

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 辛苦原创所得,转载请注明出处 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ...

  4. EndNote(二)之英文引文导入方式

    在上一篇EndNote教程(一)--基本介绍中介绍了基本使用,今天将来介绍如何将常用文献引文导入EndNote中. EndNote在文献管理方面有着很多优点,可以节约很多精力.但是,不同文献查询网站可 ...

  5. 【hive】——Hive四种数据导入方式

    Hive的几种常见的数据导入方式这里介绍四种:(1).从本地文件系统中导入数据到Hive表:(2).从HDFS上导入数据到Hive表:(3).从别的表中查询出相应的数据并导入到Hive表中:(4).在 ...

  6. [Spring MVC] - SpringMVC的各种参数绑定方式

    SpringMVC的各种参数绑定方式 1. 基本数据类型(以int为例,其他类似):Controller代码: @RequestMapping("saysth.do") publi ...

  7. HIVE几种数据导入方式

    HIVE几种数据导入方式 今天的话题是总结Hive的几种常见的数据导入方式,我总结为四种:(1).从本地文件系统中导入数据到Hive表:(2).从HDFS上导入数据到Hive表:(3).从别的表中查询 ...

  8. SpringMVC的各种参数绑定方式

    1. 基本数据类型(以int为例,其他类似):2. 包装类型(以Integer为例,其他类似):3. 自定义对象类型:4. 自定义复合对象类型:5. List绑定:6. Set绑定:7. Map绑定: ...

  9. 十一、Struts2封装请求参数的方式

    十一.Struts2封装请求参数的方式 方式一.Action 本身作为model对象,通过成员setter封装(一个名字为params的拦截器干的) 注意:表单中的名称要和动作类中的名称一致(这是必须 ...

随机推荐

  1. servlet简介

    web 开发分为两种:静态开发(使用html)和动态开发(使用servlet/jsp,jsp就是servlet,ASP ,PHP) 所以servlet是sun公司提供的一门专门用于开发动态web资源的 ...

  2. angular2的管道初体验

    ng管道是应用里面比较重要的一个技术,他涉及很多功能 包括排序过滤 废话不说 直接上代码 新建个文件夹吧这个samplepipe.ts放进去 然后 你要做什么 在里面写管道代码 然后在app.modu ...

  3. linux常用命令 http://mirrors.163.com/ubuntu-releases/12.04/

    由于记忆力有限,把平时常用的Linux命令整理出来,以便随时查阅: linux 基本命令 ls     (list 显示当前目录下文件和目录 ls -l 详细显示 =ll ) [root@linux ...

  4. [C++] [算法] KMP算法

    KMP串匹配算法是一个经典的算法. 传统BF算法是传统的字符串匹配算法.很好理解.叶实现.但时间复杂度太高. 本文将从字符串模式字符串被称为.为了匹配字符串被称为主弦. KMP配时能够少移动从串的位置 ...

  5. jQuery代码优化 事件委托篇

    <转自 http://www.jb51.net/article/28770.htm> 参考文章:  解密jQuery事件核心 - 绑定设计(一) 参考文章:  解密jQuery事件核心 - ...

  6. 使用搬瓦工搭建javaweb环境

        /* 本文是基于搬瓦工vps的centos-6-x86_64的Linux系统搭建. 需准备的工具:1.putty(用于连接Linux系统)  2.WinSCP(搬瓦工官方提供的ftp上传下载工 ...

  7. Android关闭系统锁屏

    昨晚探索了一下Android系统内的目录,意外发现系统锁屏的数据库 使用adb shell进入系统根目录 adb shell su sqlite3 data/system/locksettings.d ...

  8. C#解leetcode 16. 3Sum Closest

    Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...

  9. Ecstore后台中显示页面display,page,singlepage方法的区别?

    dispaly 显示的页面不包含框架的其他页面,只是本身的页面(使用范围:Ecstore的前端.后端). page 显示的页面包含在框架的里面(使用范围:Ecstore的前端.后端). singlep ...

  10. mysql查看binlog日志

    1.语法:(用于在二进制日志中显示事件.如果您不指定’log_name’,则显示第一个二进制日志.LIMIT子句和SELECT语句具有相同的语法.) show binlog events [IN 'l ...