人生是一场不能存盘的RPG,我只能尽量多搞几个Screenshot

November 25, 2007

回来看看

Filed under: 随便说说

感谢TOR,我才能回来看看.
不能访问blogsome已经很久了.不知道还要被封多久.

问候GFW他老木.

July 25, 2007

IE Language Preference and Culture in Page Directive

Filed under: ASP.NET

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.

June 23, 2007

Martial Art Vocabulary

Filed under: 其他

Self-defence

Punch

Kick

Head butt

Stand-Up Aggression

Choke

Collar Grab

Bear Hug Over the Arms

June 19, 2007

Classic Mistakes in Development

Filed under: 经验积累

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

June 18, 2007

Enable multisession of vista remote desktop

Filed under: 使用技巧

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.

凤凰大视野-中国远征军

Filed under: 乱翻书

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日率部安全进入印度.

window.onload and body onload =

Filed under: ASP.NET

本文测试环境为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);
}

June 16, 2007

Technical Vocabulary

Filed under: 其他

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.

June 15, 2007

睡觉的诀窍 南怀瑾

Filed under: 乱翻书

睡觉的诀窍 南怀瑾

……所以,根据医学和我的体验、观察,一个人真正睡着觉最多只有两个钟头,其余都是浪费时间,躺在枕头上做梦,没有哪个人不做梦。至于醒来觉得自己没有做梦,那是因为他忘记了。通常一个人睡两个钟头就够了,为什么有人要睡七、八个钟头?那是你赖床躺在枕头上休息的习惯养成的,并非我们需要那么久的睡眠时间,尤其打坐做功夫的人晓得,正午只要闭眼真正睡着三分钟,等于睡两个钟头,不过要对好正午的时间。夜晚则要在正子时睡着,五分钟等于六个钟头。就这个时间的学问又大了,同宇宙法则、地球法则、易经阴阳的道理有关系,而且你会感觉到,心脏下面硬是有一股力量降下来,与丹田(肾上)的力量融合,所谓”水火既济”,豁然一下,那你睡眠够了,精神百倍。所以失眠或真要夜里熬夜的人,正子时的时刻,哪怕二十分钟也一定要睡,睡不着也要训练自己睡着。过了正子时大约十二点半以后,你不会想睡了,这很糟糕。更严重的,到了天快亮,四、五点钟,五、六点卯时的时候,你又困得想睡,这时如果一睡,一天都会昏头。所以想从事熬夜工作的人,正子时,即使有天大的事也要摆下来,睡它半小时,到了卯时(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点为未初

June 11, 2007

Can not open CHM with chinese name or in folder with chinese folder

Filed under: 使用技巧

Solution:
In “Regional and Language options” dialog, Set “Standards and formats” to Chiese (PRC)

June 6, 2007

SnagIt免费注册

Filed under: 开发工具

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上无法安装.

June 5, 2007

AJAX Components

Filed under: ASP.NET

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

为什么在派生类中再次实现一个Interface?

Filed under: .NET, C#

比如:
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:

戍戎戊戌

Filed under: 乱翻书

戍(树), 人+戈,守边

戎(荣), 十为甲+戈,本意为兵器的总合,后泛指军事.弓、殳、矛、戈、戟为古代五戎

戊(勿), 天干第5,属中央,戊戌维新,指1898年(农历戊戌年).

戌(虚), 地支第11,十二生肖属狗,指晚上七点钟至九点钟

June 4, 2007

Working with Vista .net 3.0

Filed under: .NET, Windows platform

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 。

机器性能测试网站

Filed under: 网络资源

http://www.systemrequirementslab.com/referrer/srtest

How to get IIS version

Filed under: ASP.NET

I found this registry in a web applcation setup project.

registry path:
HKLM\SYSTEM\CurrentControlSet\Services\W3SVC\Prarameters
value: MajorVersion

June 3, 2007

当词霸2006遭遇vista

Filed under: 使用技巧

安装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

  感谢您使用我们的产品!

                                北京金山软件有限公司

May 31, 2007

为什么一个COM组件被重复下载

Filed under: .NET, 使用技巧

不知何故,一个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>

May 30, 2007

authentication and authorization

Filed under: .NET

这两个单词我一直记不住
authentication (checking a user’s identity) and authorization (verifying a user’s right to access resources).
authentication,就象有人敲门时问”谁!”,对应”then”的发音.
authorization,是看用户的权限(right),对应”ri”的发音.

May 29, 2007

禁止IE Cache页面

Filed under: ASP.NET

在页面中使用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

COM Interop

Filed under: .NET, C#

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使用.

May 28, 2007

ASP.NET 中的各种Control

Filed under: ASP.NET

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适用于动态布局

深入研究Windows内部原理系列讲座

http://www.microsoft.com/china/technet/webcasts/class/windowsserver1.mspx
可以作为Windows internals 4e的参考.

1.Windows的昨天,今天和明天

Windows Operating System Internals Curriculum Resource Kit (CRK)
http://www.academicresourcecenter.net/curriculum/pfv.aspx?id=6191

Windows Vista Kernel Changes
http://www.microsoft.com/emea/itsshowtime/sessionh.aspx?videoid=340
http://en.wikipedia.org/wiki/Mark_Russinovich

May 24, 2007

欧亨利小说

Filed under: 乱翻书

http://homepage.fudan.edu.cn/~Ayukawa/at/20050501.htm

May 21, 2007

Assembly.Load() 系列方法

Filed under: Uncategorized

在.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 );

注意:当assembly被加载到reflection-only context,只能做Reflection。可以读到它里面所有的Type,但不能
Create Instance.其好处:
  1. Skip assembly strong name verifications
  2. Skip CAS policy check
  3. Skip processor architecture loading rule
  4. Not execute any code in the target assembly, including module constructor
  5. Not apply any binding policy.
和execution assembly load APIs的比较:
  1. There is one inspection context per AppDomain. All the reflection only assemblies live in that context.
  2. Reflection only assemblies will be unloaded only when the AppDomain is unloaded, same as execution assemblies.
  3. CLR will not probe for dependencies. The user of those APIs is responsible to provide all the necessary assemblies using Reflection Only Assembly Load APIs. The reason of this decision is that by probing dependencies, CLR may return a different assembly than the one you want. And it will be very difficult to overwrite CLR’s decision. However, if an assembly with the same idemtity is already loaded in the inspection context, CLR will use it to satisfy the dependency.
  4. All reflection only assemblies will be cached. Only one assembly per identity is allowed in the inspection context. It does not matter how that assembly was loaded - the first one loaded always wins. This means:
  5. If someone attempts to load a second one using ReflectionOnlyLoadFrom(), it will fail with a FileLoadException. The decision is based on 3). If multiple assemblies are allowed to be loaded in inspection context, CLR will not know which assembly to be used when looking for dependencies.
  6. If ReflectionOnlyLoad() is called on an assembly when another assembly with that identity was already loaded, the already-loaded assembly will be returned.
  7. ReflectionOnlyAssemblyResolve event will be fired, instead of AssemblyResolve event.
  8. You have to return a reflection only assembly in ReflectionOnlyAssemblyResolve event handler.
  9. CLR will not return instances of custom attributes, since that means executing code of the target assembly. Instead, a new class CustomAttributeData will be used to return information about the custom attributes.

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

How to check windows username and password

Filed under: Code snippets

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;

May 15, 2007

TiddlyWiki

Filed under: 网络资源

http://www.allwiki.com/wiki/TiddlyWiki

May 13, 2007

Multiple Acrive Result Sets(MARS) in .NET 2.0

Filed under: SQL&DB Accessing

Using MADS to Execute multiple commands on a connecton.

Add MultipleActiveResultSets=true into the connection string.

新:.NET 2.0提供的异步数据访问

Filed under: SQL&DB Accessing

在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

May 11, 2007

XSS的资料收集

Filed under: ASP.NET

常见的手法:
在页面或地址栏中写入javascript代码,经过HEX编码编码後会更隐蔽.
javaScript的用途:
盗取当前用户的cookie信息
通过XMLHttpRequest() 整蛊web server.

如何检查XSS
在各种输入接口输入或者在GET的URL参数中加入: “><img src=1 onerror=javascript:alert(document.cookie)><” 如果有js alert执行,说明可能有潜在漏洞。

防御
过滤非法的输入
把user提交的某些可以在浏览器中执行的代码encode後再发送给请求者

The Cross Site Scripting (XSS) FAQ
http://www.cgisecurity.com/articles/xss-faq.shtml

How To: Prevent Cross-Site Scripting in ASP.NET
http://msdn2.microsoft.com/en-us/library/ms998274.aspx

MS Anti-Cross Site Scripting Library V1.5
http://blog.joycode.com/saucer/archive/2006/11/21/87365.aspx
http://msdn2.microsoft.com/en-us/security/aa973814.aspx

May 10, 2007

LoadOption versus DataRowState and DataRowVersion

Filed under: Uncategorized

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的Active Mode和Passive Mode

Filed under: Uncategorized

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.Find中使用匿名方法

Filed under: Uncategorized

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;
});
}

Parse IIS log using MS Log Paser2.2 in c#

Filed under: Uncategorized

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;

April 27, 2007

能否在函数中修改string类型的函数参数

Filed under: C#

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

April 4, 2007

Access a Fedora VM from a windows network

Filed under: 开发工具

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了.

March 21, 2007

Using Configuration.Section to access subsection

Filed under: .NET, Code snippets

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];

March 9, 2007

用户名Regex

Filed under: Regular Expression

只接受非空的输入,可由字符,音标,数字,空格,括号等组成, 不能以空格开头.
“^[\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.

March 7, 2007

.net2.0 自带的压缩/解压类GZipStream Class

Filed under: .NET, Code snippets

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();

March 6, 2007

Parse IIS log using MS Log Paser2.2 in c#

Filed under: Uncategorized

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

Filed under: ASP.NET

出自: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 技巧和窍门

Filed under: Visual Studio

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

March 3, 2007

Image Resource

Filed under: Uncategorized

如果在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>

UserSetting的读写

Filed under: Uncategorized

在.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();
}

March 2, 2007

WM_POPUPSYSTEMMENU message

Filed under: .NET

在task bar上点击鼠标右键,会弹出system menu,此消息为:
WM_POPUPSYSTEMMENU(0x313)

February 28, 2007

