Scut:参数导入方式(有遗留疑问)
先上一段代码:
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:参数导入方式(有遗留疑问)的更多相关文章
- mybatis mapper xml文件的导入方式和查询方式
mybatis mapper xml文件的导入方式和查询方式 ssm框架 Mybatis mapper与SQLSession的关系 每个基于MyBatis的应用都是以一个SqlSessionFact ...
- 将Hive统计分析结果导入到MySQL数据库表中(一)——Sqoop导入方式
https://blog.csdn.net/niityzu/article/details/45190787 交通流的数据分析,需求是对于海量的城市交通数据,需要使用MapReduce清洗后导入到HB ...
- 相机标定过程(opencv) + matlab参数导入opencv + matlab标定和矫正
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 辛苦原创所得,转载请注明出处 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ...
- EndNote(二)之英文引文导入方式
在上一篇EndNote教程(一)--基本介绍中介绍了基本使用,今天将来介绍如何将常用文献引文导入EndNote中. EndNote在文献管理方面有着很多优点,可以节约很多精力.但是,不同文献查询网站可 ...
- 【hive】——Hive四种数据导入方式
Hive的几种常见的数据导入方式这里介绍四种:(1).从本地文件系统中导入数据到Hive表:(2).从HDFS上导入数据到Hive表:(3).从别的表中查询出相应的数据并导入到Hive表中:(4).在 ...
- [Spring MVC] - SpringMVC的各种参数绑定方式
SpringMVC的各种参数绑定方式 1. 基本数据类型(以int为例,其他类似):Controller代码: @RequestMapping("saysth.do") publi ...
- HIVE几种数据导入方式
HIVE几种数据导入方式 今天的话题是总结Hive的几种常见的数据导入方式,我总结为四种:(1).从本地文件系统中导入数据到Hive表:(2).从HDFS上导入数据到Hive表:(3).从别的表中查询 ...
- SpringMVC的各种参数绑定方式
1. 基本数据类型(以int为例,其他类似):2. 包装类型(以Integer为例,其他类似):3. 自定义对象类型:4. 自定义复合对象类型:5. List绑定:6. Set绑定:7. Map绑定: ...
- 十一、Struts2封装请求参数的方式
十一.Struts2封装请求参数的方式 方式一.Action 本身作为model对象,通过成员setter封装(一个名字为params的拦截器干的) 注意:表单中的名称要和动作类中的名称一致(这是必须 ...
随机推荐
- jQuery整体架构源码解析
最近一直在研读 jQuery 源码,初看源码一头雾水毫无头绪,真正静下心来细看写的真是精妙,让你感叹代码之美. 其结构明晰,高内聚.低耦合,兼具优秀的性能与便利的扩展性,在浏览器的兼容性(功能缺陷.渐 ...
- Cyclic Nacklace - HDU 3746(next求循环节)
题目大意:给你一些串,问如果想让这个串里面的循环节至少循环两次,需要添加几个字符(只能在最前面或者最后面添加).比如ababc 需要添加5个就是添加ababc. 分析:其实字符串的长度len-next ...
- Python监控日志程序
一个简易的日志监控的脚本,功能如下:1.windows环境2.当匹配日志关键字时会发出声音,匹配的关键字不同,播放的声音不同3.能做到实时响应 注意:是在win环境下哦 直接上代码吧 1 2 3 4 ...
- 基于RMAN的异机数据库克隆(rman duplicate)
对于基于生产环境下的数据库的版本升级或者测试新的应用程序的性能及其影响,备份恢复等等,我们可以采取从生产环境以克隆的方式将其克隆到本地而不影响生产数据库的正常使用.实现这个功能我们可以借助rman d ...
- [Unity-24] Unity的四种载入场景的方法
Unity官方提供了4种载入场景(scene)的方法.各自是: 1. Application.LoadLevel():同步载入 2. Application.LoadLevelAsync():异步载入 ...
- C\C++代码优化的27个建议
1. 记住阿姆达尔定律: funccost是函数func运行时间百分比,funcspeedup是你优化函数的运行的系数. 所以,如果你优化了函数TriangleIntersect执行40%的运行时间, ...
- EEPlat 的数据层模式
EEPlat 的数据库底层架构能够同一时候支持多种数据库的集成应用.同一时候能够支持分布式数据库的集成应用.业务对象通过指定数据源与对应的数据库通过数据源层进行数据交互,数据源层通过数据库种类.自己主 ...
- mysql在高内存、IO利用率上的几个优化点 (sync+fsync) 猎豹移动技术博客
http://dev.cmcm.com/archives/107 Posted on 2014年10月16日 by liuding | 7条评论 以下优化都是基于CentOS系统下的一些优化整理,有不 ...
- Java 数据类型转换(转换成字节型)
package com.mystudypro.byteutil; import java.io.UnsupportedEncodingException; public class ConToByte ...
- updatepanel的用法之triggers
triggers有的两种触发器asyncpostbacktrigger和postbacktrigger.asyncpostbacktrigger(异步回调触发器):局部刷新,只刷新updatepane ...