先上一段代码:

        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. Storm-1.0.1+ZooKeeper-3.4.8+Netty-4.1.3 HA集群安装

    Storm-1.0.1+ZooKeeper-3.4.8+Netty-4.1.3 HA集群安装 下载Storm-1.0.1 http://mirrors.tuna.tsinghua.edu.cn/apa ...

  2. windows server作为文件服务器如何精细控制权限

    最近使用windows server 2003搭建了文件服务器,对于其中关于共享文件权限的精细控制有了较深的体会. 当前实现基本的共享文件目录结构是(上传图片真心费劲,大家将就一下吧): |--部门1 ...

  3. spring注解方式实现定时器,并且cron表达式中不识别L的方法

    1.Spring的配置: <beans xmlns:task="http://www.springframework.org/schema/task" xsi:schemaL ...

  4. setState的同步更新

    react中的setState特点: 是异步操作函数: 组件在还没有渲染之前, this.setState 还没有被调用: 批量执行 State 转变时让 DOM 渲染更快(相对比一个一个的setSt ...

  5. mysql 更新有外键约束的字段

    给一个表的字段更新,发现 这个字段是外键,刚开始用了笨 的方法,取消外键,修改后,在添加, 网上百度了. 这样设置 先 关闭外键约束 SET FOREIGN_KEY_CHECKS=0; 执行完了 打开 ...

  6. Android中scrollview的scrollto方法不起作用的办法

    有时候,我们在onCreate函数中调用ScrollBy函数.ScrollTo函数,会出现无效果的情况 public class ShowTraffic extends Activity Scroll ...

  7. 网络接口 使用NSURLConnection完成Get和Post方法

    网络接口 使用NSURLConnection完成Get和Post方法 什么是URL: URL就是统一资源定位器(UniformResourceLocator:URL).通俗地说,它是用来指出某一项信息 ...

  8. 将JSON数组显示前台Table中

    将JSON数组显示前台Table中 在最近的学习中遇到一个小问题,如何把JSON数组显示在前台的table中,经过一番借鉴和学习之后终于解决了这个问题.具体的代码如下: (前提:利用ajax获取过来的 ...

  9. Python之路,Day12 - 那就做个堡垒机吧

    Python之路,Day12 - 那就做个堡垒机吧   本节内容 项目实战:运维堡垒机开发 前景介绍 到目前为止,很多公司对堡垒机依然不太感冒,其实是没有充分认识到堡垒机在IT管理中的重要作用的,很多 ...

  10. 封装对Cookie和Session设置或取值的类

    public class CookieHelper : System.Web.SessionState.IReadOnlySessionState    { public static void Se ...