String Resource使用

Filed under: .NET

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;
不要轻易手动修改这些自动生成的代码,容易乱套.

February 26, 2007

收假了

Filed under: 随便说说

收假了,对我而言,这才是新年的开始.整个假期,我基本没有碰平时常看的技术站点.
今天打开ie和FeedDemon,不禁感有排山倒海,扑面而来的感觉.
Google Doc上线了.
MSDN Magazine也有了新的issue.
Scott 也没闲着.

够我看一阵子的.

February 13, 2007

.NET 2.0 中字符串比较

Filed under: Uncategorized

常用的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)

Writing Compilers and Interpreters 2e的source code

Filed under: 技术书籍

http://www.wiley.com/legacy/compbooks/catalog/11353-0.htm

ftp://ftp.wiley.com/public/computer_books/Software_Development/Mak-Writing_Compilers/

模拟一个文件被cut后Icon的半透明效果

Filed under: ASP.NET

在一个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;
}

February 9, 2007

Writing Quality Code by FxCop team

Filed under: .NET

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/

February 8, 2007

About Infargistics UltraWebTree NodeChanged Event

Filed under: ASP.NET

UltraWebTree在缺省情况下,
<AutoPostBackFlags NodeChanged=”false” /> 就是在client edit一个node,并不会引发
server 端的NodeChanged event,但奇怪的是如果给NodeClicked event 指定了一个
event handler, NodeChanged event就会被触发,神奇.

February 5, 2007

在Client JavaScript中支持多语言

Filed under: ASP.NET

一个小小的Trick:
在server端读出语言相关的字符串资源并注入到client端:
System.Text.StringBuilder sb = new System.Text.StringBuilder();

sb.Append(”<script type=’text/javascript’>”);
sb.Append(”var I18N = new Array();\n”);
sb.AppendFormat(”I18N[’{0}’] = ‘{1}’;\n”, “my_String_1″, GetResourceString(”my_String_1″));
sb.AppendFormat(”I18N[’{0}’] = ‘{1}’;\n”, “my_String_2″, GetResourceString(”my_String_2″));
sb.Append(”</script>”);

ClientScript.RegisterClientScriptBlock(GetType(), “I18N”, sb.ToString());

在客户端进行读取:
function getI18N(resourceId)
{

return I18N[resourceId];

}

var myString1 = getI18N(”myString_1″))

February 3, 2007

如何在关闭ModalDialog时避免打开新的IE窗口

Filed under: ASP.NET

很多时候,asp.net程序需要弹出一个Modal Dialg来收集用户的输入,这个Modal Dialg会有”OK”,”Cancel”两个button,使用javascript关闭dialog,但是有一些猫腻会导致在Modal Dialg中点击了”OK”或”Cancel”后,不但dialog不关闭反而打开一个新的IE.

原因就在于如果点击button导致了页面的提交,就会出现上述情况,如果这个Modal Dialg所对应的aspx页面是用vs自动生成,asp:button缺省就会提交页面,
此时如果在页面的<head></head>中添加<base target=_self></base>,就可以防止打开新的IE,但故事并没有结束,如果不幸在页面的form中,指定了
<form id=”form1″ runat=”server” target=”_self”>
用上述方法也阻止不了新的IE弹出.此时,需要使用更强大的手段:及在page load时指定form1的target:
javaScript:
function handleOnLoad()
{
window.name = ‘dialognew’ + Number(new Date()).toString();
document.dialognew.target = window.name;
}
form:
<form id=”dialognew” method=”post” target=”_self” runat=”server”>

January 17, 2007

Can’t use “New Query” in MS Sql Server Managemnet Studio

Filed under: SQL&DB Accessing

When I try to use “New Query” in MS Sql Server Managemnet Studio, an error pop up:
Cannot find template file for the new query (’C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\SqlWorkbenchProjectItems\SQL\SQLFile.sql’).

I check this file on other guy’s machine, and found this file is an empty sql file.
So, I create it on my machine and fix the error.

I think I mistakenly deleted it by a disk cleaning tool name fastcleaner because this file with 0 byte size.

January 12, 2007

XP磁盘清理

Filed under: 使用技巧

1.sfc.exe /purgecache

2.Delete %windir%\$ntuninstallq311889$

3.Delete %windir%\driver cache\i386\driver.cab文件

4.清理C:\Documents and Settings\ 各个user目录下的 application data, My documents, Local Settings目录.
All users\Application Data\Microsoft Help 很大,但不能删
User\Local Settings\Temp 很值得一删.

5.%windir%\Installer也可以清理一下

January 9, 2007

vs2005 sp1 之后的 Server Application Unavailable

Filed under: ASP.NET

在装了 vs2005 sp1 之后,遭遇错误
Server Application Unavailable

The web application you are attempting to access on this web server is currently unavailable.
Please hit the “Refresh” button in your web browser to retry your request.
在产看了Eventlog(Application)之后,看到:

aspnet_wp.exe could not be launched because the username and/or password supplied in the
processModel section of the config file are invalid.

aspnet_wp.exe could not be started. The error code for the failure is 80004005.

这两个错误成对出现,由此怀疑 ASPNET 这个帐号的设置有问题.
经过一番折腾,得出解决方案:
1. 删除ASPNET帐号,
2. 为了保险,运行 aspnet_regiis -u, 此过程并不能删除ASPNET帐号,实在有些令人不解
3. 运行 aspnet_regiis -i, 重新安装ASP.net, 此过程会生成ASPNET帐号.
4. 运行 iisreset

December 21, 2006

WPF之窗体模型

Filed under: Windows platform

编程
1. MyApp.xaml
Define Start up window(StartupUri) for the application
<Application StartupUri = “MyWindow.xaml”/>

2.MyWindow.xaml

<Window x:Class=”MyWindow” Width=”300″ Height=”200″ Title=”">
<Button Click=”ButtonClick”>
</Button>
</Window>

3.MyWindow.cs

4.myProj.csproj

5.msbuild myProj.csproj

编译过程:
Layout,Control的设定被转化为 BAML(Binary App Markup Language), 再嵌入到resources中
BAML+ C# -> exe

实验1: 查看obj目录,包含编译的中间结果:
MyWindow.cs
MyWindow.g.cs
MyWindow.baml

实验2:查看msbuild 编译时在控制台的输出

执行流程:
SourceInitialized
Activated
Loaded
ContentRendered
Deactivated/Acrivated
Closing
Closed

交互
WindowsFormsHost(将windows control放到wpf form)
ElementHost(将wpf control 放到 windows from)
HwndHost, HwndSource(与Win32和MFC窗体/控件进行交互)

Reference
www.techjie.com

December 19, 2006

Install Firefox2.0 in Fedora C6

Filed under: 使用技巧

I want to upgrage the FireFox 1.5 come with FC6 to FireFox 2.0.
But when I run the firefox-2.0-1.fc6.remi.i386.rpm, an error message popup:
“Missing Dependency: gecko-libs = 1.8.0.8 is needed by package yelp”

Where could I get gecko-libs? The answer is FireFox-2.0-1.fc6.remi.i386.rpm!
The rpm of FireFox 2.0 contains gecko-libs.

So I try to uninstall FireFox 1.5 before install FireFox 2.0.
rpm -e firefox
Another error occurred: “Failed dependencies……”
Then, I used
rpm -e –nodeps firefox, unstalling was successful!

After that, I run rpm -ivh FireFox-2.0-1.fc6.remi.i386.rpm, successful!

Linux Services

Filed under: 使用技巧

1.Start service:
service smb start

2.Stop service
service yum-updatesd stop

2.Restart service
service smb restart

3.List all service
service –status-all

4.Service auto start
ntsysv

5.Services:
yum-updatesd Auto update

6.GUI Setting:
System->Administration->Server Settings->Services

December 13, 2006

VMPlayer 中的Fedora不能调整分辨率

Filed under: 使用技巧

Soultion:
Modify /etc/X11/xorg.conf

# Xorg configuration created by pyxf86config
Section “ServerLayout”
Identifier “Default Layout”
Screen 0 “Screen0″ 0 0
InputDevice “Keyboard0″ “CoreKeyboard”
EndSection

Section “Monitor”
Identifier “Monitor0″
HorizSync 1.0 - 10000.0
VertRefresh 1.0 - 10000.0
EndSection

Section “InputDevice”
Identifier “Keyboard0″
Driver “kbd”
Option “XkbModel” “pc105″
Option “XkbLayout” “us”
EndSection

Section “Device”
Identifier “Videocard0″
Driver “vmware”
EndSection

Section “Screen”
Identifier “Screen0″
Device “Videocard0″
Monitor “Monitor0″
DefaultDepth 24
SubSection “Display”
Depth 24
Modes “1152x864″ “1024x768″ “800x600″
EndSubSection
EndSection

我的Host机器分辨率为1280x1024, 为了不让VMPlayer产生滚动条,1152x864是fedora的最大分辨率.

December 10, 2006

The Sysinternals Video Library-Windows Crash Dump & Hang Analysis

Filed under: Uncategorized

–Why does winows crash?
Sth’s wrong in kernel-mode
Unhandled exception
OS or driver detected server inconsistency
Invalid memory references
Hardware error

–Crach Dump Types and Mechanisms
How to config:
My Computer->Property->Advanced->Startup and Recovery->Setting

Crash Dump Types:
Complete: default for server, all of RAM
Kernel memory dump: OS/Driver memory, No process memory, default for vista
Small: Default for XP

Minidumps:
Contents: Bugcheck code, parameters, List of drivers, mini info on current process
Location: %windir%\minidump

What initiates a Crash?
OS or driver detects fatal condition
Call KeBugCheckEx()

Bugcheck code(Stop code)
Documented in WinDBG’s Help file(Debugging Techniques->Bug Checks).

Crash Steps:
Turn off interrupts
Tells other CPUs to stop
Paints the blue screen
If dump configured, records in paging file

Analysis Tools
WinDBG
KD

Kernel image: Ntoskrnl.exe Ntoskrnal.pdb

Key internal concepts:
process
thread
memory protection
interrupt request level(IRQL)

Config the debug tool to download system symbol from symbol server.
You can set symbol directories through File->Symbol File Path,
Eg,SRV*c:\websymbols*http://msdl.microsoft.com/download/symbols
or using .sympath from the WinDbg command window
Symchk.exe : force symbol download.

