摘要: 博客园上海俱乐部3月15日的活动终于圆满结束了。作为活动的筹办者和主持人,想把筹办中的一些想法和事例跟大家分享下。  阅读全文
posted @ 2009-03-16 17:28 枫 阅读(1440) | 评论 (32)编辑
     摘要: Silverlight 2已经发布挺久了,已经有不少silverlight方面的教程,但本系列希望尝试从实际开发的角度去了解Silverlight的开发。  阅读全文
posted @ 2008-12-03 14:17 枫 阅读(140) | 评论 (0)编辑
     摘要: Silverlight 2已经发布挺久了,已经有不少silverlight方面的教程,但本系列希望尝试从实际开发的角度去了解Silverlight的开发。  阅读全文
posted @ 2008-12-01 15:47 枫 阅读(1729) | 评论 (9)编辑
     摘要: 在.NET世界中三层架构已经深入人心,是否有人考虑过另外的开发模式呢?  阅读全文
posted @ 2007-03-19 21:58 枫 阅读(2871) | 评论 (9)编辑
     摘要: 由园子里近期刮起的ORM旋风,结合自己的一些实际经验,谈谈自己对ORM的理解。  阅读全文
posted @ 2007-01-06 23:25 枫 阅读(14330) | 评论 (15)编辑

记得以前在看关于讲面向对象的书的时候都会拿Dog和Cat来做例子。比如他们都会叫,则他们都应该有个Bark方法,然后进一步抽象到Animal这个类。

然后进一步往深处讲,则会跟你谈到设计类的时候应该要关注这个类的行为,其实也就是方法了。同时它具有哪些对我们有用的字段和属性,这里我们不谈这个。

但是现在在实际的操作过程中呢?我感觉很多人都是拿了一个问题之后立即开始分析里面所包含的实体类,这个实体类有哪些字段和属性,完了以后加上CRUD方法,最后再在Business Layer里面根据界面的需求进行一通拼装。OK,Mission Complete!

所以在经过一段时间之后我就迷糊了。比如说在一个人力资源管理系统中,有一个人力资源部用户类HRUser,这个用户可以添加一条新雇员的信息,那么我想这个AddNewEmp的方法应该放在HRUser里面,因为是HRUser来做这件事的。但是实际做项目当中我感觉好像HRUser应该是一个实体类,里面不会给任何的方法,这个AddNewEmp的方法肯定会被写在别的地方,它的存在只是为了去响应用户在UI上点了添加雇员的这个按钮罢了。

中午也因为这个问题跟朋友讨论了一下,他说他喜欢实体类然后加控制器的这种做法。比如说你对Emp这个雇员类当作实体类的话,那么就应该有个EmpController,负责Emp的CRUD这些事情。这样做的好处在于分的很清楚。这样做确实是可以,但是如果这样那么好像我开头所讲的那种分析就没什么意义了,一切东西都能够做成一个实体类加控制器嘛。那么到底是书上讲的压根在实际工作中就行不通呢还是我们的做法根本就不是OOP呢?

到底应该怎样做呢?谈谈你的看法吧。

posted @ 2006-11-26 00:07 枫 阅读(8647) | 评论 (20)编辑

Document element (also can be called as root element) is needed for a valid xml document.

Xml namespace is done by defining the Universal Resource Indicator (URIs) which includes Uniform Resource Locators (URL) and Uniform Resource Numbers (URN).

There are 2 ways to define a namespace:
1). Default namespace: define it using the xmlns attribute without a prefix. For example: <html xmlns="http://www.w3.org/1999/xhtml">
2). Prefixed namespace: define it using the xmlns attribute with a prefix. For example: <blist:books xmlns:blist="http://www.wrox.com/books/xml">

DTD may either be stored internally as part of the XML document or externally in a separate file, accessible via a URL.
an internal example:

<?xml version=”1.0” ?>
<!-- DTD is not parsed as XML, but read by parser for validation -->
<!DOCTYPE book [
<!ELEMENT book (title, chapter+)>
<!ATTLIST book author CDATA #REQUIRED>
<!ELEMENT title (#PCDATA)>
<!ELEMENT chapter (#PCDATA)>
<!ATTLIST chapter id #REQUIRED>
]>

Extensible Stylesheet Language Transformation (XSLT) is a language used for converting XML documents from one format to another. The two below are used mainly:
1) Converting XML into HTML
2) Converting XML into another XML

Document Object Model (DOM): this API will laod the whole xml document into the RAM to do the parsing work. It is well suited for traversing and modifying an XML document, but provides little support for finding an arbitrary element or attribute. Of course it has the lower performance.

Simple API for XML (SAX): it loads the document as a stream of data parts instead of aggregation. It's straight-forward only.

