Nov 02

Microsoft has been competing with community, which makes?them seems very stupid.?Java has a comprehensive community, and they?host many high-quality open source projects. The Java ecosystem is so diverse that you can always find quick solutions, in additon to developing self-owned systems. Microsoft doesn’t have?much?intention to develop or support open source community of C#. Instead, they compete with community, or just harvest comunity endeavor. It’s really stupid because C# developers will lose posibility to having more high-quality choice in the future.

A?new example is?their anoucement of developing?Model 2, instead of supporting the open source MVC framework like?MonoRail. The community has been developing MonoRail?in recent years. In 2007 RC3 is realsed after a year development. This MVC framework is a good choice for developers who love flexible HTML and hate the WebForm model. Microsoft staff give very weak reasons for why not supporting existing projects.

Undoubtedly Microsoft is?and has been a great company. It doesn’t necessarily mean that a great company never does stupid things. However, companies in different sizes have different social influence. If a large company does stupid things, they are wasting social wealth and put their partners on high stake as well as themselves. Maybe their open-source strategy limits the advancement direction.

Some related commments:

Nov 02

由朋友介绍,给一家公司的Java开发人员,做了一个3天的培训,期望能让他们快速地了解和掌握.NET和C#开发。面对一帮做了5年或以上开发的大哥们,是很有压力的。上一次这么大压力,是几年前的事情,有位山东来的老教授,白发苍苍,讲授了很多年Turbo C 2.0,老骥伏枥志在千里的他与时俱进想学习C#,让我又钦佩又紧张。

几天课程讲下来,感觉还可以,也不枉那5天熬夜看的不少资料。另外,毕竟C#和Java相似的地方,还挺多的。对于一位Java开发者,或者对两种语言都感兴趣的朋友,应该对这篇文章非常感兴趣的:

Dare Obasanjo写的《C#与Java异同比较》(Comparison of Microsoft’s C# Programming Language to Sun Microsystems’ Java Programming Language)。

Oct 06

不管是写ASP.NET网站,还是JSP网站,程序调试是必不可缺少的工作之一。常用的方式有用Response输出到浏览器中,然后看结果;或者写到一个日志文件中,然后查看调试信息。这个时候,log4net和log4j是非常好的日志工具,只要简单配置一下,就可以很快使用。通过使用不同的Appender,可以把调试信息和日志信息输出到多个目标中去,比如输出到文件、系统日志、控制台(ConsoleAppender)、彩色控制台(ColoredConsolAppender)、电子邮件或者网络广播……

最有意思的就在这里了……就是使用UdpAppender输出到网络上!那么就可以实时观看网页程序运行时的信息了!

基本结构如下:

1. 我们的ASP.NET(或JSP)在运行的时候,可以使用log4net(或log4j)来做日志;
2. 在目标日志中添加一个UdpAppender,设置一个目标IP地址和端口号;
3. 在目标UDP地址的端口上侦听,把收到的UDP数据包输出到一个ColoredConsoleAppender上。OK,完成!

在第2步中,目标IP地址可以设置成本机IP,或另一台机器的IP地址;也可以设置成一个UDP广播地址,这样就能多台机器侦听了。在侦听机器上,可以得到这样的效果:

有趣吧,log4net和log4j设计的很赞,很强的可扩展性!

嗯,得承认本文不是原创,原文地址:A log4net Realtime Color Console for ASP.Net
http://www.codeproject.com/useritems/AspLog4netColorConsole.asp

Sep 05
  1. 创建套接字:Listener Socket
  2. 绑定套接字
  3. 开始侦听
    • 初始化连接请求:BeginConnect
  4. 等待事件
    • AcceptCallback():ClientHandler Socket
    • 初始化接收的请求:BeginReceive
  5. 等待事件
    • ReceiveCallback()
    • 初始化发送的请求:BeginSend
  6. 等待事件
    • SendCallback
    • 设置时间
  7. 关闭套接字Socket

在.NET中进行C#编程的话,参见System.Net.Sockets命名空间和异步编程相关知识。

客户端的基本流程,请访问另一篇日志。

Sep 04

MetaWeblog API是一种给予XML-RPC的应用协议,类似于Atom APILiveJournal API,我们可以通过MetaWeblog API来远程发布、修改日志。Windows Live Spaces提供了对MetaWeblog API的支持,我们可以通过Windows Live Writer来发表日志,也可以通过编程的方式来发表日志。在开始之前,需要一些步骤来启动这个API:

  1. 如果没有Passport帐号,请在www.passport.com注册并获得一个。
  2. 如果还没有space,请在spaces.live.com注册并获得一个。
  3. 登录进入你的space,然后打开Settings(设置),然后打开Email Publishing(电子邮件发布)选项。
  4. 打开电子邮件发布功能。
  5. 选择一个Secret Word。

好了,现在可以开始使用MetaWeblog了,你的用户名就是你space的名字,你的密码就是Secret Word,使用API的地址就是:

https://storage.msn.com/storageservice/MetaWeblog.rpc

如果想了解更多关于这个API的资料,可以参见微软的文档《Windows Live Spaces MetaWeblog API》。

如果想了解如何使用C#、VB.NET开发日志发布程序,请参见MetaWeblog API Code Samples

如果想了解如何使用Python来操作MetaWeblog API,请参见Python文档中的xmlrpclib模块。其实总体来说,还是觉得用Python写最方便。

Apr 14

对IIS 7一直很关注,它看起来是真正能和Apache多方面抗衡的下一代Web服务器。刚收到一封邮件,不少服务商开始提供免费的测试版的IIS 7.0虚拟主机服务。

其中几家是:
http://www.discountasp.com/sp_iis7hosting.aspx
http://www.appliedi.net/iis7-hosting/
http://www.maximumaspbeta.com/