The Sysinternals Video Library-Tour of the Sysinternals Tools

Filed under: Web cast学习

The Sysinternals Video Library (http://www.solsem.com/videolibrary.html)]
Tour of the Sysinternals Tools
The history of Sysinternals, an overview of the site, and a fast paced
tour of the major tools

–History:
*1996: ntinternals.com
10 tools
1500 visitors/day
*2006: sysinternals.com
100 tools
80000 visitors/day

–Tools
Process Explorer(Thread details, Handle view, dll view)

Handle (lists hanles)
ListDlls (lists Dlls)

PsList (Show information about processes and threads)
PsKill (Kill processes)
PsSuspend (Suspedn processes)
PsExec (execute a command local/remote)
psexec \\remote cmd
PsService

PsInfo
PsLogList
PsLoggeOn

BgInfo
ProcFeatures (Processor hardware features)
LoadOrders (load order of drivers and services)

PendMoves (list pending file operations)
Portmon (serial port monitor)

DebugView
Winobj
LiveKd

Filemon
Diskmon
DiskView (Graphical disk sector utility )
Du (View disk usage by directory )

Contig (defragment your frequently used file)
PageDefrag
Junction (Create Win2K NTFS symbolic links )
Sync(Flush cached data to disk)

Strings (dump strings in any file)

Regmon
Regjump

Autoruns
Sigcheck
RootkitRevealer

AccessEnum
ShareEnum
SDelete
NewSID

TCPView
Whois(See who owns an Internet address)
AdRestore (Undelete Server 2003 Active Directory objects)

December 5, 2006

[HTML] Disabled control can’t be submited!

Filed under: ASP.NET

Forms in HTML documents.
http://www.w3.org/TR/html4/interact/forms.html#adef-readonly
17.12 Disabled and read-only controls
17.13.2 Successful controls

TextBox can be used with readonly attribute.
Checkbox will be used with javeScript “return false;” to simulate the readonly state.

December 4, 2006

Application_Start 中的断点

Filed under: ASP.NET

我在Application_Start中加了一个断点,第一次使用f5运行程序,断点可以工作,
然后终止程序,再运行,断点就不工作了,重起IIS,断点又可以工作,
原因不明.

Gadget开发入门

Filed under: Windows platform

http://microsoftgadgets.com/Sidebar/DevelopmentOverview.aspx

–Where is the Side bar
C:\Programe Files\Windows SideBar\
SideBar的主程序以及公用的Gadget

“%userprofile%\AppData\Local\Microsoft\Windows Sidebar\Gadgets”
此处保存的是某个特定用户的Gadget.

–Run the Sider bar
Start -> All Programs -> Accessories

在vista的help中,查找 Windows Sidebar: frequently asked questions
How do I open Sidebar?
Click to open Windows Sidebar.对应的link为:
<a class=”shellExecuteLink” href=”shortcut:&quot;%25programfiles%25\windows sidebar\sidebar.exe&quot;”
title=”Click to open Windows Sidebar”>
<img src=”mshelp://help/?id=Microsoft.Windows.Resources.ShellExecuteTopicIcon”>
Click to open <span class=”notLocalizable”>Windows</span> Sidebar.
</a>
href=”shortcut:”%programfiles%\… “”这种写法我还是首次注意到.

–Mechanism of Sidebar and Gadget
Gadget由HTML, JavaScript,CSS,图片,资源组成, 通过调用Sidebar提供的API和系统中的ActiveX对象来完成操作.
常用到的ActiveX:
JScripting.FileSystemObject访问文件系统,
Microsoft.XmlDom分析XML文件,
Microsoft.XMLHTTP调用Web Service

Gadget本身是zip或cab格式,如果使用cab格式,需要进行数字签名, VS2005提供了数字签名工具Signtool.exe.

Gadget在其安全配置上,与普通的Web网页有很多不同点。
1. Gadget可以创建任何已安装的ActiveX对象的实例,因为其被配置为”可以初始化并且脚本访问未被标记为安全的ActiveX”。
2. Gadget也可以访问跨域的数据源,因为只有将不同位置的数据进行相应的集成,Gadget对于开发人员和最终用户才有意义。
3. 重要!!一个在Microsoft Gadget Gallery中发布的Gadget只能使用系统已有的ActiveX,禁止下载任何新的ActiveX控件,
无论这个ActiveX控件是签名或者未签名的。

注意:一个Gadget可以有多个实例同时运行.

–文件组成:
Gadget 所在folder的名称必须以.gadget结尾. 比如HelloWorld.gadget
* 我写了一个gadget,目录命名为为Mailsnatcher.gadget,无法从Gadget Gallery中看到,
改为eMailsnatcher.gadget,就可以看到了,原因不明.

以Clock为例, Clock位于%programfiles%\Windows\Gadgets\Clock.Gadget
主程序位于en-US下,可见各个语言对应的主程序可以不同.
en-US\中的gadget.xml是最关键的部分,定义了整个Gadget的信息以及用到的资源.
.Html用于定义gadget的UI,行为

gadget.xml gadget 的manifest, 只能取gadget.xml这个名字

常用的资源有:
icon, gadget.xml中<icons>中指定,用于在Gadget Gallery中显示.
defaultImage , gadget.xml中<defaultImage> 中指定,用于在拖动时显示.
logo, gadget.xml中<logo >中指定,用于在拖动时显示.用于在Gadget Gallery中显示详细信息.
这3个资源的路径都是相对于.gadget目录的.

–开发要点:
无IDE,不能所见即所得; 无法进行Debug,只能写Log来Trace;

–Sample
在”%userprofile%\AppData\Local\Microsoft\Windows Sidebar\Gadgets”下
生成目录: HelloWorld.gadget

在HelloWorld.gadget下生成文件gadget.xml
<?xml version=”1.0″ encoding=”utf-8″ ?>
<gadget>
<name>First Gadget!</name>
<namespace>Example.You</namespace>
<version>1.0</version>
<author name=”Aloneplayer”>
<info url=”" />
</author>
<copyright>2006</copyright>
<description>My first gadget</description>
<hosts>
<host name=”sidebar”>
<base type=”HTML” apiVersion=”1.0.0″ src=”HelloWorld.html” />
<permissions>full</permissions>
<platform minPlatformVersion=”0.3″ />
</host>
</hosts>
</gadget>

在HelloWorld.gadget下生成文件HelloWorld.html
<html>
<head>
<title>Hello, World!</title>
<style>
body {
width:130;
height:50;
}
</style>
</head>
<body>
<span id=”gadgetContent” style=”font-family: Tahoma; font-size: 10pt;”>Hello, World!</span>
</body>
</html>

此时,就可以点击Sider bar上的”+”呼出Gadget Gallery,可以看到一个以gadget.xml中<name>为命名的
gadget.

修改HelloWorld.html,使用背景:
<style>
body {
width:130;
height:50;
background: url(’Background.png’);
padding-top: 5px;
}
</style>

使用API:
<html>
<head>
<title>Hello, World!</title>
<style>
body{
width:130;
height:50;
background: url(’Background.png’); }
padding-top: 5px;
</style>
<script>
var variableName = “ProgramFiles”;
function setContentText() {
gadgetContent.innerText = System.Environment.getEnvironmentVariable(variableName);
}
</script>
</head>
<body onload=”setContentText()”>
<span id=”gadgetContent” style=”font-family: Tahoma; font-size: 10pt;”>Hello, World!</span>
</body>
</html>

添加Setting,此刻可以看到Gadget上会出现一个扳手状的buttong,同时context menu上也会出现”options”
用于进行setting
<html>
<head>
<style>
body{
width:250;
height:75;
}
</style>
<script>
function init()
{
var currentSetting = System.Gadget.Settings.read(”variableName”);
if (currentSetting != “”)
envVar.innerText = currentSetting;
}

System.Gadget.onSettingsClosing = SettingsClosing;
function SettingsClosing(event)
{
if (event.closeAction == event.Action.commit)
{
variableName = envVar.value;
System.Gadget.Settings.write(”variableName”, variableName);
}

event.cancel = false;
}
</script>
</head>
<body onload=”init()”>
<span id=”mySpan” style=”font-family: Tahoma; font-size: 10pt;”>
Environment Variable:<br>
<input type=”text” id=”envVar” length=”40″>
</span>
</body>
</html>

–发布:
把所有的文件做成一个zip包或cab包,把包的后缀改成.gadget,双击.gadget,就可以安装这个
gadget.

November 30, 2006

Function Discovery Browser

Filed under: 开发工具

A new tool come with .NET SDK 3.0
C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin\fdbrowser.exe

November 29, 2006

My Vista

Filed under: Windows platform

Virtual PC 2007 beta1 + 1G memory

Offiece 2007

Visio 2007

Windows SDK for Windows Vista

现在的问题是,玩点什么好呢?

November 26, 2006

几本新书

Filed under: 技术书籍

今天逛了逛书店.看到几本书值得进一步了解:

.NET Patterns: Architecture, Design, and Process
中译本: .NET模式:架构、设计与过程
免费试读: http://www.dearbook.com.cn/book/ReadBook.aspx?pno=TS0029381
讲述.net framework中用到的Design pattern, 以及在web service中的应用.

Maximizing ASP.NET: Real World, Object-Oriented Development -by Jeffery Putz
中译本: 最优化ASP.NET –面向对象开发实践
免费试读: http://book.csdn.net/bookfiles/90/index.html
偏重于实践和案例分析

ASP.NET 2.0 MVP Hacks and Tips
中译本: ASP.NET 2.0编程珠玑– 来自MVP的权威开发指南
免费试读: http://book.csdn.net/bookfiles/185/index.html
看名字应该完全来自实战, 可能不是完全适合每个人

DOM Scripting: Web Design with JavaScript and the Document Object Model
中译本: JavaScript DOM 编程艺术
免费试读: http://book.csdn.net/bookfiles/177/
http://domscripting.com/

同时对csdn有点小小建议:
能否学习china-pub,告诉我中译本图书的原书名,不要让我用放大镜在封面照片上找.
能否把封面图片上的dearbook.com字样去掉.
http://book.csdn.net/bookfiles/185/index.html

November 24, 2006

Vista 优化

Filed under: Windows platform

–bcdedit.exe
修改多重启动菜单

–Vista BootPRO
图形UI,修改启动设置

TweakVI for Windows Vista
http://www.totalidea.com/content/tweakvi/tweakvi-index.html

微软新系统Vista服务优化攻略
http://soft.yesky.com/os/435/2087435.shtml

Windows Command

Filed under: 使用技巧

———————-Service 相关
–列举系统中运行的service
tasklist /svc xp
tlist -s win2k

–重启IIS
iisreset

–启动,停止service
net start Service
net stop Service

sc start “my service”
sc stop “my service”

–安装service
installutil XXX.XXX.exe Install .NET service
sc create myservice Install win32 service

–卸载service
Installutil /u myservice .NET service
sc delete myservice Win32 service

———————-控制台相关
–打开控制台,可以看到常用的.msc
mmc

–打开services 控制台
services.msc

–性能监测器
perfmon.msc

–共享文件夹管理器
fsmgmt.msc

–把网络共享映射到一个盘符
net use x: \\<ip>\c$

–把目录映射到一个盘符
subst z: c:\Temp
subst z: /D 去掉映射

–Event 查看
eventvwr

–内存使用情况查看
mem

November 23, 2006

Create the group label in the dropdown list.

Filed under: ASP.NET

http://www.w3schools.com/tags/tag_optgroup.asp
<select>
<optgroup label=”Swedish Cars”>
<option value =”volvo”>Volvo</option>
<option value =”saab”>Saab</option>
</optgroup>
<optgroup label=”German Cars”>
<option value =”mercedes”>Mercedes</option>
<option value =”audi”>Audi</option>
</optgroup>
</select>

November 22, 2006

How to Get Neutral Culture

Filed under: .NET, Code snippets

string resourceFolder = “Folder”;
string resourceFileName = “ResFile.resx”;
CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture;
string fileName = String.Format(”{0}\\{1}\\{2}”, resourceFolder, ci.Name, resourceFileName);

Console.WriteLine(fileName);

ci = new CultureInfo(ci.LCID & 0x03ff);

fileName = String.Format(”{0}\\{1}\\{2}”, resourceFolder, ci.Name, resourceFileName);
Console.WriteLine(fileName);

ci = new CultureInfo(”zh-CHS”);
Console.WriteLine(ci.IsNeutralCulture); //Note! it’s true

ci = new CultureInfo(”fr-FR”);
Console.WriteLine(ci.IsNeutralCulture);

November 21, 2006

Prison break

Filed under: 娱乐

也许是等待了太长的时间, 盼来的第11集让我觉得时间过的飞快,
看完了甚至怀疑是不是这一集不足40分钟.500万回到了T-bag手中,
相比之下,好过被龌龊的狱警拿走.
各路人马都急了,焦点转移到了sara身上,最要命的是11的结尾又是
某人名悬一线,虽然知道导演和编剧不会让迷人的sara挂掉,但还是
有些焦躁不安,期待下文…..

November 18, 2006

通过脚本修改xp的cd key

Filed under: 使用技巧

http://www.larkmoon.com/read.php/45.htm

ON ERROR RESUME NEXT

Dim VOL_PROD_KEY
if Wscript.arguments.count<1 then
   VOL_PROD_KEY=InputBox("Message1"&vbCr&vbCr&"Message2","The Title","UserInput, key")
   if VOL_PROD_KEY="" then
     Wscript.quit
   end if
else
   VOL_PROD_KEY = Wscript.arguments.Item(0)   ‘Get usr input from command line
end if

VOL_PROD_KEY = Replace(VOL_PROD_KEY,"-","") ‘Remove hyphens if any

‘WMI
for each Obj in GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf ("win32_WindowsProductActivation")

   result = Obj.SetProductKey (VOL_PROD_KEY)   ’Update key

   if err = 0 then
      Wscript.echo "OK!"
   end if

   if err 0 then
      Wscript.echo "Failed"
      Err.Clear
   end if
Next
 

November 12, 2006

width, clientWidth, offsetWidth and scrollWidth

Filed under: Uncategorized

#div_test
{
width:300px;
height:200px;
padding:10px;
border:10px solid #ff0000;
background:#ccc;
font-size:12px;
}

<div id=”Div_CnLei”>
<a href=”javascript:alert(ShowSizeInfo());”>Show size info</a>
</div>

可得到如下结论:
IE7.0,IE6.0,FF1.06:
clientWidth = width + padding
clientHeight = height + padding
offsetWidth = width + padding + border
offsetHeight = height + padding + border

还一个是scrollWidth, scrollHeight
一般的用法是通过计算scrollleft 或 scrollTop做一个滚动的区域.
注意!scrollTop和scrollLeft描述的是一个距离,而不是位置,比如div.scrollTop描述的是
div滚动后的最上边和div的可见区域的最上边之间的距离.所以向上滚动要scrollTop++

在MSDN中,可以找到一张让人抓狂的图:
Measuring Element Dimension and Location, 可以看看

November 11, 2006

RegisterClientScriptBlock and RegisterStartupScript

Filed under: ASP.NET

这两个函数在asp.net1.1中是Page class上的方法.
在asp.net2.0中,变成了ClientScriptManager class上的方法,一般用法是在Page Load事件中调用:
this.ClientScript.RegisterClientScriptBlock
this.ClientScript.RegisterStartupScript

与此配套的函数还有
IsClientScriptBlockRegistered
IsStartupScriptRegistered
设想你写了一个web control, 需要一段client javaScript,如果user 在一个form上创建了这个control
多次,如果没有这个判断,就会生成多份代码.但在page上只注册一段代码可以不调用这个方法,
使用相同的type和key注册代码会被忽略.

这两个方法唯一的不同在于
RegisterClientScriptBlock()在Web 窗体的开始处,<form runat=”server”>之后生成代码,
而RegisterStartupScript()在 Web 窗体的结尾处,</form>标识之前生成代码。
从名称上看,asp.net 希望RegisterStartupScript生成的代码用于在page刚刚完成加载,OnLoad 事件
尚未触发前执行.

–参考
从 ASP.NET 服务器控件插入客户端脚本
http://www.microsoft.com/china/MSDN/library/archives/library/DNAspp/html/aspnet-injectclientsidesc.asp#aspnet-injectclientsidesc_topic3

Adding Client-Side Message Boxes in your ASP.NET Web
http://aspnet.4guysfromrolla.com/articles/021104-1.2.aspx

November 10, 2006

Key not valid for use in specified state

When I create a data base in the VS2005, I get a error message box which
says: “An error occurred while processing the local data file:
Key not valid for use in specified state.” The .mdf was created successfully
but I can’t open it in VS2005.

Google tell me to delete the folder:
C:\Documents and Settings\<My Name>\Application Data\Microsoft\VisualStudio\8.0
I clean the folder, then I can use the data base as usual.

Cool Javescript

Filed under: 代码学习

javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.images; DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position=’absolute’; DIS.left=Math.sin(R*x1+i*x2+x3)*x4+x5; DIS.top=Math.cos(R*y1+i*y2+y3)*y4+y5}R++}setInterval(’A()’,5); void(0);