Difference between SAX and DOM:
1) DOM uses a parallel approach to the document, it can access several different level nodes with one method. SAX only can starting at the beginning and responding to its contents once for each node and in the order they appear in the document.
2) DOM needs larger memory and has a lower performance. SAX needs smaller memory and has a higher performance. So if reading a very big xml document, using SAX is better.

As DOM doesn't support well for finding an arbitrary element or attribute, XPath can help us to do the work. It is a navigational query language for locating data within an XML document.

posted @ 2006-11-23 15:43 枫 阅读(67) | 评论 (0)编辑
Visual Studio 2005中对Web Project有一个Publish Web Site的菜单,你可以选择这个菜单来发布你的Web Project。

但是在第一次使用中就遇到了这个问题:


自己查看原因,原来是publish之后的precompile code试图将我Login页面的后台代码所对应的Login类转换为WebControls里面的Login类。大家知道.NET 2.0里面提供了一个Login的控件,其本身类的名称也是为Login。因此既然找到了这个原因,那么解决方案就很简单了,把你Login页面的类外面套一个Namesapce,并修改页面文件最上面的定义就可以避免这个错误了。

例子:

namespace MyPage
{
    partical 
class Login
    {
        
//your code here
    }
}

然后修改你的页面中的这部分为
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="MyPage.Login" %>


附:
1) VS 2005对发布Web Project的一个补丁:http://msdn.microsoft.com/asp.net/reference/infrastructure/wdp/default.aspx
2) 更多信息:http://weblogs.asp.net/scottgu/archive/2006/03/27/441147.aspx
posted @ 2006-07-06 09:08 枫 阅读(344) | 评论 (1)编辑
记得很久以前就看到过一篇文章,说搞不懂HttpModule,HttpHandler和HttpContext的算不上好的ASP.NET程序员。由此看来,在此之前我都算不上一个好的ASP.NET程序员。

要想搞清楚上面的几个东西,首先就要搞清楚当一个HttpRequest发送到服务器之后,服务器是怎么处理这个Request并且将处理的结果返回给客户端。在ASP.NET中,当一个HttpRequest到达服务器时,它会首先被inetinfo.exe截获,然后转交给ASPNET_ISAPI.dll处理。而ASPNET_ISAPI.dll则将请求转送到一个HttpPipeline的管道里面,ASPNET_WP.exe进程会接到请求并把它交给HttpRuntime来处理。如下图



那么请求在这个HttpRuntime里面又怎么工作呢?我们可以用下面的这个流程来表示:

HttpRequest ----> HttpApplicationFactory ----> 生成一个HttpApplication实例 ----> HttpModule ----> HttpHandlerFactory ----> HttpHandler ----> 生成结果传输回客户端,在这里我们已经可以看到HttpModule和HttpHandler了!

首先我们看HttpModule,它到底是做什么用的呢?
MSDN上的定义:http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpguide/html/cpconHttpModules.asp
从中可以看到我们可以自定义编程HttpModule来实现对HttpRequest中的内容做一个处理或者过滤。下面的链接中可以转向一个MSDN的例子:http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpguide/html/cpconcustomhttpmodules.asp,具体我这里就不多说了。

具体在这个例子中,我们可以看到我们是通过在IHttpModule接口中的Init方法中注册HttpApplication中的BeginReqeust和EndRequest事件来使我们可以在不同的阶段处理不同的事情。但是实际上,HttpApplication中包含了更多的事件,见MSDN链接:http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpref/html/frlrfsystemwebhttpapplicationclasstopic.asp

再看HttpHanlder,先回顾一下上面讲到的HttpApplication中的那些事件:

[执行处理程序。]

PostRequestHandlerExecute

当进入到这个步骤时,HttpModule开始将Request转移给HttpHandler来处理,处理完的结果再转交给HttpModule发回到客户端。那么HttpHandler又怎么工作呢?其实跟HttpModule差不多,都是通过实现IHttpHanler接口,然后在web.config中注册自己的Handler来执行。

关于这个如何执行以及例子都可以参考MSDN,我想那边的可能更好懂一点。链接:http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpguide/html/cpconaspnetrequestprocessing.asp

 最后关于HttpContext,它是在HttpApplication的实例创建出来之后就一直存在着,可以方便你的去访问HttpRequest中的一些信息。但是需要注意的是在使用里面的一些对象之前建议先弄明白里面一些对象的生命周期,否则可能会引发异常。更多的信息可以参考《ASP.NET Framework深度历险》一书。

关于实践:DNN中大量使用了自定义的HttpModule和HttpHandler来处理这些东西,所以如果有条件不妨去研究DNN,看看这些东西到底能为我们做些什么。

参考资料:
《ASP.NET Framework深度历险》
《DotNetNuke Friendly Urls》
MSDN
http://www.microsoft.com/china/msdn/library/architecture/architecture/architecturetopic/BuildSucApp/BSAAsecmodsecmod37.mspx?mfr=true

posted @ 2006-06-08 11:36 枫 阅读(788) | 评论 (1)编辑