先上一段代码:

  1. public EnvironmentSetting()
  2. {
  3. var appServer = GetServerSection();
  4. var protocol = GetProtocolSection();
  5. var cacheSection = GetCacheSection();
  6. var scriptSection = GetScriptSection();
  7.  
  8. CacheGlobalPeriod = cacheSection.ShareExpirePeriod;
  9. CacheUserPeriod = cacheSection.PersonalExpirePeriod;
  10.  
  11. ScriptSysAsmReferences = scriptSection.SysAssemblyReferences;
  12. ScriptAsmReferences = scriptSection.AssemblyReferences;
  13. GamePort = protocol.GamePort;
  14. GameIpAddress = string.IsNullOrEmpty(protocol.GameIpAddress) ? GetLocalIp() : protocol.GameIpAddress;
  15.  
  16. try
  17. {
  18. if (!string.IsNullOrEmpty(appServer.EntityAssemblyName))
  19. {
  20. EntityAssembly = Assembly.LoadFrom(appServer.EntityAssemblyName);
  21. }
  22. }
  23. catch (Exception ex)
  24. {
  25. TraceLog.WriteError("Load entity assembly error:\"{0}\" {1}", appServer.EntityAssemblyName, ex);
  26. }
  27. ActionDispatcher = new ScutActionDispatcher();
  28. InitSerializer();
  29. Reset();
  30. }

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

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

  1. private static AppServerSection GetServerSection()
  2. {
  3. return ConfigManager.Configger.GetFirstOrAddConfig<AppServerSection>();
  4. }
  1. public AppServerSection()
  2. {
  3. ProductCode = ConfigUtils.GetSetting("Product.Code", );
  4. ProductName = ConfigUtils.GetSetting("Product.Name", "Game");
  5. ProductServerId = ConfigUtils.GetSetting("Product.ServerId", );
  6. UserLoginDecodeKey = ConfigUtils.GetSetting("Product.ClientDesDeKey", "");
  7. ClientVersion = new Version(, , );
  8. Version ver;
  9. if (Version.TryParse(ConfigUtils.GetSetting("Product.ClientVersion", "1.0.0"), out ver))
  10. {
  11. ClientVersion = ver;
  12. }
  13.  
  14. PublishType = ConfigUtils.GetSetting("PublishType", "Release");
  15. ActionTimeOut = ConfigUtils.GetSetting("ActionTimeOut", );
  16. LanguageTypeName = ConfigUtils.GetSetting("Game.Language.TypeName", "Game.src.Locale.DefaultLanguage");
  17.  
  18. ActionTypeName = ConfigUtils.GetSetting("Game.Action.TypeName");
  19. if (string.IsNullOrEmpty(ActionTypeName))
  20. {
  21. string assemblyName = ConfigUtils.GetSetting("Game.Action.AssemblyName", "GameServer.CsScript");
  22. if (!string.IsNullOrEmpty(assemblyName))
  23. {
  24. ActionTypeName = assemblyName + ".Action.Action{0}," + assemblyName;
  25. }
  26. }
  27. ScriptTypeName = ConfigUtils.GetSetting("Game.Action.Script.TypeName", "Game.Script.Action{0}");
  28. EntityAssemblyName = ConfigUtils.GetSetting("Game.Entity.AssemblyName");
  29. DecodeFuncTypeName = ConfigUtils.GetSetting("Game.Script.DecodeFunc.TypeName", "");
  30. RemoteTypeName = ConfigUtils.GetSetting("Game.Remote.Script.TypeName", "Game.Script.Remote.{0}");
  31. AccountServerUrl = ConfigUtils.GetSetting("AccountServerUrl", "");
  32. }

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

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

  1. static EnvironmentSetting()
  2. {
  3. bool result;
  4. try
  5. {
  6. result = ConfigManager.Intialize("appServerConfigger");
  7. }
  8. catch (Exception)
  9. {
  10. result = false;
  11. }
  12. if (!result)
  13. {
  14. try
  15. {
  16. ConfigManager.GetConfigger<DefaultAppConfigger>();
  17. }
  18. catch (Exception ex)
  19. {
  20. TraceLog.WriteError("Configger init error:{0}", ex);
  21. }
  22. }
  23. LoadDecodeFunc();
  24. }
  1. public static bool Intialize(string sectionName)
  2. {
  3. lock (syncRoot)
  4. {
  5. var section = ConfigurationManager.GetSection(sectionName);
  6. if (section is IConfigger)
  7. {
  8. var instance = section as IConfigger;
  9. instance.Install();
  10. _configgerSet.Add(instance);
  11. _configger = instance;
  12. return true;
  13. }
  14. return false;
  15. }
  16. }

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

  1. ConfigManager.Intialize("appServerConfigger");
  2. ConfigManager.Intialize("ProtocolConfigger");
  3. ConfigManager.Intialize("CacheConfigger");
  4. ConfigManager.Intialize("ScriptConfigger");

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

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

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

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

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

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

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

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

  1.  

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. 简单的FOLLOW集演示程序

    /* * 该程序用于计算某个非终结符的 FOLLOW 集合 * RexfieldVon * 2013年6月30日16:02:47 */ #include <stdio.h> #includ ...

  2. Eclipse 在线汉化

    1. 打开Eclipse  , 进入菜单中 Help-->Install new Software.. 2. 到Eclipse 官网找到语言包地址,http://www.eclipse.org/ ...

  3. 字符集转换 字符类型转换 utf-8 gb2312 url

    vs默认是GB2312编码,你看到的程序源代码是,输出结果是,内部存储是, 1 如果你想改变内部存储可以用下面的这些函数 2 如果你想改变源代码的存储方式你可以用文本编辑工具修改之后重新编译 3 如果 ...

  4. ORACLE功能GREATEST功能说明具体实例

    1           语法 GREATEST(expr_1, expr_2, ...expr_n) 2           说明 GREATEST(expr_1, expr_2, ...expr_n ...

  5. javascript touch事件

    touchstart : 當手指觸摸屏幕時觸發:即使已經有一個手指放在了屏幕上也會觸發. touchmove : 當手指在屏幕上滑動時連續的觸發,在這個事件發生期間,商用preventDefault( ...

  6. Weibo SSO认证 和初次请求数据

    在进行SSO请求之前 我们要先去新浪微博的开放平台http://open.weibo.com/进行创建应用.以便得到appKey 和AppSecret. 点击创建应用 .进行资料填写  在这里 App ...

  7. BestCoder冠军赛 - 1009 Exploration 【Tarjan+并查集缩点】

    [题意] 给一个图,这个图中既有有向边,又有无向边,每条边只能走一次,问图中是否存在环. 最多10^6个点,10^6个无向边,10^6个有向边 [题解] 因为既有有向边又有无向边,所以不能单纯的用ta ...

  8. Pyhton开发【第五篇】:Python基础之杂货铺

    Python开发[第五篇]:Python基础之杂货铺   字符串格式化 Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进 ...

  9. Android Studio 使用GitHub

    Android Studio 使用GitHub 1.安装配置 默认大家都已经安装了git软件,参考下图进行git与as关联 配置git  设置GitHub用户信息  填写完用户名,密码后可以点击Tes ...

  10. codevs4203山区建小学

    /* 状态:f[i][j] 前i个村庄已经建了j个学校 转移:f[i][j]=min(f[i][j],f[ii][j-1]+s[ii+1][i]) 1<=ii<=i-1 */ #inclu ...