Open a web page contains image, and copy the code snippet into IE’s address, GO!

GAC里有什么?

Filed under: .NET

Keywords:GAC,GAC_32,GAC_MSIL,NativeImages

安装了.net2.0后,在命令行下可以看到
c:\windows\assembly目录下有如下内容
2006-04-08 00:32 <DIR> GAC
2006-11-10 21:55 <DIR> GAC_32
2006-04-07 23:39 <DIR> GAC_MSIL
2006-04-08 00:32 <DIR> NativeImages1_v1.1.4322
2006-10-20 04:23 <DIR> NativeImages_v2.0.50727_32
2006-10-19 02:18 <DIR> temp
2006-10-19 02:19 <DIR> tmp

GAC中是.net1.1的assembly

从.net2.0开始支持64bit,理论上.net assembly是MSIL代码,不用关心平台是
32位还是64位,但有些Manage c++的assembly同时包含MSIL code和Native code,
所以出现了32bit .net assembly 和64bit .net assemlby,在32位平台上,只需要安装
32bit .net assembly, 在64位平台上,要能直接运行32位的程序(Windows on windows),
所以要同时安装32bit .net assembly和64bit .net assembly,然而不是所有的assembly
都包含native code,所以可以把.net assembly分为两部分,所以在32位机器上会看到
GAC_32和GAC_MSIL这两个目录,在64位机器上会看到GAC_32,GAC_64,
GAC_MSIL这三个目录.打开GAC_32和GAC_MSIL这两个目录,可以看到GAC_MSIL
中包含大部分.net framework assembly和所有应用程序的assemly,GAC_32中包含
mscorlib等底层的assembly.

打开NativeImages目录,可以看到目录中包含所有的.net framework assembly的Native
Image,可见为了提高性能,MS为所有的.net framework assembly生成了image,

temp和tmp是两个空目录.

c:\windows\assembly下的隐藏文件Desktop.ini指定了使用Shell扩展SHFusion.dll来显示目录下的文件.

RegisterClientScriptBlock vs RegisterStartupScript

Filed under: ASP.NET

RegisterClientScriptBlock一般返回的是客户端函数的包装,而RegisterStartupScript返回得函数在document装载完成后会执行,类似于body onload=”f()”里面的函数;

这两个方法在客户端呈现的代码位置不同,RegisterClientScriptBlock在<form runat=server>之后,而RegisterStartupScript在</form>之前。

November 9, 2006

An error in my T-SQL

Filed under: SQL&DB Accessing

Column XXX is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
——————
http://sqlzoo.net/howto/source/z.dir/err979/sqlserver
When using a GROUP BY clause every field in the SELECT list must be either:
One of the GROUP BY terms - in this case region
An aggregate function - for example SUM or COUNT
An expression based on the above

In the example the field name may not be used on the SELECT line.
SELECT name, region, MAX(population)
FROM bbc
GROUP BY region

In a group by line each region shows up only once - however in a typical region such
as Africa there are several different name values. WHich one should SQL pick?

Solutions
-Remove the offending field from the SELECT line
-Add the field to the GROUP BY clause
-Aggregate the offending field

Specific to SQL Server

Administrator can’t open IIS Manager

Filed under: 使用技巧

I had been added to the administrator group on a remote server, but when I try to manage the IIS service on it, the access was denied.
Other people tell me to modify my User Profile on the server:
My computer’s context menu->Propery->Advanced->User Profiles
Find my name, change Profile Type from Roaming to Local.