目前提供IIS 7.0 beta host的不多,大概不到10家。更多的服务商,见Google搜索:

Apr 12

dasblog的模版非常强大,即使不懂技术,也可以自由地设计dasblog的模版和主题,然后通过嵌入宏(macro),就能以不同的方式呈现博客。完整的宏列表请见下面的链接,包含了版本、用法、解释等信息:

DasBlog Macro Definitions
http://www.jforsythe.com/jforsythe/projects/dasblogMacros.html

Mar 26

Please do not use the .NET 2.0 HMACSHA512 and HMACSHA384 Classes

http://blogs.msdn.com/shawnfa/archive/2007/01/31/please-do-not-use-the-net-2-0-h
macsha512-and-hmacsha384-classes.aspx

We’ve recently discovered a bug in the HMACSHA512 and HMACSHA384 classes which
shipped in the .NET Framework 2.0.? This bug will cause these algorithms to
produce incorrect results which are not consistent with other implementations
of HMAC-SHA-512 and HMAC-SHA-384.? Unfortunately, we did not discover this bug
until recently, and the shipping .NET Framework 2.0 on all platforms is
affected by it.? The only two affected algorithms are the HMAC-SHA-512 and
HMAC-SHA-384; other HMAC algorithms do produce correct values.

The next service pack to the .NET Framework will contain a fix for this bug,
which will cause the HMACSHA384 and HMACSHA512 classes to produce correct HMAC
values.? However, this will cause their output to be inconsistent with the
output of the unserviced .NET Framework 2.0 classes.? In order to allow
applications running on serviced framework to interact with applications
running on the unserviced version, we will introduce two compatibility switches
in the service pack.

First, both the HMACSHA512 and HMACSHA384 classes will have a new Boolean
property, ProduceLegacyHmacValues.? By setting this property to true, the
object will produce values which match what the unserviced .NET Framework would
have produced.? You should set this property only once after you’ve created
your HMAC object, and you will need to reset your key afterwards:

??? public static void Test()

??? {

??????? HMACSHA512 hmac = new HMACSHA512();

??????? hmac.ProduceLegacyHmacValues = true;

??????? hmac.Key = // … get the hmac key

??????? // …

??????? // use the hmac algorithm

??????? // …

??? }

In order to help applications where it is expensive or impossible to change the
code, we’ve added a new configuration switch for the application’s
.exe.config file which will cause all HMAC objects created within the
application to use the unserviced calculation.

<configuration>

??? <runtime>

??????? <legacyHMACMode enabled=”1″ />

??? </runtime>

</configuration>

Finally, in order to help debug any issues that arise when upgrading to the
service pack, the first time an instance of either class is created, we will
log a warning message to the event log and to any attached debugger.? The
message text (which will hopefully help to point search engine results here as
well) will be:

“This application is using the HMAC-SHA-384 or HMAC-SHA-512 keyed hash
algorithm. The implementation of these algorithms were updated in service pack
1 of .NET Framework 2.0 and by default do not produce results consistent with
the unserviced versions of the classes. For more information about the changes
to the algorithms and how to disable this warning message please see the
release notes for service pack 1.”

This warning will only be produced the first time an instance of either object
is created in a process.? If the configuration switch to enable process-wide
legacy mode is set, then we will suppress the message.? We’ve also provided a
second configuration switch which will let you manually suppress the warning
message for your application.

<configuration>

??? <runtime>

??????? <legacyHMACWarning enabled=”0″ />

??? </runtime>

</configuration>

If you need a replacement class for HMACSHA512 before the next service pack
ships, then you can roll your own relatively easily.? Some code to do this
would look like this:

internal sealed class MyHmacSha512 : System.Security.Cryptography.HMAC

{

??? public MyHmacSha512(byte[] key)

??? {

??????? if (key == null)

??????????? throw new ArgumentNullException(”key”);

??????? HashName = “SHA512″;

??????? HashSizeValue = 512;

??????? BlockSizeValue = 128;

??????? Key = key;

??? }

}

Similarly, a substitute class can be derived for HMACSHA384:

internal sealed class MyHmacSha384 : System.Security.Cryptography.HMAC

{

??? public MyHmacSha384(byte[] key)

??? {

??????? if (key == null)

??????????? throw new ArgumentNullException(”key”);

??????? HashName = “SHA384″;

??????? HashSizeValue = 384;

??????? BlockSizeValue = 128;

??????? Key = key;

??? }

}

This change will start to appear in future CTPs.? Again, I personally, and the
CLR security team in general, are very sorry for any problems this may have
caused in your applications.? Please feel free to ask any questions in the
comments for this post, and I’ll make sure that they get answered as soon as
possible.

Mar 20

这些天在写一个程序,需要用到URL Rewriting。在ASP.NET 2.0中有内置的URL Mapping设置,能够满足一部分需求,我基本上就用它了。如果想编写更强大的URL重写,比如支持正则表达式,下面两篇文章应该足够参考了:

1. Tip/Trick: Url Rewriting with ASP.NET

2. A Complete URL Rewriting Solution for ASP.NET 2.0

调试的时候,发现一个问题是Cassini的对URL Rewriting支持的行为和IIS不一样,最大的区别是内置URL Mapping对目录重写的支持,Cassini是支持的,IIS要到Vista中的7.0时才可以~

Mar 06

美好的世界中,懒人总有选择。对我这样一个Python新手,没有足够的闲暇时间,去读完Python中的XML处理模块,那么最好的方式,就是利用已有的只是囖。那么最直接的方式,就是利用.NET的类库,这方面的工具就是:

IronPython
http://www.codeplex.com/IronPython

Python for .NET
http://pythonnet.sourceforge.net/

Python这个脚本语言有很灵活的选择,比如你熟悉Java,可以考虑JPython,^_^