回来看看
感谢TOR,我才能回来看看.
不能访问blogsome已经很久了.不知道还要被封多久.
问候GFW他老木.
Create a web application with chinese and english resource strings.resx and strings.zh-CN.resx.
Read resource with following code:
ResourceManager L10N = new ResourceManager(”WebAppCulture.strings”, typeof(_Default).Assembly);
this.Label1.Text = L10N.GetString(”Name”);
this.Label2.Text = “Culture: “+Thread.CurrentThread.CurrentCulture.Name;
this.Label3.Text = “UICulture: ” + Thread.CurrentThread.CurrentUICulture.Name;
相关设定有:
OS
IE
Page:Culture
Page:UICulture
结果有:
CurrentThread.CurrentCulture
CurrentThread.CurrentUICulture
结论,IE Language Preference 和Page:Culture相互作用,影响当前线程的Culture.对UICulture无影响
如果不指定Page:Culture, CurrentThread.CurrentCulture为OS的culture
如果指定了Page:Culture, CurrentThread.CurrentCulture为IE指定的culture
如果不支持IE指定的culture, CurrentThread.CurrentCulture为Page:Culture指定的culture
如果不指定Page:UICulture, CurrentThread.CurrentUICulture为OS指定的culture
如果指定了Page:UICulture, CurrentThread.CurrentUICulture为Page:UICulture指定的culture
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/localization/culture.aspx#autoculture
If the first language in the list matches the name of a neutral culture supported by the .NET Framework, ASP.NET will try to use the function CultureInfo.CreateSpecificCulture() to create a specific culture for the purpose of formatting.
If the first language in the list isn’t a culture supported by the .NET Framework, ASP.NET will fall back to the culture specified after the colon in the Culture declaration.
Self-defence
Punch
Kick
Head butt
Stand-Up Aggression
Choke
Collar Grab
Bear Hug Over the Arms
By Steve McConnell
http://blogs.construx.com/blogs/stevemcc/archive/2007/06/15/Classic-Mistakes-Updated.aspx
Confusing estimates with targets
Excessive multi-tasking
Assuming global development has a negligible impact on total effort
Unclear project vision
Trusting the map more than the terrain
Outsourcing to reduce cost
Letting a team go dark (replaces the previous “lack of management controls”)
|
People-Related Mistakes |
Process-Related Mistakes |
Product-Related Mistakes |
Technology-Related Mistakes |
|||
|
1. Undermined motivation 2. Weak personnel 3. Uncontrolled problem employees 4. Heroics 5. Adding people to a late project 6. Noisy, crowded offices 7. Friction between developers and customers 8. Unrealistic expectations 9. Lack of effective project sponsorship 10. Lack of stakeholder buy-in 11. Lack of user input 12. Politics placed over substance 13. Wishful thinking |
14. Overly optimistic schedules 16. Insufficient risk management 17. Contractor failure Insufficient planning 18. Abandonment of planning under pressure 19. Wasted time during the fuzzy front end 20. Shortchanged upstream activities 21. Inadequate design 22. Shortchanged quality assurance 23. Insufficient management controls 24. Premature or too frequent convergence 25. Omitting necessary tasks from estimates 26. Planning to catch up later 27. Code-like-hell programming |
28. Requirements gold-plating 29. Feature creep 30. Developer gold-plating 31. Push me, pull me negotiation 32. Research-oriented development |
33. Silver-bullet syndrome 34. Overestimated savings from new tools or methods 35. Switching tools in the middle of a project 36. Lack of automated source |
Currently, Vista just support single session of remote desktop connection.
There is a patch broking this limitation.
vista_concurrent_rdp_sessions.rar
Instruction:
1.Copy termsrv.dll.patched32bit into %SystemRoot%\System32\
2.Run patch_termsrv_32bit.bat as Administrator.
3.Reboot.
http://baike.baidu.com/history/id=787492
重要中国将领及人物
卫立煌 - 1944年第二次远征军总司令
戴安澜 - 第200师师长
廖耀湘 - 第22师师长
宋希濂 - 第11集团军军长
李弥 - 第8军副军长兼荣一师师长
杜聿明 - 1942年第一次远征军总指挥
余韶 - 第96师师长
甘丽初 - 第6军军长
彭壁生 - 第49师师长
吕国铨 - 第93师师长
刘伯龙 - 第28师师长
马维骥 - 第29师师长
张珍 - 第66军军长
孙立人 - 新38师师长
史迪威 - (美国人)中印缅战区参谋长,中国驻印军总司令
1.
美方参谋:约瑟夫.史迪威
1942年2月,中国10万远征军入缅,其编制为第5军,第6军和第66军。
第5军 军长杜聿明, 下辖机械化200师(约9000人),师长戴安澜
第6军
第66军
全国15个机械化师,9个用于远征.
先头部队为第5军200师,当时中国唯一的机械化部队,师长戴安澜,安徽无为人,毕业于
黄埔3期,参加长城保卫战,台儿庄,武汉战役,35岁升任200师师长.
1939年11月, 广西昆仑关,200师对阵敌第五师团,毙敌少将中村正雄.
入缅前(1941.12-1942.2)驻于滇西保山.
2.同古(Toungoo)战役
第5军200师经畹町入缅,3月6日抵缅甸中部水陆交通要冲同古(东吁),直面兵力两倍于
己的敌55师团,激战于色当河大桥.
3月15日前后同古机场失守.守军团长李树正遭军法枪决.
激战至3月29日,敌56师团3天行军300公里增援,色当河桥头阵地失守,战局急转直下.
30日,廖耀湘率22师增援,掩护200师撤退.
此役200师伤亡过半.日军集结4个师团约10万人迅速北上.局势危急.
3.盟军大撤退
罗卓英上将任远征军第一路司令,新38师师长孙立人奉命守卫曼德勒(Mandalay).
盟军意图集结中方3个军,英方5个师约25万人与敌在曼德勒会战.
4月12日敌33师团一个联队(1000多人)围攻缅中部油田仁安羌,英军主力7000人被围
4月16日,孙立人派刘放武113团前往增援.4月18日上午退敌解围.
4月20日曼德勒正面英军不辞而别,并计划炸桥.
蒋介石急令远征军将会战改为纵深防御,重点放在腊戌
4月28日,敌主力56师团占领腊戌,远征军退路被截断.英军向印度撤退,6万远征军向
缅北密支那撤退.
5月,56师团抢先占领密支那.
4.败走野人山
5月,杜聿明下令北撤,200师负责断后亦北撤,18日遭伏击,师长戴安澜重伤,5月底,余
部2000余人分散突围回国.
5月26日戴安澜将军牺牲于缅北茅邦村.
孙立人抗命突围,5月26日率部安全进入印度.
本文测试环境为IE7,vs2005
<html>
<head>
<title>Untitled Page</title>
<script type=”text/javascript”>
function pageLoaded()
{
window.status=”Page loaded”;
}
</script>
</head>
<body onload=”pageLoaded();”>
<script type=”text/javascript”>
window.onload=windowLoad;
function windowLoad()
{
window.status=”Window loaded”;
}
</script>
</body>
</html>
当这个html页面被加载时,windowLoad()会被执行,而pageLoaded()不会被执行.
如果把JavaScript代码全部放在<Head>中
<html>
<head>
<title>Untitled Page</title>
<script type=”text/javascript”>
function pageLoaded()
{
window.status=”Page loaded”;
}
window.onload=windowLoad;
function windowLoad()
{
window.status=”Window loaded”;
}
</script>
</head>
<body onload=”pageLoaded();”>
</body>
</html>
则pageLoaded()执行而windowLoad()不执行.
MSDN对onload有如下描述
The onload attribute of the body object sets an onload event handler for the window.
可见,在IE解析html文件时,后出现的设定会覆盖前边的设定.即window.onload
和onload=” “,后出现者起作用.
如果要两者都执行,则要使用attachEvent来指定window load时要运行的函数:
if (document.all){
window.attachEvent(’onload’,FuncName)
}
else{
window.addEventListener(’load’,FuncName,false);
}
Evaluating the technical feasibility.You need to demonstrate the feasibility of your design.
Object-oriented programming concept: inheritance, modularity, polymorphism, and encapsulation.
The Application object corresponds to a single application.
This means being able to evaluate requirements and then recommend, evaluate, and
refine a design for the application
Silver-bullet syndrome
Developer will translate stakeholders’ vision into tangible software.
As technologists, our first instinct to any problem might be to write some code.
The result of this thinking are beneficial to the organization.
睡觉的诀窍 南怀瑾
……所以,根据医学和我的体验、观察,一个人真正睡着觉最多只有两个钟头,其余都是浪费时间,躺在枕头上做梦,没有哪个人不做梦。至于醒来觉得自己没有做梦,那是因为他忘记了。通常一个人睡两个钟头就够了,为什么有人要睡七、八个钟头?那是你赖床躺在枕头上休息的习惯养成的,并非我们需要那么久的睡眠时间,尤其打坐做功夫的人晓得,正午只要闭眼真正睡着三分钟,等于睡两个钟头,不过要对好正午的时间。夜晚则要在正子时睡着,五分钟等于六个钟头。就这个时间的学问又大了,同宇宙法则、地球法则、易经阴阳的道理有关系,而且你会感觉到,心脏下面硬是有一股力量降下来,与丹田(肾上)的力量融合,所谓”水火既济”,豁然一下,那你睡眠够了,精神百倍。所以失眠或真要夜里熬夜的人,正子时的时刻,哪怕二十分钟也一定要睡,睡不着也要训练自己睡着。过了正子时大约十二点半以后,你不会想睡了,这很糟糕。更严重的,到了天快亮,四、五点钟,五、六点卯时的时候,你又困得想睡,这时如果一睡,一天都会昏头。所以想从事熬夜工作的人,正子时,即使有天大的事也要摆下来,睡它半小时,到了卯时(7:00)想睡觉千万不要睡,那一天精神就够了。不过失眠的人都挨过十二点,在床上翻来覆去睡不着,结果快天亮睡着了,到第二天下午都昏头昏脑,因此你会感觉失眠、睡眠不足,实际上是你没有经验。
“午时”一般约合今天的中午十一点至十三点之间,午时三刻是将近正午十二点,太阳挂在天空中央,是地面上阴影最短的时候。
这在当时人看来是一天当中”阳气”最盛的时候。
古代十二时辰对照表
子时 23点–1点
丑时 1点– 3点
寅时 3点–5点
卯时 5点–7点
辰时 7点–9点
巳时 9点–11点
午时 11点–13点
未时 13点–15点
申时 15点–17点
酉时 17点–19点
戌时 19点–21点
亥时 21点–23点
另外,每一时辰又细分为初和正,如23点为子初,半夜24点为子正,中午12点为午正,下午1点为未初
Solution:
In “Regional and Language options” dialog, Set “Standards and formats” to Chiese (PRC)
SnagIt 7.2.5免费注册地址:http://www.techsmith.com/snagit/ukdn.asp
SnagIt 7.2.5下载地址:http://www.oldapps.com/OldApps/SnagIT/SnagIt725.exe
遗憾的是SnagIt 7.2.5的安装程序在Vista上无法安装.
http://ajax.asp.net/about/default.aspx?tabid=47
1.ASP.NET 2.0 AJAX Extensions and Document, Source Code
扩展ASP.NET 2.0 server-side从而提供了和ASP.NET兼容的AJAX编程模型
2.Microsoft AJAX Library
JaveScript library
3.ASP.NET AJAX Control Toolkit
ASP.NET AJAX control SDK以及sample
在线演示http://ajax.asp.net/ajaxtoolkit/
4.ASP.NET Futures
5.Sample Applications
比如:
TemplateContorl实现了INameContainer,其派生类UserContorl又实现INameContainer.
INameContainer仅仅是一个marker interface,其用途也就是看一个class是否实现了此interface,
UserContorl就算不实现INameContainer,仍然可以cast为INameContainer.
又如:
StringCollection,实现了IList, ICollection, IEnumerable,而IList实现了ICollection, IEnumerable,
ICollection又实现了IEnumerable.
其目的在于可在StringCollection中显式实现这些Interface,对一些方法的参数类型进行强化:
public int IndexOf(string value);
int IList.IndexOf(object value)
{
return this.IndexOf((string) value);
}
以便在编译阶段发现问题.
考察如下代码:
interface ITest
{
void ShowMsg();
}
interface IITest:ITest
{
}
public class TestA : ITest
{
public void ShowMsg()
{
Console.WriteLine(”TestA:”);
}
void ITest.ShowMsg()
{
Console.WriteLine(”TestA:ITest”);
}
}
public class TestB :TestA, ITest
{
public void ShowMsg() //Complier warning,hides inherited member ‘TestA.ShowMsg()’
{
Console.WriteLine(”TestB:”);
}
void ITest.ShowMsg()
{
Console.WriteLine(”TestB:ITest”);
}
}
TestB test = new TestB();
test.ShowMsg();
(test as TestA).ShowMsg();
ITest itest = new TestB();
itest.ShowMsg();
输出:
TestB:
TestA:
TestB:ITest
如果去掉TestB对ITest的实现, (test as ITest).ShowMsg();将输出TestB:
戍(树), 人+戈,守边
戎(荣), 十为甲+戈,本意为兵器的总合,后泛指军事.弓、殳、矛、戈、戟为古代五戎
戊(勿), 天干第5,属中央,戊戌维新,指1898年(农历戊戌年).
戌(虚), 地支第11,十二生肖属狗,指晚上七点钟至九点钟
1.Virtual Studio
Vista只支持 vb6和vs2005, 使用vs2005
需要VS2005 sp1 和 vs2005 sp1 update for vista
2.sql server
Microsoft SQL Server 2005 requires SP2 to run on Windows Vista.
3.IIS
http://blogs.msdn.com/webdevtools/archive/2006/09/18/761206.aspx
Developing Web Applications on Windows Vista with Visual Studio 2005
Select Web Management Tools->IIS6 Management Compatibility->IIS Metabase and IIS6 configuration compatiblity
Select WWW service->ASP.ET
Run Visual Studio 2005 in the context of an administrator account
4..NET framework
Microsoft .NET Framework 3.0 Deployment Guide
http://msdn2.microsoft.com/en-us/library/aa480173.aspx
SDK for vista and .net framework 3.0
Visual Studio 2005 extensions for .NET Framework 3.0
Visual Studio 2005 Extensions for WwF
Visual Studio 2005 Extensions for WCF, WPF 。
I found this registry in a web applcation setup project.
registry path:
HKLM\SYSTEM\CurrentControlSet\Services\W3SVC\Prarameters
value: MajorVersion
安装ciba2006时,除了黑屏一次,还算正常.
运行ciba2006,vista弹出一个”Program Compatibility Assistant”对话框,我选择了”Check for solutions online”,呵呵,金山还真地给出了solution:
http://cp.iciba.com/vistainfo/ciba06.shtml
尊敬的用户您好:
目前《金山词霸2006专业版》支持的操作系统是简体中文/繁体中文/英文/日文Windows98/ME/2000/XP,尚不支持Vista操作系统。因此在Vista操作系统上安装时可能会出现一些不可预见的错误,当有错误出现时,请尽快进行软件卸载。
《金山词霸2007专业版》提供免费支持至Vista操作系统的升级服务,详细信息,请登陆www.iciba.com!
感谢您使用我们的产品!
北京金山软件有限公司
不知何故,一个COM组件被重复下载,以下是针对这个问题的检查点:
1.Check <Windows Dir>\Downloaded Program Files
2.Check 注册表中My Computer\HKEY_CLASSES_ROOT\<Class Name>\CLSID
后发现,已下载的com组件的version与HTML中指定的版本不同,故反复下载.
<OBJECT id=<??????> onresize=\”window.oExportsDialog.fnSetSize ()\” codeBase=http://<myhost>/???.cab#Version=1,0,21,1975 data=data:application/x-oleobject;base64,+jIurin7Qky/+XrPoasKGxAHAAATIQAA3BEAAA== border=0
classid=CLSID:??????????????????????? name=????></OBJECT>
这两个单词我一直记不住
authentication (checking a user’s identity) and authorization (verifying a user’s right to access resources).
authentication,就象有人敲门时问”谁!”,对应”then”的发音.
authorization,是看用户的权限(right),对应”ri”的发音.
在页面中使用HTML标记:
<HEAD>
<META http-equiv=Pragma content=no-cache>
<META http-equiv=Cache-Control content=no-cache>
<META HTTP-EQUIV=”Expires” CONTENT=”-1″>
CACHE-CONTROL (49) Cache control directives.
PRAGMA (17) Implementation-specific directives that might apply to any recipient along the request/response chain.
EXPIRES (10) Date and time after which the resource should be considered outdated.
HOWTO:防止在 Internet Explorer 中进行缓存
http://support.microsoft.com/kb/234067/zh-cn
1. null 参数的传入
COM components don’t support parameter overloading, so for each value in a parameter list, you’ve got to pass in something, even if it does nothing.
Moreover, COM parameters are always passed by reference, which means that you can’t pass in a null value.
Instead of creating “dummy” object variables, the Type.Missing field can be used.
class Program
{
private static Object OptionalParamHandler = Type.Missing;
static void Main(string[] args)
{
Application NewExcelApp = new Application();
NewExcelApp.Worksheets.Add(ref OptionalParamHandler,
ref OptionalParamHandler, ref OptionalParamHandler,
ref OptionalParamHandler);
}
}
2. RuntimeWrappedException(new in .net 2.0)
COM errors won’t be CLS compliant, they won’t be caught with Exception, .net 2.0提供
RuntimeWrappedException封装了Non CLS-Compliant的异常.
代码一般写成:
private static void IllustrateExceptions()
{
try
{
// Something that throws an exception
}
catch (Exception ex)
{
// In 1.x this will catch only CLS-Compliant
// In 2.0 both CLS and Non CLS-Compliant will
// be caught by this block.
}
catch
{
// All exceptions, CLS-Compliant and Non CLS-Compliant are caught
}
}
3. COM interop的缺点:
Static members COM objects are fundamentally different from .NET types. One of the differences is lack of support for static members.
Parameterized constructors COM types don’t allow parameters to be passed into a constructor. This limits the control you have over initialization and the use of overloaded constructors.
Inheritance One of the biggest issues is the limitations COM objects place on the inheritance chain. Members that shadow members in a base class aren’t recognizable, and therefore, aren’t callable or usable in any real sense.
Portability Operating systems other than Windows don’t have a registry. Reliance on the Windows registry limits the number of environments a .NET application can be ported to.
如果一个.NET Class要被COM使用,就必须:
提供无参数的构造函数,暴露给COM的type和type member必须为public.
Abstract clsss 不能被COM使用.
ASP.NET Web Server Controls Overview
http://msdn2.microsoft.com/en-us/library/zsyt68f1.aspx
Overview of user controls vs. custom controls
http://support.microsoft.com/kb/893667/en-us
UserControl和WebControl 的比较
UserControl用于单个程序,WebControl用于多个程序,易于发布
WebControl缺乏对Design Time的支持
UserControl适用于固定布局,WebControl适用于动态布局
http://www.microsoft.com/china/technet/webcasts/class/windowsserver1.mspx
可以作为Windows internals 4e的参考.
1.Windows的昨天,今天和明天
|
Windows Operating System Internals Curriculum Resource Kit (CRK) Windows Vista Kernel Changes |
在.NET1.0中提供了
Assembly.Load(string assemblyString)
根据assembly的display name加载.
Assembly SampleAssembly = Assembly.Load(”SampleAssembly, Version=1.0.2004.0, Culture=neutral, PublicKeyToken=8744b20f8da049e3″);
Assembly.LoadFrom(string assemblyFile)
根据assembly所在的路径( 相对于当前目录)加载.
Assembly SampleAssembly = Assembly.LoadFrom(”c:\\Sample.Assembly.dll”);
在.NET1.1中又提供了
Assembly.LoadFile(string path)
LoadFile 与LoadFrom的比较:
LoadFile does not load files into the LoadForm context, and does not resolve dependencies using the load path,
LoadFrom cannot be used to load assemblies that have the same identities but different paths
在.NET 2.0中提供了
Assembly.ReflectionOnly属性(readonly)
指示assembly是否被加载到reflection-only context中
Assembly.ReflectionOnlyLoad(string assemblyString)
根据assembly的display name加载assembly到reflection-only context中.
string fullName = “System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″;
Assembly theAssembly = Assembly.ReflectionOnlyLoad( fullName );
Assembly.ReflectionOnlyLoadFrom(string assemblyFile)
根据assembly所在的路径( 相对于当前目录)加载assembly到reflection-only context中.
string file = “c:\\a.dll“;
Assembly theAssembly = Assembly.ReflectionOnlyLoadFrom( file );
PRB:Assembly.LoadFrom 不加载与其位于同一目录的依赖程序集
http://support.microsoft.com/kb/327435/zh-cn
Reflection Only Assembly Loading
http://blogs.msdn.com/junfeng/archive/2004/08/24/219691.aspx
LoadFile vs. LoadFrom
http://blogs.msdn.com/suzcook/archive/2003/09/19/loadfile-vs-loadfrom.aspx
WindowsIdentity
http://support.microsoft.com/kb/319615/zh-cn
static public bool CheckAccount(string userName, string pwd)
{
string user = userName;
string domin = System.Environment.MachineName;
IntPtr tokenHandle = new IntPtr(0);
if (userName.Contains(”\\”))
{
string[] arr = userName.Split(new char[] { ‘\\’});
user = arr[1];
domin = arr[0];
}
// Call LogonUser to obtain an handle to an access token.
bool returnValue = LogonUser(user, domin, pwd,
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT,
ref tokenHandle);
return returnValue;
}
[DllImport(”advapi32.dll”, SetLastError = true)]
public extern static bool LogonUser(String lpszUsername, String lpszDomain,
String lpszPassword, int dwLogonType,
int dwLogonProvider, ref IntPtr phToken);
const int LOGON32_PROVIDER_DEFAULT = 0;
//This parameter causes LogonUser to create a primary token.
const int LOGON32_LOGON_INTERACTIVE = 2;
const int SecurityImpersonation = 2;
Using MADS to Execute multiple commands on a connecton.
Add MultipleActiveResultSets=true into the connection string.
在connection string中指定 Asynchronous Processing = true.
Sample:
string strConn = “Data Source=.; Database=Pubs; Integrated Security=true; Asynchronous Processing=true”;
using (SqlConnection cn = new SqlConnection(strConn))
{
using(SqlCommand cmd = cn.CreateCommand())
{
cmd.CommandText = “”;
IAsyncResult ar = command.BeginExecuteReader();
// …
// do other processing
// …
SqlDataReader r = command.EndExecuteReader(ar);
}
}
参考
Asynchronous Command Execution in ADO.NET 2.0
http://msdn2.microsoft.com/en-us/library/ms379553(VS.80).aspx
|
常见的手法: 如何检查XSS 防御 The Cross Site Scripting (XSS) FAQ How To: Prevent Cross-Site Scripting in ASP.NET MS Anti-Cross Site Scripting Library V1.5 |
1. DataRow state and DataRow version
http://msdn2.microsoft.com/zh-cn/library/ww3k31w0(VS.80).aspx
2.DataTabel.Load
http://msdn2.microsoft.com/zh-cn/library/4e06d41f(vs.80).aspx
3.DataViewRowState Enumeration
DataView.RowStateFilter = DataViewRowState.???
FTP Server的port 21用于传输名令
Active Mode:
Client使用port n和server port 21建立连接,传输命令 port, Server 使用端口20和Client端口n+1建立连接,如果client安装了firewall,server 会被block.
Passive Mode:
Client使用port n和server port 21建立连接,传输命令 pasv, Server 选择使用端口p和Client建立连接,并把p发送给client,由clien使用端口n+1和server的端口p建立连接.
List<T>.Find的定义为:
public T Find (Predicate<T> match)
Predicate的定义为
public delegate bool Predicate<T> (T obj)
当前 List 的元素被逐个传递给 Predicate 委托,并在 List 中向前移动,
下面的代码可以找出名为jeep的Car
public class CarList
{
List<Car> carList = new List<Car>();
Car jeep = carList.Find(FindJeep)
private static bool FindJeep(Car car)
{
ret car.Name = “jeep”;
}
}
假设要找出和updateCar的Name相同的Car,改如何实现FineCarWithSameName方法?
public void Update(Car updateCar)
{
Car carFound = carList.Find(FineCarWithSameName);
}
问题在于在FineCarWithSameName方法中不能访问变量updateCar,此时使用匿名方法就可以解决:
public void Update(Car updateCar)
{
Car carFound = carList.Find(
delegate(Car car)
{
return car.Name == updateCar.Name;
});
}
http://www.codeproject.com/csharp/SimpleLogParse.asp
Download and install Log parser 2.2 from Microsoft
Add a reference to LogParser.dll in the installation directory
using MSUtil;
string test = “string”;
this.funString(test);
Console.WriteLine(test); //依然输出”string”
private void funString(string input)
{
input = “new string”;
}
如果换一种写法,答案就很明了:
string a = “string a”;
string b = a;
a = “new string a”;
Console.WriteLine(a); // new string a
Console.WriteLine(b); // string a
这是由于string 虽然是reference 类型,但:
A String object is called immutable (read-only) because its value cannot be modified once it has been created.
Methods that appear to modify a String object actually return a new String object that contains the modification.
funString中的input是test的一个reference, 但修改input不会修改test, 就像上个例子中的a和b.
此时生成的IL代码为:
.method private hidebysig instance void funString(string input) cil managed
{
// Code size 9 (0x9)
.maxstack 8
IL_0000: nop
IL_0001: ldstr “new string” //把 “new string”压栈
IL_0006: starg.s input //把栈顶元素即 “new string” 赋给input
IL_0008: ret
} // end of method Form1::funString
如果把代码写成
private void funRefString(ref string input)
{
input = “new string”;
}
则会生成代码
.method private hidebysig instance void funRefString(string& input) cil managed
{
// Code size 9 (0x9)
.maxstack 8
IL_0000: nop
IL_0001: ldarg.1 //把1号参数,即input压栈, 这是和funString的最核心的不同, funString通过忽略这条指令来
//保证string的immutable
//同时,此处没有ldind.ref 这条指令,对string进行了特殊处理
IL_0002: ldstr “new string” //把 “new string”压栈
IL_0007: stind.ref //把栈顶的两个元素弹出来,进行ref 赋值.
IL_0008: ret
} // end of method Form1::funRefString
此时直接修改了test的值.
如果fun的参数是其他reference类型,使用或不使用ref关键字生成的代码也有所不同,但执行结果完全相同:
.method private hidebysig instance void funForm(class [System.Windows.Forms]System.Windows.Forms.Form f) cil managed
{
// Code size 14 (0xe)
.maxstack 8
IL_0000: nop
IL_0001: ldarg.1
IL_0002: ldstr “new Form Text”
IL_0007: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Text(string)
IL_000c: nop
IL_000d: ret
} // end of method Form1::funForm
.method private hidebysig instance void funRefForm(class [System.Windows.Forms]System.Windows.Forms.Form& f) cil managed
{
// Code size 15 (0xf)
.maxstack 8
IL_0000: nop
IL_0001: ldarg.1
IL_0002: ldind.ref //这是唯一的不同, 其中用是把栈顶元素弹出,再把其address压栈,对于reference type来说,没有任何意义.
IL_0003: ldstr “new Form Text”
IL_0008: callvirt instance void [System.Windows.Forms]System.Windows.Forms.Control::set_Text(string)
IL_000d: nop
IL_000e: ret
} // end of method Form1::funRefForm
1.设置VMPlayer的Ethernet为Bridged模式.
Bridged模式下VM会象内一台独立的机器.
NAT模式会用到VMWare DHCP Service来模拟一个DHCP Server为VM分配IP,VM会通过
一个虚拟设备VMnet8(VMWare NAT Service)来连接到Host和外界网络.
Host-Only模式和NAT很象,唯一的不同就是没有用到NAT服务,无法访问外界网络,Host和
VM通过VMWare Network Adapter VMnet1这块虚拟网卡通信.
2.在VM中执行System-config-network
设置使用DHCP自动获得IP,自动获得DNS信息, 指定DNS server, 指定hostname(hhFedora).
或修改etc/resolv.conf
3. service network restart
很重要!
现在就何以通过机器名hhFedora来访问VM了.
Using Configuration.Section to access subsection
Copy from http://geekswithblogs.net/mnf/archive/2006/05/12/77981.aspx
I have a section in Web.Config:
<applicationSettings>
<FSBsnsCsLib.Properties.Settings>
…
</FSBsnsCsLib.Properties.Settings>
</applicationSettings>
I’ve tried to access inner section using shortcut “Section/Subsection”
string sSectionName=”applicationSettings/FSBusinessLib.My.MySettings”;
System.Configuration.ClientSettingsSection sectSettings = (ClientSettingsSection)config.Sections[sSectionName];
but it returned null.
The correct way is the following:
conststringcnstApplicationSection = “applicationSettings”;
ConfigurationSectionGroupgrpApplicationSection = config.SectionGroups[cnstApplicationSection];
string sSectionName=”FSBusinessLib.My.MySettings”;
System.Configuration.ClientSettingsSection sectSettings = grpApplicationSection .Sections[sSectionName];
只接受非空的输入,可由字符,音标,数字,空格,括号等组成, 不能以空格开头.
“^[\p{L}\p{Mn}\p{N}\p{Pc}\p{Po}\p{Ps}\p{Pe}\p{Pd}]+[\p{L}\p{Mn}\p{Zs}\p{N}\p{Pc}\p{Po}\p{Ps}\p{Pe}\p{Pd}]?$”
\p{L} - Allows all letters
\p{Mn} - Allows non-spacing marks including accents and umlauts
\p{Zs} - Allows space separator characters including normal space
\p{N} - Allows all numbers
\p{Ps} - Allows all Open characters such as {, ( and [ but not <
\p{Pe} - Allows all Close characters such as }, ) and ] but not >
\p{Sm} - Allows all math characters
\p{Pc} - represent connection punctuation, such as “_”,
\p{Po} - represent punctuations.
\p{Pd} - Dashes and hyphens.
http://www.codeguru.com/csharp/.net/net_data/sortinganditerating/article.php/c13375/
http://msdn2.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx
支持gzip格式(见RFC 1952),生成的压缩文件后缀为.gz,不能压缩大于4GB的文件
和XP内置的zip格式不兼容
//–压缩
FileStream fs = new FileStream(”es_resume.doc”, FileMode.Open);
byte[] input = new byte[fs.Length];
fs.Read(input, 0, input.Length);
fs.Close();
FileStream fsOutput = new FileStream(”es_resume.gzip”,
FileMode.Create,
FileAccess.Write);
GZipStream zip = new GZipStream(fsOutput, CompressionMode.Compress);
zip.Write(input, 0, input.Length);
zip.Close();
fsOutput.Close();
//–解压
FileStream fs = new FileStream(”es_resume.gzip”, FileMode.Open);
FileStream fsOutput = new FileStream(”es_resume2.doc”,
FileMode.Create,
FileAccess.Write);
GZipStream zip = new GZipStream(fs, CompressionMode.Decompress, true);
byte[] buffer = new byte[4096];
int bytesRead;
bool continueLoop = true;
while (continueLoop)
{
bytesRead = zip.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
break;
fsOutput.Write(buffer, 0, bytesRead);
}
zip.Close();
fsOutput.Close();
fs.Close();
http://www.codeproject.com/csharp/SimpleLogParse.asp
Download and install Log parser 2.2 from Microsoft
Add a reference to LogParser.dll in the installation directory
using MSUtil;
出自:IIS 7.0 探索用于 Windows Vista 的 Web 服务器和更多内容
1> IIS 7.0 的核心完全模块化,由 40 多项功能组成,这些功能基于一个新的可扩展层,这个层
允许.NET Framework 来扩展或替换。
2> IIS元数据被基于分布式 XML 配置文件applicationHost.config 文件替换.该文件包含服务器级
别的配置默认设置.在 IIS 7.0 中,配置系统是完全可扩展的。新模块可以添加它们自己的配置
架构,从而使应用程序能够与 IIS 和 ASP.NET一起配置其功能
3>新的图形化 IIS 管理器管理工具取代了InetMgr.exe MMC 管理单元.可将自定义管理 UI 添加到工具中
http://iis.net/default.aspx?tabid=7&subtabid=73
IIS 7.0 提供了 appcmd.exe 命令行工具
http://iis.net/default.aspx?tabid=2&subtabid=25&i=954&p=1
4>可以利用 Microsoft.Web.Administration API 通过 .NET 应用程序管理IIS
iis.net/default.aspx?tabid=2&subtabid=25&i=1076。
5>在 IIS 7.0 中,ASP.NET 有两个版本:经典模式和集成模式。
经典模式的工作方式与它在以前版本的 IIS 中完全相同。
集成模式是新的平台默认设置,它使用全新的引擎来提供与 IIS Web 服务器前所未有的集成。
在集成模式下,可以用 ASP.NET API 开发 IIS 7.0 模块,这样的模块可以直接与 Web 服务
器集成,并且能够提供用基本 C++ API 即可实现的几乎所有服务。
http://mvolo.com/2006/11/10/stopping-hotlinking-with-iis-and-aspnet.aspx
6>URL 授权与 ASP.NET 2.0 成员身份和角色管理功能无缝集成在一起
7>新的XML日志文件
8>通过 appcmd.exe 命令行工具或使用 Microsoft.Web.Administration API 以编程方式访问
服务器的实时状态
9>Windows Vista 上的 IIS 受限于每次 10 个并发请求
Visual Studio 2005 IDE 技巧和窍门
http://www.microsoft.com/china/msdn/library/langtool/vs2005/bb245788.mspx?mfr=true
1. 使用宏列举出所有的快捷键,导入配置文件
2.编辑快捷键的配置文件
My Documents\Visual Studio 2005\Settings\MyKeyboardShortcuts.vssettings
3.使用宏快速切换窗口布局,并将宏添加到ToolBar上.
4.Using team setting.file
5.Reset vs 的配置
devenv.exe /resetuserdata
如果在from中使用了一个image,以前的做法是直接通过文件系统来访问这个资源,或是把image作为resoruce嵌入到Assembly中,后者会对Assembly的加载带来负面影响.
在.net2.0中,在使用Image时可以选择使用Local Resource或是Project reouce File,如果使用Local reource,
就会按老路,在resource中添加Image的内容,然后把reouce嵌入到Assembly中.
如果使用Project resouce File,就会生成所谓的Strong type resouce.
1.把Image copy到project所在的路径\Resources
2.生成Project一级的Resouce File:
Resources.resx 记录resource的type和path
<data name=”Winter” type=”System.Resources.ResXFileRef, System.Windows.Forms”>
<value>..\Resources\Winter.jpg;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Resource.Designer.cs,生成代码来访问resouce:
internal static System.Drawing.Bitmap Winter
{
get {
object obj = ResourceManager.GetObject(”Winter”, resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
在.net2.0中,Project级的resource存在于Solution Explorer的Proertires目录下,
可以可视化的编辑这个resource,添加string, icon, image,file等类型的resource
VS2005会在Resource.Designer.cs自动生成强类型的resouce,调用的语句如:
this.Icon = <NameSpace>Properties.Resources.<ResourceName>
在.net2.0中,Project级的resource存在于Solution Explorer的Proertires目录下有一个
名为Setting.settings的文件.在此处声明用户配置会在Setting.Designer.cs中生成相关
代码,读写用户配置:
The developer can enter setting information directly into Visual Studio, choosing a name, scope (User/Application), type and optional value. Strongly-typed classes are generated that provide programmatic access to the settings, as well as load and save operations that manipulate settings in the user’s Local Settings\Application Data folder.
private void LoadRecentUrls()
{
String recentUrlsXml = Properties.Settings.Default.RecentUrls;
if (!string.IsNullOrEmpty(recentUrlsXml))
{
XmlSerializer xs = new XmlSerializer(typeof(List<UrlInfo>));
List<UrlInfo> urlInfos = (List<UrlInfo>)xs.Deserialize(new StringReader(recentUrlsXml));
foreach (UrlInfo urlInfo in urlInfos)
{
recentUrlsMenuItem.DropDownItems.Add(new UrlMenuItem(urlInfo));
}
recentUrlsMenuItem.Enabled = true;
}
}
private void SaveRecentUrls()
{
List<UrlInfo> urlInfos = new List<UrlInfo>();
foreach (UrlMenuItem menuItem in recentUrlsMenuItem.DropDownItems)
{
urlInfos.Add(menuItem.UrlInfo);
}
XmlSerializer xs = new XmlSerializer(typeof(List<UrlInfo>));
StringWriter sw = new StringWriter();
xs.Serialize(sw, urlInfos);
Properties.Settings.Default.RecentUrls = sw.ToString();
Properties.Settings.Default.Save();
}
// 在没有这个之前,我使用了:
private void ReadRecentFiles()
{
ConnectionStringsSection section = (ConnectionStringsSection)ConfigurationManager.GetSection(”connectionStrings”);
//I must use <clear/> in <connectionStrings>.
//Or, a defualt sql connection string will be read.
for (int i = 0; i < section.ConnectionStrings.Count; i++)
{
FileInfo fileInfo = new FileInfo(section.ConnectionStrings[i].ConnectionString);
}
private void SaveRecentFiles()
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConnectionStringsSection appSection = (ConnectionStringsSection)config.GetSection(”connectionStrings”);
appSection.ConnectionStrings.Clear();
int count = Math.Min(this.recentFiles.Count, this.recentFilesCount);
for (int i = 0; i < count; i++)
{
FileInfo file = new FileInfo(this.recentFiles[i]);
appSection.ConnectionStrings.Add(new ConnectionStringSettings(file.Name, file.FullName));
}
config.Save();
}
在task bar上点击鼠标右键,会弹出system menu,此消息为:
WM_POPUPSYSTEMMENU(0x313)
1.方法1
把resource文件(Strings.resx和Strings.zh-CHS.resx)作为Embedded Resource build到Assembly中.
假定生成的assembly的default namespace为MyApp,resource位于Res 目录下,
则会在assembly中生成名为MyApp.Res.Strings.resources的resource,
同时生成zh-CHS目录,及:GMailClient.resources.dll,其中包含名为GMailClient.Res.Strings.zh-CHS.resources的资源.
//First parameter is: Assemlby default namespace + folder + base resource name
//Second parameter is : Assembly contails the
resourceManager = new ResourceManager(”MyApp.Res.Strings”, System.Reflection.Assembly.GetExecutingAssembly());
StringResources.GetString(resId);
测试:
使用 System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(”zh-CN”);
设定UICulture,ResourceManager会使用这个Culture来读取对应的resource.
注意:Culture ‘zh-CHS’ is a neutral culture(与某种语言关联但不与国家/地区关联的区域性). It cannot be used in formatting and parsing and therefore cannot be set as the thread’s current culture.BUT, Culture ‘zh-CHS’ can be set as Current UI Culture.
在这里,我有意生成名为GMailClient.Res.Strings.zh-CHS.resources的resource(Chinese, neutral),但设定UICulture为zh-CN(PRC:Special),读取结果正确.可推测其逻辑为:对于一个Special Culture,找不到相应的
资源,就尝试其对应的neutral culture对应的资源.
对于NeutralCulture和:specified culture可以使用下面的函数进行转化
public static CultureInfo GetNeutralCulture(string cultureName)
{
System.Globalization.CultureInfo c = new System.Globalization.CultureInfo(cultureName);
if (! c.IsNeutralCulture)
{
c = new System.Globalization.CultureInfo(c.LCID & 0x3FF); //低10位
}
return c;
}
举例
zh-CHS 0x0004 Chinese (Simplified) , Neutral
zh-CN 0x0804 Chinese - China
zh-CHT 0x7C04 Chinese (Traditional) , Neutral
zh-TW 0x0404 Chinese - Taiwan
zh-HK 0x0C04 Chinese - Hong Kong SAR
zh-MO 0x1404 Chinese - Macao SAR
zh-SG 0x1004 Chinese - Singapore
下面的代码可以显示zh的相关的culture
foreach ( CultureInfo ci in CultureInfo.GetCultures( CultureTypes.AllCultures ) )
{
if ( ci.TwoLetterISOLanguageName == “zh” )
{
Console.Write( “{0,-6} {1,-40}”, ci.Name, ci.EnglishName );
if ( ci.IsNeutralCulture ) {
Console.WriteLine( “: neutral” );
}
else {
Console.WriteLine( “: specific” );
}
}
}
/*
This code produces the following output.
zh-CHS Chinese (Simplified) : neutral
zh-TW Chinese (Taiwan) : specific
zh-CN Chinese (People’s Republic of China) : specific
zh-HK Chinese (Hong Kong S.A.R.) : specific
zh-SG Chinese (Singapore) : specific
zh-MO Chinese (Macao S.A.R.) : specific
zh-CHT Chinese (Traditional) : neutral
*/
方法2:自己搞
public class PublicResourcesManager
{
private ResXResourceReader _resXReader;
private IDictionaryEnumerator _resXEnum;
public PublicResourcesManager(string resourceRootFolder, string resourceFileName)
{
CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentUICulture;
string resourceFolder = resourceRootFolder.TrimEnd(’\\’);
string fileName = String.Format(”{0}\\{1}\\{2}”, resourceFolder, ci.Name, resourceFileName);
try
{
// first try [country][region] folder…
_resXReader = new ResXResourceReader(fileName);
_resXEnum = _resXReader.GetEnumerator();
if (_resXEnum!=null)
return;
}
catch(Exception ex) {}
_resXReader.Close();
try
{
// try [country] folder (if culture isn’t a neutral culture…
if (!ci.IsNeutralCulture)
{
ci = new CultureInfo(ci.LCID & 0x03ff);
fileName = String.Format(”{0}\\{1}\\{2}”, resourceFolder, ci.Name, resourceFileName);
_resXReader = new ResXResourceReader(fileName);
_resXEnum = _resXReader.GetEnumerator();
if (_resXEnum!=null)
return;
}
}
catch(Exception ex) {}
_resXReader.Close();
try
{
// just try root folder…
fileName = String.Format(”{0}\\{1}”, resourceFolder, resourceFileName);
_resXReader = new ResXResourceReader(fileName);
_resXEnum = _resXReader.GetEnumerator();
}
catch(Exception ex)
{
string err = ex.Message;
}
}
public string GetString(string name)
{
string str = “”;
if (_resXEnum != null)
{
_resXEnum.Reset();
while (_resXEnum.MoveNext())
{
if (string.Compare(name, _resXEnum.Key.ToString(), true, CultureInfo.InvariantCulture)==0)
str=(string)_resXEnum.Value;
}
}
return str;
}
}
此处的逻辑是先找Folder\CultureName\Resource来找
如果失败,就把Culture转成neutral culture,再按Folder\CultureName\Resource找一次.
再失败,就尝试Folder\Resource
最常用的还是.net自己提供的resource管理机制,
在Form的property grid中可以设定form的Language,会为Form自动生成该Language的resource:
如MainForm.zh-CHS.resx,这些resource会被设置为Embedded Resource,其内容为:
<data name=”$this.Icon” type=”System.Drawing.Icon, System.Drawing”>
<value>…Binary Content…<value>
</date>
<data name=”$this.Text” type=”System.Drawing.Icon, System.Drawing”>
<value>Hello!<value>
</date>
在InitializeComponent()会生成代码
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
resources.ApplyResources(this, “$this”);
resources.ApplyResources(this.pictureBox1, “pictureBox1″);
把resourc中的内容读出,并设置到from上.
3.使用时:
this.pictureBox1.Image = global::MyApplication.Properties.Resources.Winter;
不要轻易手动修改这些自动生成的代码,容易乱套.
收假了,对我而言,这才是新年的开始.整个假期,我基本没有碰平时常看的技术站点.
今天打开ie和FeedDemon,不禁感有排山倒海,扑面而来的感觉.
Google Doc上线了.
MSDN Magazine也有了新的issue.
Scott 也没闲着.
…
够我看一阵子的.
常用的string一般有两种:
1. 和culture相关,用于给用户显示,或由用户选择.
2. hardcode到代码中,由developer来使用.
在.net1.0中常用的字符串比较函数为:
String.Compare (String, String)
String.Compare (String, String, Boolean)
String.Compare (String, String, Boolean, CultureInfo)
在.net2.0中,提供了新的字符串比较函数
String.Compare (String, String, StringComparison)
对于Culture-specific strings,请使用:
if (String.Compare(”MyUserDefinedStrng”, “MYUSERDEFINEDSTRING”, StringComparison.CurrentCultureIgnoreCase) == 0)
{}
当然如果不使用第3个参数,缺省也使用current culture,但是使用后可以明确意图,方便代码维护.
对于 Invariant-specific strings,请使用:
if (String.Compare(”MyHardCodedString”, “MYHARDCODEDSTRING”, StringComparison.OrdinalIgnoreCase) == 0)
{}
NB: 不要使用StringComparison.InvariantCulture 和StringComparison.InvariantCultureIgnoreCase 选项
原因请参照:
New Recommendations for Using Strings in Microsoft .NET 2.0中
What About the Earlier Recommendation for Invariant Culture?一节:
InvariantCulture is culture-independent and culture-insensitive, You can specify the invariant culture by name using an empty string (”") or by its culture identifier 0x007F.
It is associated with the English language but not with any country/region.
参考:
New recommendations for string comparisons in .Net 2.0
(http://msdn2.microsoft.com/en-us/library/ms973919.aspx)
Performing Culture-Insensitive String Comparisons
(ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxwalkthrough/html/abae50ef-32f7-4a50-a540-fd256fd1aed0.htm)
在一个tree 空间中进行的实验:
function AfterNodeSelChange(treeId, nodeId)
{
var selectNode = document.getElementById(nodeId);
var subElements = selectNode.children;
for(x=0; x<subElements.length; x++)
{
var subElement = subElements.item(x);
if(subElement.tagName == ‘IMG’)
{
if(subElement.src != ‘’)
{
subElement.style.cssText = “filter:progid:DXImageTransform.Microsoft.Alpha(opacity=50);”;
}
}
}
//selectNode.filters.item(”DXImageTransform.Microsoft.Alpha”).opacity=50;
}
Fxcop team 发布了一本九十几页的小书<<The Quality Code Handbook>>
http://blogs.msdn.com/fxcop/archive/2007/02/07/free-writing-quality-code-e-book-with-information-on-both-native-and-managed-code-analysis.aspx
该书使用的文件格式并不常见,需要阅读工具:http://www.dnaml.com/
UltraWebTree在缺省情况下,
<AutoPostBackFlags NodeChanged=”false” /> 就是在client edit一个node,并不会引发
server 端的NodeChanged event,但奇怪的是如果给NodeClicked event 指定了一个
event handler, NodeChanged event就会被触发,神奇.
一个小小的Trick:
在server端读出语言相关的字符串资源并注入到client端:
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(”<script type=’text/javascript’>”);