He is correct.

November 6, 2006

What’s Event Toaster?

Filed under: Visual Studio

装完了VS 2005 SDK后,在任务栏上出现了一个名为Event Toaster的图标,google后得知这是VS SDK Power Toys的一个小工具,可在VS工作时触发事件,执行一些命令,可在
VS 2005的Tools -> Option中PowerToys->EventToaster中进行设置.

参考:
http://blogs.msdn.com/aaronmar/archive/2006/07/19/671687.aspx

November 3, 2006

Some “new” tools for me.

Filed under: 技术资源

1.VMWare Player. It’s free.
There are some images for it:
http://www.vmware.com/vmtn/appliances/

2.Lingoes dictionary. Free.
http://www.lingoes.net/

3.ubuntu. Debian
http://www.ubuntu.org.cn/
http://www.debian.org/international/Chinese/

4.DownThemAll for firefox2.0

October 28, 2006

FWK Design Guidelines CD

Filed under: .NET

Transcripts for the MSDN Designing .NET Class Libraries chats (Brad Abrams’ Blog)
http://blogs.msdn.com/brada/archive/2005/07/11/437388.aspx

MSDN: Designing .NET Framework Class Libraries cross index (More chat transcripts by CLR PM)
http://www.bluebytesoftware.com/blog/PermaLink,guid,26be120b-7b86-47f2-bb2c-1c8a063807a5.aspx

Designing .NET Class Libraries (MSDN 所有的讲座)
http://msdn2.microsoft.com/en-us/netframework/aa497250.aspx

————————————-
Setting The Stage
by Brad Abrams
————————————-

————————————
API Usability
by Steven Clarke(http://blogs.msdn.com/stevencl/default.aspx)
http://msdn.microsoft.com/chats/transcripts/net/2005_0223_apiusability.aspx
http://www.microsoft.com/seminar/shared/asp/view.asp?url=/seminar/en/20040929usability/manifest.xml&rate=1
————————————
了解API的使用者(Target audience),提供易用,好懂的API

1.如何收集反馈,在开发周期中检查是否达到设计目标
2.API的3重境界:
能工作
易懂的API,用户明白如何工作,
用户可以预测(predict)如何使用

3.没有程序员愿意学习如何使用API

4.如何设计API
从设计开始就注意
Use the Cognitive Dimensions
Understand users’ scenarios.
Get feedback

5. Cognitive Dimensions
abstraction level
Learning Style : Top down
Working Framework : work set
Work-Step Unit : Develop 完成一个工作所需的步骤
Premature Commitment
Progressive Evaluation
9. Gathering User Feedback
Early and often
API review
Expreience review
Usablity study

14. Common Usability Problems

————————————-
Designing Progressive APIs
by Krzysztof Cwalina {CLR Team PM}
http://www.microsoft.com/seminar/shared/asp/view.asp?url=/seminar/en/20040929prog_apis/manifest.xml&rate=2
————————————-
3种程序员
1. Vertical
2. Pragmatic
3. Einsteins
vb, MFC, ATL

Progressive API
1.易学:
80/20 Rule
Defaults and helps
2.Powerful
Richness
Performance
Scalablity
3.Consistent

设计原则: Scenario-Driven
Defing top scenario
Write code samples first, design API later
Make top scenario easy, make the rest possible
Usablity test top scenarios

设计原则2: Supporting experimentation

设计原则3: Aggregate component

设计原则4: Self-Documenting APIs
命名
Exception
设计原则5: Keeping Things Simple
Number of objects
Dependencies
Lines of code
OO

————————————-
Designing Inheritance Hierarchies
by Brad Abrams
http://www.microsoft.com/seminar/shared/asp/view.asp?url=/seminar/en/20040929hierarchies/manifest.xml&rate=2
————————————-
Keywords: Interface versus base class
So you can do the minimum now, and then add more to it in the future.

Overriding的思考点:
1.不要改变base class 定义的 contract
2.通常需要call base, 除非有充足的理由.
3.不要让class写出这样的code:
if( obj is network stream) …
else if(obj is …) …

Interface
Explicit Implementation

————————————-
FxCop in Depth
by Jeffrey Van Gogh, Michael Murray
http://www.microsoft.com/seminar/shared/asp/view.asp?url=/seminar/en/20041012fxcop/manifest.xml&rate=0
http://www.microsoft.com/china/msdn/events/webcasts/shared/msdntv/episode.aspx?xml=/china/msdn/events/webcasts/msdntv/20031204FxCopMM/manifest.xml
————————————-
FxCop干了什么:
Access IL metadata
Examine IL method bodies
Walk call graphs
Determine some argument
Use spelling checker (if office is installed)
规则分类:
COM
Design
Globalization
Naming
Performance
Usage
Security
Custom

————————————-
Designing for Managed Memory World(经典!)
by Brad Abrams
http://www.microsoft.com/seminar/shared/asp/view.asp?url=/seminar/en/20040929memory_world/manifest.xml&rate=1
————————————-
Framework的作者需要封装native 资源
~ 被编译器翻译为
protected override void Finalize()
{
try
{

}
finally
{
base.finalize();
}
}

何时需要~即 Finalize()
仅在需要释放外部资源时.

Dispose Pattern
Dispose()会 被多次调用
Dispose()不能throw exceptiion
if(disposed)
throw new ObjectDisposedException();

使用:
using( Resource res = new Resource())
{
res.DoWork();
}

GC.AddMemoryPressure()
GC.RemoveMemoryPressure()

HandleCollector
.NET Framework 2.0 中新增。
跟踪未处理的句柄,并在达到指定阈值时强制执行垃圾回收。

————————————-
Member Types
by Brad Abrams
http://www.microsoft.com/seminar/shared/asp/view.asp?url=/seminar/en/20040929member_types/manifest.xml&rate=2
————————————-
1.Constructor
在c++中不要在一个Constructor中throw exception.
在c#中可以这样做,Finalizer仍旧可以调用,GC仍旧可被执行.

永远显式定义一个default constuctor,以免错误:
//v1
public class Foo
{
}
此时 Foo f = new Foo(); 正常工作

//v2
pubolc class Foo
{
public Foo(int value)
}
此时 Foo f = new Foo(); 出错

So what that essentially means is between the two releases, you’ve removed the default
one and added this new one, so that will break code.

2. Overloading
参数少的函数会假定传入defatul value
参数的顺序要一致,参数最多的函数最好定义为virtual

Performance:
使JIT生成 in-line函数:
少使用virutal method
不要定义过多的局部变量

Property and Method:
property 返回不变的值如: string Name{get;},
从逻辑上说是一个data member
method 返回变化的值: Guid GetNext(){};conversion,
复杂的逻辑
可能不会马上返回.

不要定义用来生成snapshotting的array 类型的property,, 防止这样的写法:
for(int i= 0; i < list.Length; i++)
{
list.All[i]….
}

Event Pattern
protected void DoClick()
{
PaintDown();
try
{
onClick(); //call event handler
}
finally
{
if(windowHandler != null)
{
PaintUp();
}
}
}

Static Member 的用途及使用pattern
Singleton Pattern
Factory methods

Ref and Out Parameters:
主要用于interop
Ref是CLR的特性
Out是c#的属性

————————————-
Naming Conventions
by Brad Abrams
http://msdn2.microsoft.com/en-us/netframework/aa497259.aspx
————————————-
All type and publicly exposed member are PascalCased
Parameter are camelCased

So also the principle of least surprise, you want to do what developers expect.

Type Naming:
1.使用名词
2.如果从Exception派生, 命名为ArgumetException
————————————-
Packaging, Assemblies and Namespaces
by Michael Murray (Longhon SDK Team PM)

Assemply 和Namespace 为什么要使用不同的名字?
Assemply名称使人易于找出需要reference的dll
不同版本的Type最好位于不同的assembly.
同一个Assemlby中的代码的信任级别是相同的.
改动会引发rebuild

————————————-

————————————-
Performance
by Rico Mariani, Maoni Stephens
————————————-

————————————-
Rich Type System

————————————-

October 24, 2006

IE的安全模式

Filed under: 使用技巧

在Accessories(附件)->SystemTools中有一个shortcut, “C:\Program Files\Internet Explorer\iexplore.exe” -extoff
可无插件运行IE.

October 23, 2006

Java面试中的陷阱(转贴)

Filed under: C#

第一,谈谈final, finally, finalize的区别。

final?修饰符(关键字)如果一个类被声明为final,意味着它不能再派生出新的子类,不能作为父类被继承。因此一个类不能既被声明为 abstract的,又被声明为final的。将变量或方法声明为final,可以保证它们在使用中不被改变。被声明为final的变量必须在声明时给定初值,而在以后的引用中只能读取,不可修改。被声明为final的方法也同样只能使用,不能重载

finally?再异常处理时提供 finally 块来执行任何清除操作。如果抛出一个异常,那么相匹配的 catch 子句就会执行,然后控制就会进入 finally 块(如果有的话)。
finalize?方法名。java 技术允许使用 finalize() 方法在垃圾收集器将对象从内存中清除出去之前做必要的清理工作。这个方法是由垃圾收集器在确定这个对象没有被引用时对这个对象调用的。它是在 object 类中定义的,因此所有的类都继承了它。子类覆盖 finalize() 方法以整理系统资源或者执行其他清理工作。finalize() 方法是在垃圾收集器删除对象之前对这个对象调用的。

第二,anonymous inner class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)?

匿名的内部类是没有名字的内部类。不能extends(继承) 其它类,但一个内部类可以作为一个接口,由另一个内部类实现。

第三,static nested class 和 inner class的不同,说得越多越好(面试题有的很笼统)。
nested class (一般是c++的说法),inner class (一般是java的说法)。java内部类与c++嵌套类最大的不同就在于是否有指向外部的引用上。具体可见http: //www.frontfree.net/articles/services/view.asp?id=704&page=1
注: 静态内部类(inner class)意味着1创建一个static内部类的对象,不需要一个外部类对象,2不能从一个static内部类的一个对象访问一个外部类对象

第四,&和&&的区别。
&是位运算符。&&是布尔逻辑运算符。

第五,hashmap和hashtable的区别。
都属于map接口的类,实现了将惟一键映射到特定的值上。
hashmap 类没有分类或者排序。它允许一个 null 键和多个 null 值。
hashtable 类似于 hashmap,但是不允许 null 键和 null 值。它也比 hashmap 慢,因为它是同步的。

第六,collection 和 collections的区别。
collections是个java.util下的类,它包含有各种有关集合操作的静态方法。
collection是个java.util下的接口,它是各种集合结构的父接口。

第七,什么时候用assert。
断言是一个包含布尔表达式的语句,在执行这个语句时假定该表达式为 true。如果表达式计算为 false,那么系统会报告一个 assertionerror。它用于调试目的:
assert(a > 0); // throws an assertionerror if a <= 0
断言可以有两种形式:
assert expression1 ;
assert expression1 : expression2 ;
expression1 应该总是产生一个布尔值。
expression2 可以是得出一个值的任意表达式。这个值用于生成显示更多调试信息的 string 消息。
断言在默认情况下是禁用的。要在编译时启用断言,需要使用 source 1.4 标记:
javac -source 1.4 test.java
要在运行时启用断言,可使用 -enableassertions 或者 -ea 标记。
要在运行时选择禁用断言,可使用 -da 或者 -disableassertions 标记。
要系统类中启用断言,可使用 -esa 或者 -dsa 标记。还可以在包的基础上启用或者禁用断言。
可以在预计正常情况下不会到达的任何位置上放置断言。断言可以用于验证传递给私有方法的参数。不过,断言不应该用于验证传递给公有方法的参数,因为不管是否启用了断言,公有方法都必须检查其参数。不过,既可以在公有方法中,也可以在非公有方法中利用断言测试后置条件。另外,断言不应该以任何方式改变程序的状态。

第八,gc是什么? 为什么要有gc? (基础)。
gc是垃圾收集器。java 程序员不用担心内存管理,因为垃圾收集器会自动进行管理。要请求垃圾收集,可以调用下面的方法之一:
system.gc()
runtime.getruntime().gc()

第九,string s = new string(”xyz”);创建了几个string object?
两个对象,一个是”xyx”,一个是指向”xyx”的引用对象s。

第十,math.round(11.5)等於多少? math.round(-11.5)等於多少?
math.round(11.5)返回(long)12,math.round(-11.5)返回(long)-11;

第十一,short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错?
short s1 = 1; s1 = s1 + 1;有错,s1是short型,s1+1是int型,不能显式转化为short型。可修改为s1 =(short)(s1 + 1) 。short s1 = 1; s1 += 1正确。

第十二,sleep() 和 wait() 有什么区别? 搞线程的最爱
sleep()方法是使线程停止一段时间的方法。在sleep 时间间隔期满后,线程不一定立即恢复执行。这是因为在那个时刻,其它线程可能正在运行而且没有被调度为放弃执行,除非(a)”醒来”的线程具有更高的优先级
(b)正在运行的线程因为其它原因而阻塞。
wait()是线程交互时,如果线程对一个同步对象x 发出一个wait()调用,该线程会暂停执行,被调对象进入等待状态,直到被唤醒或等待时间到。

第十三,java有没有goto?
goto?java中的保留字,现在没有在java中使用。

第十四,数组有没有length()这个方法? string有没有length()这个方法?
数组没有length()这个方法,有length的属性。
string有有length()这个方法。

第十五,overload和override的区别。overloaded的方法是否可以改变返回值的类型?
方法的重写overriding和重载overloading是java多态性的不同表现。重写overriding是父类与子类之间多态性的一种表现,重载overloading是一个类中多态性的一种表现。如果在子类中定义某方法与其父类有相同的名称和参数,我们说该方法被重写 (overriding)。子类的对象使用这个方法时,将调用子类中的定义,对它而言,父类中的定义如同被”屏蔽”了。如果在一个类中定义了多个同名的方法,它们或有不同的参数个数或有不同的参数类型,则称为方法的重载(overloading)。overloaded的方法是可以改变返回值的类型。

第十六,set里的元素是不能重复的,那么用什么方法来区分重复与否呢? 是用==还是equals()? 它们有何区别?
set里的元素是不能重复的,那么用iterator()方法来区分重复与否。equals()是判读两个set是否相等。
equals()和==方法决定引用值是否指向同一对象equals()在类中被覆盖,为的是当两个分离的对象的内容和类型相配的话,返回真值。

第十七,给我一个你最常见到的runtime exception。
arithmeticexception, arraystoreexception, bufferoverflowexception, bufferunderflowexception, cannotredoexception, cannotundoexception, classcastexception, cmmexception, concurrentmodificationexception, domexception, emptystackexception, illegalargumentexception, illegalmonitorstateexception, illegalpathstateexception, illegalstateexception,
imagingopexception, indexoutofboundsexception, missingresourceexception, negativearraysizeexception, nosuchelementexception, nullpointerexception, profiledataexception, providerexception, rasterformatexception, securityexception, systemexception, undeclaredthrowableexception, unmodifiablesetexception, unsupportedoperationexception

第十八,error和exception有什么区别?
error 表示恢复不是不可能但很困难的情况下的一种严重问题。比如说内存溢出。不可能指望程序能处理这样的情况。
exception 表示一种设计或实现问题。也就是说,它表示如果程序运行正常,从不会发生的情况。

第十九,list, set, map是否继承自collection接口?
list,set是

map不是

第二十,abstract class和interface有什么区别?
声明方法的存在而不去实现它的类被叫做抽象类(abstract class),它用于要创建一个体现某些基本行为的类,并为该类声明方法,但不能在该类中实现该类的情况。不能创建abstract 类的实例。然而可以创建一个变量,其类型是一个抽象类,并让它指向具体子类的一个实例。不能有抽象构造函数或抽象静态方法。abstract 类的子类为它们父类中的所有抽象方法提供实现,否则它们也是抽象类为。取而代之,在子类中实现该方法。知道其行为的其它类可以在类中实现这些方法。
接口(interface)是抽象类的变体。在接口中,所有方法都是抽象的。多继承性可通过实现这样的接口而获得。接口中的所有方法都是抽象的,没有一个有程序体。接口只可以定义static final成员变量。接口的实现与子类相似,除了该实现类不能从接口定义中继承行为。当类实现特殊接口时,它定义(即将程序体给予)所有这种接口的方法。然后,它可以在实现了该接口的类的任何对象上调用接口的方法。由于有抽象类,它允许使用接口名作为引用变量的类型。通常的动态联编将生效。引用可以转换到接口类型或从接口类型转换,instanceof 运算符可以用来决定某对象的类是否实现了接口。

第二十一,abstract的method是否可同时是static,是否可同时是native,是否可同时是synchronized?
都不能

第二十二,接口是否可继承接口? 抽象类是否可实现(implements)接口? 抽象类是否可继承实体类(concrete class)?
接口可以继承接口。抽象类可以实现(implements)接口,抽象类是否可继承实体类,但前提是实体类必须有明确的构造函数。

第二十三,启动一个线程是用run()还是start()?
启动一个线程是调用start()方法,使线程所代表的虚拟处理机处于可运行状态,这意味着它可以由jvm调度并执行。这并不意味着线程就会立即运行。run()方法可以产生必须退出的标志来停止一个线程。

第二十四,构造器constructor是否可被override?
构造器constructor不能被继承,因此不能重写overriding,但可以被重载overloading。

第二十五,是否可以继承string类?
string类是final类故不可以继承。

第二十六,当一个线程进入一个对象的一个synchronized方法后,其它线程是否可进入此对象的其它方法?
不能,一个对象的一个synchronized方法只能由一个线程访问。

第二十七,try {}里有一个return语句,那么紧跟在这个try后的finally {}里的code会不会被执行,什么时候被执行,在return前还是后?
会执行,在return前执行。

第二十八,编程题: 用最有效率的方法算出2乘以8等於几?
有c背景的程序员特别喜欢问这种问题。

2 << 3

第二十九,两个对象值相同(x.equals(y) == true),但却可有不同的hash code,这句话对不对?
不对,有相同的hash code。

第三十,当一个对象被当作参数传递到一个方法后,此方法可改变这个对象的属性,并可返回变化后的结果,那么这里到底是值传递还是引用传递?
是值传递。java 编程语言只由值传递参数。当一个对象实例作为一个参数被传递到方法中时,参数的值就是对该对象的引用。对象的内容可以在被调用的方法中改变,但对象的引用是永远不会改变的。

第三十一,swtich是否能作用在byte上,是否能作用在long上,是否能作用在string上?
switch(expr1)中,expr1是一个整数表达式。因此传递给 switch 和 case 语句的参数应该是 int、 short、 char 或者 byte。long,string 都不能作用于swtich。

第三十二,编程题: 写一个singleton出来。
singleton模式主要作用是保证在java应用程序中,一个类class只有一个实例存在。
一般singleton模式通常有几种种形式:
第一种形式: 定义一个类,它的构造函数为private的,它有一个static的private的该类变量,在类初始化时实例话,通过一个public的getinstance方法获取对它的引用,继而调用其中的方法。
public class singleton {
  private singleton(){}
  //在自己内部定义自己一个实例,是不是很奇怪?
  //注意这是private 只供内部调用
  private static singleton instance = new singleton();
  //这里提供了一个供外部访问本class的静态方法,可以直接访问  
  public static singleton getinstance() {
    return instance;   
   }
}
第二种形式:
public class singleton {
  private static singleton instance = null;
  public static synchronized singleton getinstance() {
  //这个方法比上面有所改进,不用每次都进行生成对象,只是第一次     
  //使用时生成实例,提高了效率!
  if (instance==null)
    instance=new singleton();
return instance;   }
}
其他形式:
定义一个类,它的构造函数为private的,所有方法为static的。
一般认为第一种形式要更加安全些

hashtable和hashmap
hashtable继承自dictionary类,而hashmap是java1.2引进的map interface的一个实现

hashmap允许将null作为一个entry的key或者value,而hashtable不允许

还有就是,hashmap把hashtable的contains方法去掉了,改成containsvalue和containskey。因为contains方法容易让人引起误解。

最大的不同是,hashtable的方法是synchronize的,而hashmap不是,在
多个线程访问hashtable时,不需要自己为它的方法实现同步,而hashmap
就必须为之提供外同步。

hashtable和hashmap采用的hash/rehash算法都大概一样,所以性能不会有很大的差异。

如何识别SQL server以及service pack的版本

Filed under: SQL&DB Accessing

方法1.执行 select @@version
SQL Server 2005 RTM版本为9.00.1399.06
SQL Server 2005 SP1版本为9.00.2047.00 (我目前的版本)
SQL Server 2005积累补丁版本为9.00.2153.00

方法2.执行
SELECT SERVERPROPERTY(’productversion’), SERVERPROPERTY (’productlevel’), SERVERPROPERTY (’edition’)
http://support.microsoft.com/kb/321185/zh-cn

October 22, 2006

c#问答

Filed under: C#

—-VS自动生成的代码为
namespace ConsoleApplication1
{
class Program
{
….

}
}
class Program的访问权限为? 能否定义为private 或 protected?

—-构造函数是否可以为virtual? why?

—-c#中的overloading函数是否可以仅仅只有返回值不同,why?
(在调用函数,并忽略其返回值时, 你能说出是在调用哪个函数吗?)
能不能参数列表完全相同,仅仅用ref或out来区别?
—-有没有特例?
public static explicit operator Int32(Rational r){}
public static explicit operator Single(Rational r){}
实际生成的代码在metadata中的记录为:
public static Int32 op_Explicit(Rational r)
public static Single op_Explicit(Rational r)
CLR可以仅通过返回值识别函数,c++,c#,vb,java都不支持.

—-为什么要定义缺省构造器?
//v1
public class Foo
{
}
//v2
pubolc class Foo
{
public Foo(int value)
}
此时已有的代码会出现什么问题?

—-C++的构造函数中能否抛出异常,c#呢?why?此时GC的行为如何?

—-How about this code snippet?

class a
{
public a(int c)
{

}
}

class b : a
{
public b(int c) //: base(c)
{ }
}

—-How about this one?
class a
{
public a()
{ }
}

class b : a
{
public b()
{ }
}

A:
class a
{
public a()
{ }
public a(int c)
{

}
}

class b : a
{
public b(int c)
{ }
}

Will creat code in b.b(int c) to call a()

—-能否在finally block中return一个值? why?

—-下面的代码返回值为?
private static int GetInt()
{
string a = null;
try
{
Console.WriteLine(a.Length);
return 10;
}
finally
{
Console.WriteLine(”finally block”);
}
return 100;
}
(因为没有catch,所以不会有返回值.)
如果去掉Console.WriteLine(a.Length); return 10 和 finally谁先执行?
(return 10 先执行)

—-What is the difference:

try
{}
catch()
{
throw;
}

try
{}
catch()
{
throw new Exception();
}

—-Do you like using:
try
{}
catch(Excption e)
{}
why?

October 18, 2006

老大推荐的网站

Filed under: 网络资源

http://www.techcrunch.com/ 技术网站

http://www.flypig.org/ blog

http://www.larkware.com/

http://www.coghead.com/ web design

Tip/Trick: Patterns and Practices Guidance Explorer for .NET and ASP.NET

http://flickr.com/

October 13, 2006

收集Scott Mitchell的文章

Filed under: ASP.NET

Online Articles
http://www.4guysfromrolla.com/ScottMitchell.shtml

Working with data in asp.net 2.0
http://www.asp.net/learn/dataaccess/default.aspx?tabid=63
中文版:http://www.cnblogs.com/lovecherry/archive/2006/07/02/440840.html

Blog : {Scott on Writing}
http://www.scottonwriting.net/sowBlog/

Scott’s Code Project
http://www.scottonwriting.net/sowBlog/CodeProjects.htm

October 12, 2006

把势与pattern

把势与pattern
-AlonePlayer@gmail.com 2006.10.12
把式或把势,武术的旧称,实指武术中的架势.谚曰:”练拳不练把,等于瞎胡打;宁教十趟拳,不教一个把”
武术中的每一势都是实战中萃取出的精华(不包含那些舞蹈化,艺术化的东西),简单者,一看即知用法,小孩
打架或许都曾用过,高妙者内藏玄机,可以千变万化,也可以不变应万变,要理解需要知道它的各种应用场景,
发招的劲道火候.先贤为了武术的传承,把势排列组合,形成套路,同时也暗示了某些势的组合应用,但这也带
来一些负面影响,一者使人的思维拘泥与套路,难以随心而发,再者练习时平均分配时间,不利于重点练习.大师
在技臻化境时往往忘记了套路,体内产生一种本能,见招即有应对,且对时间,空间,力量,速度拿捏
精准,接应之妙,令人叹为观止.而对这些临敌因素,则千变万化,无法见诸文字,可谓一说即错,后学者务必耐心
揣摩,勤于练习,多多实践,方能有所得.

挤公车

Filed under: 随便说说

挤公车
-AlonePlayer@gmail.com 2006.10.12
相信大家都有过这种经历,在100米外看着自己要坐的车缓缓启动,绝尘而去,
很令人沮丧.或许,因为坐不上这趟车,你会迟到,会参加不了某个重要的会议,会
错过火车或飞机,进而错过更多的事情.但人生充满了不定因素,或许,你转头望去,
下一辆车正转过前一个街角.车上的人很挤,但令人欣慰的是司机风风火火,一站
一站,居然超过前面那辆你错过的车.

等车时,大家都生怕自己慢了一步,都是一副焦急的神态,等上了车,就各有不同了,
有的人是短途,随便找个地方容身,有的人从车头挤到车尾,期望能找到一个座位,
有的人报纸铺地,把一阶台阶改造成自己的座位,有的人运气很好,刚刚上车不久,
身边就有一个乘客下车,留下一个座位给他,有的人东张西望,盘算着哪个人就要
下车,好站在那人身边等座位,有的人心存善良,讲座位让给他人,自己站着,却也一
身轻松.

September 21, 2006

Code Smith应用

Filed under: 开发工具

Code Smith应用
在我们的project中,对于一个web service要进行3个地方的处理
1.asmx file,比如GCRecommendWebSiteManagementService.asmx.vb, 提供web methods
<System.Web.Services.WebService(Namespace:=”http://tempuri.org/“)> _
Public Class GCRecommendWebSiteManagementService
Inherits BaseService

<WebMethod(), System.Web.Services.Protocols.SoapHeader(”TokenValue”)> _
Public Function GetAllRecommendWebSite() As DataSet
end Function
end Class

2.内部逻辑class, 比如GCRecommendWebSiteManagementControl.vb
Public Class GCRecommendWebSiteManagementControl
Inherits BaseControl
Public Function GetAllRecommendWebSite() As DataSet

End Function
end class

3.在Client 端提供proxy 比如GCRecommendWebSiteManagementServiceProxy.vb
<System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute(”code”), _
System.Web.Services.WebServiceBindingAttribute(Name:=”GCRecommendWebSiteManagementServiceSoap”, [Namespace]:=”http://tempuri.org/“)> _
Public Class GCRecommendWebSiteManagementServiceProxy
Inherits BaseProxy
<System.Web.Services.Protocols.SoapHeaderAttribute(”TokenValue”), _
System.Web.Services.Protocols.SoapDocumentMethodAttribute(”http://tempuri.org/GetAllRecommendWebSite“, RequestNamespace:=”http://tempuri.org/“, ResponseNamespace:=”http://tempuri.org/“, Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)> _
Public Function GetAllRecommendWebSite() As System.Data.DataSet
Dim results() As Object = Me.Invoke(”GetAllRecommendWebSite”, New Object(-1) {})
Return CType(results(0), System.Data.DataSet)
End Function

Public Function BeginGetAllRecommendWebSite(ByVal callback As System.AsyncCallback, ByVal asyncState As Object) As System.IAsyncResult
Return Me.BeginInvoke(”GetAllRecommendWebSite”, New Object(-1) {}, callback, asyncState)
End Function

Public Function EndGetAllRecommendWebSite(ByVal asyncResult As System.IAsyncResult) As System.Data.DataSet
Dim results() As Object = Me.EndInvoke(asyncResult)
Return CType(results(0), System.Data.DataSet)
End Function
end Class

三部分代码大同小异,目前的做法是copy-post-modify,不好.
我想可以通过下面的方法来自动生成代码:
1. 在GCRecommendWebSiteManagementControl.vb中定义出一个web service所有方法的原型.
2. 在CodeSmith 模板文件执行时利用CodeDomProvider.CompileAssemblyFromSource动态build这个文件,
生成一个assembly,再遍历这个assemlby中的type,type中的method, 利用code dom 就可以生成对应的代码.

注意由于vb会在build一个assembly时加入诸如My.MyApplication,My.MyComputer的class,同时一个
class也会从object继承一些method,所以又需要定义一个attribut来标识需要生成代码的type和
method.

收获
1.使用了自定义的assembly(包含标识type和method的attribute)
2.使用子模板,根据不同的语言生成代码.
3.使用code behind文件,把大量的逻辑放在.cs文件中
4.复习了codedom,
VBCodeProvider.CreateGenerator 已被废弃,现在的用法是:
CodeDomProvider codeProvider = CodeDomProvider.CreateProvider(”VisualBasic”);
codeProvider.GenerateCodeFromMember(cmm, sw, new CodeGeneratorOptions());
5.CodeDom动态编译

September 19, 2006

vs2005快捷键收集

Filed under: Visual Studio

//——-Coding
Ctrl+K, Ctrl+M
Surroun Ctrl+K, Ctrl+S
Code snippet Ctrl+K, Ctrl+X

注释 Ctrl+K, Ctrl+C
remove注释 Ctrl+K, Ctrl+U
Clipboard内容循环 Ctrl+Shift+V

删除当前行 Ctrl+Shift+L

自动换行 Ctrl+E, Ctrol+W

大小写 Ctrl+Shift+U, Ctrl+U

Navigation backward Ctrl+-
Navigation forward Ctrl+Shift+-
//——-Refactor
Rename Ctrl+R, Ctrl+R

//——-Search
渐进式搜索 Ctrl+I
反向渐进式搜索 Ctrl+Shift+I

//——-各种窗口
Command window Ctrl+Alt+A
Show breakpoints window Ctrl+Alt+B
Solution explore Ctrl+Alt+L
Code Definition window Ctrl+\, Ctrl+D

Exceptions Ctrl+Alt+E
Attach to Process Ctrl+Alt+P
Task List Ctrl+\,Ctrl+T
Error List Ctrl+\,Ctrl+E
Toolbox Ctrl+Alt+T
Class Ctrl+Shift+C

Macro Explore Alt+F8

//——-Bookmark
Bookmark window Ctrl+K, Ctrl+W
Toogle Bookmark Ctrl+K, Ctrl+K
Next Bookmark Ctrl+K, Ctrl+N
Previous Bookmark Ctrl+K, Ctrl+P
Clear Bookmarks Ctrl+K, Ctrl+L
Add Task List Ctrl+K, Ctrl+H
Remove Task List Ctrl+K, Ctrl+H

//——-Format
Format Ctrl+K, Ctrl+D

//——-Breakpoint
New breakpoint Ctrl+D
Clear all breakpoints Ctrl+Shift+F9

//——-VS
全屏 Shift+Alt+Enter
切换active file Ctrl+Tab
Open file Ctrl+O
New file Ctrl+N
New project Ctrl+Shift+N

September 15, 2006

STAThreadAttribute

Filed under: .NET

在VS中,生成一个windows application,程序的Main()函数上会应用
STAThreadAttribut, 而生成Console application就不会应用这个Attribute

static class Program
{
[STAThread]
static void Main()
{

Application.Run(new Form1());
}
}

class Program
{
static void Main(string[] args)
{
}
}

缺省情况下,application的主线程的Apartment state为multi-threaded apartment
(ApartmentState.MTA),设置主线程Apartment state的唯一方法就是使用STAThreadAttribut.

STAThreadAttribut使得一个application的COM 线程模式为single-threaded apartment (STA),
STAThreadAttribut只能应用在程序的入口函数上,对于其他的函数不起作用,

在程序中设置一个线程的COM 线程模式,也可以使用如下的代码:

Thread t = new Thread(new ThreadStart(StartNewStaThread));
//.net1.1
t.ApartmentState = ApartmentState.STA;
t.Start();

private void StartNewStaThread()
{
Application.Run(new Form1());
}
在.net2.0中Thread.ApartmentState被Thread.SetApartmentState (ApartmentState state)取代

注意线程的Apartment state 必须要在线程启动前设置.

从逻辑上说,apartment 是线程和object的容器,apartment中的object可以被这个apartment中任何
一个线程访问. 一个STA只能包含一个线程,一个MTA可以包含多个线程。MTA中各线程可以并行的调用
本公寓内实例化的组件一个进程可以包含多个STA,但只能有一个MTA。

.NET framework不使用apartment 模式, 所有的managed object在使用共享资源时自发地保证线程
安全.由于COM使用了apartment,所以CLR在操作COM ojbect时需要生成和初始化apartment.常用的COM组件有
Clipboar和File Dialog.COM 线程模型只适用于使用 COM interop 的应用程序。如果将此属性应用到
不使用 COM interop 的应用程序,将没有任何效果。
Windows Forms不支持MTA.所以windows程序要使用STAThreadAttribut

在Fantasy Soft的bolg不可错过的MSDN TV-IronPython: Python on the .NET Framework,有
下列描述:
如果你打算在Interactive Mode下面直接执行以上代码,你会碰到如下的错误:
Traceback (most recent call last):
at <shell>
System.InvalidCastException: Creating an instance of the COM component with CLSID {D45FD2FC-5C6E-11D1-9EC1-00C04FD7081F}
from the IClassFactory failed due to the following error: 80004002.
这是由线程的问题引起的,解决的办法就是修改IronPythonConsole目录下PythonCommandLine.cs,在源代码的Main函数前增加[STAThread],
然后重新构建这个Solution。

MSDN上对80004002的定义是: Interface not supported error
见:Standard COM Errors
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/CS07Default/html/b88924d0-f9ca-41a5-af9e-66158ab795d2.asp

September 14, 2006

IronPython Python on the .NET Framework笔记

Filed under: .NET

见IronPython: Python on the .NET Framework
http://msdn.microsoft.com/msdntv/episode.aspx?xml=episodes/en/20051110PythonJH/manifest.xml
————————————-
Build IronPython
————————————-
msbuild IronPython.sln
若在vs中build,请把 IronPythonConsole设为startup project.

————————————-
构成
————————————-
ipy.exe IronPython的控制台
ipyw.exe
Iron.Math.dll
Iron.Python.dll
Lib\Site.py

————————————-
IronPython 用到了.net2.0 哪些 Feature?
————————————-
These include Generics, DynamicMethods, new kinds of delegates, and more.

————————————-
Demo中feature的学习
————————————-
1.import Python 库

>>> import sys # 导入sys module;
>>> sys.path.append(”c:/Python24/Lib”) # 增加搜索路径
>>> import this # 导入Python中名为this的module;
>>> import random # 导入Python中名为random的module;
>>> random.__doc__ # 打印模块的document;
>>> cards = range(51) # range方法用于产生51个元素的List
>>> random.shuffle(cards) # 洗牌
>>> cards # 打印洗牌结果

2. 使用.net 类库

>>> import System # import the standard system module
>>> System.Environment.Version # 打印syste version
>>> form System.Math import * # import all the functions from the math module
>>> Sin(PI/2)
>>> form System import Random
>>> r = Random() # Create new instance
>>> [r.Next(0, 100) for i in range(10)] # 生成10个随机数

3. 派生
>>> class MyRandom(Random): pass # pass表示一条空语句
>>> mr = new MyRandow()
>>> [mr.Next(0, 100) for i in range(10)]
>>> mr.foo = 42 # 为实例mr增加了一个名为foo的field
>>> def Sample(self): return 0.5 # 定义了一个名为Sample的function
>>> MyRandom.Sample = Sample # Override Random 的Sample方法
>>> [mr.Next(0,100) for i in range(10)] # 此时由于改写了Sample方法,而Next方法需要依靠Sample方法的返回结果,
# 因此得到值全为50
>>> def Sample(self): return 0.8 + 0.2*super(MyRandom, self).Sample() # 重新定义了Sample function,调用基类方法

4. 使用From,为control定义event handler
>>> from AvalonStartup import *
>>> w = Window()
>>> w.Show()
>>> b = Button(Content=”Click me”)
>>> w.Content = b
>>> def doIt(* args ): print args
>>> b.Click += doIt

4. 使用 XAML
>>> calc = LoadXaml(’calc.xaml’)
>>> w.Content = calc
>>> for node in Walk(calc) : print node

>>> [node for node in Walk(calc) if isinstance(node, Button)] # 判断一个instance 的type
>>> buttons = _
>>> for b in buttons : print b
>>> for b in buttons : b.Background = Brushes.Blue
>>> ss = SpeakchSynthesizer()
>>> def sayIt(b , e) : ss.SpeakTextAsync(b.Name)
>>> for b in buttons : b.Click += sayIt

5. 与C#调用PythonEngine, 在vs中debug .py调本
在xaml文件中写
<Button Content=”Run Script” Click =”RunScript”>

在cs文件中
using IronPython.Hosting;
public void RunScript(object a , object b)
{
PythonEngine engine = new PythonEngine();
engine.SetVariable(”win” , this);
engine.Execute(”win.SetImage(’c:/images/itrun.jpg’)”);

System.Windows.Forms.OpFileDialog ofd = new System.Windows.Forms.OpFileDialog();
ofd.ShowDialog();
eng.RunFile(ofd.FileName); # 执行文件simple.py
}

# simple.py
text = TextBlock(Text=”Hello”, FontSize=100, Forground=Brush.White)
a = DoubleAnination(0.0 , Duration(TimeSpan.FromSeconds(3)))
a.RepeatBehavior = RepeatBehavior(3)
text.BeginAnimation(Shape.OpacityProperty , a)
Canvas.SetLeft(text , 50)
Canvas.SetTop(text , 10)
win.Content.Children[1].Children.Add(text)

由于IronPython代码最终是会转换为IL代码,由.NET Framework运行,故而IronPyton实现了以下功能:

在c#中调用一个.py文件,如果文件中出错,vs可以brack到出错的代码,
.net debugger可以可以在.py文件中加断点,
可以在debug时修改.py中变量的值

6. 在.py脚本中调用COM组件
首先使用.tlbimp生成将COM组件的wrapper
>tlbimp c:\WINDOWS\msagent\agentsvr.exe
生成AgentServerOjbects.dll

# merlin.py
import sys
sys.LoadAssemblyFromFile(AgentServerObjects.dll)
from AgentServerOjbects import *
a = AgentServerClass
id, rast = a.Load(”merlin.acs”)
ch = a.GetCharacter(id)
ch.SetSize(128,128)
ch.Show(0)
ch.MoveTo(600,100,2000)

我使用的是IronPython1.0, 在1.0中,去掉了LoadAssemblyByName和LoadAssemblyFromFile这两个方法.
而使用built-in module:clr来提供Loading .NET libraries的功能:
clr.AddReference
clr.AddReferenceToFile
clr.AddReferenceToFileAndPath
clr.AddReferenceByName
clr.AddReferenceByPartialName

代码修要改为
# merlin.py for IronPython 1.0
import clr
clr.AddReferenceToFileAndPath(’c:\IronPython\AgentServerObjects.dll’)
from AgentServerObjects import *
a = AgentServerClass()
id, rast = a.Load(”merlin.acs”)
ch = a.GetCharacter(id)
ch.SetSize(128,128)
ch.Show(0)
ch.MoveTo(600,100,2000)

September 12, 2006

IIS 7.0 RC1的新feature

Filed under: ASP.NET

原文见.
http://weblogs.asp.net/scottgu/archive/2006/09/07/IIS-7.0-RC1.aspx

1.可以create多个web site(IIS6也可以啊?)
2.IIS 管理和 asp.net管理被放在一起
3.IIS 使用和asp.net类似的web.conifg,发布时不再需要使用admin script去设置IIS
4.IIS 管理工具提供了”delegated administration”,可用于远程管理.
5.IIS 管理工具的UI可扩展,从而可以管理自己写的HTTP runtime modules.
6.IIS 管理工具集成了ASP.NET 2.0 Membership 管理
7.IIS 5 中在一个web site下只能create Virtual Directory,
IIS 6 中在一个web site下可以create website 或 Virtual Directory,
可设置一个VD的Application Setting,如果设置了Application Setting,VD的图标会变化.
在IIS 7 中,明确区分了Application和VD,在web site的context menu 上有两个选项:
create vd 和 create application.






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham